def test_edges_in_homogeneous(self): g = BinaryMixedTree(MixedGraph({0, 1, 2, 3, 4, 5}, [(0, 1), (1, 2), (3, 4), (4, 5)])) g.add_directed(frozenset([2]), frozenset([3])) value = edges_in_homogeneous_subset(g, g.homogeneous_subset()) expected = [frozenset([frozenset([0]), frozenset([1])]), frozenset([frozenset([1]), frozenset([2])])] self.assertEqual(value, expected)
def test_edges_in_homogeneous_simple_graph(self): g = BinaryMixedTree(MixedGraph({0, 1})) g.add_directed(frozenset([0]), frozenset([1])) value = edges_in_homogeneous_subset(g, g.homogeneous_subset()) expected = [] self.assertEqual(value, expected)
def test_simple_homogeneous_subset(self): g = BinaryMixedTree(MixedGraph({0, 1, 2}, [(0, 2)])) g.add_directed(frozenset([0]), frozenset([1])) value = g.homogeneous_subset() expected = {frozenset([0]), frozenset([2])} self.assertEqual(value, expected)
def test_one_edge_available(self): g = BinaryMixedTree(MixedGraph({0, 1, 2, 3}, [(1, 2), (0, 1)])) g.add_directed(frozenset([3]), frozenset([2])) value = edge_choice_for_algo1(BasicTreeConstruction(g)) expected = frozenset([frozenset([1]), frozenset([0])]) self.assertEqual(value, expected)
def test_homogeneous_subset_2(self): g = BinaryMixedTree( MixedGraph({0, 1, 2, 3, 4, 5}, [(1, 2), (2, 3), (3, 4), (4, 5)])) g.add_directed(frozenset([0]), frozenset([1])) value = g.homogeneous_subset() expected = {frozenset([0])} self.assertEqual(value, expected)
def test_init_one_edge(self): g = BinaryMixedTree(MixedGraph({1, 2}, [(1, 2)])) v_xy = g.add_union(frozenset([1]), frozenset([2])) expected = BinaryMixedTree(MixedGraph({1, 2})) expected.add(frozenset([1, 2])) expected.add_directed(frozenset([1]), frozenset([1, 2])) expected.add_directed(frozenset([2]), frozenset([1, 2])) self.assertEqual(g, expected) self.assertEqual(v_xy, frozenset([1, 2]))
def test_restrict(self): g = BinaryMixedTree(MixedGraph({0, 1, 2, 3}, [(0, 1), (1, 2)])) g.add_directed(frozenset([1]), frozenset([3])) h = g.restriction( frozenset([frozenset([0]), frozenset([1]), frozenset([2])])) self.assertEqual( h, BinaryMixedTree(MixedGraph({0, 1, 2}, [(0, 1), (1, 2)])))
def test_undirected_tree(self): g = BinaryMixedTree(MixedGraph({0, 1, 2, 3}, [(0, 1), (1, 2)])) g.add_directed(frozenset([2]), frozenset([3])) h = g.underlying_undirected_graph() self.assertEqual( h, Graph.from_edges([(frozenset([0]), frozenset([1])), (frozenset([1]), frozenset([2])), (frozenset([2]), frozenset([3]))]))
def test_A_set(self): t = BinaryMixedTree(MixedGraph({1, 2, 3})) t.add(frozenset([1, 3])) t.add_directed(frozenset([1]), frozenset([2])) t.add_directed(frozenset([1]), frozenset([1, 3])) s = s_0(t) s[frozenset([1, 3])] = {frozenset([3]), frozenset([1])} delta_plus = t(frozenset([1]), undirected=False, begin=True, end=False, closed=False) A = line_14(delta_plus, s, frozenset([1])) self.assertEqual(A, {frozenset([2]), frozenset([3])})
def test_one_undirected(self): g = BinaryMixedTree(MixedGraph({0, 1, 2}, [(0, 1)])) g.add_directed(frozenset([1]), frozenset([2])) value_graph_2, value_map_2 = BasicTreeConstruction(g, s_0(g)).step(StratAlgo1()) expected_graph = BinaryMixedTree(MixedGraph({2})) expected_graph.add(frozenset([0, 1])) expected_graph.add_undirected(frozenset([2]), frozenset([0, 1])) expected_map = {frozenset([0]): {frozenset([0])}, frozenset([1]): {frozenset([1])}, frozenset([2]): {frozenset([2])}, frozenset([0, 1]): {frozenset([0]), frozenset([1])}} self.assertEqual(value_graph_2, expected_graph) self.assertEqual(value_map_2, expected_map)
def test_one_edge_available(self): h = HyperGraph(frozenset([frozenset([1]), frozenset([2]), frozenset([3])]), frozenset([frozenset([frozenset([1])]), frozenset([frozenset([2])]), frozenset([frozenset([3])]), frozenset([frozenset([1]), frozenset([2])]), frozenset([frozenset([2]), frozenset([3])]), frozenset([frozenset([i + 1]) for i in range(3)]) ])) t = BinaryMixedTree(MixedGraph({1, 2, 3}, [(1, 3)])) t.add_directed(frozenset([1]), frozenset([2])) self.assertEqual(edge_choice_for_algo3(BasicTreeConstruction(t, s_0(t), h)), frozenset([frozenset([1]), frozenset([3])]))
def test_empty_delta_z(self): h = HyperGraph(frozenset([frozenset([1]), frozenset([2]), frozenset([3])]), frozenset([frozenset([frozenset([1])]), frozenset([frozenset([2])]), frozenset([frozenset([3])]), frozenset([frozenset([1]), frozenset([2])]), frozenset([frozenset([2]), frozenset([3])]), frozenset([frozenset([i + 1]) for i in range(3)]) ])) t = BinaryMixedTree(MixedGraph({1, 2, 3})) t.add(frozenset([1, 3])) t.add_directed(frozenset([1]), frozenset([2])) self.assertEqual( delta_z_subset_algo3(BasicTreeConstruction(t, s_0(t), h), set(), frozenset([1, 3]), frozenset([1])), set())
def test_line_16_2(self): t = BinaryMixedTree(MixedGraph({1, 2, 3, 4, 5, 6}, [(3, 6)])) t.add(frozenset([1, 3])) t.add_directed(frozenset([1]), frozenset([2])) t.add_directed(frozenset([3]), frozenset([4])) t.add_directed(frozenset([1]), frozenset([1, 3])) t.add_undirected(frozenset([1, 3]), frozenset([5])) s = s_0(t) s[frozenset([1, 3])] = {frozenset([1]), frozenset([3])} delta_plus = t(frozenset([1]), undirected=False, begin=True, end=False, closed=False) A = line_14(delta_plus, s, frozenset([1])) dict_s = line_16(A, delta_plus, s) self.assertEqual(dict_s, {frozenset([2]): frozenset([2]), frozenset([3]): frozenset([1, 3])})
def test_edge_choice(self): g = HyperGraph(frozenset([frozenset([i]) for i in range(1, 7)])) for i in range(1, 7): g.add_edge(frozenset([frozenset([i])])) g.add_edge(frozenset([frozenset([i]) for i in range(1, 7)])) g.add_edge(frozenset([frozenset([1]), frozenset([2])])) g.add_edge(frozenset([frozenset([4]), frozenset([5])])) g.add_edge(frozenset([frozenset([5]), frozenset([6])])) g.add_edge(frozenset([frozenset([4]), frozenset([5]), frozenset([6])])) g.add_edge(frozenset([frozenset([3]), frozenset([4]), frozenset([5])])) g.add_edge(frozenset([frozenset([3]), frozenset([4]), frozenset([5]), frozenset([6])])) g.add_edge(frozenset([frozenset([1]), frozenset([2]), frozenset([3]), frozenset([4]), frozenset([5])])) t = BinaryMixedTree(MixedGraph({1, 2, 3, 4, 5, 6}, [(1, 3), (3, 6), (1, 5)])) t.add_directed(frozenset([1]), frozenset([2])) t.add_directed(frozenset([3]), frozenset([4])) self.assertEqual(edges_in_homogeneous_subset(t, t.homogeneous_subset()), list(t.edges[0])) value = edge_choice_for_algo3(BasicTreeConstruction(t, s_0(t), g)) self.assertEqual(value, frozenset([frozenset([1]), frozenset([3])]))
def test_hypergraph_1(self): h = HyperGraph(frozenset([frozenset([1]), frozenset([2]), frozenset([3])]), frozenset([frozenset([frozenset([1])]), frozenset([frozenset([2])]), frozenset([frozenset([3])]), frozenset([frozenset([1]), frozenset([2])]), frozenset([frozenset([2]), frozenset([3])]), frozenset([frozenset([i + 1]) for i in range(3)]) ])) t = BinaryMixedTree(MixedGraph({1, 2, 3}, [(1, 3)])) t.add_directed(frozenset([1]), frozenset([2])) maps = s_0(t) next_tree, next_map = BasicTreeConstruction(t, maps, h).step(StratAlgo3()) self.assertEqual( {frozenset([1]): {frozenset([1])}, frozenset([2]): {frozenset([2])}, frozenset([3]): {frozenset([3])}, frozenset([1, 3]): {frozenset([1]), frozenset([3])}}, next_map) expected_graph = BinaryMixedTree(MixedGraph({2})) expected_graph.add(frozenset([1, 3])) expected_graph.add_undirected(frozenset([2]), frozenset([1, 3])) self.assertEqual(expected_graph, next_tree)
def test_delta_z(self): g = HyperGraph(frozenset([frozenset([i]) for i in range(1, 7)])) for i in range(1, 7): g.add_edge(frozenset([frozenset([i])])) g.add_edge(frozenset([frozenset([i]) for i in range(1, 7)])) g.add_edge(frozenset([frozenset([1]), frozenset([2])])) g.add_edge(frozenset([frozenset([4]), frozenset([5])])) g.add_edge(frozenset([frozenset([5]), frozenset([6])])) g.add_edge(frozenset([frozenset([4]), frozenset([5]), frozenset([6])])) g.add_edge(frozenset([frozenset([3]), frozenset([4]), frozenset([5])])) g.add_edge(frozenset([frozenset([3]), frozenset([4]), frozenset([5]), frozenset([6])])) g.add_edge(frozenset([frozenset([1]), frozenset([2]), frozenset([3]), frozenset([4]), frozenset([5])])) t = BinaryMixedTree(MixedGraph({1, 2, 3, 4, 5, 6}, [(3, 6), (1, 5)])) s = s_0(t) s[frozenset([1, 3])] = {frozenset([1]), frozenset([3])} t.add(frozenset([1, 3])) t.add_directed(frozenset([1]), frozenset([2])) t.add_directed(frozenset([3]), frozenset([4])) expected = {frozenset([5])} value = delta_z_subset_algo3(BasicTreeConstruction(t, s, g), frozenset([frozenset([5])]), frozenset([1, 3]), frozenset([1])) self.assertEqual(expected, value)
def test_hypergraph_2(self): g = HyperGraph(frozenset([frozenset([i]) for i in range(1, 7)])) for i in range(1, 7): g.add_edge(frozenset([frozenset([i])])) g.add_edge(frozenset([frozenset([i]) for i in range(1, 7)])) g.add_edge(frozenset([frozenset([1]), frozenset([2])])) g.add_edge(frozenset([frozenset([4]), frozenset([5])])) g.add_edge(frozenset([frozenset([5]), frozenset([6])])) g.add_edge(frozenset([frozenset([4]), frozenset([5]), frozenset([6])])) g.add_edge(frozenset([frozenset([3]), frozenset([4]), frozenset([5])])) g.add_edge(frozenset([frozenset([3]), frozenset([4]), frozenset([5]), frozenset([6])])) g.add_edge(frozenset([frozenset([1]), frozenset([2]), frozenset([3]), frozenset([4]), frozenset([5])])) t = BinaryMixedTree(MixedGraph({1, 2, 3, 4, 5, 6}, [(3, 6), (1, 5), (1, 3)])) t.add_directed(frozenset([1]), frozenset([2])) t.add_directed(frozenset([3]), frozenset([4])) next_tree, next_map = BasicTreeConstruction(t, s_0(t), g).step(StratAlgo3()) self.assertEqual({frozenset([1]): {frozenset([1])}, frozenset([2]): {frozenset([2])}, frozenset([3]): {frozenset([3])}, frozenset([4]): {frozenset([4])}, frozenset([5]): {frozenset([5])}, frozenset([6]): {frozenset([6])}, frozenset([1, 3]): {frozenset([1]), frozenset([3])} }, next_map) expected_tree = BinaryMixedTree(MixedGraph({2, 5, 3, 4, 6}, [(3, 6)])) expected_tree.add(frozenset([1, 3])) expected_tree.add_undirected(frozenset([1, 3]), frozenset([5])) expected_tree.add_undirected(frozenset([1, 3]), frozenset([2])) expected_tree.add_directed(frozenset([3]), frozenset([1, 3])) expected_tree.add_directed(frozenset([3]), frozenset([4])) self.assertEqual(expected_tree, next_tree)
def test_restrict_error(self): g = BinaryMixedTree(MixedGraph({0, 1, 2, 3}, [(0, 1), (1, 2)])) g.add_directed(frozenset([1]), frozenset([3])) with self.assertRaises(ValueError): g.restriction(frozenset([frozenset([4])]))
def test_no_edge_available(self): g = BinaryMixedTree(MixedGraph({0, 1, 2, 3, 4}, [(0, 1), (1, 2)])) g.add_directed(frozenset([4]), frozenset([0])) g.add_directed(frozenset([3]), frozenset([2])) with self.assertRaises(ValueError): edge_choice_for_algo1(BasicTreeConstruction(g))