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); }
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); }