Model is infeasible
AnsweredHello, my program is currently not feasible. I found the restrictions on the problem by checking, but I don’t know why this restriction has a problem, and I don’t know how to modify it.
model.addConstr(TripleFront_b_1_1 == dist12+l1-l2)
In this limitation condition, the first item is defined in the front, there is continuous variable with no upper and lower limit, and the latter items are fixed values, just as I displayed in my code.
l1 = 70
l2 = 70
dist12 = model.addVar(vtype=gp.GRB.CONTINUOUS)
TripleFront_b_1_1 = model.addVar(vtype=gp.GRB.CONTINUOUS)
"dist12" is used in the previous code, and it has been verified that it can find its minimum value. So I want to know if it is the two fixed values of l1 and l2 affect the code. Looking forward to your reply.
-
Hi,
- Your variables \(\texttt{dist12}\) and \(\texttt{TripleFront_b_1_1}\) have the default lower bound of 0 and the default upper bound of infinity (see the method Model.addVar() documentation).
- Given the values of variables \(\texttt{l1}\) and \(\texttt{l2}\) are equal, your constraint reduces to \(\texttt{TripleFront_b_1_1} = \texttt{dist12}\).
- There is no further information in your post to figure out where the issue is. Please have a look at the article How do I determine why my model is infeasible? for next steps. Specifically, you can use the method model.computeIIS() to find a set of constraints/bounds that is still infeasible if isolated from the rest of the model. This set can potentially shed light on what the conflicting constraints/bound are.
Best regards,
Maliheh
0 -
Hello, thank you for your reply. I found that there are restrictions that cause my continuous variables to exceed the defined minimum value. I want to know how to modify the definition so that the minimum value of a continuous variable is negative infinity. Looking forward to your reply.
0 -
Hi,
Let's take variable \(\texttt{dist12}\) as an example. You can modify its lower bound either in the definition, by doing
dist12 = model.addVar(vtype=gp.GRB.CONTINUOUS, lb=-gp.GRB.INFINITY)
or later in the code using the Var.setAttr() method, by doing
dist12.setAttr("lb", -gp.GRB.INFINITY)Best regards,
Elisabeth
0 -
Thank you for your reply. I have modified the definition range of my continuous variables, but still have not solved the problem of the model being infeasible.
At present, the main problem lies in model. addConstr (TripleFront_b_1_3==l1+l2-dist12).
model.addConstr(TripleFront_b_1_3 == l1+l2-dist12)
When I add this constraint, the model becomes infeasible. After I remove this constraint, the model becomes feasible.As I previously asked, I initially thought it was beyond the scope of variable definition, but it was not resolved after modification.
If possible, please help me identify the problem. Looking forward to your reply.
Here is my code.
# -*- coding: utf-8 -*-
"""
Created on Wed Jul 5 13:31:01 2023
@author: jack
"""
import gurobipy as gp
from gurobipy import GRB
import numpy as np
import math
#
model = gp.Model()
#
model.setParam('NonConvex', 2)
#
x1 = model.addVar(lb=25.5,ub=115.5, vtype=gp.GRB.CONTINUOUS, name="x1")
y1 = model.addVar(lb=251.5,ub=413.5, vtype=gp.GRB.CONTINUOUS, name="y1")
x2 = model.addVar(lb=0, vtype=gp.GRB.CONTINUOUS, name="x2")
y2 = model.addVar(lb=115.5,ub=184.5, vtype=gp.GRB.CONTINUOUS, name="y2")
x3 = model.addVar(lb=178.5,ub=193.5, vtype=gp.GRB.CONTINUOUS, name="x3")
y3 = model.addVar(lb=0, vtype=gp.GRB.CONTINUOUS, name="y3")
#
dist12 = model.addVar(vtype=gp.GRB.CONTINUOUS)
dist13 = model.addVar(vtype=gp.GRB.CONTINUOUS)
dist23 = model.addVar(vtype=gp.GRB.CONTINUOUS)
#
dis12 = model.addVar(vtype=gp.GRB.CONTINUOUS)
dis13 = model.addVar(vtype=gp.GRB.CONTINUOUS)
dis23 = model.addVar(vtype=gp.GRB.CONTINUOUS)
l1 = 70
l2 = 70
l3 = 60
#
TripleFront_a = model.addVar(vtype=gp.GRB.CONTINUOUS)
TripleFront_b = model.addVar(vtype=gp.GRB.CONTINUOUS)
TripleFront_c = model.addVar(vtype=gp.GRB.CONTINUOUS)
TripleFront_d = model.addVar(vtype=gp.GRB.CONTINUOUS)
#
TripleFront_a_1 = model.addVar(vtype=gp.GRB.CONTINUOUS)
TripleFront_a_1_1 = model.addVar(vtype=gp.GRB.CONTINUOUS)
TripleFront_a_1_2 = model.addVar(vtype=gp.GRB.CONTINUOUS)
TripleFront_a_1_3 = model.addVar(vtype=gp.GRB.CONTINUOUS)
TripleFront_a_1_4 = model.addVar(vtype=gp.GRB.CONTINUOUS)
TripleFront_a_2 = model.addVar(vtype=gp.GRB.CONTINUOUS)
TripleFront_a_3 = model.addVar(vtype=gp.GRB.CONTINUOUS)
TripleFront_a_4 = model.addVar(vtype=gp.GRB.CONTINUOUS)
#
TripleFront_a_12 = model.addVar(vtype=gp.GRB.CONTINUOUS)
TripleFront_a_34 = model.addVar(vtype=gp.GRB.CONTINUOUS)
#
TripleFront_b_1 = model.addVar(vtype=gp.GRB.CONTINUOUS)
TripleFront_b_2 = model.addVar(vtype=gp.GRB.CONTINUOUS)
TripleFront_b_3 = model.addVar(vtype=gp.GRB.CONTINUOUS)
TripleFront_b_4 = model.addVar(vtype=gp.GRB.CONTINUOUS)
#
TripleFront_b_1_1 = model.addVar(vtype=gp.GRB.CONTINUOUS)
TripleFront_b_1_2 = model.addVar(vtype=gp.GRB.CONTINUOUS)
TripleFront_b_1_3 = model.addVar(vtype=gp.GRB.CONTINUOUS, lb=-gp.GRB.INFINITY)
TripleFront_b_1_4 = model.addVar(vtype=gp.GRB.CONTINUOUS)
#
TripleFront_abcd = model.addVar(vtype=GRB.CONTINUOUS)
x1.start = 79.5
y1.start = 348.7
y2.start = 178.5
x3.start = 190.5
model.addConstr(y1 == 1.8*x1+205.6)
model.addConstr(x2 == 181.5)
model.addConstr(y3 == 262.5)
model.addConstr(dis12 == (x2 - x1) ** 2 + (y2 - y1) ** 2)
model.addConstr(dis13 == (x3 - x1) ** 2 + (y3 - y1) ** 2)
model.addConstr(dis23 == (x2 - x3) ** 2 + (y2 - y3) ** 2)
model.addConstr(dis12 == dist12*dist12)
model.addConstr(dis13 == dist13*dist13)
model.addConstr(dis23 == dist23*dist23)
model.addConstr(TripleFront_a_1_1 == dist12+dist23-dist13)
model.addConstr(TripleFront_a_1_2 == dist12-dist23+dist13)
model.addConstr(TripleFront_a_1_3 == -dist12+dist23+dist13)
model.addConstr(TripleFront_a_1_4 == dist12+dist23+dist13)
model.addConstr(TripleFront_a_1_1 == TripleFront_a_1*TripleFront_a_1)
model.addConstr(TripleFront_a_1_2 == TripleFront_a_2*TripleFront_a_2)
model.addConstr(TripleFront_a_1_3 == TripleFront_a_3*TripleFront_a_3)
model.addConstr(TripleFront_a_1_4 == TripleFront_a_4*TripleFront_a_4)
#
model.addConstr(TripleFront_a_12 == TripleFront_a_1*TripleFront_a_2)
model.addConstr(TripleFront_a_34 == TripleFront_a_3*TripleFront_a_4)
#
model.addConstr(TripleFront_b_1_1 == dist12+l1-l2)
model.addConstr(TripleFront_b_1_2 == dist12-l1+l2)
model.addConstr(TripleFront_b_1_3 == l1+l2-dist12)
model.addConstr(TripleFront_b_1_4 == dist12+l1+l2)
#
model.addConstr(TripleFront_abcd == TripleFront_b_1_2)
#
model.update()
model.setObjective(TripleFront_abcd, sense=gp.GRB.MINIMIZE)
#
model.optimize()
#
if model.status == GRB.OPTIMAL:
print("Optimal Solution:")
print("x1 =", x1.x)
print("y1 =", y1.x)
print("x2 =", x2.x)
print("y2 =", y2.x)
print("x3 =", x3.x)
print("y3 =", y3.x)
print("TripleFront_abcd:", TripleFront_abcd.x)
else:
print("No solution found.")0 -
The script attached includes the problematic constraint you mentioned but it solves to optimality. It prints:
Optimal Solution:
x1 = 33.849056615523516
y1 = 266.5283019079423
x2 = 181.5
y2 = 184.49999999662015
x3 = 186.4501401613281
y3 = 262.5
TripleFront_abcd: 168.90661146556963I am not sure where the issue is. Does the above script solve to infeasibility on your machine? Which Gurobi version are you using?
In your current script, the decision variable \(\texttt{TripleFront_b_1_3}\) is defined as a free variable:
TripleFront_b_1_3 = model.addVar(vtype=gp.GRB.CONTINUOUS, lb=-gp.GRB.INFINITY)
If you change the definition of this variable to be non-negative as below, the model is then infeasible.TripleFront_b_1_3 = model.addVar(vtype=gp.GRB.CONTINUOUS)
So, modifying the lower bound of the variable \(\texttt{TripleFront_b_1_3}\) seems to take care of the infeasibility.Best regards,Maliheh0 -
Thank you, Maliheh. The above code is still not feasible on my computer. My Gurobi is version 9.1.0. At present, it may be a version issue. I will upgrade my Gurobi version later. Here are the results of my code run.
Using license file c:\gurobi\gurobi.lic
Changed value of parameter NonConvex to 2
Prev: -1 Min: -1 Max: 2 Default: -1
Gurobi Optimizer version 9.1.0 build v9.1.0rc0 (win64)
Thread count: 8 physical cores, 16 logical processors, using up to 16 threads
Optimize a model with 12 rows, 116 columns and 30 nonzeros
Model fingerprint: 0x06396f7a
Model has 12 quadratic constraints
Coefficient statistics:
Matrix range [1e+00, 2e+00]
QMatrix range [1e+00, 2e+00]
QLMatrix range [1e+00, 1e+00]
Objective range [1e+00, 1e+00]
Bounds range [3e+01, 4e+02]
RHS range [1e+02, 3e+02]
Presolve removed 7 rows and 96 columns
Continuous model is non-convex -- solving as a MIP.
User MIP start did not produce a new incumbent solution
Presolve removed 7 rows and 96 columns
Presolve time: 0.00s
Presolved: 57 rows, 26 columns, 134 nonzeros
Presolved model has 15 bilinear constraint(s)
Variable types: 26 continuous, 0 integer (0 binary)
Root relaxation: infeasible, 13 iterations, 0.00 seconds
Nodes | Current Node | Objective Bounds | Work
Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time
0 0 infeasible 0 - infeasible - - 0s
Explored 0 nodes (13 simplex iterations) in 0.03 seconds
Thread count was 16 (of 16 available processors)
Solution count 0
Model is infeasible
Best objective -, best bound -, gap -
No solution found.0 -
Hello Maliheh, I have upgraded my Gurobi to 10.0.2. Currently, when the constraint is
model. addConstr (TripleFront_abcd==TripleFront_b1_2)
the code is feasible, but when it is changed to
model. addConstr (TripleFront_abcd==TripleFront_b1_3)
the code is not feasible.The code run results are as follows.
Set parameter NonConvex to value 2
Gurobi Optimizer version 10.0.2 build v10.0.2rc0 (win64)
CPU model: Intel(R) Core(TM) i9-9900K CPU @ 3.60GHz, instruction set [SSE2|AVX|AVX2]
Thread count: 8 physical cores, 16 logical processors, using up to 16 threads
Optimize a model with 12 rows, 35 columns and 30 nonzeros
Model fingerprint: 0x91b22187
Model has 12 quadratic constraints
Coefficient statistics:
Matrix range [1e+00, 2e+00]
QMatrix range [1e+00, 2e+00]
QLMatrix range [1e+00, 1e+00]
Objective range [1e+00, 1e+00]
Bounds range [3e+01, 4e+02]
RHS range [1e+02, 3e+02]
Presolve removed 7 rows and 15 columns
Continuous model is non-convex -- solving as a MIP
User MIP start did not produce a new incumbent solution
Presolve removed 7 rows and 15 columns
Presolve time: 0.00s
Presolved: 57 rows, 26 columns, 134 nonzeros
Presolved model has 15 bilinear constraint(s)
Variable types: 26 continuous, 0 integer (0 binary)
Root relaxation: infeasible, 16 iterations, 0.00 seconds (0.00 work units)
Nodes | Current Node | Objective Bounds | Work
Expl Unexpl | Obj Depth IntInf | Incumbent BestBd Gap | It/Node Time
0 0 infeasible 0 - infeasible - - 0s
Explored 1 nodes (16 simplex iterations) in 0.01 seconds (0.00 work units)
Thread count was 16 (of 16 available processors)
Solution count 0
Model is infeasible
Best objective -, best bound -, gap -
No solution found.According to the previous code, the two are
model.addConstr(TripleFront_b_1_2 == dist12-l1+l2)
model.addConstr(TripleFront_b_1_3 == l1+l2-dist12)I want to know why the code is feasible when solving “TripleFront_b_1_2”, but not when solving “TripleFront_b_1_3” and how to solve it.
0 -
Your model is feasible if the variable \(\texttt{TripleFront_b_1_3}\) takes negative values. Since the variable \(\texttt{TripleFront_abcd}\) is defined to only take non-negative values, adding the constraint below makes the model infeasible:
model.addConstr(TripleFront_abcd==TripleFront_b1_3)
In case you would like the model to be feasible, you would need to also allow the variable \(\texttt{TripleFront_abcd}\) to take negative values by setting its lower bound to -infinity.
0 -
Thank you, Maliheh. My problem has been resolved.
0
Please sign in to leave a comment.
Comments
9 comments