+ All Categories
Home > Technology > Maximal: Comparison of Optimization Modeling Software for Python - Oct 2012

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

Date post: 13-Dec-2014
Category:
Upload: bjarni-kristjansson
View: 470 times
Download: 4 times
Share this document with a friend
Description:
 
11
Copyright © 2012 Maximal Software, Inc. All rights reserved 1 INFORMS Phoenix – October 2012 Comparison of Optimization Modeling Software for Python Presented by Bjarni Kristjansson Maximal Software, Inc.
Transcript
Page 1: Maximal: Comparison of Optimization Modeling Software for Python - Oct 2012

Copyright © 2012 Maximal Software, Inc. All rights reserved1

INFORMS Phoenix – October 2012

Comparison of Optimization Modeling Software for Python

Presented by

Bjarni KristjanssonMaximal Software, Inc.

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

Copyright © 2012 Maximal Software, Inc. All rights reserved 2

Optimization Modeling Tools for Python

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

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

Copyright © 2012 Maximal Software, Inc. All rights reserved

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)

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

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

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

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))

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

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]

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

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()

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

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]")

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

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])

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

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]])

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

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_")


Recommended