#!/usr/bin/gawk -f BEGIN { FS = OFS = ","; Seed = 1; TotalBins = 20; TotalRuns = 100; Policy = 1; Factor = 0.1; } /^$/ || /\#.*/ { next; } { LayerIndex = 1; GraphIndex = 2; NameIndex = 1+2; OperationIndex = 2+2; GoalPriorityIndex = 3+2; MinIndex = 4+2; MaxIndex = 5+2; GivenDistFlagIndex = 6+2; IsGivenDistIndex = 7+2; IsGoalDistIndex = 8+2; ChildrenCountIndex = 9+2; SanityCheckUniqueNode[$NameIndex]++; TotalNodes++; Layer[TotalNodes] = $LayerIndex; Graph[TotalNodes] = $GraphIndex; Index[$NameIndex] = TotalNodes; Name[TotalNodes] = $NameIndex; Operation[TotalNodes] = $OperationIndex; GoalPriority[TotalNodes] = $GoalPriorityIndex; Min[TotalNodes] = $MinIndex; Max[TotalNodes] = $MaxIndex; GivenDistFlag[TotalNodes] = $GivenDistFlagIndex; IsGivenDist[TotalNodes] = $IsGivenDistIndex; IsGoalDist[TotalNodes] = $IsGoalDistIndex; ChildrenCount[TotalNodes] = $ChildrenCountIndex; for (i = 1; i <= ChildrenCount[TotalNodes]; i++) Children[TotalNodes,i] = $(i+ChildrenCountIndex); GivenDistStartIndex = ChildrenCountIndex + ChildrenCount[TotalNodes]; if (IsGivenDist[TotalNodes] == 1) { for (i = 1; i <= TotalBins; i++) GivenDist[TotalNodes,i] = $(GivenDistStartIndex+i); GoalDistStartIndex = GivenDistStartIndex + TotalBins; } else GoalDistStartIndex = GivenDistStartIndex; #keep the goal dist normalized. This is not needed for given dist since it is normalized as needed. if (IsGoalDist[TotalNodes] == 1) { for (i = 1; i <= TotalBins; i++) tempDistArray[i] = $(GoalDistStartIndex+i); normalizeDist(tempDistArray); for (i = 1; i <= TotalBins; i++) GoalDist[TotalNodes,i] = tempDistArray[i]; } } END { #find the root as the one that is not a child of any other node for (layer = 1; layer <= 3; layer++) { for (graph = 0; graph <= 5; graph++) { for (nodeCounter = 1; nodeCounter <= TotalNodes; nodeCounter++) { if (Layer[node] == layer && Graph[node] == graph) { for (tempCounter = 1; tempCounter <= ChildrenCount[nodeCounter]; tempCounter++) tempArray[Index[Children[nodeCounter,tempCounter]]]++; } } for (nodeCounter = 1; nodeCounter <= TotalNodes; nodeCounter++) { if (tempArray[nodeCounter] == 0 && Layer[nodeCounter] == layer && Graph[nodeCounter] == graph) Root[layer,graph] = nodeCounter; } delete tempArray; } } print "digraph G"; print "{"; for (layer = 1; layer <= 3; layer++) { for (graph = 0; graph <= 5; graph++) { if (layer == 1 && graph >= 0 || layer > 1 && graph > 0) { print "\tsubgraph cluster_" layer "_" graph; print "\t{"; print "\t\tlabel = \"Layer "layer " Graph "graph"\";"; for (node = 1; node <= TotalNodes; node++) { if (Layer[node] == layer && Graph[node] == graph) { if (Policy == 1) #make graph as it is with all lines { for (child = 1; child <= ChildrenCount[node]; child++) { tempChild = Index[Children[node,child]]; if (Layer[tempChild] == layer && Graph[tempChild] == graph) print "\t\t" Children[node,child] " -> " Name[node]";"; else print "\t\t" Children[node,child] " -> " Name[node]";"; } } if (Policy == 2) #make graph with 1 level { for (child = 1; child <= ChildrenCount[node]; child++) { tempChild = Index[Children[node,child]]; if (ChildrenCount[tempChild] == 0) { print "\t\t" Children[node,child] " -> " Name[Root[layer,graph]] ";"; } else { if (Layer[tempChild] != layer || Graph[tempChild] != graph) print "\t\t" Children[node,child] " -> " Name[Root[layer,graph]] ";"; } } } } } print "\t}"; } } } print "}"; }