import numpy as np
import networkx as nx
population = 20
nodes = [0,1,2,3,4,5,6,7,8,9,10]
edges = [(0,1),(0,4),(1,2),(2,3),(1,3),(3,0),(0,2),(4,5),(5,6),(6,7),(10,8),(10,9),(8,9),(8,7),(9,7),(7,10)]
graph = nx.Graph()
graph.add_nodes_from(nodes)
graph.add_edges_from(edges)
Adj = nx.adjacency_matrix(graph)
print(Adj)
nodes_length = len(graph.nodes())
print(nodes_length)
def generate_chrom(nodes_length,Adj):
chrom = np.array([],dtype=int)
for x in range(nodes_length):
rand = np.random.randint(0,nodes_length)
while Adj[x,rand] != 1:
rand = np.random.randint(0,nodes_length)
chrom = np.append(chrom,rand)
return chrom
d = [generate_chrom(nodes_length, Adj) for n in range(population)]
print(d)