Skip to main content

check feasibility of an initial solution and get the constraint names that it violates.

Answered

Comments

5 comments

  • Riley Clement
    Gurobi Staff Gurobi Staff

    Hi Weihua,

    I tried to fix the variables' upper bound and lower bound so that the solution is exactly my initial solution.

    You are on the right track here.  When you call optimize() the problem will be declared infeasible.  You can then either compute an Irreducible Inconsistent Subsystem (IIS) or a relaxed model to help understand the why the model is infeasible.  Both these approaches are outlined here: How do I determine why my model is infeasible?

    Since you want all constraints that are violated, I'd recommend using the feasRelaxS() approach:

    m = gp.Model()
    ... # build your model
    ... # set lb and ub on variables to fix them to your solution
    m.feasRelaxS(2, False, False, True) # create the relaxation in-place
    m.optimize()

    # analyze results
    for v in m.getVars():
    if v.varName[:5] in ("ArtN_", "ArtP_"):
    print(v.varName, v.X)

    A more elaborate explanation of feasRelaxS can be found here: How do I change variable and/or constraint bounds to make an infeasible model feasible using feasRelax?

    I note that it may be possible you are a commercial customer.  If you are then you are welcome to open requests in the future, if you wish, through our Gurobi Help Center where we are able to respond faster.

    - Riley

    1
  • Weihua Zhang
    Gurobi-versary
    First Comment
    First Question

    Hi Riley,

    Thank you for your prompt response. I've managed to identify the violated constraints. May I confirm if these pertain to the initial solution or have they been updated subsequently?

    I appreciate your suggestion regarding the help center. I'll definitely refer to it for any future inquiries.

    Weihua

     



    0
  • Riley Clement
    Gurobi Staff Gurobi Staff

    Hi Weihua,

    In general, if you have fixed every variable in your model, by setting lower bounds equal to upper bounds, then the only solution you can have is your initial solution.  Now the third parameter in the feasRelaxS method is the vrelax parameter, which indicates whether variable bounds can be relaxed.  In the code snippet I posted the value for this parameter is False, meaning we won't allow the bounds to change and your initial solution remains the only one that can be possible.

    - Riley

    1
  • Weihua Zhang
    Gurobi-versary
    First Comment
    First Question

    Hi Riley,

    Thanks for the clarification. So the solution can violate the constraints of the model but not the bound of the variables, right? 

    Weihua

    0
  • Riley Clement
    Gurobi Staff Gurobi Staff

    Yes, that's correct, provided vrelax=False and crelax=True.  Since the original model is infeasible, the only way we can make it feasible is either to relax constraints or bounds.  When we relax all the constraints, the feasible region of the new problem consists of the bounds on the variables only, and from there we try to find a solution in this feasible region with the smallest possible violations of the original constraints.  In your case, when you fix lb = ub for all variables then the feasible region will consist of only one solution - your initial solution that you used to fix the bounds - and so solving the optimization on the resulting model will tell us which constraints are violated (and by how much).

    1

Please sign in to leave a comment.