summaryrefslogtreecommitdiff
path: root/SA_POP/utils/SANetGenerator/Net_Skeleton.py
blob: 502e95eab8bb4e0de091894d6a50677a92a66468 (plain)
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
52
53
54
55
56
#Daniel L.C. Mack
#Build Random Skeletons for SA_POP

import networkx as nx
import re
import sys
import random as rand
import Rand_Skeletons as RS

Ntasks = int(sys.argv[1]) 
Nconds = int(sys.argv[2])
inDegree = float(sys.argv[3])
outDegree = float(sys.argv[4])
rGen = int(sys.argv[5])
output = sys.argv[6]

ofile = open(output, 'w')
ofile.write("strict digraph testGraph {\n")

SANet = nx.DiGraph()
tasks = []
conds = []

#Build and record different types of nodes
for each in range(0,Ntasks+1):
	tname = "task" + str(each)
	SANet.add_node(tname)
	tasks.append(tname)
	
for each in range(0,Nconds+1):
	cname = "cond" + str(each)
	SANet.add_node(cname)
	conds.append(cname)	

#Choose function to generate from
if rGen == 1:
	SANet = RS.erdosGen(SANet, tasks, conds, inDegree, outDegree)		

#Print out the graph currently into something resembling an SANet, for GraphViz to render			
for each in tasks:
	ofile.write("\"" + each + "\" [shape = box, style=filled, color = grey];\n"  )

for each in conds:
	ofile.write("\"" + each +"\" [ style=filled, color = grey];\n")
	
for edge in SANet.edges():
	ofile.write("\"" + edge[0] + "\" -> \"" + edge[1] + "\";\n")
ofile.write("}\n")
ofile.close()