Skip to content

Commit 63d9ff6

Browse files
committed
added results, updated README
1 parent 10006d0 commit 63d9ff6

File tree

3 files changed

+85
-4
lines changed

3 files changed

+85
-4
lines changed

README.md

Lines changed: 85 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,86 @@
1-
### Following is what each file contains:
1+
# Linear-Program-Solvers
22

3-
1. `simplex_solver.py` contains the actual code that solves standard form LP using simplex algorithm
4-
2. `test.py` contains some random test cases which checks the validity of simplex solver by comparing against brute force search
5-
3. `network_flow.py` contains code that given an adjacency matrix of a graph creates both the primal (flow) LP and its dual (which corresponds to min-cut) LP in standard form and runs simplex solver on them
3+
### Introduction
4+
- This repository contains implementations of following [linear program (LP)](https://en.wikipedia.org/wiki/Linear_programming) solver algorithms in Python and NumPy:
5+
1. [Simplex algorithm](https://en.wikipedia.org/wiki/Simplex_algorithm)
6+
2. Primal-Dual Infeasible [Interior Point](https://en.wikipedia.org/wiki/Interior-point_method) method
7+
3. Brute force algorithm (exhaustive search over all possible bases)
8+
- The solvers are tested on concrete [max-flow (network flow)](https://en.wikipedia.org/wiki/Maximum_flow_problem) problems (see _Results_ section below)
9+
- Refer to in-code documentation and comments for description of how the code is working
10+
11+
### Repository structure
12+
- Directory `solvers/` contains the implementation of the mentioned solvers
13+
1. `solvers/simplex_solver.py` contains the actual implementation of the `SimplexSolver` class
14+
2. `solvers/interior_point_solver.py` contains the actual implementation of the `InteriorPointSolver` class
15+
3. `solvers/brute_solver.py` contains the actual implementation of the `BruteSolver` class
16+
- `utils.py` contains definition of the following useful helper functions:
17+
1. `network_flow_to_std_LP()` that converts a given max-flow problem instance to its corresponding LP
18+
2. `primal_to_dual()` that converts a given primal LP in standard form to its corresponding dual in standard form
19+
- `main.py` contains example driver code that solves two max-flow problem instances using the solvers
20+
21+
### Results
22+
We test `SimplexSolver` and `InteriorPointSolver` on two separate max-flow instances.
23+
- Network for first max-flow instance is given below (green circle marks a [min-cut](https://en.wikipedia.org/wiki/Minimum_cut#With_Terminals) of the network)
24+
25+
![Small Graph](results/test_1.png)
26+
`SimplexSolver` gives the following flow assignment for this instance:
27+
28+
| Edge | Flow | Capacity |
29+
| ------ | ------| ---------- |
30+
|(0, 1) | 16 | 16 |
31+
|(0, 2) | 10 | 13 |
32+
|(1, 2) | 8 | 10 |
33+
|(1, 3) | 12 | 12 |
34+
|(2, 1) | 4 | 4 |
35+
|(2, 4) | 14 | 14 |
36+
|(3, 2) | 0 | 9 |
37+
|(3, 5) | 19 | 20 |
38+
|(4, 3) | 7 | 7 |
39+
|(4, 5) | 7 | 7 |
40+
41+
The total flow leaving source (vertex-0) in the above flow assignment (16 + 10 = 26) is equal to the sum of the capacities of edges going out of the cut shown above in green (12 + 14 = 26). Hence, this flow assignment is optimal [(cf. max-flow min-cut theorem)](https://en.wikipedia.org/wiki/Max-flow_min-cut_theorem)
42+
43+
- Network for second max-flow instance is given below (green circle marks a [min-cut](https://en.wikipedia.org/wiki/Minimum_cut#With_Terminals) of the network)
44+
45+
![Large Graph](results/test_2.png)
46+
`InteriorPointSolver` gives the following flow assignment for this instance:
47+
48+
| Edge | Flow | Capacity |
49+
| ------ | ------| ---------- |
50+
| ( 0, 1) | 11.00 | 11 |
51+
| ( 0, 2) | 8.00 | 15 |
52+
| ( 0, 3) | 10.00 | 10 |
53+
| ( 1, 5) | 11.09 | 18 |
54+
| ( 1, 6) | 3.48 | 4 |
55+
| ( 2, 1) | 3.00 | 3 |
56+
| ( 2, 2) | 4.00 | 8 |
57+
| ( 2, 3) | 5.00 | 5 |
58+
| ( 3, 4) | 5.17 | 6 |
59+
| ( 3, 7) | 2.27 | 3 |
60+
| ( 3, 8) | 8.33 | 11 |
61+
| ( 4, 3) | 0.76 | 4 |
62+
| ( 4, 7) | 5.72 | 17 |
63+
| ( 4, 8) | 1.05 | 6 |
64+
| ( 5, 4) | 1.76 | 3 |
65+
| ( 5, 5) | 8.00 | 16 |
66+
| ( 5, 9) | 9.33 | 13 |
67+
| ( 6, 1) | 0.58 | 12 |
68+
| ( 6, 4) | 0.61 | 4 |
69+
| ( 6, 11) | 2.30 | 21 |
70+
| ( 7, 8) | 1.00 | 4 |
71+
| ( 7, 9) | 4.64 | 9 |
72+
| ( 7, 10) | 3.02 | 4 |
73+
| ( 7, 11) | 2.33 | 3 |
74+
| ( 8, 7) | 3.00 | 4 |
75+
| ( 8, 10) | 4.37 | 5 |
76+
| ( 8, 11) | 3.50 | 4 |
77+
| ( 9, 10) | 5.83 | 7 |
78+
| ( 9, 11) | 8.14 | 9 |
79+
| (10, 8) | 0.49 | 2 |
80+
| (10, 11) | 12.73 | 15 |
81+
82+
The total flow leaving source (vertex-0) in the above flow assignment (11 + 8 + 10 = 29) is equal to the sum of the capacities of edges going out of the cut shown above in green (11 + 3 + 5 + 10 = 29). Hence, this flow assignment is optimal [(cf. max-flow min-cut theorem)](https://en.wikipedia.org/wiki/Max-flow_min-cut_theorem)
83+
84+
### References
85+
1. [Introduction to Linear Optimization](https://www.amazon.com/Introduction-Linear-Optimization-Scientific-Computation/dp/1886529191) by Dimitris Bertsimas, John Tsitsiklis
86+
2. [Interior-Point Methods](https://www.youtube.com/watch?v=7CMWdO5dgdQ) by Stephen Wright

results/test_1.png

166 KB
Loading

results/test_2.png

297 KB
Loading

0 commit comments

Comments
 (0)