/// <summary>
        /// Compute the utility of accessing the access station
        /// </summary>
        /// <param name="origin">The origin of the trip, flat</param>
        /// <param name="interchange">The access station, flat</param>
        /// <param name="weightedTravelTime"></param>
        /// <returns>The utility of picking the access station, NaN if it isn't possible</returns>
        private float ComputeAccessUtility(int origin, int interchange, out float weightedTravelTime)
        {
            float v = 0.0f;

            // figure out which data to use
            if (!PremiumTransitNetwork.GetAllData(origin, interchange, TimeOfDay, out Time ivtt, out Time walk, out Time wait, out Time boarding, out float cost) | ivtt <= Time.Zero)
            {
                if (!TransitNetwork.GetAllData(origin, interchange, TimeOfDay, out ivtt, out walk, out wait, out boarding, out cost) | walk <= Time.Zero)
                {
                    weightedTravelTime = float.NaN;
                    return(float.NaN);
                }
            }
            // once we have the data we can then compute the utility
            v += IvttFactor * ivtt.ToMinutes()
                 + WalkTimeFactor * walk.ToMinutes()
                 + WaitTimeFactor * wait.ToMinutes()
                 + BoardingFactor * boarding.ToMinutes()
                 + CostFactor * cost;
            // we can also compute the weighted travel time here in order to avoid additional lookups
            weightedTravelTime = ivtt.ToMinutes()
                                 + EgressWaitPerception * wait.ToMinutes()
                                 + EgressWalkPerception * walk.ToMinutes();
            return(v);
        }
        /// <summary>
        /// Computes the utility of a single interchange
        /// </summary>
        /// <param name="o">flat origin zone</param>
        /// <param name="d">flat destination zone</param>
        /// <param name="zones">an array of zones</param>
        /// <param name="interchange">the flat interchange zone to use</param>
        /// <param name="maxDistance">The maximum distance allowed</param>
        /// <param name="result">the utility of using this interchange</param>
        /// <param name="distanceByAuto">The distance the origin is from the interchange in auto travel time</param>
        /// <param name="parking"></param>
        /// <returns>True if this is a valid interchange zone, false if not feasible.</returns>
        private bool ComputeUtility(int o, int d, IZone[] zones, int interchange, float[] parking, float maxDistance,
                                    out float result, out float distanceByAuto)
        {
            result = float.NaN;
            Time  ivtt, walk, wait, boarding;
            float cost;
            float v = 0.0f;
            var   destinationDistance = AutoNetwork.TravelTime(o, d, TimeOfDay).ToMinutes();

            if (Access)
            {
                // distance is actually the travel time
                distanceByAuto = AutoNetwork.TravelTime(o, interchange, TimeOfDay).ToMinutes();
                // there is no need to continue if we have already found the max number of paths that are shorter
                // it also a valid choice to drive longer in order to use the access station compared to just going to the final destination.
                // we also are not feasible if there is no parking spots
                if (distanceByAuto >= maxDistance | destinationDistance < distanceByAuto | parking[interchange] <= 0)
                {
                    return(false);
                }
                // get the from interchange to destination costs (we need to include boarding here even though we don't actually use it in our utility function
                // making individual calls for the data would be more expensive

                if (!TransitNetwork.GetAllData(interchange, d, TimeOfDay, out ivtt, out walk, out wait, out boarding, out cost) | ivtt <= Time.Zero | walk <= Time.Zero)
                {
                    return(false);
                }
            }
            else
            {
                // This will be executed if we want to run the EGRESS model

                // distance is actually the travel time from the station we get off at to our destination
                distanceByAuto = AutoNetwork.TravelTime(interchange, d, TimeOfDay).ToMinutes();
                // make sure we clip properly
                if (distanceByAuto >= maxDistance | destinationDistance < distanceByAuto | parking[interchange] <= 0)
                {
                    return(false);
                }
                // in egress the transit trip is actually before the drive, so origin to the interchange is transit
                if (!TransitNetwork.GetAllData(o, interchange, TimeOfDay, out ivtt, out walk, out wait, out boarding, out cost) | ivtt <= Time.Zero | walk <= Time.Zero)
                {
                    return(false);
                }
            }
            v += IvttFactor * ivtt.ToMinutes()
                 + WaitTimeFactor * wait.ToMinutes()
                 + WalkTimeFactor * walk.ToMinutes()
                 + BoardingFactor * boarding.ToMinutes();
            v += AutoTimeFactor * distanceByAuto;
            v += AutoCostFactor * AutoNetwork.TravelCost(o, interchange, TimeOfDay);
            v += ParkingFactor * (float)Math.Log(parking[interchange]);
            v += ParkingCostFactor * zones[interchange].ParkingCost;
            // Now add in the origin to interchange zone utilities
            result = v;
            return(true);
        }
