Ejemplo n.º 1
0
        public void TestTwoHopsOneTransferCloseStopsSuccessfulSkippedPseudo()
        {
            // build dummy db.
            var db = new TransitDb();

            db.AddStop(0, 0, 0);
            db.AddStop(1, 1, 1);
            db.AddStop(2, 2, 2);
            db.AddStop(3, 3, 3);
            db.AddTrip(0, 0, 0);
            db.AddTrip(0, 0, 0);
            db.AddTrip(0, 0, 0);
            db.AddConnection(0, 1, 0, 8 * 3600, 8 * 3600 + 10 * 60);
            db.AddConnection(1, 2, 0, 8 * 3600 + 10 * 60, 8 * 3600 + 15 * 60);
            db.AddConnection(2, 3, 0, 8 * 3600 + 15 * 60, 8 * 3600 + 25 * 60);

            db.SortConnections(DefaultSorting.DepartureTime, null);

            // build dummy transfers db.
            var transfersDb = new TransfersDb(1024);

            transfersDb.AddTransfer(1, 2, 60); // this leads to a transfer time faster than the actual connection.

            // run algorithm.
            var departureTime = new DateTime(2017, 05, 10, 07, 30, 00);
            var algorithm     = new ProfileSearch(db, departureTime, transfersDb,
                                                  (profileId, day) => true);

            algorithm.SetSourceStop(0, 07 * 3600 + 30 * 60);
            algorithm.SetTargetStop(3, 0);
            algorithm.Run();

            // test results.
            Assert.IsTrue(algorithm.HasRun);
            Assert.IsTrue(algorithm.HasSucceeded);

            // check arrival profile(s).
            var arrivalStops = algorithm.ArrivalStops;

            Assert.AreEqual(3, arrivalStops.Count);
            Assert.AreEqual(3, arrivalStops[2]);
            var arrivalProfiles = algorithm.ArrivalProfiles;

            Assert.AreEqual(3, arrivalProfiles.Count);
            Assert.AreEqual(08 * 3600 + 25 * 60, arrivalProfiles[2].Seconds);
            Assert.AreEqual(55 * 60, algorithm.Duration(2));
            Assert.AreEqual(new DateTime(2017, 05, 10, 08, 25, 00), algorithm.ArrivalTime(2));

            // check stop profiles.
            var connections = db.GetConnectionsEnumerator(DefaultSorting.DepartureTime);
            var profiles    = algorithm.GetStopProfiles(3);

            Assert.AreEqual(3, profiles.Count);
            var profile = profiles[0];

            Assert.IsTrue(profile.IsEmpty);
            profile = profiles[1];
            Assert.IsTrue(profile.IsEmpty);
            profile = profiles[2];
            Assert.AreEqual(2, profile.PreviousConnectionId);
            Assert.AreEqual((int)(departureTime - departureTime.Date).TotalSeconds + 55 * 60, profile.Seconds);

            profiles = algorithm.GetStopProfiles(2);
            Assert.AreEqual(4, profiles.Count);
            profile = profiles[0];
            Assert.IsTrue(profile.IsEmpty);
            profile = profiles[1];
            Assert.IsTrue(profile.IsEmpty);
            profile = profiles[2];
            Assert.AreEqual(1, profile.PreviousConnectionId);
            Assert.AreEqual((int)(departureTime - departureTime.Date).TotalSeconds + 45 * 60, profile.Seconds);
            profile = profiles[3];
            Assert.IsTrue(profile.IsTransfer);
            Assert.AreEqual(1, profile.PreviousStopId);
            Assert.AreEqual((int)(departureTime - departureTime.Date).TotalSeconds + 40 * 60 + 60, profile.Seconds);

            profiles = algorithm.GetStopProfiles(1);
            Assert.AreEqual(3, profiles.Count);
            profile = profiles[0];
            Assert.IsTrue(profile.IsEmpty);
            profile = profiles[1];
            Assert.IsTrue(profile.IsEmpty);
            profile = profiles[2];
            Assert.AreEqual(0, profile.PreviousConnectionId);
            Assert.AreEqual((int)(departureTime - departureTime.Date).TotalSeconds + 40 * 60, profile.Seconds);

            profiles = algorithm.GetStopProfiles(0);
            Assert.AreEqual(1, profiles.Count);
            profile = profiles[0];
            Assert.AreEqual(Itinero.Transit.Constants.NoConnectionId, profile.PreviousConnectionId);
            Assert.AreEqual((int)(departureTime - departureTime.Date).TotalSeconds, profile.Seconds);

            // build dummy transfers db.
            transfersDb = new TransfersDb(1024);
            transfersDb.AddTransfer(1, 2, 6 * 60); // this leads to a transfer time slower than the actual connection.

            // run algorithm.
            departureTime = new DateTime(2017, 05, 10, 07, 30, 00);
            algorithm     = new ProfileSearch(db, departureTime, transfersDb,
                                              (profileId, day) => true);
            algorithm.SetSourceStop(0, 07 * 3600 + 30 * 60);
            algorithm.SetTargetStop(3, 0);
            algorithm.Run();

            // test results.
            Assert.IsTrue(algorithm.HasRun);
            Assert.IsTrue(algorithm.HasSucceeded);

            // check arrival profile(s).
            arrivalStops = algorithm.ArrivalStops;
            Assert.AreEqual(3, arrivalStops.Count);
            Assert.AreEqual(3, arrivalStops[2]);
            arrivalProfiles = algorithm.ArrivalProfiles;
            Assert.AreEqual(3, arrivalProfiles.Count);
            Assert.AreEqual(08 * 3600 + 25 * 60, arrivalProfiles[2].Seconds);
            Assert.AreEqual(55 * 60, algorithm.Duration(2));
            Assert.AreEqual(new DateTime(2017, 05, 10, 08, 25, 00), algorithm.ArrivalTime(2));

            // check stop profiles.
            connections = db.GetConnectionsEnumerator(DefaultSorting.DepartureTime);
            profiles    = algorithm.GetStopProfiles(3);
            Assert.AreEqual(3, profiles.Count);
            profile = profiles[0];
            Assert.IsTrue(profile.IsEmpty);
            profile = profiles[1];
            Assert.IsTrue(profile.IsEmpty);
            profile = profiles[2];
            Assert.AreEqual(2, profile.PreviousConnectionId);
            Assert.AreEqual((int)(departureTime - departureTime.Date).TotalSeconds + 55 * 60, profile.Seconds);

            profiles = algorithm.GetStopProfiles(2);
            Assert.AreEqual(3, profiles.Count);
            profile = profiles[0];
            Assert.IsTrue(profile.IsEmpty);
            profile = profiles[1];
            Assert.IsTrue(profile.IsEmpty);
            profile = profiles[2];
            Assert.AreEqual(1, profile.PreviousConnectionId);
            Assert.AreEqual((int)(departureTime - departureTime.Date).TotalSeconds + 45 * 60, profile.Seconds);

            profiles = algorithm.GetStopProfiles(1);
            Assert.AreEqual(3, profiles.Count);
            profile = profiles[0];
            Assert.IsTrue(profile.IsEmpty);
            profile = profiles[1];
            Assert.IsTrue(profile.IsEmpty);
            profile = profiles[2];
            Assert.AreEqual(0, profile.PreviousConnectionId);
            Assert.AreEqual((int)(departureTime - departureTime.Date).TotalSeconds + 40 * 60, profile.Seconds);

            profiles = algorithm.GetStopProfiles(0);
            Assert.AreEqual(1, profiles.Count);
            profile = profiles[0];
            Assert.AreEqual(Itinero.Transit.Constants.NoConnectionId, profile.PreviousConnectionId);
            Assert.AreEqual((int)(departureTime - departureTime.Date).TotalSeconds, profile.Seconds);

            var tripStatus = algorithm.GetTripStatus(0);

            Assert.AreEqual(2, tripStatus.Transfers);
            Assert.AreEqual(0, tripStatus.StopId);
            Assert.AreEqual(08 * 3600 + 00 * 60, tripStatus.DepartureTime);
        }
