Exemple #1
0
        private void ShowCalculatedRoute(string IATA1, string IATA2)
        {
            if (AirlineData.FindIDByIATA(IATA1) == null || AirlineData.FindIDByIATA(IATA2) == null)
            {
                MessageBox.Show("Введіть коректні дані!");
                return;
            }

            airList = AStar.AStarMinPath(AirlineData.FindIDByIATA(IATA1), AirlineData.FindIDByIATA(IATA2));
            if (airList == null)
            {
                MessageBox.Show("На жаль такого маршруту не існує :(");
                return;
            }
            for (int i = 0; i < airList.Count; i++)
            {
                allAirports.Add(airList[i].Current);
            }

            for (int i = 0; i < allAirports.Count; i++)
            {
                List <PointLatLng> points = new List <PointLatLng>();
                if (i == allAirports.Count - 1)
                {
                    points.Add(new PointLatLng(allAirports[i].Latitude, allAirports[i].Longitude));

                    GMapMarker marker = new GMarkerGoogle(points[0], GMarkerGoogleType.red_dot);
                    marker.ToolTipText = Convert.ToString(i) + 's';
                    marker.ToolTipMode = MarkerTooltipMode.Never;
                    overlay.Markers.Add(marker);
                }
                else if (i == 0)
                {
                    points.Add(new PointLatLng(allAirports[i].Latitude, allAirports[i].Longitude));
                    points.Add(new PointLatLng(allAirports[i + 1].Latitude, allAirports[i + 1].Longitude));

                    GMapMarker marker = new GMarkerGoogle(points[0], GMarkerGoogleType.green_dot);
                    marker.ToolTipText = Convert.ToString(i) + 'f';
                    marker.ToolTipMode = MarkerTooltipMode.Never;
                    overlay.Markers.Add(marker);

                    var polygon = new GMapPolygon(points, "line");
                    overlay.Polygons.Add(polygon);
                }

                else
                {
                    points.Add(new PointLatLng(allAirports[i].Latitude, allAirports[i].Longitude));
                    points.Add(new PointLatLng(allAirports[i + 1].Latitude, allAirports[i + 1].Longitude));

                    GMapMarker marker = new GMarkerGoogle(points[0], GMarkerGoogleType.yellow_dot);
                    marker.ToolTipText = Convert.ToString(i) + 'm';
                    marker.ToolTipMode = MarkerTooltipMode.Never;
                    overlay.Markers.Add(marker);

                    var polygon = new GMapPolygon(points, "line");
                    overlay.Polygons.Add(polygon);
                }
            }
        }
Exemple #2
0
        protected internal static double GetPriceByPath(string sourceCode, string destinationCode)
        {
            var source      = AirlineData.GetAirPort(sourceCode);
            var destination = AirlineData.GetAirPort(destinationCode);
            var distance    = GetPath(source, destination);

            return(distance * PRICE_FOR_1_KILOMETR);
        }
