private void Search(AirportChain2 chain, FlightShort startFlight, string departure, int level)
        {
            if (!_flightsData.ContainsKey(departure)) {
                return;
            }

            DateTime departureDateTime = startFlight.DateTime.AddHours(_minimalStopHours);
            var dirsections = _flightsData[departure];

            if (level == _depth - 1) {
                var finishAirports = dirsections.Keys.Where(arrival => _finishAirports.Contains(arrival));

                foreach (string arrival in finishAirports) {
                    var flights = dirsections[arrival];
                    if (flights.Any(flight => flight.DateTime > departureDateTime)) {
                        _chains.Add(chain.Next(arrival));
                    }
                }
                return;
            }

            foreach (string arrival in dirsections.Keys) {
                var flights = dirsections[arrival];

                var nextFlight = flights.FirstOrDefault(flight => flight.DateTime > departureDateTime);

                if (nextFlight != null) {
                    Search(chain.Next(arrival), nextFlight, arrival, level + 1);
                }
            }
        }
Esempio n. 2
0
        public IReadOnlyCollection<AirportChain2> Search(string[] startAirports, DateTime start, DateTime end)
        {
            _chains.Clear();

            var flights = _flightsData
                .Where(flight => start < flight.DateTime && flight.DateTime < end)
                .OrderBy(flight => flight.DateTime)
                .ToArray();

            var startFlights = _flightsData
                .Where(
                    flight =>
                        start < flight.DateTime && flight.DateTime < end && startAirports.Contains(flight.Departure))
                .GroupBy(flight => flight.Arrival)
                .Select(group => group.OrderBy(flight => flight.DateTime).FirstOrDefault())
                .OrderBy(flight => flight.DateTime)
                .ToList();

            AirportChain2 chain = new AirportChain2();

            for (int i = 0; i < startFlights.Count; i++) {
                var startFlight = startFlights[i];
                Console.WriteLine("{0} of {1}", i, startFlights.Count);
                Search(chain.Next(startFlight), startFlight, flights, 1);
            }

            return _chains.AsReadOnly();
        }
Esempio n. 3
0
        private void Search(AirportChain2 chain, FlatFlight startFlight, FlatFlight[] flights, int level)
        {
            if (_finishAirports.Contains(startFlight.Arrival)) {
                if (level == _depth) {
                    _chains.Add(chain);
                }
                return;
            }
            if (level == _depth) {
                return;
            }

            DateTime departureDateTime = startFlight.DateTime.AddHours(_minimalStopHours);

            int len = flights.Length;
            int skipCount = 0;
            for (; skipCount < len; skipCount++) {
                if (flights[skipCount].DateTime > departureDateTime) {
                    break;
                }
            }

            var xFlights = flights
                .Skip(skipCount)
                .ToArray();
            if (xFlights.Length == 0) {
                return;
            }

            var startFlights = xFlights
                .Where(flight => flight.Departure == startFlight.Arrival)
                .GroupBy(flight => flight.Arrival)
                .Select(group => group.OrderBy(flight => flight.DateTime).FirstOrDefault())
                .ToList();

            int count = startFlights.Count;

            for (int i = 0; i < startFlights.Count; i++) {
                var flight = startFlights[i];

                if (level < 3) {
                    Console.WriteLine("{0} {1} of {2}", new string('>', level), i, count);
                }
                Search(chain.Next(flight), flight, xFlights, level + 1);
            }
        }
Esempio n. 4
0
 private AirportChain2(AirportChain2 chain, FlatFlight flight)
 {
     Airports = new List<string>(chain.Airports);
     AddFlight(flight);
 }
Esempio n. 5
0
 private AirportChain2(AirportChain2 chain, string arrival)
 {
     Airports = new List<string>(chain.Airports);
     Airports.Add(arrival);
 }