Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        public double CalculateV(ITrip trip)
        {
            double v = 0;

            v += CSchoolBus;

            if (trip.TripChain.Person.Licence)
            {
                v += DriversLicence;
            }

            if (trip.TripChain.Person.Youth)
            {
                v += YouthPassenger;
                v += YouthWalk;
            }
            if (trip.TripChain.Person.YoungAdult)
            {
                v += YoungAdultPassenger;
                v += YoungAdultWalk;
            }

            if (trip.Purpose == Activity.School)
            {
                v += SchoolPurpose;
            }
            else if (trip.TripNumber > 1 && trip.TripChain.Trips[trip.TripChain.Trips.IndexOf(trip) - 1].Purpose == Activity.School)
            {
                v += SchoolPurpose;
            }
            v += Data.TravelTime(trip.OriginalZone, trip.DestinationZone, trip.ActivityStartTime).ToMinutes() * Distance;
            v += trip.TripChain.Person.Age * Age;
            return(v);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Calcualtes the V value for the given trip
        /// </summary>
        /// <param name="trip">The trip to calcualte for</param>
        /// <returns>The V for the trip</returns>
        public double CalculateV(ITrip trip)
        {
            double V = 0;
            IZone  o = trip.OriginalZone, d = trip.DestinationZone;

            if ((o == d) & UseIntrazonalRegression)
            {
                V += IntrazonalConstantWeight + o.InternalDistance * IntrazonalDistanceWeight;
            }
            else
            {
                V += this.Constant;
                V += AutoData.TravelTime(o, d, trip.ActivityStartTime).ToMinutes() * this.travelTime;
                V += AutoData.TravelCost(o, d, trip.ActivityStartTime) * this.travelCost;
            }
            V += d.ParkingCost * parking;
            if (trip.Purpose == Activity.Market | trip.Purpose == Activity.JointMarket)
            {
                V += this.dpurp_shop_drive;
            }
            else if (trip.Purpose == Activity.IndividualOther | trip.Purpose == Activity.JointOther)
            {
                V += this.dpurp_oth_drive;
            }
            return(V);
        }
Ejemplo n.º 3
0
        public float CalculateV(IZone origin, IZone destination, Time time)
        {
            CheckInterchangeZone();
            var zoneArray       = Root.ZoneSystem.ZoneArray;
            var flatOrigin      = zoneArray.GetFlatIndex(origin.ZoneNumber);
            var flatDestination = zoneArray.GetFlatIndex(destination.ZoneNumber);
            var flatInterchange = zoneArray.GetFlatIndex(InterchangeZone.ZoneNumber);

            // Make sure that this is a valid trip first
            var toDestinationTime = Second.InVehicleTravelTime(flatInterchange, flatDestination, time).ToMinutes();

            if (toDestinationTime > MaxAccessToDestinationTime)
            {
                return(float.NaN);
            }

            float v = LogParkingFactor * LogOfParking;

            if (ClosestZone.GetFlatData()[flatOrigin])
            {
                v += Closest;
            }

            // calculate this second in case the toDestinationTime is invalid
            // Cost of accessing the station
            v += AccessInVehicleTravelTime * First.TravelTime(flatOrigin, flatInterchange, time).ToMinutes()
                 + (AccessCost * (First.TravelCost(flatOrigin, flatInterchange, time) + FareTTC));

            // Station to Destination time
            v += InVehicleTravelTime * toDestinationTime;

            // Walk Time
            v += WalkTime * Second.WalkTime(flatInterchange, flatDestination, time).ToMinutes();
            return(v);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Calculates the V value for the given trip
        /// </summary>
        /// <param name="trip">The trip to calculate for</param>
        /// <returns>The V for the trip</returns>
        public double CalculateV(ITrip trip)
        {
            double v = 0;
            IZone  o = trip.OriginalZone, d = trip.DestinationZone;

            if ((o == d) & UseIntrazonalRegression)
            {
                v += IntrazonalConstantWeight + o.InternalDistance * IntrazonalDistanceWeight;
            }
            else
            {
                v += Constant;
                v += AutoData.TravelTime(o, d, trip.ActivityStartTime).ToMinutes() * TravelTimeBeta;
                v += AutoData.TravelCost(o, d, trip.ActivityStartTime) * TravelCostBeta;
            }
            v += d.ParkingCost * Parking;
            if (trip.Purpose == Activity.Market | trip.Purpose == Activity.JointMarket)
            {
                v += DpurpShopDrive;
            }
            else if (trip.Purpose == Activity.IndividualOther | trip.Purpose == Activity.JointOther)
            {
                v += DpurpOthDrive;
            }
            return(v);
        }
Ejemplo n.º 5
0
        /// <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="egressZones"></param>
        /// <param name="maxDistance">The maximum distance allowed</param>
        /// <param name="selectedEgressZones"></param>
        /// <param name="result">the utility of using this interchange</param>
        /// <param name="distance">The distance the origin is from the interchange in auto travel time</param>
        /// <param name="accessStationIndex"></param>
        /// <param name="egressUtility"></param>
        /// <param name="egressTime"></param>
        /// <param name="egressZone"></param>
        /// <returns>True if this is a valid interchange zone, false if not feasible.</returns>
        // ReSharper disable once UnusedParameter.Local
        private bool ComputeUtility(int o, int d, IZone[] zones, int interchange, int accessStationIndex, int[] egressZones, float maxDistance, float[][] egressUtility, float[][] egressTime, int[][] selectedEgressZones, out float result, out float distance, out IZone egressZone)

        {
            float v = ComputeAccessUtility(o, interchange, out distance);

            // our total travel time / distance is the egress time plus the time it takes to get to the station to begin with
            if (egressTime[accessStationIndex][d] == 0)
            {
                throw new XTMFRuntimeException(this, "In '" + Name + "' the egress time between zone " + zones[egressZones[accessStationIndex]].ZoneNumber + " and " + zones[d].ZoneNumber + " was equal to 0!");
            }
            if (distance <= AutoNetwork.TravelTime(o, d, TimeOfDay).ToMinutes())
            {
                var egressUtil = egressUtility[accessStationIndex][d];
                // Step 1, compute the egress station, and the utility from access station to egress to destination
                if (distance < maxDistance & !float.IsNaN(v) & !float.IsNaN(egressUtil))
                {
                    egressZone = zones[selectedEgressZones[accessStationIndex][d]];
                    // Step 2, compute the utility going from origin to access station
                    v     += egressUtil;
                    result = v;
                    return(true);
                }
            }
            egressZone = null;
            result     = float.NaN;
            return(false);
        }
Ejemplo n.º 6
0
        /// <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);
        }
Ejemplo n.º 7
0
        private float CalculateDATTime(Time time, IZone originalZone, int accessFlat, IZone destinationZone, bool access)
        {
            var origin      = ZoneSystem.GetFlatIndex(originalZone.ZoneNumber);
            var destination = ZoneSystem.GetFlatIndex(destinationZone.ZoneNumber);

            if (access)
            {
                return((AutoNetwork.TravelTime(origin, accessFlat, time)
                        + TransitNetwork.TravelTime(accessFlat, destination, time)).ToMinutes());
            }
            else
            {
                return((TransitNetwork.TravelTime(origin, accessFlat, time)
                        + AutoNetwork.TravelTime(accessFlat, destination, time)).ToMinutes());
            }
        }
        /// <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));
        }
