Created
August 27, 2019 18:17
-
-
Save negedng/03330c14bf191a94d7e0ce73934f8c50 to your computer and use it in GitHub Desktop.
Functions to generate random weighted trees and complete graphs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def random_tree(V): | |
heads = [i for i in range(V-1)] | |
tails = [i+1 for i in range(V-1)] | |
weights = list(np.random.rand(V-1)) | |
G = [[heads[i],tails[i],weights[i]] for i in range(len(heads))] | |
return V, G | |
def random_complete_graph(V): | |
heads, tails, weights = [], [], [] | |
for i in range(V-1): | |
for j in range(i+1, V): | |
heads.append(i) | |
tails.append(j) | |
weights = list(np.random.rand(len(heads))) | |
G = [[heads[i],tails[i],weights[i]] for i in range(len(heads))] | |
return V, G |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment