コード例 #1
0
    def test_isomorphic_wedges(self):
        wedge = Subgraph(nodes=[(1, 1), (2, 1), (3, 2)],
                         edges=[(1, 2, 1), (1, 3, 2)])

        isomorphic_wedge = Subgraph(nodes=[(5, 2), (8, 1), (15, 1)],
                                    edges=[(5, 15, 2), (8, 15, 1)])

        cl1 = canonical_label(wedge)
        cl2 = canonical_label(isomorphic_wedge)

        self.assertEqual(cl1, cl2,
                         "non-matching canonical labels of isomorphic wedges")
コード例 #2
0
    def test_non_isomorphic_triangles(self):
        triangle = Subgraph(nodes=[(1, 1), (2, 1), (3, 2)],
                            edges=[(1, 2, 1), (1, 3, 2), (2, 3, 1)])

        non_isomorphic_triangle = Subgraph(nodes=[(1, 1), (2, 2), (3, 2)],
                                           edges=[(1, 2, 1), (1, 3, 2),
                                                  (2, 3, 1)])

        cl1 = canonical_label(triangle)
        cl2 = canonical_label(non_isomorphic_triangle)

        self.assertNotEqual(
            cl1, cl2, "matching canonical labels of non-isomorphic triangles")
コード例 #3
0
def calculate_T_k(k, L, Q):
    min_edges = k - 1
    max_edges = sum(range(1, k))

    potential_edges = list(combinations(range(k), 2))

    possible_patterns = set()

    for vertex_labels in product(range(1, L + 1), repeat=k):
        nodes = list(enumerate(vertex_labels))

        for num_edges in range(min_edges, max_edges + 1):

            for edges in combinations(potential_edges, num_edges):
                edges = list(edges)
                if _is_connected(edges):

                    for edge_labels in product(range(1, Q + 1),
                                               repeat=num_edges):
                        subgraph = make_subgraph(nodes, [
                            SubgraphEdge(u, v, l)
                            for (u, v), l in zip(edges, edge_labels)
                        ])
                        possible_patterns.add(canonical_label(subgraph))

    return len(possible_patterns)
コード例 #4
0
 def remove_subgraph(self, subgraph):
     self.patterns[canonical_label(subgraph)] -= 1
コード例 #5
0
 def add_subgraph(self, subgraph):
     self.patterns[canonical_label(subgraph)] += 1
コード例 #6
0
 def remove_subgraph(self, subgraph):
     self.patterns.subtract([canonical_label(subgraph)])
コード例 #7
0
 def add_subgraph(self, subgraph):
     self.patterns.update([canonical_label(subgraph)])