How to represent the sum of binary variables ?
AnsweredI am solving a SMT problem with gurobi.

Some restrictions are listed below.







I represent them with the following code.
##con4
for i in range(self.in1.i):
constraint_scheduling += [
quicksum(x[i,d,t] * self.in1.l_t[t] for d in range(self.in1.d) for t in range(self.in1.t)) <=
self.in1.b_max[i]]
constraint_scheduling += [
quicksum(x[i,d,t] * self.in1.l_t[t] for d in range(self.in1.d) for t in range(self.in1.t)) >=
self.in1.b_min[i]]##con6
for i in range(self.in1.i):
for s in range(1, self.in1.c_min[i]):
for d in range(self.in1.d - s - 1):
constraint_scheduling += [quicksum(x[i,d,t] for t in range(self.in1.t))
+ s - quicksum(x[i,j,t] for j in range(d + 1, d + s + 1) for t in range(self.in1.t))
+ quicksum((x[i,d + s + 1,t] for t in range(self.in1.t))) >= 1]Are those correct?
-
Hi,
This looks sort of correct to me.
You are creating TempConstr objects and then adding them to some constraint_scheduling object. Generally you would add use addConstr( ) to add these TempConstr objects to the model.
I guess it is possible you have created a constraint_scheduling object where the add operator appends these TempConstr to a list, and these TempConstr are added to the model later, but it seems more likely that a LLM has given you code that is a mixture of gurobipy and some other 3rd party framework.
- Riley
0 -
Thank you,I have already found out where the problem lies.
0
Please sign in to leave a comment.
Comments
2 comments