Skip to main content

Model is infeasible or unbounded

Answered

Comments

5 comments

  • Official comment
    Simranjit Kaur
    • Gurobi Staff
    This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?.
  • Eli Towle
    • Gurobi Staff

    Hi William,

    You can write a model to the human-readable LP (.lp) format with the Model.write() method. It looks like you are computing an IIS; you can also write an ILP (.ilp) file to determine which subsystem of constraints is infeasible (in your case, it is a single constraint). Both of these are more helpful if you name your variables and constraints.

    I suspect the issue is with the generateOperatingSystemsCountVars() function that you define. It returns a list of lists, each element of which is zero. Thus, when you add your Equation 4 constraints using operatingSystemsVars, the LHSs all evaluate to zero:

    # The following are all equivalent (Equation 4)
    model.addConstr((quicksum(U[m[0]][t] * operatingSystemsVars[m[0]-1][t] for m in M if t >= m[1])) >= D[t])
    model.addConstr(quicksum(U[m[0]][t] * 0 for m in M if t >= m[1]) >= D[t])
    model.addConstr(0 >= D[t])

    If the RHS is positive, this constraint is infeasible. Also, note that the Equation 4 constraints do not include any of the X or Y model variables.

    Eli

    1
  • William Praat
    • Gurobi-versary
    • First Comment
    • First Question

    Eli Towle Thank you for your reply.

    Thank you for explaining what is going wrong. However, does this also mean that it is not possible to let Gurobi change the value of for example K(t) or operatingSystemsVars. I guess it is technically possible by adding them as vars to the model but to me this does not seem logical as they are not decision variables in the original mathematical model.

     

    William

    Update:

    I've made a very basic version of the model and did a test with it and it does find a solution. However, this is not how I expected it to go. I did the test with the following code and with T = 10 for now:

    purchaseDecisionVars = generatePurchaseDecisionVars(T, M)
    salvageDecisionVars = generateSalvageDecisionVars(T, M)

    model = Model("HydrogenSystemOptimization")


    X = model.addVars(purchaseDecisionVars, lb=0, vtype=GRB.INTEGER, name="systems purchases: ")
    Y = model.addVars(salvageDecisionVars, lb=0, vtype=GRB.INTEGER, name="systems salvaged: ")

    for t in range(T):
    for m in M:
    print("T= ", t, " m[0]: ", m[1])
    model.addConstr(quicksum(X[m[0],i] - Y[m[0],i] for i in range(t) if i >= m[1]) >= 0, name="non-zero")

    model.setObjective((quicksum((quicksum(A * X[m[0],t] - L * Y[m[0],t] for t in range(T) if t >= m[1])) for m in M)), GRB.MINIMIZE)

     

     

    This is the result:

    systems purchases: [0,0] -0
    systems purchases: [0,1] -0
    systems purchases: [0,2] -0
    systems purchases: [0,3] -0
    systems purchases: [0,4] -0
    systems purchases: [0,5] -0
    systems purchases: [0,6] -0
    systems purchases: [0,7] -0
    systems purchases: [0,8] -0
    systems purchases: [0,9] -0
    systems purchases: [1,4] -0
    systems purchases: [1,5] -0
    systems purchases: [1,6] -0
    systems purchases: [1,7] -0
    systems purchases: [1,8] -0
    systems purchases: [1,9] -0
    systems purchases: [2,8] -0
    systems purchases: [2,9] -0
    systems salvaged: [0,0] -0
    systems salvaged: [0,1] -0
    systems salvaged: [0,2] -0
    systems salvaged: [0,3] -0
    systems salvaged: [0,4] -0
    systems salvaged: [0,5] -0
    systems salvaged: [0,6] -0
    systems salvaged: [0,7] -0
    systems salvaged: [0,8] -0
    systems salvaged: [0,9] 1e+30
    systems salvaged: [1,4] -0
    systems salvaged: [1,5] -0
    systems salvaged: [1,6] -0
    systems salvaged: [1,7] -0
    systems salvaged: [1,8] -0
    systems salvaged: [1,9] 1e+30
    systems salvaged: [2,8] -0
    systems salvaged: [2,9] 1e+30
    Obj: total costs: -1.5e+33

     

    So for some reason the constraint I added does not work for the last t but I don't understand why. Also interesting, if I change the non-zero constraint from 0 to 1 (simulating some demand) it cannot find a solution.

    0
  • Eli Towle
    • Gurobi Staff

    Hi William,

    Gurobi searches for an optimal assignment of values to the model variables. If the elements of operatingSystemsVars aren't model variables, then they are fixed constants/coefficients that will not be changed by Gurobi.

    Have you written out an LP file to inspect the model visually? With this code, a lot of your "non-zero" constraints are \( 0 \geq 0 \). Changing the RHS to 1 will result in a constraint that is never satisfied, and thus an infeasible model. Note that every constraint should include a variable. If this isn't the case, you end up with a constraint that is always false (so the model is automatically infeasible), or a constraint that is always true (meaning the constraint doesn't affect the feasible region).

    For t=9, you add constraints for every i in range(t). However, range(9) is the numbers 0 through 8. Thus, "systems salvaged" variables with a second index of t=9 do not appear in any constraints. Perhaps you should be using range(t+1) in the quicksum() function of the "non-zero" constraints?

    Eli

     

    1
  • William Praat
    • Gurobi-versary
    • First Comment
    • First Question

    Dear Eli,

    Thank you for this clarification. Your description gave me a much better understanding of how Gurobi works and I was able to get my model working. There were some more issues I had to resolve but I got my model working as intended and it is generating results that make sense.

    Especially the LP file helped me to find the problems, thank you for pointing that out.

    Again, thank you for the support!

    William

    0

Post is closed for comments.