1 1 Modeling Flows John H. Vande Vate Spring, 2006
Jan 18, 2016
11
Modeling Flows
John H. Vande Vate
Spring, 2006
22
New Project Opportunity
• Sponsor: CARE and Shelter First
• Design temporary shelters (tents)
• Design delivery mechanism
• Design logistics network
• Evaluate inventory levels, locations and cost
33
Agenda
• Network Flows– Review definition
– Simple Transportation Model
– Minimum Cost Flow Model
• Adding Realism– Multiple commodities
– Weight, Cube, Linear Cube
– Concave Costs
– Modeling Time
44
Reference
Network Flows: Theory, Algorithms, and Applications (Hardcover)by Ravindra K. Ahuja, Thomas L. Magnanti, James B.
Orlin
55
What Are They?
• Specially Structured Linear Programs
• Each variable appears in at most two constraints– At most one constraint with a +1 coefficient– At most one constraint with a -1 coefficient
• Each variable may be constrained by bounds
• Integer Data => Integer Solutions
66
Transportation Model
• Move Goods from Plants to Warehouses
• Single Commodity!
• Plants have supplies
• Warehouses have demands
• Costs are proportional to volume shipped (this usually isn’t very realistic)
77
Example 2-3 (p 36)
• Single Product
• Two plants with identical production costs
• Two warehouses
• Markets allocated to warehouses for now
• Proportional transportation costs
88
Example 2-3 cont’dSimplified Version of Example 2-3 in Simchi-Levi
Plant1 Plant2 DemandWarehouse1 -$ 4$ 100Warehouse2 5$ 2$ 100Capacity 200 60
Plant1 Plant2 Total To DemandWarehouse1 100 0 100 >= 100Warehouse2 40 60 100 >= 100Total From 140 60
<= <=Capacity 200 60
Plant1 Plant2 TotalWarehouse1 -$ -$ -$ Warehouse2 200$ 120$ 320$ Total 200$ 120$ 320$
Unit Transport Costs
Flows
Costs
99
Transportation Model (AMPL)
• Set Plants;
• Set Warehouses;
• Param Supply {Plants};
• Param Demand {Warehouses};
• Param Cost{Plants, Warehouses};
• Var Flow{Plants, Warehouses}>= 0;
• minimize TotalCost: sum{p in Plants, w in Warehouses} Cost[p,w]*Flow[p,w];
• s.t. WithinSupply{p in Plants}:sum{w in Warehouses} Flow[p, w] <= Supply[p];
• s.t. MeetDemand{w in Warehouses}:sum{p in Plants} Flow[p, w] >= Demand[w];
1010
Minimum Cost Flow• Move Goods from Plants to Markets via
Warehouses
• Single Commodity!
• Plants have supplies
• Markets have demands
• Costs are proportional to volume shipped
1111
Example 2-3 Cont’d
Simplified Version of Example 2-3 in Simchi-Levi
Plant1 Plant2 Market1 Market2 Market3Warehouse1 -$ 4$ Warehouse1 3$ 4$ 5$ Warehouse2 5$ 2$ Warehouse2 2$ 1$ 2$ Capacity (000) 200 60 Demand (000) 50 100 50
Plant1 Plant2 Total To Total From Market1 Market2 Market3Warehouse1 - = - Warehouse1Warehouse2 - = - Warehouse2Total From - - - - - Total to
<= <= >= >= >=Capacity 200 60 50 100 50 Demand
Plant1 Plant2 Total Market1 Market2 Market3Warehouse1 -$ -$ -$ Warehouse1 -$ -$ -$ -$ Warehouse2 -$ -$ -$ Warehouse2 -$ -$ -$ -$ Total -$ -$ -$ -$ -$ -$ -$
Total Transportation Cost ($000)-$
Costs
Flows
Unit Transport Costs
1212
Minimum Cost Flow• Set Locs;
• Set Edges in Locs cross Locs;
• param Cost{Edges};
• param NetSupply{Locs};
• var FlowVol{Edges} >= 0;
• minimize TotalCost:sum{(f,t) in Edges} Cost[f,t]*FlowVol[f,t];
• s.t. PathDefinition{loc in Locs}: sum{(loc, t) in Edges} FlowVol[loc,t]
- sum{(f, loc) in Edges} FlowVol[f, loc] = NetSupply[loc];
1313
Homogenous Product
Must be able to interchange
positions of product anywhere
1414
Another New Project
• Milliken & Co. growing business in Asia looking to explore distribution strategy: Where should it be positioning inventories to serve that region?
1515
Multi-Commodity Flows
• Several single commodity models • You can’t to turn lead into gold
– Conserve flow of each product through each facility
• Joined by common constraints– Often capacity on lanes– Or modeling cost (through capacity)– …
1616
Multiple ProductsShipping Costs
Heavy DC Cust 1 Cust 2Plant H 300$ 500$ 600$ Plant L 100$ 300$ 400$
DC 300$ 400$
Light DC Cust 1 Cust 2Plant H 200$ 600$ 400$ Plant L 50$ 400$ 400$
DC 300$ 400$
FlowsHeavy DC Cust 1 Cust 2 Total Supply
Plant H - 600 DC - -
Total - 0 0Demand - 400 180
Light DC Cust 1 Cust 2 Total Supply Plant L - 600
DC - - Total - 0 0
Demand - 200 300
Transportation Costs ($/Unit)
1717
Conveyance Capacity
• Weight Limits, e.g., 40,000 lbs• Cubic Capacity (53’ trailer)
– 3,970 cubic ft.– Length 52' 6" – Width 99" – Height 110"
• Linear Cube (53’ trailer)– If load is not stackable, just floor space
1818
Conveyance Capacity
Product H Product L Total- - - Limit/Truck
Unit Weight 500 100 0 40,000 Unit Cube 10 20 0 3,900
1919
Multiple Products Weight & Cube
Shipping Costs Conveyances Shipping Costs Flows Conveyances Total CostWeight Cube
From\To DC Cust 1 Cust 2 Weight (Lbs) Cube (cu. ft) From\To DC Cust 1 Cust 2 From\To DC Cust 1 Cust 2Plant H 300$ 500$ 600$ 500 10 Plant H - - - Plant H - - - Plant L 100$ 300$ 400$ 100 20 Plant L - - - Plant L - - -
DC 300$ 400$ DC - - DC - -
Conveyance Capacity 40,000 3,900 Shipping Costs Conveyance to Carry the Weight Conveyance to Carry the CubeFlows From\To DC Cust 1 Cust 2 From\To DC Cust 1 Cust 2Conveyances Plant H - - - Plant H - - - Total Cost Plant L - - - Plant L - - -
DC - - DC - -
Flows Total Cost Shipping Costs Flows Conveyances Total CostHeavy DC Cust 1 Cust 2 Total Supply Conveyances Costs
Plant H - 600 From\To DC Cust 1 Cust 2 From\To DC Cust 1 Cust 2DC - - Plant H - - - Plant H -$ -$ -$
Total - 0 0 Shipping Costs Plant L - - - Plant L -$ -$ -$ Demand - 400 180 Flows DC - - DC -$ -$
Conveyances Total -$ -$ -$ Light DC Cust 1 Cust 2 Total Supply Total Cost Total
Plant L - 600 -$ DC - -
Total - 0 0Demand - 200 300
Cross Dock with Weight & Cube
Transportation Costs ($/Conveyance)
2020
Note
• No Longer a Network Model
• Solutions not integral
• Adding integrality constraints
2121
Multiple Products Weight & Cube
Shipping Costs Conveyances Shipping Costs Flows Conveyances Total CostWeight Cube
From\To DC Cust 1 Cust 2 Weight (Lbs) Cube (cu. ft) From\To DC Cust 1 Cust 2 From\To DC Cust 1 Cust 2Plant H 300$ 500$ 600$ 500 10 Plant H - - - Plant H - - - Plant L 100$ 300$ 400$ 100 20 Plant L - - - Plant L - - -
DC 300$ 400$ DC - - DC - -
Conveyance Capacity 40,000 3,900 Shipping Costs Conveyance to Carry the Weight Conveyance to Carry the CubeFlows From\To DC Cust 1 Cust 2 From\To DC Cust 1 Cust 2Conveyances Plant H - - - Plant H - - - Total Cost Plant L - - - Plant L - - -
DC - - DC - -
Flows Total Cost Shipping Costs Flows Conveyances Total CostHeavy DC Cust 1 Cust 2 Total Supply Conveyances Costs
Plant H - 600 From\To DC Cust 1 Cust 2 From\To DC Cust 1 Cust 2DC - - Plant H - - - Plant H -$ -$ -$
Total - 0 0 Shipping Costs Plant L - - - Plant L -$ -$ -$ Demand - 400 180 Flows DC - - DC -$ -$
Conveyances Total -$ -$ -$ Light DC Cust 1 Cust 2 Total Supply Total Cost Total
Plant L - 600 -$ DC - -
Total - 0 0Demand - 200 300
Cross Dock with Weight & Cube
Transportation Costs ($/Conveyance)
2222
Concave Cost
Shipment Size
Cos
tCost per unit decreasing
Without special constraints, what will solver do?
2323
Modeling Economies of Scale
• Linear Programming– Greedy– Takes the High-Range Unit Cost first!
• Integer Programming
– Add constraints to ensure first things first
– Several Strategies
2424
Convex Combination• Weighted Average
Tot
al C
ost
0
First Break Point
Second Break Point
10 20
$22
$27
Mid Point
What will the costbe?
1/5th of the way
2525
Conclusion
• If the Volume of Activity is a fraction of the way from one breakpoint to the next, the cost will be that same fraction of the way from the cost at the first breakpoint to the cost at the next
• If Volume = 10 + 20(1-)
• Then Cost = 22 + 27(1-)
2626
Idea• Express Volume of Activity as a Weighted
Average of Breakpoints• Express Cost as the same Weighted Average of
Costs at the Breaks• Activity = Min Level 0 + Break 1 1 +
Break 2 2 + Max Level 3
• Cost = Cost at Min Level 0 + Cost at Break 1 1 +
Cost at Break 2 2 + Cost at Max Level 3
• 1 = 0 + 1 + 2 + 3
2727
Does that Do It?• What can go wrong?
Volume of Activity
Tot
al C
ost
0
Minimum Sustainable
Level
Low R
ange
Cos
t/Unit
Mid-Range Cost/Unit High-Range Cost/Unit
First Break Point
Second Break Point
Maximum Operating
Level
X
2828
Role of Integer Variables
• Ensure we express Activity as a combination of two consecutive breakpoints
• var InRegion{1..NBreaks} binary;
Tot
al C
ost
0
Minimum Sustainable
Level
First Break Point
Second Break Point
Maximum Operating
Level
InRegion[1] InRegion[2] InRegion[3]
2929
Constraints• Lambda[2] = 0 unless activity is between
– BreakPoint[1] and BreakPoint[2] (Region[2]) or – BreakPoint[2] and BreakPoint[3] (Region[3])
• Lambda[2] InRegion[2] + InRegion[3];
Tot
al C
ost
Minimum Sustainable
Level
First Break Point
Second Break Point
Maximum Operating
Level
InRegion[1] InRegion[2] InRegion[3]
BreakPoint[0] BreakPoint[1] BreakPoint[2] BreakPoint[3]
3030
We can’t go wrong
Volume of Activity0
Minimum Sustainable
Level
Low R
ange
Cos
t/Unit
Mid-Range Cost/Unit High-Range Cost/Unit
First Break Point
Second Break Point
Maximum Operating
Level
X
3131
Concave CostsFixed Cost Unit Cost From To
1 5 0 1
3 3 1 2
5 2 2 3
8 1 3 4Range Select One Limits Weighting Break Cost at Break Activity Cost0 to 1 (0.00) (0.00) (0.00) 0 1.00$ 2.25 9.50$ 1 to 2 - (0.00) (0.00) 1 6.00$ 2 to 3 1.00 1.00 0.75 2 9.00$ 3 to 4 - 1.00 0.25 3 11.00$
0 - 4 12.00$ Sum 1 1 Minimum 2.25
3232
In AMPL Speak• param NBreaks;• param BreakPoint{0..NBreaks};• param CostAtBreak{0..NBreaks};• var Lambda{0..NBreaks} >= 0;• var Activity;• var Cost;• s.t. DefineCost:• Cost = sum{b in 0..NBreaks} CostAtBreak[b]*Lambda[b];• s.t. DefineActivity:• Activity = sum{b in 0..NBreaks} BreakPoint[b]*Lambda[b];• s.t. ConvexCombination:• 1 = sum{b in 0..NBreaks}Lambda[b];
3333
And Activity in One Region
• InRegion[1] + InRegion[2] + InRegion[3] 1• Why 1?• If it is in Region[2]:
– Lambda[1] InRegion[1] + InRegion[2] = 1– Lambda[2] InRegion[2] + InRegion[3] = 1– Other Lambda’s are 0
3434
AMPL Speakparam NBreaks;param BreakPoint{0..NBreaks};param CostAtBreak{0..NBreaks};var Lambda{0..NBreaks} >= 0;var Activity;var Cost;s.t. DefineCost:Cost = sum{b in 0..NBreaks} CostAtBreak[b]*Lambda[b];s.t. DefineActivity:Activity = sum{b in 0..NBreaks} BreakPoint[b]*Lambda[b];s.t. ConvexCombination:1 = sum{b in 0..NBreaks}Lambda[b];
3535
What We Added
• var InRegion{1..NBreaks} binary;
• s.t. InOneRegion:
• sum{b in 1..NBreaks} InRegion[b] <= 1;
• s.t. EnforceConsecutive{b in 0..NBreaks-1}:
• Lambda[b] <= InRegion[b] + InRegion[b+1];
• s.t. LastLambda:
– Lambda[NBreaks] <= InRegion[NBreaks];
3636
Good News!• AMPL offers syntax to “automate” this• Read Chapter 14 of Fourer for details• <<BreakPoint[1], BreakPoint[2]; Slope[1],
Slope[2], Slope[3]>> Variable;
– Slope[1] before BreakPoint[1]– Slope[2] from BreakPoint[1] to BreakPoint[2]– Slope[3] after BreakPoint[2]– Has 0 cost at activity 0
3737
Modeling Time
• Incorporating Schedules into Network Flow Models
• Example– Given several scheduled pick-ups and
deliveries (must pick-up and deliver on-time)
– Question: How many vehicles required?– Assumption: One load on a vehicle at a
time (No shared capacity)
3838
Example
• How many vehicles are required to meet a schedule of departures and returns…
• No shared capacity
Leg Departure Return1 8:00 10:252 9:30 11:453 14:00 16:534 11:31 15:215 8:12 9:526 15:03 17:137 12:24 14:228 13:33 16:439 8:00 10:34
10 10:56 14:25
3939
Network ModelFrom\To LegLeg 1 2 3 4 5 6 7 8 9 10
1 0 0 1 1 0 1 1 1 0 12 0 0 1 0 0 1 1 1 0 03 0 0 0 0 0 0 0 0 0 04 0 0 0 0 0 0 0 0 0 05 0 0 1 1 0 1 1 1 0 16 0 0 0 0 0 0 0 0 0 07 0 0 0 0 0 1 0 0 0 08 0 0 0 0 0 0 0 0 0 09 0 0 1 1 0 1 1 1 0 1
10 0 0 0 0 0 1 0 0 0 0
From\To Leg
Leg 1 2 3 4 5 6 7 8 9 10
Total Immediate Successors
1 0 0 0 0 0 0 0 0 0 1 12 0 0 0 0 0 0 1 0 0 0 13 0 0 0 0 0 0 0 0 0 0 04 0 0 0 0 0 0 0 0 0 0 05 0 0 1 0 0 0 0 0 0 0 16 0 0 0 0 0 0 0 0 0 0 07 0 0 0 0 0 1 0 0 0 0 18 0 0 0 0 0 0 0 0 0 0 09 0 0 0 1 0 0 0 0 0 0 1
10 0 0 0 0 0 0 0 0 0 0 0
Total Immediate
Predecessors 0 0 1 1 0 1 1 0 0 1
Total Routes
Required 5
Assignments of successor legs
Which Legs can be in the same route
4040
How to Construct the Routes?From\To Leg
Leg 1 2 3 4 5 6 7 8 9 10
Total Immediate Successors
1 0 0 0 0 0 0 0 0 0 1 12 0 0 0 0 0 0 1 0 0 0 13 0 0 0 0 0 0 0 0 0 0 04 0 0 0 0 0 0 0 0 0 0 05 0 0 1 0 0 0 0 0 0 0 16 0 0 0 0 0 0 0 0 0 0 07 0 0 0 0 0 1 0 0 0 0 18 0 0 0 0 0 0 0 0 0 0 09 0 0 0 1 0 0 0 0 0 0 1
10 0 0 0 0 0 0 0 0 0 0 0
Total Immediate
Predecessors 0 0 1 1 0 1 1 0 0 1
Total Routes
Required
Assignments of successor legs
Route ending with
3Who precedes
3?
5 does
Route: 5 => 3
Who precedes 5?
4141
How to Construct the Routes?From\To Leg
Leg 1 2 3 4 5 6 7 8 9 10
Total Immediate Successors
1 0 0 0 0 0 0 0 0 0 1 12 0 0 0 0 0 0 1 0 0 0 13 0 0 0 0 0 0 0 0 0 0 04 0 0 0 0 0 0 0 0 0 0 05 0 0 1 0 0 0 0 0 0 0 16 0 0 0 0 0 0 0 0 0 0 07 0 0 0 0 0 1 0 0 0 0 18 0 0 0 0 0 0 0 0 0 0 09 0 0 0 1 0 0 0 0 0 0 1
10 0 0 0 0 0 0 0 0 0 0 0
Total Immediate
Predecessors 0 0 1 1 0 1 1 0 0 1
Total Routes
Required
Assignments of successor legs
Route ending with
6
Who precedes 6?
7 does
Route: 2 => 7 => 6
Who precedes 7?
2 does
Who precedes 2?
4242
2nd Example of Time
• How many vehicles?
• Common: – Schedule provided– No shared capacity
• Different: Not just one terminal
Trip From Departure To Arrival From\To Port1 Port21 Port2 0 Refinery3 12 Refinery1 21 162 Port1 8 Refinery1 29 Refinery2 19 153 Port1 32 Refinery2 51 Refinery3 13 124 Port2 49 Refinery3 61
4343
As a Network Problem
Service RequirementsTrip From Departure To Arrival Deadhead Travel Times
1 Port2 0 Refinery3 12 From\To Port1 Port22 Port1 8 Refinery1 29 Refinery1 21 163 Port1 32 Refinery2 51 Refinery2 19 154 Port2 49 Refinery3 61 Refinery3 13 12
Which Trips can be in the same routeFrom\To TripTrip 1 2 3 4
1 0 0 1 1 These calculations determine whether the row and column are different and 2 0 0 0 1 if the arrival time of the row's trip plus the deadhead travel time from the row trip's destination 3 0 0 0 0 to the column trip's origin is less than or equal to the departure time of the column trip.4 0 0 0 0
Assignments of successor tripsFrom\To Trip
Trip 1 2 3 4
Total Immediate Successors
1 02 03 04 0
Total Immediate
Predecessors 0 0 0 0Total Routes
Required
4
4444
Singapore Electric Generator
Unit Costs Jan Feb Mar Apr. MayProduction 28.00$ 27.00$ 27.80$ 29.00$
Inventory 0.30$ 0.30$ 0.30$ 0.30$
Production Qty 0 0 0 0Production Limits 60 62 64 66
Beginning Inventory 15 -43 -79 -113Delivery Reqmts 58 36 34 59 MinimumEnding Inventory (43) (79) (113) (172) 7
Production Cost -$ -$ -$ -$ Inventory Cost (4.20)$ (18.30)$ (28.80)$ (42.75)$ Total
Total Cost (4.20)$ (18.30)$ (28.80)$ (42.75)$ (94.05)$
Singapore Electric Generator Production
4545
Average Balances
• Assuming Smooth Demands
Averages (Starting + Ending)/2
4646
Inventory
• Balancing Your Checkbook– Previous Balance + Income - Expenses = New Balance
• Modeling Dynamic Inventory– Starting Inv. + Production - Shipments = Ending Inv.
4747
Singapore Electric Generator
Unit Costs Jan Feb Mar Apr. MayProduction 28.00$ 27.00$ 27.80$ 29.00$
Inventory 0.30$ 0.30$ 0.30$ 0.30$
Production Qty 0 0 0 0Production Limits 60 62 64 66
Beginning Inventory 15 -43 -79 -113Delivery Reqmts 58 36 34 59 MinimumEnding Inventory (43) (79) (113) (172) 7
Production Cost -$ -$ -$ -$ Inventory Cost (4.20)$ (18.30)$ (28.80)$ (42.75)$ Total
Total Cost (4.20)$ (18.30)$ (28.80)$ (42.75)$ (94.05)$
Singapore Electric Generator Production
4848
Network Model
• Ending Inv = Calculated Ending Inv
• Prod. Qty <= Production Limits
• FinalInv >= MinimumEndingInv
Bounds
4949
Network Model
• Ending Inv = Calculated Ending Inv
• How Many constraints is this?
• Which constraints does Ending Inv for Jan appear in?
• With what coefficients?
• Which constraints does Production Qty in February appear in?
5050
Summary• Network Flows
– Transportation• Supply & Demand
– Minimum Cost Flows • Supply, Demand &Flow conservation
• Multicommodity Flows– Conserve flow of each commodity
• Weight, Cube & Conveyances– Not a network flow model– Non-integral solutions
• Non-Linear Costs– Requires integer variables
• Modeling Time
5151
Next
• Inventory– Deterministic (predominantly)
• Pipeline
• Cycle
– Stochastic (later)• Safety stock safety