Ejemplo n.º 2
0
        public void TestOneHopScheduled()
        {
            // build dummy db.
            var db       = new TransitDb();
            var schedule = db.AddSchedule();

            db.AddScheduleEntry(schedule, new DateTime(2017, 01, 01), new DateTime(2018, 01, 01),
                                DayOfWeek.Monday);
            db.AddStop(0, 0, 0);
            db.AddStop(1, 1, 1);
            db.AddTrip(schedule, 0, 0);
            db.AddConnection(0, 1, 0, 3600, 3600 + 40 * 60);
            db.SortConnections(DefaultSorting.DepartureTime, null);

            // run algorithm.
            var departureTime = new DateTime(2017, 05, 08, 00, 50, 00);
            var algorithm     = new ProfileSearch(db, departureTime,
                                                  db.GetIsTripPossibleFunc());

            algorithm.SetSourceStop(0, 50 * 60);
            algorithm.SetTargetStop(1, 0);
            algorithm.Run();

            // test results.
            Assert.IsTrue(algorithm.HasRun);
            Assert.IsTrue(algorithm.HasSucceeded);

            // check arrival profile(s).
            var arrivalStops = algorithm.ArrivalStops;

            Assert.AreEqual(3, arrivalStops.Count);
            Assert.AreEqual(1, arrivalStops[2]);
            var arrivalProfiles = algorithm.ArrivalProfiles;

            Assert.AreEqual(3, arrivalProfiles.Count);
            Assert.AreEqual(3600 * 01 + 40 * 60, arrivalProfiles[2].Seconds);
            Assert.AreEqual(50 * 60, algorithm.Duration(2));
            Assert.AreEqual(new DateTime(2017, 05, 08, 01, 40, 00), algorithm.ArrivalTime(2));

            // check stop profiles.
            var connections = db.GetConnectionsEnumerator(DefaultSorting.DepartureTime);
            var profiles    = algorithm.GetStopProfiles(1);
            var profile     = profiles[0];

            Assert.IsTrue(profile.IsEmpty);
            profile = profiles[1];
            Assert.IsTrue(profile.IsEmpty);
            profile = profiles[2];
            Assert.AreEqual(0, profile.PreviousConnectionId);
            Assert.AreEqual((int)(departureTime - departureTime.Date).TotalSeconds + 50 * 60, profile.Seconds);
            connections.MoveTo(profile.PreviousConnectionId);
            Assert.AreEqual(0, connections.TripId);
            Assert.AreEqual(0, connections.DepartureStop);
            profiles = algorithm.GetStopProfiles(0);
            profile  = profiles[0];
            Assert.AreEqual(Itinero.Transit.Constants.NoConnectionId, profile.PreviousConnectionId);
            Assert.AreEqual((int)(departureTime - departureTime.Date).TotalSeconds, profile.Seconds);

            var tripStatus = algorithm.GetTripStatus(0);

            Assert.AreEqual(2, tripStatus.Transfers);
            Assert.AreEqual(0, tripStatus.StopId);
            Assert.AreEqual(3600, tripStatus.DepartureTime);

            // run algorithm.
            departureTime = new DateTime(2017, 05, 10, 00, 50, 00);
            algorithm     = new ProfileSearch(db, departureTime,
                                              db.GetIsTripPossibleFunc());
            algorithm.SetSourceStop(0, 50 * 60);
            algorithm.SetTargetStop(1, 0);
            algorithm.Run();

            Assert.IsTrue(algorithm.HasRun);
            Assert.IsFalse(algorithm.HasSucceeded);
        }
