예제 #1
0
 public DependencyStructure(CloudMakefile cloudMakefile, string debugFilename)
 {
     CloudManager.WriteLine(debugFilename, "CloudMakefile: " + cloudMakefile.ToString());
     _cloudMakefile = cloudMakefile;
     _entries       = new List <string> ();
     _policies      = cloudMakefile.GetPolicies();
     _inputs        = new List <List <int> > ();
     _outputs       = new List <List <int> > ();
     for (int i = 0; i < _policies.Count; i++)
     {
         _inputs.Add(new List <int> ());
         _outputs.Add(new List <int> ());
     }
     _reverseInputs                = new List <List <int> > ();
     _reverseOutputs               = new List <List <int> > ();
     _entryTokens                  = new HashSet <int> ();
     _policyTokens                 = new HashSet <int> ();
     _order                        = cloudMakefile.GetOrder();
     _configFiles                  = new HashSet <string> ();
     _modifiedConfigFiles          = new HashSet <string> ();
     _cloudMakeConfigFiles         = new HashSet <string> ();
     _modifiedCloudMakeConfigFiles = new HashSet <string> ();
     _debugFilename                = debugFilename;
 }
예제 #2
0
        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]));
            }
        }
예제 #3
0
        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));
                    }
                }
            }
        }
예제 #4
0
        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);
        }