CSC 8301– Design & Analysis of Algorithms: Linear...
Transcript of CSC 8301– Design & Analysis of Algorithms: Linear...
Villanova University Department of Computing Sciences
CSC 8301– Design &Analysis of Algorithms:Linear Programming
Professor Henry CarterFall 2016
Villanova University Department of Computing Sciences
Iterative Improvement
• Start with a feasible solution
• Improve some part of the solution
• Repeat until the solution is optimal
2
Villanova University Department of Computing Sciences
A Geometric Solution
• Maximize: 3x + 5y
3
x
y
( 0, 2 )
( 0, 0 ) ( 4, 0 )
( 3, 1 )
3x + 5y = 10
3x + 5y = 14
3x + 5y = 20
Villanova University Department of Computing Sciences
The Simplex Method
• A convenient means for iterating over extreme points
• Problem must be:
‣ Maximization problem
‣ All constraints must be linear equations with nonnegative right-hand sides
‣ All variables must be nonnegative
4
Villanova University Department of Computing Sciences
Step 0: Standard Form
• Min-max conversion
• Representing inequalities with slack variables
• Replace negative variables with two nonnegative variables
5
Villanova University Department of Computing Sciences
Example Standard Form
• Maximize: 3x + 5ySubject to: x + y ≤ 4
x + 3y ≤ 6x ≥ 0, y ≥ 0
6
• Maximize: 3x + 5y + 0u + 0vSubject to: x + y + u = 4
x + 3y + v = 6x, y, u, v ≥ 0
Villanova University Department of Computing Sciences
Basic Feasible Solution
• Find an initial extreme point to begin iterative improvement
• For m constraints over n variables, set (n - m) variables to 0
• Common approach is to zero the original variables and set the slack variables accordingly
• For our example, (0, 0, 4, 6)
7
Villanova University Department of Computing Sciences
Constructing the Simplex Tableau
• Constraint Coefficients
• Objective Row
• Recognize the corresponding solution
8
• Maximize: 3x + 5y + 0u + 0v
Subject to: x + y + u = 4x + 3y + v = 6x, y, u, v ≥ 0
Villanova University Department of Computing Sciences
Example Tableau
9
1 1 1 0 4
1 3 0 1 6
-3 -5 0 0 0
x y u vu
v
Villanova University Department of Computing Sciences
Iterating the Extreme Point
• Choose the entering variable (new basic variable)
• Choose the departing variable (new nonbasic variable)
• Pivot Operations
10
Villanova University Department of Computing Sciences
Example Iteration
11
1 1 1 0 4
1 3 0 1 6
-3 -5 0 0 0
x y u vu
v
Villanova University Department of Computing Sciences
Example Iteration
12
1 1 1 0 4
1 3 0 1 6
-3 -5 0 0 0
x y u vu
v
θu=
θv=
Villanova University Department of Computing Sciences
Example Iteration
13
1 1 1 0 4
1 3 0 1 6
-3 -5 0 0 0
x y u vu
v
Villanova University Department of Computing Sciences
Example Iteration
14
1 1 1 0 4
1/3 1 0 1/3 2
-3 -5 0 0 0
x y u vu
v
Villanova University Department of Computing Sciences
Example Iteration
15
2/3 0 1 -1/3 2
1/3 1 0 1/3 2
-4/3 0 0 5/3 10
x y u vu
y
Villanova University Department of Computing Sciences
Example Iteration
16
2/3 0 1 -1/3 2
1/3 1 0 1/3 2
-4/3 0 0 5/3 10
x y u vu
y
Villanova University Department of Computing Sciences
Example Iteration
17
1 0 3/2 -1/2 3
0 1 -1/2 1/2 1
0 0 2 1 14
x y u vx
y
Villanova University Department of Computing Sciences
Practical Points
• Prevent cycling with Bland’s Rule
• Algorithmically finding an initial feasible solution
• Two-phase Simplex Method
18
Villanova University Department of Computing Sciences
Analysis
• Number of extreme points grows exponentially
• In practice, between m and 3m iterations are needed
• Operations per iteration: O(mn)
• Other approaches:
‣ Ellipsoid method (polynomial worst-case)
‣ Karmarkar’s algorithm (empirically efficient)
19
Villanova University Department of Computing Sciences
Practice
• Set up the first simplex tableau for the following linear programming problem:
Maximize: x + 2y
subject to: 4x ≥ yy ≤ 3 + xx ≥ 0, y ≥ 0
20
Villanova University Department of Computing Sciences
Recap
• Iterative methods start with a solution then iteratively improve it until optimal
• Linear programming optimizes a linear equation with constraints
• The Simplex Method iterates over extreme points in the feasible region
• Very common in practice (even included in Excel add-on)
21
Villanova University Department of Computing Sciences
Modeling a Transportation Network
• Recall: weighted digraphs
• Represent start and end as a source vertex and a sink vertex
• Represent paths with positive capacity using edge weight
• Flow Network
22
Villanova University Department of Computing Sciences
Finding a Flow
• Rules:
‣ Flow-conservation
‣ Edge capacity
• Flow value
• Maximize the value
23
Villanova University Department of Computing Sciences
Ford-Fulkerson
• Initialize a 0-value flow
• Iteratively search for an augmented path
‣ Any path from source to sink with available flow capacity
• When no more augmenting paths can be found, the flow is maximized
24
Villanova University Department of Computing Sciences
Greedy Approach Example
25
1
5
2 33
2 5
1
3 4
4
62
Villanova University Department of Computing Sciences
Shortest Augmenting Path
• Uses a BFS to traverse the graph
• Along the path, adjust the incoming flow for each vertex if there is edge capacity available
• If a vertex with no outgoing capacity is encountered, adjust the incoming flow on a back edge
• Augment the current flow each time a new augmenting path reaches the sink
‣ Terminate if no augmenting path to the sink exists
26
Villanova University Department of Computing Sciences
Example: 1st augmenting path
• Queue:
27
1
5
2 30/3
0/2 0/5
0/1
0/3 0/4
4
60/2
1 ∞ -23456
Villanova University Department of Computing Sciences
Example: 2nd augmenting path
• Queue:
28
1
5
2 30/3
2/2 2/5
0/1
0/3 0/4
4
62/2
1 ∞ -23456
Villanova University Department of Computing Sciences
Example: no more augmenting paths
• Queue:
29
1
5
2 31/3
2/2 1/5
1/1
1/3 1/4
4
62/2
1 ∞ -23456
Villanova University Department of Computing Sciences
Analysis
• Time to find one augmenting path (using adjacency lists): O(|E|)
• Maximum iterations needed: |E||V|/2
• Worst-case: O( )
30
Villanova University Department of Computing Sciences
Max-flow Min-cut theorem
• A cut is a set of edges that, when removed, eliminate all paths from source to sink
• A min-cut is a cut where the sum of the edge weights is minimized
• The value of a max-flow is equal to the capacity of the min-cut
31
Villanova University Department of Computing Sciences
Finding the Min-cut
• Queue: 1, 4
32
1
5
2 31/3
2/2 1/5
1/1
1/3 1/4
4
62/2
1 ∞ -234 2 1+56
Villanova University Department of Computing Sciences
Practice
33
1 52
3 7
6
5
8
4 4
4 6
2
Villanova University Department of Computing Sciences
Recap
• Iterative improvement of a max-flow using augmented paths
• Shortest augmenting path algorithm considers both forward and backward edges to find an augmenting path
• The max-flow value of a network is equal to the min-cut capacity
34
Villanova University Department of Computing Sciences
Next Time...
• Levitin Chapter 10.3-10.4
‣ Remember, you need to read it BEFORE you come to class!
• Homework:
‣ 10.1: 3, 5, 8
‣ 10.2: 1-4, 10
35