Model Infeasible by solving multi-objective model
AnsweredHello,
I am solving a multi-objective model using the epsilon constrain method. but my code is not working. after using the epsilon method model become infeasible. is that possible to use epsilon constrain gurobi? can you check what is an issue in my code?
# max f1 = X1 <br>
# max f2 = 3 X1 + 4 X2 <br>
# st X1 <= 20 <br>
# X2 <= 40 <br>
# 5 X1 + 4 X2 <= 200 <br>
m = Model('power')
x1 = m.addVar(vtype=GRB.CONTINUOUS)
x2 = m.addVar(vtype=GRB.CONTINUOUS)
c1 = m.addConstr(x1<=20)
c2 = m.addConstr(x2<=40)
c3 = m.addConstr(5*x1+4*x2 <= 200)
f1 = m.addVar()
f2 = m.addVar()
c_f1 = m.addConstr(f1==x1)
c_f2 = m.addConstr(f2 == (3*x1)+(4*x2))
o_f1 = m.setObjective(f1,GRB.MAXIMIZE)
#o_f2 = m.setObjective(f2,GRB.MAXIMIZE)
m.update()
m.optimize()
apply epsilon constrain
f2_min = 60
f2_max = 184
e = 0 # parameter value initialize 0 and editable
C_epsilon = m.addConstr(f2 == e)
m.update()
m.optimize()
n = 4
step = int((f2_max - f2_min) / n)
steps = list(range(int(f2_min),int(f2_max),step)) + [f2_max]
x1_l = []
x2_l = []
for i in steps:
e = i
C_epsilon = m.addConstr(f2 == e)
m.optimize()
x1_l.append(x1) # add x1 variable value into list by each loop
x2_l.append(x2) # add x2 variable value into list by each loop
print(x1_l,x2_l)
what is wrong with my code.
for reference model explanation
-
Official comment
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?. -
Hi John,
By using
C_epsilon = m.addConstr(f2 == e)
in the \(\texttt{for}\)-loop, you are adding new constraints, instead of modifying the old one. What you are looking for is
C_epsilon.RHS = e
in the \(\texttt{for}\)-loop.
Please note that for LPs, there are possibly better ways to obtain the Pareto Front than using the \(\epsilon\)-method, e.g., Aneja & Nair 1979, Cohon 1978, Ehrgott 2000.
Best regards,
JaromiłBest regards,
Jaromił0 -
Hello Jaromił,
Thank you so much for your help and referances.
all referances you mention are not free so I need to find another way find that referances.I have one more question about the lower and upper bounds (f2_min,f2_max ). Here in my code I pre defined value.
Is there any simple way to find f2_min and f2_max in gurobi?
Here I submit code for argument e-constraint. that will help for others:# deactivate all objective
# remove C_epsilon = m.addConstr(f2 == e)
m.optimize()
x1_l = []
x2_l = []
e=0
delta = 0.00001
s = m.addVar(vtype=GRB.CONTINUOUS)
O_f1 = m.setObjective(f1+(delta*s), GRB.MAXIMIZE)
C_e = m.addConstr(f2-s == e)
for i in range(160,190,6):
e = i
C_e.RHS = e
m.optimize()
v=m.getVars()
x1_l.append(v[0].x)
x2_l.append(v[1].x)
plt.plot(x1_l,x2_l,'o-.');
plt.title('efficient Pareto-front');
plt.grid(True);Thank you
john Karippery1 -
Hi John,
Is there any simple way to find f2_min and f2_max in gurobi?
You can find the f2_min and f2_max values by minimizing and maximizing the underlying model and setting f2 as its objective. So basically change
o_f1 = m.setObjective(f1,GRB.MAXIMIZE)
to
o_f2 = m.setObjective(f2,GRB.MAXIMIZE)
m.optimize()
f2_max = m.ObjVal
o_f2 = m.setObjective(f2,GRB.MINIMIZE)
m.optimize()
f2_min = m.ObjValand then proceed with the rest of your code.
Best regards,
Jaromił0
Post is closed for comments.
Comments
4 comments