lecture 6

advertisement
DMOR
Networks
Graphs: Koenigsberg bridges
Leonard Euler problem (1736)
Nodes
Edges
Is there a walk which uses each edge
exactly once?
Build two more bridges.
Each such walk has to enter and leave any given
node. The degree of any node has to be even.
Eulerian cycle
Hamiltonian cycle
Travelling salesman
problem
TSP - cycle
Duration:
2d7h2m
Length:
3615 km
TSP - trail
Duration:
2 d 4 h 37 m
Length:
3436 km
TSP – a real walk
Duration:
29 d 11 h 21 m
Length:
3485 km
Travelling salesman problem TSP
• Mathematically
min
𝑥 𝑖𝑗
𝑑𝑖𝑗 𝑥𝑖𝑗
𝑖
p. w.
𝑗
𝑖≠𝑗
𝑥𝑖𝑗 = 1, for all 𝑖
𝑗
𝑖≠𝑗
𝑥𝑖𝑗 = 1, for all 𝑗
𝑖
𝑖≠𝑗
𝑥𝑖𝑗 = 0 or 1,
for all 𝑖 and 𝑗, where 𝑖 ≠ 𝑗
• Variable xij = 1, if the salesman passes from i to j, 0 otherwise
• Going from one city to the same city is forbidden
• Is this all ???
TSP
• Is this all?
• Let’s say our solution with 5 cities is
x12=x23=x31=x45=x54=1
• It satisfies all the constraints. But it involves
subtours (cycles involving fewer than all cities)
• We need to introduce additional constraints
Subtour elimination
• For two cities
• For three cities
• For four cities
• Etc.
• In practical implementation too many constraints: with 30 cities there
would be 870 constraints eliminating only subtours of length 2
Subtour eleimination – second
approach
• Introduce nonnegative variables ui:
• Subtours are eliminated
• How many such constraints?
• (N-1)2-N, i.e. with 30 cities there would be 812 constraints.
Game
• http://www.tsp.gatech.edu/games/index.html
Introduction to networks
• Two main elements:
– arcs/edges
– nodes
• A graph is a structure consisting of nodes and arcs bewteen nodes
• A directed graph (a digraph) is a graph in which arcs have a given
direction
• A network is a graph (or digraph), in which arcs have a flow assigned
to it
• Simple examples:
Nodes
Arcs
Flow
Cities
Highways
Cars
Hubs
Wire
Transmitted
packets
Pipelines joints
Pipes
Water
Introduction to networks
• Chain is a sequence of arcs connecting two nodes i and j, e.g.
figure on the right: ABCE, ADCE
• Path is a sequence of directed arcs connecting two nodes , e.g.
figure on the right ABDE, but not ABCE
• Cycle is a chain, which connects a node with the same node
without any repetition (retracing) e.g. figure on the right
ABCEDA, but not ABCDECBA
• Connected graph/network has only one part
Graph
Directed graph
Introduction to networks
• Tree – a connected graph which does not have cycles.
• Spanning tree is a tree chosen among arcs in the graph
so that all nodes in the tree were connected
Two trees
Two spanning trees
• Flow capacity – upper (sometimes also lower) limit for the flow at a given
arc in the network, e.g. maximal number of cars that can pass per minute
at a given road
• Source is a node which introduces a flow into the network
• Sink is a node which takes the flow out of the network
The shortest route problem
• Formulation: For a given graph in which every arc is
assigned with a distance bewteen the two nodes it
connects, what is the shortest path between node i and j.
• Example: What is the shortest route bewteen A and H?
Enumeration – impractical
Dijkstra algorithm
Dijkstra algorithm
http://optlabserver.sce.carleton.ca/PO
Animations2007/Dijkstras
Algo.html
Minimum spanning tree
• Formulation: For a given graph, in which every arc is assigned with a
distance between the two nodes it connects, find a spanning tree
that has minimal total length.
• Example: Find minimal length for a wire that connects all the offices
in the building when all the available wire paths are given.
• Algorithm:
http://optlabserver.sce.carleton.ca/POAnimations
2007/MinSpanTree.html
An example of the so called greedy algorithm – it does what’s best in a given step not looking at the other
stages of the problem (usually ineffective – here it is effective!)
One can do a maximal spanning tree the same way
Maximum flow and the minimum cut
• Formulation: What is the maximal flow between two given nodes in a
graph? Each node is assigned with a maximal flow.
• Example: Find a maximal flow of cars from an underground parking lot
downtown to the motorway entrance.
• Each arc is assigned with a maximal simultaneous flow between the two
nodes it connects
– Maximal flow may differ depending on the flow direction (e.g. one-way streets)
Example solution:
4 cars/m on route A-D-E-G
3 cars/m ojn route A-B-E-G
4 cars/m on route A-C-F-G
Total flow between A and G is 11
cars/m
Is this optimal???
Maximum flow and the minimum cut
• Algorithm: Ford and Fulkerson (Canadian Journal of
Mathematics 1956)
http://optlabserver.sce.carleton.ca/POAnimations2007/MaxFlow.html
Maximum flow/minimum cut
• In Ford Fulkerson algorithm, why do we need to add flow in the
opposite direction?
– Accounting convention that keeps track of the flow that, if necessary,
can be reversed.
Maximum flow/minimum cut
• Maximum flow is closely related to minimum cut:
– A cut in a graph is a set of directed arcs which contains at least one arc in every
possible path from the source to the sink. If we remove arcs from a given cut,
the flow from the source to the sink will no longer be possible.
– Cut value is the sum of all flow capacities (direction from the source to the sink)
for each arc in a cut.
• Possible cuts with cut values indicated on them
Download