Skip to main content

difference between python gurobi and AMPL gurobi

Answered

Comments

2 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

    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.0

    If \( \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+01

    If 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

Post is closed for comments.