Introduction to Networks

advertisement
Introduction to Networks
z
z
z
z
Network Models (Applications)
Notation and Terminology
The Shortest Path Problem
Dijkstra’s Algorithm for Solving the Shortest
Path Problem
1
MIT and James Orlin © 2003
Network Models
z
z
z
z
Optimization models that exhibit a very special
structure
For special cases, this structure to dramatically
reduce computational complexity
First widespread application of LP to problems of
industrial logistics
Addresses huge number of diverse applications
2
MIT and James Orlin © 2003
Networks are Everywhere
z
Physical Networks
–
–
–
–
z
Road Networks
Railway Networks
Airline traffic Networks
Electrical networks, e.g., the power grid
Abstract networks
– organizational charts
– precedence relationships in projects
z
Others?
3
MIT and James Orlin © 2003
Notation and Terminology
Note: Network terminology is not (and never will be)
standardized. The same concept may be denoted in
many different ways.
Called:
• NETWORK
• directed graph
• digraph
• graph
1
3
2
4
Also Seen
Graph G = (V,E)
Network G = (N, A)
Vertex set V = {1,2,3,4}
Node set N = {1, 2, 3, 4}
Edge set:
{(1,2),
(1,3),
(3,2),
(3,4),
(2,4)}
Arc Set
A={1-2,1-3,3-2,3-4,2-4}
4
MIT and James Orlin © 2003
Directed and Undirected Networks
1
b
c
a
4
2
1
e
3
d
An Undirected Graph
•
b
c
a
2
e
4
3
d
A Directed Graph
Networks are used to transport commodities
• physical goods (products, liquids)
• communication
• electricity, etc.
•
The field of Network Optimization concerns
optimization problems on networks
MIT and James Orlin © 2003
5
Overview:
z
z
z
Networks and graphs are powerful modeling
tools.
Most OR models have networks or graphs as
a major aspect
Representations of networks
– A great insight from computer scientists: how
data is represented is important to how it is used
6
MIT and James Orlin © 2003
Applications of Network Optimization
Applications
Physical analog
of nodes
Physical analog
of arcs
Flow
phone exchanges,
Cables, fiber optic Voice messages,
Communication
computers,
links, microwave
Data,
systems
transmission
relay links
Video transmissions
facilities, satellites
Pumping stations
Reservoirs, Lakes
Integrated
Gates, registers,
computer circuits
processors
Hydraulic systems
Pipelines
Water, Gas, Oil,
Hydraulic fluids
Wires
Electrical current
Mechanical systems
Joints
Rods, Beams,
Springs
Heat, Energy
Transportation
systems
Intersections,
Airports,
Rail yards
Highways,
Airline routes
Railbeds
Passengers,
freight,
vehicles,
operators7
MIT and James Orlin © 2003
Representation of arc lists
(for directed graphs)
1
b
2
c
a
4
1: (1,2), (1,4)
e
3
d
A Directed Graph
2: (2,3)
3: ∅
4: (4,2), (4,3)
•Create a list of arcs for each node
•There are lots of very similar variants of this
type of representation
8
MIT and James Orlin © 2003
Path: Example: 5, 2, 3, 4.
(or 5, c, 2, b, 3, e, 4)
•No node is repeated.
•Directions are ignored.
1
Directed Path . Example: 1, 2, 5, 3, 4
(or 1, a, 2, c, 5, d, 3, e, 4)
•No node is repeated.
•Directions are important.
Cycle (or circuit or loop)
1, 2, 3, 1. (or 1, a, 2, b, 3, e)
•A path with 2 or more nodes, except
that the first node is the last node.
•Directions are ignored.
Directed Cycle: (1, 2, 3, 4, 1) or
1, a, 2, b, 3, c, 4, d, 1
•No node is repeated.
•Directions are important.
MIT and James Orlin © 2003
5
c
a
b
2
c
1
a
a
2
2
3 e
4
d
b
3 e
4
b
e
1
5
d
d
3
c
4
a
2
e
1
d
b
3
c
4
9
Walks
1
b
2
c
a
4
1
e
3
d
5
a
4
b
2
c
e
3
d
5
Walks are paths that can repeat nodes and arcs
Example of a directed walk: 1-2-3-5-4-2-3-5
A walk is closed if its first and last nodes are the same.
A closed walk is a cycle except that it can repeat nodes
and arcs.
10
MIT and James Orlin © 2003
More terminology
1
3
2
4
An undirected network is connected
if every node can be reached from
every other node by a path
5
1
3
2
4
5
MIT and James Orlin © 2003
A directed network is connected if
it’s undirected version is connected.
This directed graph is connected,
even though there is no directed
path between 2 and 5.
11
More Definitions
1
3
2
4
A network is connected if every node
can be reached from every other
node by following a sequence of
arcs in which direction is ignored.
5
A spanning tree is a connected subset of a network
including all nodes, but containing no cycles.
1
3
1
3
1
3
2
4
2
4
2
4
5
MIT and James Orlin © 2003
5
5
12
More on Trees
z
An out-tree is a spanning tree in which every node has
exactly one incoming arc except for the root.
z Theorem. In an out-tree, there is a directed path from the
root to all other nodes. (All paths come out of the root).
1
1
3
2
4
5
2
4
7
12
3
5
8
6
9
10
11
13
13
MIT and James Orlin © 2003
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
14
MIT and James Orlin © 2003
Shortest Path Problem
z
Where does it arise in practice?
– Common applications
• shortest paths in a vehicle
• shortest paths in internet routing
• shortest paths around MIT (TAMU)
– Less obvious: close connection to dynamic
programming which we will see in later lectures
z
How will we solve the shortest path problem?
– Dijkstra’s algorithm
15
MIT and James Orlin © 2003
Dijkstra’s Algorithm for the Shortest
Path Problem
2
4
4
2
2
1
1
2
3
4
6
2
3
3
5
Exercise with
your partner.
Find the
shortest paths
by inspection.
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
16
distance
from
node
1.
MIT and James Orlin © 2003
A Key Step in Shortest Path Algorithms
z
z
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
72
j
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.
17
MIT and James Orlin © 2003
Dijkstra’s Algorithm
Initialize distances.
begin
d(s) : = 0 and pred(s) : = 0;
d(j) : = ∞ for each j ∈ N - {s};
LIST : = {s};
while LIST ≠ φ 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)
18
MIT and James Orlin © 2003
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
Find
the node
node
on
Initialize
the ii on
LIST
with
LIST
withand
distances
minimum
minimum
LIST.
distance.
distance.
The Output from Dijkstra’s
Algorithm
To
findnode
the has
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
6
6
5
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.
20
MIT and James Orlin © 2003
Comments on Dijkstra’s Algorithm
z
z
z
z
z
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).
How can we recognize a shortest path tree? We
will see that next lecture.
21
MIT and James Orlin © 2003
Representation as an integer program
z
An integer program is a linear program in
which some or all of the variables are
required to be integer
z
We will formulate the shortest path
problem as an integer program.
– Find the shortest path from node 1 to node 6
z
Decision variables:
– xij = 1 if arc (i,j) is in the path.
– xij = 0 if arc (i,j) is not in the path
22
MIT and James Orlin © 2003
Constraints
z
z
z
z
There is one arc out of node 1
There is one arc into node 6
For every other node i, the number of arcs
on the path entering node i is the number
of arcs leaving node i.
Other constraints can be added, but this
turns out to be enough.
23
MIT and James Orlin © 2003
2
4
1
6
3
5
x12
x13 x23 x24 x25 x35 x46 x54 x56
1
-1
0
0
0
0
1
0
-1
0
0
0
0
1
-1
0
0
0
0
1
0
-1
0
0
0
1
0
0
-1
0
0
0
1
0
-1
0
0
0
0
1
0
-1
0
0
0
-1
1
0
0
0
0
0
1
-1
=
=
=
=
=
=
The constraint matrix is the node arc incidence matrix
MIT and James Orlin © 2003
1
0
0
0
0
-1
24
On Incidence Matrices
z
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.
z
Thus, we can solve the shortest path problem as an LP, and
get the optimum path.
25
MIT and James Orlin © 2003
Summary
z
z
z
z
The shortest path problem
Dijkstra’s algorithm finds the shortest path from
node 1 to all other nodes in increasing order of
distance from the source node.
The bottleneck operation is identifying the
minimum distance label. One can speed this
up, and get an incredibly efficient algorithm
Formulation of shortest path as an LP
26
MIT and James Orlin © 2003
Some final comments
z
The shortest path problem shows up
again and again in network optimization
z
There is an interesting connection with
dynamic programming
z
There are other solution techniques as
well. We’ll see one in a later lecture.
27
MIT and James Orlin © 2003
Download