static void Main(string[] args)
        {
            string data_path = "Server = PC-201606172102\\SQLExpress;DataBase = 乘务计划;Integrated Security = true";
            //string data_path = "Server = PC-201606172102\\SQLExpress;DataBase = 乘务计划CSP1440;Integrated Security = true";
            NetWork Net = new NetWork();

            Net.CreateNetwork(data_path);
            Net.IsAllTripsCovered();
            //检查无误
            InitialSolution IS = new InitialSolution(Net);

            Stopwatch sw = new Stopwatch();

            sw.Start();

            IS.GetFeasibleSolutionByPenalty();
            //IS.GetFeasibleSolutionByMethod1();//顺逆向标号在多基地时有问题:如对点i,顺向时最短路对应基地为B1,逆向时最短路对应基地为B2.错误
            sw.Stop();

            Report Report_IS = new Report(IS.PathSet);

            Console.WriteLine(Report_IS.TransferSolution());

            Console.WriteLine("平均纯乘务时间:{0} 平均换乘时间{1} 平均task数{2}", Report_IS.summary_mean.mean_PureCrew
                              , Report_IS.summary_mean.mean_Trans, Report_IS.summary_mean.mean_Tasks);
            Report_IS.WriteCrewPaths(@"D:\代码项目\C#\CG-version2.1_cost_1440-重构\CG_CSP_1440\ISS_LineList.txt");

            Console.WriteLine(sw.Elapsed.TotalSeconds);
            //checked:OK
            /*********<<下面开始测试CG>>***************************************************************************/
            CSP csp = new CSP(Net);

            csp.Branch_and_Price(IS);
            int y = 0;
        }
