lecture 7

34
Advanced Algorithms Network Optimization Valeria Fionda KRDB Research Group Faculty of Computer Science Free University of Bozen-Bolzano (Partially based on material by John W. Chinneck, Jeff Erickson, Michael Trick, Peitsang Wu, J. Vanderbei, J. Orlin) Valeria Fionda (KRDB-FUB) Advanced Algorithms 1 / 34

Upload: ttungl

Post on 12-May-2017

212 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 7

Advanced AlgorithmsNetwork Optimization

Valeria Fionda

KRDB Research GroupFaculty of Computer Science

Free University of Bozen-Bolzano(Partially based on material by John W. Chinneck, Jeff Erickson, Michael Trick, Peitsang

Wu, J. Vanderbei, J. Orlin)

Valeria Fionda (KRDB-FUB) Advanced Algorithms 1 / 34

Page 2: Lecture 7

Max flow problem

Given a network G = (V ,A) the maximum flow problem is to find afeasible flow from the single source of G to the single sink of Ghaving the maximum value.

The network is subjected to some restrictions:1 It must contain one source node and one sink node.2 All the remaining nodes are transshipment nodes.3 The maximum amount of flow through an arc is given by the capacity

of that arc.4 The objective is to maximize the total amount of flow from the source

to the sink. This amount is measured either as the amount leaving thesource or as the amount entering in the sink.

Valeria Fionda (KRDB-FUB) Advanced Algorithms 2 / 34

Page 3: Lecture 7

Multi-source multi-sink maximum flow problem

It is a generalization of the single-source single-sink problem in whichthere are a set of sources S = {s1, ..., sn} and a set of sinksT = {t1, ..., tm}Problem: Look for maximum flow from nodes in S to nodes in T .

We can transform the multi-source multi-sink problem into amaximum flow problem by adding a dummy source s connected toeach vertex in S and a dummy sink t connected to each vertex in Twith infinite capacity on each edge.

Valeria Fionda (KRDB-FUB) Advanced Algorithms 3 / 34

Page 4: Lecture 7

Max flow/Min cut theorem

Max flow/Min cut theorem

The maximum flow problem is related to the minimum cut problem.

A cut is defined as any set of arcs containing at least one arc fromany directed path from the source node to the sink node.

In other words, if the arcs in the cut are removed then the flow fromthe source to the sink is completely cut off.

The cut value is the sum of the arc capacities of the arcs of the cut.

The minimum cut problem is that of finding the cut having theminimum value over all the possible cuts.

Valeria Fionda (KRDB-FUB) Advanced Algorithms 4 / 34

Page 5: Lecture 7

Max flow/Min cut theorem

Max flow/Min cut theorem

For any network with a single supply node and the demand node, themaximum flow from the supply node to the demand node is equals tothe minimum cut value for all cuts of the network.

Valeria Fionda (KRDB-FUB) Advanced Algorithms 5 / 34

Page 6: Lecture 7

Max flow/Min cut theorem

Max flow/Min cut theorem

The minimum cut is just a kind of distributed bottleneck (i.e., abottleneck for a whole network as opposed to a simple bottleneck fora series of pipe).The minimum cut value can be determined using the Ford andFulkerson algorithm.However, it is interesting to know where the minimum cut is (i.e., thetraffic engineers determine that the maximum flow of vehicles fromthe car park to the freeway on-ramp is too small and they want toexpand roadways).After Ford and Fulkerson algorithm ends, mark the arc having flowequal to their capacity and look for a cut consisting only in those arcs.

Valeria Fionda (KRDB-FUB) Advanced Algorithms 6 / 34

Page 7: Lecture 7

Max flow/Min cut theorem Application example

Max flow/Min cut theorem

An undirected network G = (N,A) is bipartite if N can be partitionedinto N1 and N2 so that for every arc (i , j), i ∈ N1 and j ∈ N2.

A matching in N is a set of arcs no two of which are incident to acommon node.

Matching Problem: Find a matching of maximum cardinality.

Valeria Fionda (KRDB-FUB) Advanced Algorithms 7 / 34

Page 8: Lecture 7

Max flow/Min cut theorem Application example

Max flow/Min cut theorem

A node cover is a subset S of nodes such that each arc of G isincident to a node of S .

Node Cover Problem: Find a node cover of minimum cardinality.

Valeria Fionda (KRDB-FUB) Advanced Algorithms 8 / 34

Page 9: Lecture 7

Max flow/Min cut theorem Application example

Max flow/Min cut theorem

Theorem. The maximum cardinality of a matching is equal to theminimum cardinality of a node cover.

Valeria Fionda (KRDB-FUB) Advanced Algorithms 9 / 34

Page 10: Lecture 7

Max flow/Min cut theorem Application example

