コード例 #1
0
    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)
コード例 #2
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)
コード例 #3
0
    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)
コード例 #4
0
    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])]))
コード例 #5
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)