Verify whether the given variables satisfy the constraints?
AnsweredAre there any api I can use to verify whether specific variables given by programmer satisfy the constraints? So that I can find wrong constrains write by myself.
Thank you
0
-
There is no particular single function to achieve that. However, you can fix all variables to a specific value and optimize the model. If the model is infeasible then, you can compute an IIS and write it to a file to see which of the constraints and fixed values cause the infeasibility. You can open the IIS file with any standard text editor.
A pseudo code would look something like
model = gp.Model()
# ...
# construct model as usual
# ...
# add equality constraints to fix variables to some values
fixedvalues = [...] # list of fixed values for variables you would like to check for feasiblity
vars = model.getVars()
for i in range(len(vars)):
model.addConstr(vars[i] == fixedvalues[i])
model.optimize()
if model.status == GRB.OPTIMAL:
print("Fixed point is feasible")
elif model.status == GRB.INFEASIBLE:
print("Fixed point is infeasible. Computing IIS")
model.computeIIS()
model.write("IIS.ilp")
print("IIS written to file IIS.ilp")Of course you can generate the fixing equality constraints in a different way.
Best regards,
Jaromił0
Please sign in to leave a comment.
Comments
1 comment