Skip to main content

Can one change variable values in a gurobipy model object and see how this affects constraints?

Answered

Comments

1 comment

  • Simranjit Kaur
    Gurobi Staff Gurobi Staff

    Hi Lutz,

    You can fix a variable by setting its lower bound and upper bound to the same value and resolve the model.

    var.UB = my_value
    var.LB = my_value

    To see how these changes affect your constraints, you can check constraint attributes like Slack or Pi. Slack shows the difference between the left-hand side and the right-hand side of the constraint, indicating how close the constraint is to being binding. Pi represents the dual prices or shadow prices of the constraints, which can tell you how the objective value would improve if you slightly increased the right-hand side of the constraint.

    slack = constr.getAttr('Slack')
    pi = constr.getAttr('Pi')

    You may also find the following articles helpful:

    Best regards,
    Simran

    0

Please sign in to leave a comment.