示例#1
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);
        }