Exemplo n.º 1
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);
        }
Exemplo n.º 2
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);
            }
        }
Exemplo n.º 3
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);
     }
 }