Max flow/Min cut theorem

Valeria Fionda (KRDB-FUB) Advanced Algorithms 10 / 34

Page 11: Lecture 7

Max flow/Min cut theorem Application example

Max flow/Min cut theorem

Valeria Fionda (KRDB-FUB) Advanced Algorithms 11 / 34

Page 12: Lecture 7

Max flow/Min cut theorem Application example

Max flow/Min cut theorem

Valeria Fionda (KRDB-FUB) Advanced Algorithms 12 / 34

Page 13: Lecture 7

Max flow/Min cut theorem Application example

Max flow/Min cut theorem

Valeria Fionda (KRDB-FUB) Advanced Algorithms 13 / 34

Page 14: Lecture 7

Max flow/Min cut theorem Application example

Max flow/Min cut theorem

The minimum node cover is the set of nodes incident to the arcs acrossthe cut.

Valeria Fionda (KRDB-FUB) Advanced Algorithms 14 / 34

Page 15: Lecture 7

Variants

Circulation Problem with demand

Circulation is a generalisation of network flow problems with flowconservation required for the nodes (i.e. there are no special nodes).Rather than maximize the total flow, we work with a fixed set ofdemands and supplies.Each node v has an associated demand dv :

If dv > 0, we say v is a demand node;if dv = 0, v is a transshipment node;if dv < 0, v is a supply node (it supplies −dv units).

A circulation is a function f such that:1 Capacity Constraint: 0 ≤ f (v ,w) ≤ u(v ,w), for all arc (v ,w);2 Demand Condition:

∑w f (w , v)−

∑w f (v ,w) = dv , for all nodes v .

Valeria Fionda (KRDB-FUB) Advanced Algorithms 15 / 34

Page 16: Lecture 7

Variants

Circulation Problem with demands

If a feasible circulation exists then∑

v dv = 0.

Algorithm: convert the circulation problem into a max flow problemby introducing a source s, and join it to all supply nodes, with edgecapacity equal to −dv . Similarly, add a sink node t, and join eachdemand node to t, with edge capacity dv . The circulation is feasibleif and only if the maxflow has value exactly

∑v : demand node dv .

Valeria Fionda (KRDB-FUB) Advanced Algorithms 16 / 34

Page 17: Lecture 7

Variants

Circulation Problem with demands and lower bounds

In some applications, certain amount of flow is forced on some edges.That is, f (v ,w) ≥ l(v ,w), and so there is a lower bound on the valueof flow at some edges.

The conditions for the flow, with demands, now change to:1 Capacity Constraint: l(v ,w) ≤ f (v ,w) ≤ u(v ,w), for all arc (v ,w);2 Demand Condition:

∑w f (w , v)−

∑w f (v ,w) = dv , for all nodes v .

Again, deciding if a circulation is feasible is done in two steps:1 Model the lower bounds with supply/demands

2 solve the maxflow related problem.

Valeria Fionda (KRDB-FUB) Advanced Algorithms 17 / 34

Page 18: Lecture 7

Minimum Cost Flow Problem

Minimum Cost Flow Problem

Minimum Cost Flow Problem considers:1 flow through a network with limited arc capacities;2 a cost (or distance) for flow through an arc;3 multiple sources (supply nodes) and multiple destinations (demand

nodes).

The minimum cost flow problem can be solved efficiently ifformulated as a linear programming problem by using a streamlinedversion of the simplex method called the network simplex method.

Valeria Fionda (KRDB-FUB) Advanced Algorithms 18 / 34

Page 19: Lecture 7

Minimum Cost Flow Problem

Minimum Cost Flow Problem

Minimum Cost Flow Problem is described as follows:1 The network is a directed and connected network.2 At least one of the nodes is a source node.3 At least one of the other nodes is a sink node.4 All the remaining nodes are transshipment nodes.5 Flow through an arc is allowed only in the direction indicated by the

arrowhead, where the maximum amount of flow is given by thecapacity of that arc. (If flow can occur in both directions, this wouldbe represented by a pair of arcs pointing in opposite directions.)

6 The network has enough arcs with sufficient capacity to enable all theflow generated at the supply nodes to reach all the demand nodes.

7 The cost of the flow through each arc is proportional to the amount ofthat flow, where the cost per unit flow is known.

8 The objective is to minimize the total cost of sending the availablesupply through the network to satisfy the given demand. (Analternative objective is to maximize the total profit from doing this.)

Valeria Fionda (KRDB-FUB) Advanced Algorithms 19 / 34

Page 20: Lecture 7

Minimum Cost Flow Problem LP formulation

LP formulation

Decision variables:

xij (with (i , j) ∈ E ): quantity of flow along the arc (i , j);

Objective:

minimize∑

(i,j)∈E cij · xijConstraints:

