Docsity

Algorithms Tutorial: Bipartite Matching, Edge Disjoint Paths, Flow Networks, Exercises of Algorithms and Programming

Toggle sidebar
bg1
Tutorial questionsAlgorithms 9007
2019 Semester 1Tutorial 9
The University of Sydney
School of Computer Science
Pre-tutorial questions
Do you know the basic concepts of this week’s lecture content? These questions are only to test yourself.
They will not be explicitly discussed in the tutorial, and no solutions will be given to them.
1. Bipartite matching.
(a) What is a bipartite matching?
(b) How can one use flow networks to find a maximum bipartite matching?
(c) What does the marriage theorem state?
2. Edge disjoint paths
(a) What does it mean that two paths in a graph are edge disjoint?
(b) How can one use flow networks to count the maximum number of edge disjoint paths?
3. Extensions of flow networks
(a) What is flow networks with node supplies and demands?
(b) What is a circulation in a network with supplies and demands?
(c) How can one use flow networks to model supply and demand?
Tutorial
Problem 1
Suppose you’re in charge of managing a fleet of airplanes and you’d like to create a flight schedule for them.
Here’s a very simple model for this. Your market research has identified a set of m particular flight segments
that that would be very lucrative if you could serve them; flight segment jis specified by four parameters:
its origin airport, its destination airport, its departure time, and its arrival time. An example of six flights
segments you’d like to serve with your planes over the course of a single day may include:
1. Brisbane (depart 6 am) - Sydney (arrive 7 am)
2. Sydney (depart 6:30 am) - Melbourne (arrive 8 am)
3. Sydney (depart 8 am) - Cairns (arrive 11 am)
4. Melbourne (depart 12 am) - Adelaide (arrive 2 pm)
5. Townsville (depart 2:15 pm) - Brisbane (arrive 4 pm)
6. Adelaide (depart 4:00 pm) - Perth (arrive 7 pm)
It is possible to use a single plane for a flight segment i, and then later for flight segment j, provided
that:
1. the destination of iis the same as the origin of jand there’s enough time to perform maintenance on
the plane in between; or
1
pf3
pf4

Partial preview of the text

Download Algorithms Tutorial: Bipartite Matching, Edge Disjoint Paths, Flow Networks and more Exercises Algorithms and Programming in PDF only on Docsity!

Algorithms 9007 Tutorial questions 2019 Semester 1 Tutorial 9

The University of Sydney School of Computer Science

Pre-tutorial questions

Do you know the basic concepts of this week's lecture content? These questions are only to test yourself. They will not be explicitly discussed in the tutorial, and no solutions will be given to them.

  1. Bipartite matching.

(a) What is a bipartite matching? (b) How can one use ow networks to nd a maximum bipartite matching? (c) What does the marriage theorem state?

  1. Edge disjoint paths

(a) What does it mean that two paths in a graph are edge disjoint? (b) How can one use ow networks to count the maximum number of edge disjoint paths?

  1. Extensions of ow networks

(a) What is ow networks with node supplies and demands? (b) What is a circulation in a network with supplies and demands? (c) How can one use ow networks to model supply and demand?

Tutorial

Problem 1 Suppose you're in charge of managing a eet of airplanes and you'd like to create a ight schedule for them. Here's a very simple model for this. Your market research has identi ed a set of m particular ight segments that that would be very lucrative if you could serve them; ight segment j is speci ed by four parameters: its origin airport, its destination airport, its departure time, and its arrival time. An example of six ights segments you'd like to serve with your planes over the course of a single day may include:

  1. Brisbane (depart 6 am) - Sydney (arrive 7 am)
  2. Sydney (depart 6:30 am) - Melbourne (arrive 8 am)
  3. Sydney (depart 8 am) - Cairns (arrive 11 am)
  4. Melbourne (depart 12 am) - Adelaide (arrive 2 pm)
  5. Townsville (depart 2:15 pm) - Brisbane (arrive 4 pm)
  6. Adelaide (depart 4:00 pm) - Perth (arrive 7 pm)

