저는 파이썬과 networkx를 사용하여 노드를 임의로 끄덕임에 할당합니다. 끄덕임은 세 가지 범주 (흰색, 검은 색 및 기타)로 분류되며 각 범주에는 33 개의 노드가 있습니다. 코드가 작동하지만 두 가지 질문이 있습니다. 1- 하나의 노드가 두 번 선택되지 않도록하려면 어떻게합니까? 내 말은 첫 번째 라운드에서 말은 노드 4와 56 사이에 정의 된 에지를 말합니다. 어떻게하면이 라운드를 다시 선택할 수 있습니까? 2- 다음 단계는 내가하고 싶은 일로 와이트를 할당하는 것입니다. 예를 들어, x가 흰색이고 y가 흰색 일 가능성이 높습니다. 이걸 어떻게 추가 할 수 있습니까?임의의 가장자리를 가진 그래프를 배열하십시오.
import networkx as nx
import matplotlib.pyplot as plt
import random
import numpy
G=nx.Graph()
w=1
b=34
o=67
while w < 34:
G.add_node(w, race='white')
w+=1
while b < 67:
G.add_node(b, race='black')
b+=1
while o < 100:
G.add_node(o, race='other')
o+=1
from numpy import random as rand
###first round edges assignment
num1edge = int(raw_input("Please enter number of edges you want to start with: "))
i=0
while i< num1edge:
x1 = rand.randint (1, 99)
y1 = rand.randint (x1, 99)
G.add_edge(x1,y1)
i+=1
numrounds = int(raw_input("Please enter how many times you want to run: "))
numedge = int(raw_input("Please enter number of edges you want to be created in each round: "))
j = 0
k = 0
while j < numrounds:
while k < num1edge:
x = rand.randint (1, 99)
y = rand.randint (x, 99)
G.add_edge(x,y)
k+=1
j+=1
nx.draw(G)
plt.show()