public CloudMakefile(CloudMakefile cloudMakefile) { List <HashSet <int> > inputs = cloudMakefile.GetInputs(); List <HashSet <int> > outputs = cloudMakefile.GetOutputs(); List <HashSet <int> > reverseInputs = cloudMakefile.GetReverseInputs(); List <HashSet <int> > reverseOutputs = cloudMakefile.GetReverseOutputs(); List <HashSet <int> > order = cloudMakefile.GetOrder(); _inputs = new List <HashSet <int> > (); for (int i = 0; i < inputs.Count; i++) { _inputs.Add(new HashSet <int> (inputs [i])); } _outputs = new List <HashSet <int> > (); for (int i = 0; i < outputs.Count; i++) { _outputs.Add(new HashSet <int> (outputs [i])); } _reverseInputs = new List <HashSet <int> > (); for (int i = 0; i < reverseInputs.Count; i++) { _reverseInputs.Add(new HashSet <int> (reverseInputs [i])); } _reverseOutputs = new List <HashSet <int> > (); for (int i = 0; i < reverseOutputs.Count; i++) { _reverseOutputs.Add(new HashSet <int> (reverseOutputs [i])); } _dfas = new List <DFA> (cloudMakefile.GetDFAs()); _policies = new List <string> (cloudMakefile.GetPolicies()); _order = new List <HashSet <int> > (); for (int i = 0; i < order.Count; i++) { _order.Add(new HashSet <int> (order [i])); } }
// Run CloudMake public void Run() { #if DEBUG CloudManager.WriteLine(_debugFilename, "Started Running CloudMake."); #endif List <HashSet <int> > outputs = _cloudMakefile.GetOutputs(); HashSet <int> activeEntryTokens = new HashSet <int> (_entryTokens); int tier = 0; while ((activeEntryTokens.Count > 0) || (_policyTokens.Count > 0)) { HashSet <int> entryTokensToRemove = new HashSet <int> (activeEntryTokens); #if DEBUG foreach (int token in activeEntryTokens) { CloudManager.WriteLine(_debugFilename, "Active Entry: " + _entries [token]); foreach (int policyToken in _reverseInputs[token]) { _policyTokens.Add(policyToken); } } #endif // If there are no more transitions to run. if (tier >= _order.Count) { break; } // Find active policies in this tier of policies. HashSet <int> activeTransitions = new HashSet <int> (_order [tier]); #if DEBUG CloudManager.WriteLine(_debugFilename, "Active Transitions:"); foreach (int transition in activeTransitions) { CloudManager.WriteLine(_debugFilename, "Transition " + transition.ToString()); } CloudManager.WriteLine(_debugFilename, ""); #endif activeTransitions.IntersectWith(_policyTokens); // Execute the active policies. foreach (int token in activeTransitions) { CloudManager.WriteLine(_debugFilename, "Active Policy: " + _policies [token]); Dictionary <string, string> outputEntries = new Dictionary <string, string> (); string policy = _policies [token]; if (policy.Contains("$(inputs)")) { String inputs = ""; HashSet <int> entriesToConsider = new HashSet <int> (_inputs [token]); entriesToConsider.IntersectWith(_entryTokens); foreach (int entry in entriesToConsider) { inputs += " " + _entries [entry]; } policy = policy.Replace(" $(inputs)", inputs); } foreach (int entryToken in _outputs[token]) { string entryname = _entries [entryToken]; outputEntries.Add(entryname, HashEntry(entryname)); } string[] program = policy.Split(new char[] { ' ', '\t' }, 2); CloudManager.WriteLine(_debugFilename, "Directory: " + Directory.GetCurrentDirectory()); CloudManager.WriteLine(_debugFilename, "Execute: " + program [0] + " " + program [1]); using (Process proc = new System.Diagnostics.Process()) { proc.EnableRaisingEvents = false; proc.StartInfo.FileName = program [0]; proc.StartInfo.Arguments = program [1]; proc.Start(); proc.WaitForExit(); } ; List <Tuple <string, int> > outputEntriesToConsider = _cloudMakefile.FindMatchingEntries("", new HashSet <int> (outputs [token])); foreach (Tuple <string, int> entry in outputEntriesToConsider) { string entryname = entry.Item1; if ((outputEntries.ContainsKey(entryname)) && (HashEntry(entryname) != outputEntries [entryname])) { int entryIndex = _entries.IndexOf(entryname); _entryTokens.Add(entryIndex); activeEntryTokens.Add(entryIndex); } else if (!outputEntries.ContainsKey(entryname)) { _entryTokens.Add(_entries.Count); activeEntryTokens.Add(_entries.Count); AddEntry(entry); } } _policyTokens.Remove(token); } // Remove the appropriate entries. foreach (int token in entryTokensToRemove) { activeEntryTokens.Remove(token); } tier++; } // Update modifies config and CloudMake config files. foreach (int token in _entryTokens) { string entryname = _entries [token]; string filename; filename = MatchEntryToConfigFile(entryname); if (filename != null) { _modifiedConfigFiles.Add(filename); } filename = MatchEntryToCloudMakeConfigFile(entryname); if (filename != null) { _modifiedCloudMakeConfigFiles.Add(filename); } } }
public CloudMakefile(CloudMakefile cloudMakefile, List <int> selectedPolicies) : this() { List <HashSet <int> > inputs = cloudMakefile.GetInputs(); List <HashSet <int> > outputs = cloudMakefile.GetOutputs(); List <DFA> dfas = cloudMakefile.GetDFAs(); List <string> policies = cloudMakefile.GetPolicies(); List <HashSet <int> > order = cloudMakefile.GetOrder(); Dictionary <int, int> dfaTransform = new Dictionary <int, int> (); int dfaCount = 0; int newDfaIndex; int count = -1; for (int newPolicyIndex = 0; newPolicyIndex < selectedPolicies.Count; newPolicyIndex++) { int oldPolicyIndex = selectedPolicies [newPolicyIndex]; _inputs.Add(new HashSet <int> ()); _outputs.Add(new HashSet <int> ()); foreach (int oldDfaIndex in inputs[oldPolicyIndex]) { if (!dfaTransform.ContainsKey(oldDfaIndex)) { dfaTransform [oldDfaIndex] = dfaCount; _dfas.Add(dfas [oldDfaIndex]); dfaCount++; _reverseInputs.Add(new HashSet <int> ()); _reverseOutputs.Add(new HashSet <int> ()); } newDfaIndex = dfaTransform [oldDfaIndex]; _inputs [newPolicyIndex].Add(newDfaIndex); _reverseInputs [newDfaIndex].Add(newPolicyIndex); } foreach (int oldDfaIndex in outputs[oldPolicyIndex]) { if (!dfaTransform.ContainsKey(oldDfaIndex)) { dfaTransform [oldDfaIndex] = dfaCount; _dfas.Add(dfas [oldDfaIndex]); dfaCount++; _reverseInputs.Add(new HashSet <int> ()); _reverseOutputs.Add(new HashSet <int> ()); } newDfaIndex = dfaTransform [oldDfaIndex]; _outputs [newPolicyIndex].Add(newDfaIndex); _reverseOutputs [newDfaIndex].Add(newPolicyIndex); } _policies.Add(policies [oldPolicyIndex]); } for (int i = 0; i < order.Count; i++) { bool created = false; foreach (int oldPolicyIndex in order[i]) { if (selectedPolicies.Contains(oldPolicyIndex)) { if (!created) { _order.Add(new HashSet <int> ()); created = true; count += 1; } _order [count].Add(selectedPolicies.IndexOf(oldPolicyIndex)); } } } }
static public List <CloudMakefile> SplitCloudMakefile(CloudMakefile initialCloudMakefile) { List <CloudMakefile> res = new List <CloudMakefile> (); List <List <int> > selectedPolicies = new List <List <int> > (); List <int> unexploredPolicies = new List <int> (); List <int> unexploredDfas = new List <int> (); List <int> unsearchedPolicies = new List <int> (); List <int> unsearchedDfas = new List <int> (); List <HashSet <int> > inputs = initialCloudMakefile.GetInputs(); List <HashSet <int> > outputs = initialCloudMakefile.GetOutputs(); List <HashSet <int> > reverseInputs = initialCloudMakefile.GetReverseInputs(); List <HashSet <int> > reverseOutputs = initialCloudMakefile.GetReverseOutputs(); int count = 0; bool explorePolicy; // Fill the unsearched fields. for (int i = 0; i < initialCloudMakefile.GetPolicies().Count; i++) { unsearchedPolicies.Add(i); } for (int i = 0; i < initialCloudMakefile.GetDFAs().Count; i++) { unsearchedDfas.Add(i); } // Divide CloudMakefile to independent pieces. while (unsearchedPolicies.Count != 0) { // Console.Out.WriteLine ("Unsearched Policies"); // for (int i = 0; i < unsearchedPolicies.Count; i++) // Console.Out.WriteLine (unsearchedPolicies [i].ToString ()); // Console.Out.WriteLine ("Unsearched DFAs"); // for (int i = 0; i < unsearchedDfas.Count; i++) // Console.Out.WriteLine (unsearchedDfas [i].ToString ()); unexploredPolicies.Add(unsearchedPolicies [0]); unsearchedPolicies.RemoveAt(0); explorePolicy = true; selectedPolicies.Add(new List <int> ()); while ((unexploredPolicies.Count != 0) || (unexploredDfas.Count != 0)) { if (explorePolicy) { while (unexploredPolicies.Count != 0) { int policyIndex = unexploredPolicies [0]; /* * Console.Out.WriteLine ("Selected Policy: " + policyIndex); * Console.Out.WriteLine ("Inputs:" + String.Join (" ", inputs [policyIndex])); * Console.Out.WriteLine ("Outputs:" + String.Join (" ", outputs [policyIndex])); */ foreach (int dfaIndex in inputs[policyIndex]) { if (unsearchedDfas.Contains(dfaIndex)) { unexploredDfas.Add(dfaIndex); unsearchedDfas.Remove(dfaIndex); } } foreach (int dfaIndex in outputs[policyIndex]) { if (unsearchedDfas.Contains(dfaIndex)) { unexploredDfas.Add(dfaIndex); unsearchedDfas.Remove(dfaIndex); } } unexploredPolicies.RemoveAt(0); selectedPolicies [count].Add(policyIndex); } } else { while (unexploredDfas.Count != 0) { int dfaIndex = unexploredDfas [0]; /* * Console.Out.WriteLine ("Selected Index: " + dfaIndex); * Console.Out.WriteLine ("Reverse Inputs:" + String.Join (" ", reverseInputs [dfaIndex])); * Console.Out.WriteLine ("Reverse Outputs:" + String.Join (" ", reverseOutputs [dfaIndex])); */ foreach (int policyIndex in reverseInputs[dfaIndex]) { if (unsearchedPolicies.Contains(policyIndex)) { unexploredPolicies.Add(policyIndex); unsearchedPolicies.Remove(policyIndex); } } foreach (int policyIndex in reverseOutputs[dfaIndex]) { if (unsearchedPolicies.Contains(policyIndex)) { unexploredPolicies.Add(policyIndex); unsearchedPolicies.Remove(policyIndex); } } unexploredDfas.RemoveAt(0); } } explorePolicy = !explorePolicy; } count++; } // Print Selected Policies. /*for (int i = 0; i < selectedPolicies.Count; i++) { * Console.Out.Write ("[ "); * selectedPolicies [i].Sort (); * for (int j = 0; j < selectedPolicies[i].Count; j++) * Console.Out.Write (selectedPolicies [i] [j].ToString () + " "); * Console.Out.WriteLine ("]"); * }*/ // Create the CloudMakefiles. for (int i = 0; i < selectedPolicies.Count; i++) { res.Add(new CloudMakefile(initialCloudMakefile, selectedPolicies [i])); } return(res); }