From 01bb81bf1173e1789543537c44e813f7833774a5 Mon Sep 17 00:00:00 2001 From: dmack Date: Tue, 10 Nov 2009 21:58:01 +0000 Subject: Tue Nov 10 21:55:22 UTC 2009 Daniel L.C. Mack --- SA_POP/ChangeLog | 20 +++++- SA_POP/utils/SANetGenerator/Net_Complete.py | 100 ++++++++++++++++++++++++++++ SA_POP/utils/SANetGenerator/Net_Skeleton.py | 4 +- SA_POP/utils/SANetGenerator/Rand_Params.py | 75 +++++++++++++++++++++ 4 files changed, 196 insertions(+), 3 deletions(-) create mode 100755 SA_POP/utils/SANetGenerator/Net_Complete.py create mode 100755 SA_POP/utils/SANetGenerator/Rand_Params.py 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 + + * 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 + + * 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 * SA_POP_Types.h: @@ -9,8 +25,8 @@ Mon Nov 9 00:49:19 UTC 2009 William R. Otte * SA_WorkingPlan.cpp: * WorkingPlan.h: - Portablility fixes. - + Portablility fixes. + Wed Nov 4 22:47:08 UTC 2009 John S. Kinnebrew 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("\n") +nfile.write("\n\n\t") +nfile.write("\n\t\n\t\n\t\n\t\n") + +tnode = 1001 +for each in tasks: + ttonum[each] = tnode + nfile.write("\n\t\n\t\t" + str(tnode) + "\n\t\t" + each + "\n\t\t" + str(ParamInfo[1][each]) + "\n\t\t\n\t\t\n\t\n" ) + tnode += 1 + +cnode = 2001 +for each in conds: + ctonum[each] = cnode + nfile.write("\n\t\n\t\t" + str(cnode) + "\n\t\t" + each + "\n\t\t" + str(0) + "\n\t\t0\n\t\t\n\t\t\n\t\n" ) + cnode += 1 + +for each in conds: + plinks = ParamInfo[2][each] + for link in plinks: + nfile.write("\n\t\n\t\t" + str(ctonum[each]) + "\n\t\t" + str(ttonum[link[0]]) + "\n\t\tPort\n\t\t" + str(link[1]) + "\n\t\t0\n\t\t\n") + +for each in tasks: + elinks = ParamInfo[3][each] + for link in elinks: + nfile.write("\n\t\n\t\t" + str(ttonum[each]) + "\n\t\t" + str(ctonum[link[0]]) + "\n\t\tPort\n\t\t" + str(link[1]) + "\n\t\n") + +nfile.write("") +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 + + + + + + + + -- cgit v1.2.1