コード例 #1
0
            private void AddNext(PowerplantInfo info)
            {
                int pNeeded = _powerRequest.load - totalP;
                int p;

                if (pNeeded >= info.pmax)
                {
                    p = info.pmax;
                }
                else if (info.pmin > pNeeded)
                {
                    p = info.pmin;
                    ReducePreviousP(p - pNeeded);
                }
                else
                {
                    p = pNeeded;
                }

                unused.Remove(info);
                used.Add(info);
                ps.Add(p);

                CalculateTotalPAndCost();

                done = totalP == _powerRequest.load;
            }
コード例 #2
0
 private void ReducePreviousP(int toReduce)
 {
     for (int i = used.Count - 1; i >= 0; --i)
     {
         PowerplantInfo info = used[i];
         ps[i] -= toReduce;
         if (ps[i] < info.pmin)
         {
             int diff = info.pmin - ps[i];
             toReduce = diff;
             ps[i]    = info.pmin;
         }
         else
         {
             break;
         }
     }
 }