Exemplo n.º 2
0
        public void TestInstance(string caseName, string mealWindow, DataReader Data, ref Summary singleCaseSummary)
        {
            Stopwatch sw_all       = new Stopwatch();
            Stopwatch sw_creat_net = new Stopwatch();
            Stopwatch sw_IS        = new Stopwatch();
            Stopwatch sw_BandB     = new Stopwatch();

            sw_all.Start();
            sw_creat_net.Start();
            sw_IS.Start();

            NetWork Net = new NetWork();

            Net.CreateNetwork(Data);
            Net.IsAllTripsCovered();
            sw_creat_net.Stop();

            Console.WriteLine("connect arc num: {0}", Net.ArcSet.Count);
            Console.WriteLine("connect node num: {0}", Net.NodeSet.Count);

            //get initail solution
            InitialSolution IS = new InitialSolution(Net);

            //IS.GetFeasibleSolutionByPenalty();
            //IS.GetFeasibleSolutionByMethod1();
            IS.GetVirtualPathSetAsInitSoln();
            sw_IS.Stop();
            //Report Report_IS = new Report(IS.PathSet);
            //Console.WriteLine(Report_IS.TransferSolution());
            //Console.WriteLine("平均纯乘务时间:{0} 平均换乘时间{1} 平均task数{2}", Report_IS.summary_mean.mean_PureCrew,
            //    Report_IS.summary_mean.mean_Trans, Report_IS.summary_mean.mean_Tasks);

            //string initial_solution_dir = System.Environment.CurrentDirectory + "\\结果\\" + caseName + "\\初始解.txt";
            //Report_IS.WriteCrewPaths(initial_solution_dir);
            //Console.WriteLine(sw_IS.Elapsed.TotalSeconds);

            /*********<<下面开始测试CG>>***************************************************************************/
            sw_BandB.Start();
            CSP csp = new CSP(Net);

            csp.testCase = caseName + "\\" + mealWindow;
            csp.Branch_and_Price(IS);
            sw_BandB.Stop();
            sw_all.Stop();

            Logger.GetUncoveredTasks(csp.GetOptPathSet(), Net.TripList, caseName, mealWindow);
            Logger.GetSchedule(csp.GetOptPathSet(), caseName, mealWindow);


            singleCaseSummary = new Summary("CG", caseName + "_" + mealWindow, sw_all.Elapsed.TotalSeconds, csp.LB_LR, csp.UB_LR, csp.num_all_crew);

            string       path     = System.Environment.CurrentDirectory + "\\结果\\" + caseName + "\\" + mealWindow + "\\求解信息.txt";
            FileStream   fs       = new FileStream(path, FileMode.Create);
            StreamWriter strwrite = new StreamWriter(fs);

            strwrite.WriteLine("建网时间:{0}", sw_creat_net.Elapsed.TotalSeconds);
            strwrite.WriteLine("接续弧的数量:{0}", Net.ArcSet.Count());
            strwrite.WriteLine("网络中节点数量:{0}", Net.NodeSet.Count());
            //strwrite.WriteLine("初始解产生时间:{0}", sw_IS.Elapsed.TotalSeconds);
            strwrite.WriteLine("LP_OPT_SOLN时间:{0}", csp.time_root_node);
            strwrite.WriteLine("分支定界用时:{0}", sw_BandB.Elapsed.TotalSeconds);
            strwrite.WriteLine("总乘务组数量:{0}", csp.num_all_crew);
            strwrite.WriteLine("模型总共求解时间:{0}", sw_all.Elapsed.TotalSeconds);
            strwrite.WriteLine("总目标函数:{0}", /*csp.OBJVALUE);*/ csp.All_obj);
            strwrite.WriteLine("最短路总计算次数:{0}", csp.total_nums_rcspp);
            strwrite.WriteLine("初始解列数:{0}", IS.PathSet.Count);
            strwrite.WriteLine("列池总数:{0}", csp.ColumnPool.Count);
            strwrite.Close();
            fs.Close();

            // get objective value in the process of iterations
            StreamWriter obj_iter = new StreamWriter(System.Environment.CurrentDirectory + "\\结果\\" + caseName + "\\" + mealWindow + "\\OBJ迭代.csv");

            obj_iter.WriteLine("ObjValue");
            foreach (var obj in csp.obj_iter)
            {
                obj_iter.WriteLine(obj);
            }
            obj_iter.Close();

            //string num_label_iter = System.Environment.CurrentDirectory + "\\结果\\" + caseName + "\\标号数量与求解时间迭代(2).csv";
            //strwrite = new StreamWriter(num_label_iter, false, Encoding.Default);
            //strwrite.WriteLine("iter,label num,time*10000");
            //for (int i = 0; i < csp.num_label_iter.Count; i++)
            //{
            //    strwrite.WriteLine(i + 1 + "," + csp.num_label_iter[i] + "," + csp.time_rcspp[i] * 10000);
            //}
            //strwrite.Close();
        }
        static void Main(string[] args)
        {
            //string data_path = "Server = PC-201606172102\\SQLExpress;DataBase = 乘务计划;Integrated Security = true";
            //string data_path = "Server = PC-201606172102\\SQLExpress;DataBase = 乘务计划CSP1440;Integrated Security = true";
            // string data_dir = @"\data\京津";
            Stopwatch sw_all       = new Stopwatch();
            Stopwatch sw_creat_net = new Stopwatch();
            Stopwatch sw_IS        = new Stopwatch();
            Stopwatch sw_BandB     = new Stopwatch();

            sw_all.Start();
            string test_case = "沪杭";                     //"BigScale";////

            CrewRules.All_Num_Crew = 240;                //京津-60;沪杭-240;bigscal-300;bigscal2-400
            string     data_dir = @"\data\" + test_case; //京津";
            DataReader Data     = new DataReader();

            List <string> csvfiles;

            Data.Connect_csvs(out csvfiles, data_dir);
            Data.LoadRules_csv(); //该函数并未考虑时间窗
            //考虑时间窗的话,为了测试方便,直接在代码里设置时间窗的参数,而不是放在文件中

            Data.CrewRules.DisplayRules();
            Data.LoadData_csv(Data.CrewRules.MaxDays);

            sw_creat_net.Start();
            NetWork Net = new NetWork();

            Net.CreateNetwork(Data);
            Net.IsAllTripsCovered();
            sw_creat_net.Stop();

            sw_IS.Start();
            //检查无误
            InitialSolution IS = new InitialSolution(Net);

            //IS.GetFeasibleSolutionByPenalty();
            IS.GetFeasibleSolutionByMethod1();//顺逆向标号在多基地时有问题:如对点i,顺向时最短路对应基地为B1,逆向时最短路对应基地为B2.错误
            sw_IS.Stop();

            Report Report_IS = new Report(IS.PathSet);

            Console.WriteLine(Report_IS.TransferSolution());
            Console.WriteLine("平均纯乘务时间:{0} 平均换乘时间{1} 平均task数{2}", Report_IS.summary_mean.mean_PureCrew,
                              Report_IS.summary_mean.mean_Trans, Report_IS.summary_mean.mean_Tasks);
            //string initial_solution_dir = System.Environment.CurrentDirectory + "\\结果\\京津\\初始解.txt";
            string initial_solution_dir = System.Environment.CurrentDirectory + "\\结果\\" + test_case + "\\初始解.txt";

            //Report_IS.WriteCrewPaths(@"D:\代码项目\C#\CG-version2.1_cost_1440-重构\CG_CSP_1440\jj158ISS_LineList.txt");
            Report_IS.WriteCrewPaths(initial_solution_dir);
            Console.WriteLine(sw_IS.Elapsed.TotalSeconds);
            //checked:OK
            /*********<<下面开始测试CG>>***************************************************************************/
            sw_BandB.Start();
            CSP csp = new CSP(Net);

            csp.testCase = test_case;
            csp.Branch_and_Price(IS);
            sw_BandB.Stop();
            sw_all.Stop();

            StreamWriter obj_iter = new StreamWriter(System.Environment.CurrentDirectory + "\\结果\\" + test_case + "\\OBJ迭代.csv");

            obj_iter.WriteLine("ObjValue");
            foreach (var obj in csp.obj_iter)
            {
                obj_iter.WriteLine(obj);
            }
            obj_iter.Close();


            string       path     = System.Environment.CurrentDirectory + "\\结果\\" + test_case + "\\求解信息.txt";
            FileStream   fs       = new FileStream(path, FileMode.Create);
            StreamWriter strwrite = new StreamWriter(fs);

            strwrite.WriteLine("建网时间:{0}", sw_creat_net.Elapsed.TotalSeconds);
            strwrite.WriteLine("接续弧的数量:{0}", Net.ArcSet.Count());
            strwrite.WriteLine("网络中节点数量:{0}", Net.NodeSet.Count());
            strwrite.WriteLine("初始解产生时间:{0}", sw_IS.Elapsed.TotalSeconds);
            strwrite.WriteLine("分支定界用时:{0}", sw_BandB.Elapsed.TotalSeconds);
            strwrite.WriteLine("总乘务组数量:{0}", csp.num_all_crew);
            strwrite.WriteLine("模型总共求解时间:{0}", sw_all.Elapsed.TotalSeconds);
            strwrite.WriteLine("总目标函数:{0}", /*csp.OBJVALUE);*/ csp.All_obj);
            strwrite.WriteLine("最短路总计算次数:{0}", csp.total_nums_rcspp);
            strwrite.WriteLine("初始解列数:{0}", IS.PathSet.Count);
            strwrite.WriteLine("列池总数:{0}", csp.ColumnPool.Count);
            strwrite.Close();
            fs.Close();

            string dualprice_iter = System.Environment.CurrentDirectory + "\\结果\\" + test_case + "\\对偶乘子迭代.csv";

            strwrite = new StreamWriter(dualprice_iter, false, Encoding.Default);
            //strwrite.WriteLine("iter,dual_price");
            csp.task_dualPrice.OrderBy(k => k.Key).ToDictionary(k => k.Key, v => v.Value);
            int i = 0;

            for (i = 1; i < csp.task_dualPrice.Keys.Count; i++)
            {
                strwrite.Write("task" + i + ",");
            }
            strwrite.WriteLine("task" + i);
            for (int j = 0; j < csp.task_dualPrice[1].Count; j++)
            {
                for (i = 1; i < csp.task_dualPrice.Keys.Count; i++)
                {
                    strwrite.Write(csp.task_dualPrice[i][j] + ",");
                }
                strwrite.WriteLine(csp.task_dualPrice[i][j]);
            }
            strwrite.Close();

            string num_label_iter = System.Environment.CurrentDirectory + "\\结果\\" + test_case + "\\标号数量与求解时间迭代(2).csv";

            strwrite = new StreamWriter(num_label_iter, false, Encoding.Default);
            strwrite.WriteLine("iter,label num,time*10000");
            for (i = 0; i < csp.num_label_iter.Count; i++)
            {
                strwrite.WriteLine(i + 1 + "," + csp.num_label_iter[i] + "," + csp.time_rcspp[i] * 10000);
            }
            strwrite.Close();

            //string time_rcspp_iter = System.Environment.CurrentDirectory + "\\结果\\" + test_case + "\\最短路求解时间迭代.csv";
            //strwrite = new StreamWriter(time_rcspp_iter, false, Encoding.Default);
            //strwrite.WriteLine("iter,time");
            //for (i = 0; i < csp.time_rcspp.Count; i++)
            //{
            //    strwrite.WriteLine(i+1 + "," );
            //}
            //strwrite.Close();
        }