Problems solving simple examples with Gurobi

583 views
Skip to first unread message

john...@gmail.com

unread,
Jul 31, 2016, 5:28:06 PM7/31/16
to Pyomo Forum
Hey!
I am completely new to Pyomo. I installed Gurobi-Solvers and tried to run some simple examples from the pyomo-guide. I work with Spyder (Anakonda2 64bit) - I always get the same output - here an example:

from __future__ import division
from pyomo.environ import *

model
= ConcreteModel()

model
.x = Var([1,2], domain=NonNegativeReals)

model
.OBJ = Objective(expr = 2*model.x[1] + 3*model.x[2])

model
.Constraint1 = Constraint(expr = 3*model.x[1] + 4*model.x[2] >= 1)


opt
= SolverFactory("gurobi")
instance
= model.create_instance()
results
= opt.solve(instance)
results
.write()

Result on screen:

==========================================================
# = Solver Results                                         =
# ==========================================================
# ----------------------------------------------------------
#   Problem Information
# ----------------------------------------------------------
Problem:
- Name:
 
Lower bound: 0.666666666667
 
Upper bound: 0.666666666667
 
Number of objectives: 1
 
Number of constraints: 2
 
Number of variables: 3
 
Number of binary variables: 0
 
Number of integer variables: 0
 
Number of continuous variables: 3
 
Number of nonzeros: 3
 
Sense: minimize
# ----------------------------------------------------------
#   Solver Information
# ----------------------------------------------------------
Solver:
- Status: ok
 
Return code: 0
 
Message: Model was solved to optimality (subject to tolerances), and an optimal solution is available.
 
User time: 0.0
 
System time: 0.0
 
Termination condition: optimal
 
Termination message: Model was solved to optimality (subject to tolerances), and an optimal solution is available.
 
Error rc: 0
 
Time: 0.233999967575
# ----------------------------------------------------------
#   Solution Information
# ----------------------------------------------------------
Solution:
- number of solutions: 0
  number of solutions displayed
: 0


WARNING
: DEPRECATION WARNING: Cannot call Model.create_instance() on a
        constructed model
; returning a clone of the current model instance.
# ==========================================================
# = Solver Results                                         =
# ==========================================================
# ----------------------------------------------------------
#   Problem Information
# ----------------------------------------------------------
Problem:
- Name:
 
Lower bound: 0.666666666667
 
Upper bound: 0.666666666667
 
Number of objectives: 1
 
Number of constraints: 2
 
Number of variables: 3
 
Number of binary variables: 0
 
Number of integer variables: 0
 
Number of continuous variables: 3
 
Number of nonzeros: 3
 
Sense: minimize
# ----------------------------------------------------------
#   Solver Information
# ----------------------------------------------------------
Solver:
- Status: ok
 
Return code: 0
 
Message: Model was solved to optimality (subject to tolerances), and an optimal solution is available.
 
User time: 0.0
 
System time: 0.0
 
Termination condition: optimal
 
Termination message: Model was solved to optimality (subject to tolerances), and an optimal solution is available.
 
Error rc: 0
 
Time: 0.233999967575
# ----------------------------------------------------------
#   Solution Information
# ----------------------------------------------------------
Solution:
- number of solutions: 0
  number of solutions displayed
: 0


Hopefully someone could help :)

David Woodruff

unread,
Jul 31, 2016, 6:33:33 PM7/31/16
to pyomo...@googlegroups.com
With a ConcreteModel, there is no need to create an instance because the model object is an instance, so change these two lines:
instance = model.create_instance()
results
= opt.solve(instance)

to be
results = opt.solve(model)

(You would have needed those two lines if you had been using an
AbstractModel object)

--
You received this message because you are subscribed to the Google Groups "Pyomo Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pyomo-forum...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Gabriel Hackebeil

unread,
Aug 4, 2016, 11:47:52 AM8/4/16
to pyomo...@googlegroups.com
The solution is loaded into the model by default. You can access it by inspecting the variable values (e.g., model.x(), value(model.x), or model.x.value). If you want to view it via the results object, you must load it back into the results via

instance.solutions.store_to(results)
results.write()

Gabe

Reply all
Reply to author
Forward
0 new messages