Exemplo n.º 1
0
        // Adds entry to dependency structure.
        public void AddEntry(Tuple <string, int> entry)
        {
            string        entryname      = entry.Item1;
            int           id             = entry.Item2;
            HashSet <int> reverseInputs  = _cloudMakefile.GetReverseInputs() [id];
            HashSet <int> reverseOutputs = _cloudMakefile.GetReverseOutputs() [id];
            int           entryIndex     = _entries.Count;

            if (_entries.Contains(entryname))
            {
                return;
            }
            _entries.Add(entryname);
            _reverseInputs.Add(new List <int> (reverseInputs));
            _reverseOutputs.Add(new List <int> (reverseOutputs));
            foreach (int policyIndex in reverseInputs)
            {
                _inputs [policyIndex].Add(entryIndex);
            }
            foreach (int policyIndex in reverseOutputs)
            {
                _outputs [policyIndex].Add(entryIndex);
            }
        }
Exemplo n.º 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]));
            }
        }
Exemplo n.º 3
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);
        }