Ejemplo n.º 9
0
            private float CalculateDATTime(SparseArray <IZone> _zoneSystem, INetworkData _autoNetwork, ITripComponentData _transitNetwork, Time time,
                                           IZone originalZone, int accessFlat, IZone destinationZone, bool access)
            {
                var origin      = _zoneSystem.GetFlatIndex(originalZone.ZoneNumber);
                var destination = _zoneSystem.GetFlatIndex(destinationZone.ZoneNumber);

                if (access)
                {
                    return((_autoNetwork.TravelTime(origin, accessFlat, time)
                            + _transitNetwork.TravelTime(accessFlat, destination, time)).ToMinutes());
                }
                else
                {
                    return((_transitNetwork.TravelTime(origin, accessFlat, time)
                            + _autoNetwork.TravelTime(accessFlat, destination, time)).ToMinutes());
                }
            }
Ejemplo n.º 10
0
 override public float CalculateV(IZone origin, IZone destination, Time time)
 {
     if (IsContained(origin, destination))
     {
         return(Aivtt * NetworkData.TravelTime(origin, destination, time).ToMinutes());
     }
     return(0);
 }
Ejemplo n.º 11
0
        private float[] ComputeFriction(IZone[] zones, IDemographicCategory cat, float[] friction)
        {
            var numberOfZones = zones.Length;

            float[] ret = friction ?? (new float[numberOfZones * numberOfZones]);
            // let it setup the modes so we can compute friction
            cat.InitializeDemographicCategory();
            try
            {
                Parallel.For(0, numberOfZones, new ParallelOptions {
                    MaxDegreeOfParallelism = Environment.ProcessorCount
                }, delegate(int j)
                {
                    var destination = zones[j];
                    if (!InverseLookup(destination.RegionNumber, out int regionIndex))
                    {
                        // make sure to reset the friction to zero
                        for (int i = 0; i < numberOfZones; i++)
                        {
                            ret[i * numberOfZones + j] = float.NegativeInfinity;
                        }
                        return;
                    }
                    // store the log of the population and the employment since we will be using this for each origin
                    var employmentLog = (float)Math.Log((destination.Employment - destination.ManufacturingEmployment) + 1);
                    var populationLog = (float)Math.Log(destination.Population + 1);
                    for (int i = 0; i < numberOfZones; i++)
                    {
                        var origin = zones[i];
                        if (origin.RegionNumber <= 0)
                        {
                            ret[i * numberOfZones + j] = float.NegativeInfinity;
                        }
                        else
                        {
                            var autoTime = RegionEmploymentGeneralParameter[regionIndex] *
                                           NetworkData.TravelTime(origin, destination, SimulationTime).ToMinutes();
                            var destinationUtility = RegionEmploymentParameter[regionIndex] * employmentLog
                                                     + RegionPopulationParameter[regionIndex] * populationLog;
                            // this isn't friction, it is V where friction will be e^V
                            ret[i * numberOfZones + j] = destinationUtility + autoTime;
                        }
                    }
                });
            }
            catch (AggregateException e)
            {
                if (e.InnerException is XTMFRuntimeException)
                {
                    throw new XTMFRuntimeException(this, e.InnerException.Message);
                }
                throw new XTMFRuntimeException(this, e.InnerException?.Message + "\r\n" + e.InnerException?.StackTrace);
            }
            // Use the Log-Sum from the V's as the impedence function
            return(ret);
        }
