File size: 415 Bytes
4919e19
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
import random
from graph_module import Graph

def generate_random_graph(num_vertices, density):
    graph = Graph(num_vertices, directed=True)
    for u in range(num_vertices):
        for v in range(num_vertices):
            if u == v:
                continue
            if random.random() < density:
                weight = random.randint(-2, 10)
                graph.add_edge(u, v, weight)
    return graph