def test_one_edge(self):
        g = BinaryMixedTree(MixedGraph({1, 2}, [(1, 2)]))

        value = edge_choice_for_algo1(BasicTreeConstruction(g))
        expected = frozenset([frozenset([1]), frozenset([2])])

        self.assertEqual(expected, value)
    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_one_undirected(self):
        g = BinaryMixedTree(MixedGraph({0, 1, 2, 3, 4}, [(2, 3)]))
        g.update(DIRECTED_EDGE, [(frozenset([2]), frozenset([0])),
                                 (frozenset([3]), frozenset([1])),
                                 (frozenset([3]), frozenset([4]))],
                 node_creation=False)

        value = edge_choice_for_algo1(BasicTreeConstruction(g))
        expected = frozenset([frozenset([3]), frozenset([2])])

        self.assertEqual(expected, value)
    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])]))
예제 #5
0
    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_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())
예제 #7
0
    def test_tree_sequence(self):
        g = BinaryMixedTree(MixedGraph({0, 1}, [(0, 1)]))

        g2 = BinaryMixedTree(MixedGraph())
        g2.add(frozenset([0, 1]))

        expected = [
            (g, s_0(g)),
            (g2, {
                frozenset([1]): {frozenset([1])},
                frozenset([0]): {frozenset([0])},
                frozenset([0, 1]): {frozenset([0]), frozenset([1])}
            }
             )
        ]
        value = BasicTreeConstruction(g, s_0(g)).tree_sequence(StratAlgo1())

        self.assertEqual(value, expected)
    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_edge_choice_for_algo3(self):
        h = HyperGraph(
            frozenset([frozenset([1]), frozenset([2]), frozenset([3]), frozenset([4]), frozenset([5]), frozenset([6])]),
            frozenset([frozenset([frozenset([1])]),
                       frozenset([frozenset([2])]),
                       frozenset([frozenset([3])]),
                       frozenset([frozenset([4])]),
                       frozenset([frozenset([5])]),
                       frozenset([frozenset([6])]),
                       frozenset([frozenset([4]), frozenset([5])]),
                       frozenset([frozenset([5]), frozenset([6])]),
                       frozenset([frozenset([1]), frozenset([2]), frozenset([3]), frozenset([4]), frozenset([5]),
                                  frozenset([6])])]))

        g = BinaryMixedTree(MixedGraph({1, 2, 3, 4, 5, 6}, [(1, 2), (2, 4), (4, 3), (4, 5), (5, 6)]))
        map = s_0(g)

        value = edge_choice_for_algo3(BasicTreeConstruction(g, map, h))
        expected = frozenset({frozenset([4]), frozenset([5])})

        self.assertEqual(list(g.edges[0]), edges_in_homogeneous_subset(g, g.homogeneous_subset()))
        self.assertEqual(expected, value)
    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)
예제 #11
0
    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)
예제 #12
0
    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_multiple_edges_available(self):
     g = BinaryMixedTree(MixedGraph({0, 1, 2, 3}, [(0, 1), (0, 2), (2, 3)]))
     value = edge_choice_for_algo1(BasicTreeConstruction(g))
     self.assertTrue(value in g.edges[0])
 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))
 def test_no_edge(self):
     g = BinaryMixedTree(MixedGraph({1}))
     with self.assertRaises(ValueError):
         edge_choice_for_algo1(BasicTreeConstruction(g))