def test_sanity(self): """ Sanity Test This is a simple sanity check for your function; passing is not a guarantee of correctness. """ g1 = Graph(is_directed=True) g1.add_edge('a', 'b', capacity=16, flow=12) g1.add_edge('a', 'c', capacity=13, flow=11) g1.add_edge('b', 'd', capacity=12, flow=12) g1.add_edge('c', 'b', capacity=4, flow=0) g1.add_edge('c', 'e', capacity=14, flow=11) g1.add_edge('d', 'c', capacity=9, flow=0) g1.add_edge('d', 'f', capacity=20, flow=19) g1.add_edge('e', 'd', capacity=7, flow=7) g1.add_edge('e', 'f', capacity=4, flow=4) self.assertFalse(AugmentingTest.augmenting(g1, 'a', 'f')) g2 = g1.copy() g2.set_flow('b', 'd', 11) self.assertTrue(AugmentingTest.augmenting(g2, 'a', 'f')) g3 = Graph(is_directed=True) g3.add_edge('a', 'b', capacity=1, flow=0) self.assertTrue(AugmentingTest.augmenting(g3, 'a', 'b')) g4 = Graph(is_directed=True) g4.add_edge('a', 'b', capacity=0, flow=0) self.assertFalse(AugmentingTest.augmenting(g4, 'a', 'b'))
def sensitive(G: Graph, s: str, t: str) -> Tuple[str, str]: """ Sig: Graph G(V,E), str, str -> Tuple[str, str] Pre: Post: Ex: sensitive(g1, 'a', 'f') = ('b', 'd') """ R = G.copy() nodes = set() dfs_residual(G, R, s, nodes) reachable = set() dfs_find_reachable(R, s, reachable) for (u, v) in G.edges: if u in reachable and v not in reachable: return (u, v)
def test_extended_sanity(self): """ sanity test for returned augmenting path This is a simple sanity check for your function; passing is not a guarantee of correctness. """ g1 = Graph(is_directed=True) g1.add_edge('a', 'b', capacity=16, flow=12) g1.add_edge('a', 'c', capacity=13, flow=11) g1.add_edge('b', 'd', capacity=12, flow=12) g1.add_edge('c', 'b', capacity=4, flow=0) g1.add_edge('c', 'e', capacity=14, flow=11) g1.add_edge('d', 'c', capacity=9, flow=0) g1.add_edge('d', 'f', capacity=20, flow=19) g1.add_edge('e', 'd', capacity=7, flow=7) g1.add_edge('e', 'f', capacity=4, flow=4) path_exists, path = AugmentingTest.augmenting_extended(g1, 'a', 'f') self.assertFalse(path_exists) self.assertListEqual(path, []) g2 = g1.copy() g2.set_flow('b', 'd', 11) path_exists, path = AugmentingTest.augmenting_extended(g2, 'a', 'f') self.assertTrue(path_exists) self.assertIsAugmentingPath(g2, 'a', 'f', path) g3 = Graph(is_directed=True) g3.add_edge('a', 'b', capacity=1, flow=0) path_exists, path = AugmentingTest.augmenting_extended(g3, 'a', 'b') self.assertTrue(path_exists) self.assertIsAugmentingPath(g2, 'a', 'b', path) g4 = Graph(is_directed=True) g4.add_edge('a', 'b', capacity=0, flow=0) path_exists, path = AugmentingTest.augmenting_extended(g4, 'a', 'b') self.assertFalse(path_exists) self.assertListEqual(path, [])