Flow conservation:∑

i :(i,k)∈E xik −∑

i :(j,i)∈E xji = d(i) for each i ∈ VCapacity: xij ≤ uij

Nonnegativity: xij ≥ 0

Valeria Fionda (KRDB-FUB) Advanced Algorithms 20 / 34

Page 21: Lecture 7

Minimum Cost Flow Problem LP formulation

Minimum Cost Flow Problem

Valeria Fionda (KRDB-FUB) Advanced Algorithms 21 / 34

Page 22: Lecture 7

Java Implementation

Flow network representation

Flow edge data type. Associate flow fe and capacity ce with edgee = v → w .Flow network data type. Need to process edge e = v → w in eitherdirection: include e in both v and w ’s adjacency lists.

Residual capacity.Forward edge: residual capacity = ce − fe .Backward edge: residual capacity = fe .

Augment flow.Forward edge: subtract fP .Backward edge: add fP .

Valeria Fionda (KRDB-FUB) Advanced Algorithms 22 / 34

Page 23: Lecture 7

Java Implementation

Flow network representation

Augmenting path in original network is equivalent to directed path inresidual network.

Valeria Fionda (KRDB-FUB) Advanced Algorithms 23 / 34

Page 24: Lecture 7

Java Implementation

Flow network representation

Valeria Fionda (KRDB-FUB) Advanced Algorithms 24 / 34

Page 25: Lecture 7

Java Implementation

Flow network representation

Valeria Fionda (KRDB-FUB) Advanced Algorithms 25 / 34

Page 26: Lecture 7

Java Implementation

Flow network representation

Valeria Fionda (KRDB-FUB) Advanced Algorithms 26 / 34

Page 27: Lecture 7

Java Implementation

Flow network representation

Conventions. Allow self-loops and parallel edges.

Valeria Fionda (KRDB-FUB) Advanced Algorithms 27 / 34

Page 28: Lecture 7

Java Implementation

Flow network representation

Valeria Fionda (KRDB-FUB) Advanced Algorithms 28 / 34

Page 29: Lecture 7

Java Implementation

Flow network representation

Valeria Fionda (KRDB-FUB) Advanced Algorithms 29 / 34

Page 30: Lecture 7

Java Implementation

Ford Fulkerson algorithm

Valeria Fionda (KRDB-FUB) Advanced Algorithms 30 / 34

Page 31: Lecture 7

Java Implementation

Ford Fulkerson algorithm

Valeria Fionda (KRDB-FUB) Advanced Algorithms 31 / 34

Page 32: Lecture 7

AMPL Implementation

Ford Fulkerson algorithm - Model

# Definitions

# ------------

set NODES; # nodes in the network

set ARCS within {NODES, NODES}; # arcs in the network

# Symbolic parameters indicating entering and leaving nodes.

param Source symbolic in NODES;

param Sink symbolic in NODES;

param Capacity{ARCS}; # Maximum capacities of the arcs.

var x{(i,j) in ARCS}; # Variables defining the arc-flows.

var flow >= 0; # Flow between the desired nodes.

# Objective Function.

# ------------

maximize Objective : flow;

Valeria Fionda (KRDB-FUB) Advanced Algorithms 32 / 34

Page 33: Lecture 7

AMPL Implementation

Ford Fulkerson algorithm - Model

# Constraints

# ------------

# Flow in to the network.

subject to FlowIn : sum {(Source,j) in ARCS} x[Source,j] - sum{(j,Source) in

ARCS} x[j,Source] = flow;

# Flow out of the network.

subject to FlowOut : sum {(Sink,j) in ARCS} x[Sink,j] - sum{(j,Sink) in ARCS}x[j,Sink] = - flow;

# Flow Conservation Constraint. For all transshipmen nodes Flow In = Flow Out.

subject to FlowConservation {k in (NODES diff {Source, Sink})}: sum{(i,k) in

ARCS} x[i,k] = sum{(k,j) in ARCS} x[k,j];

# Capacity constraint

subject to capacity {(i,j) in in ARCS} : x[i,j] <= Capacity[i,j];

# Nonnegativity constraint

subject to positive {(i,j) in in ARCS} : x[i,j] >= 0;

Valeria Fionda (KRDB-FUB) Advanced Algorithms 33 / 34

Page 34: Lecture 7

AMPL Implementation

Ford Fulkerson algorithm - Data file

set NODES := a b c d e f g h i j k l m;

param Source := c;

param Sink := f;

param: ARCS: Capacity :=

a b 19,

a c 7,

a d 13,

a e 2,

a f 9,

b a 19,

b f 10,

b g 18,

b h 2,

b c 14,

...

Valeria Fionda (KRDB-FUB) Advanced Algorithms 34 / 34