Example #1
0
        protected virtual void CreateFeasibleSolution()
        {
            print("--------{0}开始生成可行解--------", System.DateTime.Now.ToLongTimeString());
            IMDPDecision d = (Data.DS as IALPDecisionSpace).CloseAllDecision();

            for (int t = CurrentTime; t < Data.TimeHorizon; t++)
            {
                int       iteration = t;
                IALPState tempstate = (Data.InitialState as IALPState);
                Task      ta        = factory.StartNew(() =>
                {
                    StateActive temp = new StateActive()
                    {
                        T = iteration, S = tempstate, D = d
                    };
                    if (curSAS.FirstOrDefault(i => i.Equals(temp)) == null)
                    {
                        tempSA.Push(temp);
                        lock (RMPModel)
                        {
                            temp.Var = AddCol(temp.T, temp.S, temp.D);
                        }
                    }
                }, cts.Token);
                tasks.Add(ta);
            }
            ;
            Task.WaitAll(tasks.ToArray());
            tasks.Clear();
            curSAS.UnionWith(tempSA);
            tempSA.Clear();
            print("--------{0}生成可行解完毕--------", System.DateTime.Now.ToLongTimeString());
        }
Example #2
0
 private void SolveSubProblem()
 {
     for (int t = CurrentTime; t < Data.TimeHorizon; t++)
     {
         IALPState    temp_s   = null;
         IMDPDecision deci_a   = null;
         bool         IsSubOpt = RCG(t, out temp_s, out deci_a);
         if (!IsSubOpt)
         {
             int          iteration = t;
             IALPState    tempstate = temp_s;
             IMDPDecision tempdeci  = deci_a;
             Task         ta        = factory.StartNew(() =>
             {
                 StateActive temp = new StateActive()
                 {
                     T = iteration, S = tempstate, D = tempdeci
                 };
                 if (curSAS.FirstOrDefault(i => i.Equals(temp)) == null)
                 {
                     tempSA.Push(temp);
                     lock (RMPModel)
                     {
                         temp.Var = AddCol(temp.T, temp.S, temp.D);
                     }
                 }
             }, cts.Token);
             tasks.Add(ta);
             //StateActive tempSA = new StateActive() { T = t, S = temp_s, D = deci_a };
             //if (curSAS.Add(tempSA))
             //{
             //    tempSA.Var = AddCol(t, temp_s, deci_a);
             //}
         }
         IsOptimal = IsSubOpt && IsOptimal;
         //System.Console.WriteLine("#{0}第{1}个子问题已经解决!", System.DateTime.Now.ToLongTimeString(), t);
     }
     Task.WaitAll(tasks.ToArray());
     tasks.Clear();
     curSAS.UnionWith(tempSA);
     tempSA.Clear();
 }