How does ==
work in Gurobi Python?
After I have created the needed variables (x[s,d,r]
), I'm trying to make an if
statement like x[s,d,r] == 1
. The problem is, that this statement is always true so it does not matter if I set it to x[s,d,r]==0
or x[s,d,r]==2
, it is always the same.
x[s,d,r]
is a binary variable defined by x[s,d,r] = m.addVar(0.0,1.0,1.0,GRB.BINARY,"x_"+ s+"_"+ d +"_" + r)
.
z = 0.0
for s in students:
for d in dates:
if (s,d) in preferences:
if preferences[s,d]!=0:
for r in rooms:
if (d,r) in tutorials:
if x[s,d,r]>0.001:
print('%s:%s:%s:%s '%(s,d,r,preferences[s,d]))
z = z + preferences[s,d]
else:
print('no')
m.setObjective((z), GRB.MAXIMIZE)
So if x[s,d,r]>0.001: is the part that always evaluates to "true".
Aucun commentaire:
Enregistrer un commentaire