Behavior changing when adding intermediate variables
Awaiting user inputHi, I am working with Gurobi 9.12 for a jupyter notebook, and in it, I have a constraint
m.addConstr(1800-t_c[l]+t_c[i]<=M*(1-O[l,j]*O[i,j]))
Where t_c[l] and t_c[i] are continuous variables and O[l,j] and O[i,j] are binary variables, and my program runs fine and gives good and reasonable solutions, but when I introduce an intermediate variable to replace O[l,j]*O[i,j] since I am working to remove quadratic constraints, like the following:
tempvar1 = m.addVar(vtype = GRB.BINARY)
m.addConstr(tempvar1 == O[l,j]*O[i,j])#Just for testing
m.addConstr(1800-t_c[l]+t_c[i]<=M*(1-tempvar1))
The program is suddenly infeasible. There are no other constraints on tempvar1 or t_c, and the only other constraint on O is
print('Only look at 1 item at a time')
for i in range(len(O)):
m.addConstr(np.sum(O[i])==1)
Does anyone have any advice about why adding this intermediate variable might change the behavior of the optimizer and what I can do to prevent it from happening?
Solved it! It looks like the fact that it was working was actually a bug, when i=l, the constraint collapses to something infeasible, which for some reason wasn't catching in the compiler in the original statement
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Can you please post a complete minimal working example that includes the definitions of \( \texttt{O} \), \( \texttt{t_c} \), and \( \texttt{M} \)?
0
Post is closed for comments.
Comments
2 comments