Esempio n. 1
0
        public void Read()
        {
            int lid = 1;

            StreamReader sR = File.OpenText(@"F:\trainCrew\trainCrew\DAL\test.txt");

            string nextLine;

            while ((nextLine = sR.ReadLine()) != null)
            {
                string[] arr = nextLine.Split('\t');//分割每个字段

                RouteLine result = new RouteLine {
                    RouteLineID = lid, Line = arr[1], InitTime = TimeSpan.Parse(arr[2]), InitStation = arr[3], EndTime = TimeSpan.Parse(arr[4]), EndStation = arr[5]
                };
                if (result.Timelength().TotalMinutes > 2.5) //超过2分钟
                {
                    Common.routelines.Add(result);          //这是个合理的时间段
                    lid++;
                }
            }

            sR.Close();
        }
Esempio n. 2
0
        public bool push(int dataTripID)                         //抓取一个车次,并尝试将其堆在此空间中,如果不能堆叠它,返回false,否则true
        {
            RouteLine candidate = Common.routelines[dataTripID]; //要入栈的车次
            TimeSpan  aux;                                       //辅助变量

            //块为空
            if (blocks.Count() == 0)
            {//加载新快
                _push("Trip", candidate);
                _push("Fat", null);
                timeDriving = timeContinuosDriving = candidate.Timelength();//这个车次的时间差
                return(true);
            }

            /****块不为空***/

            //是否插入午餐
            if (!hasLunch)
            {
                /*还没有午餐*/
                if (timeDriving >= Common.generalIntervals["maxTimeDrivingBeforeLunch"])//驾驶时间大于最大驾驶时间
                {
                    hasLunch = true;
                    _push("Lunch", null);                         // 插入午餐
                    timeContinuosDriving = new TimeSpan(0, 0, 0); //重置连续开车时间为 0
                }
            }

            //是否驾驶时间太长
            if (timeContinuosDriving >= Common.generalIntervals["maxTimeContinuousDriving"])
            {
                timeContinuosDriving = new TimeSpan(0, 0, 0); //重置连续开车时间为 0
                _push("Rest", null);                          //插入休息
            }

            /**重新初始化**/
            aux = candidate.Timelength();
            aux = timeDriving + aux;

            /*设置条件,看入栈的车次是否符合*/
            if (!(aux < Common.generalIntervals["maxTimeDriving"]))//比最大驾驶时间大
            {
                return(false);
            }

            if (!(blocks[blocks.Count() - 1].endTime <= candidate.InitTime))//要入栈的车次的出发时间比原上一班的时间结束时间早
            {
                return(false);
            }


            /*候选车次开始入栈*/
            //添加进车次集合
            if (blocks[blocks.Count() - 1].endTime < candidate.InitTime)
            {
                _push("Leisure", candidate.InitTime); //开车时间作为空闲的起始时间
                aux         = blocks[blocks.Count() - 1].Timelength();
                timeLeisure = timeLeisure + aux;      //空闲时间的长度
            }

            /**重新初始化**/
            aux         = candidate.Timelength();
            timeDriving = timeDriving + aux;

            if (blocks[blocks.Count() - 1].type.Equals("Fat"))//正好轮到高峰期
            {
                aux = candidate.Timelength();
                timeContinuosDriving = timeContinuosDriving + aux;
            }
            else
            {
                timeContinuosDriving = new TimeSpan(0, 0, 0);
            }

            _push("RouteLine", candidate);
            _push("Fat", null);
            return(true);
        }