It is possible to use a single plane for a ight segment i, and then later for ight segment j, provided that:

  1. the destination of i is the same as the origin of j and there's enough time to perform maintenance on the plane in between; or
  1. you can add a ight segment in between that gets the plane from the destination of i to the origin of j with adequate time in between.

For the example above you can group ights 1, 3, and 5 together by allocating an hour maintaince between each ight and adding an additional 1 hour ight between Cairns and Townsville for example. Your goal based on the two conditions stated above is to determine if it is possible to service all m ights using at most k planes. In order to do this you will need to reuse planes as efficiently as possible.

Solution: The solution is based on the following idea. Units of ow will correspond to airplanes. We will have an edge for each ight, and upper and lower capacity bounds of 1 on these edges to require that exactly one unit of ow crosses this edge. In other words, each ight must be served by one of the places. If (ui; vi) is the edge representing ight i, and (uj ; vj ) is the edge representing ight j, and ight j is reachable from ight i, then we will have an edge from vi to ui with capacity 1. For the example above we get the following s − t capacitated network where it is possible to achieve a ow of 2. Although we use max ow this problem is a minimisation problem in the sense that the aim is to nd the minimum max ow for the following graph where all the edges that are solid are 1.

s

BNE 6

SYD 6:

SYD 7

MEL 8

SYD 8

MEL 2

CNS 11

ADL 2

TSV 2:

ADL 4

BNE 2:

PER 7

t

Problem 2 Given an undirected graph G = (V; E) and edge capacities c : E → R+ and two vertices s and t, design an algorithm for computing a minimum capacity s-t cut.

Solution: Note that the graph is undirected, so we cannot compute a max- ow using the Ford-Fulkerson algorithm, which expects a directed graph as input. Construct a new directed graph G′^ = (V; E′) with capacities c′^ where for each edge (u; v) ∈ E we create two antiparallel edges (u; v) and (v; u) and set c′(u; v) = c′(v; u) = c(u; v). It's easy to argue that for any cut (A; B) we have c(A; B) = c′(A; B). Thus the min s-t cut with respect to G′^ and c′^ is also a minimum with respect to G and c.

Problem 3 We de ne a new version of the game Capture the Flag. The game is played in a maze that consists of a large number of rooms that are connected by doors. Each door connects two rooms. Each player starts in a given room in the maze (different players may start in different rooms). From each room a player can decide to move to any adjacent room, going through a door, as long as the door is open. All doors are open in the

long. Luckily, a variant of the algorithm can be shown to run for at most O(m log C) iterations. The idea is very simple: Select an augmenting path maximizing the minimum residual capacity along the path. Show how to modify Dijkstra's algorithm to nd such a path in the residual graph Gf^.

Solution: (Sketch.) Recall that Dijkstra's algorithm computes a tentative distance value from s to every vertex in V ; let us denote this tentative distance d[u]. Initially d[s] = 0 and d[u] = +∞ for all other vertices u. The algorithm builds a priority queue for V so that the priority of u ∈ V is d[u]. In each iteration it extracts the vertex u with minimum priority and updates the priority of each neighbor v of u by setting d[v] = min{d[v]; d[u] + ℓ(u; v)}. The tricky part of the analysis is to show that when we remove a vertex u the shortest path distance from s to u equals d[u]. Let us denote the residual capacity of an edge e with ~c(e). In our modi ed version we again keep a tentative value T [u] for each vertex. Initially T [s] = ∞ and T [u] = 0 for all vertices u ∈ V − s. We build a priority queue for V so that the priority of u ∈ V is T [u]. In each iteration we extract the vertex u with maximum priority and update the priority of each neighbor v of u by setting T [v] = max{T [v]; min{T [u]; ~c(u; v)}}. The trick of the analysis is to show that when we remove u from the priority queue the best bottleneck residual capacity to go from s to u equals T [u]. The argument is very similar to the one used for Dijkstra's algorithm, so I'll leave it up to you to ll in the details.