Esempio n. 1
0
        //从文本初始化
        public Airline(string RawData)
        {
            var RawDataArray = RawData.Split(",".ToCharArray());

            ID                     = RawDataArray[0];
            Date                   = RawDataArray[1];
            InterKbn               = RawDataArray[2];
            No                     = RawDataArray[3];
            StartAirPort           = RawDataArray[4];
            EndAirPort             = RawDataArray[5];
            StartTime              = DateTime.Parse(RawDataArray[6]);
            EndTime                = DateTime.Parse(RawDataArray[7]);
            PlaneID                = RawDataArray[8];
            ModifiedPlaneID        = PlaneID;
            PlaneType              = RawDataArray[9];
            ModifiedPlaneType      = PlaneType;
            GuestCnt               = int.Parse(RawDataArray[10]);
            CombinedVoyageGuestCnt = int.Parse(RawDataArray[11]);
            //座位数根据机型获得
            if (!Solution.PlaneTypeSeatCntDic.ContainsKey(PlaneType))
            {
                Solution.PlaneTypeSeatCntDic.Add(PlaneType, int.Parse(RawDataArray[12]));
            }
            ImportFac          = double.Parse(RawDataArray[13]);
            Problem            = null;
            PreviousAirline    = null;
            NextAirLine        = null;
            ComboAirline       = null;
            _ModifiedStartTime = StartTime;
            _ModifiedEndTime   = EndTime;
        }
Esempio n. 2
0
        public static void RunTest()
        {
            Airline A0001 = new Airline()
            {
                ID           = "A0001",
                Date         = "2016-6-15",
                No           = "1",
                StartAirPort = "北京",
                EndAirPort   = "武汉"
            };

            Airline A0002 = new Airline()
            {
                ID           = "A0002",
                Date         = "2016-6-19",
                No           = "2",
                StartAirPort = "武汉",
                EndAirPort   = "北京"
            };


            //联合运输
            Airline A0003 = new Airline()
            {
                ID           = "A0003",
                Date         = "2016-6-20",
                No           = "3",
                StartAirPort = "上海",
                EndAirPort   = "巴黎"
            };

            Airline A0004 = new Airline()
            {
                ID           = "A0004",
                Date         = "2016-6-20",
                No           = "3",
                StartAirPort = "巴黎",
                EndAirPort   = "上海"
            };
            CombinedVoyage C0001 = new CombinedVoyage(A0001, A0002);
            CombinedVoyage C0002 = new CombinedVoyage(A0003, A0004);
        }