Ejemplo n.º 12
0
        private void LoadTimes(SparseTwinIndex <float> data, INetworkData network)
        {
            var flatData = data.GetFlatData();
            var time     = TimeToLoad;

            for (int i = 0; i < flatData.Length; i++)
            {
                var row = flatData[i];
                for (int j = 0; j < row.Length; j++)
                {
                    row[j] = network.TravelTime(i, j, time).ToMinutes();
                }
            }
        }
Ejemplo n.º 13
0
        public bool Feasible(IZone originZone, IZone destinationZone, Time time)
        {
            var zoneArray   = Root.ZoneSystem.ZoneArray;
            var origin      = zoneArray.GetFlatIndex(originZone.ZoneNumber);
            var destination = zoneArray.GetFlatIndex(destinationZone.ZoneNumber);

            if (CurrentlyFeasible <= 0)
            {
                return(false);
            }
            if (AdvancedNetworkData == null)
            {
                return(NetworkData.ValidOd(origin, destination, time) && (!CheckPositiveIVTT || NetworkData.TravelTime(origin, destination, time).ToMinutes() > 0));
            }

            AdvancedNetworkData.GetAllData(origin, destination, time, out float ivtt, out float walk, out float wait, out float boarding, out float cost);
            return(AdvancedNetworkData.ValidOd(origin, destination, time) &&
                   ((!CheckPositiveIVTT || ivtt > 0)) &&
                   ((!CheckPositiveWalk || walk > 0)));
        }
Ejemplo n.º 14
0
        /// <summary>
        /// Calculate the utility between two zones
        /// </summary>
        /// <param name="zoneO">The flat origin index</param>
        /// <param name="zoneJ">The flat destination index</param>
        /// <returns>The utility between the two zones.</returns>
        public float CalculateUtilityToE(int pdO, int pdD, int zoneO, int zoneD, int workerIndex, float distance)
        {
            var segment = GetSegment(pdO, pdD);

            if (segment == null)
            {
                return(0);
            }
            double utility = 0.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 time = AutoNetwork.TravelTime(zoneO, zoneD, TimeOfDay).ToMinutes();

            utility = Math.Exp((workerIndex == 0 ? segment.PassengerTime : segment.AutoTime) * time +
                               (workerIndex == 2 ? segment.SaturatedVehicles : 0));
            // transit
            time = TransitNetwork.TravelTime(zoneO, zoneD, TimeOfDay).ToMinutes();
            if (time > 0)
            {
                utility += Math.Exp(segment.TransitTime * time + segment.TransitConstant);
            }
            // distance
            if (distance < segment.MaxDistance)
            {
                utility += Math.Exp(segment.Distance * distance + segment.DistanceConstant);
            }
            var constants = 1.0;

            if (zoneO == zoneD)
            {
                constants *= segment.ExpIntrazonalConstant;
            }
            if (pdO == pdD)
            {
                constants *= segment.ExpIntraPDConstant;
            }
            return((float)(utility * constants));
        }
