Esempio n. 1
0
        public void TestOneHop()
        {
            // build dummy db.
            var db = new TransitDb();

            db.AddStop(0, 0, 0);
            db.AddStop(1, 1, 1);
            db.AddTrip(0, 0, 0);
            db.AddConnection(0, 1, 0, 3600, 3600 + 40 * 60);
            db.SortConnections(DefaultSorting.DepartureTime, null);

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

            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, 10, 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);
        }
Esempio n. 2
0
        public void TestTwoHopsOneTransferCloseStopsSuccessful()
        {
            // 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.AddConnection(0, 1, 0, 8 * 3600, 8 * 3600 + 10 * 60);
            db.AddConnection(2, 3, 1, 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, 100);

            // 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(5, arrivalStops.Count);
            Assert.AreEqual(3, arrivalStops[4]);
            var arrivalProfiles = algorithm.ArrivalProfiles;

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

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

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

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

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

            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(08 * 3600 + 00 * 60, tripStatus.DepartureTime);

            tripStatus = algorithm.GetTripStatus(1);
            Assert.AreEqual(4, tripStatus.Transfers);
            Assert.AreEqual(2, tripStatus.StopId);
            Assert.AreEqual(08 * 3600 + 15 * 60, tripStatus.DepartureTime);
        }
Esempio 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);
        }