Beispiel #1
0
 public void LoadRules_csv()
 {
     CSV_      = CSV_Set_["CrewRules"];
     CrewRules = new CG_CSP_1440.CrewRules();
     CrewRules.MinTranstime            = Convert.ToInt32(CSV_.ColumnData_Set_["最短换乘时间"][0]);
     CrewRules.MinInterval             = Convert.ToInt32(CSV_.ColumnData_Set_["间休时间窗"][0]);
     CrewRules.MaxInterval             = Convert.ToInt32(CSV_.ColumnData_Set_["间休时间窗"][1]);
     CrewRules.MinConsecutiveDriveTime = Convert.ToInt32(CSV_.ColumnData_Set_["连续驾驶时间窗"][0]);
     CrewRules.MaxConsecutiveDriveTime = Convert.ToInt32(CSV_.ColumnData_Set_["连续驾驶时间窗"][1]);
     CrewRules.PureCrewTime            = Convert.ToInt32(CSV_.ColumnData_Set_["乘务时间窗"][0]);
     CrewRules.TotalCrewTime           = Convert.ToInt32(CSV_.ColumnData_Set_["乘务时间窗"][1]);
     CrewRules.MinNonBaseRest          = Convert.ToInt32(CSV_.ColumnData_Set_["外驻时间窗"][0]);
     CrewRules.MaxNonBaseRest          = Convert.ToInt32(CSV_.ColumnData_Set_["外驻时间窗"][1]);
     CrewRules.MaxLongDuties           = Convert.ToInt32(CSV_.ColumnData_Set_["交路允许长度"][0]);
     CrewRules.MaxDays = Convert.ToInt32(CSV_.ColumnData_Set_["持续天数"][0]);
 }
Beispiel #2
0
        //int TransTime           = CrewRules.minTransTime;
        ////int minInterval         = (int)CrewRules.Interval.min;
        //int maxInterval         = (int)CrewRules.Interval.max;
        ////int minConsecuDrive     = (int)CrewRules.ConsecuDrive.min;//铭-240;岩-180
        ////int maxConsecuDrive     = (int)CrewRules.ConsecuDrive.max;
        //int PureCrewTime        = CrewRules.PureCrewTime;//same
        //int TotalCrewTime       = CrewRules.TotalCrewTime;//铭-540;岩-480
        //int minNonBaseRest      = (int)CrewRules.NonBaseRest.min;//铭-720;岩-960
        //int maxNonBaseRest      = (int)CrewRules.NonBaseRest.max;
        //int Longest             = CrewRules.MaxLongDuties;//先一样
        //int MaxDays             = CrewRules.MaxDays;
        #endregion

        public void CreateNetwork(DataReader Data)
        {
            //DataReader Data = new DataReader();
            ////Data.Ds = Data.ConnSQL(ConnStr);
            ////Data.LoadData_sql(Data.Ds, MaxDays);
            //List<string> csvfiles;
            //Data.Connect_csvs(out csvfiles, ConnStr);
            //Data.LoadRules_csv();
            //Data.LoadData_csv(MaxDays);
            CrewRules = Data.CrewRules;
            //建弧
            this.NodeSet  = Data.NodeSet;
            this.TripList = Data.TripList;
            ArcSet        = new List <Arc>();
            int  i, j;
            Node trip1, trip2;
            int  length = 0;
            Node virO   = NodeSet[0];
            Node virD   = NodeSet[1];

            List <Node> odBase = Data.ODBaseList;

            for (i = 0; i < odBase.Count; i++) //虚拟起终点弧
            {
                //virO--OBase
                if (odBase[i].Type == 0)
                {
                    Arc arc = new Arc();
                    arc.O_Point = virO;
                    arc.D_Point = odBase[i];
                    arc.Cost    = 0;  //NodeSet[i].StartTime;
                    arc.ArcType = 20; //1-接续弧,2-出乘弧,3-退乘弧, 20-虚拟起点弧,30-虚拟终点弧
                    ArcSet.Add(arc);
                    virO.Out_Edges.Add(arc);
                    odBase[i].In_Edges.Add(arc);
                }
                else if (odBase[i].Type == 2)
                {
                    Arc arc = new Arc();
                    arc.O_Point = odBase[i];
                    arc.D_Point = virD;
                    arc.Cost    = 0;
                    arc.ArcType = 30;
                    ArcSet.Add(arc);
                    odBase[i].Out_Edges.Add(arc);
                    virD.In_Edges.Add(arc);
                }
            }

            for (i = 2; i < NodeSet.Count; i++)
            {
                trip1 = NodeSet[i];
                for (j = 2; j < NodeSet.Count; j++)
                {
                    trip2 = NodeSet[j];

                    if (trip1.Type == 1 && trip2.Type == 1) //接续弧
                    {
                        length = trip2.StartTime - trip1.EndTime;
                        if (trip1 != trip2 && trip1.EndStation == trip2.StartStation && length > 0)
                        {
                            //if ((trip1.RoutingID == trip2.RoutingID) ||
                            //    (trip1.RoutingID != trip2.RoutingID &&
                            //    ((TransTime <= length && length <= Interval[1]) ||
                            //    (trip2.StartTime > 1440 && trip1.EndTime < 1440 && minNonBaseRest <= length && length <= maxNonBaseRest))))
                            if (trip1.RoutingID == trip2.RoutingID || Transferable(trip1, trip2, length))//顺序不能变,因为是通过逻辑转换才将上面的简化为这样
                            {
                                Arc arc = new Arc();
                                arc.O_Point = trip1;
                                arc.D_Point = trip2;
                                arc.Cost    = length;
                                arc.ArcType = length >= CrewRules.MinNonBaseRest ? 22 : 1;//22-跨天了
                                ArcSet.Add(arc);
                                trip1.Out_Edges.Add(arc);
                                trip2.In_Edges.Add(arc);
                            }
                        }
                    }
                    else if (trip1.EndStation == trip2.StartStation && trip1.Type == 0 && trip2.Type == 1)
                    {
                        Arc arc = new Arc();
                        arc.O_Point = trip1;
                        arc.D_Point = trip2;
                        arc.Cost    = trip2.StartTime;
                        arc.ArcType = 2;
                        ArcSet.Add(arc);
                        trip1.Out_Edges.Add(arc);
                        trip2.In_Edges.Add(arc);
                    }
                    else if (trip1.EndStation == trip2.StartStation && trip1.Type == 1 && trip2.Type == 2)
                    {
                        Arc arc = new Arc();
                        arc.O_Point = trip1;
                        arc.D_Point = trip2;
                        int d = (trip1.EndTime / 1440 + 1);
                        arc.Cost    = 1440 * d - trip1.EndTime;
                        arc.ArcType = 3;
                        ArcSet.Add(arc);
                        trip1.Out_Edges.Add(arc);
                        trip2.In_Edges.Add(arc);
                    }
                }
            }
            //原始区段数
            num_physical_trip = (NodeSet.Count - 2 - 2 * DataReader.CrewBaseList.Count) / CrewRules.MaxDays;

            #region CheckTestArcs
            //foreach (Arc arc in ArcSet)
            //{
            //    Console.WriteLine(arc.O_Point.ID + " -> " + arc.D_Point.ID + " type: " + arc.ArcType);
            //}
            #endregion
            //删去出度或入度为0的点与弧
            DeleteUnreachableNodeandEdge(ref TripList);
        }