from sympy import *
import numpy as np
import networkx as nx
G=nx.Graph()
with open ("testing.txt", "r") as myfile:
Matrice=eval(myfile.readline())
Matnum = np.array(np.array(Matrice))
Matnum = Matnum.astype(np.int, copy=False)
G.add_node(Matnum.shape[1])
for i in range(0,Matnum.shape[1]):
for j in range(i+1,Matnum.shape[1]):
if Matnum[i,j] == 1:
G.add_edge(i,j)
print nx.max_clique(G)
有关信息,读取行是由另一个脚本创建的Matrix:
Matrix([[1, 1, 1, 0, 0, ....... 0, 0, 1, 0, 1]])
你有解决方案吗? THKS
答案 0 :(得分:8)
文档对于它所在的位置有点模棱两可,但以下内容对我有用:
In [4]:
G = nx.complete_graph(4)
from networkx.algorithms.approximation import clique
clique.max_clique(G)
Out[4]:
{0, 1, 2, 3}