Example #3
0
 /// <summary>
 /// Computes the weighted travel time between two points.
 /// This method does not include the line hull time!
 /// </summary>
 /// <param name="origin">The zone to start from, flat space</param>
 /// <param name="destination">The zone to end at, flat space</param>
 /// <returns>The weighted travel time from egress station to destination</returns>
 private float ComputeWeightedTimeWithoutRail(int origin, int destination)
 {
     if (!TransitNetwork.GetAllData(origin, destination, TimeOfDay, out Time ivtt, out Time walk, out Time wait, out Time boardings, out float cost) | walk <= Time.Zero)
     {
         return(float.NaN);
     }
     return(ivtt.ToMinutes()
            + EgressWaitPerception * wait.ToMinutes()
            + EgressWalkPerception * walk.ToMinutes());
 }
Example #4
0
        /// <summary>
        /// Computes and stores the mode split for a zone going to Pearson.
        /// This will also compute the logsum for each zone.
        /// </summary>
        /// <param name="zone">The flat indexed zone to compute for</param>
        /// <param name="utilities">The array to store the results in</param>
        private void ComputeModeSplitForZone(int zone, ModeSplitUtilities[] utilities)
        {
            // first we need to get the data from the network
            float aivtt, acost, tivtt, twalk, twait, _railTime, tfare;

            AutoNetwork.GetAllData(zone, PearsonFlatZoneNumber, TimeOfDay, out aivtt, out acost);
            bool transit = TransitNetwork.GetAllData(zone, PearsonFlatZoneNumber, TimeOfDay, out tivtt, out twalk, out twait, out _railTime, out tfare);

            // Second compute the utilities for each mode
            utilities[zone].Auto = (float)Math.Exp(BetaAutoTime * aivtt + BetaAutoCost * acost);
            if (transit && (tivtt > 0 | twalk > 0))
            {
                utilities[zone].Transit = (float)Math.Exp(BetaTransitConstant + BetaTransitTime * (tivtt + twalk + twait) + BetaTransitFare * tfare);
                var total = utilities[zone].Auto + utilities[zone].Transit;
                utilities[zone].Logsum   = (float)Math.Log(total);
                utilities[zone].Auto    /= total;
                utilities[zone].Transit /= total;
            }
            else
            {
                utilities[zone].Logsum  = (float)Math.Log(utilities[zone].Auto);
                utilities[zone].Auto   /= 1f;
                utilities[zone].Transit = 0f;
            }
        }
        /// <summary>
        /// Calculate the utility between two zones
        /// </summary>
        /// <param name="pdD"></param>
        /// <param name="zoneO">The flat origin index</param>
        /// <param name="pdO"></param>
        /// <param name="zoneD"></param>
        /// <param name="workerIndex"></param>
        /// <returns>The utility between the two zones.</returns>
        private float CalculateUtilityToE(int pdO, int pdD, int zoneO, int zoneD, int workerIndex)
        {
            var segment = GetSegment(pdO, pdD);

            if (segment == null)
            {
                return(0);
            }
            // Worker Categories:
            // 0 = No Car / No License
            // 1 = Less cars than people with licenses
            // 2 = More or equal cars to persons with licenses
            float perceivedTime = AutoNetwork.TravelTime(zoneO, zoneD, TimeOfDay).ToMinutes();
            var   utility       = Math.Exp((workerIndex == 0 ? segment.PassengerTime : segment.AutoTime) * perceivedTime +
                                           (workerIndex == 2 ? segment.SaturatedVehicles : 0));

            // transit
            TransitNetwork.GetAllData(zoneO, zoneD, TimeOfDay, out float trueTime, out float walk, out float wait, out perceivedTime, out float cost);
            if (perceivedTime > 0)
            {
                utility += Math.Exp(segment.TransitTime * perceivedTime + segment.TransitConstant);
            }
            var constants = segment.ExpSegmentConstant;

            if (zoneO == zoneD)
            {
                constants *= segment.ExpIntrazonalConstant;
            }
            if (pdO == pdD)
            {
                constants *= segment.ExpIntraPDConstant;
            }
            return((float)(utility * constants));
        }
