예제 #1
0
파일: Form1.cs 프로젝트: AtanasK/VP
 public Form1()
 {
     InitializeComponent();
     Airport airport = new Airport("Александар Велики", "Скопје", "SKP");
     airport.AddDestination(new Destination("Виена", 1240, 260));
     lbAirports.Items.Add(airport);
     loadDestinations();
 }
예제 #2
0
        protected static internal NextAirport DijkstraMinPath(string sourceCode, string destinationCode)
        {
            try {
                Queue <NextAirport> flight  = new Queue <NextAirport>();
                List <string>       visited = new List <string>();
                Stack <NextAirport> result  = new Stack <NextAirport>();
                Airport             source  = AirlineData.GetAirPort(sourceCode);
                var next = AirlineData.GetNextStation(sourceCode);
                next.Weight = 0;//sorce
                flight.Enqueue(next);
                result.Push(next);
                double BestPrice = 0;
                var    counter   = 0;
                while (flight.Count != 0)
                {
                    var _flight = flight.Dequeue();         //remove first minimum
                    if (_flight.Current == destinationCode) //we are here
                    {
                        return(_flight);
                    }

                    foreach (var neighbour in _flight.adjacementList)
                    {
                        if (neighbour != null)
                        {
                            // NextAirport _next = new NextAirport(neighbour.IATA, ,);
                            NextAirport _next = AirlineData.GetNextStation(neighbour.IATA);

                            //BestPrice = _flight.Weight + GetPriceByPath(_flight.Current, neighbour.IATA);
                            if (!visited.Contains(neighbour.IATA) && _next != null)
                            {
                                _next.Weight = GetPriceByPath(_flight.Current, neighbour.IATA);

                                Console.Write(counter);
                                Console.WriteLine(neighbour.IATA);

                                if (BestPrice == 0)
                                {
                                    BestPrice = GetPriceByPath(_flight.Current, neighbour.IATA);//_next.weight;
                                }
                                else
                                {
                                    if (BestPrice > _next.Weight)
                                    {
                                        BestPrice = _next.Weight;
                                        result.Push(_next);
                                    }
                                }
                                flight.Enqueue(_next);
                                SortQueue(ref flight);
                                visited.Add(_flight.Current);
                            }
                        }
                    }
                    counter++;
                }

                Console.ReadKey();
            }
            catch (Exception r)

            {
                Console.WriteLine(r);
            }

            return(null);
        }
예제 #3
0
 private void btnAddAirportSave_Click(object sender, EventArgs e)
 {
     Airport      = new Airport(tbAddAirportName.Text.Trim(), tbAddAirportCity.Text.Trim(), tbAddAirportShortname.Text.Trim());
     DialogResult = DialogResult.OK;
 }
 public DodadiAerodrom()
 {
     InitializeComponent();
     Airport = new Airport();
 }
 private void btnAirportSave_Click(object sender, EventArgs e)
 {
     Airport      = new Airport(tbAirportCity.Text.Trim(), tbAirportName.Text.Trim(), tbAirportShortcut.Text.Trim());
     DialogResult = System.Windows.Forms.DialogResult.OK;
 }
 private void btnSaveAiroport_Click(object sender, EventArgs e)
 {
     Airport      = new Airport(tbName.Text.Trim(), tbCity.Text.Trim(), tbShort.Text.Trim());
     DialogResult = System.Windows.Forms.DialogResult.OK;
 }
예제 #7
0
        private void ProcessAirportsDatFile()
        {
            var cities    = new List <City>();
            var countries = new Dictionary <string, Country>();

            Log.Logger.Information("Processing airports.dat file...");
            var pattern     = @"^(?<Id>\d+),""
                             (?<AirportName>[^""]+)"",""
                             (?<CityName>[^""]+)"",""
                             (?<CountryName>[^""]+)"",""
                             (?<IATACode>[A-Z]{3})"",""
                             (?<ICAOCode>[A-Z]{4})"",
                             (?<Latitude>-?[0-9]*\.?[0-9]*),
                             (?<Longtitude>-?[0-9]*\.?[0-9]*),
                             (?<Altitude>-?[0-9]*)";
            var regionInfos = CultureInfo.GetCultures(CultureTypes.SpecificCultures)
                              .Select(s => new RegionInfo(s.ToString()))
                              .Select(s => new { s.EnglishName, s.TwoLetterISORegionName, s.ThreeLetterISORegionName })
                              .Distinct()
                              .ToDictionary(a => a.EnglishName, a => new { a.TwoLetterISORegionName, a.ThreeLetterISORegionName });
            int wrongLineCount = 0;

            foreach (var line in File.ReadLines(DatFilePath))
            {
                var match = Regex.Match(line, pattern, RegexOptions.IgnorePatternWhitespace);
                if (match.Success)
                {
                    var     cityName    = match.Groups["CityName"].Value;
                    var     countryName = match.Groups["CountryName"].Value;
                    Airport airport     = new Airport();
                    airport.Id           = int.Parse(match.Groups["Id"].Value);
                    airport.TimeZoneName = AirportTimeZones[airport.Id];
                    if (!countries.ContainsKey(countryName))
                    {
                        if (!regionInfos.ContainsKey(countryName))
                        {
                            Log.Logger.Error("Invalid country name! - country: " + countryName);
                            wrongLineCount++;
                            continue;
                        }
                        Country country = new Country
                        {
                            Id                 = countries.Keys.Count + 1,
                            Name               = countryName,
                            TwoLetterISOCode   = regionInfos[countryName].TwoLetterISORegionName,
                            ThreeLetterISOCode = regionInfos[countryName].ThreeLetterISORegionName
                        };

                        countries.Add(countryName, country);
                    }
                    airport.Country   = countries[countryName];
                    airport.CountryId = airport.Country.Id;
                    var city = cities.Where(a => a.Name == cityName && a.CountryId == airport.CountryId).FirstOrDefault();
                    if (city == null)
                    {
                        city = new City
                        {
                            Id           = cities.Count + 1,
                            Name         = cityName,
                            CountryId    = airport.CountryId,
                            TimeZoneName = airport.TimeZoneName
                        };
                        cities.Add(city);
                    }
                    airport.City     = city;
                    airport.CityId   = airport.City.Id;
                    airport.Name     = match.Groups["AirportName"].Value;
                    airport.IATACode = match.Groups["IATACode"].Value;
                    airport.ICAOCode = match.Groups["ICAOCode"].Value;
                    airport.Location = new Location
                    {
                        Longtitude = double.Parse(match.Groups["Longtitude"].Value),
                        Latitude   = double.Parse(match.Groups["Latitude"].Value),
                        Altitude   = int.Parse(match.Groups["Altitude"].Value)
                    };
                    Airports.Add(airport);
                }
                else
                {
                    Log.Logger.Error("Invalid row! - data: " + line);
                    wrongLineCount++;
                }
            }
            Log.Logger.Information("Total skipped row count: " + wrongLineCount);
            Log.Logger.Information("Finished processing airports.dat file...");
            CreateJsonFiles(cities, countries.Values.ToList());
        }
예제 #8
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     createAirport = new Airport(tbCity.Text, tbName.Text, tbShortcut.Text);
     DialogResult  = DialogResult.OK;
 }