Hello,
I am a beginner to gurobipy. I have an objective function which is a sum of 3 LinExpr expressions. I have to maximize this function for "n" sets and I do this in a for loop. I have a set of constraints as well.
The problem here is I get an error sometime (***NOT ALWAYS***) but exactly at the same line of code saying: File "linexpr.pxi", line 62, in gurobipy.LinExpr.__init__ (../../src/python/gurobipy.c:27663)
TypeError: float() argument must be a string or a number.
The code i have looks something like this.
for i in range(n):
get inputs (code not shown here) - These are the number of variables
model = Model("mymodel")
x = model.addVars(5,vtype=GRB.BINARY,name= "x")
y = model.addVars(5,vtype=GRB.BINARY,name= "y")
z = model.addVars(6,vtype=GRB.BINARY,name= "z")
coeff_x = [1 for j in range 5]
coeff_y = [-1 for j in range 4]
coeff_z = [1 for j in range 6]
for each_i in range(len(y)):
model.addConstr(z[i] == or_(x[i],y[i]))
Line 1 model.setObjective (LinExpr(coeff_x,x) +
Line 2 LinExpr(coeff_y,y) +
Line 3 LinExpr(coeff_z,z))
model.update()
model.optimize()
When I run this, the error is always at line 3 telling
"File "linexpr.pxi", line 62, in gurobipy.LinExpr.__init__ (../../src/python/gurobipy.c:27663)
TypeError: float() argument must be a string or a number "
This error does not happen always, quite random. For example if my n is set to 100, i get this error at i= 2 and sometimes at i = 65 etc. No real pattern.
What can be the source of error.??
Thanks in advance