Module 9c (ppt file)

advertisement
Computational Methods for
Management and Economics
Carla Gomes
Module 9c
Network Models
Special cases of the Minimum Cost Flow Problem –
shortest path problem
(Slides adapted from J.Orlin’s and Hillier’s)
Special Cases of the Minimum Cost Flow Model
• Transportation and assignment problem
(module 8)
• Shortest path problem
Shortest Path Problem
The Shortest Path Problem
2
4
4
2
2
1
1
2
3
4
6
2
3
3
5
What is the shortest path from a source node (often
denoted as s) to a sink node, (often denoted as t)?
What is the shortest path from node 1 to node 6?
Assumptions for this lecture:
1. There is a path from the source to all other nodes.
2. All arc lengths are non-negative
Shortest Path Problem
• Where does it arise in practice?
– Common applications
• shortest paths in a vehicle
• shortest paths in internet routing
– Less obvious: close connection to dynamic
programming
• How will we solve the shortest path problem?
– Dijkstra’s algorithm
Shortest Path Problem
2
4
4
2
2
1
1
2
3
4
6
2
3
3
5
Find the
shortest paths
by inspection.
Shortest Path Problem
0
2
4
0
4
2
1
2
1
1
2
3
4
6
-1
2
3
3
0
All arcs have capacity 1
5
0
Shortest Path Problem
Special case of
Min. Cost Flow
Problem.
Why?
Representation as an integer program
• An integer program is a linear program in which
some or all of the variables are required to be
integer
• We will formulate the shortest path problem as an
integer program.
– Find the shortest path from node 1 to node 6
• Decision variables:
– xij = 1 if arc (i,j) is in the path.
– xij = 0 if arc (i,j) is not in the path
Constraint matrix
of Shortest Path Problem
2
4
1
6
3
5
x12
x13 x23 x24 x25 x35 x46 x54 x56
1
1
0
0
0
0
0
0
0
=
1
-1
0
0
0
0
-1
0
0
1
-1
0
0
1
0
-1
0
1
0
0
-1
0
1
0
-1
0
0
1
0
0
0
-1
1
0
0
0
1
=
=
=
=
0
0
0
0
0
0
0
0
0
0
-1
0
-1
=
-1
The constraint matrix is the node arc incidence matrix
On Incidence Matrices
• If the constraint matrix for a linear program is a node-arc
incidence matrix (at most one 1 and at most one –1 per
column), then the linear program solves in integer optima.
• Thus, we can solve the shortest path problem as an LP, and
get the optimum path.
On Incidence Matrices
• If the constraint matrix for a linear program is a
node-arc incidence matrix (at most one 1 and at
most one –1 per column), then the linear program
solves in integer optima.
• Thus, we can solve the shortest path problem as an
LP, and get the optimum path.
Shortest Path Pivoting
Littletown Fire Department
• Littletown is a small town in a rural area.
• Its fire department serves a relatively large geographical
area that includes many farming communities.
• Since there are numerous roads throughout the area,
many possible routes may be available for traveling to
any given farming community.
Question: Which route from the fire station to a
certain farming community minimizes the total
number of miles?
The Littletown Road System
8
6
A
1
3
6
Fire
Station
4
2
C
D
6
7
6
3
3
B
5
4
4
F
Farming
Community
G
5
E
2
4
H
7
The Network Representation
A
3
(Origin)
O
1
6
4
B
6
4
5
2
D
3
E
7
C
8
F
3
6
5
4
G
2
H
4
6
7
T
(Destination)
Spreadsheet Model
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
B
C
D
From
Fire St.
Fire St.
Fire St.
A
A
B
B
B
B
C
C
D
D
E
E
E
E
F
F
G
G
G
H
H
To
A
B
C
B
D
A
C
D
E
B
E
E
F
D
F
G
H
G
Farm Com.
F
H
Farm Com.
G
Farm Com.
On Route
1
0
0
1
0
0
0
0
1
0
0
0
0
0
1
0
0
0
1
0
0
0
0
0
Total Distance
19
E
F
Distance
3
6
4
1
6
1
2
4
5
2
7
3
8
3
6
5
4
3
4
3
2
6
2
7
G
H
I
J
K
Nodes
Fire St.
A
B
C
D
E
F
G
H
Farm Com.
Net Flow
1
0
0
0
0
0
0
0
0
-1
=
=
=
=
=
=
=
=
=
=
Supply/Demand
1
0
0
0
0
0
0
0
0
-1
Note: in order to use the LP model we have to consider direct arcs 
Replace undirected arcs with two arcs – in particular the cases in which it makes sense
to travel in both directions.
Assumptions of a Shortest Path Problem
1. You need to choose a path through the network that starts at a
certain node, called the origin, and ends at another certain node,
called the destination.
2. The lines connecting certain pairs of nodes commonly are links
(which allow travel in either direction), although arcs (which
only permit travel in one direction) also are allowed.
3. Associated with each link (or arc) is a nonnegative number
called its length. (Be aware that the drawing of each link in the
network typically makes no effort to show its true length other
than giving the correct number next to the link.)
4. The objective is to find the shortest path (the path with the
minimum total length) from the origin to the destination.
Applications of Shortest Path
Problems
1.Minimize the total distance traveled.
2.Minimize the total cost of a sequence of
activities.
3.Minimize the total time of a sequence of
activities.
Minimizing Total Cost: Sarah’s Car Fund
• Sarah has just graduated from high school.
• As a graduation present, her parents have given her a car fund of
$21,000 to help purchase and maintain a three-year-old used car for
college.
• Since operating and maintenance costs go up rapidly as the car ages,
Sarah may trade in her car on another three-year-old car one or more
times during the next three summers if it will minimize her total net
cost. (At the end of the four years of college, her parents will trade
in the current used car on a new car for Sarah.)
Question: When should Sarah trade in her car (if at all)
during the next three summers?
Sarah’s Cost Data
Operating and
Maintenance Costs
for Ownership Year
Trade-in Value at End
of Ownership Year
Purchase
Price
1
2
3
4
1
$12,000
$2,000
$3,000
$4,500
$6,500
2
3
$8,500 $6,500 $4,500
4
$3,000
Shortest Path Formulation
25,000
Shortest path
17,000
10,500
10,500
(Origin)
0
1
5,500
5,500
2
5,500
3
5,500
4
(Destination)
10,500
x
Buying
at moment x
y
Trading in
at moment Y
17,000
12 + 2 +3 - 6.5
Arc length = purchase price + operating and maintenance cost- trade-in value
Spreadsheet Model
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
B
C
D
E
Year 1
Year 2
Year 3
Year 4
Operating &
Maint. Cost
$2,000
$3,000
$4,500
$6,500
Trade-in Value
at End of Year
$8,500
$6,500
$4,500
$3,000
Purchase
Price
$12,000
From
Year 0
Year 0
Year 0
Year 0
Year 1
Year 1
Year 1
Year 2
Year 2
Year 3
To
Year 1
Year 2
Year 3
Year 4
Year 2
Year 3
Year 4
Year 3
Year 4
Year 4
On Route
0
1
0
0
0
0
0
0
1
0
Cost
$5,500
$10,500
$17,000
$25,000
$5,500
$10,500
$17,000
$5,500
$10,500
$5,500
Total Cost
$21,000
F
G
H
I
J
Nodes
Year 0
Year 1
Year 2
Year 3
Year 4
Net Flow
1
0
0
0
-1
=
=
=
=
=
Supply/Demand
1
0
0
0
-1
Planning Vehicle Replacement at Phillips Petroleum
• Phillips Petroleum had a fleet of 1,500 cars and 3,800 trucks.
• Modeled replacement strategy as shortest path model (20-year time
horizon)—solved model once for each class of vehicle.
• Could keep, purchase (replace), or lease, at 3-month intervals.
• Costs considered included:
– Maintenance and operating costs (fuel, oil, repair),
– Leasing cost for leased vehicles,
– Purchasing cost for purchased vehicles,
– State license fees and road taxes,
– Tax effects (investment tax credits, depreciation)
• First used to make lease-or-buy decision, then vehicle-replacement
strategy, and more recently for other equipment (non-vehicle).
For more details, see Waddell (1983) Jul-Aug Interfaces article, “A Model for Equipment
Replacement Decisions and Policies”.
Dijkstra’s Algorithm for the
Shortest Path Problem
2
4
4
2
2
1
1
2
3
4
6
2
3
3
5
Exercise: find the shortest path from node 1 to all
other nodes. Keep track of distances using labels, d(i)
and each node’s immediate predecessor, pred(i).
d(1)= 0, pred(1)=0;
d(2) = 2, pred(2)=1
Find the other distances, in order of increasing
distance from node 1.
A Key Step in Shortest Path Algorithms
• Let d( ) denote a vector of temporary distance labels.
• d(j) is the length of some path from the origin node 1 to
node j.
Procedure Update(i)
for each (i,j)  A(i) do
if d(j) > d(i) + cij then d(j) : = d(i) + cij and
pred(j) : = i;
Path P
1
62
i
10
78
j
72
Up to this point, the best path from 1 to j has length 78
But P, (i,j) is a path from 1 to j of length 72.
Dijkstra’s Algorithm
Initialize distances.
begin
d(s) : = 0 and pred(s) : = 0;
d(j) : =  for each j  N - {s};
LIST : = {s};
while LIST  f do
begin
let d(i) : = min {d(j) : j  LIST};
remove node i from LIST;
update(i)
if d(j) decreases, place j in LIST
end
end
LIST = set of
temporary nodes
Select the node i on
LIST with minimum
distance label, and
then update(i)
Scan the arcs out
of i, and update
d( ), pred( ), and
d(4) = 
\ 6 LIST
pred(4) = 2
An Example
\ 2
d(2) = 
pred(2) = 1
2
d(1) = 0 11
pred(1) = 0
22
44
2
1
2
3
4
2
3
The
End
4
3
d(6) = 
\ 6
pred(6) = 5
66
5
\ 4
\ 4\ 3
d(3) = 
d(5) = 
pred(3) = 1\ 2
pred(5) = 2
LIST = {1,
\ 2,\ 3,
\ 6}
\ 4,\ 5,
\
Find
the
node
on
Find
the node
Initialize
the ii on
LIST
with
LIST
withand
distances
minimum
minimum
LIST.
distance.
distance.
The Output from Dijkstra’s
findnode
the has
Algorithm To
Each
2
6
4
2
4
2
0
shortest
path
one incoming
from node j, trace
arc (except for
back from the
the
nodesource)
to the
source.
2
1
1
2
3
2
4
3
3
5
6
6
4
3
Dijkstra provides a shortest path from node 1 to
all other nodes. It provides a shortest path tree.
Note that this tree is an out-tree.
Comments on Dijkstra’s
Algorithm
• Dijkstra’s algorithm makes nodes permanent in
increasing order of distance from the origin node.
• Dijkstra’s algorithm is efficient in its current
form. The running time grows as n2, where n is
the number of nodes
• It can be made much more efficient
• In practice it runs in time linear in the number of
arcs (or almost so).
Download