Example #6
0
 private static float ComputeSubV(ITripComponentData data, int flatOrigin, int flatDestination, Time t, float ivttWeight, float walkWeight, float waitWeight, float boardingWeight, float costWeight)
 {
     data.GetAllData(flatOrigin, flatDestination, t, out float ivtt, out float walk, out float wait, out float boarding, out float cost);
     return(ivttWeight * ivtt
            + walkWeight * walk
            + waitWeight * wait
            + boardingWeight * boarding
            + costWeight * cost);
 }
 private static float ComputeV(ITripComponentData data, int egress, int destination, Time time, float ivttWeight, float walkWeight, float waitWeight, float boardingWeight, float costWeight)
 {
     data.GetAllData(egress, destination, time, out Time ivtt, out Time walk, out Time wait, out Time boarding, out float cost);
     return(ivttWeight * ivtt.ToMinutes()
            + walkWeight * walk.ToMinutes()
            + waitWeight * wait.ToMinutes()
            + boardingWeight * boarding.ToMinutes()
            + costWeight * cost);
 }
Example #8
0
 private float ComputeUtility(ITripComponentData transitNetwork, int originIndex, int destIndex)
 {
     if (transitNetwork.GetAllData(originIndex, destIndex, StartTime, out float trueTravelTime, out float walk, out float wait, out float perceivedTravelTime, out float cost) && (perceivedTravelTime > 0))
     {
         return(PerceivedTransitTime * perceivedTravelTime
                + TransitFare * cost);
     }
     return(float.NegativeInfinity);
 }
Example #9
0
        private static float ComputeSubV(ITripComponentData data, int flatOrigin, int flatDestination, Time t, float ivttWeight, float walkWeight, float waitWeight, float costWeight)
        {
            Time  ivtt, walk, wait, boarding;
            float cost;

            data.GetAllData(flatOrigin, flatDestination, t, out ivtt, out walk, out wait, out boarding, out cost);
            return(ivttWeight * ivtt.ToMinutes()
                   + walkWeight * walk.ToMinutes()
                   + waitWeight * wait.ToMinutes()
                   + costWeight * cost);
        }
Example #10
0
 private float ComputeUtility(ITripComponentData transitNetwork, int originIndex, int destIndex)
 {
     if (transitNetwork.GetAllData(originIndex, destIndex, StartTime, out float ivtt, out float walk, out float wait, out float boardingPenalty, out float cost) && (boardingPenalty > 0))
     {
         return(TIVTT * ivtt
                + Boarding * boardingPenalty
                + TWALK * walk
                + TWAIT * wait
                + TransitFare * cost);
     }
     return(float.NegativeInfinity);
 }
Example #11
0
 internal bool GetEgressUtility(int flatEgressZone, int flatDestinationZone, Time time, out float egressUtility)
 {
     // Make sure that we can get from the egress station to the destination zone at that current point in the day
     if (!Third.ValidOd(flatEgressZone, flatDestinationZone, time))
     {
         egressUtility = float.MinValue;
         return(false);
     }
     Third.GetAllData(flatEgressZone, flatDestinationZone, time, out Time ivtt, out Time walk, out Time wait, out Time boarding, out float cost);
     egressUtility = ivtt.ToMinutes() + EgressWaitFactor * wait.ToMinutes() + EgressWalkFactor * walk.ToMinutes();
     return(egressUtility != float.MaxValue);
 }
