Exemplo n.º 1
0
 /// <summary>
 /// Get how long it takes to go somewhere
 /// </summary>
 /// <param name="person"></param>
 /// <param name="origin"></param>
 /// <param name="destination"></param>
 /// <param name="tashaTime"></param>
 /// <returns></returns>
 public Time TravelTime(ITashaPerson person, IZone origin, IZone destination, Time tashaTime)
 {
     if (AlternativeTravelMode == null || TashaRuntime.AutoType.CanUse(person))
     {
         return(TashaRuntime.AutoMode.TravelTime(origin, destination, tashaTime));
     }
     return(AlternativeTravelMode.TravelTime(origin, destination, tashaTime));
 }
Exemplo n.º 2
0
        /// <summary>
        /// Calculating if an egress trip is feasible
        /// Assuming the go access Calculate V was called before this function
        /// </summary>
        /// <param name="trip">the trip</param>
        /// <returns>is this trip feasible?</returns>
        public bool Feasible(ITrip trip)
        {
            if (!trip.TripChain.Person.Licence || trip.TripChain.Person.Household.Vehicles.Length == 0)
            {
                return(false);
            }

            if (trip.OriginalZone.Distance(trip.DestinationZone) < GOData.MinDistance)
            {
                return(false);
            }

            int[] accessStations = GOData.GetClosestStations(trip.OriginalZone.ZoneNumber);
            int   accessStation  = -1;
            int   egressStation  = LatestAccessStation(trip.TripChain, trip, out ITrip accessTrip);

            if (egressStation == -1)
            {
                return(false);                       //there was no access prior to this egress
            }
            Time time = Time.Zero;

            foreach (int station in accessStations)
            {
                if ((time = new Time(GOData.GetTransitAccessTime(trip.OriginalZone.ZoneNumber, station))) > Time.Zero)
                {
                    accessStation = station;
                }
            }

            if ((accessStation == -1))
            {
                if (Walking == null)
                {
                    return(false);
                }
                else
                {
                    foreach (var station in accessStations)
                    {
                        ITransitStation transitStation = GOData.GetStation(station);

                        if (transitStation.ClosestZone == -1)
                        {
                            continue;
                        }

                        ITrip intermediateTrip = TashaRuntime.CreateTrip(trip.TripChain, trip.OriginalZone, TashaRuntime.ZoneSystem.Get(transitStation.ClosestZone), Activity.Intermediate,
                                                                         trip.ActivityStartTime);

                        if (Walking.Feasible(intermediateTrip))
                        {
                            time = Walking.TravelTime(intermediateTrip.OriginalZone,
                                                      intermediateTrip.DestinationZone,
                                                      intermediateTrip.ActivityStartTime);

                            trip.Attach("Walking", intermediateTrip);

                            accessStation = station;

                            //found a walking trip no need to look further
                            break;
                        }
                    }
                }
            }

            if (time == Time.Zero)
            {
                return(false);
            }

            Time duration = time;

            //if there was an access before this egress
            if (egressStation == accessStation
                // ReSharper disable once CompareOfFloatsByEqualityOperator
                || GOData.GetGoFrequency(accessStation, egressStation, trip.ActivityStartTime.ToFloat()) == 0 ||
                duration + trip.ActivityStartTime < new Time(GOData.StartTime) ||
                duration + trip.ActivityStartTime > new Time(GOData.EndTime)
                )
            {
                return(false);
            }

            return(true);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Calculating if an egress trip is feasible
        /// Assuming the go access Calculate V was called before this function
        /// </summary>
        /// <param name="trip">the trip</param>
        /// <returns>is this trip feasible?</returns>
        public bool Feasible(ITrip trip)
        {
            if (!trip.TripChain.Person.Licence || trip.TripChain.Person.Household.Vehicles.Length == 0)
            {
                return(false);
            }

            if (trip.OriginalZone.Distance(trip.DestinationZone) < goData.MinDistance)
            {
                return(false);
            }

            int[] accessStations = goData.GetClosestStations(trip.OriginalZone.ZoneNumber);
            int   accessStation  = -1;
            ITrip accessTrip;
            int   egressStation = LatestAccessStation(trip.TripChain, trip, out accessTrip);

            if (egressStation == -1)
            {
                return(false);                       //there was no access prior to this egress
            }
            Time time = Time.Zero;

            foreach (int station in accessStations)
            {
                if ((time = new Time(goData.GetTransitAccessTime(trip.OriginalZone.ZoneNumber, station))) > Time.Zero)
                {
                    accessStation = station;
                }
            }

            if ((accessStation == -1) & (Walking == null))
            {
                return(false);
            }
            if (accessStation == -1)
            {
                //No Feasible access station by Transit so attempt walk trip

                //no feasible accessStation when going by transit, try walking
                foreach (var station in accessStations)
                {
                    ITransitStation transitStation = goData.GetStation(station);

                    if (transitStation.ClosestZone == -1)
                    {
                        continue;
                    }

                    ITrip intermediateTrip = this.TashaRuntime.CreateTrip(trip.TripChain, trip.OriginalZone, this.TashaRuntime.ZoneSystem.Get(transitStation.ClosestZone), Activity.Intermediate,
                                                                          trip.ActivityStartTime);

                    if (Walking.Feasible(intermediateTrip))
                    {
                        time = Walking.TravelTime(intermediateTrip.OriginalZone,
                                                  intermediateTrip.DestinationZone,
                                                  intermediateTrip.ActivityStartTime);

                        trip.Attach("Walking", intermediateTrip);

                        accessStation = station;

                        //found a walking trip no need to look further
                        break;
                    }
                }
            }

            if (time == Time.Zero)
            {
                return(false);
            }

            Time duration = time;

            //if there was an access before this egress
            if (egressStation == accessStation ||
                goData.GetGoFrequency(accessStation, egressStation, trip.ActivityStartTime.ToFloat()) == 0 ||
                duration + trip.ActivityStartTime < new Time(this.goData.StartTime) ||
                duration + trip.ActivityStartTime > new Time(this.goData.EndTime)
                )
            {
                return(false);
            }

            return(true);
        }