際際滷

際際滷Share a Scribd company logo
INFORMS Phoenix  October 2012




  Comparison of Optimization
   Modeling Software for Python

                   Presented by

         Bjarni Kristjansson
        Maximal Software, Inc.




   Copyright 息 2012 Maximal Software, Inc. All rights reserved
                                                                 1
Optimization Modeling Tools for Python




   MPLPY  MPL Optimax
   PULP-OR
   PYOMO
   CPLEX API for Python
   GUROBI API for Python
   GAMS API for Python




           Copyright 息 2012 Maximal Software, Inc. All rights reserved   2
Indexing



MPL:
 cutNames               #   [w1, w2, ... w8]
 patternNames           #   [p1, p2, ..., p29]
 priceSheet             #   28
 sheetsAvail            #   2000
 sutDemand              #   [500, 400, 300, 450, 350,                          200, 800, 200]
 cutsInPattern          #   [[1, 0, 0, 0, 0, 0, 0, 0,                          0, 0, 0, 0, 0, 0, 0,
                               0, 0, 0, 0, 0, 0, 0, 0,                         0, 0, 0, 0, 0],.. ,
                               0, 0, 0, 0, 0, 0, 0, 0,                         0]



 Model model = mpl.Models.Add(CutStock")
 mod.IndexSets.AddNameSet("cuts", cutNames)
 mod.IndexSets.AddNameSet("patterns", patternNames)




                 Copyright 息 2012 Maximal Software, Inc. All rights reserved
Data


MPL:
    model.DataConstants.Add("PriceSheet", priceSheet)
     model.DataConstants.Add("SheetsAvail", sheetsAvail)
     model.DataVectors.AddDense("CutDemand[cuts]", cutDemand)
     model.DataVectors.Add("CutsInPattern[patterns, cuts]",
cutsInPattern)

PULP-OR:
    CutsInPattern = makeDict([Cuts,Patterns],CutsInPattern)
    CutDemand = makeDict([Cuts],CutDemand)

PYOMO:
    tmp = {}
    for i in range(len(Cuts)):
       tmp[Cuts[i]] = CutDemand[i]
    CutDemand = tmp




                   Copyright 息 2012 Maximal Software, Inc. All rights reserved
Variables


MPL:
   model.PlainVariables.Add("SheetsCut", "-> T1")
   model.PlainVariables.Add("TotalCost", "-> TC")
   model.VariableVectors.Add("PatternCount[patterns]", "-> """)
   model.VariableVectors.Add("ExcessCuts[cuts]", "-> X")

PULP-OR:
  SheetsCut = LpVariable("SheetsCut",0)
  TotalCost = LpVariable("TotalCost",0)
  PatternCount = LpVariable.dicts("PatternCount",Patterns, lowBound
     = 0)
  ExcessCuts = LpVariable.dicts("ExcessCuts",Cuts, lowBound = 0)

PYOMO:
  model.SheetsCut = Var()
  model.TotalCost = Var()
  model.PatternCount = Var(Patterns, bounds=(0,None))
  model.ExcessCuts = Var(Cuts, bounds=(0,None))


                Copyright 息 2012 Maximal Software, Inc. All rights reserved
Variables


CPLEX:
  cpx = cplex.Cplex()
  cpx.variables.add(names = ["SheetsCut"], lb = [0], ub =
     [cplex.infinity])
  cpx.variables.add(names = ["TotalCost"], lb = [0], ub =
     [cplex.infinity], obj = [1])
  cpx.variables.add(names = Patterns)
  cpx.variables.add(names = Cuts)

GUROBI:
  SheetsCut = m.addVar(0, GRB.INFINITY, 0,
     GRB.CONTINUOUS,"SheetsCut")
  TotalCost = m.addVar(0, GRB.INFINITY, 1, GRB.CONTINUOUS,"TotCost")
  PatternCount = []
  for i in range(patcount):
     newvar = m.addVar(0, GRB.INFINITY, 0, GRB.CONTINUOUS,
     Patterns[i])
     PatternCount += [newvar]



                Copyright 息 2012 Maximal Software, Inc. All rights reserved
Objective


MPL:
  model.Objectives.Add("TotalCost", ObjectSense.Minimize)


PULP-OR:
  prob += TotalCost,"


PYOMO:
  model.objective = Objective(expr=1.0*model.TotalCost)


CPLEX:
  cpx.objective.set_sense(cpx.objective.sense.minimize)


GUROBI:
  m.ModelSense = 1
  m.update()



                Copyright 息 2012 Maximal Software, Inc. All rights reserved
Constraints


MPL:
 model.PlainConstraints.Add("TotCost",
    "TotalCost = PriceSheet*SheetsCut")
 model.PlainConstraints.Add("RawAvail", "SheetsCut < SheetsAvail")
 model.PlainConstraints.Add("Sheets",
    "SheetsCut = SUM(patterns: PatternCount[patterns])")
 model.ConstraintVectors.Add("CutReq[cuts]",
    "SUM(patterns: CutsInPattern[patterns, cuts] *
                   PatternCount[patterns])=
     CutDemand[cuts] + ExcessCuts[cuts]")




                Copyright 息 2012 Maximal Software, Inc. All rights reserved
Constraints


PULP-OR:
  prob += TotalCost == PriceSheet*SheetsCut,"TotCost
  prob += SheetsCut <= SheetsAvail,"RawAvail
  for c in Cuts:
     prob += lpSum([CutsInPattern[c][p]*PatternCount[p] for p in
     Patterns]) == CutDemand[c] + ExcessCuts[c],"CutReq" + str(c)

PYOMO:
  model.TotCost = Constraint(expr = model.TotalCost
     == PriceSheet* model.SheetsCut)
  model.RawAvail = Constraint(expr = model.SheetsCut <= SheetsAvail)
  model.CutReq = Constraint(Cuts)
  for c in Cuts:
     model.CutReq.add(c,expr=
     sum(CutsInPattern[c][p]*model.PatternCount[p] for p in Patterns)
     == CutDemand[c] + model.ExcessCuts[c])




                Copyright 息 2012 Maximal Software, Inc. All rights reserved
Constraints


CPLEX:
  cpx.linear_constraints.add(lin_expr =
     [cplex.SparsePair(ind = ["SheetsCut", "TotalCost"],
  val = [-PriceSheet, 1.0])], senses = ["E"], rhs = [0])

  cpx.linear_constraints.add(lin_expr =
     [cplex.SparsePair(ind = indA,val = valA)], senses = ["E"], rhs =
     [0])

  for c in range(cutcount):
     cpx.linear_constraints.add(lin_expr = [cplex.SparsePair(ind =
     indP[c],val = valP[c])], senses = ["E"], rhs = [CutDemand[c]])




                Copyright 息 2012 Maximal Software, Inc. All rights reserved
Constraints


GUROBI:
  m.addConstr(LinExpr(PriceSheet, SheetsCut), GRB.EQUAL,
     TotalCost,"TotCostCalc")
  m.addConstr(LinExpr(1, SheetsCut), GRB.LESS_EQUAL, SheetsAvail,"RawAvail")

  sheetsB = LinExpr()
  for i in range(patcount):
     sheetsB.addTerms(1, PatternCount[i])m.addConstr(sheetsB, GRB.EQUAL,
     sheetsCut,"Sheets")

  for c in range(cutcount):
     cutReqB = LinExpr()
     cutReqB.addTerms(-1,ExcessCuts[c])
     for p in range(patcount):
       cutReqB.addTerms(CutsInPattern[c][p],PatternCount[p])
     m.addConstr(cutReqB, GRB.EQUAL, CutDemand[c],"CutReq_")




                     Copyright 息 2012 Maximal Software, Inc. All rights reserved
Ad

Recommended

Bitmap management like a boss
Bitmap management like a boss
Somkiat Khitwongwattana
Solution Manual for Introduction to Programming Using Python 1st Edition by S...
Solution Manual for Introduction to Programming Using Python 1st Edition by S...
romanelins
Maximal: Achieving Optimal Solution Performance for your Optimization Modelin...
Maximal: Achieving Optimal Solution Performance for your Optimization Modelin...
Bjarni Kristj叩nsson
Seminar: Introduction to Maximal Software and the MPL Modeling System - Oct 2012
Seminar: Introduction to Maximal Software and the MPL Modeling System - Oct 2012
Bjarni Kristj叩nsson
New Release 5.0 of MPL and OptiMax Library - OR Vienna 2015
New Release 5.0 of MPL and OptiMax Library - OR Vienna 2015
Bjarni Kristj叩nsson
Seminar: Embedding Optimization in Applications with MPL OptiMax - April 2012
Seminar: Embedding Optimization in Applications with MPL OptiMax - April 2012
Bjarni Kristj叩nsson
MBA Presentation Skills
MBA Presentation Skills
dallas_simmons
Seminar: New Stochastic Programming Features for MPL - Nov 2011
Seminar: New Stochastic Programming Features for MPL - Nov 2011
Bjarni Kristj叩nsson
Mathematical optimization and python
Mathematical optimization and python
Open-IT
Stuart Mitchell - Pulp Optimisation
Stuart Mitchell - Pulp Optimisation
danny.adair
Introduction to Price Optimisation
Introduction to Price Optimisation
Ammar Mohemmed
Exp.docx
Exp.docx
vennapusaIndrasenare
Model Presolve, Warmstart and Conflict Refining in CP Optimizer
Model Presolve, Warmstart and Conflict Refining in CP Optimizer
Philippe Laborie
AMPL Workshop, part 2: From Formulation to Deployment
AMPL Workshop, part 2: From Formulation to Deployment
Bob Fourer
Linear programming in matlab
Linear programming in matlab
IAEME Publication
PyCon Siberia 2016. 亠 亟仂于亠磺亠 亠舒仄!
PyCon Siberia 2016. 亠 亟仂于亠磺亠 亠舒仄!
Ivan Tsyganov
MBA Semester linear analysis and programming function
MBA Semester linear analysis and programming function
haribabu9697
2. lp iterative methods
2. lp iterative methods
Hakeem-Ur- Rehman
Maximal: Deploying Optimization Models on Servers and Mobile Platforms - Oct ...
Maximal: Deploying Optimization Models on Servers and Mobile Platforms - Oct ...
Bjarni Kristj叩nsson
Maximal: MPL Software Demo - INFORMS Phoenix Oct 2012
Maximal: MPL Software Demo - INFORMS Phoenix Oct 2012
Bjarni Kristj叩nsson
Seminar: CoinMP - Open Source Solver - Nov 2011
Seminar: CoinMP - Open Source Solver - Nov 2011
Bjarni Kristj叩nsson
Seminar: Data Modeling for Optimization with MPL - Oct 2012
Seminar: Data Modeling for Optimization with MPL - Oct 2012
Bjarni Kristj叩nsson
Seminar: New Pricing Programs and Free Software Offers by Maximal - Oct 2012
Seminar: New Pricing Programs and Free Software Offers by Maximal - Oct 2012
Bjarni Kristj叩nsson
OR Connect: A New Web 2.0 Online Initiative for O.R. - INFORMS Jan 2011
OR Connect: A New Web 2.0 Online Initiative for O.R. - INFORMS Jan 2011
Bjarni Kristj叩nsson
INFORMS: IT Board Report - April 2011
INFORMS: IT Board Report - April 2011
Bjarni Kristj叩nsson
INFORMS: IT Committee Report - August 2011
INFORMS: IT Committee Report - August 2011
Bjarni Kristj叩nsson
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM

More Related Content

Similar to Maximal: Comparison of Optimization Modeling Software for Python - Oct 2012 (10)

Mathematical optimization and python
Mathematical optimization and python
Open-IT
Stuart Mitchell - Pulp Optimisation
Stuart Mitchell - Pulp Optimisation
danny.adair
Introduction to Price Optimisation
Introduction to Price Optimisation
Ammar Mohemmed
Exp.docx
Exp.docx
vennapusaIndrasenare
Model Presolve, Warmstart and Conflict Refining in CP Optimizer
Model Presolve, Warmstart and Conflict Refining in CP Optimizer
Philippe Laborie
AMPL Workshop, part 2: From Formulation to Deployment
AMPL Workshop, part 2: From Formulation to Deployment
Bob Fourer
Linear programming in matlab
Linear programming in matlab
IAEME Publication
PyCon Siberia 2016. 亠 亟仂于亠磺亠 亠舒仄!
PyCon Siberia 2016. 亠 亟仂于亠磺亠 亠舒仄!
Ivan Tsyganov
MBA Semester linear analysis and programming function
MBA Semester linear analysis and programming function
haribabu9697
2. lp iterative methods
2. lp iterative methods
Hakeem-Ur- Rehman
Mathematical optimization and python
Mathematical optimization and python
Open-IT
Stuart Mitchell - Pulp Optimisation
Stuart Mitchell - Pulp Optimisation
danny.adair
Introduction to Price Optimisation
Introduction to Price Optimisation
Ammar Mohemmed
Model Presolve, Warmstart and Conflict Refining in CP Optimizer
Model Presolve, Warmstart and Conflict Refining in CP Optimizer
Philippe Laborie
AMPL Workshop, part 2: From Formulation to Deployment
AMPL Workshop, part 2: From Formulation to Deployment
Bob Fourer
Linear programming in matlab
Linear programming in matlab
IAEME Publication
PyCon Siberia 2016. 亠 亟仂于亠磺亠 亠舒仄!
PyCon Siberia 2016. 亠 亟仂于亠磺亠 亠舒仄!
Ivan Tsyganov
MBA Semester linear analysis and programming function
MBA Semester linear analysis and programming function
haribabu9697

More from Bjarni Kristj叩nsson (8)

Maximal: Deploying Optimization Models on Servers and Mobile Platforms - Oct ...
Maximal: Deploying Optimization Models on Servers and Mobile Platforms - Oct ...
Bjarni Kristj叩nsson
Maximal: MPL Software Demo - INFORMS Phoenix Oct 2012
Maximal: MPL Software Demo - INFORMS Phoenix Oct 2012
Bjarni Kristj叩nsson
Seminar: CoinMP - Open Source Solver - Nov 2011
Seminar: CoinMP - Open Source Solver - Nov 2011
Bjarni Kristj叩nsson
Seminar: Data Modeling for Optimization with MPL - Oct 2012
Seminar: Data Modeling for Optimization with MPL - Oct 2012
Bjarni Kristj叩nsson
Seminar: New Pricing Programs and Free Software Offers by Maximal - Oct 2012
Seminar: New Pricing Programs and Free Software Offers by Maximal - Oct 2012
Bjarni Kristj叩nsson
OR Connect: A New Web 2.0 Online Initiative for O.R. - INFORMS Jan 2011
OR Connect: A New Web 2.0 Online Initiative for O.R. - INFORMS Jan 2011
Bjarni Kristj叩nsson
INFORMS: IT Board Report - April 2011
INFORMS: IT Board Report - April 2011
Bjarni Kristj叩nsson
INFORMS: IT Committee Report - August 2011
INFORMS: IT Committee Report - August 2011
Bjarni Kristj叩nsson
Maximal: Deploying Optimization Models on Servers and Mobile Platforms - Oct ...
Maximal: Deploying Optimization Models on Servers and Mobile Platforms - Oct ...
Bjarni Kristj叩nsson
Maximal: MPL Software Demo - INFORMS Phoenix Oct 2012
Maximal: MPL Software Demo - INFORMS Phoenix Oct 2012
Bjarni Kristj叩nsson
Seminar: CoinMP - Open Source Solver - Nov 2011
Seminar: CoinMP - Open Source Solver - Nov 2011
Bjarni Kristj叩nsson
Seminar: Data Modeling for Optimization with MPL - Oct 2012
Seminar: Data Modeling for Optimization with MPL - Oct 2012
Bjarni Kristj叩nsson
Seminar: New Pricing Programs and Free Software Offers by Maximal - Oct 2012
Seminar: New Pricing Programs and Free Software Offers by Maximal - Oct 2012
Bjarni Kristj叩nsson
OR Connect: A New Web 2.0 Online Initiative for O.R. - INFORMS Jan 2011
OR Connect: A New Web 2.0 Online Initiative for O.R. - INFORMS Jan 2011
Bjarni Kristj叩nsson
INFORMS: IT Board Report - April 2011
INFORMS: IT Board Report - April 2011
Bjarni Kristj叩nsson
INFORMS: IT Committee Report - August 2011
INFORMS: IT Committee Report - August 2011
Bjarni Kristj叩nsson
Ad

Recently uploaded (20)

FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
Wenn alles versagt - IBM Tape sch端tzt, was z辰hlt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape sch端tzt, was z辰hlt! Und besonders mit dem neust...
Josef Weingand
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
OpenPOWER Foundation & Open-Source Core Innovations
OpenPOWER Foundation & Open-Source Core Innovations
IBM
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Enhance GitHub Copilot using MCP - Enterprise version.pdf
Nilesh Gule
Securing AI - There Is No Try, Only Do!.pdf
Securing AI - There Is No Try, Only Do!.pdf
Priyanka Aash
Wenn alles versagt - IBM Tape sch端tzt, was z辰hlt! Und besonders mit dem neust...
Wenn alles versagt - IBM Tape sch端tzt, was z辰hlt! Und besonders mit dem neust...
Josef Weingand
cnc-processing-centers-centateq-p-110-en.pdf
cnc-processing-centers-centateq-p-110-en.pdf
AmirStern2
"Database isolation: how we deal with hundreds of direct connections to the d...
"Database isolation: how we deal with hundreds of direct connections to the d...
Fwdays
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
ReSTIR [DI]: Spatiotemporal reservoir resampling for real-time ray tracing ...
revolcs10
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
Cyber Defense Matrix Workshop - RSA Conference
Cyber Defense Matrix Workshop - RSA Conference
Priyanka Aash
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC and Open Hackathons Monthly Highlights June 2025
OpenACC
Connecting Data and Intelligence: The Role of FME in Machine Learning
Connecting Data and Intelligence: The Role of FME in Machine Learning
Safe Software
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
Python Conference Singapore - 19 Jun 2025
Python Conference Singapore - 19 Jun 2025
ninefyi
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Seminar: Evolving Landscape of Post-Quantum Cryptography.pptx
FIDO Alliance
The Future of Technology: 2025-2125 by Saikat Basu.pdf
The Future of Technology: 2025-2125 by Saikat Basu.pdf
Saikat Basu
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
CapCut Pro Crack For PC Latest Version {Fully Unlocked} 2025
pcprocore
10 Key Challenges for AI within the EU Data Protection Framework.pdf
10 Key Challenges for AI within the EU Data Protection Framework.pdf
Priyanka Aash
Ad

Maximal: Comparison of Optimization Modeling Software for Python - Oct 2012

  • 1. INFORMS Phoenix October 2012 Comparison of Optimization Modeling Software for Python Presented by Bjarni Kristjansson Maximal Software, Inc. Copyright 息 2012 Maximal Software, Inc. All rights reserved 1
  • 2. Optimization Modeling Tools for Python MPLPY MPL Optimax PULP-OR PYOMO CPLEX API for Python GUROBI API for Python GAMS API for Python Copyright 息 2012 Maximal Software, Inc. All rights reserved 2
  • 3. Indexing MPL: cutNames # [w1, w2, ... w8] patternNames # [p1, p2, ..., p29] priceSheet # 28 sheetsAvail # 2000 sutDemand # [500, 400, 300, 450, 350, 200, 800, 200] cutsInPattern # [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],.. , 0, 0, 0, 0, 0, 0, 0, 0, 0] Model model = mpl.Models.Add(CutStock") mod.IndexSets.AddNameSet("cuts", cutNames) mod.IndexSets.AddNameSet("patterns", patternNames) Copyright 息 2012 Maximal Software, Inc. All rights reserved
  • 4. Data MPL: model.DataConstants.Add("PriceSheet", priceSheet) model.DataConstants.Add("SheetsAvail", sheetsAvail) model.DataVectors.AddDense("CutDemand[cuts]", cutDemand) model.DataVectors.Add("CutsInPattern[patterns, cuts]", cutsInPattern) PULP-OR: CutsInPattern = makeDict([Cuts,Patterns],CutsInPattern) CutDemand = makeDict([Cuts],CutDemand) PYOMO: tmp = {} for i in range(len(Cuts)): tmp[Cuts[i]] = CutDemand[i] CutDemand = tmp Copyright 息 2012 Maximal Software, Inc. All rights reserved
  • 5. Variables MPL: model.PlainVariables.Add("SheetsCut", "-> T1") model.PlainVariables.Add("TotalCost", "-> TC") model.VariableVectors.Add("PatternCount[patterns]", "-> """) model.VariableVectors.Add("ExcessCuts[cuts]", "-> X") PULP-OR: SheetsCut = LpVariable("SheetsCut",0) TotalCost = LpVariable("TotalCost",0) PatternCount = LpVariable.dicts("PatternCount",Patterns, lowBound = 0) ExcessCuts = LpVariable.dicts("ExcessCuts",Cuts, lowBound = 0) PYOMO: model.SheetsCut = Var() model.TotalCost = Var() model.PatternCount = Var(Patterns, bounds=(0,None)) model.ExcessCuts = Var(Cuts, bounds=(0,None)) Copyright 息 2012 Maximal Software, Inc. All rights reserved
  • 6. Variables CPLEX: cpx = cplex.Cplex() cpx.variables.add(names = ["SheetsCut"], lb = [0], ub = [cplex.infinity]) cpx.variables.add(names = ["TotalCost"], lb = [0], ub = [cplex.infinity], obj = [1]) cpx.variables.add(names = Patterns) cpx.variables.add(names = Cuts) GUROBI: SheetsCut = m.addVar(0, GRB.INFINITY, 0, GRB.CONTINUOUS,"SheetsCut") TotalCost = m.addVar(0, GRB.INFINITY, 1, GRB.CONTINUOUS,"TotCost") PatternCount = [] for i in range(patcount): newvar = m.addVar(0, GRB.INFINITY, 0, GRB.CONTINUOUS, Patterns[i]) PatternCount += [newvar] Copyright 息 2012 Maximal Software, Inc. All rights reserved
  • 7. Objective MPL: model.Objectives.Add("TotalCost", ObjectSense.Minimize) PULP-OR: prob += TotalCost," PYOMO: model.objective = Objective(expr=1.0*model.TotalCost) CPLEX: cpx.objective.set_sense(cpx.objective.sense.minimize) GUROBI: m.ModelSense = 1 m.update() Copyright 息 2012 Maximal Software, Inc. All rights reserved
  • 8. Constraints MPL: model.PlainConstraints.Add("TotCost", "TotalCost = PriceSheet*SheetsCut") model.PlainConstraints.Add("RawAvail", "SheetsCut < SheetsAvail") model.PlainConstraints.Add("Sheets", "SheetsCut = SUM(patterns: PatternCount[patterns])") model.ConstraintVectors.Add("CutReq[cuts]", "SUM(patterns: CutsInPattern[patterns, cuts] * PatternCount[patterns])= CutDemand[cuts] + ExcessCuts[cuts]") Copyright 息 2012 Maximal Software, Inc. All rights reserved
  • 9. Constraints PULP-OR: prob += TotalCost == PriceSheet*SheetsCut,"TotCost prob += SheetsCut <= SheetsAvail,"RawAvail for c in Cuts: prob += lpSum([CutsInPattern[c][p]*PatternCount[p] for p in Patterns]) == CutDemand[c] + ExcessCuts[c],"CutReq" + str(c) PYOMO: model.TotCost = Constraint(expr = model.TotalCost == PriceSheet* model.SheetsCut) model.RawAvail = Constraint(expr = model.SheetsCut <= SheetsAvail) model.CutReq = Constraint(Cuts) for c in Cuts: model.CutReq.add(c,expr= sum(CutsInPattern[c][p]*model.PatternCount[p] for p in Patterns) == CutDemand[c] + model.ExcessCuts[c]) Copyright 息 2012 Maximal Software, Inc. All rights reserved
  • 10. Constraints CPLEX: cpx.linear_constraints.add(lin_expr = [cplex.SparsePair(ind = ["SheetsCut", "TotalCost"], val = [-PriceSheet, 1.0])], senses = ["E"], rhs = [0]) cpx.linear_constraints.add(lin_expr = [cplex.SparsePair(ind = indA,val = valA)], senses = ["E"], rhs = [0]) for c in range(cutcount): cpx.linear_constraints.add(lin_expr = [cplex.SparsePair(ind = indP[c],val = valP[c])], senses = ["E"], rhs = [CutDemand[c]]) Copyright 息 2012 Maximal Software, Inc. All rights reserved
  • 11. Constraints GUROBI: m.addConstr(LinExpr(PriceSheet, SheetsCut), GRB.EQUAL, TotalCost,"TotCostCalc") m.addConstr(LinExpr(1, SheetsCut), GRB.LESS_EQUAL, SheetsAvail,"RawAvail") sheetsB = LinExpr() for i in range(patcount): sheetsB.addTerms(1, PatternCount[i])m.addConstr(sheetsB, GRB.EQUAL, sheetsCut,"Sheets") for c in range(cutcount): cutReqB = LinExpr() cutReqB.addTerms(-1,ExcessCuts[c]) for p in range(patcount): cutReqB.addTerms(CutsInPattern[c][p],PatternCount[p]) m.addConstr(cutReqB, GRB.EQUAL, CutDemand[c],"CutReq_") Copyright 息 2012 Maximal Software, Inc. All rights reserved