Example #12
0
 public override float CalculateV(IZone origin, IZone destination, Time time)
 {
     if (IsContained(origin, destination))
     {
         if (NetworkData.GetAllData(origin, destination, time, out Time ivtt, out Time walkTime, out Time waitTime, out Time boarding, out float cost))
         {
             return(IVTT * ivtt.ToMinutes() + Wait * waitTime.ToMinutes()
                    + Walk * walkTime.ToMinutes() + Boarding * boarding.ToMinutes() + Cost * cost);
         }
     }
     return(0f);
 }
Example #13
0
 private static bool ComputeThird(ITripComponentData data, int flatOrigin, int flatDestination, Time t, float walkTime, float waitTime, out float result)
 {
     data.GetAllData(flatOrigin, flatDestination, t, out float ivtt, out float walk, out float wait, out float boarding, out float cost);
     if (walk <= 0)
     {
         result = float.PositiveInfinity;
         return(false);
     }
     result = walk * walkTime
              + wait * waitTime
              + ivtt;
     return(true);
 }
Example #14
0
        public virtual float CalculateV(IZone originZone, IZone destinationZone, Time time)
        {
            var zoneArray   = Root.ZoneSystem.ZoneArray;
            var origin      = zoneArray.GetFlatIndex(originZone.ZoneNumber);
            var destination = zoneArray.GetFlatIndex(destinationZone.ZoneNumber);
            // initialize to the combined constant value for the mode
            float v = Constant + PartTime + NoDriversLicense + SingleVehicleHousehold + MultipleVehicleHousehold
                      + AgeConstant1 + AgeConstant2 + AgeConstant3 + AgeConstant4
                      + Parking * destinationZone.ParkingCost
                      + GetDensityV(originZone, destinationZone);
            // if we need to calculate distance
            var zoneDistance = Root.ZoneSystem.Distances.GetFlatData()[origin][destination];

            // if the trip is smaller than the short distance
            if (zoneDistance <= ShortDistance)
            {
                v += ShortDistanceConstant;
            }

            v += Distance * (zoneDistance / 1000f);
            // check what kind of network data we are working with to see if we can use subcomponents
            if (AdvancedNetworkData == null)
            {
                NetworkData.GetAllData(origin, destination, time, out float ivtt, out float cost);
                v += IVTT * ivtt + TravelCost * cost;
            }
            else
            {
                AdvancedNetworkData.GetAllData(origin, destination, time, out float ivtt, out float walk, out float wait, out float boarding, out float cost);
                v += IVTT * ivtt
                     + Walk * walk
                     + ((walk > 0) & (ivtt <= 0) ? AdjacentZone : 0f)
                     + Wait * wait
                     + Boarding * boarding
                     + TravelCost * cost;
            }
            return(v);
        }
Example #15
0
        private static bool ComputeThird(ITripComponentData data, int flatOrigin, int flatDestination, Time t, float walkTime, float waitTime, out float result)
        {
            data.GetAllData(flatOrigin, flatDestination, t, out Time ivtt, out Time walk, out Time wait, out Time boarding, out float cost);
            var timeWalkingInMinutes = walk.ToMinutes();

            if (timeWalkingInMinutes <= 0)
            {
                result = float.PositiveInfinity;
                return(false);
            }
            result = timeWalkingInMinutes * walkTime
                     + wait.ToMinutes() * waitTime
                     + ivtt.ToMinutes();
            return(true);
        }
