diff options
author | dmack <dmack@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2009-11-10 21:58:01 +0000 |
---|---|---|
committer | dmack <dmack@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2009-11-10 21:58:01 +0000 |
commit | 01bb81bf1173e1789543537c44e813f7833774a5 (patch) | |
tree | ab0861fc0a8b81b6d264b79e9b32e53074724c65 | |
parent | 22f3879e0f771689a774dad0aa8ad461bdd7b6ee (diff) | |
download | ATCD-01bb81bf1173e1789543537c44e813f7833774a5.tar.gz |
Tue Nov 10 21:55:22 UTC 2009 Daniel L.C. Mack <daniel.l.mack@vanderbilt.edu>
-rw-r--r-- | SA_POP/ChangeLog | 20 | ||||
-rwxr-xr-x | SA_POP/utils/SANetGenerator/Net_Complete.py | 100 | ||||
-rwxr-xr-x | SA_POP/utils/SANetGenerator/Net_Skeleton.py | 4 | ||||
-rwxr-xr-x | SA_POP/utils/SANetGenerator/Rand_Params.py | 75 |
4 files changed, 196 insertions, 3 deletions
diff --git a/SA_POP/ChangeLog b/SA_POP/ChangeLog index c697c630ddb..210cd50e76c 100644 --- a/SA_POP/ChangeLog +++ b/SA_POP/ChangeLog @@ -1,3 +1,19 @@ +Tue Nov 10 21:55:22 UTC 2009 Daniel L.C. Mack <daniel.l.mack@vanderbilt.edu> + + * utils/SANetGenerator/Net_Complete.py: + * utils/SANetGenerator/Net_Skeleton.py: + * utils/SANetGenerator/Rand_Params.py: + + Added the capability of the SANet Generator to utilize some simple parameterization + and output a SANet .xml file + + +Tue Nov 10 21:54:59 UTC 2009 Daniel L.C. Mack <daniel.l.mack@vanderbilt.edu> + + * utils/SANetGenerator/Net_Skeleton.py: + + Updated to fix a bug with knowing when to stop. + Mon Nov 9 00:49:19 UTC 2009 William R. Otte <wotte@dre.vanderbilt.edu> * SA_POP_Types.h: @@ -9,8 +25,8 @@ Mon Nov 9 00:49:19 UTC 2009 William R. Otte <wotte@dre.vanderbilt.edu> * SA_WorkingPlan.cpp: * WorkingPlan.h: - Portablility fixes. - + Portablility fixes. + Wed Nov 4 22:47:08 UTC 2009 John S. Kinnebrew <john.s.kinnebrew@vanderbilt.edu> diff --git a/SA_POP/utils/SANetGenerator/Net_Complete.py b/SA_POP/utils/SANetGenerator/Net_Complete.py new file mode 100755 index 00000000000..7986eabe903 --- /dev/null +++ b/SA_POP/utils/SANetGenerator/Net_Complete.py @@ -0,0 +1,100 @@ +#Daniel L.C. Mack +#Build Random Graphs for SA_POP with simple parameter assignment +#Note, the random values can cause a dead process, am working to find out why. + +import networkx as nx +import re +import sys +import random as rand +import Rand_Skeletons as RS +import Rand_Params as RP + +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]) +outname = sys.argv[6] + +output = outname + ".dot" +outSAN = outname + ".xml" + +ofile = open(output, 'w') +ofile.write("strict digraph testGraph {\n") + +SANet = nx.DiGraph() +tasks = [] +conds = [] +ttonum = {} +ctonum = {} + +#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 +print "Generate Skeleton" +if rGen == 1: + SANet = RS.erdosGen(SANet, tasks, conds, inDegree, outDegree) + +print "Generate Parameters" +#Choose a method for placing probabilities on the skeleton +ParamInfo = RP.flatGen(SANet, tasks, conds) + +#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() + +#Print out a SAN XML +print "Print SAN XML" +nfile = open(outSAN, 'w') +nfile.write("<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n<SANet:network\n\txmlns:SANet=\"http://www.vanderbilt.edu/SANet\"\n") +nfile.write("\txmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n\txsi:schemaLocation=\"http://www.vanderbilt.edu/SANet SANet_Network.xsd\"\n\txmlns=\"http://www.vanderbilt.edu/SANet\">") +nfile.write("\n\n\t") +nfile.write("<defaultAttenFactor />\n\t<defaultTaskCost />\n\t<defaultCondUtil />\n\t<defaultCondProbTrue />\n\t<linkThresh />\n") + +tnode = 1001 +for each in tasks: + ttonum[each] = tnode + nfile.write("\n\t<taskNode>\n\t\t<nodeID>" + str(tnode) + "</nodeID>\n\t\t<name>" + each + "</name>\n\t\t<priorProb>" + str(ParamInfo[1][each]) + "</priorProb>\n\t\t<attenFactor />\n\t\t<cost />\n\t</taskNode>\n" ) + tnode += 1 + +cnode = 2001 +for each in conds: + ctonum[each] = cnode + nfile.write("\n\t<condNode>\n\t\t<nodeID>" + str(cnode) + "</nodeID>\n\t\t<name>" + each + "</name>\n\t\t<probTrue>" + str(0) + "</priorProb>\n\t\t<utility>0</utility>\n\t\t<kind />\n\t\t<attenFactor />\n\t</condNode>\n" ) + cnode += 1 + +for each in conds: + plinks = ParamInfo[2][each] + for link in plinks: + nfile.write("\n\t<precondLink>\n\t\t<condID>" + str(ctonum[each]) + "</condID>\n\t\t<taskID>" + str(ttonum[link[0]]) + "</taskID>\n\t\t<portID>Port</portID>\n\t\t<trueProb>" + str(link[1]) + "</trueProb>\n\t\t<falseProb>0</falseProb>\n\t\t</precondLink>\n") + +for each in tasks: + elinks = ParamInfo[3][each] + for link in elinks: + nfile.write("\n\t<effectLink>\n\t\t<taskID>" + str(ttonum[each]) + "</taskID>\n\t\t<condID>" + str(ctonum[link[0]]) + "</condID>\n\t\t<portID>Port</portID>\n\t\t<weight>" + str(link[1]) + "</weight>\n\t</effectLink>\n") + +nfile.write("</SANet:network>") +nfile.close() + + + + + +
\ No newline at end of file diff --git a/SA_POP/utils/SANetGenerator/Net_Skeleton.py b/SA_POP/utils/SANetGenerator/Net_Skeleton.py index 502e95eab8b..50ded82b1be 100755 --- a/SA_POP/utils/SANetGenerator/Net_Skeleton.py +++ b/SA_POP/utils/SANetGenerator/Net_Skeleton.py @@ -34,7 +34,9 @@ for each in range(0,Nconds+1): #Choose function to generate from if rGen == 1: - SANet = RS.erdosGen(SANet, tasks, conds, inDegree, outDegree) + 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: diff --git a/SA_POP/utils/SANetGenerator/Rand_Params.py b/SA_POP/utils/SANetGenerator/Rand_Params.py new file mode 100755 index 00000000000..5efad373c31 --- /dev/null +++ b/SA_POP/utils/SANetGenerator/Rand_Params.py @@ -0,0 +1,75 @@ +#!/usr/bin/env python +# encoding: utf-8 +""" +Rand_Params.py +Created by Daniel Mack on 2009-10-27. +Generates Random Parameters for a Skeleton +""" + +import sys +import os +import networkx as nx +import random as rand + +#Uniform +def flatGen(SANet, tasks, conds): + effLinks = {} + preLinks = {} + priors = {} + + #use the tasks as the starting point for assigning probabilities + for each in tasks: + effects = SANet.successors(each) + effLinks[each] = [] + effAr = effLinks[each] + for eff in effects: + #uses uniform for the time being + weight = rand.uniform(0,2) - 1 + #a tuple for efficient look up + lnk = (eff, weight) + effAr.append(lnk) + + effLinks[each] = effAr + + preconds = SANet.predecessors(each) + + #this is uniform at .5 probability across all tasks + prior = 1.0 + preprob = 0.0 + #must have preconditions + #TEMP#TEMP#TEMP#TEMPTEMP#TEMP#TEMP#TEMP + #currently all preconditions must be positive + #TEMP#TEMP#TEMP#TEMP#TEMP#TEMP#TEMP#TEMP + if len(preconds) > 0: + #Value is .5 to the power of the number of preconditions + prior = pow(.5, len(preconds)) + #Each precondition probability is .5 to the number of preconditions - 1 + #Should work for positive and negative, but for now, all preconditions are positive. + preprob = pow(.5, (len(preconds) - 1)) + + priors[each] = prior + + #Book keeping for the graph. + #Assemble information on precondition links + for pre in preconds: + if pre in preLinks: + temp = preLinks[pre] + #A pair of task and precondition probability from the given conditon + temp.append((each,preprob)) + preLinks[pre] =temp + else: + lnks = [] + lnks.append((each, preprob)) + preLinks[pre] = lnks + + #returns the network structure, the priors on the tasks and hashmaps of the links and their values + info = (SANet, priors, preLinks, effLinks) + return info + + + + + + + + |