Pyomo + CPLEX - No Solution Displayed

729 views
Skip to first unread message

dqc

unread,
Sep 23, 2015, 12:14:40 PM9/23/15
to pyomo...@googlegroups.com
I'm using CPLEX Community Edition with Pyomo but think that although the model is beeing solved, I cannot get the solution (Variables, in Pyomo terminology).

Following is a example - with minor modification to cope with minor change in notation of pyomo -  from http://www.ibm.com/developerworks/cloud/library/cl-optimizepythoncloud1/

The major problem is:
# ----------------------------------------------------------
#   Solution Information
# ----------------------------------------------------------
Solution: 
- number of solutions: 0
  number of solutions displayed: 0

I expected to have the Variables here. 

Code bellow:

#Explicit importing makes it more clear what a user needs to define
#versus what is included within the pyomo library
from pyomo.environ import (ConcreteModel, Objective, Var, NonNegativeReals,
                              maximize, Constraint)

Products = ['Doors', 'Windows']
ProfitRate = {'Doors':300, 'Windows':500}
Plants = ['Door Fab', 'Window Fab', 'Assembly']
HoursAvailable = {'Door Fab':4, 'Window Fab':12, 'Assembly':18}
HoursPerUnit = {('Doors','Door Fab'):1, ('Windows', 'Window Fab'):2,
                ('Doors','Assembly'):3, ('Windows', 'Assembly'):2,
                ('Windows', 'Door Fab'):0, ('Doors', 'Window Fab'):0}

#Concrete Model
model = ConcreteModel()
#Decision Variables
model.WeeklyProd = Var(Products, within=NonNegativeReals)

#Objective
model.obj = Objective(expr=
            sum(ProfitRate[i] * model.WeeklyProd[i] for i in Products),
            sense = maximize)

def CapacityRule(model, p):
    """User Defined Capacity Rule
    
    Accepts a pyomo Concrete Model as the first positional argument,
    and and a plant index as a second positional argument
    """
    
    return sum(HoursPerUnit[i,p] * model.WeeklyProd[i] for i in Products) <= HoursAvailable[p]


# This statement is what Pyomo needs to generate one constraint for each plant
model.Capacity = Constraint(Plants, rule = CapacityRule)

# ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

from pyomo.opt import SolverFactory
opt = SolverFactory("cplex")
results = opt.solve(model)
#sends results to stdout
results.write()

# ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Output
# ==========================================================
# = Solver Results                                         =
# ==========================================================
# ----------------------------------------------------------
#   Problem Information
# ----------------------------------------------------------
Problem: 
- Name: tmp524cn2mb
  Lower bound: 3600.0
  Upper bound: 3600.0
  Number of objectives: 1
  Number of constraints: 4
  Number of variables: 3
  Number of nonzeros: 5
  Sense: maximize
# ----------------------------------------------------------
#   Solver Information
# ----------------------------------------------------------
Solver: 
- Status: ok
  User time: 0.01
  Termination condition: optimal
  Termination message: Dual simplex - Optimal\x3a Objective = 3.6000000000e+03
  Error rc: 0
  Time: 0.10359001159667969
# ----------------------------------------------------------
#   Solution Information
# ----------------------------------------------------------
Solution: 
- number of solutions: 0
  number of solutions displayed: 0

Gabe Hackebeil

unread,
Sep 23, 2015, 12:55:27 PM9/23/15
to pyomo...@googlegroups.com
The solution is now automatically loaded into the instance. You can disable this by passing "load_solution=False" into the solve command (it might be load_solutions).

Gabe

On Sep 23, 2015, at 9:04 AM, dqc <deo.queir...@gmail.com> wrote:

Dear all,

I had been using Pyomo with the Community Edition of CPLEX without problems. I had to reinstall everything in my computer for order reasons and suddenly I can't get it to work anymore.

I used to create "SolverFactory('cplex')" and with this run "solve" in a model and the result was a dictionary with 'Solution' key that had the variables of the optimization.

Now I have the following output, where the problematic part is the value of 'Solution' key (no variables solved appearing):

Problem: 
- Name: tmpz1of1gmt
  Lower bound: 1.507233057183755
  Upper bound: 1.507233057183755
  Number of objectives: 1
  Number of constraints: 64
  Number of variables: 21
  Number of nonzeros: 111
  Sense: minimize
Solver: 
- Status: ok
  User time: 0.12
  Termination condition: optimal
  Termination message: MIP - Integer optimal solution\x3a Objective = 1.5072330572e+00
  Statistics: 
    Branch and bound: 
      Number of bounded subproblems: 272
      Number of created subproblems: 272
  Error rc: 0
  Time: 0.22814488410949707
Solution: 
- number of solutions: 0
  number of solutions displayed: 0

If is necessary, I can create a toy example to reproduce my problem.

--
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.
Reply all
Reply to author
Forward
0 new messages