How do I know which constraint is reaching its limit first?
AnsweredDear all.
I am working in an optimization model which computes the maximum power injection that can be incorporated into an electrical network, in general, the model is working I am getting reasonable results so far, However, I am struggling to identify the constraint that is limiting my objective function.
I would like to ask you if you know a way to export the internal report of the solver in a way that I can which is the constraint who is reaching its limits first.
Thank you for your time.
-
Hi Sandra,
The Slack attribute can tell you which constraint is active at the current solution. After an optimization run is finished and a feasible point has been found, you can check whether the slack of a linear constraint is almost \(0\)
for c in model.getConstrs():
if c.Slack < 1e-6:
print('Constraint %s is active at solution point' % (c.ConstrName))Note that equality constraints are always active. For quadratic constraints, you can get the slack via the QCSlack attribute.
EDIT: Fixed sign from ">" to "<".
Best regards,
Jaromił0 -
Dear Jaromil.
Thank you for your answer; I would like to point out that I am working in Matlab, using YALMIP, and Gurobi is my solver. Do you have any guide or suggestion to implement this code in Matlab?
Thank you again.
0 -
Dear Sandra,
Attributes are not supported in the MATLAB API. To get the information you seek, you have to compute the value of your constraints at the solution point after an optimal optimization run by hand, i.e., multiply each coefficient with the corresponding variable and check vs the respective right hand side.
Best regards,
Jaromił0 -
Can we get active variables just like active constraint's where slack is 0. For Decision variables if we keep upper and lower bound where I am not writing any constraintsSince equality constraints are always active, so is there a way to skip those while doing for loop in model.getConstrs()
0 -
Can we get active variables just like active constraint's where slack is 0. For Decision variables if we keep upper and lower bound where I am not writing any constraints
Since equality constraints are always active, so is there a way to skip those while doing for loop in model.getConstrs()
I am not sure I understand your question. Since you mention \(\texttt{model.getConstrs()}\), I assume that you are using the Python API. In this case, you can access all attributes as described in the documentation.
0
Please sign in to leave a comment.
Comments
5 comments