just for the record, cos I already got what i was searching for, the
code of the other is basically the same, and I use the same solver but
with an API (OpenOpt, CVXOPT-GLPK)
something like:
# -*- coding: utf-8 -*-
"""
Created on Mon Apr 23 18:43:57 2012
@author: Noone
"""
import xlrd
from openopt import *
from numpy import *
from lpsolve55 import *
from scipy import *
#from cvxopt import *
wb = xlrd.open_workbook('datos.xls')
wb.sheet_names()
sh=wb.sheet_by_index(0)
m=[]
h=[]
p=[]
def chunks(l, inicio,largo):
return l[inicio:inicio+largo]
for rownum in range(80):#grupo 1
temp=sh.row_values(rownum+7)
m=m+chunks(temp, 8, 80)
#print m
h=h+chunks(temp, 92, 80)
for rownum in range(673, 673+80):#maximo de hembras por perro
temp=sh.row_values(rownum)
p.append(temp[8])
lb = zeros(80**2*2)
ub = ones(80**2*2)
# making my matrix according to restrictions
def matriz(n):
O=[ [0]*n**2*2 for y in range(n*3) ]
for x in range(n*2):
for z in range(x*n,((x+1)*n)):
O[x].insert(z,1)
O[x].pop(z+1)
for x in range (n):
for z in range(n):
O[n*2+x].insert((z)*n+x,1)
O[n*2+x].pop((z)*n+x+1)
return O
I=matriz(80)
pp=[1]*160
#objective function, just the beneficence from each point
f = m+h
#Matrix subject to restrictions
A=I
#Restriction values
b=p+pp
#Range of Vars
intVars=range(80**2*2)
#Actualizing the MILP:
p = MILP(f, A=A, b=b, lb=lb, ub=ub, goal='max')
#success = p.exportToMPS('milp_1')
r=p.solve('glpk', iprint =-1, )
print 'objFunValue:', r.ff
print 'x_opt:', r.xf
OUTPUT:
objFunValue: 12898.0
with PULP i got that each variable is getting result 1, so it's
logical that it isn't getting the restrictions, by the way, it was a
nice trick the LpAffineExpression, it made me save a lot of time.
whatsoever the PULP OUTPUT was:
Total Costs = 77022.0
for v in prob.variables():
OUTPUT:
perros_9986 = 1
perros_9987 = 1
perros_9988 = 1
perros_9989 = 1
perros_999 = 1
perros_9990 = 1
perros_9991 = 1
perros_9992 = 1
perros_9993 = 1 ...... and for ever and ever 1.
See you around!! and thanks for your time once again!
Regards, Francisco