Example #1
0
            private float ComputeUtility(INetworkData autoNetwork, int originIndex, int destinationIndex)
            {
                float aivtt, cost;

                autoNetwork.GetAllData(originIndex, destinationIndex, StartTime, out aivtt, out cost);
                return(AIVTT * aivtt + AutoCost * cost);
            }
Example #2
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;
            }
        }
Example #3
0
        public double CalculateV(ITrip trip)
        {
            // compute the non human factors
            var zoneSystem = Root.ZoneSystem;
            var zoneArray  = zoneSystem.ZoneArray;
            var o          = zoneArray.GetFlatIndex(trip.OriginalZone.ZoneNumber);
            var d          = zoneArray.GetFlatIndex(trip.DestinationZone.ZoneNumber);
            var chain      = trip.TripChain;
            var p          = chain.Person;

            GetPersonVariables(p, out float timeFactor, out float constant, out float costParameter);
            float v = constant;

            // if Intrazonal
            if (o == d)
            {
                v += IntrazonalConstant;
                v += IntrazonalTripDistanceFactor * zoneSystem.Distances.GetFlatData()[o][d] * 0.001f;
            }
            else
            {
                var parkingCosts = zoneArray.GetFlatData()[d].ParkingCost * Math.Min(MaximumHoursForParking, TimeToNextTrip(trip));
                Network.GetAllData(o, d, trip.TripStartTime, out float ivtt, out float cost);
                v += timeFactor * ivtt + costParameter * (cost + parkingCosts);
            }
            // Apply personal factors
            if (p.Female)
            {
                v += FemaleFlag;
            }
            var age = p.Age;

            v += AgeUtilLookup[Math.Min(Math.Max(age - 15, 0), 15)];
            if (age >= 65)
            {
                v += Over65;
            }
            else if (age >= 55)
            {
                v += Over55;
            }
            //Apply trip purpose factors
            switch (trip.Purpose)
            {
            case Activity.Market:
                v += MarketFlag;
                break;

            case Activity.IndividualOther:
                v += OtherFlag;
                break;

            case Activity.School:
                v += SchoolFlag;
                break;
            }
            return(v);
        }
Example #4
0
        public double CalculateV(ITrip trip)
        {
            // compute the non human factors
            var   zoneSystem      = Root.ZoneSystem;
            var   zoneArray       = zoneSystem.ZoneArray;
            IZone originalZone    = trip.OriginalZone;
            IZone destinationZone = trip.DestinationZone;
            var   o = zoneArray.GetFlatIndex(originalZone.ZoneNumber);
            var   d = zoneArray.GetFlatIndex(destinationZone.ZoneNumber);
            var   p = trip.TripChain.Person;
            float timeFactor, constant, costFactor;

            GetPersonVariables(p, out timeFactor, out constant, out costFactor);
            float v         = constant;
            var   startTime = trip.TripStartTime;

            // if Intrazonal
            if (o == d)
            {
                v += IntrazonalConstant;
                v += IntrazonalTripDistanceFactor * zoneSystem.Distances.GetFlatData()[o][d] * 0.001f;
            }
            else
            {
                // if not intrazonal
                float aivtt, cost;
                Network.GetAllData(o, d, startTime, out aivtt, out cost);
                v += timeFactor * aivtt + costFactor * cost;
                if (originalZone.RegionNumber == destinationZone.RegionNumber)
                {
                    v += IntraRegionalFlag;
                }
            }
            //Apply trip purpose factors
            switch (trip.Purpose)
            {
            case Activity.Market:
                v += MarketFlag;
                break;

            case Activity.IndividualOther:
                v += OtherFlag;
                break;
            }
            return((double)(v + GetPlanningDistrictConstant(trip.ActivityStartTime, originalZone.PlanningDistrict, destinationZone.PlanningDistrict)));
        }
Example #5
0
        public virtual float CalculateV(IZone originZone, IZone destinationZone, Time time)
        {
            var zoneArray   = this.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 = this.Constant + PartTime + NoDriversLicense + SingleVehicleHousehold + MultipleVehicleHousehold
                      + this.AgeConstant1 + this.AgeConstant2 + this.AgeConstant3 + this.AgeConstant4
                      + this.Parking * destinationZone.ParkingCost
                      + this.GetDensityV(originZone, destinationZone);
            // if we need to calculate distance
            var zoneDistance = this.Root.ZoneSystem.Distances.GetFlatData()[origin][destination];

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

            v += this.Distance * (zoneDistance / 1000f);
            // check what kind of network data we are working with to see if we can use subcomponents
            if (this.AdvancedNetworkData == null)
            {
                // This is a simple mode such as Auto
                float ivtt, cost;
                NetworkData.GetAllData(origin, destination, time, out ivtt, out cost);
                v += IVTT * ivtt + TravelCost * cost;
            }
            else
            {
                // Then we have trip component data
                float ivtt, walk, wait, boarding, cost;
                this.AdvancedNetworkData.GetAllData(origin, destination, time, out ivtt, out walk, out wait, out boarding, out cost);
                v += this.IVTT * ivtt
                     + this.Walk * walk
                     + ((walk > 0) & (ivtt <= 0) ? this.AdjacentZone : 0f)
                     + this.Wait * wait
                     + this.Boarding * boarding
                     + this.TravelCost * cost;
            }
            return(v);
        }
Example #6
0
 protected float GetTravelLogsum(INetworkData autoNetwork, ITripComponentData transitNetwork, int i, int j, Time time)
 {
     float ivtt, cost;
     if(!autoNetwork.GetAllData(i, j, time, out ivtt, out cost))
     {
         return 0.0f;
     }
     return (float)(GetTransitUtility(transitNetwork, i, j, time)
         + Math.Exp(ivtt * AutoTime + cost * Cost));
 }
Example #7
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 #8
0
 private float ComputeUtility(INetworkData autoNetwork, int originIndex, int destinationIndex)
 {
     float aivtt, cost;
     autoNetwork.GetAllData(originIndex, destinationIndex, StartTime, out aivtt, out cost);
     return AIVTT * aivtt + AutoCost * cost;
 }