Ejemplo n.º 1
0
        private void Validate_Solutions(double Removal_Ratio)
        {
            Solution_List_Threading = new ConcurrentStack <Solution>()
            {
            };
            List <Solution> Holder = new List <Solution>()
            {
            };

            count = Convert.ToInt32(Solution_List.Count * (1 - Removal_Ratio));
            int Count_Original = count;

            for (int n = 0; n < Count_Original; n++)
            {
                using (e = new CountdownEvent(NumberOfThreads))
                {
                    for (int i = 0; i < NumberOfThreads; i++)
                    {
                        ThreadPool.QueueUserWorkItem(new WaitCallback(Validate_Solutions), i);
                    }
                    e.Wait();
                }
                int max = -1;
                int mx  = -1;
                for (int i = 0; i < Solution_List_Threading.Count; i++)
                {
                    if (max < Solution_List_Threading.ElementAt(i).Unknowns_Sum)
                    {
                        max = Solution_List_Threading.ElementAt(i).Unknowns_Sum;
                        mx  = i;
                    }
                }
                Holder.Add(new Solution(Solution_List_Threading.ElementAt(mx)));
                Solution_List_Threading.Clear();
                Solution_List.RemoveAt(mx);
                count = Convert.ToInt32(Solution_List.Count * (1 - Removal_Ratio));
            }
            Solution_List = new List <Solution>(Holder); Holder.Clear();
        }
Ejemplo n.º 2
0
 private void Validate_Solutions(double Removal_Ratio)
 {
     Solution_List_Threading = new ConcurrentStack<Solution>() { };
     List<Solution> Holder = new List<Solution>() { };
     count = Convert.ToInt32(Solution_List.Count * (1 - Removal_Ratio));
     int Count_Original = count;
     for (int n = 0; n < Count_Original; n++)
     {
         using (e = new CountdownEvent(NumberOfThreads))
         {
             for (int i = 0; i < NumberOfThreads; i++)
             {
                 ThreadPool.QueueUserWorkItem(new WaitCallback(Validate_Solutions), i);
             }
             e.Wait();
         }
         int max = -1;
         int mx = -1;
         for (int i = 0; i < Solution_List_Threading.Count; i++)
         {
             if (max < Solution_List_Threading.ElementAt(i).Unknowns_Sum)
             {
                 max = Solution_List_Threading.ElementAt(i).Unknowns_Sum;
                 mx = i;
             }
         }
         Holder.Add(new Solution(Solution_List_Threading.ElementAt(mx)));
         Solution_List_Threading.Clear();
         Solution_List.RemoveAt(mx);
         count = Convert.ToInt32(Solution_List.Count * (1 - Removal_Ratio));
     }
     Solution_List = new List<Solution>(Holder); Holder.Clear();
 }