In my code, I can only choose whether the graph is oriented, weighted, and the number of edges and I can't select the number of vertices.
Is there any way to add a parameter to my function control to select the number of vertices?
My code is below:
list_adj = []
list_w = []
def graph(list_adj,length,weight,oriented):
count = 0
#non oriented
if oriented == False:
list_adj_non_o = [ [] for i in range(length) ]
for i in range(length):
k = random.randint(0,length-1)
if k != i and k not in list_adj_non_o[i]:
list_adj_non_o[i].append(k)
if k != i and k not in list_adj_non_o[k]:
list_adj_non_o[k].append(i)
count +=1
if weight == True:
list_w.append(random.randint(1,10))
else:
list_w.append(1)
print("list_adj_non_o : ",list_adj_non_o)
print("list_w : ", list_w)
print("number of vertices : ",count)
return list_adj_non_o
graph(list_adj,10,False,False)
Thank you for helping me.