Esempio n. 3
0
        private static bool FixCombinedVoyage(int index, List <Airline> PlaneAirlineList)
        {
            //同时,拉直航程,会出现提前问题
            //使用常规方法进行修复
            Utility.Log("开始修复联程问题-航班号:" + PlaneAirlineList[index].No);
            var StandScore = Statistics.WriteResult(PlaneAirlineList);

            Utility.Log("调整前的分数:" + StandScore);
            bool    R1           = true;
            bool    R2           = true;
            var     CloneAirline = Utility.DeepCopy(PlaneAirlineList);
            Airline first        = CloneAirline[index];
            Airline second       = first.NextAirLine;

            if (first.Problem != null && (first.Problem.DetailType != ProblemType.None) || first.Problem.IsNotEnoughStayAirportTime)
            {
                Utility.Log("修复前半段:");
                R1 = FixAirportProblemByChangeTakeOffTime(CloneAirline, index, first);
            }
            second.Problem = GetProblem(second);
            if (second.Problem != null && (second.Problem.DetailType != ProblemType.None) || second.Problem.IsNotEnoughStayAirportTime)
            {
                Utility.Log("修复后半段:");
                R2 = FixAirportProblemByChangeTakeOffTime(CloneAirline, index + 1, second);
            }
            var AfterFixScore = Statistics.WriteResult(CloneAirline);

            Utility.Log("调整后的增加分数:" + (AfterFixScore - StandScore));
            CloneAirline = Utility.DeepCopy(PlaneAirlineList);
            first        = CloneAirline[index];
            second       = first.NextAirLine;
            CombinedVoyage combined = first.ComboAirline;

            if (combined.CanChangeDirect)
            {
                //CanDirect是拉直的前提条件
                //如果决定拉直航程,看一下拉直之后是否存在问题
                var problem      = GetProblem(combined.DirectAirLine);
                var ResultDirect = true;
                //存在问题的情况下,起飞和降落是否能调整起飞时间解决问题
                switch (problem.DetailType)
                {
                case ProblemType.TyphoonTakeOff:
                    //台风引起的无法飞行,可以提前飞行!
                    if (!FixTyphoonTakeOffByChangeTakeOffTime(combined.DirectAirLine))
                    {
                        ResultDirect = false;
                        Utility.Log("[无法修复]联程航班ID:" + first.ID);
                    }
                    else
                    {
                        first.Problem           = combined.DirectAirLine.Problem;
                        first.ModifiedStartTime = combined.DirectAirLine.ModifiedStartTime;
                    }
                    break;

                case ProblemType.AirportProhibitTakeOff:
                case ProblemType.AirportProhibitLand:
                case ProblemType.TyphoonLand:
                    //降落(机场限制)具有可用最早最晚降落时间
                    if (!FixByChangeTakeOffTime(combined.DirectAirLine))
                    {
                        ResultDirect = false;
                        Utility.Log("[无法修复]联程航班ID:" + first.ID);
                    }
                    else
                    {
                        first.Problem           = combined.DirectAirLine.Problem;
                        first.ModifiedStartTime = combined.DirectAirLine.ModifiedStartTime;
                    }
                    break;

                case ProblemType.None:
                    break;

                default:
                    Utility.Log("联程错误:" + problem.DetailType.ToString());
                    ResultDirect = false;
                    break;
                }
                var AfterDirectFixScore = double.MaxValue;
                if (ResultDirect)
                {
                    //第一段航程进行标注:直航
                    if (first.Problem == null)
                    {
                        first.Problem = new Problem();
                    }
                    first.FixMethod  = enmFixMethod.Direct;
                    first.ImportFac  = combined.ImportFac;
                    first.EndAirPort = combined.DirectAirLine.EndAirPort;
                    //第二段航程进行标注:取消
                    if (second.Problem == null)
                    {
                        second.Problem = new Problem();
                    }
                    second.FixMethod    = enmFixMethod.CancelByDirect;
                    second.ImportFac    = combined.ImportFac;
                    AfterDirectFixScore = Statistics.WriteResult(CloneAirline);
                    Utility.Log("调整后的增加分数:" + (AfterDirectFixScore - StandScore));
                }

                if (R1 && R2 && (!ResultDirect || AfterFixScore < AfterDirectFixScore))
                {
                    //R1,R2成功,并且 拉直失败 或者 常规比较划算
                    if (first.Problem != null && first.Problem.DetailType != ProblemType.None)
                    {
                        FixAirportProblemByChangeTakeOffTime(PlaneAirlineList, index, first);
                    }
                    if (second.Problem != null && second.Problem.DetailType != ProblemType.None)
                    {
                        FixAirportProblemByChangeTakeOffTime(PlaneAirlineList, index + 1, second);
                    }
                    return(true);
                }
                else
                {
                    //使用拉直
                    if (ResultDirect)
                    {
                        first  = PlaneAirlineList[index];
                        second = first.NextAirLine;
                        //第一段航程进行标注:直航
                        if (first.Problem == null)
                        {
                            first.Problem = new Problem();
                        }
                        first.FixMethod  = enmFixMethod.Direct;
                        first.ImportFac  = combined.ImportFac;
                        first.EndAirPort = combined.DirectAirLine.EndAirPort;
                        //第二段航程进行标注:取消
                        if (second.Problem == null)
                        {
                            second.Problem = new Problem();
                        }
                        second.FixMethod    = enmFixMethod.CancelByDirect;
                        second.ImportFac    = combined.ImportFac;
                        AfterDirectFixScore = Statistics.WriteResult(CloneAirline);
                        return(true);
                    }
                }
            }
            else
            {
                if (R1 && R2)
                {
                    //R1,R2成功,并且 拉直失败 或者 常规比较划算
                    if (first.Problem != null && first.Problem.DetailType != ProblemType.None)
                    {
                        FixAirportProblemByChangeTakeOffTime(PlaneAirlineList, index, first);
                    }
                    if (second.Problem != null && second.Problem.DetailType != ProblemType.None)
                    {
                        FixAirportProblemByChangeTakeOffTime(PlaneAirlineList, index + 1, second);
                    }
                    return(true);
                }
            }
            return(false);
        }
