当递归调用“ clique”时,会给出一个属性错误,提示“ AttributeError:'NoneType'对象没有属性'nodes'“。如何在不创建类的情况下解决此问题。我只想将C和gmax作为图形对象进行处理?请,谢谢。实现是分支,是集团问题的束缚
def clique(C,P,gmax): #sub funtion
if (len(list(C.nodes))>len(list(gmax.nodes))):
gmax=C
if (len(list(C.nodes)))+len(P)>len(list(gmax.nodes)):
for i in range(len(P)):
p=P[0]#lowest vertex degree
P=np.delete(P,np.where(P==P[0])) #remove the lowest degree vertex
C1=nx.Graph()
C1=C1.add_nodes_from(list(C.nodes)+[p])#add vertex p to new clique
P1=np.array([])
P1=np.in1d(np.array(list(G.adj[p])),P)
clique(C1,P1,gmax)
return
def CP(G):#main funciton
gmax=nx.Graph() #contains max clique
V=[node for (node,val) in sorted(G.degree(),key=lambda pair: pair[1])]#sorts degree of vertices low to high
C=nx.Graph()
P=np.array(V)
clique(C,gmax)
return list(gmax.nodes)