안녕하세요, 저는 python을 처음 사용하고 있고, +1 기호가있는 노드 클러스터를 찾기 위해 첫 프로그램을 만들려고합니다.defaultdict의 올바른 위치에 요소를 넣으십시오.
1 2 1
1 3 1
2 3 1
2 4 -1
2 5 1
3 6 -1
4 7 -1
4 9 -1
내가 그래프를 작성하는 I가 사전에있는 모든 인접를 저장 :이 같은 (노드간에 서명, 노드를 종료 노드 시작) 3 열이있는 파일이 있습니다. 이제 다른 사전 (defaultdict (list))에 모든 슈퍼 노드 (그 사이에 +1 부호가있는 팀 노드)를 저장하려고합니다. 내가 DICT의 올바른 위치에 요소를 넣어하는 방법을 잘 모릅니다 때문에 내가 여기에 코드를 중지
G = nx.Graph()
G = nx.read_edgelist('example.txt', delimiter='\t', nodetype=int, data=(('sign', int),))
adjacencies = {}
supernodes = defaultdict(list)
for i in G.nodes:
adjacencies[i] = list(G.neighbors(i))
flag = 0
if flag == 0:
for node in G.nodes:
supernodes[node].append(node)
flag = 1
break
else:
for i in G.nodes():
for j in adjacencies[i]:
if G.get_edge_data(i,j) == 1:
for v in supernodes.values():
: 그래서 나는 다음과 같은 코드를 썼습니다. 내가하고 싶은 단계는 다음과 같습니다 내가 좋아하는 개의 supernode 있습니다
1 : [1,2,3,5]
2 : [4]
3 : [6,8]
등
1. check if edge(i,j) is +1 and then
2. if i is in supernodes then add j in the same list where i is
3. if j is in supernodes then add i in the same list where j is
4. if i and j is not in supernodes the add a new list in supernodes and add
i,j elements
이것은 +1 부호를 가진 모든 노드의 이웃을 계산합니다. 뭔가 다른 것을하려고 노력하고있는 Im. 나는이 그래프를 여기에 가지고있다 : [link] (http://images.slideplayer.com/12/3525987/slides/slide_24.jpg) 나는 supernodes를 찾아야한다. 그래프의 슈퍼 노드는 얼룩입니다. –
완전히 솔직하게 질문하는 것은 오해의 소지가 있습니다. 슈퍼 노드 집합이라고 부르는 것을 얻기 위해 편집을 참조하십시오. – rodgdor