# HW10

## Due Date: April 29, before midnight (11:59:59PM)

This assignment comprises both written questions and implementation-based lab.

## HW10

Answer the following questions from the DPV book: i) Q7.17 (all parts), ii) Q7.21

## Lab10: Network Flow

Implement the Edmonds-Karp maximum flow algorithm described in Lecture24. In particular, for Edmonds-Karp start from the Ford-Fulkerson algorithm described in Section 7.2, with the only difference being that you need to always find the shortest $s$-$t$ path (via BFS, assuming edge weight 1) when finding augmenting paths (see Section 7.2.5).

Your code should output the final i) maxflow value, ii) the actual flow along each edge from the source (print edges in sorted order, along with the flow value on each edge).

You can test you code on the simple example from the book chapter, using source 's' and sink 't':

s a 3
s b 3
s c 4
a d 2
b a 10
b d 1
c e 5
d c 1
d e 1
d t 2
e t 5


Your output should match:

flow ('s', 'a', 2), ('s', 'b', 1), ('s', 'c', 4)
maxflow value 7


## Bonus

In addition to the maxflow and the actual flow, compute the minimum cut value and the actual capacities of the edges that cross the cut (print the edges in sorted order, along with their capacities). For the example graph above, the output should be:

cut_edges ('a', 'd', 2), ('b', 'd', 1), ('s', 'c', 4)
mincut value 7


### Grading

Use submitty to submit a PDF with the output and one .py script. Your code should take as input the name of the graph file and the source and sink vertex, e.g., lab10.py g5_s0_t53.txt 0 53; here '0' is the source vertex and '53' the sink vertex.

Here are two other graphs to test your code: g5_s0_t53.txt, and g10_s0_t485.txt. Note that the source vertex s and the sink vertex t are specified in the filename. So for g5_s0_t53.txt the source is '0' and sink is '53'. Treat all vertices as strings (this way the output will be consistent when you print the sorted edges in the flow/cut). The output for g5_s0_t53.txt is:

flow ('0', '24', 59), ('0', '25', 7), ('0', '31', 44), ('0', '32', 3)
maxflow value 113

cut_edges ('28', '53', 69), ('31', '53', 14), ('40', '41', 30)
mincut value 113


and the output for g10_s0_t485.txt is:

flow ('0', '103', 2), ('0', '126', 5), ('0', '136', 12), ('0', '138', 15), ('0', '158', 43), ('0', '159', 35), ('0', '184', 2), ('0', '199', 55), ('0', '20', 63), ('0', '205', 1), ('0', '218', 3), ('0', '244', 16), ('0', '249', 23), ('0', '266', 8), ('0', '276', 1), ('0', '289', 28), ('0', '290', 27), ('0', '297', 19), ('0', '305', 48), ('0', '323', 23), ('0', '343', 8), ('0', '360', 32), ('0', '368', 22), ('0', '381', 10), ('0', '387', 2), ('0', '406', 62), ('0', '415', 71), ('0', '416', 4), ('0', '429', 11), ('0', '43', 4), ('0', '435', 22), ('0', '442', 16), ('0', '444', 28), ('0', '56', 12), ('0', '58', 3), ('0', '60', 19), ('0', '68', 9), ('0', '8', 1), ('0', '88', 14)
maxflow value 779

cut_edges ('0', '103', 2), ('0', '136', 12), ('0', '138', 15), ('0', '158', 43), ('0', '159', 35), ('0', '199', 55), ('0', '205', 1), ('0', '266', 8), ('0', '297', 19), ('0', '415', 71), ('0', '435', 22), ('100', '101', 5), ('130', '131', 5), ('184', '185', 2), ('20', '21', 57), ('20', '279', 1), ('20', '426', 5), ('221', '222', 3), ('253', '254', 16), ('253', '481', 7), ('258', '259', 16), ('277', '278', 1), ('289', '485', 28), ('292', '293', 27), ('305', '306', 48), ('323', '324', 23), ('345', '346', 6), ('357', '358', 2), ('365', '485', 3), ('367', '485', 5), ('370', '485', 16), ('371', '372', 6), ('383', '485', 10), ('390', '485', 2), ('406', '407', 61), ('406', '485', 1), ('423', '424', 4), ('429', '485', 11), ('431', '432', 24), ('44', '45', 4), ('445', '446', 28), ('473', '474', 16), ('56', '485', 12), ('59', '485', 3), ('63', '64', 19), ('70', '71', 9), ('8', '9', 1), ('88', '89', 9)
mincut value 779


Finally, submit your output on the following graphs g50_s0_t2511.txt. FYI, the correct value of maxflow/mincut should be 1224. If your code is efficient, then also submit output on g100_s0_t12077.txt. FYI, the correct value of maxflow/mincut should be 11883.

### Policy on Academic Honesty

You are free to discuss how to tackle the assignment, but all coding must be your own. Please do not copy or modify code from anyone else, including code on the web. Any students caught violating the academic honesty principle will get an automatic F grade on the course and will be referred to the dean of students for disciplinary action.