Ejemplo n.º 3
0
        public void TestTwoHopsOneTransferVersusOneHopSuccessful()
        {
            // build dummy db.
            var db = new TransitDb();

            db.AddStop(0, 0, 0);
            db.AddStop(1, 1, 1);
            db.AddStop(2, 2, 2);
            db.AddTrip(0, 0, 0);
            db.AddTrip(0, 0, 0);
            db.AddTrip(0, 0, 0);
            db.AddConnection(0, 1, 0, 8 * 3600, 8 * 3600 + 10 * 60);
            db.AddConnection(1, 2, 1, 8 * 3600 + 15 * 60, 8 * 3600 + 25 * 60);
            db.AddConnection(0, 2, 2, 8 * 3600 + 16 * 60, 8 * 3600 + 25 * 60);

            db.SortConnections(DefaultSorting.DepartureTime, null);

            // run algorithm.
            var departureTime = new DateTime(2017, 05, 10, 07, 30, 00);
            var algorithm     = new ProfileSearch(db, departureTime,
                                                  (profileId, day) => true);

            algorithm.SetSourceStop(0, 07 * 3600 + 30 * 60);
            algorithm.SetTargetStop(2, 0);
            algorithm.Run();

            // test results.
            Assert.IsTrue(algorithm.HasRun);
            Assert.IsTrue(algorithm.HasSucceeded);

            // check arrival profile(s).
            var arrivalStops = algorithm.ArrivalStops;

            Assert.AreEqual(3, arrivalStops.Count);
            Assert.AreEqual(2, arrivalStops[2]);
            var arrivalProfiles = algorithm.ArrivalProfiles;

            Assert.AreEqual(3, arrivalProfiles.Count);
            Assert.AreEqual(08 * 3600 + 25 * 60, arrivalProfiles[2].Seconds);
            Assert.AreEqual(55 * 60, algorithm.Duration(2));
            Assert.AreEqual(new DateTime(2017, 05, 10, 08, 25, 00), algorithm.ArrivalTime(2));

            // check stop profiles.
            var connections   = db.GetConnectionsEnumerator(DefaultSorting.DepartureTime);
            var precedingStop = Itinero.Transit.Constants.NoStopId;
            var transfers     = Itinero.Transit.Constants.NoTransfers;

            // get profiles at stop 2.
            var profiles = algorithm.GetStopProfiles(2);
            var profile  = profiles[0];

            Assert.IsTrue(profile.IsEmpty);
            profile = profiles[1];
            Assert.IsTrue(profile.IsEmpty);
            profile = profiles[2];
            Assert.AreEqual(2, profile.PreviousConnectionId);
            Assert.AreEqual((int)(departureTime - departureTime.Date).TotalSeconds + 55 * 60, profile.Seconds);
            connections.MoveTo(profile.PreviousConnectionId);
            Assert.AreEqual(0, connections.DepartureStop);
            Assert.AreEqual(2, connections.TripId);

            // get previous profile and check this is stop 0.
            profile  = algorithm.GetPreceding(profiles, 2, out precedingStop, out transfers);
            profiles = algorithm.GetStopProfiles(0);
            profile  = profiles[0];
            Assert.AreEqual(Itinero.Transit.Constants.NoConnectionId, profile.PreviousConnectionId);
            Assert.AreEqual((int)(departureTime - departureTime.Date).TotalSeconds, profile.Seconds);

            // check the profiles at stop 1.
            profiles = algorithm.GetStopProfiles(1);
            profile  = profiles[0];
            Assert.IsTrue(profile.IsEmpty);
            profile = profiles[1];
            Assert.IsTrue(profile.IsEmpty);
            profile = profiles[2];
            Assert.AreEqual(0, profile.PreviousConnectionId);
            Assert.AreEqual((int)(departureTime - departureTime.Date).TotalSeconds + 40 * 60, profile.Seconds);
            connections.MoveTo(profile.PreviousConnectionId);
            Assert.AreEqual(0, connections.DepartureStop);
            Assert.AreEqual(0, connections.TripId);

            var tripStatus = algorithm.GetTripStatus(0);

            Assert.AreEqual(2, tripStatus.Transfers);
            Assert.AreEqual(0, tripStatus.StopId);
            Assert.AreEqual(08 * 3600 + 00 * 60, tripStatus.DepartureTime);

            tripStatus = algorithm.GetTripStatus(1);
            Assert.AreEqual(4, tripStatus.Transfers);
            Assert.AreEqual(1, tripStatus.StopId);
            Assert.AreEqual(08 * 3600 + 15 * 60, tripStatus.DepartureTime);

            tripStatus = algorithm.GetTripStatus(2);
            Assert.AreEqual(2, tripStatus.Transfers);
            Assert.AreEqual(0, tripStatus.StopId);
            Assert.AreEqual(08 * 3600 + 16 * 60, tripStatus.DepartureTime);
        }