Esempio n. 4
0
        //读取CSV文件
        public static void ReadCSV()
        {
            StreamReader reader = null;

            //飞行表
            if (File.Exists(Utility.FlyTimeCSV))
            {
                reader = new StreamReader(Utility.FlyTimeCSV);
                Utility.Log("读取飞行时间表文件:" + Utility.FlyTimeCSV);
                //去除标题
                reader.ReadLine();
                while (!reader.EndOfStream)
                {
                    var items = reader.ReadLine().Split(",");
                    var key   = items[0] + int.Parse(items[1]).ToString("D2") + int.Parse(items[2]).ToString("D2");
                    //原数据存在主键重复的问题
                    if (!FlyTimeDic.ContainsKey(key))
                    {
                        FlyTimeDic.Add(key, int.Parse(items[3]));
                    }
                }
                reader.Close();
                Utility.Log("飞行时间记录数:" + FlyTimeDic.Count);
            }
            //读取航班信息表
            Utility.Log("读取航班信息文件:" + Utility.AirlineCSV);
            reader = new StreamReader(Utility.AirlineCSV);
            List <Airline> AirlineList = new List <Airline>();

            //去除标题
            reader.ReadLine();
            while (!reader.EndOfStream)
            {
                var airline = new Airline(reader.ReadLine());
                AirlineList.Add(airline);
                AirlineDic.Add(airline.ID, airline);
            }
            reader.Close();
            var SameComboAirKey = AirlineList.GroupBy((x) => { return(x.ComboAirLineKey); });

            foreach (var item in SameComboAirKey)
            {
                if (item.Count() == 2)
                {
                    Airline first;
                    Airline second;
                    if (item.First().StartTime > item.Last().StartTime)
                    {
                        first  = item.Last();
                        second = item.First();
                    }
                    else
                    {
                        first  = item.First();
                        second = item.Last();
                    }
                    var combined = new CombinedVoyage(first, second);
                    first.IsFirstCombinedVoyage = true;
                    first.ComboAirline          = combined;
                    second.ComboAirline         = combined;
                    CombinedVoyageList.Add(combined);
                }
            }
            Utility.Log("航班数:" + AirlineDic.Count + " 联程数:" + CombinedVoyageList.Count);

            if (File.Exists(Utility.TyphoonCSV))
            {
                Utility.Log("读取台风场景文件:" + Utility.TyphoonCSV);
                reader = new StreamReader(Utility.TyphoonCSV);
                //去除标题
                reader.ReadLine();
                while (!reader.EndOfStream)
                {
                    var typhoon = new Typhoon(reader.ReadLine());
                    CheckCondition.TyphoonList.Add(typhoon);
                    if (!CheckCondition.TyphoonAirport.Contains(typhoon.AirPort))
                    {
                        CheckCondition.TyphoonAirport.Add(typhoon.AirPort);
                    }
                    if (typhoon.TroubleType == "停机")
                    {
                        CheckCondition.TyphoonAirportRemain.Add(typhoon.AirPort, typhoon.StayCnt);
                    }
                    Utility.Log(typhoon.ToString());
                }
                reader.Close();
                Utility.Log("台风场景数:" + CheckCondition.TyphoonList.Count);
            }

            if (File.Exists(Utility.AirportProhibitCSV))
            {
                Utility.Log("读取机场限制文件:" + Utility.AirportProhibitCSV);
                reader = new StreamReader(Utility.AirportProhibitCSV);
                //去除标题
                reader.ReadLine();
                while (!reader.EndOfStream)
                {
                    CheckCondition.AirPortProhibitList.Add(new AirPortProhibit(reader.ReadLine()));
                }
                reader.Close();
                Utility.Log("机场限制数:" + CheckCondition.AirPortProhibitList.Count);
            }

            if (File.Exists(Utility.PlaneProhibitCSV))
            {
                Utility.Log("读取航线-飞机限制文件:" + Utility.PlaneProhibitCSV);
                reader = new StreamReader(Utility.PlaneProhibitCSV);
                //去除标题
                reader.ReadLine();
                while (!reader.EndOfStream)
                {
                    CheckCondition.PlaneProhibitList.Add(new PlaneProhibit(reader.ReadLine()));
                }
                reader.Close();
                Utility.Log("航线-飞机限制数:" + CheckCondition.AirPortProhibitList.Count);
            }

            if (File.Exists(Utility.TransTimeCSV))
            {
                Utility.Log("读取旅客中转时间限制表文件:" + Utility.TransTimeCSV);
                reader = new StreamReader(Utility.TransTimeCSV);
                //去除标题
                reader.ReadLine();
                while (!reader.EndOfStream)
                {
                    TransTimeList.Add(new TransTime(reader.ReadLine()));
                }
                reader.Close();
                Utility.Log("旅客中转时间限制数:" + TransTimeList.Count);
            }

            if (File.Exists(Utility.AirportCSV))
            {
                Utility.Log("读取机场表文件:" + Utility.AirportCSV);
                reader = new StreamReader(Utility.AirportCSV);
                //去除标题
                reader.ReadLine();
                while (!reader.EndOfStream)
                {
                    var temp = reader.ReadLine().Split(",".ToCharArray());
                    if (temp[1] == "1")
                    {
                        DomaticAirport.Add(temp[0]);
                    }
                }
                reader.Close();
                Utility.Log("国际机场数:" + DomaticAirport.Count);
            }


            Utility.Log("执飞表建立:");
            GetAirlineDicByPlaneId();
            Utility.Log("飞机数量:" + PlaneIdAirlineDic.Count());
        }