8/13/2019 03 Networks 2 Print
1/45
Network Models II
Shortest PathCross Docking
Enhance Modeling SkillsModeling with AMPL
15.057 Spring 03 Vande Vate 1
8/13/2019 03 Networks 2 Print
2/45
The Shortest Path Model
aFind theshortestpath fromHome to 5
H
H
6
53
4
21
8
3
3
21
6
14
2 1
3
7
1
15.057 Spring 03 Vande Vate 2
8/13/2019 03 Networks 2 Print
3/45
Directiona
Two-waystreets a One-way
streets H
H
6
53
4
21
8
3
3
21
6
14
2 1
3
7
1
15.057 Spring 03 Vande Vate 3
8/13/2019 03 Networks 2 Print
4/45
03ShortestPathModel.xls
ConnectivityFrom\To Home Site 1 Site 2 Site 3 Site 4 Site 5 Site 6 Site 7
DistanceFrom\To Home Site 1 Site 2 Site 3 Site 4 Site 5 Site 6 Site 7
Home 1 Home 4 7 8Site 1 1 1 1 Site 1 4 6 1Site 2 1 1 1 Site 2 6 1 2Site 3 1 1 1 Site 3 1 1 1Site 4 1 1 1 1 Site 4 7 1 3 2Site 5 1 1 1 Site 5 2 3 3Site 6 1 1 1 Site 6 3 3Site 7 1 1 1 Site 7 8 2 1
RouteFrom\To Home Site 1 Site 2 Site 3 Site 4 Site 5 Site 6 Site 7
TotalFrom
TotalDistance Home Site 1 Site 2 Site 3 Site 4 Site 5 Site 6 Site 7
TotalFrom
Home 0 Home 0 0 0Site 1 0 Site 1 0 0 0Site 2 0 Site 2 0 0 0Site 3 0 Site 3 0 0 0
Site 4 0 Site 4 0 0 0Site 5 0 Site 5 0 0 0Site 6 0 Site 6 0 0 0Site 7 0 Site 7 0 0 0
Total To 0 Total To 0 0 0Total From -
Total To 0Net Required 1 -1 0
Shortest Path Model
11
1
00 000000 000000 000000 0000
00 000000 000000 000000 0000
0000000 00 0000
00000000000 0
15.057 Spring 03 Vande Vate 4
8/13/2019 03 Networks 2 Print
5/45
Challengea
Build a Solver model
15.057 Spring 03 Vande Vate 5
8/13/2019 03 Networks 2 Print
6/45
A Solver Model
aThe Objective: Minimize $U$21a The Variables: $C$13:$J$20
a The Constraints:Only travel on existing edges
$C$13:$J$20
8/13/2019 03 Networks 2 Print
7/45
Flow Conservation
aNumber From - Number To = Net Requireda Number of times - Number of = ?we leave times we enter
a +1 at Home (we leave once)a -1 at Site 5 (we arrive once)a 0 everywhere else
each time we arrive (if ever), we leave
15.057 Spring 03 Vande Vate 7
8/13/2019 03 Networks 2 Print
8/45
Compare with Assignment Modela Assignment Model
Sum across each row = 1Sum down each column = 1
Each variable appears in 2 constraintsa Shortest Path Model
Sum across a row - Sum down the column = 0Trips out of a site - Trips into the siteEach variable appears in ? constraints
15.057 Spring 03 Vande Vate 8
8/13/2019 03 Networks 2 Print
9/45
Network Flow Problems
a Each variable appears in at most two constraints
At most one constraint as - the variable At most one constraint at + the variable
a AssignmentSum across each row = 1Sum down each column = 1
aShortest PathSum across the a row - sum down the col = #
15.057 Spring 03 Vande Vate 9
8/13/2019 03 Networks 2 Print
10/45
Bounds
a Variables can also have boundse.g., in the Shortest Path Model:
Number of times we use each variableLower bound: >= 0Upper bound:
8/13/2019 03 Networks 2 Print
11/45
Properties of Network Flowsa If the bounds and RHS are integral, the
solution will be integrala It the costs are integral, the reduced costs
and marginal values will be integrala Can be solved very quicklya Limited demands on memory
15.057 Spring 03 Vande Vate 11
8/13/2019 03 Networks 2 Print
12/45
Crossdocking
a 2 customersa Minimize shipping costs
a 3 plantsa 2 distribution centers
15.057 Spring 03 Vande Vate 12
8/13/2019 03 Networks 2 Print
13/45
A Network Model
15.057 Spring 03 Vande Vate
Unit Shipping Costs Arc Capacities
Plant toDC DC 1 DC 2 Costs Plant to DC DC 1 DC 2Plant 1 5.0$ 5.0$ Capacities Costs Plant 1 200 200Plant 2 1.0$ 1.0$ Flows Flows Plant 2 200 200Plant 3 1.0$ 0.5$ Payments Payments Plant 3 200 200
DC toCustomer DC 1 DC 2
DC toCustomer DC 1 DC 2
Customer 1 2.0$ 2.0$ Customer 1 200 200Customer 2 12.0$ 12.0$ Customer 2 200 200
Shipments Payments
Plant toDC DC 1 DC 2 Total Out Supply Plant to DC DC 1 DC 2 Total OutPlant 1 - - - 200 Plant 1 -$ -$ -$Plant 2 - - - 300 Costs Plant 2 -$ -$ -$
Plant 3 - - - 100 Capacities Plant 3 -$ -$ -$Total In - - Flows Total In -$ -$ -$Costs
CapacitiesDC to
Customer DC 1 DC 2 Total In DemandDC to
Customer DC 1 DC 2 Total OutPayments Customer 1 - - - 400 Customer 1 -$ -$ -$
Customer 2 - - - 180 Customer 2 -$ -$ -$
Total Out - - Total In -$ -$ -$
Net Flow DC 1 DC 2- - Total Shipping Cost -$
Minimum Cost Network Flow Problem
Transportation Costs ($ 000/Ton) Transportation Capacities
8/13/2019 03 Networks 2 Print
14/45
Challengea Build a Solver Model
15.057 Spring 03 Vande Vate 14
8/13/2019 03 Networks 2 Print
15/45
A Solver Model
a Objective: Minimize $K$28a Variables: $C$17:$D$19, $C$23:$D$24 a Constraints:
Do not exceed supply at the plants$E$17:$E$19 = $F$23:$F$24
Do not exceed shipping capacity$C$17:$D$19
8/13/2019 03 Networks 2 Print
16/45
And...
a Flow conservation at the DCs$C$28:$D$28 = 0
a Supply and Demand like Autopowera Flow conservation at DCs like Shortest Path
15.057 Spring 03 Vande Vate 16
8/13/2019 03 Networks 2 Print
17/45
Network Flows: Good News a Lots of applications a Simple Models a Optimal Solutions Quickly a Integral Data, Integral Answers
15.057 Spring 03 Vande Vate 17
8/13/2019 03 Networks 2 Print
18/45
Network Flows: Bad News a Underlying Assumptions
Single Homogenous ProductLinear Costs
No conversions or losses...
15.057 Spring 03 Vande Vate 18
8/13/2019 03 Networks 2 Print
19/45
Homogenous Product
15.057 Spring 03 Vande Vate 19
Must be able to interchange positions of product anywhere
8/13/2019 03 Networks 2 Print
20/45
Linear Costs a No Fixed Chargesa No Volume Discountsa No Economies of Scale
15.057 Spring 03 Vande Vate 20
8/13/2019 03 Networks 2 Print
21/45
Summarya Network FlowsSimple Formulation
Flow Out (sum across a row) = DemandFlow In - Flow Out = Constant
Limited byHomogenous ProductLinear Costsetc.
Integer Data give Integral Solutions
15.057 Spring 03 Vande Vate 21
8/13/2019 03 Networks 2 Print
22/45
Modeling with AMPLa Problems with Excel Solver
Integration of Model and DataExample:
Change the time horizon of our Inventory Model
Excel is a limited database toola Algebraic Modeling Languages
Separate the Model from the Data Keep the data in databases
15.057 Spring 03 Vande Vate 22
8/13/2019 03 Networks 2 Print
23/45
How they work
Conceptual Model
Data
Algebraic Modeling LanguageAMPL/OPL/GAMS/XPress/...
OptimizerCPLEXOSLXPress
15.057 Spring 03 Vande Vate 23
8/13/2019 03 Networks 2 Print
24/45
8/13/2019 03 Networks 2 Print
25/45
Our Use of AMPL
a Pseudo AMPL to discuss modelsIn classIn exams
a Need to be precise aboutWhats a parameter, variable, Indexing: relationships between variables,data, constraints
a Challenges and Project
15.057 Spring 03 Vande Vate 25
8/13/2019 03 Networks 2 Print
26/45
Is this necessary/valuable?a AMPL is very detailed
Expect 1 or 2 per team to masterRest to read and understand
a Brings out the real issuesPractical implementation -- you can oversee
Data issues -- the real challengea Valuable tool
15.057 Spring 03 Vande Vate 26
8/13/2019 03 Networks 2 Print
27/45
The Transportation Modela set ORIG; a set DEST; a param supply {ORIG}; a param demand {DEST}; a param cost {ORIG, DEST}; a var Trans {ORIG, DEST} >= 0;
15.057 Spring 03 Vande Vate 27
8/13/2019 03 Networks 2 Print
28/45
Transportation Modelminimize Total_Cost:
sum{o in ORIG, d in DEST}cost[o,d]*Trans[o,d];
s.t. Supply {o in ORIG}:sum{d in DEST} Trans[o,d] = demand[d];
15.057 Spring 03 Vande Vate 28
8/13/2019 03 Networks 2 Print
29/45
The Dataa An Access Database called TransportationData.mdba Tables in the database
Origins: Supply information
Destinations: Demand information
Origin Supply Amsterdam 500
Antwerp 700The Hague 800
Destination DemandLeipzig 400Liege 200Nancy 900Tilburg 500
15.057 Spring 03 Vande Vate 29
8/13/2019 03 Networks 2 Print
30/45
The Costs
a Cost: Unittransportationcosts
origin destination cost Amsterdam Leipzig 120 Amsterdam Liege 41 Amsterdam Nancy 130 Amsterdam Tilburg 59.5 Antwerp Leipzig 61 Antwerp Liege 100 Antwerp Nancy 40 Antwerp Tilburg 110
The Hague Leipzig 102.5The Hague Liege 122The Hague Nancy 90The Hague Tilburg 42
15.057 Spring 03 Vande Vate 30
8/13/2019 03 Networks 2 Print
31/45
8/13/2019 03 Networks 2 Print
32/45
Reading Data
table OriginTable IN "ODBC""D:\Personal\15057\TransportationData.mdb" "Origins": ORIG
8/13/2019 03 Networks 2 Print
33/45
Explanation
a "D:\Personal\15057\TransportationData.mdb is thepath to the database. Alternatively you can create aDSN (data source name) for this file, say TransportData,and use the command DSN=TransportData.
a "Origins is the name of the table in the database.
Alternatively we can use an SQL command like SQL=SELECT * FROM Originsa The : is syntax. What follows is the mapping of the data
we read to AMPL objects that will hold it.a The brackets [] around Origin mean that this field in the
database indexes the data, e.g., 500 is the supply for Amsterdam.
15.057 Spring 03 Vande Vate 33
8/13/2019 03 Networks 2 Print
34/45
Explanation Continueda ORIG
8/13/2019 03 Networks 2 Print
35/45
8/13/2019 03 Networks 2 Print
36/45
Explanation
a "D:\Personal\15057\TransportationData.mdb is thepath to the database. Alternatively you can create aDSN (data source name) for this file, say TransportData,and use the command DSN=TransportData.
a Destinations is the name of the table in the database.
Alternatively we can use an SQL command like SQL=SELECT * FROM Destinationsa The : is syntax. What follows is the mapping of the data
we read to AMPL objects that will hold it.a The brackets [] around Destination mean that this field
in the database indexes the data, e.g., 400 is thedemand for Leipzig.
15.057 Spring 03 Vande Vate 36
8/13/2019 03 Networks 2 Print
37/45
Explanation Continueda DEST
8/13/2019 03 Networks 2 Print
38/45
Reading Costtable CostTable IN "ODBC"
"D:\Personal\15057\TransportationData.mdb" "Cost": [origin, destination], cost;
Explanation:a table is a keyword that says we will read or write data a CostTable is a name we made up. No other AMPL
model entity can have this namea IN is a key word that says we are reading data.a ODBC says we are using ODBC to read the data
15.057 Spring 03 Vande Vate 38
8/13/2019 03 Networks 2 Print
39/45
8/13/2019 03 Networks 2 Print
40/45
Explanation Continueda We dont have an
8/13/2019 03 Networks 2 Print
41/45
Running AMPLa model d:\15057\TransportationModel.mod; a option solver cplex; # use cplex to solve a solve; a display Trans;
15.057 Spring 03 Vande Vate 41
8/13/2019 03 Networks 2 Print
42/45
Writing Output
table TransOutTable OUT "ODBC""D:\Personal\15057\TransportationData.mdb"
"TransOut": {origin in ORIG, destination in DEST:
Trans[origin, destination] > 0}
-> [origin, destination], Trans[origin,destination]~Trans;write table TransOutTable;Explanation:
a table is a keyword that says we will read or write dataa TransOutTable is a name we made up. No other AMPL
model entity can have this name
15.057 Spring 03 Vande Vate 42
8/13/2019 03 Networks 2 Print
43/45
Explanationa OUT is a key word that says we are writing data.a ODBC says we are using ODBC to write the dataa "D:\Personal\15057\TransportationData.mdb is the
path to the database. Or you can use DSN=a "TransOut is the name of the table to create. AMPL
drops and writes this table. Any data currently in thetable is lost.
a : is syntax. It separates the description of thedestination from the definition of the data and themapping of the columns
15.057 Spring 03 Vande Vate 43
8/13/2019 03 Networks 2 Print
44/45
More Explanation
a {origin in ORIG, destination in DEST:Trans[origin, destination] > 0} defines the index set
that will control the data to write out. This says to onlyreport on origin-destination pairs where we actuallysend a positive flow.
a -> is syntax. It separates the indexing from the datadefinition and mapping to fields of the output table.
a [origin, destination] indicates that the records of theoutput table are indexed by the origin-destination pairs.
AMPL will write a new record for each pair.a Trans[origin,destination]~Trans says to create a field
called Trans in the table and to populate it with thevalues of the Trans variable.
15.057 Spring 03 Vande Vate 44
8/13/2019 03 Networks 2 Print
45/45