diff options
author | dmack <dmack@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2009-10-20 19:22:10 +0000 |
---|---|---|
committer | dmack <dmack@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2009-10-20 19:22:10 +0000 |
commit | 2327627f86535caf18fafb97b0b24103b4d37ef8 (patch) | |
tree | a728b60cbdc8b16eef71c9d60ec6f83c47c30450 | |
parent | 27926fe3de408cb90048ce7507843fae88add755 (diff) | |
download | ATCD-SAPOP_Threat_dev.tar.gz |
Tue Oct 20 19:20:36 UTC 2009 Daniel L.C. Mack <daniel.l.mack@vanderbilt.edu>SAPOP_Threat_dev
-rw-r--r-- | ChangeLog | 12 | ||||
-rwxr-xr-x | utils/SANetGenerator/Net_Skeleton.py | 56 | ||||
-rwxr-xr-x | utils/SANetGenerator/Rand_Skeletons.py | 75 |
3 files changed, 142 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog index 641f0ffa5c0..89cfa749d0e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,13 @@ +Tue Oct 20 19:20:36 UTC 2009 Daniel L.C. Mack <daniel.l.mack@vanderbilt.edu> + + * utils/SANetGenerator: + + * utils/SANetGenerator/Net_Skeleton.py: + * utils/SANetGenerator/Rand_Skeletons.py: + + Added the initial files for generating SANets. Rand Skeletons is for different + random graph algorithms. Net Skeleton is a sample program using Rand Skeletons. + Thu Oct 15 00:40:20 UTC 2009 Ben Podgursky <bpodgursky@gmail.com> * C2W/C2W_Demo.cpp: @@ -20,7 +30,7 @@ Thu Oct 15 00:40:20 UTC 2009 Ben Podgursky <bpodgursky@gmail.com> * utils/PDDLtoSANetTranslator/PDDLParser/src/pddl4j/ErrorManager.java: - Eliminated initial action + Eliminated initial action Sun Oct 4 19:44:35 UTC 2009 Ben Podgursky <bpodgursky@gmail.com> diff --git a/utils/SANetGenerator/Net_Skeleton.py b/utils/SANetGenerator/Net_Skeleton.py new file mode 100755 index 00000000000..502e95eab8b --- /dev/null +++ b/utils/SANetGenerator/Net_Skeleton.py @@ -0,0 +1,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() + + + + + + +
\ No newline at end of file diff --git a/utils/SANetGenerator/Rand_Skeletons.py b/utils/SANetGenerator/Rand_Skeletons.py new file mode 100755 index 00000000000..76b1ea05932 --- /dev/null +++ b/utils/SANetGenerator/Rand_Skeletons.py @@ -0,0 +1,75 @@ +#Daniel Mack +#Random Skeleton Generators + +import networkx as nx +import random as rand + + +#Modified Erdos-Renyi Graph Generator +def erdosGen(SANet, tasks, conds, inDegree, outDegree): + inD = {} + outD = {} + pairs = {} + haltGen = 0; + haltOut = 0; + haltIn = 0; + + #continue until the graph has met the in/out degreee limits + while haltGen == 0: + ctask = "" + ccond = "" + found = 0 + while found == 0: + #Choose Task + ctask = tasks[rand.randrange(len(tasks))] + #Choose Cond + ccond = conds[rand.randrange(len(conds))] + key = ctask + "," + ccond + #if already been used as either an effect or precondition + if key in pairs: + found = 0 + else: + #valid pair for random pairing + found = 1 + pairs[key] = 1 + + #choose direction + EfforPre = rand.randrange(2) + + #If 0 then it's a precondition link + if EfforPre == 0 and haltIn == 0: + SANet.add_edge(ccond, ctask) + if ctask in inD: + inD[ctask] += 1 + else: + inD[ctask] = 1 + elif haltOut == 0: + #otherwise it's an effect + SANet.add_edge(ctask, ccond) + if ctask in outD: + outD[ctask] += 1 + else: + outD[ctask] = 1 + + #Check for Stopping Conditions + totalIn = 0.0 + totalOut = 0.0 + for each in tasks: + if each in inD: + totalIn += inD[each] + if each in outD: + totalOut += outD[each] + avgIn = totalIn/len(tasks) + avgOut = totalOut/len(tasks) + + + if avgIn >= inDegree: + haltIn = 1 + if avgOut >= outDegree: + haltOut = 1 + if haltIn == 1 and haltOut == 1: + print avgIn + print avgOut + haltGen = 1 + + return SANet
\ No newline at end of file |