Exemple #3
0
        protected static internal void DijkstraMinPath(string sourceID, string destinationID)
        {
            try
            {
                var           watch         = Stopwatch.StartNew();
                var           priotityQueue = new Queue <NextAirport>();
                List <string> visited       = new List <string>();
                var           path          = new Dictionary <NextAirport, NextAirport>();
                Airport       source        = AirlineData.GetAirPort(sourceID);
                var           next          = AirlineData.GetNextStation(sourceID);
                next.Weight = 0;//sorce
                priotityQueue.Enqueue(next);
                Graph.Source = next;
                double BestPrice = 0;

                path[next] = null;
                while (priotityQueue.Count > 0)
                {
                    var _flight = priotityQueue.Dequeue();
                    if (_flight.Current.ID == destinationID)
                    {
                        watch.Stop();
                        Graph.Destination = _flight;
                        Graph.Path        = path;
                        Console.WriteLine("Time spended {0}", watch.ElapsedMilliseconds);
                        Console.WriteLine("Count of visited vertices = {0}", visited.Count);
                        ReturnMinPath();

                        return;
                    }
                    visited.Add(_flight.Current.ID);

                    foreach (var neighbour in _flight.adjacementList)
                    {
                        NextAirport _next = AirlineData.GetNextStation(neighbour.DestinationId);;
                        if (!visited.Contains(neighbour.DestinationId) && _next != null)
                        {
                            var best = GetPriceByPath(_flight.Current.ID, neighbour.DestinationId) + _flight.Weight;//maybe best price
                            if (best < _next.Weight)
                            {
                                _next.Weight = best;
                                priotityQueue.Enqueue(_next);
                                path[_next] = _flight;
                                SortQueue(ref priotityQueue);
                            }
                        }
                    }
                }

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

            {
                Console.WriteLine(r);
            }
        }
Exemple #4
0
        public Form1()
        {
            InitializeComponent();
            AirlineData.LoadData();
            GMapProviders.GoogleMap.ApiKey = @"AIzaSyAPFEPeEVq_ECcRp6lcWzh-zpmyJG6nQKo";

            gMap.MapProvider = GMapProviders.GoogleMap;
            gMap.ShowCenter  = false;
            gMap.Position    = new PointLatLng(25, 35);

            List <String> citylist = MergeSortClass <String> .MergeSort(AirlineData.GetCityList());

            List <String> citylist2 = citylist.GetRange(0, citylist.Count);

            comboBoxCity1.DataSource = citylist;
            comboBoxCity2.DataSource = citylist2;
        }
Exemple #5
0
 protected static internal void SearchPointsWithBfs(string sourceID, string searchID)
 {
     try
     {
         var     watch   = Stopwatch.StartNew();
         Airport source  = AirlineData.GetAirPort(sourceID);
         var     next    = AirlineData.GetNextStation(sourceID);
         var     que     = new Queue <NextAirport>();
         var     visited = new List <Airport>();
         que.Enqueue(next);
         visited.Add(source);
         var counter = 0;
         while (que.Count > 0)
         {
             var vertex = que.Dequeue();
             if (vertex.Current.ID == searchID)
             {
                 watch.Stop();
                 Console.WriteLine("Airport with code {0} and name {1} finded from start airport {2}", vertex.Current.ID, vertex.Current.AirportName, sourceID);
                 Console.WriteLine("Count of vetrices between two vertices = {0}", counter);
                 Console.WriteLine("Count of visited vertices = {0}", visited.Count);
                 Console.WriteLine("Time spended {0}", watch.ElapsedMilliseconds);
                 return;
             }
             foreach (var neighbour in vertex.adjacementList)
             {
                 if (neighbour.DestinationId != null)
                 {
                     if (!(visited.Contains(AirlineData.GetAirPort(neighbour.DestinationId))))
                     {
                         que.Enqueue(AirlineData.GetNextStation(neighbour.DestinationId));
                         visited.Add(AirlineData.GetAirPort(neighbour.DestinationId));
                         counter++;
                     }
                 }
             }
         }
     }
     catch (Exception r)
     {
         Console.WriteLine(r);
     }
 }
Exemple #6
0
        private void ShowAirportsInTwoCity(string city1, string city2)
        {
            List <int> PointColor = new List <int>();

            allAirports = AirlineData.ReturnListOfAirportsBy2City(city1, city2);
            for (int i = 0; i < allAirports.Count; i++)
            {
                PointLatLng point = new PointLatLng(allAirports[i].Latitude, allAirports[i].Longitude);
                if (allAirports[i].CityName == city1)
                {
                    GMapMarker marker = new GMarkerGoogle(point, GMarkerGoogleType.blue_dot);
                    marker.ToolTipText = Convert.ToString(i) + 'f';
                    marker.ToolTipMode = MarkerTooltipMode.Never;
                    overlay.Markers.Add(marker);
                }
                else
                {
                    GMapMarker marker = new GMarkerGoogle(point, GMarkerGoogleType.red_dot);
                    marker.ToolTipText = Convert.ToString(i) + 's';
                    marker.ToolTipMode = MarkerTooltipMode.Never;
                    overlay.Markers.Add(marker);
                }
            }
        }
Exemple #7
0
        protected static internal List <NextAirport> AStarMinPath(string sourceID, string destinationID)
        {
            // отримуємо найкоротший шлях від аеропорта А до аеропорта Б

            NextAirport neighbourNode1;

            var watch     = Stopwatch.StartNew();
            var closedSet = new Queue <NextAirport>();
            var openSet   = new Queue <NextAirport>();

            AStar.Source      = AirlineData.GetNextStation(sourceID);
            AStar.Destination = AirlineData.GetNextStation(destinationID);

            AStar.Source.previous                    = null;
            AStar.Source.PathLengthFromStart         = 0;
            AStar.Source.HeuristicEstimatePathLength = GetPath(AStar.Source.Current, AStar.Destination.Current);

            openSet.Enqueue(AStar.Source);

            // Console.WriteLine($"Start searching path from {AStar.Source.Current.AirportName} to {AStar.Destination.Current.AirportName} ");
            while (openSet.Count > 0)
            {
                var currentAirport = openSet.OrderBy(node => node.EstimateFullPathLength).First();
                currentAirport = openSet.Dequeue();

                if (currentAirport.Current.ID == destinationID) // mccarran
                {
                    Console.WriteLine("Time spended {0}", watch.ElapsedMilliseconds);
                    Console.WriteLine($"There is the way from {AStar.Source.Current.AirportName} to {AStar.Destination.Current.AirportName} ");
                    return(ReturnMinPath(currentAirport));
                }

                closedSet.Enqueue(currentAirport);

                foreach (var neighbourAirport in currentAirport.adjacementList)
                {
                    neighbourNode1 = AirlineData.GetNextStation(neighbourAirport.DestinationId);

                    if (closedSet.Count(node => node.Current.ID == neighbourNode1.Current.ID) > 0)
                    {
                        continue;
                    }

                    double temp_PathLenghtFromStart = currentAirport.PathLengthFromStart + GetPath(currentAirport.Current, neighbourNode1.Current);                                                                                                                                                     // neighbourNode1.PathLengthFromStart = currentAirport.PathLengthFromStart + GetPath(currentAirport.Current, AirlineData.GetAirPort(neighbourNode.ITA)); // виглядає правильніше, працює довше, результат коректний

                    var openNode = openSet.FirstOrDefault(node => node.Current.ID == neighbourNode1.Current.ID);
                    if (openNode == null || temp_PathLenghtFromStart <= neighbourNode1.PathLengthFromStart)
                    {
                        neighbourNode1.previous                    = currentAirport;
                        neighbourNode1.PathLengthFromStart         = temp_PathLenghtFromStart;
                        neighbourNode1.HeuristicEstimatePathLength = GetPath(neighbourNode1.Current, AStar.Destination.Current);
                    }
                    if (openNode == null)
                    {
                        openSet.Enqueue(neighbourNode1);
                    }
                }
            }
            Console.WriteLine($"There is no way from airport with name {AStar.Source.Current.AirportName} to airport {AStar.Destination.Current.AirportName}");
            Console.WriteLine("Time spended {0}", watch.ElapsedMilliseconds);

            return(null);
        }