Esempio n. 1
0
 public void TSSNetWork()
 {
     //rtboc.Text += "系统正在自行建立时空状态网络,请稍候..." + "\r\n";
     Ds = net.ConnDataBase();
     //net.LoadData(Ds,2);
     //net.LoadData_csv(1);
     net.CreateT_S_NetWork();
     //net.CreateT_S_S_NetWork();
     //return net;
     // rtboc.Text += "时空状态网络已经建成,开始计算..." + "\r\n";
     lag.IterationGap(ref net, 0.0005);
 }
        private void Form1_Load(object sender, EventArgs e)
        {
            Ds = cnw.ConnDataBase();
            //cnw.LoadData(Ds, 2);
            //cnw.LoadData_csv(1);
            cnw.CreateT_S_NetWork();
            //cnw.CreateT_S_S_NetWork();
            //cnw.CreateT_S_S_NetWork(int mindrivetime,int maxdrivetime,int maxconntime,int mintranslation,int minrelaxtime,int maxrelaxtime,int minoutrelaxtime,int maxoutrelaxtime,int mindaycrewtime,int maxdaycrewtime);
            cnw.CreateT_S_S_NetWork(70, 300, 40, 15, 3312, 3330, 3400, 3900, 150, 300);
            //(int maxdrivetime,int mindrivetime,int maxconntime,int mintranslation,int minrelaxtime,int maxrelaxtime,int minoutrelaxtime,int maxoutrelaxtime,int maxdaycrewtime,int mindaycrewtime)
            int k = cnw.T_S_S_NodeList.Count;

            Dt = cnw.ShowResult1();
            dataGridView1.DataSource = Dt;
        }
