Skip to main content

Model Infeasible

Answered

Comments

5 comments

  • Alison Cozad
    Gurobi Staff Gurobi Staff

    It sounds like you are on the right track with computing the IIS to help point you in the direction of the constraints that may be causing the infeasibility.  Did you get any useful information from your model1.ilp file?

    Really, we typically recommend one of the following to find a subset of model constraints that is responsible for making the model infeasible:

    1. ComputeIIS.  This is a model diagnostic tool that computes a set of infeasible constraints and variable limits bounds that would be feasible if one of them were removed. This subset is known as an irreducibly inconsistent set (IIS).   To see this in action, check out Workforce1 and Workforce2 on the Gurobi Example page.
    2. Model.feasRelaxS() and Model.feasRelax(). These tools will relax the constraints and/or variable limits in your model then it will penalize the constraint and limit violations.  In doing so, it can highlight constraints and limits that may be most challenging to the original model feasibility.  To see this in action, check out Workforce3 on the Gurobi Example page.

    Both methods are aimed at narrowing down your search from the full constraint list to a smaller subset.  Once you have a subset of suspect constraints or variables limits, you can decide which to modify or relax to address the infeasibility in your original problem.

    To learn more, check out Diagnose and cope with infeasibility and  How do I determine why my model is infeasible?

    0
  • Eric Song
    Gurobi-versary
    First Comment
    First Question

    Thank you, Miss. Alison.  It is very kind of you to give so much help!

    According to model1.ilp, the problematic constraints are constr 1-3, which is naturally the case.

    Besides, I tried to make the parameters bigger( such as c_{i}), now, 2 of 4 models become feasible.

    I will test the code using Model.feasRelaxS() and Model.feasRelax() with your suggestion.

    Keep in touch!

    Regrads.

    0
  • Eric Song
    Gurobi-versary
    First Comment
    First Question

    Hi Miss.Alison. 

    Problem solved after using Model.feasRelaxS(). Thank you so much!

    One more question, would you please tell me how to view the modified model after using the function?

    Thank you so so much!

    Regards. 

    0
  • Alison Cozad
    Gurobi Staff Gurobi Staff

    There are a few ways you can view a model.  The quickest way is to write out the model file using model.write(<filename>).  If you use a .lp extension, you will write out an LP file.  I find this is more human-readable than the alternative MPS file.

    Alternatively, you can dump the variables and constraints into a dataframe.  Here is some example code to do this:

    import gurobipy as gp
    from gurobipy import GRB
    import pandas as pd

    m = gp.read('<your model filename>') # Or create your model here

    # Variable info
    varInfo = [(v.varName, v.LB, v.UB) for v in m.getVars() ] # use list comprehension
    df_var = pd.DataFrame(varInfo) # convert to pandas dataframe
    df_var.columns=['Variable Name','LB','UB'] # Add column headers
    print(df_var.head())

    # Linear constraint info
    constrInfo = [(c.constrName, m.getRow(c), c.Sense, c.RHS) for c in m.getConstrs() ]
    df_constr = pd.DataFrame(constrInfo)
    df_constr.columns=['Constraint Name','Constraint equation', 'Sense','RHS']
    print(df_constr.head())

    For more details about model, variable, and constraint attributes and methods, please refer to the Gurobi Python API Details.
    0
  • Eric Song
    Gurobi-versary
    First Comment
    First Question

    Hi Miss. Alison,

    Thank you so much! I'll try out this method.

    Have a good day!

     

    Regards.

    0

Please sign in to leave a comment.