示例#1
0
def CliqueNumEqualsChromaticNum(G):
    
    result = False
    if (graph_clique_number(G) == chromatic_number(G)):
        result = True
    
    return result
def ChromaticNumberEqualsCLiqueNumber(G):
    
    if(chromatic_number(G) == graph_clique_number(G)):
        result = True
    else:
        result = False
    
    return result
示例#3
0
    def compute_features(self):

        # graph clique number
        self.add_feature(
            "graph_clique_number",
            lambda graph: clique.graph_clique_number(graph),
            "The clique number of a graph is the size of the largest clique in the graph",
            InterpretabilityScore(3),
        )

        # number of maximal cliques
        self.add_feature(
            "num_max_cliques",
            lambda graph: clique.graph_number_of_cliques(graph),
            "The number of maximal cliques in the graph",
            InterpretabilityScore(3),
        )

        n_cliques = lambda graph: len([
            u for u in list(clique.enumerate_all_cliques(graph)) if len(u) > 1
        ])
        self.add_feature(
            "num_cliques",
            n_cliques,
            "The number of cliques in the graph",
            InterpretabilityScore(3),
        )

        clique_sizes = lambda graph: [
            len(u) for u in list(clique.enumerate_all_cliques(graph))
            if len(u) > 1
        ]
        self.add_feature(
            "clique_sizes",
            clique_sizes,
            "the distribution of clique sizes",
            InterpretabilityScore(3),
            statistics="centrality",
        )

        @lru_cache(maxsize=None)
        def eval_cliques(graph):
            """this evaluates the main function and cach it for speed up."""
            cliques = [
                len(u) for u in list(clique.find_cliques(graph)) if len(u) > 1
            ]
            return np.bincount(cliques)[np.nonzero(np.bincount(cliques))]

        maximal_clique_sizes = (
            lambda graph: eval_cliques(graph)[0] / eval_cliques(graph)[-1])
        self.add_feature(
            "clique_sizes_maximal",
            maximal_clique_sizes,
            "the ratio of number of max and min size cliques",
            InterpretabilityScore(3),
        )
示例#4
0
def sizeoflargestclique(a):

    from networkx.algorithms import approximation, clique

    largestcliquesize = clique.graph_clique_number(a)
    print(largestcliquesize)
示例#5
0
        #add the new node
        vertexToAddNum = resultGraph.number_of_nodes()
        resultGraph.add_node(vertexToAddNum)
        x_sets[vertexIndex % CYCLE_LENGTH].append(vertexToAddNum)
        #add its edges
        resultGraph.add_edge( (vertexToAddNum - 1) % CYCLE_LENGTH, vertexToAddNum )
        resultGraph.add_edge( vertexToAddNum % CYCLE_LENGTH, vertexToAddNum)
        resultGraph.add_edge( (vertexToAddNum + 1) % CYCLE_LENGTH, vertexToAddNum)

    #x_i forms a clique
    for thisXSet in x_sets:
        if(len(thisXSet) > 1):
            for thisCliqueEdge in product(thisXSet, thisXSet):
                if(thisCliqueEdge[0] != thisCliqueEdge[1]):
                    resultGraph.add_edge(thisCliqueEdge[0], thisCliqueEdge[1])
                    
    #X_i joins its neighbours
    for thisXSetIndex in range(0,CYCLE_LENGTH):
        x1 = x_sets[thisXSetIndex]
        x2 = x_sets[(thisXSetIndex+1) % CYCLE_LENGTH]
        for vertexI in x1:
            for vertexJ in x2:
                resultGraph.add_edge(vertexI,vertexJ)
                    
    return resultGraph
 
result = Construct()
print("Clique number: {0}".format(graph_clique_number(result)))
f = File(DIRECTORY, G = result, logger = MY_LOGGER, base="C5-")
f.save()