Esempio n. 3
0
        private void buttonok_Click(object sender, EventArgs e)
        {
            int maxdrivetime    = Convert.ToInt32(textBoxmaxdrive.Text);
            int mindrivetime    = Convert.ToInt32(textBoxmindrive.Text);
            int maxdaycrewtime  = Convert.ToInt32(textBoxmaxdaycrew.Text);
            int mindaycrewtime  = Convert.ToInt32(textBoxmindaycrew.Text);
            int maxconntime     = Convert.ToInt32(textBoxconn.Text);
            int mintranslation  = Convert.ToInt32(textBoxtran.Text);
            int minrelaxtime    = Convert.ToInt32(textBoxminrelax.Text);
            int maxrelaxtime    = Convert.ToInt32(textBoxmaxrelax.Text);
            int minoutrelaxtime = Convert.ToInt32(textBoxminoutrelax.Text);
            int maxoutrelaxtime = Convert.ToInt32(textBoxmaxoutrelax.Text);
            int days            = Convert.ToInt32(textBoxdays.Text);
            int step            = Convert.ToInt32(textBoxstep.Text);


            List <int[]> windows = new List <int[]>();

            //STLunch = 660; ETLunch = 780; STDinner = 1020; ETDinner = 1140; //2h
            //int STLunch = 630, ETLunch = 810, STDinner = 990, ETDinner = 1170; //3h
            windows.Add(new int[4] {
                660, 780, 1020, 1140
            });                                              //2h
            windows.Add(new int[4] {
                630, 810, 990, 1170
            });                                             //3h
            windows.Add(new int[4] {
                600, 840, 960, 1200
            });                                              //4h
            //windows.Add(new int[4] {480,   840,   900,   1260}); //不考虑 windows})
            windows.Add(new int[4] {
                4000, 8400, 9600, 14400
            });
            //windows.Add(new int[4] { 3000, 7200, 7210, 28800 });//INF

            string[] Cur_case = { "case21\\", "case22\\", "case33\\", "case34\\" };


            for (int j = 0; j < windows.Count - 3; j++)
            {
                #region MyRegion
                Stopwatch realTime = new Stopwatch();
                realTime.Restart();

                str = "";

                CGandLR LR_CG = new CGandLR();

                StartTime = DateTime.Now;
                int    sh        = StartTime.Hour;
                int    sm        = StartTime.Minute;
                int    ss        = StartTime.Second;
                int    sms       = StartTime.Millisecond;
                int    sa        = (sh * 60 + sm) * 60 + ss;
                double starttime = sa + 0.001 * sms;
                //Ds = net.ConnDataBase();
                //net.LoadData(Ds,days);
                net.LoadData_csv(days,
                                 "..\\DATA\\沪杭\\Timetable.csv",
                                 "..\\DATA\\沪杭\\CrewBase.csv",
                                 "..\\DATA\\沪杭\\Crew.csv",
                                 "..\\DATA\\沪杭\\Station.csv");
                net.CreateT_S_NetWork();

                net.SetMealWindows(windows[j][0], windows[j][1], windows[j][2], windows[j][3]);

                //net.CreateT_S_S_NetWork(mindrivetime,maxdrivetime,maxconntime,mintranslation,minrelaxtime, maxrelaxtime,minoutrelaxtime,maxoutrelaxtime, mindaycrewtime, maxdaycrewtime);//daycrewtime-120出退乘
                //net.CreateT_S_S_NetWork(180, 250, 40, 15, 3312, 3330, 3400, 3900, 180, 250);//京津城际实例
                net.CreateT_S_S_NetWork(240, 540, 90, 13, 3312, 3300, 3400, 3900, 240, 540);//沪宁杭
                //net.CreateT_S_S_NetWork(180, 720, 200, 6, 3312, 3330, 600, 2800, 180, 720);//bigscale
                //net.CreateT_S_S_NetWork(120, 780, 400, 6, 3312, 3330, 540, 2880, 120, 780);//bigscale2

                //lag = new Lagrange(net, 350);
                LR_CG.InitLR(net, 350);
                lag = LR_CG.LR;
                LR_CG.InitCG(net);

                string case_dir = System.Environment.CurrentDirectory +
                                  "\\12算例结果\\new_test\\沪杭\\" + Cur_case[j];

                StreamWriter file_1 = new StreamWriter(case_dir +
                                                       "交路内容与求解信息" + lag.step_size + "_M3_(1000)_in==0_nosppedLB.txt", false, Encoding.Default);
                StreamWriter file_2 = new StreamWriter(case_dir +
                                                       "iterationBound" + lag.step_size + "_M3_(1000)_in==0_nosppedLB.csv", false, Encoding.Default);
                StreamWriter file_3 = new StreamWriter(case_dir +
                                                       "convergeBound" + lag.step_size + "_M3_(1000)_in==0_nosppedLB.csv", false, Encoding.Default);

                Console.WriteLine("solve case: " + Cur_case[j]);
                Console.WriteLine("state arc number: " + net.T_S_S_ArcList.Count);
                Console.WriteLine("state node number: " + net.T_S_S_NodeList.Count);


                EndTime_Net = DateTime.Now;
                int    eh_Net      = EndTime_Net.Hour;
                int    em_Net      = EndTime_Net.Minute;
                int    es_Net      = EndTime_Net.Second;
                int    ems_Net     = EndTime_Net.Millisecond;
                int    ea_Net      = (eh_Net * 60 + em_Net) * 60 + es_Net;
                double endtime_Net = ea_Net + 0.001 * ems_Net;
                time_Net = endtime_Net - starttime;
                Console.WriteLine("create net spend time: {0} s", time_Net);

                bool isnotcontain = true;
                isnotcontain = net.AllLineContain();
                if (isnotcontain == false)//|| isnotcontain)
                {
                    //if (radioButtonk.Checked == true)
                    //{
                    //int K = 100;// Convert.ToInt32(textBoxend.Text);
                    //lag.k = 0;
                    //lag.IterationK(ref net, K);
                    //}
                    LR_CG.LR_and_CG(ref net, 10);

                    if (radioButtonGap.Checked == true)
                    {
                        double Gap = Convert.ToDouble(textBoxend.Text);

                        //lag.IterationGap(ref net, Gap);
                    }
                    if (radioButtonUB.Checked == true)
                    {
                        int N = Convert.ToInt32(textBoxend.Text);
                        //lag.IterationUBStay(ref net, N);
                    }

                    EndTime = DateTime.Now;
                    int    eh      = EndTime.Hour;
                    int    em      = EndTime.Minute;
                    int    es      = EndTime.Second;
                    int    ems     = EndTime.Millisecond;
                    int    ea      = (eh * 60 + em) * 60 + es;
                    double endtime = ea + 0.001 * ems;
                    time = endtime - starttime;

                    realTime.Stop();

                    Console.WriteLine("{0} spend time: {1} s", Cur_case[j], realTime.Elapsed.TotalSeconds);
                    Console.WriteLine("calculate time(except net construction time): {0} s"
                                      , realTime.Elapsed.TotalSeconds - time_Net);

                    if (checkCur.Checked == true && checkCurBest.Checked == false)
                    {
                        showgap_cur.Draw(lag.CurLB, lag.CurUB, time);
                        showgap_cur.Show();
                    }
                    else if (checkCur.Checked == false && checkCurBest.Checked == true)
                    {
                        showgap_curbest.Draw(lag.CurBestLB, lag.CurBestUB, time);
                        showgap_curbest.Show();
                    }
                    else if (checkCur.Checked == true && checkCurBest.Checked == true)
                    {
                        showgap_cur.Draw(lag.CurLB, lag.CurUB, time);
                        showgap_curbest.Draw(lag.CurBestLB, lag.CurBestUB, time);
                        showgap_curbest.Show();
                        showgap_cur.Show();
                    }

                    //保存文件
                    int i = 0;
                    for (i = 0; i < lag.YUB.Count; i++)
                    {
                        str += "乘务交路" + (i + 1).ToString() + "为:" + lag.YUB[i] + "\r\n";
                    }
                    double gap = (lag.BestUB - lag.BestLB) / lag.BestUB;
                    str += "BestLB为:" + lag.BestLB.ToString("f2") + "\r\n";
                    str += "BestUB为:" + lag.BestUB.ToString("f2") + "\r\n";
                    str += "迭代次数K为:" + lag.k.ToString() + "\r\n";
                    str += "Gap为:" + gap.ToString("f4") + "\r\n";
                    str += "建网时间为:" + time_Net.ToString("f2") + "s" + "\r\n";
                    str += "state arc number: " + net.T_S_S_ArcList.Count + "\r\n";
                    str += "state node number: " + net.T_S_S_NodeList.Count + "\r\n";
                    str += "求解时间为:" + time.ToString("f2") + "s" + "\r\n";
                    str += "real求解时间为:" + realTime.Elapsed.TotalSeconds.ToString("f2") + "s" + "\r\n";
                    str += "决策变量个数为:" + net.T_S_S_ArcList.Count * lag.CrewCount;

                    file_1.WriteLine(str);
                    file_1.Close();

                    string LB_UB = "";
                    file_2.WriteLine("CurLB,CurUB");
                    for (i = 0; i < lag.CurLB.Count; i++)
                    {
                        LB_UB = "";
                        LB_UB = i < lag.CurUB.Count ?
                                Convert.ToString(lag.CurLB[i]) + "," + Convert.ToString(lag.CurUB[i])
                            : Convert.ToString(lag.CurLB[i]);
                        file_2.WriteLine(LB_UB);// + "," + lag.CurUB[i]);
                    }
                    file_2.Close();

                    file_3.WriteLine("CurBestLB,CurBestUB");
                    for (i = 0; i < lag.CurBestLB.Count; i++)
                    {
                        LB_UB = "";
                        LB_UB = i < lag.CurBestUB.Count ?
                                Convert.ToString(lag.CurBestLB[i]) + "," + Convert.ToString(lag.CurBestUB[i])
                            : Convert.ToString(lag.CurBestLB[i]);
                        file_3.WriteLine(LB_UB);// + "," + lag.CurUB[i]);
                    }
                    file_3.Close();
                }

                Console.WriteLine("{0} 求解完成 ", Cur_case[j]);
                #endregion
            }

            MessageBox.Show("保存成功!", "please close",
                            MessageBoxButtons.OK,
                            MessageBoxIcon.Stop,
                            MessageBoxDefaultButton.Button1,
                            MessageBoxOptions.ServiceNotification);
        }