Example #16
0
        public double CalculateV(ITrip trip)
        {
            // compute the non human factors
            IZone originalZone    = trip.OriginalZone;
            var   o               = ZoneArray.GetFlatIndex(originalZone.ZoneNumber);
            IZone destinationZone = trip.DestinationZone;
            var   d               = ZoneArray.GetFlatIndex(destinationZone.ZoneNumber);
            var   p               = trip.TripChain.Person;

            GetPersonVariables(p, out float constant, out float perceivedTimeFactor, out float costFactor);
            float v = constant;

            if (Network.GetAllData(o, d, trip.TripStartTime, out float ivtt, out float walk, out float wait, out float perceivedTime, out float cost))
            {
                v += perceivedTime * perceivedTimeFactor
                     + cost * costFactor;
            }
Example #17
0
        public double CalculateV(ITrip trip)
        {
            // compute the non human factors
            IZone originalZone = trip.OriginalZone;
            var   o = ZoneArray.GetFlatIndex(originalZone.ZoneNumber);
            IZone destinationZone = trip.DestinationZone;
            var   d = ZoneArray.GetFlatIndex(destinationZone.ZoneNumber);
            var   p = trip.TripChain.Person;
            float perceivedTimeFactor, constant, costFactor;

            GetPersonVariables(p, out constant, out perceivedTimeFactor, out costFactor);
            float v = constant;
            // if Intrazonal
            float ivtt, walk, wait, perceivedTime, cost;

            if (Network.GetAllData(o, d, trip.TripStartTime, out ivtt, out walk, out wait, out perceivedTime, out cost))
            {
                v += perceivedTime * perceivedTimeFactor
                     + cost * costFactor;
            }
            else
            {
                return(float.NegativeInfinity);
            }
            //Apply trip purpose factors
            switch (trip.Purpose)
            {
            case Activity.Market:
                v += MarketFlag + ZonalDensityForActivitiesArray[d];
                break;

            case Activity.IndividualOther:
                v += OtherFlag + ZonalDensityForActivitiesArray[d];
                break;

            case Activity.Home:
                v += ZonalDensityForHomeArray[d];
                break;

            default:
                v += ZonalDensityForActivitiesArray[d];
                break;
            }
            v += GetPlanningDistrictConstant(trip.TripStartTime, originalZone.PlanningDistrict, destinationZone.PlanningDistrict);
            return((double)v);
        }
Example #18
0
        private static bool ComputeThird(ITripComponentData data, int flatOrigin, int flatDestination, Time t, float WalkTime, float WaitTime, out float result)
        {
            Time  ivtt, walk, wait, boarding;
            float cost;

            data.GetAllData(flatOrigin, flatDestination, t, out ivtt, out walk, out wait, out boarding, out cost);
            var walkTime = walk.ToMinutes();

            if (walkTime <= 0)
            {
                result = float.PositiveInfinity;
                return(false);
            }
            result = walkTime * WalkTime
                     + wait.ToMinutes() * WaitTime
                     + ivtt.ToMinutes();
            return(true);
        }
Example #19
0
        public double CalculateV(ITrip trip)
        {
            // compute the non human factors
            var   zoneSystem      = Root.ZoneSystem;
            var   zoneArray       = zoneSystem.ZoneArray;
            IZone originalZone    = trip.OriginalZone;
            var   o               = zoneArray.GetFlatIndex(originalZone.ZoneNumber);
            IZone destinationZone = trip.DestinationZone;
            var   d               = zoneArray.GetFlatIndex(destinationZone.ZoneNumber);
            var   p               = trip.TripChain.Person;

            GetPersonVariables(p, out float constant, out float timeFactor, out float walkBeta, out float waitBeta, out float boardingBeta, out float costFactor);
            float v = constant;

            // if Intrazonal
            if (o == d)
            {
                v += IntrazonalConstant;
                v += IntrazonalTripDistanceFactor * zoneSystem.Distances.GetFlatData()[o][d] * 0.001f;
            }
            else
            {
                // if not intrazonal
                if (originalZone.RegionNumber != destinationZone.RegionNumber)
                {
                    v += InterRegionalTrip;
                }

                if (Network.GetAllData(o, d, trip.TripStartTime, out float ivtt, out float walk, out float wait, out float boarding, out float cost))
                {
                    if (ivtt <= 0)
                    {
                        v += NoTIVTTPenalty;
                    }
                    v += ivtt * timeFactor
                         + walk * walkBeta
                         + wait * waitBeta
                         + boarding * boardingBeta
                         + cost * costFactor;
                }
Example #20
0
        public bool Feasible(IZone originZone, IZone destinationZone, Time time)
        {
            var zoneArray   = this.Root.ZoneSystem.ZoneArray;
            var origin      = zoneArray.GetFlatIndex(originZone.ZoneNumber);
            var destination = zoneArray.GetFlatIndex(destinationZone.ZoneNumber);

            if (CurrentlyFeasible <= 0)
            {
                return(false);
            }
            if (AdvancedNetworkData == null)
            {
                return(this.NetworkData.ValidOD(origin, destination, time) && (!this.CheckPositiveIVTT || this.NetworkData.TravelTime(origin, destination, time).ToMinutes() > 0));
            }
            else
            {
                float ivtt, walk, wait, boarding, cost;
                AdvancedNetworkData.GetAllData(origin, destination, time, out ivtt, out walk, out wait, out boarding, out cost);
                return(this.AdvancedNetworkData.ValidOD(origin, destination, time) &&
                       ((!this.CheckPositiveIVTT || ivtt > 0)) &&
                       ((!this.CheckPositiveWalk || walk > 0)));
            }
        }
Example #21
0
 private static float ComputeV(ITripComponentData data, int egress, int destination, Time time, float ivttWeight, float walkWeight, float waitWeight, float boardingWeight, float costWeight)
 {
     Time ivtt, walk, wait, boarding;
     float cost;
     data.GetAllData( egress, destination, time, out ivtt, out walk, out wait, out boarding, out cost );
     return ivttWeight * ivtt.ToMinutes()
         + walkWeight * walk.ToMinutes()
         + waitWeight * wait.ToMinutes()
         + boardingWeight * boarding.ToMinutes()
         + costWeight * cost;
 }
Example #22
0
 private double GetTransitUtility(ITripComponentData network, int i, int j, Time time)
 {
     float ivtt, walk, wait, cost, boarding;
     if(!network.GetAllData(i, j, time, out ivtt, out walk, out wait, out boarding, out cost))
     {
         return 0f;
     }
     return Math.Exp(
           TransitTime * ivtt
         + TransitWalk * walk
         + TransitWait * wait
         + Cost * cost);
 }
Example #23
0
 private static bool ComputeThird(ITripComponentData data, int flatOrigin, int flatDestination, Time t, float walkTime, float waitTime, out float result)
 {
     float ivtt, walk, wait, boarding;
     float cost;
     data.GetAllData( flatOrigin, flatDestination, t, out ivtt, out walk, out wait, out boarding, out cost );
     if ( walk <= 0 )
     {
         result = float.PositiveInfinity;
         return false;
     }
     result = walk * walkTime
             + wait * waitTime
             + ivtt;
     return true;
 }
Example #24
0
 private static float ComputeSubV(ITripComponentData data, int flatOrigin, int flatDestination, Time t, float ivttWeight, float walkWeight, float waitWeight, float boardingWeight, float costWeight)
 {
     float ivtt, walk, wait, boarding;
     float cost;
     data.GetAllData( flatOrigin, flatDestination, t, out ivtt, out walk, out wait, out boarding, out cost );
     return ivttWeight * ivtt
         + walkWeight * walk
         + waitWeight * wait
         + boardingWeight * boarding
         + costWeight * cost;
 }
Example #25
0
        public double CalculateV(ITrip trip)
        {
            // compute the non human factors
            var   zoneSystem = Root.ZoneSystem;
            var   zoneArray = zoneSystem.ZoneArray;
            IZone originalZone = trip.OriginalZone;
            var   o = zoneArray.GetFlatIndex(originalZone.ZoneNumber);
            IZone destinationZone = trip.DestinationZone;
            var   d = zoneArray.GetFlatIndex(destinationZone.ZoneNumber);
            var   p = trip.TripChain.Person;
            float timeFactor, constant, costFactor, walkBeta, waitBeta, boardingBeta;

            GetPersonVariables(p, out constant, out timeFactor, out walkBeta, out waitBeta, out boardingBeta, out costFactor);
            float v = constant;

            // if Intrazonal
            if (o == d)
            {
                v += IntrazonalConstant;
                v += IntrazonalTripDistanceFactor * zoneSystem.Distances.GetFlatData()[o][d] * 0.001f;
            }
            else
            {
                // if not intrazonal
                if (originalZone.RegionNumber != destinationZone.RegionNumber)
                {
                    v += InterRegionalTrip;
                }
                float ivtt, walk, wait, boarding, cost;
                if (Network.GetAllData(o, d, trip.TripStartTime, out ivtt, out walk, out wait, out boarding, out cost))
                {
                    if (ivtt <= 0)
                    {
                        v += NoTIVTTPenalty;
                    }
                    v += ivtt * timeFactor
                         + walk * walkBeta
                         + wait * waitBeta
                         + boarding * boardingBeta
                         + cost * costFactor;
                }
                else
                {
                    return(float.NegativeInfinity);
                }
            }
            //Apply trip purpose factors
            switch (trip.Purpose)
            {
            case Activity.Market:
                v += MarketFlag + ZonalDensityForActivitiesArray[d];
                break;

            case Activity.IndividualOther:
                v += OtherFlag + ZonalDensityForActivitiesArray[d];
                break;

            case Activity.Home:
                v += ZonalDensityForHomeArray[d];
                break;

            default:
                v += ZonalDensityForActivitiesArray[d];
                break;
            }
            v += GetPlanningDistrictConstant(trip.TripStartTime, originalZone.PlanningDistrict, destinationZone.PlanningDistrict);
            return((double)v);
        }
Example #26
0
        private bool BuildUtility(IZone firstOrigin, IZone secondOrigin, Pair <IZone[], float[]> accessData, IZone firstDestination, IZone secondDestination,
                                  ITashaPerson person, Time firstTime, Time secondTime, out float dependentUtility)
        {
            var   zones = accessData.First;
            var   utils = accessData.Second;
            var   totalUtil = 0.0f;
            float ivttBeta, costBeta, constant;

            GetPersonVariables(person, out constant, out ivttBeta, out costBeta);
            totalUtil = VectorHelper.Sum(utils, 0, utils.Length);
            if (totalUtil <= 0)
            {
                dependentUtility = float.NaN;
                return(false);
            }
            dependentUtility = GetPlanningDistrictConstant(firstTime, firstOrigin.PlanningDistrict, firstDestination.PlanningDistrict)
                               + GetPlanningDistrictConstant(secondTime, secondOrigin.PlanningDistrict, secondDestination.PlanningDistrict);
            totalUtil = 1 / totalUtil;
            // we still need to do this in order to reduce time for computing the selected access station
            VectorHelper.Multiply(utils, 0, utils, 0, totalUtil, utils.Length);
            var zoneSystem = Root.ZoneSystem.ZoneArray;
            var fo         = zoneSystem.GetFlatIndex(firstOrigin.ZoneNumber);
            var so         = zoneSystem.GetFlatIndex(secondOrigin.ZoneNumber);
            var fd         = zoneSystem.GetFlatIndex(firstDestination.ZoneNumber);
            var sd         = zoneSystem.GetFlatIndex(secondDestination.ZoneNumber);

            totalUtil = 0;
            var fastTransit        = TransitNetwork as ITripComponentCompleteData;
            var fastAuto           = AutoNetwork as INetworkCompleteData;
            var stationIndexLookup = StationIndexLookup;

            if (stationIndexLookup == null)
            {
                stationIndexLookup = CreateStationIndexLookup(zoneSystem, zones);
            }
            if (fastTransit == null | fastAuto == null)
            {
                for (int i = 0; i < utils.Length; i++)
                {
                    var stationIndex = StationIndexLookup[i];
                    var probability  = utils[i];
                    if (probability > 0)
                    {
                        var   local = 0.0f;
                        float perceivedTime, cost, twalk, twait, trueTime;
                        TransitNetwork.GetAllData(stationIndex, fd, firstTime, out trueTime, out twalk, out twait, out perceivedTime, out cost);
                        local += perceivedTime * ivttBeta + cost * costBeta;
                        TransitNetwork.GetAllData(stationIndex, so, secondTime, out perceivedTime, out twalk, out twait, out perceivedTime, out cost);
                        local += perceivedTime * ivttBeta + cost * costBeta;
                        AutoNetwork.GetAllData(fo, stationIndex, firstTime, out perceivedTime, out cost);
                        local += perceivedTime * ivttBeta + costBeta * cost;
                        AutoNetwork.GetAllData(stationIndex, sd, secondTime, out perceivedTime, out cost);
                        local     += perceivedTime * ivttBeta + costBeta * cost;
                        totalUtil += local * probability;
                    }
                }
            }
            else
            {
                int numberOfZones = zoneSystem.GetFlatData().Length;
                // fo, and so are constant across stations, so we can pull that part of the computation out
                fo = fo * numberOfZones;
                so = so * numberOfZones;
                float[] firstAutoMatrix     = fastAuto.GetTimePeriodData(firstTime);
                float[] firstTransitMatrix  = fastTransit.GetTimePeriodData(firstTime);
                float[] secondAutoMatrix    = fastAuto.GetTimePeriodData(secondTime);
                float[] secondTransitMatrix = fastTransit.GetTimePeriodData(secondTime);
                if (firstTransitMatrix == null || secondTransitMatrix == null)
                {
                    dependentUtility = float.NaN;
                    return(false);
                }
                for (int i = 0; i < utils.Length; i++)
                {
                    var stationIndex          = stationIndexLookup[i];
                    int origin1ToStation      = (fo + stationIndex) << 1;
                    int stationToDestination1 = ((stationIndex * numberOfZones) + fd) * 5;
                    int origin2ToStation      = (so + stationIndex) * 5;
                    int stationToDestination2 = ((stationIndex * numberOfZones) + sd) << 1;
                    if (utils[i] > 0)
                    {
                        // transit utility
                        var tivtt   = firstTransitMatrix[stationToDestination1] + secondTransitMatrix[origin2ToStation];
                        var tcost   = firstTransitMatrix[stationToDestination1 + 3] + secondTransitMatrix[origin2ToStation + 3];
                        var aivtt   = firstAutoMatrix[origin1ToStation] + secondAutoMatrix[stationToDestination2];
                        var acost   = firstAutoMatrix[origin1ToStation + 1] + secondAutoMatrix[stationToDestination2 + 1];
                        var utility = (tivtt + aivtt) * ivttBeta + (acost + tcost) * costBeta;
                        totalUtil += utility * utils[i];
                    }
                }
            }
            dependentUtility += totalUtil;
            return(true);
        }
Example #27
0
 private float ComputeUtility(ITripComponentData transitNetwork, int originIndex, int destIndex)
 {
     float ivtt, walk, wait, boardingPenalty, cost;
     if(transitNetwork.GetAllData(originIndex, destIndex, StartTime, out ivtt, out walk, out wait, out boardingPenalty, out cost) && (boardingPenalty > 0))
     {
         return TIVTT * ivtt
             + Boarding * boardingPenalty
             + TWALK * walk
             + TWAIT * wait
             + TransitFare * cost;
     }
     return float.NegativeInfinity;
 }
 private float ComputeUtility(ITripComponentData transitNetwork, int originIndex, int destIndex)
 {
     float trueTravelTime, walk, wait, perceivedTravelTime, cost;
     if (transitNetwork.GetAllData(originIndex, destIndex, StartTime, out trueTravelTime, out walk, out wait, out perceivedTravelTime, out cost) && (perceivedTravelTime > 0))
     {
         return PerceivedTransitTime * perceivedTravelTime
             + TransitFare * cost;
     }
     return float.NegativeInfinity;
 }