difference between python gurobi and AMPL gurobi
回答済みI have a minimization model as follow :
\ LP format - for model browsing. Use MPS format to capture full model detail.
Minimize
Z + 0 y6 + 0 y17 + 0 y25 + 0 y32 + 0 y37
Subject To
cut1: - Z - y1 - 3.5 y2 - 2.5 y3 - 4 y4 - y5 - 2 y7 - 1.5 y8 - 2 y9
- 0.5 y10 - 4.5 y11 - 2 y12 - 3.5 y13 - 4 y14 - 2 y15 - 2.5 y16 - 2 y18
- 5 y19 - 5.5 y20 - 4 y21 - 1.5 y22 - y23 - 6.5 y24 - 2 y26 - 2 y27
- 0.5 y28 - 8 y29 - 2.5 y30 - y31 - 4.5 y33 - 4 y34 - 4 y35 - 0.5 y36
<= 0
Bounds
y1 <= 1
y2 <= 1
y3 <= 1
y4 <= 1
y5 <= 1
y6 <= 1
y7 <= 1
y8 <= 1
y9 <= 1
y10 <= 1
y11 <= 1
y12 <= 1
y13 <= 1
y14 <= 1
y15 <= 1
y16 <= 1
y17 <= 1
y18 <= 1
y19 <= 1
y20 <= 1
y21 <= 1
y22 <= 1
y23 <= 1
y24 <= 1
y25 <= 1
y26 <= 1
y27 <= 1
y28 <= 1
y29 <= 1
y30 <= 1
y31 <= 1
y32 <= 1
y33 <= 1
y34 <= 1
y35 <= 1
y36 <= 1
y37 <= 1
End
the Z is unrestricted variable , while 0<= y <=1
if I optimize this model on python by using gurobipy package :
MP_model.optimize ()
the objective is 0, while the same model on AMPL is giving -91 as objective ??!!
-
正式なコメント
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?. -
When reading LP files, Gurobi assumes variables have a lower bound of zero unless otherwise specified. If \( \texttt{Z} \) were unbounded, the LP file would contain the line
Z free
in the \( \texttt{Bounds} \) section. The LP file contains no such line, so Gurobi interprets the lower bound of \( \texttt{Z} \) to be \( 0 \):
>>> import gurobipy as gp
>>> m = gp.read('model.lp')
Using license file /Users/towle/gurobi.lic
Read LP format model from file model.lp
Reading time = 0.00 seconds
: 1 rows, 38 columns, 33 nonzeros
>>> m.getVarByName('Z').LB
0.0If \( \texttt{Z} \) were unbounded, then \( -91 \) is the correct optimal objective value:
>>> m.getVarByName('Z').LB = -gp.GRB.INFINITY
>>> m.optimize()
Gurobi Optimizer version 9.1.2 build v9.1.2rc0 (mac64)
Thread count: 2 physical cores, 4 logical processors, using up to 4 threads
Optimize a model with 1 rows, 38 columns and 33 nonzeros
Model fingerprint: 0xddb989e0
Coefficient statistics:
Matrix range [5e-01, 8e+00]
Objective range [1e+00, 1e+00]
Bounds range [1e+00, 1e+00]
RHS range [0e+00, 0e+00]
Presolve removed 1 rows and 38 columns
Presolve time: 0.02s
Presolve: All rows and columns removed
Iteration Objective Primal Inf. Dual Inf. Time
0 -9.1000000e+01 0.000000e+00 0.000000e+00 0s
Solved in 0 iterations and 0.03 seconds
Optimal objective -9.100000000e+01If you built this model using the gurobipy package, you did not correctly define \( \texttt{Z} \) to be an unbounded variable. By default, variables added to a model using Model.addVar() or Model.addVars() have a lower bound of \( 0 \). To add an unbounded variable, set its lower bound to \( \texttt{-GRB.INFINITY} \):
z = MP_model.addVar(lb=-gp.GRB.INFINITY, name='Z')
1
投稿コメントは受け付けていません。
コメント
2件のコメント