forked from sysu-eda/DeepRL-Scheduling
-
Notifications
You must be signed in to change notification settings - Fork 0
/
dag_generator.py
51 lines (46 loc) · 1.52 KB
/
dag_generator.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'''
Copyright 2018 Hongzheng Chen
E-mail: [email protected]
This is the implementation of Deep-reinforcement-learning-based scheduler for High-Level Synthesis.
This file contains the random DAG generator.
'''
from graph import Graph
import random
NUM_GRAPH = 5000
class DAGGen(object):
def __init__(self, num, tot_node=50, min_per_layer=1, max_per_layer=5, link_rate=0.5, mul_rate=0.3):
res = "digraph {\n"
res += " node [fontcolor=black]\n"
res += " property [mul=%d,lf=%.1f]\n" % (random.randint(2,5),random.uniform(1.0,2.0))
nowNode = 0
edges = []
pre_layer = []
while nowNode < tot_node:
newNode = random.randint(min_per_layer, max_per_layer)
if nowNode + newNode > tot_node:
newNode = tot_node - nowNode
cur_layer = []
for i in range(nowNode,nowNode + newNode):
cur_layer.append(i)
for j in pre_layer:
for k in cur_layer:
if random.random() < link_rate:
edges.append((j,k))
pre_layer = cur_layer[:]
nowNode += newNode
for i in range(tot_node):
if random.random() < mul_rate:
typename = "mul"
else:
typename = "add"
res += " %d [ label = %s ];\n" % (i, typename)
for (step,edge) in enumerate(edges):
res += " %d -> %d [ name = %d ];\n" % (edge[0],edge[1],step)
res += "}\n"
output = open("./DAG/dag_" + str(num) + ".dot","w")
output.write(res)
output.close()
for i in range(1,NUM_GRAPH+1):
DAGGen(i,tot_node=random.randint(10,50),mul_rate=random.uniform(0.3,0.5))
if i % 100 == 0:
print("Generated %d / %d DAGs." % (i,NUM_GRAPH))