コード例 #1
0
        private void Find_Max_Index(Simplex_Table _Table, List <int> _Residual)
        {
            int           Row_Count = _Table.Rows.Count - 1;
            List <double> Row       = _Table.Rows[Row_Count].Row_Values;
            int           count     = Row.Count;
            double        max       = -1;
            int           mx        = -1;

            for (int i = 0; i < count; i++)
            {
                if (max < Row[i])
                {
                    max = Row[i];
                    mx  = i;
                }
            }
            if (mx != -1)
            {
                for (int i = 0; i < count; i++)
                {
                    if (max == Row[i])
                    {
                        Value_Possibility VP = new Value_Possibility();
                        VP.Max_Index = i;
                        VP.Min_Selected_Indicators_Result = -1;
                        VP.Min_Selected_Indicator         = -1;
                        Data.Values.Add(VP);
                        Table_Possibility TP = new Table_Possibility();
                        TP.Table = Make_Simplex_Tabel_Copy(_Table);
                        TP.Residual.AddRange(_Residual);
                        Data.Tables.Add(TP);
                    }
                }
            }
        }
コード例 #2
0
        private void Simplex_Cycle(Simplex_Table _Table)
        {
            Table_Possibility start = new Table_Possibility();

            start.Table = Make_Simplex_Tabel_Copy(_Table);
            start.Residual.AddRange(Residual_Back);
            Data.Tables.Add(start);
            Data.Values.Add(new Value_Possibility());
            while (Data.Tables.Count != 0)
            {
                int count = Data.Tables.Count;
                for (int i = 0; i < count; i++)
                {
                    Find_Max_Index(Data.Tables[i].Table, Data.Tables[i].Residual);
                    Data.Tables.RemoveAt(i);
                    Data.Values.RemoveAt(i);
                    i--; count--;
                }
                count = Data.Tables.Count;
                for (int i = 0; i < count; i++)
                {
                    Find_Min_Selected_Indicators_Result(Data.Tables[i].Table, Data.Tables[i].Residual, Data.Values[i].Max_Index);
                    Data.Tables.RemoveAt(i);
                    Data.Values.RemoveAt(i);
                    i--; count--;
                }
                count = Data.Tables.Count;
                List_Of_Item_Indexs_To_Remove = new ConcurrentStack <int> {
                };
                Concurent_Table = new ConcurrentDictionary <int, Table_Possibility>(Thread_Count, count);
                Concurent_Value = new ConcurrentDictionary <int, Value_Possibility>(Thread_Count, count);
                for (int i = 0; i < count; i++)
                {
                    Concurent_Table[i] = Data.Tables[i];
                    Concurent_Value[i] = Data.Values[i];
                }
                using (e = new CountdownEvent(count))
                {
                    for (int i = 0; i < count; i++)
                    {
                        ThreadPool.QueueUserWorkItem(new WaitCallback(Simplex_Cycle_Step), i);
                    }
                    e.Wait();
                }
                for (int i = 0; i < count; i++)
                {
                    Data.Tables[i] = Concurent_Table[i];
                    // Data.Values[i] = Concurent_Value[i]; // Values dont change in calculation if they do, uncoment
                }
                int index;
                while (List_Of_Item_Indexs_To_Remove.TryPop(out index))
                {
                    Data.Tables[index] = null;
                    Data.Values[index] = null;
                }
                Data.Tables.RemoveAll(item => item == null);
                Data.Values.RemoveAll(item => item == null);
            }
        }
コード例 #3
0
 private void Simplex_Cycle(Simplex_Table _Table)
 {
     Table_Possibility start = new Table_Possibility();
     start.Table = Make_Simplex_Tabel_Copy(_Table);
     start.Residual.AddRange(Residual_Back);
     Data.Tables.Add(start);
     Data.Values.Add(new Value_Possibility());
     while (Data.Tables.Count != 0)
     {
         int count = Data.Tables.Count;
         for (int i = 0; i < count; i++)
         {
             Find_Max_Index(Data.Tables[i].Table, Data.Tables[i].Residual);
             Data.Tables.RemoveAt(i);
             Data.Values.RemoveAt(i);
             i--; count--;
         }
         count = Data.Tables.Count;
         for (int i = 0; i < count; i++)
         {
             Find_Min_Selected_Indicators_Result(Data.Tables[i].Table, Data.Tables[i].Residual, Data.Values[i].Max_Index);
             Data.Tables.RemoveAt(i);
             Data.Values.RemoveAt(i);
             i--; count--;
         }
         count = Data.Tables.Count;
         List_Of_Item_Indexs_To_Remove = new ConcurrentStack<int> { };
         Concurent_Table = new ConcurrentDictionary<int, Table_Possibility>(Thread_Count, count);
         Concurent_Value = new ConcurrentDictionary<int, Value_Possibility>(Thread_Count, count);
         for (int i = 0; i < count; i++)
         {
             Concurent_Table[i] = Data.Tables[i];
             Concurent_Value[i] = Data.Values[i];
         }
         using (e = new CountdownEvent(count))
         {
             for (int i = 0; i < count; i++)
             {
                 ThreadPool.QueueUserWorkItem(new WaitCallback(Simplex_Cycle_Step), i);
             }
             e.Wait();
         }
         for (int i = 0; i < count; i++)
         {
             Data.Tables[i] = Concurent_Table[i];
             // Data.Values[i] = Concurent_Value[i]; // Values dont change in calculation if they do, uncoment
         }
         int index;
         while (List_Of_Item_Indexs_To_Remove.TryPop(out index))
         {
             Data.Tables[index] = null;
             Data.Values[index] = null;
         }
         Data.Tables.RemoveAll(item => item == null);
         Data.Values.RemoveAll(item => item == null);
     }
 }
