Download presentation
Presentation is loading. Please wait.
Published byAntony Kitchin Modified over 9 years ago
1
Perspective of mathematical optimization and its applications Tokyo University of Marine Science and Technology Mikio Kubo
2
How to Solve Real Combinatorial Optimization Problems Quickly Mixed Integer Programming (MIP) Solver Constraint Programming (CP) Solver Scheduling Solver (or develop (meta)heuristics)... using Python Language
3
Why Python? We can do anything by importing some modules Optimization import gurobipy (MIP) import SCOP (CP) Draw graphs import networkX Also fly! import antigravity ? http://xkcd.com/353 /
4
Mixed Integer Programming (MIP) Variables x : Real or Integer or Binary Constraints Linear or (convex) Quadratic Expressions minimize c’x+x’Qx (objective function) subject to Ax=b (constraints)
5
What’s Gurobi? MIP solver Developed by: Zonghao Gu, Edward Rothberg , Robert Bixby Current version 4.6.1 Free academic license
6
Gurobi Objects Model Variable Constraint LinExprQuadExpr Column Callbacks GRBError addVar addConstr SOS addSOS
7
Introduction to Gurobi (1) Create a model object model = Model("Wine Blending")
8
Add variable objects x1 = model.addVar(name="x1") x2 = model.addVar(name="x2") x3 = model.addVar(name="x3") Model update (needed before adding constraints; lazy update!) model.update() Introduction to Gurobi (2)
9
Introduction to Gurobi (3) Set the objective model.setObjective(15*x1 + 18*x2 + 30*x3, GRB.MAXIMIZE) Add constraints model.addConstr(2*x1 + x2 + x3 <= 60) model.addConstr(x1 + 2*x2 + x3 <= 60) model.addConstr(x3 <= 30) Optimize model.optimize()
10
Modeling with Lists Add variable objects into list x=[ ] for i in range(1,4): var=model.addVar(name=“x[ %s]”%i ) x.append(var) Add constraint “x1 + x2 + x3 <= 2” model.addConstr( sum(x) <= 2 ) or model.addConstr( quicksum(x) <= 2 ) X[1]X[2]X[3] ・・・
11
Modeling with Dictionaries Dictionary that maps keys (“Dry”, “Medium”, “Sweet”) to variable objects x={ } x[“Dry”]= model.addVar(name=“Dry”) x[“Medium”]= model.addVar(name=“Medium”) x[“Sweet”]= model.addVar(name=“Sweet”) Key “Hello”, “Dry Wine” Value “Nihao” Variable Object Mapping
12
Modeling with Dictionaries Add constraint “2 x1 + x2 + x3 <= 30” model.addConstr( 2* x[“Dry”]+ x[“Medium”] +x[“Sweet”] <=30 ) multidict Blends, Profit = multidict({"Dry":15, "Medium":18, "Sweet":30}) => Blends=["Dry", "Medium“, "Sweet“] Profit[“Dry”]=15, Profit[“Medium”]=18,...
13
Wine Blending with Dictionaries (1) multidict Blends, Profit = multidict({"Dry":15, "Medium":18, "Sweet":30}) => Blends=["Dry", "Medium“, "Sweet“] List of Keys Profit[“Dry”]=15, Profit[“Medium”]=18,... Grapes, Inventory = multidict({"Alfrocheiro":60, "Baga":60, "Castelao":30}) Use = { ("Alfrocheiro","Dry"):2, ("Alfrocheiro","Medium"):1, ("Alfrocheiro","Sweet"):1, ("Baga","Dry"):1,.... }
14
Wine Blending with Dictionaries (2) x = {} for j in Blends: x[j] = model.addVar(vtype="C", name="x[%s]"%j) model.update() model.setObjective(quicksum(Profit[j]*x[j] for j in Blends), GRB.MAXIMIZE) for i in Grapes: model.addConstr(quicksum(Use[i,j]*x[j] for j in Blends) <= Inventory[i], name="use[%s]"%i) model.optimize()
15
k-median problem A facility location problem with min-sum objective function Number of customers n=200 Number of facilities selected from customer sites k=20
16
Formulation week formulation
17
Python Code ( 1 ) from gurobipy import * model = Model("k-median") x, y = {}, {} # empty dictionaries Key “Hanako”, (1,2) Value “127cm” Variable Object Mapping Dictionary Data Structure
18
I=range(n) J=range(n) for j in J: y[j] = model.addVar(vtype="B", name="y[%s]"%j) for i in I: x[i,j] =model.addVar( vtype="B",name="x[%s,%s]"%(i,j)) model.update() Python Code (2) model.setObjective(quicksum(c[i,j]*x[i,j] for i in I for j in J)) Add variable objects “B” means binary variable or GRB.BINARY Set the objective
19
Python Code (3) for i in I: model.addConstr(quicksum(x[i,j] for j in J) = = 1, "Assign[%s]"%i) for j in J: model.addConstr(x[i,j] <= y[j], "Strong[%s,%s]"%(i,j)) model.addConstr(quicksum(y[j] for j in J) = = k, "k_median")
20
Python Code (4) … model.optimize() print “Opt.value=”,model.ObjVal edge=[] for (i,j) in x: if x[i,j].X= =1: edge.append((i,j)) return edge
21
Python Code (5) import networkx as NX #networkX module import matplotlib.pyplot as P #prepare drawing P.ion() G = NX.Graph() #graph object G.add_nodes_from(range(n)) #add nodes for (i,j) in edge: #add edges G.add_edge(i,j) NX.draw(G)
22
Optimize a model with 401 Rows, 40200 Columns and 80400 NonZeros … Explored 1445 nodes (63581 simplex iterations) in 67.08 seconds Thread count was 2 (of 2 available processors) Optimal solution found (tolerance 1.00e-04) Best objective 1.0180195861e+01, best bound 1.0179189780e+01, gap 0.0099% Opt.value= 10.1801958607 Weak formulation (result) n=200,k=20
23
Upper and lower bounds (Weak Formulation)
24
Optimize a model with 40401 Rows, 40200 Columns and 160400 NonZeros … Explored 0 nodes (1697 simplex iterations) in 3.33 seconds (No branching !) Thread count was 2 (of 2 available processors) Optimal solution found (tolerance 1.00e-04) Best objective 1.0180195861e+01, best bound 1.0180195861e+01, gap 0.0% Opt.value= 10.1801958607 Strong formulation (result)
25
k-center problem A facility location problem with min-max object n=100 customers , k=10 facilities k-center (n=30,k=3) k-median (n=30,k=3)
26
Formulation
27
Upper and lower bounds (n=100,k=10)
28
k-Covering Problem =1 if customer is not covered # of uncovered customers parameter that is =1 if distance is less than or equal to θ
29
k-Covering+Binary Search Upper and Lower Bounds UB , LB while UB – LB >ε: θ= (UB+LB)/2 if opt. val. of k-covering is 0 then UB = θ else LB = θ
30
Computational Experiments
31
Constraint Programming (CP) Variables x has to be selected from a finite domain (set of values) Constraints Linear, (non-convex) Quadratic, All Different or Any Types of Combinatorial Expressions
32
Assignment Problem (MIP/CP) Assign three jobs A,B,C to three workers 1,2,3 MIP formulation: x ij Binary CP formulation : x[i] with domain {A,B,C} AllDiff ( x[1], x[2], x[3] )
33
Constraint Programming Solver SCOP (Solver for COnstraint or Programming) developed by Prof. Ibaraki and Prof. Nonobe ITC (International Timetabling Competition) 2007 – Finalist for all 3 tracks (3 rd, 2 nd, 3 rd among 5 finalists) International Nurse Rostering Competition (INRC) 2010 – Finalists for all 3 tracks (2 nd,3 rd, 4 th among 5 finalists)
34
SCOP Objects Model Variable Linear addVariable(s) Quadratic Alldiff addConstraint
35
Scheduling Activities (=Variables) x has to be selected from a set of modes (=domain of CP) Resource Renewable or Non-renewable Resources (=Constraints) Temporal Constraints
36
Scheduling Solver OptSeq II developed by Prof. Ibaraki and Prof. Nonobe Algorithms CPU sec. # of Feasible Solutions Error from Best Known Tabu search 1 3095/270284.07% Priority-rule method 2 30270/270180.05% Our tabu search 3 10269/270 95.88% 1. [De Reyck and Herroelen, 1999] 333MHz PC 2. [Heilmann, 2001] 333MHz PC 3. 1GHz PC Multi-mode RCPSP PSPLIB [Kolisch and Sprecher, 1997]
37
OptSeq Objects Model Attribute Mode addActivity Resource Temporal addResource addTemporal addMode
38
Applications Train scheduling in a steel plant: Flow optimization using Gurobi + Detailed scheduling using OptSeq Supply Chain Modeling Language (SCML)
39
What’s SCML? SCML Supply Chain Optimization Models Combinatorial Optimization Models Solvers (metaheuristics, MIP/CP solvers) SCML.py
40
Supply Chain Optimization Models resource constrained scheduling lot-sizing logistics network design safety stock allocation economic order quantity inventory policy optimization vehicle routing
41
謝謝 Thank You ご清聴ありがとうございました
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.