The model is unbounded, why can I get the value of the variable?
回答済みThis is the information obtained
Set parameter DualReductions to value 0
Set parameter InfUnbdInfo to value 1
Gurobi Optimizer version 9.5.1 build v9.5.1rc2 (win64)
Thread count: 4 physical cores, 8 logical processors, using up to 8 threads
Optimize a model with 5 rows, 25 columns and 47 nonzeros
Model fingerprint: 0x0a300c02
Variable types: 22 continuous, 3 integer (3 binary)
Coefficient statistics:
Matrix range [3e-01, 5e+00]
Objective range [8e-01, 1e+00]
Bounds range [1e+00, 1e+00]
RHS range [5e+00, 5e+00]
Found heuristic solution: objective 2.550000e+09
Presolve time: 0.00s
Presolved: 5 rows, 25 columns, 47 nonzeros
Variable types: 22 continuous, 3 integer (3 binary)
Root relaxation: unbounded, 2 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 postponed 0 2.5500e+09 - - - 0s
Explored 1 nodes (2 simplex iterations) in 0.00 seconds (0.00 work units)
Thread count was 8 (of 8 available processors)
Solution count 1: 2.55e+09
Model is unbounded
Best objective 2.550000003375e+09, best bound -, gap -
Obj: 2550000003.375
delta:-13800000000.0
b_0:0.0
psi_0:-14199999995.5
b_1:0.0
psi_1:2000000000.0
b_2:0.0
psi_2:2000000000.0
q_0_0:2000000000.0
x_0_0:0.0
gamma_0_0:2000000000.0
q_1_0:2000000000.0
x_1_0:0.0
gamma_1_0:2000000000.0
q_2_0:2000000000.0
x_2_0:0.0
gamma_2_0:2000000000.0
eta_0_0:2000000000.0
eta_0_1:2000000000.0
eta_0_2:2000000000.0
eta_1_0:2000000000.0
eta_1_1:2000000000.0
eta_1_2:2000000000.0
eta_2_0:2000000000.0
eta_2_1:2000000000.0
eta_2_2:2000000000.0
Optimization was stopped with status 5
None
-
正式なコメント
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 try Gurobot, our chatbot interface offering instant, expert-level support. -
Thank you very much for your answer.
When I run this part of the code, I can get the value of the variable, like mentioned above
print("Obj:", m1.objVal)
for w in m1.getVars():
print(f"{w.varName}:{round(w.x, 3)}")But when I run this part of the code, it shows that the model is unbounded and does not produce the values of the variables.
if m1.status == GRB.status.OPTIMAL:
t1 = m1.runtime
t_MP.append(t1)
delta_sol = []
delta_sol.append(m1.getVarByName('delta').x)
b_sol = []
q_sol = []
x_sol = []
gamma_sol = []
eta_sol = []
psi_sol = []
for i in I:
b_sol.append(m1.getVarByName('b_%s' % i).x)
psi_sol.append(m1.getVarByName('psi_%s' % i).x)
for i in I:
q_sol.append([])
x_sol.append([])
gamma_sol.append([])
for t in T:
q_sol[i].append(m1.getVarByName('q_%s_%s' % (i, t)).x)
x_sol[i].append(m1.getVarByName('x_%s_%s' % (i, t)).x)
gamma_sol[i].append(m1.getVarByName('gamma_%s_%s' % (i, t)).x)
for i in I:
eta_sol.append([])
for j in I:
eta_sol[i].append(m1.getVarByName('eta_%s_%s' % (i, j)).x)
print(t1, t_MP, b_sol, q_sol, x_sol, gamma_sol, psi_sol, delta_sol, eta_sol)
else:
print('Optimization was stopped with status %d' % m1.status)0 -
In this part
print("Obj:", m1.objVal)
for w in m1.getVars():
print(f"{w.varName}:{round(w.x, 3)}")you don't check the status of your model. However, you are lucky, because Gurobi finds a feasible solution before declaring the model as unbounded. Thus you can print the solution point values of the last feasible solution found.
In your second code snippet, you check whether the model status is OPTIMAL. However, the model status is not OPTIMAL, thus you jump into the \(\texttt{else}\) case and only get the printed message.
If you want to always print the solution point values when a solution point is available independent of the model status, you can check the SolCount attribute
if m1.SolCount > 0:
# print solutionBest regards,
Jaromił0 -
Hi, Jaromił
The model is unbounded, can the attribute 'x' be used in the first part of the code above? Isn't the attribute 'x' only available in the optimal status?
0 -
HI Xiaona,
The attribute X can be retrieved whenever Gurobi finds a feasible solution. In your case, Gurobi finds a feasible solution before declaring the model as unbounded. Thus, the X attribute is available although the model is declared as unbounded. When your model is declared as unbounded, then the solution point values probably don't have any meaning for your application but nevertheless, you can query them.
Best regards,
Jaromił0 -
Hi, Jaromił,
Thank you very much for your answer, which is helpful to me. I think I should change the unbounded status of the model.
0
投稿コメントは受け付けていません。
コメント
6件のコメント