コード例 #4
0
        private void Find_Min_Selected_Indicators_Result(Simplex_Table _Table, List <int> _Residual, int Max_Index)
        {
            double     min      = -1;
            int        mn       = -1;
            List <Row> Row_List = _Table.Rows;
            int        count    = Row_List.Count - 1;

            for (int i = 0; i < count; i++)
            {
                double value = _Table.Selected_Indicators_Result[i] / Row_List[i].Row_Values[Max_Index];
                if (value >= 0)
                {
                    min = value;
                    mn  = i;
                    i   = count;
                }
            }
            if (mn != -1)
            {
                for (int i = 0; i < count; i++)
                {
                    if (Row_List[i].Row_Values[Max_Index] >= 0)
                    {
                        double tikrinti = _Table.Selected_Indicators_Result[i] / Row_List[i].Row_Values[Max_Index];
                        if (tikrinti < min && tikrinti > 0)
                        {
                            min = tikrinti;
                            mn  = i;
                        }
                    }
                }
                for (int i = 0; i < count; i++)
                {
                    if (Row_List[i].Row_Values[Max_Index] > 0)
                    {
                        double tikrinti = _Table.Selected_Indicators_Result[i] / Row_List[i].Row_Values[Max_Index];
                        if (tikrinti == min)
                        {
                            Value_Possibility newValue = new Value_Possibility();
                            newValue.Max_Index = Max_Index;
                            newValue.Min_Selected_Indicator         = i;
                            newValue.Min_Selected_Indicators_Result = min;
                            Data.Values.Add(newValue);
                            Table_Possibility TP = new Table_Possibility();
                            TP.Table = Make_Simplex_Tabel_Copy(_Table);
                            TP.Residual.AddRange(_Residual);
                            Data.Tables.Add(TP);
                        }
                    }
                }
            }
            else
            {
            }
        }
コード例 #5
0
        private void Find_Min_Selected_Indicators_Result(Simplex_Table _Table, List<int> _Residual, int Max_Index)
        {
            double min = -1;
            int mn = -1;
            List<Row> Row_List = _Table.Rows;
            int count = Row_List.Count - 1;
            for (int i = 0; i < count; i++)
            {
                double value = _Table.Selected_Indicators_Result[i] / Row_List[i].Row_Values[Max_Index];
                if (value >= 0)
                {
                    min = value;
                    mn = i;
                    i = count;
                }
            }
            if (mn != -1)
            {
                for (int i = 0; i < count; i++)
                {
                    if (Row_List[i].Row_Values[Max_Index] >= 0)
                    {
                        double tikrinti = _Table.Selected_Indicators_Result[i] / Row_List[i].Row_Values[Max_Index];
                        if (tikrinti < min && tikrinti > 0)
                        {
                            min = tikrinti;
                            mn = i;
                        }
                    }
                }
                for (int i = 0; i < count; i++)
                {
                    if (Row_List[i].Row_Values[Max_Index] > 0)
                    {
                        double tikrinti = _Table.Selected_Indicators_Result[i] / Row_List[i].Row_Values[Max_Index];
                        if (tikrinti == min)
                        {
                            Value_Possibility newValue = new Value_Possibility();
                            newValue.Max_Index = Max_Index;
                            newValue.Min_Selected_Indicator = i;
                            newValue.Min_Selected_Indicators_Result = min;
                            Data.Values.Add(newValue);
                            Table_Possibility TP = new Table_Possibility();
                            TP.Table = Make_Simplex_Tabel_Copy(_Table);
                            TP.Residual.AddRange(_Residual);
                            Data.Tables.Add(TP);
                        }
                    }
                }
            }
            else
            {

            }
        }
コード例 #6
0
 private void Find_Max_Index(Simplex_Table _Table, List<int> _Residual)
 {
     int Row_Count = _Table.Rows.Count - 1;
     List<double> Row = _Table.Rows[Row_Count].Row_Values;
     int count = Row.Count;
     double max = -1;
     int mx = -1;
     for (int i = 0; i < count; i++)
     {
         if (max < Row[i])
         {
             max = Row[i];
             mx = i;
         }
     }
     if (mx != -1)
     {
         for (int i = 0; i < count; i++)
         {
             if (max == Row[i])
             {
                 Value_Possibility VP = new Value_Possibility();
                 VP.Max_Index = i;
                 VP.Min_Selected_Indicators_Result = -1;
                 VP.Min_Selected_Indicator = -1;
                 Data.Values.Add(VP);
                 Table_Possibility TP = new Table_Possibility();
                 TP.Table = Make_Simplex_Tabel_Copy(_Table);
                 TP.Residual.AddRange(_Residual);
                 Data.Tables.Add(TP);
             }
         }
     }
 }