Ejemplo n.º 15
0
        private float[] ComputeFriction(IZone[] zones, IDemographicCategory cat, float[] friction)
        {
            var numberOfZones = zones.Length;

            float[] ret = friction == null ? new float[numberOfZones * numberOfZones] : friction;
            // let it setup the modes so we can compute friction
            cat.InitializeDemographicCategory();
            Parallel.For(0, numberOfZones, new ParallelOptions {
                MaxDegreeOfParallelism = Environment.ProcessorCount
            }, delegate(int i)
            {
                int index  = i * numberOfZones;
                var origin = zones[i];
                if (!InverseLookup(zones[i].RegionNumber, out int regionIndex))
                {
                    for (int j = 0; j < numberOfZones; j++)
                    {
                        ret[index++] = 0;
                    }
                    return;
                }
                for (int j = 0; j < numberOfZones; j++)
                {
                    var destination = zones[j];
                    var autoTime    = NetworkData.TravelTime(origin, destination, SimulationTime);
                    var population  = destination.Population;
                    ret[index++]    = (float)(RegionAutoParameter[regionIndex] * autoTime.ToMinutes()
                                              // population
                                              + RegionPopulationParameter[regionIndex] * Math.Log(population + 1)
                                              // employment
                                              + RegionEmploymentProfessionalParameter[regionIndex] * Math.Log(destination.ProfessionalEmployment + 1)
                                              + RegionEmploymentGeneralParameter[regionIndex] * Math.Log(destination.GeneralEmployment + 1)
                                              + RegionEmploymentSalesParameter[regionIndex] * Math.Log(destination.RetailEmployment + 1)
                                              + RegionEmploymentManufacturingParameter[regionIndex] * Math.Log(destination.ManufacturingEmployment + 1));
                }
            });
            // Use the Log-Sum from the V's as the impedence function
            return(ret);
        }
Ejemplo n.º 16
0
 private void ComputeFriction(IZone[] zones, int numberOfZones, float[] ret)
 {
     Parallel.For(0, numberOfZones, new ParallelOptions {
         MaxDegreeOfParallelism = Environment.ProcessorCount
     }, delegate(int i)
     {
         var origin = zones[i];
         if (!InverseLookup(origin.RegionNumber, out int regionIndex))
         {
             return;
         }
         int index = (i * numberOfZones);
         for (int j = 0; j < numberOfZones; j++)
         {
             var destination = zones[j];
             ret[index++]    = (float)(RegionAutoParameter[regionIndex] * NetworkData.TravelTime(origin, destination, SimulationTime).ToMinutes()
                                       // population
                                       + RegionPopulationParameter[regionIndex] * Math.Log(destination.Population + 1)
                                       // employment
                                       + RegionNonManufacturingEmploymentParameter[regionIndex] * Math.Log(destination.ProfessionalEmployment
                                                                                                           + destination.GeneralEmployment + destination.RetailEmployment + 1));
         }
     });
 }
Ejemplo n.º 17
0
 public Time TravelTime(IZone origin, IZone destination, Time time)
 {
     return(Network.TravelTime(origin, destination, time));
 }
Ejemplo n.º 18
0
 /// <summary>
 /// This gets the travel time between zones
 /// </summary>
 /// <param name="origin">Where to start</param>
 /// <param name="destination">Where to go</param>
 /// <param name="time">What time of day is it? (hhmm.ss)</param>
 /// <returns>The amount of time it will take</returns>
 public Time TravelTime(IZone origin, IZone destination, Time time)
 {
     return(AutoData.TravelTime(origin, destination, time));
 }
Ejemplo n.º 19
0
 public bool ProduceResult(Pair <IZone, IZone> data)
 {
     return(NetworkData.TravelTime(data.First, data.Second, SimulationTime) > Time.Zero);
 }