public static double DistanceFromSchoolLog(this IPoint origin, IPoint destination, int minute) { return (origin == null ? 0 : Math.Log(1 + ImpedanceRoster.GetValue("distance", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, minute, origin, destination).BlendVariable / 10)); }
protected override void RegionSpecificCustomizations(ChoiceProbabilityCalculator.Alternative alternative, IPersonWrapper _person, IParcelWrapper destinationParcel) { double intracounty = ImpedanceRoster.GetValue("intracounty", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, 1, _person.Household.ResidenceParcel, destinationParcel).Variable; alternative.AddUtilityTerm(45, intracounty); }
protected override void RegionSpecificOtherTourDistrictCoefficients(ChoiceProbabilityCalculator.Alternative alternative, ITourWrapper _tour, IParcelWrapper destinationParcel) { //add any region-specific new terms in region-specific class, using coefficient numbers 114-120, or other unused variable # //Global.PrintFile.WriteLine("JAX_OtherTourDestinationModel.RegionSpecificOtherTourDistrictCoefficients called"); double crossriver = ImpedanceRoster.GetValue("crossriver", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, 1, _tour.OriginParcel, destinationParcel).Variable; double intracounty = ImpedanceRoster.GetValue("intracounty", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, 1, _tour.OriginParcel, destinationParcel).Variable; if (_tour.DestinationPurpose == Global.Settings.Purposes.Escort) { alternative.AddUtilityTerm(114, crossriver); } else if (_tour.DestinationPurpose == Global.Settings.Purposes.PersonalBusiness || _tour.DestinationPurpose == Global.Settings.Purposes.Medical) { alternative.AddUtilityTerm(115, crossriver); alternative.AddUtilityTerm(119, intracounty); } else if (_tour.DestinationPurpose == Global.Settings.Purposes.Shopping) { alternative.AddUtilityTerm(116, crossriver); alternative.AddUtilityTerm(119, intracounty); } else if (_tour.DestinationPurpose == Global.Settings.Purposes.Meal) { alternative.AddUtilityTerm(117, crossriver); alternative.AddUtilityTerm(119, intracounty); } else if (_tour.DestinationPurpose == Global.Settings.Purposes.Social || _tour.DestinationPurpose == Global.Settings.Purposes.Recreation) { alternative.AddUtilityTerm(118, crossriver); alternative.AddUtilityTerm(119, intracounty); } }
public void Run(IPersonWrapper person, int sampleSize) { if (person == null) { throw new ArgumentNullException("person"); } person.ResetRandom(0); if (Global.Configuration.IsInEstimationMode) { // if (!_helpers[ParallelUtility.threadLocalAssignedIndex.Value].ModelIsInEstimationMode) { // return; // } if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME) { return; } } ChoiceProbabilityCalculator choiceProbabilityCalculator = _helpers[ParallelUtility.threadLocalAssignedIndex.Value].GetChoiceProbabilityCalculator(person.Id); if (_helpers[ParallelUtility.threadLocalAssignedIndex.Value].ModelIsInEstimationMode) { if (person.UsualWorkParcel == null) { return; } bool choseHome = person.UsualWorkParcelId == person.Household.ResidenceParcelId; // JLB 20120329 added these two lines IParcelWrapper chosenParcel = choseHome ? null : person.UsualWorkParcel; //RunModel(choiceProbabilityCalculator, person, sampleSize, person.UsualWorkParcel); RunModel(choiceProbabilityCalculator, person, sampleSize, chosenParcel, choseHome); // JLB 20120329 replaced above line // when chosenParcel is null: // DestinationSampler doesn't try to assign one of the sampled destinations as chosen // choseHome is NOT null, and RunModel sets the oddball location as chosen choiceProbabilityCalculator.WriteObservation(); } else { RunModel(choiceProbabilityCalculator, person, sampleSize); ChoiceProbabilityCalculator.Alternative chosenAlternative = choiceProbabilityCalculator.SimulateChoice(person.Household.RandomUtility); ParcelWrapper choice = (ParcelWrapper)chosenAlternative.Choice; person.WorkLocationLogsum = chosenAlternative.ComputeLogsum(); person.UsualWorkParcelId = choice.Id; person.UsualWorkParcel = choice; person.UsualWorkZoneKey = ChoiceModelFactory.ZoneKeys[choice.ZoneId]; SkimValue skimValue = ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, 1, person.Household.ResidenceParcel, choice); person.AutoTimeToUsualWork = skimValue.Variable; person.AutoDistanceToUsualWork = skimValue.BlendVariable; person.SetWorkParcelPredictions(); } }
private void RunAVModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, IHouseholdWrapper household, int choice = Constants.DEFAULT_VALUE) { int ageOfHouseholdHead = 0; double totalCommuteTime = 0; foreach (var person in household.Persons) { if (person.Sequence == 1) { ageOfHouseholdHead = person.Age; } if (person.IsWorker && person.UsualWorkParcel != null && person.UsualWorkParcelId != household.ResidenceParcelId) { var destinationArrivalTime = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.WorkTourModeModel); var destinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.WorkTourModeModel); totalCommuteTime += ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, destinationArrivalTime, household.ResidenceParcel, person.UsualWorkParcel).Variable; totalCommuteTime += ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, destinationDepartureTime, person.UsualWorkParcel, household.ResidenceParcel).Variable; } } // 0 Conventional auotos var alternative = choiceProbabilityCalculator.GetAlternative(0, true, choice == 0); alternative.Choice = 0; //utility is 0 // 1 AVs alternative = choiceProbabilityCalculator.GetAlternative(1, true, choice == 1); alternative.Choice = 1; alternative.AddUtilityTerm(200, Global.Configuration.AV_AutoTypeConstant); alternative.AddUtilityTerm(200, Global.Configuration.AV_HHIncomeUnder50KCoefficient * household.HasIncomeUnder50K.ToFlag()); alternative.AddUtilityTerm(200, Global.Configuration.AV_HHIncomeOver100KCoefficient * household.Has100KPlusIncome.ToFlag()); alternative.AddUtilityTerm(200, Global.Configuration.AV_HHHeadUnder35Coefficient * (ageOfHouseholdHead < 35).ToFlag()); alternative.AddUtilityTerm(200, Global.Configuration.AV_HHHeadOver65Coefficient * (ageOfHouseholdHead >= 65).ToFlag()); alternative.AddUtilityTerm(200, Global.Configuration.AV_CoefficientPerHourCommuteTime * (totalCommuteTime / 60.0)); // 2 not available alternative = choiceProbabilityCalculator.GetAlternative(2, false, choice == 2); alternative.Choice = 2; // 3 not available alternative = choiceProbabilityCalculator.GetAlternative(3, false, choice == 3); alternative.Choice = 3; // 4 not available alternative = choiceProbabilityCalculator.GetAlternative(4, false, choice == 4); alternative.Choice = 4; }
public static double DistanceFromOrigin(this IPoint origin, IPoint destination, int minute) { if (origin == null) { throw new ArgumentNullException("origin"); } if (destination == null) { throw new ArgumentNullException("destination"); } return(ImpedanceRoster.GetValue("distance", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, minute, origin, destination).BlendVariable / 10); }
protected override void RegionSpecificTransitImpedanceCalculation(int skimMode, int pathType, double votValue, int outboundTime, int returnTime, int originZoneId, int destinationZoneId, ref double outboundInVehicleTime, ref double returnInVehicleTime, ref double pathTypeSpecificTime, ref double pathTypeSpecificTimeWeight) { //this is the outer weight on the sum of all the path specific terms //copied from PSRC and adapted to use a different set of skim names and also constant terms - in units of minutes pathTypeSpecificTimeWeight = 1.0; double lrtTime = ImpedanceRoster.GetValue("lrttime", skimMode, pathType, votValue, outboundTime, originZoneId, destinationZoneId).Variable; double comTime = ImpedanceRoster.GetValue("comtime", skimMode, pathType, votValue, outboundTime, originZoneId, destinationZoneId).Variable; double premTime = ImpedanceRoster.GetValue("premtime", skimMode, pathType, votValue, outboundTime, originZoneId, destinationZoneId).Variable; double circTime = ImpedanceRoster.GetValue("cirtime", skimMode, pathType, votValue, outboundTime, originZoneId, destinationZoneId).Variable; double othTime = ImpedanceRoster.GetValue("othtime", skimMode, pathType, votValue, outboundTime, originZoneId, destinationZoneId).Variable; pathTypeSpecificTime = Global.Configuration.PathImpedance_TransitLightRailTimeAdditiveWeight * lrtTime + Global.Configuration.PathImpedance_TransitCommuterRailTimeAdditiveWeight * comTime + Global.Configuration.PathImpedance_TransitPremiumBusTimeAdditiveWeight * premTime + Global.Configuration.PathImpedance_TransitCirculatorBusTimeAdditiveWeight * circTime + Global.Configuration.PathImpedance_TransitOtherModeTimeAdditiveWeight * othTime; pathTypeSpecificTime += Math.Min((othTime > Constants.EPSILON).ToFlag() * Global.Configuration.PathImpedance_TransitOtherModePathConstant, Math.Min((comTime > Constants.EPSILON).ToFlag() * Global.Configuration.PathImpedance_TransitCommuterRailPathConstant, Math.Min((lrtTime > Constants.EPSILON).ToFlag() * Global.Configuration.PathImpedance_TransitLightRailPathConstant, Math.Min((circTime > Constants.EPSILON).ToFlag() * Global.Configuration.PathImpedance_TransitCirculatorBusPathConstant, (premTime > Constants.EPSILON).ToFlag() * Global.Configuration.PathImpedance_TransitPremiumBusPathConstant)))); if (returnTime > 0) { lrtTime = ImpedanceRoster.GetValue("lrttime", skimMode, pathType, votValue, returnTime, destinationZoneId, originZoneId).Variable; comTime = ImpedanceRoster.GetValue("comtime", skimMode, pathType, votValue, returnTime, destinationZoneId, originZoneId).Variable; premTime = ImpedanceRoster.GetValue("premtime", skimMode, pathType, votValue, returnTime, destinationZoneId, originZoneId).Variable; circTime = ImpedanceRoster.GetValue("circtime", skimMode, pathType, votValue, returnTime, destinationZoneId, originZoneId).Variable; othTime = ImpedanceRoster.GetValue("othtime", skimMode, pathType, votValue, returnTime, destinationZoneId, originZoneId).Variable; pathTypeSpecificTime += +Global.Configuration.PathImpedance_TransitLightRailTimeAdditiveWeight * lrtTime + Global.Configuration.PathImpedance_TransitCommuterRailTimeAdditiveWeight * comTime + Global.Configuration.PathImpedance_TransitPremiumBusTimeAdditiveWeight * premTime + Global.Configuration.PathImpedance_TransitCirculatorBusTimeAdditiveWeight * circTime + Global.Configuration.PathImpedance_TransitOtherModeTimeAdditiveWeight * othTime; pathTypeSpecificTime += Math.Min((othTime > Constants.EPSILON).ToFlag() * Global.Configuration.PathImpedance_TransitOtherModePathConstant, Math.Min((comTime > Constants.EPSILON).ToFlag() * Global.Configuration.PathImpedance_TransitCommuterRailPathConstant, Math.Min((lrtTime > Constants.EPSILON).ToFlag() * Global.Configuration.PathImpedance_TransitLightRailPathConstant, Math.Min((circTime > Constants.EPSILON).ToFlag() * Global.Configuration.PathImpedance_TransitCirculatorBusPathConstant, (premTime > Constants.EPSILON).ToFlag() * Global.Configuration.PathImpedance_TransitPremiumBusPathConstant)))); } } //end RegionSpecificTransitImpedanceCalculation
protected override void RegionSpecificTransitImpedanceCalculation(int skimMode, int pathType, double votValue, int outboundTime, int returnTime, int originZoneId, int destinationZoneId, ref double outboundInVehicleTime, ref double returnInVehicleTime, ref double pathTypeSpecificTime, ref double pathTypeSpecificTimeWeight) { //Global.PrintFile.WriteLine("DVRPC_PathTypeModel.RegionSpecificTransitImpedanceCalculation called"); //this is the outer weight on the sum of all the path specific terms pathTypeSpecificTimeWeight = 1.0; pathTypeSpecificTime = Global.Configuration.PathImpedance_TransitLightRailTimeAdditiveWeight * ImpedanceRoster.GetValue("lrttime", skimMode, pathType, votValue, outboundTime, originZoneId, destinationZoneId).Variable + Global.Configuration.PathImpedance_TransitSubwayTimeAdditiveWeight * ImpedanceRoster.GetValue("subtime", skimMode, pathType, votValue, outboundTime, originZoneId, destinationZoneId).Variable + Global.Configuration.PathImpedance_TransitCommuterRailTimeAdditiveWeight * ImpedanceRoster.GetValue("comrtime", skimMode, pathType, votValue, outboundTime, originZoneId, destinationZoneId).Variable + Global.Configuration.PathImpedance_TransitPremiumBusTimeAdditiveWeight * ImpedanceRoster.GetValue("brttime", skimMode, pathType, votValue, outboundTime, originZoneId, destinationZoneId).Variable + Global.Configuration.PathImpedance_TransitPATTimeAdditiveWeight * ImpedanceRoster.GetValue("pattime", skimMode, pathType, votValue, outboundTime, originZoneId, destinationZoneId).Variable + Global.Configuration.PathImpedance_TransitTrolleyTimeAdditiveWeight * ImpedanceRoster.GetValue("troltime", skimMode, pathType, votValue, outboundTime, originZoneId, destinationZoneId).Variable; if (returnTime > 0) { pathTypeSpecificTime += +Global.Configuration.PathImpedance_TransitLightRailTimeAdditiveWeight * ImpedanceRoster.GetValue("lrttime", skimMode, pathType, votValue, returnTime, destinationZoneId, originZoneId).Variable + Global.Configuration.PathImpedance_TransitSubwayTimeAdditiveWeight * ImpedanceRoster.GetValue("subtime", skimMode, pathType, votValue, returnTime, destinationZoneId, originZoneId).Variable + Global.Configuration.PathImpedance_TransitCommuterRailTimeAdditiveWeight * ImpedanceRoster.GetValue("comrtime", skimMode, pathType, votValue, returnTime, destinationZoneId, originZoneId).Variable + Global.Configuration.PathImpedance_TransitPremiumBusTimeAdditiveWeight * ImpedanceRoster.GetValue("brttime", skimMode, pathType, votValue, returnTime, destinationZoneId, originZoneId).Variable + Global.Configuration.PathImpedance_TransitPATTimeAdditiveWeight * ImpedanceRoster.GetValue("pattime", skimMode, pathType, votValue, returnTime, destinationZoneId, originZoneId).Variable + Global.Configuration.PathImpedance_TransitTrolleyTimeAdditiveWeight * ImpedanceRoster.GetValue("troltime", skimMode, pathType, votValue, returnTime, destinationZoneId, originZoneId).Variable; } } //end RegionSpecificTransitImpedanceCalculation
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITripWrapper trip, TripTime choice = null) { IPersonWrapper person = trip.Person; IPersonDayWrapper personDay = trip.PersonDay; ITourWrapper tour = trip.Tour; // person inputs int partTimeWorkerFlag = person.IsPartTimeWorker.ToFlag(); int nonworkingAdultFlag = person.IsNonworkingAdult.ToFlag(); int universityStudentFlag = person.IsUniversityStudent.ToFlag(); int retiredAdultFlag = person.IsRetiredAdult.ToFlag(); int drivingAgeStudentFlag = person.IsDrivingAgeStudent.ToFlag(); int childAge5Through15Flag = person.IsChildAge5Through15.ToFlag(); int childUnder5Flag = person.IsChildUnder5.ToFlag(); // set tour inputs int workTourFlag = tour.IsWorkPurpose().ToFlag(); int notWorkTourFlag = (!tour.IsWorkPurpose()).ToFlag(); int notHomeBasedTourFlag = (!tour.IsHomeBasedTour).ToFlag(); // set trip inputs bool originChangeMode = trip.Sequence > 1 && trip.GetPreviousTrip().DestinationPurpose == Global.Settings.Purposes.ChangeMode; int originWorkFlag = trip.IsWorkOriginPurpose().ToFlag(); int originSchoolFlag = trip.IsSchoolOriginPurpose().ToFlag(); int originEscortFlag = trip.IsEscortOriginPurpose().ToFlag(); int originShoppingFlag = trip.IsShoppingOriginPurpose().ToFlag(); int originPersonalBusinessFlag = trip.IsPersonalBusinessOriginPurpose().ToFlag(); int originMealFlag = trip.IsMealOriginPurpose().ToFlag(); int originSocialFlag = trip.IsSocialOriginPurpose().ToFlag(); int sovOrHovTripFlag = trip.UsesSovOrHovModes().ToFlag(); int transitTripFlag = trip.IsTransitMode().ToFlag(); int halfTourFromOriginFlag = trip.IsHalfTourFromOrigin.ToFlag(); int halfTourFromDestinationFlag = (!trip.IsHalfTourFromOrigin).ToFlag(); // set remaining inputs ITimeWindow timeWindow = tour.IsHomeBasedTour ? personDay.TimeWindow : tour.ParentTour.TimeWindow; ITripModeImpedance[] impedances = trip.GetTripModeImpedances(); int remainingToursCount = personDay.HomeBasedTours - personDay.GetTotalSimulatedTours(); int tripRemainingInHalfTour = (trip.DestinationParcel != null && trip.DestinationParcel != tour.OriginParcel).ToFlag(); // we don't know exact # for (int arrivalPeriodIndex = 1; arrivalPeriodIndex < DayPeriod.SmallDayPeriods.Length; arrivalPeriodIndex++) { MinuteSpan arrivalPeriod = DayPeriod.SmallDayPeriods[arrivalPeriodIndex]; int previousArrivalTime = trip.GetPreviousTrip().ArrivalTime; if (previousArrivalTime < arrivalPeriod.Start || previousArrivalTime > arrivalPeriod.End) { continue; } ITripModeImpedance arrivalImpedance = impedances[arrivalPeriod.Index]; // moved to here so not reset for every alternative foreach (TripTime time in TripTime.Times) { MinuteSpan departurePeriod = time.DeparturePeriod; // moved to here so can use travel time ITripModeImpedance departureImpedance = impedances[departurePeriod.Index]; // change availability check to include travel duration int travelDuration = (int)Math.Round(departureImpedance.TravelTime + 0.5); // if not the trip home, on a home-based tour, also include fastest time from the destinatinon to home // if (trip.Tour.IsHomeBasedTour && trip.DestinationPurpose != Global.Settings.Purposes.NoneOrHome) { // var fastestMode = Math.Min(trip.Tour.Mode, Global.Settings.Modes.Hov3); // var pathTypeModel = PathTypeModelFactory.Singleton.Run(trip.DestinationParcel, trip.Household.ResidenceParcel, departurePeriod.Middle, 0, // trip.Tour.DestinationPurpose, trip.Tour.CostCoefficient, trip.Tour.TimeCoefficient, // trip.Person.IsDrivingAge, trip.Household.VehiclesAvailable, trip.Tour.Person.TransitFareDiscountFraction, false, fastestMode).First(); // travelDuration += (int) Math.Round(pathTypeModel.PathTime + 0.5); // } int bestArrivalTime = trip.IsHalfTourFromOrigin ? Math.Max(departurePeriod.End - travelDuration, 1) : Math.Min(departurePeriod.Start + travelDuration, Global.Settings.Times.MinutesInADay); bool available = originChangeMode ? arrivalPeriod.Index == time.DeparturePeriod.Index : (trip.IsHalfTourFromOrigin && // if change mode, must be in same period arrivalPeriod.Index > departurePeriod.Index && timeWindow.EntireSpanIsAvailable(bestArrivalTime, arrivalPeriod.Start - 1)) || (!trip.IsHalfTourFromOrigin && arrivalPeriod.Index < departurePeriod.Index && timeWindow.EntireSpanIsAvailable(arrivalPeriod.End, bestArrivalTime - 1)) || arrivalPeriod.Index == time.DeparturePeriod.Index && timeWindow.TotalAvailableMinutes(arrivalPeriod.Start, arrivalPeriod.End) > travelDuration; double departurePeriodFraction = timeWindow.TotalAvailableMinutes(departurePeriod.Start, departurePeriod.End) / (departurePeriod.End - departurePeriod.Start + 1D); int duration = Math.Abs(departurePeriod.Middle - arrivalPeriod.Middle); available = available && departurePeriodFraction > 0; //ensure transit path type is available in alternative if (trip.Mode == Global.Settings.Modes.Transit && !Global.StopAreaIsEnabled) { double transitPathTypeInVehicleTime = ImpedanceRoster.GetValue("ivtime", trip.Mode, trip.PathType, trip.ValueOfTime, time.DeparturePeriod.Middle, trip.OriginParcel.ZoneId, trip.DestinationParcel.ZoneId).Variable; available = available && (transitPathTypeInVehicleTime > 0); } ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(time.Index, available, choice != null && choice.Equals(time)); // if (choice.Equals(tripTime) && !available) { // Console.WriteLine(available); // } if (!alternative.Available) { continue; } alternative.Choice = time; double departurePeriodShift = time.DeparturePeriod.Index * (48.0 / DayPeriod.SMALL_DAY_PERIOD_TOTAL_TRIP_TIMES); //adjust shift amount if period lengths change if (trip.IsHalfTourFromOrigin) { // outbound "departure" (arrival) period constants alternative.AddUtilityTerm(11, time.DeparturePeriod.Middle.IsBetween(Global.Settings.Times.ThreeAM, Global.Settings.Times.SixAM).ToFlag()); alternative.AddUtilityTerm(12, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.SixAM, Global.Settings.Times.SevenAM).ToFlag()); alternative.AddUtilityTerm(13, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.SevenAM, Global.Settings.Times.EightAM).ToFlag()); alternative.AddUtilityTerm(14, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.EightAM, Global.Settings.Times.NineAM).ToFlag()); alternative.AddUtilityTerm(15, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.NineAM, Global.Settings.Times.TenAM).ToFlag()); alternative.AddUtilityTerm(16, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.TenAM, Global.Settings.Times.OnePM).ToFlag()); alternative.AddUtilityTerm(17, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.OnePM, Global.Settings.Times.FourPM).ToFlag()); alternative.AddUtilityTerm(18, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.FourPM, Global.Settings.Times.SevenPM).ToFlag()); alternative.AddUtilityTerm(19, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.SevenPM, Global.Settings.Times.TenPM).ToFlag()); alternative.AddUtilityTerm(20, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.TenPM, Global.Settings.Times.MinutesInADay).ToFlag()); } else { // return departure period constants alternative.AddUtilityTerm(21, time.DeparturePeriod.Middle.IsBetween(Global.Settings.Times.ThreeAM, Global.Settings.Times.SevenAM).ToFlag()); alternative.AddUtilityTerm(22, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.SevenAM, Global.Settings.Times.TenAM).ToFlag()); alternative.AddUtilityTerm(23, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.TenAM, Global.Settings.Times.OnePM).ToFlag()); alternative.AddUtilityTerm(24, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.OnePM, Global.Settings.Times.ThreePM).ToFlag()); alternative.AddUtilityTerm(124, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.ThreePM, Global.Settings.Times.FourPM).ToFlag()); alternative.AddUtilityTerm(25, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.FourPM, Global.Settings.Times.FivePM).ToFlag()); alternative.AddUtilityTerm(26, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.FivePM, Global.Settings.Times.SixPM).ToFlag()); alternative.AddUtilityTerm(27, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.SixPM, Global.Settings.Times.SevenPM).ToFlag()); alternative.AddUtilityTerm(28, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.SevenPM, Global.Settings.Times.NinePM).ToFlag()); alternative.AddUtilityTerm(29, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.NinePM, Global.Settings.Times.Midnight).ToFlag()); alternative.AddUtilityTerm(30, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.Midnight, Global.Settings.Times.MinutesInADay).ToFlag()); } alternative.AddUtilityTerm(31, duration.IsRightExclusiveBetween(Global.Settings.Times.ZeroHours, Global.Settings.Times.OneHour).ToFlag()); // 0 - 1 alternative.AddUtilityTerm(32, duration.IsRightExclusiveBetween(Global.Settings.Times.OneHour, Global.Settings.Times.TwoHours).ToFlag()); // 1 - 2 alternative.AddUtilityTerm(33, duration.IsRightExclusiveBetween(Global.Settings.Times.TwoHours, Global.Settings.Times.ThreeHours).ToFlag()); // 2 - 3 alternative.AddUtilityTerm(34, duration.IsRightExclusiveBetween(Global.Settings.Times.ThreeHours, Global.Settings.Times.FiveHours).ToFlag()); // 3 - 5 alternative.AddUtilityTerm(35, duration.IsRightExclusiveBetween(Global.Settings.Times.FiveHours, Global.Settings.Times.SevenHours).ToFlag()); // 5 - 7 alternative.AddUtilityTerm(36, duration.IsRightExclusiveBetween(Global.Settings.Times.SevenHours, Global.Settings.Times.NineHours).ToFlag()); // 7 - 9 alternative.AddUtilityTerm(37, duration.IsRightExclusiveBetween(Global.Settings.Times.NineHours, Global.Settings.Times.TwelveHours).ToFlag()); // 9 - 12 alternative.AddUtilityTerm(38, duration.IsRightExclusiveBetween(Global.Settings.Times.TwelveHours, Global.Settings.Times.FourteenHours).ToFlag()); // 12 - 14 alternative.AddUtilityTerm(39, duration.IsRightExclusiveBetween(Global.Settings.Times.FourteenHours, Global.Settings.Times.EighteenHours).ToFlag()); // 14 - 18 alternative.AddUtilityTerm(40, (duration >= Global.Settings.Times.EighteenHours).ToFlag()); // 18 - 24 //these were duplicate departure shift variables before, and constrained to 0 in all the coefficient files - replaced by duration shifts alternative.AddUtilityTerm(41, partTimeWorkerFlag * duration); alternative.AddUtilityTerm(43, nonworkingAdultFlag * duration); alternative.AddUtilityTerm(45, universityStudentFlag * duration); alternative.AddUtilityTerm(47, retiredAdultFlag * duration); alternative.AddUtilityTerm(49, drivingAgeStudentFlag * duration); alternative.AddUtilityTerm(51, childAge5Through15Flag * duration); alternative.AddUtilityTerm(53, childUnder5Flag * duration); alternative.AddUtilityTerm(55, halfTourFromOriginFlag * duration); alternative.AddUtilityTerm(131, workTourFlag * halfTourFromOriginFlag * duration); alternative.AddUtilityTerm(133, workTourFlag * halfTourFromDestinationFlag * duration); alternative.AddUtilityTerm(135, notWorkTourFlag * halfTourFromDestinationFlag * duration); alternative.AddUtilityTerm(137, notHomeBasedTourFlag * duration); alternative.AddUtilityTerm(145, originEscortFlag * duration); alternative.AddUtilityTerm(147, originShoppingFlag * duration); alternative.AddUtilityTerm(149, originMealFlag * duration); alternative.AddUtilityTerm(151, originSocialFlag * duration); alternative.AddUtilityTerm(153, originPersonalBusinessFlag * duration); alternative.AddUtilityTerm(155, originSchoolFlag * duration); alternative.AddUtilityTerm(42, partTimeWorkerFlag * departurePeriodShift); alternative.AddUtilityTerm(44, nonworkingAdultFlag * departurePeriodShift); alternative.AddUtilityTerm(46, universityStudentFlag * departurePeriodShift); alternative.AddUtilityTerm(48, retiredAdultFlag * departurePeriodShift); alternative.AddUtilityTerm(50, drivingAgeStudentFlag * departurePeriodShift); alternative.AddUtilityTerm(52, childAge5Through15Flag * departurePeriodShift); alternative.AddUtilityTerm(54, childUnder5Flag * departurePeriodShift); alternative.AddUtilityTerm(56, halfTourFromOriginFlag * departurePeriodShift); alternative.AddUtilityTerm(132, workTourFlag * halfTourFromOriginFlag * departurePeriodShift); alternative.AddUtilityTerm(134, workTourFlag * halfTourFromDestinationFlag * departurePeriodShift); alternative.AddUtilityTerm(136, notWorkTourFlag * halfTourFromDestinationFlag * departurePeriodShift); alternative.AddUtilityTerm(138, notHomeBasedTourFlag * departurePeriodShift); alternative.AddUtilityTerm(146, originEscortFlag * departurePeriodShift); alternative.AddUtilityTerm(148, originShoppingFlag * departurePeriodShift); alternative.AddUtilityTerm(150, originMealFlag * departurePeriodShift); alternative.AddUtilityTerm(152, originSocialFlag * departurePeriodShift); alternative.AddUtilityTerm(154, originPersonalBusinessFlag * departurePeriodShift); alternative.AddUtilityTerm(156, originSchoolFlag * departurePeriodShift); alternative.AddUtilityTerm(86, sovOrHovTripFlag * Math.Max(departureImpedance.GeneralizedTime, 0) * tour.TimeCoefficient); alternative.AddUtilityTerm(88, transitTripFlag * Math.Max(departureImpedance.GeneralizedTime, 0) * tour.TimeCoefficient); alternative.AddUtilityTerm(89, transitTripFlag * (departureImpedance.GeneralizedTime < 0).ToFlag()); alternative.AddUtilityTerm(92, halfTourFromOriginFlag * Math.Log(departurePeriodFraction)); alternative.AddUtilityTerm(92, halfTourFromDestinationFlag * Math.Log(departurePeriodFraction)); alternative.AddUtilityTerm(99, tripRemainingInHalfTour / (1D + halfTourFromOriginFlag * departureImpedance.AdjacentMinutesBefore + halfTourFromDestinationFlag * departureImpedance.AdjacentMinutesAfter)); alternative.AddUtilityTerm(97, remainingToursCount / (1D + halfTourFromOriginFlag * (arrivalImpedance.TotalMinutesAfter + departureImpedance.TotalMinutesBefore) + halfTourFromDestinationFlag * (arrivalImpedance.TotalMinutesBefore + departureImpedance.TotalMinutesAfter))); alternative.AddUtilityTerm(98, remainingToursCount / (1D + halfTourFromOriginFlag * Math.Max(arrivalImpedance.MaxMinutesBefore, departureImpedance.MaxMinutesBefore) + halfTourFromDestinationFlag * Math.Max(arrivalImpedance.MaxMinutesBefore, departureImpedance.MaxMinutesAfter))); } } }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, TripWrapper trip, HouseholdDayWrapper householdDay, int choice = Constants.DEFAULT_VALUE) { var household = (HouseholdWrapper)trip.Household; var person = (PersonWrapper)trip.Person; var personDay = (PersonDayWrapper)trip.PersonDay; var tour = (TourWrapper)trip.Tour; var halfTour = (TourWrapper.HalfTour)trip.HalfTour; var personDays = householdDay.PersonDays; var isJointTour = tour.JointTourSequence > 0 ? 1 : 0; var isIndividualTour = isJointTour == 1 ? 0 : 1; var destinationParcel = tour.DestinationParcel; var jointHalfOfFullJointHalfTour = ((trip.Direction == Global.Settings.TourDirections.OriginToDestination && tour.FullHalfTour1Sequence > 0) || (trip.Direction == Global.Settings.TourDirections.DestinationToOrigin && tour.FullHalfTour2Sequence > 0)).ToFlag(); var individualHalfOfFullJointHalfTour = ((trip.Direction == Global.Settings.TourDirections.OriginToDestination && tour.FullHalfTour1Sequence == 0 && tour.FullHalfTour2Sequence > 0) || (trip.Direction == Global.Settings.TourDirections.DestinationToOrigin && tour.FullHalfTour2Sequence == 0 && tour.FullHalfTour1Sequence > 0)).ToFlag(); var individualHalfTour = (isIndividualTour == 1 || individualHalfOfFullJointHalfTour == 1) ? 1 : 0; var jointHalfTour = 1 - individualHalfTour; //destination parcel variables var foodBuffer2 = 0.0; var totEmpBuffer2 = 0.0; var retailBuffer2 = 0.0; if (destinationParcel != null) { foodBuffer2 = Math.Log(1 + destinationParcel.EmploymentFoodBuffer2); totEmpBuffer2 = Math.Log(1 + destinationParcel.EmploymentTotalBuffer2); retailBuffer2 = Math.Log(1 + destinationParcel.EmploymentRetailBuffer2); } var carOwnership = person.GetCarOwnershipSegment(); // household inputs var onePersonHouseholdFlag = household.IsOnePersonHousehold.ToFlag(); //var householdInc75KP = household.Has75KPlusIncome; var votALSegment = tour.GetVotALSegment(); var transitAccessSegment = household.ResidenceParcel.TransitAccessSegment(); var totalAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId] [Global.Settings.Purposes.HomeBasedComposite][carOwnership][votALSegment][transitAccessSegment]; var homeFoodBuffer2 = Math.Log(1 + household.ResidenceParcel.EmploymentFoodBuffer2); var homeTotEmpBuffer2 = Math.Log(1 + household.ResidenceParcel.EmploymentTotalBuffer2); var homeRetailBuffer2 = Math.Log(1 + household.ResidenceParcel.EmploymentRetailBuffer2); // person-day inputs var homeBasedTours = personDay.HomeBasedTours; var simulatedToursFlag = personDay.SimulatedToursExist().ToFlag(); var simulatedBusinessStops = personDay.SimulatedBusinessStops; int simulatedBusinessStopsFlag = simulatedBusinessStops > 0 ? 1 : 0; var simulatedSchoolStops = personDay.SimulatedSchoolStops; var simulatedEscortStops = personDay.SimulatedEscortStops; var simulatedPersonalBusinessStops = personDay.SimulatedPersonalBusinessStops; var simulatedShoppingStops = personDay.SimulatedShoppingStops; var simulatedMealStops = personDay.SimulatedMealStops; var simulatedSocialStops = personDay.SimulatedSocialStops; var simulatedRecreationStops = personDay.SimulatedRecreationStops; var simulatedMedicalStops = personDay.SimulatedMedicalStops; var primaryFamilyTimeFlag = householdDay.PrimaryPriorityTimeFlag; // tour inputs var hovDriverTourFlag = tour.IsHovDriverMode().ToFlag(); var hovPassengerTourFlag = tour.IsHovPassengerMode().ToFlag(); var transitTourFlag = tour.IsTransitMode().ToFlag(); var walkTourFlag = tour.IsWalkMode().ToFlag(); var bikeTourFlag = tour.IsBikeMode().ToFlag(); var autoTourFlag = tour.IsAnAutoMode().ToFlag(); var notHomeBasedTourFlag = (!tour.IsHomeBasedTour).ToFlag(); var workTourFlag = tour.IsWorkPurpose().ToFlag(); var businessTourFlag = tour.IsBusinessPurpose().ToFlag(); var personalBusinessTourFlag = tour.IsPersonalBusinessPurpose().ToFlag(); var socialTourFlag = tour.IsSocialPurpose().ToFlag(); var socialOrRecreationTourFlag = tour.IsSocialOrRecreationPurpose().ToFlag(); var schoolTourFlag = tour.IsSchoolPurpose().ToFlag(); var escortTourFlag = tour.IsEscortPurpose().ToFlag(); var shoppingTourFlag = tour.IsShoppingPurpose().ToFlag(); // trip inputs var oneSimulatedTripFlag = halfTour.OneSimulatedTripFlag; var twoSimulatedTripsFlag = halfTour.TwoSimulatedTripsFlag; var threeSimulatedTripsFlag = halfTour.ThreeSimulatedTripsFlag; var fourSimulatedTripsFlag = halfTour.FourSimulatedTripsFlag; var fivePlusSimulatedTripsFlag = halfTour.FivePlusSimulatedTripsFlag; var twoPlusSimulatedTripsFlag = twoSimulatedTripsFlag + threeSimulatedTripsFlag + fourSimulatedTripsFlag + fivePlusSimulatedTripsFlag; var halfTourFromOriginFlag = trip.IsHalfTourFromOrigin.ToFlag(); var halfTourFromDestinationFlag = (!trip.IsHalfTourFromOrigin).ToFlag(); var beforeMandatoryDestinationFlag = trip.IsBeforeMandatoryDestination().ToFlag(); // remaining inputs, including joint tour variables var remainingToursCount = personDay.HomeBasedTours - personDay.GetTotalSimulatedTours(); var destinationDepartureTime = trip.IsHalfTourFromOrigin // first trip in half tour, use tour destination time ? trip.Sequence == 1 ? tour.DestinationArrivalTime : trip.GetPreviousTrip().ArrivalTime : trip.Sequence == 1 ? tour.DestinationDepartureTime : trip.GetPreviousTrip().ArrivalTime; //var time = trip.IsHalfTourFromOrigin ? tour.DestinationArrivalTime : tour.DestinationDepartureTime; var time = destinationDepartureTime; bool timeIsAvailableForAnotherTrip = true; if ((trip.IsHalfTourFromOrigin && time < Global.Settings.Times.FourAM) || (!trip.IsHalfTourFromOrigin && time > Global.Settings.Times.TwoAM)) { timeIsAvailableForAnotherTrip = false; } bool stopsNeeded = false; //if ((halfTour.SimulatedTrips <= 5) // && (timeIsAvailableForAnotherTrip) // && (trip.Direction == 2) // &&((trip.Tour.Sequence == trip.PersonDay.TotalCreatedTours) // && ((simulatedSchoolStops == 0 && personDay.SchoolStops > 0) // ||(simulatedBusinessStops == 0 && personDay.BusinessStops > 0) // ||(simulatedEscortStops == 0 && personDay.EscortStops > 0) // ||(simulatedPersonalBusinessStops == 0 && personDay.PersonalBusinessStops > 0) // ||(simulatedShoppingStops == 0 && personDay.ShoppingStops > 0) // ||(simulatedSocialStops == 0 && personDay.SocialStops > 0)))) { // stopsNeeded = true; //} var from7AMto9AMFlag = (time >= Global.Settings.Times.SevenAM && time < Global.Settings.Times.NineAM).ToFlag(); var from9AMto3PMFlag = (time >= Global.Settings.Times.NineAM && time < Global.Settings.Times.ThreePM).ToFlag(); var from3PMto6PMFlag = (time >= Global.Settings.Times.ThreePM && time < Global.Settings.Times.SixPM).ToFlag(); var from6PMto10PMFlag = (time >= Global.Settings.Times.SixPM && time < Global.Settings.Times.TenPM).ToFlag(); var from10PMto7AMFlag = (time >= Global.Settings.Times.TenPM).ToFlag(); var from9AMto11AMFlag = (time >= Global.Settings.Times.NineAM && time < Global.Settings.Times.ElevenAM).ToFlag(); var from11AMto1PMFlag = (time >= Global.Settings.Times.ElevenAM && time < Global.Settings.Times.OnePM).ToFlag(); var from1PMto3PMFlag = (time >= Global.Settings.Times.OnePM && time < Global.Settings.Times.ThreePM).ToFlag(); var from3PMto5PMFlag = (time >= Global.Settings.Times.ThreePM && time < Global.Settings.Times.FivePM).ToFlag(); var from7PMto9PMFlag = (time >= Global.Settings.Times.SevenPM && time < Global.Settings.Times.NinePM).ToFlag(); var from9PMto11PMFlag = (time >= Global.Settings.Times.NinePM && time < Global.Settings.Times.ElevenPM).ToFlag(); var from11PMto7AMFlag = (time >= Global.Settings.Times.ElevenPM).ToFlag(); IEnumerable <PersonDayWrapper> orderedPersonDays = householdDay.PersonDays.OrderBy(p => p.GetJointTourParticipationPriority()).ToList().Cast <PersonDayWrapper>(); int numChildrenOnJointTour = 0; int numAdultsOnJointTour = 0; int totHHToursJT = 0; //int totHHStopsJT=0; TimeWindow timeWindow = new TimeWindow(); if (tour.JointTourSequence > 0) { foreach (PersonDayWrapper pDay in householdDay.PersonDays) { var tInJoint = (TourWrapper)pDay.Tours.Find(t => t.JointTourSequence == tour.JointTourSequence); if (!(tInJoint == null)) { // set jointTour time window timeWindow.IncorporateAnotherTimeWindow(tInJoint.PersonDay.TimeWindow); totHHToursJT = personDay.HomeBasedTours + totHHToursJT; if (pDay.Person.Age < 18) { numChildrenOnJointTour++; } if (pDay.Person.Age >= 18) { numAdultsOnJointTour++; } } } } else if (trip.Direction == Global.Settings.TourDirections.OriginToDestination && tour.FullHalfTour1Sequence > 0) { foreach (PersonDayWrapper pDay in householdDay.PersonDays) { var tInJoint = (TourWrapper)pDay.Tours.Find(t => t.FullHalfTour1Sequence == tour.FullHalfTour1Sequence); if (!(tInJoint == null)) { // set jointTour time window timeWindow.IncorporateAnotherTimeWindow(tInJoint.PersonDay.TimeWindow); timeWindow.IncorporateAnotherTimeWindow(tInJoint.PersonDay.TimeWindow); totHHToursJT = personDay.HomeBasedTours + totHHToursJT; if (pDay.Person.Age < 18) { numChildrenOnJointTour++; } if (pDay.Person.Age >= 18) { numAdultsOnJointTour++; } } } } else if (trip.Direction == Global.Settings.TourDirections.DestinationToOrigin && tour.FullHalfTour2Sequence > 0) { foreach (PersonDayWrapper pDay in householdDay.PersonDays) { var tInJoint = (TourWrapper)pDay.Tours.Find(t => t.FullHalfTour2Sequence == tour.FullHalfTour2Sequence); if (!(tInJoint == null)) { // set jointTour time window timeWindow.IncorporateAnotherTimeWindow(tInJoint.PersonDay.TimeWindow); timeWindow.IncorporateAnotherTimeWindow(tInJoint.PersonDay.TimeWindow); totHHToursJT = personDay.HomeBasedTours + totHHToursJT; if (pDay.Person.Age < 18) { numChildrenOnJointTour++; } if (pDay.Person.Age >= 18) { numAdultsOnJointTour++; } } } } else if (tour.ParentTour == null) { timeWindow.IncorporateAnotherTimeWindow(personDay.TimeWindow); } else { timeWindow.IncorporateAnotherTimeWindow(tour.ParentTour.TimeWindow); } timeWindow.SetBusyMinutes(Global.Settings.Times.EndOfRelevantWindow, Global.Settings.Times.MinutesInADay + 1); // time window in minutes for yet unmodeled portion of halftour, only consider persons on this trip var availableWindow = timeWindow.AvailableWindow(destinationDepartureTime, Global.Settings.TimeDirections.Both); var timePressure = 1000 * remainingToursCount / (Math.Max(1D, availableWindow)); //alternative.AddUtilityTerm(98, 1000 * remainingToursCount / (Math.Max(1D, maxWindowRemaining))); //var duration = availableWindow / 60D; // connectivity attributes //var c34Ratio = trip.OriginParcel.C34RatioBuffer1(); var adis = 0.0; var logDist = 0.0; var minute = DayPeriod.BigDayPeriods[DayPeriod.MIDDAY].Start; //distance from origin to destination if (tour.OriginParcel != null && tour.DestinationParcel != null) { if (trip.Direction == Global.Settings.TourDirections.OriginToDestination) { adis = ImpedanceRoster.GetValue("distance", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, minute, tour.OriginParcel, destinationParcel).Variable; } else { adis = ImpedanceRoster.GetValue("distance", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, minute, destinationParcel, tour.OriginParcel).Variable; } logDist = Math.Log(1 + adis); } // 0 - NO MORE STOPS var alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.NoneOrHome, !stopsNeeded, choice == Global.Settings.Purposes.NoneOrHome); alternative.Choice = Global.Settings.Purposes.NoneOrHome; //alternative.AddNestedAlternative(_nestedAlternativeIds[0], _nestedAlternativeIndexes[0], THETA_PARAMETER); alternative.AddUtilityTerm(1, oneSimulatedTripFlag); alternative.AddUtilityTerm(2, twoSimulatedTripsFlag); alternative.AddUtilityTerm(2, threeSimulatedTripsFlag); alternative.AddUtilityTerm(2, fourSimulatedTripsFlag); alternative.AddUtilityTerm(2, fivePlusSimulatedTripsFlag); alternative.AddUtilityTerm(6, transitTourFlag); alternative.AddUtilityTerm(7, bikeTourFlag); alternative.AddUtilityTerm(8, walkTourFlag); alternative.AddUtilityTerm(9, jointHalfTour); alternative.AddUtilityTerm(10, halfTourFromOriginFlag); alternative.AddUtilityTerm(11, totalAggregateLogsum); alternative.AddUtilityTerm(12, businessTourFlag); alternative.AddUtilityTerm(13, personalBusinessTourFlag); alternative.AddUtilityTerm(14, socialTourFlag); //alternative.AddUtilityTerm(15, schoolTourFlag); alternative.AddUtilityTerm(16, escortTourFlag); alternative.AddUtilityTerm(17, shoppingTourFlag); alternative.AddUtilityTerm(18, timePressure); //alternative.AddUtilityTerm(19, primaryFamilyTimeFlag); //alternative.AddUtilityTerm(15, from11PMto7AMFlag); //alternative.AddUtilityTerm(1, twoSimulatedTripsFlag * halfTourFromOriginFlag * isIndividualTour); //alternative.AddUtilityTerm(2, threeSimulatedTripsFlag * halfTourFromOriginFlag * isIndividualTour); //alternative.AddUtilityTerm(3, fourSimulatedTripsFlag * halfTourFromOriginFlag * isIndividualTour); //alternative.AddUtilityTerm(4, fivePlusSimulatedTripsFlag * halfTourFromOriginFlag * isIndividualTour); //alternative.AddUtilityTerm(5, twoSimulatedTripsFlag * halfTourFromDestinationFlag * isIndividualTour); //alternative.AddUtilityTerm(6, threeSimulatedTripsFlag * halfTourFromDestinationFlag * isIndividualTour); //alternative.AddUtilityTerm(7, fourSimulatedTripsFlag * halfTourFromDestinationFlag * isIndividualTour); //alternative.AddUtilityTerm(8, fivePlusSimulatedTripsFlag * halfTourFromDestinationFlag * isIndividualTour); //alternative.AddUtilityTerm(9, homeBasedTours * isIndividualTour); //alternative.AddUtilityTerm(10, homeBasedTours * isJointTour); //alternative.AddUtilityTerm(11, notHomeBasedTourFlag); //alternative.AddUtilityTerm(12, beforeMandatoryDestinationFlag*isJointTour); //alternative.AddUtilityTerm(13, beforeMandatoryDestinationFlag); //alternative.AddUtilityTerm(14, numAdultsOnJointTour); //alternative.AddUtilityTerm(15, numChildrenOnJointTour); //alternative.AddUtilityTerm(16, totHHToursJT); // alternative.AddUtilityTerm(17, totHHStopsJT); //alternative.AddUtilityTerm(22, (threeSimulatedTripsFlag + fourSimulatedTripsFlag + fivePlusSimulatedTripsFlag) * halfTourFromOriginFlag * isJointTour); //alternative.AddUtilityTerm(26, threeSimulatedTripsFlag * halfTourFromDestinationFlag * isJointTour); //alternative.AddUtilityTerm(27, fourSimulatedTripsFlag * halfTourFromDestinationFlag * isJointTour); //alternative.AddUtilityTerm(28, fivePlusSimulatedTripsFlag * halfTourFromDestinationFlag * isJointTour); // 1 - BUSINESS STOP //if (personDay.BusinessStops > 0 && (tour.DestinationPurpose <= Global.Settings.Purposes.School || tour.DestinationPurpose == Global.Settings.Purposes.Business)) { // JLB 20130704 business stops are allowed on escort tours per data prep alternative = choiceProbabilityCalculator.GetAlternative(1, (personDay.BusinessStops > 0 && (tour.DestinationPurpose <= Global.Settings.Purposes.Escort || tour.DestinationPurpose == Global.Settings.Purposes.Business) && (halfTour.SimulatedTrips <= 5) && timeIsAvailableForAnotherTrip), choice == Global.Settings.Purposes.Business); alternative.Choice = Global.Settings.Purposes.Business; //alternative.AddNestedAlternative(_nestedAlternativeIds[1], _nestedAlternativeIndexes[1], THETA_PARAMETER); //alternative.AddUtilityTerm(32, isIndividualTour); alternative.AddUtilityTerm(32, 1.0); alternative.AddUtilityTerm(33, businessTourFlag); //alternative.AddUtilityTerm(34, schoolTourFlag); //alternative.AddUtilityTerm(35, halfTourFromOriginFlag); //alternative.AddUtilityTerm(36, simulatedBusinessStops); //alternative.AddUtilityTerm(37, simulatedBusinessStopsFlag); //alternative.AddUtilityTerm(39, duration); //alternative.AddUtilityTerm(40, from9AMto11AMFlag + from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag); alternative.AddUtilityTerm(40, from9AMto3PMFlag + from3PMto6PMFlag); //alternative.AddUtilityTerm(42, logDist); //alternative.AddUtilityTerm(43, transitTourFlag); //alternative.AddUtilityTerm(44, (person.IsPartTimeWorker).ToFlag()); //GV: 21. aug - I commented out as it is the only logsum in the model //alternative.AddUtilityTerm(46, totalAggregateLogsum); //alternative.AddUtilityTerm(47,totEmpBuffer2); //alternative.AddUtilityTerm(48, hovDriverTourFlag + hovPassengerTourFlag); // 2 - SCHOOL STOP alternative = choiceProbabilityCalculator.GetAlternative(2, (((personDay.SchoolStops > 0 && tour.DestinationPurpose <= Global.Settings.Purposes.School) || (isJointTour == 1)) && halfTour.SimulatedTrips <= 5 && timeIsAvailableForAnotherTrip), choice == Global.Settings.Purposes.School); alternative.Choice = Global.Settings.Purposes.School; //alternative.AddNestedAlternative(_nestedAlternativeIds[2], _nestedAlternativeIndexes[2], THETA_PARAMETER); //alternative.AddUtilityTerm(51, workTourFlag); alternative.AddUtilityTerm(51, 1.0); //alternative.AddUtilityTerm(52, schoolTourFlag); //alternative.AddUtilityTerm(53, halfTourFromOriginFlag); //alternative.AddUtilityTerm(54, simulatedSchoolStops); //alternative.AddUtilityTerm(55, remainingToursCount); //alternative.AddUtilityTerm(56, duration); //alternative.AddUtilityTerm(57, from7AMto9AMFlag + from7PMto9PMFlag + from9PMto11PMFlag + from11PMto7AMFlag); alternative.AddUtilityTerm(57, from7AMto9AMFlag + from9AMto3PMFlag + from10PMto7AMFlag); //alternative.AddUtilityTerm(58, oneSimulatedTripFlag); //alternative.AddUtilityTerm(59, logDist); alternative.AddUtilityTerm(61, jointHalfOfFullJointHalfTour * numChildrenOnJointTour); //alternative.AddUtilityTerm(65, (person.Age < 12).ToFlag()); //alternative.AddUtilityTerm(66, (person.IsUniversityStudent).ToFlag()); // 3 - ESCORT STOP //if ((personDay.EscortStops > 0 && (tour.DestinationPurpose <= Global.Settings.Purposes.Escort || tour.DestinationPurpose == Global.Settings.Purposes.Business)) || (isJointTour==1)) { // JLB 20130704 no escort stops allowed on business tours per data prep alternative = choiceProbabilityCalculator.GetAlternative(3, (((personDay.EscortStops > 0 && tour.DestinationPurpose <= Global.Settings.Purposes.Escort) || (isJointTour == 1)) && halfTour.SimulatedTrips <= 5 && timeIsAvailableForAnotherTrip), choice == Global.Settings.Purposes.Escort); alternative.Choice = Global.Settings.Purposes.Escort; //alternative.AddNestedAlternative(_nestedAlternativeIds[3], _nestedAlternativeIndexes[3], THETA_PARAMETER); alternative.AddUtilityTerm(71, 1.0); //alternative.AddUtilityTerm(72, workTourFlag + schoolTourFlag); //alternative.AddUtilityTerm(72, isJointTour); //alternative.AddUtilityTerm(74, escortTourFlag); //alternative.AddUtilityTerm(75, socialOrRecreationTourFlag); //alternative.AddUtilityTerm(76, remainingToursCount); //alternative.AddUtilityTerm(77, duration); alternative.AddUtilityTerm(78, from7AMto9AMFlag); //alternative.AddUtilityTerm(79, from9AMto11AMFlag + from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag); //alternative.AddUtilityTerm(81, hovDriverTourFlag); //alternative.AddUtilityTerm(82, hovPassengerTourFlag); //alternative.AddUtilityTerm(83, simulatedEscortStops * isJointTour); //alternative.AddUtilityTerm(84, simulatedEscortStops * isIndividualTour); //alternative.AddUtilityTerm(85, totalAggregateLogsum); //alternative.AddUtilityTerm(86, jointHalfOfFullJointHalfTour); //alternative.AddUtilityTerm(88, enrollmentK8Buffer2); //alternative.AddUtilityTerm(89, numChildrenOnJointTour); //alternative.AddUtilityTerm(90, halfTourFromOriginFlag); // 4 - PERSONAL BUSINESS STOP alternative = choiceProbabilityCalculator.GetAlternative(4, ((personDay.PersonalBusinessStops > 0 || isJointTour == 1) && halfTour.SimulatedTrips <= 5 && timeIsAvailableForAnotherTrip), choice == Global.Settings.Purposes.PersonalBusiness); alternative.Choice = Global.Settings.Purposes.PersonalBusiness; //alternative.AddNestedAlternative(_nestedAlternativeIds[4], _nestedAlternativeIndexes[4], THETA_PARAMETER); alternative.AddUtilityTerm(91, 1.0); //alternative.AddUtilityTerm(92, (workTourFlag + schoolTourFlag + businessTourFlag)); //alternative.AddUtilityTerm(92, isJointTour); //alternative.AddUtilityTerm(93, escortTourFlag); //alternative.AddUtilityTerm(94, personalBusinessOrMedicalTourFlag * isIndividualTour); //alternative.AddUtilityTerm(95, shoppingTourFlag); //alternative.AddUtilityTerm(96, mealTourFlag); //alternative.AddUtilityTerm(97, socialOrRecreationTourFlag); //alternative.AddUtilityTerm(98, halfTourFromOriginFlag); //alternative.AddUtilityTerm(99, simulatedPersonalBusinessStops * isIndividualTour); //alternative.AddUtilityTerm(100, simulatedPersonalBusinessStops * isJointTour); //alternative.AddUtilityTerm(101, duration); //alternative.AddUtilityTerm(102, (from7AMto9AMFlag + from7PMto9PMFlag + from9PMto11PMFlag + from11PMto7AMFlag)); //alternative.AddUtilityTerm(103, from9AMto11AMFlag + from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag); alternative.AddUtilityTerm(103, from9AMto3PMFlag + from3PMto6PMFlag); //alternative.AddUtilityTerm(105, hovDriverTourFlag); //alternative.AddUtilityTerm(106, hovPassengerTourFlag); //alternative.AddUtilityTerm(109, jointHalfOfFullJointHalfTour); //alternative.AddUtilityTerm(110, totEmpBuffer2); //alternative.AddUtilityTerm(111, totalAggregateLogsum); //alternative.AddUtilityTerm(112, personalBusinessOrMedicalTourFlag * isJointTour); // 5 - SHOPPING STOP alternative = choiceProbabilityCalculator.GetAlternative(5, ((personDay.ShoppingStops > 0 || isJointTour == 1) && halfTour.SimulatedTrips <= 5 && timeIsAvailableForAnotherTrip), choice == Global.Settings.Purposes.Shopping); alternative.Choice = Global.Settings.Purposes.Shopping; //alternative.AddNestedAlternative(_nestedAlternativeIds[5], _nestedAlternativeIndexes[5], THETA_PARAMETER); alternative.AddUtilityTerm(121, 1.0); //alternative.AddUtilityTerm(122, workTourFlag + schoolTourFlag + businessTourFlag); //alternative.AddUtilityTerm(122, isJointTour); //alternative.AddUtilityTerm(123, escortTourFlag); //alternative.AddUtilityTerm(124, personalBusinessOrMedicalTourFlag); //alternative.AddUtilityTerm(125, shoppingTourFlag * isIndividualTour); //alternative.AddUtilityTerm(125, shoppingTourFlag); //alternative.AddUtilityTerm(126, mealTourFlag); //alternative.AddUtilityTerm(127, socialOrRecreationTourFlag); //alternative.AddUtilityTerm(128, halfTourFromOriginFlag); //alternative.AddUtilityTerm(129, simulatedShoppingStops * isIndividualTour); //alternative.AddUtilityTerm(130, simulatedShoppingStops * isJointTour); //alternative.AddUtilityTerm(131, duration); //alternative.AddUtilityTerm(132, from7AMto9AMFlag + from9PMto11PMFlag + from11PMto7AMFlag); //alternative.AddUtilityTerm(133, (from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag)); //alternative.AddUtilityTerm(132, from7AMto9AMFlag + from6PMto10PMFlag); alternative.AddUtilityTerm(133, (from9AMto3PMFlag + from3PMto6PMFlag + from6PMto10PMFlag)); //alternative.AddUtilityTerm(134, adultFemaleOnJointTour); //alternative.AddUtilityTerm(135, hovDriverTourFlag); //alternative.AddUtilityTerm(136, hovPassengerTourFlag); //alternative.AddUtilityTerm(137, Math.Log(1 + adis)); //alternative.AddUtilityTerm(138, shoppingTourFlag * isJointTour); //alternative.AddUtilityTerm(140, shoppingAggregateLogsum); //alternative.AddUtilityTerm(141, retailBuffer2); //alternative.AddUtilityTerm(142, numChildrenOnJointTour); //alternative.AddUtilityTerm(143, (household.Has100KPlusIncome).ToFlag()); alternative.AddUtilityTerm(134, primaryFamilyTimeFlag); // 6 - MEAL STOP //alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Meal, false, choice == Global.Settings.Purposes.Meal); //alternative.Choice = Global.Settings.Purposes.Meal; //alternative.AddNestedAlternative(12, 2, THETA_PARAMETER); // 6 - SOCIAL (OR RECREATION) STOP alternative = choiceProbabilityCalculator.GetAlternative(6, ((personDay.SocialStops > 0 || isJointTour == 1) && halfTour.SimulatedTrips <= 5 && timeIsAvailableForAnotherTrip), choice == Global.Settings.Purposes.Social); alternative.Choice = Global.Settings.Purposes.Social; //alternative.AddNestedAlternative(_nestedAlternativeIds[6], _nestedAlternativeIndexes[6], THETA_PARAMETER); alternative.AddUtilityTerm(181, 1.0); //alternative.AddUtilityTerm(182, workTourFlag + schoolTourFlag + businessTourFlag); //alternative.AddUtilityTerm(182, isJointTour); //alternative.AddUtilityTerm(183, escortTourFlag); //alternative.AddUtilityTerm(184, personalBusinessOrMedicalTourFlag); //alternative.AddUtilityTerm(185, shoppingTourFlag); //alternative.AddUtilityTerm(186, mealTourFlag); //alternative.AddUtilityTerm(187, socialOrRecreationTourFlag); //alternative.AddUtilityTerm(188, halfTourFromOriginFlag); //alternative.AddUtilityTerm(189, simulatedSocialStops * isIndividualTour); //alternative.AddUtilityTerm(197, simulatedSocialStops * isJointTour); //alternative.AddUtilityTerm(190, remainingToursCount); //alternative.AddUtilityTerm(191, duration); //alternative.AddUtilityTerm(192, from7AMto9AMFlag + from11PMto7AMFlag); //alternative.AddUtilityTerm(192, from7AMto9AMFlag); alternative.AddUtilityTerm(192, from9AMto3PMFlag + from3PMto6PMFlag + from6PMto10PMFlag); //alternative.AddUtilityTerm(194, hovDriverTourFlag); //alternative.AddUtilityTerm(195, hovPassengerTourFlag); //alternative.AddUtilityTerm(196, logDist); //alternative.AddUtilityTerm(200, numAdultsOnJointTour); // 8 - RECREATION STOP //alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Recreation, false, choice == Global.Settings.Purposes.Recreation); //alternative.Choice = Global.Settings.Purposes.Recreation; //alternative.AddNestedAlternative(12, 2, THETA_PARAMETER); // 9 - MEDICAL STOP //alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Medical, false, choice == Global.Settings.Purposes.Medical); //alternative.Choice = Global.Settings.Purposes.Medical; //alternative.AddNestedAlternative(12, 2, THETA_PARAMETER); }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITourWrapper tour, IEnumerable <PathTypeModel> pathTypeModels, IParcelWrapper destinationParcel, int householdCars, int choice = Constants.DEFAULT_VALUE) { var household = tour.Household; var householdTotals = household.HouseholdTotals; var personDay = tour.PersonDay; var person = tour.Person; // household inputs var childrenUnder5 = householdTotals.ChildrenUnder5; var childrenAge5Through15 = householdTotals.ChildrenAge5Through15; // var nonworkingAdults = householdTotals.NonworkingAdults; // var retiredAdults = householdTotals.RetiredAdults; var onePersonHouseholdFlag = household.IsOnePersonHousehold.ToFlag(); var twoPersonHouseholdFlag = household.IsTwoPersonHousehold.ToFlag(); var noCarsInHouseholdFlag = household.GetFlagForNoCarsInHousehold(householdCars); var carsLessThanDriversFlag = household.GetFlagForCarsLessThanDrivers(householdCars); var carsLessThanWorkersFlag = household.GetFlagForCarsLessThanWorkers(householdCars); var income0To25KFlag = household.Has0To25KIncome.ToFlag(); // person inputs var maleFlag = person.IsMale.ToFlag(); var ageBetween51And98Flag = person.AgeIsBetween51And98.ToFlag(); var originParcel = tour.OriginParcel; var parkingDuration = ChoiceModelUtility.GetParkingDuration(person.IsFulltimeWorker); // parking at work is free if no paid parking at work and tour goes to usual workplace var destinationParkingCost = (Global.Configuration.ShouldRunPayToParkAtWorkplaceModel && tour.Person.UsualWorkParcel != null && destinationParcel == tour.Person.UsualWorkParcel && person.PaidParkingAtWorkplace == 0) ? 0.0 : destinationParcel.ParkingCostBuffer1(parkingDuration); double escortPercentage; double nonEscortPercentage; ChoiceModelUtility.SetEscortPercentages(personDay, out escortPercentage, out nonEscortPercentage); // var timeWindow = (originParcel == tour.Household.ResidenceParcel) ? personDay.TimeWindow : tour.ParentTour.TimeWindow; // var longestWindow = timeWindow.MaxAvailableMinutesAfter(1); // var totalWindow = timeWindow.TotalAvailableMinutesAfter(1); // var expectedDurationCurrentTour = person.IsFulltimeWorker ? Global.Settings.Times.EightHours : Global.Settings.Times.FourHours; // var expectedDurationOtherTours = (personDay.TotalTours - personDay.TotalSimulatedTours) * Global.Settings.Times.TwoHours; // var expectedDurationStops = (Math.Min(personDay.TotalStops,1) - Math.Min(personDay.TotalSimulatedStops,1)) * Global.Settings.Times.OneHour; // var totalExpectedDuration = expectedDurationCurrentTour + expectedDurationOtherTours + expectedDurationStops; foreach (var pathTypeModel in pathTypeModels) { var mode = pathTypeModel.Mode; var generalizedTime = pathTypeModel.GeneralizedTimeLogsum; // var travelTime = pathTypeModel.PathTime; // var travelCost = pathTypeModel.PathCost; var available = pathTypeModel.Available; //&& (travelTime < longestWindow); var alternative = choiceProbabilityCalculator.GetAlternative(mode, available, choice == mode); alternative.Choice = mode; alternative.AddNestedAlternative(_nestedAlternativeIds[pathTypeModel.Mode], _nestedAlternativeIndexes[pathTypeModel.Mode], THETA_PARAMETER); // if (mode == Global.Settings.Modes.ParkAndRide) { // Console.WriteLine("Park and ride logsum = {0}", generalizedTimeLogsum); // } if (!available) { continue; } alternative.AddUtilityTerm(2, generalizedTime * tour.TimeCoefficient); // alternative.AddUtility(3, Math.Log(1.0 - travelTime / longestWindow)); // alternative.AddUtility(4, travelTime < longestWindow - expectedDurationCurrentTour ? Math.Log(1.0 - travelTime / (longestWindow - expectedDurationCurrentTour)) : 0); // alternative.AddUtility(5, travelTime < longestWindow - expectedDurationCurrentTour ? 0 : 1); // alternative.AddUtility(6, travelTime < totalWindow - totalExpectedDuration ? Math.Log(1.0 - travelTime / (totalWindow - totalExpectedDuration)) : 0); // alternative.AddUtility(7, travelTime < totalWindow - totalExpectedDuration ? 0 : 1); // var vot = tour.TimeCoefficient / tour.CostCoefficient; if (mode == Global.Settings.Modes.ParkAndRide) { alternative.AddUtilityTerm(10, 1); alternative.AddUtilityTerm(11, noCarsInHouseholdFlag); alternative.AddUtilityTerm(13, carsLessThanWorkersFlag); // alternative.AddUtility(129, destinationParcel.MixedUse2Index1()); alternative.AddUtilityTerm(128, destinationParcel.TotalEmploymentDensity1()); alternative.AddUtilityTerm(127, destinationParcel.NetIntersectionDensity1()); // alternative.AddUtility(123, Math.Log(destinationParcel.StopsTransitBuffer1+1)); } else if (mode == Global.Settings.Modes.Transit) { alternative.AddUtilityTerm(20, 1); // alternative.AddUtility(129, destinationParcel.MixedUse2Index1()); alternative.AddUtilityTerm(128, destinationParcel.TotalEmploymentDensity1()); alternative.AddUtilityTerm(127, destinationParcel.NetIntersectionDensity1()); // alternative.AddUtility(126, originParcel.NetIntersectionDensity1()); // alternative.AddUtility(125, originParcel.HouseholdDensity1()); alternative.AddUtilityTerm(124, originParcel.MixedUse2Index1()); // alternative.AddUtility(123, Math.Log(destinationParcel.StopsTransitBuffer1+1)); // alternative.AddUtility(122, Math.Log(originParcel.StopsTransitBuffer1+1)); } else if (mode == Global.Settings.Modes.Hov3) { alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / Global.Configuration.Coefficients_HOV3CostDivisor_Work)); alternative.AddUtilityTerm(30, 1); alternative.AddUtilityTerm(31, childrenUnder5); alternative.AddUtilityTerm(32, childrenAge5Through15); // alternative.AddUtility(34, nonworkingAdults + retiredAdults); alternative.AddUtilityTerm(35, pathTypeModel.PathDistance.AlmostEquals(0) ? 0 : Math.Log(pathTypeModel.PathDistance)); alternative.AddUtilityTerm(38, onePersonHouseholdFlag); alternative.AddUtilityTerm(39, twoPersonHouseholdFlag); alternative.AddUtilityTerm(41, noCarsInHouseholdFlag); alternative.AddUtilityTerm(42, carsLessThanDriversFlag); alternative.AddUtilityTerm(133, escortPercentage); alternative.AddUtilityTerm(134, nonEscortPercentage); } else if (mode == Global.Settings.Modes.Hov2) { alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / Global.Configuration.Coefficients_HOV2CostDivisor_Work)); alternative.AddUtilityTerm(31, childrenUnder5); alternative.AddUtilityTerm(32, childrenAge5Through15); // alternative.AddUtility(34, nonworkingAdults + retiredAdults); alternative.AddUtilityTerm(35, pathTypeModel.PathDistance.AlmostEquals(0) ? 0 : Math.Log(pathTypeModel.PathDistance)); alternative.AddUtilityTerm(40, 1); alternative.AddUtilityTerm(41, noCarsInHouseholdFlag); alternative.AddUtilityTerm(42, carsLessThanDriversFlag); alternative.AddUtilityTerm(48, onePersonHouseholdFlag); alternative.AddUtilityTerm(133, escortPercentage); alternative.AddUtilityTerm(134, nonEscortPercentage); } else if (mode == Global.Settings.Modes.Sov) { alternative.AddUtilityTerm(1, (destinationParkingCost) * tour.CostCoefficient); alternative.AddUtilityTerm(50, 1); alternative.AddUtilityTerm(53, carsLessThanWorkersFlag); alternative.AddUtilityTerm(54, income0To25KFlag); alternative.AddUtilityTerm(131, escortPercentage); alternative.AddUtilityTerm(132, nonEscortPercentage); } else if (mode == Global.Settings.Modes.Bike) { var class1Dist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? ImpedanceRoster.GetValue("class1distance", mode, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0; var class2Dist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? ImpedanceRoster.GetValue("class2distance", mode, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0; // var worstDist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? // ImpedanceRoster.GetValue("worstdistance", mode, Global.Settings.PathTypes.FullNetwork, // Global.Settings.VotGroups.Medium, tour.DestinationArrivalTime,originParcel, destinationParcel).Variable : 0; alternative.AddUtilityTerm(60, 1); alternative.AddUtilityTerm(61, maleFlag); alternative.AddUtilityTerm(63, ageBetween51And98Flag); alternative.AddUtilityTerm(169, destinationParcel.MixedUse4Index1()); alternative.AddUtilityTerm(168, destinationParcel.TotalEmploymentDensity1()); // alternative.AddUtility(167, destinationParcel.NetIntersectionDensity1()); // alternative.AddUtility(166, originParcel.NetIntersectionDensity1()); // alternative.AddUtility(165, originParcel.HouseholdDensity1()); alternative.AddUtilityTerm(164, originParcel.MixedUse4Index1()); alternative.AddUtilityTerm(162, (class1Dist > 0).ToFlag()); alternative.AddUtilityTerm(162, (class2Dist > 0).ToFlag()); // alternative.AddUtility(163, (worstDist > 0).ToFlag()); } else if (mode == Global.Settings.Modes.Walk) { alternative.AddUtilityTerm(71, maleFlag); // alternative.AddUtility(73, ageBetween51And98Flag); alternative.AddUtilityTerm(179, destinationParcel.MixedUse4Index1()); // alternative.AddUtility(178, destinationParcel.TotalEmploymentDensity1()); // alternative.AddUtility(177, destinationParcel.NetIntersectionDensity1()); // alternative.AddUtility(176, originParcel.NetIntersectionDensity1()); // alternative.AddUtility(175, originParcel.HouseholdDensity1()); alternative.AddUtilityTerm(179, originParcel.MixedUse4Index1()); } } }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITourWrapper tour, IEnumerable <IPathTypeModel> pathTypeModels, IParcelWrapper destinationParcel, int householdCars, int choice = Constants.DEFAULT_VALUE) { var household = tour.Household; var householdTotals = household.HouseholdTotals; var personDay = tour.PersonDay; var person = tour.Person; // household inputs var childrenUnder5 = householdTotals.ChildrenUnder5; var childrenAge5Through15 = householdTotals.ChildrenAge5Through15; // var nonworkingAdults = householdTotals.NonworkingAdults; // var retiredAdults = householdTotals.RetiredAdults; var onePersonHouseholdFlag = household.IsOnePersonHousehold.ToFlag(); var twoPersonHouseholdFlag = household.IsTwoPersonHousehold.ToFlag(); var noCarsInHouseholdFlag = household.GetFlagForNoCarsInHousehold(householdCars); var carsLessThanDriversFlag = household.GetFlagForCarsLessThanDrivers(householdCars); var carsLessThanWorkersFlag = household.GetFlagForCarsLessThanWorkers(householdCars); var income0To25KFlag = household.Has0To25KIncome.ToFlag(); var income75kPlusFlag = household.Has75KPlusIncome.ToFlag(); // person inputs var maleFlag = person.IsMale.ToFlag(); var ageBetween51And98Flag = person.AgeIsBetween51And98.ToFlag(); var univStudentFlag = person.IsUniversityStudent.ToFlag(); var originParcel = tour.OriginParcel; var parkingDuration = ChoiceModelUtility.GetParkingDuration(person.IsFulltimeWorker); // parking at work is free if no paid parking at work and tour goes to usual workplace var destinationParkingCost = (Global.Configuration.ShouldRunPayToParkAtWorkplaceModel && tour.Person.UsualWorkParcel != null && destinationParcel == tour.Person.UsualWorkParcel && person.PaidParkingAtWorkplace == 0) ? 0.0 : destinationParcel.ParkingCostBuffer1(parkingDuration); double escortPercentage; double nonEscortPercentage; ChoiceModelUtility.SetEscortPercentages(personDay, out escortPercentage, out nonEscortPercentage); // var timeWindow = (originParcel == tour.Household.ResidenceParcel) ? personDay.TimeWindow : tour.ParentTour.TimeWindow; // var longestWindow = timeWindow.MaxAvailableMinutesAfter(1); // var totalWindow = timeWindow.TotalAvailableMinutesAfter(1); // var expectedDurationCurrentTour = person.IsFulltimeWorker ? Global.Settings.Times.EightHours : Global.Settings.Times.FourHours; // var expectedDurationOtherTours = (personDay.TotalTours - personDay.TotalSimulatedTours) * Global.Settings.Times.TwoHours; // var expectedDurationStops = (Math.Min(personDay.TotalStops,1) - Math.Min(personDay.TotalSimulatedStops,1)) * Global.Settings.Times.OneHour; // var totalExpectedDuration = expectedDurationCurrentTour + expectedDurationOtherTours + expectedDurationStops; // paidRideShare is a special case if (Global.Configuration.PaidRideShareModeIsAvailable) { var pathTypeExtra = pathTypeModels.First(x => x.Mode == Global.Settings.Modes.PaidRideShare); var modeExtra = Global.Settings.Modes.PaidRideShare; var availableExtra = pathTypeExtra.Available; var generalizedTimeLogsumExtra = pathTypeExtra.GeneralizedTimeLogsum; var distanceExtra = pathTypeExtra.PathDistance; var alternative = choiceProbabilityCalculator.GetAlternative(modeExtra - 1, availableExtra, choice == modeExtra); alternative.Choice = modeExtra; alternative.AddNestedAlternative(_nestedAlternativeIds[modeExtra], _nestedAlternativeIndexes[modeExtra], THETA_PARAMETER); if (availableExtra) { var extraCostPerMile = Global.Configuration.AV_PaidRideShareModeUsesAVs ? Global.Configuration.AV_PaidRideShare_ExtraCostPerDistanceUnit : Global.Configuration.PaidRideShare_ExtraCostPerDistanceUnit; var fixedCostPerRide = Global.Configuration.AV_PaidRideShareModeUsesAVs ? Global.Configuration.AV_PaidRideShare_FixedCostPerRide : Global.Configuration.PaidRideShare_FixedCostPerRide; var autoTimeCoefficient = Global.Configuration.AV_PaidRideShareModeUsesAVs ? tour.TimeCoefficient * (1.0 - Global.Configuration.AV_InVehicleTimeCoefficientDiscountFactor) : tour.TimeCoefficient; alternative.AddUtilityTerm(2, generalizedTimeLogsumExtra * autoTimeCoefficient); alternative.AddUtilityTerm(2, distanceExtra * extraCostPerMile * tour.CostCoefficient); alternative.AddUtilityTerm(2, fixedCostPerRide * tour.CostCoefficient); var modeConstant = Global.Configuration.AV_PaidRideShareModeUsesAVs ? Global.Configuration.AV_PaidRideShare_ModeConstant + Global.Configuration.AV_PaidRideShare_DensityCoefficient * Math.Min(originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2, 6000) + Global.Configuration.AV_PaidRideShare_AVOwnerCoefficient * (household.OwnsAutomatedVehicles > 0).ToFlag() : Global.Configuration.PaidRideShare_ModeConstant + Global.Configuration.PaidRideShare_DensityCoefficient * Math.Min(originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2, 6000); alternative.AddUtilityTerm(90, modeConstant); alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_Age26to35Coefficient * tour.Person.AgeIsBetween26And35.ToFlag()); alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_Age18to25Coefficient * tour.Person.AgeIsBetween18And25.ToFlag()); alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_AgeOver65Coefficient * (tour.Person.Age >= 65).ToFlag()); } } foreach (var pathTypeModel in pathTypeModels) { var mode = pathTypeModel.Mode; var generalizedTimeLogsum = pathTypeModel.GeneralizedTimeLogsum; // var travelTime = pathTypeModel.PathTime; // var travelCost = pathTypeModel.PathCost; var available = pathTypeModel.Available; //&& (travelTime < longestWindow); var alternative = choiceProbabilityCalculator.GetAlternative(mode, available, choice == mode); alternative.Choice = mode; alternative.AddNestedAlternative(_nestedAlternativeIds[pathTypeModel.Mode], _nestedAlternativeIndexes[pathTypeModel.Mode], THETA_PARAMETER); // if (mode == Global.Settings.Modes.ParkAndRide) { // Console.WriteLine("Park and ride logsum = {0}", generalizedTimeLogsum); // } if (!available) { continue; } var modeTimeCoefficient = (Global.Configuration.AV_IncludeAutoTypeChoice && household.OwnsAutomatedVehicles > 0 && mode >= Global.Settings.Modes.Sov && mode <= Global.Settings.Modes.Hov3) ? tour.TimeCoefficient * (1.0 - Global.Configuration.AV_InVehicleTimeCoefficientDiscountFactor) : tour.TimeCoefficient; alternative.AddUtilityTerm(2, generalizedTimeLogsum * modeTimeCoefficient); // alternative.AddUtility(3, Math.Log(1.0 - travelTime / longestWindow)); // alternative.AddUtility(4, travelTime < longestWindow - expectedDurationCurrentTour ? Math.Log(1.0 - travelTime / (longestWindow - expectedDurationCurrentTour)) : 0); // alternative.AddUtility(5, travelTime < longestWindow - expectedDurationCurrentTour ? 0 : 1); // alternative.AddUtility(6, travelTime < totalWindow - totalExpectedDuration ? Math.Log(1.0 - travelTime / (totalWindow - totalExpectedDuration)) : 0); // alternative.AddUtility(7, travelTime < totalWindow - totalExpectedDuration ? 0 : 1); // var vot = tour.TimeCoefficient / tour.CostCoefficient; if (mode == Global.Settings.Modes.ParkAndRide) { alternative.AddUtilityTerm(10, 1); alternative.AddUtilityTerm(11, noCarsInHouseholdFlag); alternative.AddUtilityTerm(13, carsLessThanWorkersFlag); // alternative.AddUtility(129, destinationParcel.MixedUse2Index1()); alternative.AddUtilityTerm(130, Math.Log(destinationParcel.TotalEmploymentDensity1() + 1) * 2553.0 / Math.Log(2553.0)); alternative.AddUtilityTerm(128, destinationParcel.TotalEmploymentDensity1()); alternative.AddUtilityTerm(127, destinationParcel.NetIntersectionDensity1()); // alternative.AddUtility(123, Math.Log(destinationParcel.StopsTransitBuffer1+1)); } else if (mode == Global.Settings.Modes.Transit) { alternative.AddUtilityTerm(20, 1); // alternative.AddUtility(129, destinationParcel.MixedUse2Index1()); alternative.AddUtilityTerm(130, Math.Log(destinationParcel.TotalEmploymentDensity1() + 1) * 2553.0 / Math.Log(2553.0)); alternative.AddUtilityTerm(128, destinationParcel.TotalEmploymentDensity1()); alternative.AddUtilityTerm(127, destinationParcel.NetIntersectionDensity1()); // alternative.AddUtility(126, originParcel.NetIntersectionDensity1()); // alternative.AddUtility(125, originParcel.HouseholdDensity1()); alternative.AddUtilityTerm(124, originParcel.MixedUse2Index1()); // alternative.AddUtility(123, Math.Log(destinationParcel.StopsTransitBuffer1+1)); // alternative.AddUtility(122, Math.Log(originParcel.StopsTransitBuffer1+1)); alternative.AddUtilityTerm(180, univStudentFlag); alternative.AddUtilityTerm(100, income75kPlusFlag); } else if (mode == Global.Settings.Modes.Hov3) { alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / Global.Configuration.Coefficients_HOV3CostDivisor_Work)); alternative.AddUtilityTerm(30, 1); alternative.AddUtilityTerm(31, childrenUnder5); alternative.AddUtilityTerm(32, childrenAge5Through15); // alternative.AddUtility(34, nonworkingAdults + retiredAdults); alternative.AddUtilityTerm(35, ((double)pathTypeModel.PathDistance).AlmostEquals(0) ? 0 : Math.Log(pathTypeModel.PathDistance)); alternative.AddUtilityTerm(38, onePersonHouseholdFlag); alternative.AddUtilityTerm(39, twoPersonHouseholdFlag); alternative.AddUtilityTerm(41, noCarsInHouseholdFlag); alternative.AddUtilityTerm(42, carsLessThanDriversFlag); alternative.AddUtilityTerm(133, escortPercentage); alternative.AddUtilityTerm(134, nonEscortPercentage); } else if (mode == Global.Settings.Modes.Hov2) { alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / Global.Configuration.Coefficients_HOV2CostDivisor_Work)); alternative.AddUtilityTerm(31, childrenUnder5); alternative.AddUtilityTerm(32, childrenAge5Through15); // alternative.AddUtility(34, nonworkingAdults + retiredAdults); alternative.AddUtilityTerm(35, ((double)pathTypeModel.PathDistance).AlmostEquals(0) ? 0 : Math.Log(pathTypeModel.PathDistance)); alternative.AddUtilityTerm(40, 1); alternative.AddUtilityTerm(41, noCarsInHouseholdFlag); alternative.AddUtilityTerm(42, carsLessThanDriversFlag); alternative.AddUtilityTerm(48, onePersonHouseholdFlag); alternative.AddUtilityTerm(133, escortPercentage); alternative.AddUtilityTerm(134, nonEscortPercentage); } else if (mode == Global.Settings.Modes.Sov) { alternative.AddUtilityTerm(1, (destinationParkingCost) * tour.CostCoefficient); alternative.AddUtilityTerm(50, 1); alternative.AddUtilityTerm(53, carsLessThanWorkersFlag); alternative.AddUtilityTerm(54, income0To25KFlag); alternative.AddUtilityTerm(131, escortPercentage); alternative.AddUtilityTerm(132, nonEscortPercentage); } else if (mode == Global.Settings.Modes.Bike) { double class1Dist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? ImpedanceRoster.GetValue("class1distance", mode, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0; double class2Dist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? ImpedanceRoster.GetValue("class2distance", mode, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0; // double worstDist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? // ImpedanceRoster.GetValue("worstdistance", mode, Global.Settings.PathTypes.FullNetwork, // Global.Settings.VotGroups.Medium, tour.DestinationArrivalTime,originParcel, destinationParcel).Variable : 0; alternative.AddUtilityTerm(60, 1); alternative.AddUtilityTerm(61, maleFlag); alternative.AddUtilityTerm(63, ageBetween51And98Flag); alternative.AddUtilityTerm(169, destinationParcel.MixedUse4Index1()); alternative.AddUtilityTerm(168, destinationParcel.TotalEmploymentDensity1()); // alternative.AddUtility(167, destinationParcel.NetIntersectionDensity1()); // alternative.AddUtility(166, originParcel.NetIntersectionDensity1()); // alternative.AddUtility(165, originParcel.HouseholdDensity1()); alternative.AddUtilityTerm(164, originParcel.MixedUse4Index1()); alternative.AddUtilityTerm(162, (class1Dist > 0).ToFlag()); alternative.AddUtilityTerm(162, (class2Dist > 0).ToFlag()); // alternative.AddUtility(163, (worstDist > 0).ToFlag()); } else if (mode == Global.Settings.Modes.Walk) { alternative.AddUtilityTerm(70, 1); alternative.AddUtilityTerm(71, maleFlag); // alternative.AddUtility(73, ageBetween51And98Flag); alternative.AddUtilityTerm(179, destinationParcel.MixedUse4Index1()); // alternative.AddUtility(178, destinationParcel.TotalEmploymentDensity1()); // alternative.AddUtility(177, destinationParcel.NetIntersectionDensity1()); // alternative.AddUtility(176, originParcel.NetIntersectionDensity1()); // alternative.AddUtility(175, originParcel.HouseholdDensity1()); alternative.AddUtilityTerm(179, originParcel.MixedUse4Index1()); } RegionSpecificCustomizations(alternative, tour, pathTypeModel.PathType, mode, destinationParcel); } }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITripWrapper trip, IHouseholdDayWrapper householdDay, int choice = Constants.DEFAULT_VALUE) { var household = trip.Household; var person = trip.Person; var personDay = trip.PersonDay; var tour = trip.Tour; var halfTour = trip.HalfTour; var personDays = householdDay.PersonDays; var isJointTour = tour.JointTourSequence > 0 ? 1 : 0; var destinationParcel = tour.DestinationParcel; var fullJointHalfTour = ((trip.Direction == Global.Settings.TourDirections.OriginToDestination && tour.FullHalfTour1Sequence > 0) || (trip.Direction == Global.Settings.TourDirections.DestinationToOrigin && tour.FullHalfTour2Sequence > 0)).ToFlag(); var partialJointHalfTour = ((trip.Direction == Global.Settings.TourDirections.OriginToDestination && tour.PartialHalfTour1Sequence > 0) || (trip.Direction == Global.Settings.TourDirections.DestinationToOrigin && tour.PartialHalfTour2Sequence > 0)).ToFlag(); var isJoint = (isJointTour + fullJointHalfTour + partialJointHalfTour > 0) ? 1 : 0; var isIndividual = 1 - isJoint; //destination parcel variables var foodBuffer2 = 0.0; var totEmpBuffer2 = 0.0; var retailBuffer2 = 0.0; if (destinationParcel != null) { foodBuffer2 = Math.Log(1 + destinationParcel.EmploymentFoodBuffer2); totEmpBuffer2 = Math.Log(1 + destinationParcel.EmploymentTotalBuffer2); retailBuffer2 = Math.Log(1 + destinationParcel.EmploymentRetailBuffer2); } var carOwnership = person.GetCarOwnershipSegment(); // household inputs var onePersonHouseholdFlag = household.IsOnePersonHousehold.ToFlag(); //var householdInc75KP = household.Has75KPlusIncome; var votALSegment = tour.GetVotALSegment(); var transitAccessSegment = household.ResidenceParcel.TransitAccessSegment(); var totalAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId] [Global.Settings.Purposes.HomeBasedComposite][carOwnership][votALSegment][transitAccessSegment]; var homeFoodBuffer2 = Math.Log(1 + household.ResidenceParcel.EmploymentFoodBuffer2); var homeTotEmpBuffer2 = Math.Log(1 + household.ResidenceParcel.EmploymentTotalBuffer2); var homeRetailBuffer2 = Math.Log(1 + household.ResidenceParcel.EmploymentRetailBuffer2); // person-day inputs var homeBasedTours = personDay.HomeBasedTours; var simulatedToursFlag = personDay.SimulatedToursExist().ToFlag(); var simulatedWorkStops = personDay.SimulatedWorkStops; var simulatedWorkStopsFlag = personDay.SimulatedWorkStopsExist().ToFlag(); var simulatedSchoolStops = personDay.SimulatedSchoolStops; var simulatedEscortStops = personDay.SimulatedEscortStops; var simulatedPersonalBusinessStops = personDay.SimulatedPersonalBusinessStops; var simulatedShoppingStops = personDay.SimulatedShoppingStops; var simulatedMealStops = personDay.SimulatedMealStops; var simulatedSocialStops = personDay.SimulatedSocialStops; var simulatedRecreationStops = personDay.SimulatedRecreationStops; var simulatedMedicalStops = personDay.SimulatedMedicalStops; // tour inputs var hov2TourFlag = tour.IsHov2Mode().ToFlag(); var hov3TourFlag = tour.IsHov3Mode().ToFlag(); var transitTourFlag = tour.IsTransitMode().ToFlag(); var notHomeBasedTourFlag = (!tour.IsHomeBasedTour).ToFlag(); var workTourFlag = tour.IsWorkPurpose().ToFlag(); var personalBusinessOrMedicalTourFlag = tour.IsPersonalBusinessOrMedicalPurpose().ToFlag(); var socialTourFlag = tour.IsSocialPurpose().ToFlag(); var socialOrRecreationTourFlag = tour.IsSocialOrRecreationPurpose().ToFlag(); var schoolTourFlag = tour.IsSchoolPurpose().ToFlag(); var escortTourFlag = tour.IsEscortPurpose().ToFlag(); var shoppingTourFlag = tour.IsShoppingPurpose().ToFlag(); var mealTourFlag = tour.IsMealPurpose().ToFlag(); // trip inputs var oneSimulatedTripFlag = halfTour.OneSimulatedTripFlag; var twoSimulatedTripsFlag = halfTour.TwoSimulatedTripsFlag; var threeSimulatedTripsFlag = halfTour.ThreeSimulatedTripsFlag; var fourSimulatedTripsFlag = halfTour.FourSimulatedTripsFlag; var fivePlusSimulatedTripsFlag = halfTour.FivePlusSimulatedTripsFlag; //JLB changed 5 to 5Plus var halfTourFromOriginFlag = trip.IsHalfTourFromOrigin.ToFlag(); var halfTourFromDestinationFlag = (!trip.IsHalfTourFromOrigin).ToFlag(); var beforeMandatoryDestinationFlag = trip.IsBeforeMandatoryDestination().ToFlag(); // remaining inputs, including joint tour variables var time = trip.IsHalfTourFromOrigin ? tour.DestinationArrivalTime : tour.DestinationDepartureTime; var from7AMto9AMFlag = (time >= Global.Settings.Times.SevenAM && time < Global.Settings.Times.NineAM).ToFlag(); var from9AMto11AMFlag = (time >= Global.Settings.Times.NineAM && time < Global.Settings.Times.ElevenAM).ToFlag(); var from11AMto1PMFlag = (time >= Global.Settings.Times.ElevenAM && time < Global.Settings.Times.OnePM).ToFlag(); var from1PMto3PMFlag = (time >= Global.Settings.Times.OnePM && time < Global.Settings.Times.ThreePM).ToFlag(); var from3PMto5PMFlag = (time >= Global.Settings.Times.ThreePM && time < Global.Settings.Times.FivePM).ToFlag(); var from7PMto9PMFlag = (time >= Global.Settings.Times.SevenPM && time < Global.Settings.Times.NinePM).ToFlag(); var from9PMto11PMFlag = (time >= Global.Settings.Times.NinePM && time < Global.Settings.Times.ElevenPM).ToFlag(); var from11PMto7AMFlag = (time >= Global.Settings.Times.ElevenPM).ToFlag(); var remainingToursCount = personDay.HomeBasedTours - personDay.GetTotalSimulatedTours(); // connectivity attributes var c34Ratio = trip.OriginParcel.C34RatioBuffer1(); var adis = 0.0; var logDist = 0.0; var minute = DayPeriod.BigDayPeriods[DayPeriod.MIDDAY].Start; //distance from origin to destination if (tour.OriginParcel != null && tour.DestinationParcel != null) { if (trip.Direction == Global.Settings.TourDirections.OriginToDestination) { adis = ImpedanceRoster.GetValue("distance", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, minute, tour.OriginParcel, tour.DestinationParcel).Variable; } else { adis = ImpedanceRoster.GetValue("distance", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, minute, destinationParcel, tour.OriginParcel).Variable; } logDist = Math.Log(1 + adis); } var shortestTravelTime = 0D; if (trip.Sequence > 1 && tour.OriginParcel != null && trip.OriginParcel != null) { if (trip.Direction == Global.Settings.TourDirections.OriginToDestination) { shortestTravelTime = ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Hov2, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, minute, tour.OriginParcel, trip.OriginParcel).Variable; } else { shortestTravelTime = ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Hov2, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, minute, trip.OriginParcel, tour.OriginParcel).Variable; } } var windowDuration = Math.Max(1.0, trip.IsHalfTourFromOrigin // first trip in half tour, use tour destination time ? trip.Sequence == 1 ? tour.DestinationArrivalTime - tour.EarliestOriginDepartureTime - tour.IndicatedTravelTimeToDestination : trip.GetPreviousTrip().ArrivalTime - tour.EarliestOriginDepartureTime - shortestTravelTime : trip.Sequence == 1 ? tour.LatestOriginArrivalTime - tour.DestinationDepartureTime - tour.IndicatedTravelTimeFromDestination : tour.LatestOriginArrivalTime - trip.GetPreviousTrip().ArrivalTime - shortestTravelTime); var duration = windowDuration / 60D; IEnumerable <PersonDayWrapper> orderedPersonDays = householdDay.PersonDays.OrderBy(p => p.GetJointTourParticipationPriority()).ToList().Cast <PersonDayWrapper>(); int numChildrenOnJointTour = 0; int numAdultsOnJointTour = 0; int totHHToursJT = 0; //int totHHStopsJT=0; //MB use calculated variables at tour level rather than redoing time window //TimeWindow timeWindow = new TimeWindow(); if (tour.JointTourSequence > 0) { foreach (PersonDayWrapper pDay in householdDay.PersonDays) { var tInJoint = pDay.Tours.Find(t => t.JointTourSequence == tour.JointTourSequence); if (!(tInJoint == null)) { // set jointTour time window //timeWindow.IncorporateAnotherTimeWindow(tInJoint.PersonDay.TimeWindow); totHHToursJT = personDay.HomeBasedTours + totHHToursJT; if (pDay.Person.Age < 18) { numChildrenOnJointTour++; } if (pDay.Person.Age >= 18) { numAdultsOnJointTour++; } } } } else if (trip.Direction == Global.Settings.TourDirections.OriginToDestination && tour.FullHalfTour1Sequence > 0) { foreach (PersonDayWrapper pDay in householdDay.PersonDays) { var tInJoint = pDay.Tours.Find(t => t.FullHalfTour1Sequence == tour.FullHalfTour1Sequence); if (!(tInJoint == null)) { // set jointTour time window //timeWindow.IncorporateAnotherTimeWindow(tInJoint.PersonDay.TimeWindow); totHHToursJT = personDay.HomeBasedTours + totHHToursJT; if (pDay.Person.Age < 18) { numChildrenOnJointTour++; } if (pDay.Person.Age >= 18) { numAdultsOnJointTour++; } } } } else if (trip.Direction == Global.Settings.TourDirections.DestinationToOrigin && tour.FullHalfTour2Sequence > 0) { foreach (PersonDayWrapper pDay in householdDay.PersonDays) { var tInJoint = pDay.Tours.Find(t => t.FullHalfTour2Sequence == tour.FullHalfTour2Sequence); if (!(tInJoint == null)) { // set jointTour time window //timeWindow.IncorporateAnotherTimeWindow(tInJoint.PersonDay.TimeWindow); totHHToursJT = personDay.HomeBasedTours + totHHToursJT; if (pDay.Person.Age < 18) { numChildrenOnJointTour++; } if (pDay.Person.Age >= 18) { numAdultsOnJointTour++; } } } } else if (tour.ParentTour == null) { //timeWindow.IncorporateAnotherTimeWindow(personDay.TimeWindow); } else { //timeWindow.IncorporateAnotherTimeWindow(tour.ParentTour.TimeWindow); } //timeWindow.SetBusyMinutes(Global.Settings.Times.EndOfRelevantWindow, Global.Settings.Times.MinutesInADay + 1); // time window in minutes for yet unmodeled portion of halftour, only consider persons on this trip //var availableWindow = timeWindow.AvailableWindow(destinationDepartureTime, Global.Settings.TimeDirections.Both); //var duration = availableWindow/ 60D; // 0 - NO MORE STOPS var alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.NoneOrHome, true, choice == Global.Settings.Purposes.NoneOrHome); alternative.Choice = Global.Settings.Purposes.NoneOrHome; alternative.AddUtilityTerm(1, twoSimulatedTripsFlag * halfTourFromOriginFlag * isIndividual); alternative.AddUtilityTerm(2, threeSimulatedTripsFlag * halfTourFromOriginFlag * isIndividual); alternative.AddUtilityTerm(3, fourSimulatedTripsFlag * halfTourFromOriginFlag * isIndividual); alternative.AddUtilityTerm(4, fivePlusSimulatedTripsFlag * halfTourFromOriginFlag * isIndividual); alternative.AddUtilityTerm(5, twoSimulatedTripsFlag * halfTourFromDestinationFlag * isIndividual); alternative.AddUtilityTerm(6, threeSimulatedTripsFlag * halfTourFromDestinationFlag * isIndividual); alternative.AddUtilityTerm(7, fourSimulatedTripsFlag * halfTourFromDestinationFlag * isIndividual); alternative.AddUtilityTerm(8, fivePlusSimulatedTripsFlag * halfTourFromDestinationFlag * isIndividual); alternative.AddUtilityTerm(9, homeBasedTours * isIndividual); alternative.AddUtilityTerm(10, homeBasedTours * isJointTour); alternative.AddUtilityTerm(11, notHomeBasedTourFlag); //alternative.AddUtilityTerm(12, beforeMandatoryDestinationFlag*isJointTour); alternative.AddUtilityTerm(13, beforeMandatoryDestinationFlag); alternative.AddUtilityTerm(14, numAdultsOnJointTour); alternative.AddUtilityTerm(15, numChildrenOnJointTour); alternative.AddUtilityTerm(16, totHHToursJT); //alternative.AddUtilityTerm(17, totHHStopsJT); alternative.AddUtilityTerm(22, (threeSimulatedTripsFlag + fourSimulatedTripsFlag + fivePlusSimulatedTripsFlag) * halfTourFromOriginFlag * isJoint); alternative.AddUtilityTerm(26, threeSimulatedTripsFlag * halfTourFromDestinationFlag * isJoint); alternative.AddUtilityTerm(27, fourSimulatedTripsFlag * halfTourFromDestinationFlag * isJoint); alternative.AddUtilityTerm(28, fivePlusSimulatedTripsFlag * halfTourFromDestinationFlag * isJoint); alternative.AddUtilityTerm(29, totalAggregateLogsum); // 1 - WORK STOP if ((personDay.WorkStops > 0 && tour.DestinationPurpose <= Global.Settings.Purposes.School) || isJoint > 0) { alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Work, true, choice == Global.Settings.Purposes.Work); alternative.Choice = Global.Settings.Purposes.Work; //alternative.AddUtilityTerm(32, isIndividualTour); alternative.AddUtilityTerm(33, workTourFlag); alternative.AddUtilityTerm(34, schoolTourFlag); alternative.AddUtilityTerm(35, halfTourFromOriginFlag); alternative.AddUtilityTerm(36, Math.Log(1 + simulatedWorkStops)); alternative.AddUtilityTerm(37, simulatedWorkStopsFlag); alternative.AddUtilityTerm(38, (5 - simulatedWorkStops)); alternative.AddUtilityTerm(39, duration); alternative.AddUtilityTerm(40, from9AMto11AMFlag + from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag); //alternative.AddUtilityTerm(42, logDist); //alternative.AddUtilityTerm(43, transitTourFlag); //alternative.AddUtilityTerm(44, (person.IsPartTimeWorker).ToFlag()); alternative.AddUtilityTerm(46, totalAggregateLogsum); //alternative.AddUtilityTerm(47,totEmpBuffer2); alternative.AddUtilityTerm(48, hov2TourFlag + hov3TourFlag); } else { choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Work, false, choice == Global.Settings.Purposes.Work); } // 2 - SCHOOL STOP if ((personDay.SchoolStops > 0 && tour.DestinationPurpose <= Global.Settings.Purposes.School) || isJoint > 0) { alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.School, true, choice == Global.Settings.Purposes.School); alternative.Choice = Global.Settings.Purposes.School; alternative.AddUtilityTerm(51, workTourFlag); alternative.AddUtilityTerm(52, schoolTourFlag); //alternative.AddUtilityTerm(53, halfTourFromOriginFlag); alternative.AddUtilityTerm(54, Math.Log(1 + simulatedSchoolStops)); alternative.AddUtilityTerm(55, (3 - simulatedSchoolStops)); //alternative.AddUtilityTerm(55, remainingToursCount); alternative.AddUtilityTerm(56, duration); alternative.AddUtilityTerm(57, from7AMto9AMFlag + from7PMto9PMFlag + from9PMto11PMFlag + from11PMto7AMFlag); alternative.AddUtilityTerm(58, oneSimulatedTripFlag); //alternative.AddUtilityTerm(59, logDist); alternative.AddUtilityTerm(61, fullJointHalfTour * numChildrenOnJointTour); alternative.AddUtilityTerm(65, (person.Age < 12).ToFlag()); alternative.AddUtilityTerm(66, totalAggregateLogsum); //alternative.AddUtilityTerm(66, (person.IsUniversityStudent).ToFlag()); } else { choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.School, false, choice == Global.Settings.Purposes.School); } // 3 - ESCORT STOP if ((personDay.EscortStops > 0 && tour.DestinationPurpose <= Global.Settings.Purposes.Escort) || isJoint > 0) { alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Escort, true, choice == Global.Settings.Purposes.Escort); alternative.Choice = Global.Settings.Purposes.Escort; alternative.AddUtilityTerm(71, workTourFlag + schoolTourFlag); alternative.AddUtilityTerm(72, isJointTour); alternative.AddUtilityTerm(74, escortTourFlag); //alternative.AddUtilityTerm(75, socialOrRecreationTourFlag); //alternative.AddUtilityTerm(76, remainingToursCount); alternative.AddUtilityTerm(77, duration); alternative.AddUtilityTerm(78, from7AMto9AMFlag); //alternative.AddUtilityTerm(79, from9AMto11AMFlag + from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag); alternative.AddUtilityTerm(81, hov2TourFlag); alternative.AddUtilityTerm(82, hov3TourFlag); alternative.AddUtilityTerm(83, Math.Log(1 + simulatedEscortStops * isJointTour)); alternative.AddUtilityTerm(84, Math.Log(1 + simulatedEscortStops * isIndividual)); //alternative.AddUtilityTerm(85, (3 - simulatedEscortStops)); alternative.AddUtilityTerm(85, totalAggregateLogsum); alternative.AddUtilityTerm(86, fullJointHalfTour); //alternative.AddUtilityTerm(88, enrollmentK8Buffer2); alternative.AddUtilityTerm(89, numChildrenOnJointTour); alternative.AddUtilityTerm(90, halfTourFromOriginFlag); } else { choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Escort, false, choice == Global.Settings.Purposes.Escort); } // 4 - PERSONAL BUSINESS STOP if (personDay.PersonalBusinessStops > 0 || isJoint > 0) { alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.PersonalBusiness, true, choice == Global.Settings.Purposes.PersonalBusiness); alternative.Choice = Global.Settings.Purposes.PersonalBusiness; alternative.AddUtilityTerm(91, (workTourFlag + schoolTourFlag)); alternative.AddUtilityTerm(92, isJointTour); alternative.AddUtilityTerm(93, escortTourFlag); alternative.AddUtilityTerm(94, personalBusinessOrMedicalTourFlag * isIndividual); alternative.AddUtilityTerm(95, shoppingTourFlag); alternative.AddUtilityTerm(96, mealTourFlag); alternative.AddUtilityTerm(97, socialOrRecreationTourFlag); alternative.AddUtilityTerm(98, halfTourFromOriginFlag); alternative.AddUtilityTerm(99, Math.Log(1 + simulatedPersonalBusinessStops * isIndividual)); alternative.AddUtilityTerm(100, Math.Log(1 + simulatedPersonalBusinessStops * isJointTour)); alternative.AddUtilityTerm(104, (3 - simulatedPersonalBusinessStops)); alternative.AddUtilityTerm(101, duration); alternative.AddUtilityTerm(102, (from7AMto9AMFlag + from7PMto9PMFlag + from9PMto11PMFlag + from11PMto7AMFlag)); alternative.AddUtilityTerm(103, from9AMto11AMFlag + from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag); alternative.AddUtilityTerm(105, hov2TourFlag); alternative.AddUtilityTerm(106, hov3TourFlag); alternative.AddUtilityTerm(109, fullJointHalfTour); alternative.AddUtilityTerm(110, totEmpBuffer2); alternative.AddUtilityTerm(111, totalAggregateLogsum); alternative.AddUtilityTerm(112, personalBusinessOrMedicalTourFlag * isJointTour); } else { choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.PersonalBusiness, false, choice == Global.Settings.Purposes.PersonalBusiness); } // 5 - SHOPPING STOP if (personDay.ShoppingStops > 0 || isJoint > 0) { alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Shopping, true, choice == Global.Settings.Purposes.Shopping); alternative.Choice = Global.Settings.Purposes.Shopping; alternative.AddUtilityTerm(121, workTourFlag + schoolTourFlag); alternative.AddUtilityTerm(122, isJointTour); alternative.AddUtilityTerm(123, escortTourFlag); alternative.AddUtilityTerm(124, personalBusinessOrMedicalTourFlag); alternative.AddUtilityTerm(125, shoppingTourFlag * isIndividual); alternative.AddUtilityTerm(126, mealTourFlag); alternative.AddUtilityTerm(127, socialOrRecreationTourFlag); alternative.AddUtilityTerm(128, halfTourFromOriginFlag); alternative.AddUtilityTerm(129, Math.Log(1 + simulatedShoppingStops * isIndividual)); alternative.AddUtilityTerm(130, Math.Log(1 + simulatedShoppingStops * isJointTour)); alternative.AddUtilityTerm(131, duration); alternative.AddUtilityTerm(132, from7AMto9AMFlag + from9PMto11PMFlag + from11PMto7AMFlag); alternative.AddUtilityTerm(133, (from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag)); //alternative.AddUtilityTerm(134, adultFemaleOnJointTour); alternative.AddUtilityTerm(135, hov2TourFlag); alternative.AddUtilityTerm(136, hov3TourFlag); alternative.AddUtilityTerm(137, Math.Log(1 + adis)); alternative.AddUtilityTerm(138, shoppingTourFlag * isJointTour); alternative.AddUtilityTerm(140, totalAggregateLogsum); //alternative.AddUtilityTerm(141, retailBuffer2); //alternative.AddUtilityTerm(142, numChildrenOnJointTour); //alternative.AddUtilityTerm(143, (household.Has100KPlusIncome).ToFlag()); } else { choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Shopping, false, choice == Global.Settings.Purposes.Shopping); } // 6 - MEAL STOP if (personDay.MealStops > 0 || isJoint > 0) { alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Meal, true, choice == Global.Settings.Purposes.Meal); alternative.Choice = Global.Settings.Purposes.Meal; alternative.AddUtilityTerm(151, workTourFlag); //alternative.AddUtilityTerm(152, isJointTour); alternative.AddUtilityTerm(153, schoolTourFlag); alternative.AddUtilityTerm(154, escortTourFlag); alternative.AddUtilityTerm(155, personalBusinessOrMedicalTourFlag); alternative.AddUtilityTerm(156, shoppingTourFlag); alternative.AddUtilityTerm(157, mealTourFlag); alternative.AddUtilityTerm(158, socialOrRecreationTourFlag); alternative.AddUtilityTerm(159, halfTourFromOriginFlag); alternative.AddUtilityTerm(160, Math.Log(1 + simulatedMealStops * isIndividual)); alternative.AddUtilityTerm(161, Math.Log(1 + simulatedMealStops * isJointTour)); alternative.AddUtilityTerm(162, duration); alternative.AddUtilityTerm(164, from11AMto1PMFlag + from1PMto3PMFlag); alternative.AddUtilityTerm(166, onePersonHouseholdFlag); alternative.AddUtilityTerm(167, hov2TourFlag); alternative.AddUtilityTerm(168, hov3TourFlag); alternative.AddUtilityTerm(170, numChildrenOnJointTour); alternative.AddUtilityTerm(171, oneSimulatedTripFlag); alternative.AddUtilityTerm(172, Math.Log(1 + adis)); alternative.AddUtilityTerm(174, fullJointHalfTour); alternative.AddUtilityTerm(175, foodBuffer2); //alternative.AddUtilityTerm(176, homeFoodBuffer2); //alternative.AddUtilityTerm(177, (household.Has100KPlusIncome).ToFlag()); alternative.AddUtilityTerm(178, numAdultsOnJointTour); alternative.AddUtilityTerm(179, totalAggregateLogsum); } else { choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Meal, false, choice == Global.Settings.Purposes.Meal); } // 7 - SOCIAL STOP if (personDay.SocialStops > 0 || isJoint > 0) { alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Social, true, choice == Global.Settings.Purposes.Social); alternative.Choice = Global.Settings.Purposes.Social; alternative.AddUtilityTerm(181, workTourFlag + schoolTourFlag); alternative.AddUtilityTerm(182, isJointTour); alternative.AddUtilityTerm(183, escortTourFlag); alternative.AddUtilityTerm(184, personalBusinessOrMedicalTourFlag); alternative.AddUtilityTerm(185, shoppingTourFlag); alternative.AddUtilityTerm(186, mealTourFlag); alternative.AddUtilityTerm(187, socialOrRecreationTourFlag); alternative.AddUtilityTerm(188, halfTourFromOriginFlag); alternative.AddUtilityTerm(189, Math.Log(1 + simulatedSocialStops * isIndividual)); alternative.AddUtilityTerm(197, Math.Log(1 + simulatedSocialStops * isJointTour)); alternative.AddUtilityTerm(190, remainingToursCount); alternative.AddUtilityTerm(191, duration); alternative.AddUtilityTerm(192, from7AMto9AMFlag + from11PMto7AMFlag); alternative.AddUtilityTerm(194, hov2TourFlag); alternative.AddUtilityTerm(195, hov3TourFlag); alternative.AddUtilityTerm(196, logDist); alternative.AddUtilityTerm(198, totalAggregateLogsum); alternative.AddUtilityTerm(200, numAdultsOnJointTour); } else { choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Social, false, choice == Global.Settings.Purposes.Social); } // 8 - RECREATION STOP if (personDay.RecreationStops > 0 || isJoint > 0) { alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Recreation, true, choice == Global.Settings.Purposes.Recreation); alternative.Choice = Global.Settings.Purposes.Recreation; alternative.AddUtilityTerm(211, workTourFlag + schoolTourFlag); alternative.AddUtilityTerm(212, isJointTour); alternative.AddUtilityTerm(213, escortTourFlag); alternative.AddUtilityTerm(214, personalBusinessOrMedicalTourFlag); alternative.AddUtilityTerm(215, shoppingTourFlag); alternative.AddUtilityTerm(216, mealTourFlag); alternative.AddUtilityTerm(217, socialOrRecreationTourFlag); alternative.AddUtilityTerm(218, halfTourFromOriginFlag); alternative.AddUtilityTerm(219, Math.Log(1 + simulatedRecreationStops * isIndividual)); alternative.AddUtilityTerm(229, Math.Log(1 + simulatedRecreationStops * isJointTour)); alternative.AddUtilityTerm(220, remainingToursCount); alternative.AddUtilityTerm(221, duration); alternative.AddUtilityTerm(222, from7AMto9AMFlag + from11PMto7AMFlag); alternative.AddUtilityTerm(223, from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag); alternative.AddUtilityTerm(225, hov3TourFlag); alternative.AddUtilityTerm(226, numChildrenOnJointTour); alternative.AddUtilityTerm(227, numAdultsOnJointTour); //alternative.AddUtilityTerm(228, fullJointHalfTour); //alternative.AddUtilityTerm(229, openSpaceBuffer2); alternative.AddUtilityTerm(228, totalAggregateLogsum); } else { choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Recreation, false, choice == Global.Settings.Purposes.Recreation); } // 9 - MEDICAL STOP if (personDay.MedicalStops > 0 || isJoint > 0) { alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Medical, true, choice == Global.Settings.Purposes.Medical); alternative.Choice = Global.Settings.Purposes.Medical; alternative.AddUtilityTerm(231, workTourFlag + schoolTourFlag + escortTourFlag); alternative.AddUtilityTerm(232, isJointTour); alternative.AddUtilityTerm(233, personalBusinessOrMedicalTourFlag * isIndividual); alternative.AddUtilityTerm(234, personalBusinessOrMedicalTourFlag * isJointTour); alternative.AddUtilityTerm(235, shoppingTourFlag); alternative.AddUtilityTerm(236, mealTourFlag); alternative.AddUtilityTerm(237, socialOrRecreationTourFlag); alternative.AddUtilityTerm(238, halfTourFromOriginFlag); alternative.AddUtilityTerm(239, Math.Log(1 + simulatedMedicalStops * isJointTour)); alternative.AddUtilityTerm(240, Math.Log(1 + simulatedMedicalStops * isIndividual)); //alternative.AddUtilityTerm(240, fullJointHalfTour); alternative.AddUtilityTerm(241, duration); alternative.AddUtilityTerm(242, from7AMto9AMFlag + from11PMto7AMFlag); alternative.AddUtilityTerm(243, from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag); //alternative.AddUtilityTerm(248, numChildrenOnJointTour); //alternative.AddUtilityTerm(249, adultFemaleOnJointTour); alternative.AddUtilityTerm(244, totalAggregateLogsum); } else { choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Medical, false, choice == Global.Settings.Purposes.Medical); } }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITourWrapper tour, IEnumerable <dynamic> pathTypeModels, IParcelWrapper destinationParcel, int householdCars, int choice = Constants.DEFAULT_VALUE) { var household = tour.Household; var person = tour.Person; var personDay = tour.PersonDay; // household inputs var income0To25KFlag = household.Has0To25KIncome.ToFlag(); var income25To50KFlag = household.Has25To50KIncome.ToFlag(); var income75KPlusFlag = household.Has75KPlusIncome.ToFlag(); var onePersonHouseholdFlag = household.IsOnePersonHousehold.ToFlag(); var twoPersonHouseholdFlag = household.IsTwoPersonHousehold.ToFlag(); var noCarsInHouseholdFlag = household.GetFlagForNoCarsInHousehold(householdCars); var carsLessThanDriversFlag = household.GetFlagForCarsLessThanDrivers(householdCars); // person inputs var childUnder5Flag = person.IsChildUnder5.ToFlag(); var adultFlag = person.IsAdult.ToFlag(); var drivingAgeStudentFlag = person.IsDrivingAgeStudent.ToFlag(); var maleFlag = person.IsMale.ToFlag(); // remaining inputs var originParcel = tour.OriginParcel; var destinationParkingCost = destinationParcel.ParkingCostBuffer1(6); double escortPercentage; double nonEscortPercentage; ChoiceModelUtility.SetEscortPercentages(personDay, out escortPercentage, out nonEscortPercentage); // school bus is a special case - use HOV3 impedance var pathTypeExtra = pathTypeModels.First(x => x.Mode == Global.Settings.Modes.Hov3); var modeExtra = Global.Settings.Modes.SchoolBus; var availableExtra = pathTypeExtra.Available; var generalizedTimeLogsumExtra = pathTypeExtra.GeneralizedTimeLogsum; var alternative = choiceProbabilityCalculator.GetAlternative(modeExtra, availableExtra, choice == modeExtra); alternative.Choice = modeExtra; alternative.AddNestedAlternative(_nestedAlternativeIds[modeExtra], _nestedAlternativeIndexes[modeExtra], THETA_PARAMETER); if (availableExtra) { // case Global.Settings.Modes.SchoolBus: alternative.AddUtilityTerm(2, generalizedTimeLogsumExtra * tour.TimeCoefficient); alternative.AddUtilityTerm(10, 1); alternative.AddUtilityTerm(17, childUnder5Flag); alternative.AddUtilityTerm(18, adultFlag); } foreach (var pathTypeModel in pathTypeModels) { var mode = pathTypeModel.Mode; var available = pathTypeModel.Available; var generalizedTimeLogsum = pathTypeModel.GeneralizedTimeLogsum; alternative = choiceProbabilityCalculator.GetAlternative(mode, available, choice == mode); alternative.Choice = mode; alternative.AddNestedAlternative(_nestedAlternativeIds[mode], _nestedAlternativeIndexes[mode], THETA_PARAMETER); if (!available) { continue; } alternative.AddUtilityTerm(2, generalizedTimeLogsum * tour.TimeCoefficient); if (mode == Global.Settings.Modes.Transit) { alternative.AddUtilityTerm(20, 1); alternative.AddUtilityTerm(21, noCarsInHouseholdFlag); alternative.AddUtilityTerm(22, carsLessThanDriversFlag); alternative.AddUtilityTerm(27, childUnder5Flag); alternative.AddUtilityTerm(28, adultFlag); alternative.AddUtilityTerm(29, drivingAgeStudentFlag); alternative.AddUtilityTerm(129, destinationParcel.MixedUse2Index1()); // alternative.AddUtility(128, destinationParcel.TotalEmploymentDensity1()); // alternative.AddUtility(127, destinationParcel.NetIntersectionDensity1()); // alternative.AddUtility(126, originParcel.NetIntersectionDensity1()); // alternative.AddUtility(125, originParcel.HouseholdDensity1()); // alternative.AddUtility(124, originParcel.MixedUse2Index1()); // alternative.AddUtility(123, Math.Log(destinationParcel.StopsTransitBuffer1+1)); alternative.AddUtilityTerm(122, Math.Log(originParcel.StopsTransitBuffer1 + 1)); } else if (mode == Global.Settings.Modes.Hov3) { alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / ChoiceModelUtility.CPFACT3)); alternative.AddUtilityTerm(30, 1); alternative.AddUtilityTerm(37, twoPersonHouseholdFlag); alternative.AddUtilityTerm(37, onePersonHouseholdFlag); alternative.AddUtilityTerm(41, noCarsInHouseholdFlag); alternative.AddUtilityTerm(44, income0To25KFlag); alternative.AddUtilityTerm(45, income25To50KFlag); alternative.AddUtilityTerm(47, childUnder5Flag); alternative.AddUtilityTerm(133, escortPercentage); alternative.AddUtilityTerm(134, nonEscortPercentage); } else if (mode == Global.Settings.Modes.Hov2) { alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / ChoiceModelUtility.CPFACT2)); alternative.AddUtilityTerm(38, onePersonHouseholdFlag); alternative.AddUtilityTerm(40, 1); alternative.AddUtilityTerm(41, noCarsInHouseholdFlag); alternative.AddUtilityTerm(44, income0To25KFlag); alternative.AddUtilityTerm(45, income25To50KFlag); alternative.AddUtilityTerm(47, childUnder5Flag); alternative.AddUtilityTerm(133, escortPercentage); alternative.AddUtilityTerm(134, nonEscortPercentage); } else if (mode == Global.Settings.Modes.Sov) { alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient)); alternative.AddUtilityTerm(50, 1); alternative.AddUtilityTerm(52, carsLessThanDriversFlag); alternative.AddUtilityTerm(54, income0To25KFlag); alternative.AddUtilityTerm(56, income75KPlusFlag); alternative.AddUtilityTerm(59, drivingAgeStudentFlag); alternative.AddUtilityTerm(131, escortPercentage); alternative.AddUtilityTerm(132, nonEscortPercentage); } else if (mode == Global.Settings.Modes.Bike) { double class1Dist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? ImpedanceRoster.GetValue("class1distance", mode, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0; double class2Dist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? ImpedanceRoster.GetValue("class2distance", mode, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0; double worstDist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? ImpedanceRoster.GetValue("worstdistance", mode, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0; alternative.AddUtilityTerm(60, 1); alternative.AddUtilityTerm(61, maleFlag); alternative.AddUtilityTerm(69, adultFlag); alternative.AddUtilityTerm(169, destinationParcel.MixedUse4Index1()); alternative.AddUtilityTerm(168, destinationParcel.TotalEmploymentDensity1()); // alternative.AddUtility(167, destinationParcel.NetIntersectionDensity1()); // alternative.AddUtility(166, originParcel.NetIntersectionDensity1()); // alternative.AddUtility(165, originParcel.HouseholdDensity1()); alternative.AddUtilityTerm(164, originParcel.MixedUse4Index1()); alternative.AddUtilityTerm(161, (class1Dist > 0).ToFlag()); alternative.AddUtilityTerm(162, (class2Dist > 0).ToFlag()); alternative.AddUtilityTerm(163, (worstDist > 0).ToFlag()); } else if (mode == Global.Settings.Modes.Walk) { alternative.AddUtilityTerm(79, adultFlag); alternative.AddUtilityTerm(179, destinationParcel.MixedUse4Index1()); // alternative.AddUtility(178, destinationParcel.TotalEmploymentDensity1()); // alternative.AddUtility(177, destinationParcel.NetIntersectionDensity1()); // alternative.AddUtility(176, originParcel.NetIntersectionDensity1()); // alternative.AddUtility(175, originParcel.HouseholdDensity1()); alternative.AddUtilityTerm(179, originParcel.MixedUse4Index1()); } } }
private SegmentZone[] ComputeSegment(int segment) { double[] sizeFactors = Global.ContainerDaySim.GetInstance <SamplingWeightsSettingsFactory>().SamplingWeightsSettings.SizeFactors[segment]; double[] weightFactors = Global.ContainerDaySim.GetInstance <SamplingWeightsSettingsFactory>().SamplingWeightsSettings.WeightFactors[segment]; SegmentZone[] segmentZones = new SegmentZone[_zoneCount]; foreach (IParcelWrapper parcel in _eligibleParcels) { SegmentZone segmentZone = segmentZones[parcel.ZoneId]; IZone zone = _eligibleZones[parcel.ZoneId]; if (segmentZone == null) { segmentZone = new SegmentZone(_parcelCounts[parcel.ZoneId], _zoneCount) { Id = parcel.ZoneId, Key = zone.Key }; segmentZones[segmentZone.Id] = segmentZone; } double openSpace = (Global.Configuration.UseParcelLandUseCodeAsSquareFeetOpenSpace) ? parcel.LandUseCode : parcel.OpenSpaceType2Buffer1; double openSpaceSize = (Global.Configuration.UseLogOfSquareFeetOpenSpaceInDestinationSampling || Global.Configuration.UseParcelLandUseCodeAsSquareFeetOpenSpace) ? Math.Log(openSpace + 1.0) : openSpace; double factor = Math.Exp(sizeFactors[0]) * parcel.EmploymentEducation + Math.Exp(sizeFactors[1]) * parcel.EmploymentFood + Math.Exp(sizeFactors[2]) * parcel.EmploymentGovernment + Math.Exp(sizeFactors[3]) * parcel.EmploymentIndustrial + Math.Exp(sizeFactors[4]) * parcel.EmploymentMedical + Math.Exp(sizeFactors[5]) * parcel.EmploymentOffice + Math.Exp(sizeFactors[6]) * parcel.EmploymentAgricultureConstruction + Math.Exp(sizeFactors[7]) * parcel.EmploymentRetail + Math.Exp(sizeFactors[8]) * parcel.EmploymentService + Math.Exp(sizeFactors[9]) * parcel.EmploymentTotal + Math.Exp(sizeFactors[10]) * parcel.Households + Math.Exp(sizeFactors[11]) * parcel.StudentsK8 + Math.Exp(sizeFactors[12]) * parcel.StudentsUniversity + Math.Exp(sizeFactors[13]) * parcel.GetLandUseCode19() + Math.Exp(sizeFactors[14]) * parcel.OpenSpaceType1Buffer1 + Math.Exp(sizeFactors[15]) * openSpaceSize + Math.Exp(sizeFactors[16]) * parcel.StudentsHighSchool; double size = 100 * factor; if (size >= Global.Configuration.MinParcelSize) { segmentZone.TotalSize += size; } segmentZone.SetSize(parcel.Sequence, parcel.Id, size); } foreach (SegmentZone origin in segmentZones.Where(o => o != null)) { origin.RankSizes(); foreach (SegmentZone destination in segmentZones.Where(d => d != null)) { SkimValue skimValue = ImpedanceRoster.GetValue(_variableName, _mode, _pathType, _vot, _minute, origin.Id, destination.Id); //jb 20130707 mimic mb fix for 0 intrazonals if (Global.Configuration.DestinationScale == Global.Settings.DestinationScales.Zone && origin.Id == destination.Id && skimValue.Variable < Constants.EPSILON) { if (_variableName == "distance") { skimValue.Variable = 0.25 * Global.Settings.DistanceUnitsPerMile; } else if (_variableName == "ivtime" || _variableName == "time" || _variableName == "ivtfree") { skimValue.Variable = (_mode == Global.Settings.Modes.Walk) ? 5 : (_mode == Global.Settings.Modes.Bike) ? 2 : (_mode > Global.Settings.Modes.Bike && _mode < Global.Settings.Modes.Transit) ? 1 : 0; } } double sovInVehicleTime = skimValue.Variable; // give 0 weight if not connected in SOV matrix double weight = sovInVehicleTime < Constants.EPSILON ? 0.0 : Math.Exp(-2 * sovInVehicleTime * 100 / weightFactors[0]) * destination.TotalSize; origin.TotalWeight += weight; origin.SetWeight(destination.Id, weight); } origin.RankWeights(); } return(segmentZones); }
protected override void RegionSpecificTransitImpedanceCalculation(int skimMode, int pathType, double votValue, int outboundTime, int returnTime, int originZoneId, int destinationZoneId, ref double outboundInVehicleTime, ref double returnInVehicleTime, ref double pathTypeSpecificTime, ref double pathTypeSpecificTimeWeight) { //Global.PrintFile.WriteLine("Nashville_PathTypeModel.RegionSpecificTransitImpedanceCalculation called"); //Nashville BRT coded in Ferry //Nashville Commuter Rail coded in Commuter rail //Nashville Express Bus coded in Premium bus //ASC based on IVT share by sub-mode pathTypeSpecificTimeWeight = 1.0; pathTypeSpecificTime = Global.Configuration.PathImpedance_TransitLightRailTimeAdditiveWeight * ImpedanceRoster.GetValue("lrttime", skimMode, pathType, votValue, outboundTime, originZoneId, destinationZoneId).Variable / outboundInVehicleTime + Global.Configuration.PathImpedance_TransitFerryTimeAdditiveWeight * ImpedanceRoster.GetValue("ferrtime", skimMode, pathType, votValue, outboundTime, originZoneId, destinationZoneId).Variable / outboundInVehicleTime + Global.Configuration.PathImpedance_TransitCommuterRailTimeAdditiveWeight * ImpedanceRoster.GetValue("comtime", skimMode, pathType, votValue, outboundTime, originZoneId, destinationZoneId).Variable / outboundInVehicleTime + Global.Configuration.PathImpedance_TransitPremiumBusTimeAdditiveWeight * ImpedanceRoster.GetValue("premtime", skimMode, pathType, votValue, outboundTime, originZoneId, destinationZoneId).Variable / outboundInVehicleTime; if (returnTime > 0) { pathTypeSpecificTime = pathTypeSpecificTime + Global.Configuration.PathImpedance_TransitLightRailTimeAdditiveWeight * ImpedanceRoster.GetValue("lrttime", skimMode, pathType, votValue, returnTime, destinationZoneId, originZoneId).Variable / returnInVehicleTime + Global.Configuration.PathImpedance_TransitFerryTimeAdditiveWeight * ImpedanceRoster.GetValue("ferrtime", skimMode, pathType, votValue, returnTime, destinationZoneId, originZoneId).Variable / returnInVehicleTime + Global.Configuration.PathImpedance_TransitCommuterRailTimeAdditiveWeight * ImpedanceRoster.GetValue("comtime", skimMode, pathType, votValue, returnTime, destinationZoneId, originZoneId).Variable / returnInVehicleTime + Global.Configuration.PathImpedance_TransitPremiumBusTimeAdditiveWeight * ImpedanceRoster.GetValue("premtime", skimMode, pathType, votValue, returnTime, destinationZoneId, originZoneId).Variable / returnInVehicleTime; } //IVT discounted by sub-mode double outboundLightRailInVehicleTime = ImpedanceRoster.GetValue("lrttime", skimMode, pathType, votValue, outboundTime, originZoneId, destinationZoneId).Variable; double outboundFerryInVehicleTime = ImpedanceRoster.GetValue("ferrtime", skimMode, pathType, votValue, outboundTime, originZoneId, destinationZoneId).Variable; double outboundCommuterRailInVehicleTime = ImpedanceRoster.GetValue("comtime", skimMode, pathType, votValue, outboundTime, originZoneId, destinationZoneId).Variable; double outboundPremiumBusInVehicleTime = ImpedanceRoster.GetValue("premtime", skimMode, pathType, votValue, outboundTime, originZoneId, destinationZoneId).Variable; double outboundLocalBusInVehicleTime = outboundInVehicleTime - (outboundLightRailInVehicleTime + outboundFerryInVehicleTime + outboundCommuterRailInVehicleTime + outboundPremiumBusInVehicleTime); outboundInVehicleTime = Global.Configuration.PathImpedance_TransitLightRailInVehicleTimeWeight * outboundLightRailInVehicleTime + Global.Configuration.PathImpedance_TransitFerryInVehicleTimeWeight * outboundFerryInVehicleTime + Global.Configuration.PathImpedance_TransitCommuterRailInVehicleTimeWeight * outboundCommuterRailInVehicleTime + Global.Configuration.PathImpedance_TransitPremiumBusInVehicleTimeWeight * outboundPremiumBusInVehicleTime + 1 * outboundLocalBusInVehicleTime; if (returnTime > 0) { double returnLightRailInVehicleTime = ImpedanceRoster.GetValue("lrttime", skimMode, pathType, votValue, returnTime, destinationZoneId, originZoneId).Variable; double returnFerryInVehicleTime = ImpedanceRoster.GetValue("ferrtime", skimMode, pathType, votValue, returnTime, destinationZoneId, originZoneId).Variable; double returnCommuterRailInVehicleTime = ImpedanceRoster.GetValue("comtime", skimMode, pathType, votValue, returnTime, destinationZoneId, originZoneId).Variable; double returnPremiumBusInVehicleTime = ImpedanceRoster.GetValue("premtime", skimMode, pathType, votValue, returnTime, destinationZoneId, originZoneId).Variable; double returnLocalBusInVehicleTime = returnInVehicleTime - (returnLightRailInVehicleTime + returnFerryInVehicleTime + returnCommuterRailInVehicleTime + returnPremiumBusInVehicleTime); returnInVehicleTime = Global.Configuration.PathImpedance_TransitLightRailInVehicleTimeWeight * returnLightRailInVehicleTime + Global.Configuration.PathImpedance_TransitFerryInVehicleTimeWeight * returnFerryInVehicleTime + Global.Configuration.PathImpedance_TransitCommuterRailInVehicleTimeWeight * returnCommuterRailInVehicleTime + Global.Configuration.PathImpedance_TransitPremiumBusInVehicleTimeWeight * returnPremiumBusInVehicleTime + 1 * returnLocalBusInVehicleTime; } //end if (returnTime > 0) } //end RegionSpecificTransitImpedanceCalculation
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITourWrapper tour, IEnumerable <IPathTypeModel> pathTypeModels, IParcelWrapper destinationParcel, int choice = Constants.DEFAULT_VALUE) { IHouseholdWrapper household = tour.Household; Framework.DomainModels.Models.IHouseholdTotals householdTotals = household.HouseholdTotals; IPersonWrapper person = tour.Person; IPersonDayWrapper personDay = tour.PersonDay; // household inputs int income0To25KFlag = household.Has0To25KIncome.ToFlag(); int incomeOver100Flag = household.Has100KPlusIncome.ToFlag(); int childrenUnder5 = householdTotals.ChildrenUnder5; int childrenAge5Through15 = householdTotals.ChildrenAge5Through15; int nonworkingAdults = householdTotals.NonworkingAdults; int retiredAdults = householdTotals.RetiredAdults; int onePersonHouseholdFlag = household.IsOnePersonHousehold.ToFlag(); int twoPersonHouseholdFlag = household.IsTwoPersonHousehold.ToFlag(); int noCarsInHouseholdFlag = household.GetFlagForNoCarsInHousehold(household.VehiclesAvailable); int carsLessThanDriversFlag = household.GetFlagForCarsLessThanDrivers(household.VehiclesAvailable); int carsLessThanWorkersFlag = household.GetFlagForCarsLessThanWorkers(household.VehiclesAvailable); // person inputs int maleFlag = person.IsMale.ToFlag(); int ageBetween51And98Flag = person.AgeIsBetween51And98.ToFlag(); int univStudentFlag = person.IsUniversityStudent.ToFlag(); // tour inputs int shoppingTourFlag = (tour.DestinationPurpose == Global.Settings.Purposes.Shopping).ToFlag(); int mealTourFlag = (tour.DestinationPurpose == Global.Settings.Purposes.Meal).ToFlag(); int socialOrRecreationTourFlag = (tour.DestinationPurpose == Global.Settings.Purposes.Social).ToFlag(); // remaining inputs IParcelWrapper originParcel = tour.OriginParcel; int parkingDuration = ChoiceModelUtility.GetParkingDuration(person.IsFulltimeWorker); double destinationParkingCost = destinationParcel.ParkingCostBuffer1(parkingDuration); ChoiceModelUtility.SetEscortPercentages(personDay, out double escortPercentage, out double nonEscortPercentage, true); //foreach (var pathTypeModel in pathTypeModels) { foreach (IPathTypeModel pathTypeModel in pathTypeModels) { IPathTypeModel ipathTypeModel = pathTypeModel; int mode = pathTypeModel.Mode; bool available = (pathTypeModel.Mode != Global.Settings.Modes.ParkAndRide || Global.Configuration.IncludeParkAndRideInOtherHomeBasedTourModeModel) && (pathTypeModel.Mode != Global.Settings.Modes.PaidRideShare || Global.Configuration.PaidRideShareModeIsAvailable) && pathTypeModel.Available; double generalizedTimeLogsum = pathTypeModel.GeneralizedTimeLogsum; ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(mode, available, choice == mode); alternative.Choice = mode; alternative.AddNestedAlternative(_nestedAlternativeIds[pathTypeModel.Mode], _nestedAlternativeIndexes[pathTypeModel.Mode], THETA_PARAMETER); if (!available) { continue; } double modeTimeCoefficient = (Global.Configuration.AV_IncludeAutoTypeChoice && household.OwnsAutomatedVehicles > 0 && mode >= Global.Settings.Modes.Sov && mode <= Global.Settings.Modes.Hov3) ? tour.TimeCoefficient * (1.0 - Global.Configuration.AV_InVehicleTimeCoefficientDiscountFactor) : (mode == Global.Settings.Modes.PaidRideShare && Global.Configuration.AV_PaidRideShareModeUsesAVs) ? tour.TimeCoefficient * (1.0 - Global.Configuration.AV_InVehicleTimeCoefficientDiscountFactor) : tour.TimeCoefficient; alternative.AddUtilityTerm(2, generalizedTimeLogsum * modeTimeCoefficient); if (mode == Global.Settings.Modes.ParkAndRide) { alternative.AddUtilityTerm(5, 1); alternative.AddUtilityTerm(6, noCarsInHouseholdFlag); alternative.AddUtilityTerm(7, carsLessThanWorkersFlag); alternative.AddUtilityTerm(128, destinationParcel.TotalEmploymentDensity1()); } else if (mode == Global.Settings.Modes.Transit) { alternative.AddUtilityTerm(20, 1); alternative.AddUtilityTerm(21, noCarsInHouseholdFlag); alternative.AddUtilityTerm(22, carsLessThanDriversFlag); //for calibration alternative.AddUtilityTerm(120, shoppingTourFlag); alternative.AddUtilityTerm(121, mealTourFlag); // alternative.AddUtility(129, destinationParcel.MixedUse2Index1()); alternative.AddUtilityTerm(128, destinationParcel.TotalEmploymentDensity1()); // alternative.AddUtility(127, destinationParcel.NetIntersectionDensity1()); // alternative.AddUtility(126, originParcel.NetIntersectionDensity1()); // alternative.AddUtility(125, originParcel.HouseholdDensity1()); alternative.AddUtilityTerm(124, originParcel.MixedUse2Index1()); // alternative.AddUtility(123, Math.Log(destinationParcel.StopsTransitBuffer1+1)); // alternative.AddUtility(122, Math.Log(originParcel.StopsTransitBuffer1+1)); alternative.AddUtilityTerm(180, univStudentFlag); } else if (mode == Global.Settings.Modes.Hov3) { alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / ChoiceModelUtility.CPFACT3)); alternative.AddUtilityTerm(30, 1); alternative.AddUtilityTerm(31, childrenUnder5); alternative.AddUtilityTerm(32, childrenAge5Through15); alternative.AddUtilityTerm(34, nonworkingAdults + retiredAdults); alternative.AddUtilityTerm(35, pathTypeModel.PathDistance.AlmostEquals(0) ? 0 : Math.Log(pathTypeModel.PathDistance)); alternative.AddUtilityTerm(36, noCarsInHouseholdFlag); // for calibration of hov3 vs hov2 alternative.AddUtilityTerm(37, carsLessThanWorkersFlag); // for calibration of hov3 vs hov2 alternative.AddUtilityTerm(38, onePersonHouseholdFlag); alternative.AddUtilityTerm(39, twoPersonHouseholdFlag); alternative.AddUtilityTerm(41, noCarsInHouseholdFlag); alternative.AddUtilityTerm(43, carsLessThanWorkersFlag); alternative.AddUtilityTerm(133, escortPercentage); alternative.AddUtilityTerm(134, nonEscortPercentage); alternative.AddUtilityTerm(136, shoppingTourFlag); alternative.AddUtilityTerm(137, mealTourFlag); alternative.AddUtilityTerm(138, socialOrRecreationTourFlag); } else if (mode == Global.Settings.Modes.Hov2) { alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / ChoiceModelUtility.CPFACT2)); alternative.AddUtilityTerm(31, childrenUnder5); alternative.AddUtilityTerm(32, childrenAge5Through15); alternative.AddUtilityTerm(34, nonworkingAdults + retiredAdults); alternative.AddUtilityTerm(35, pathTypeModel.PathDistance.AlmostEquals(0) ? 0 : Math.Log(pathTypeModel.PathDistance)); alternative.AddUtilityTerm(40, 1); alternative.AddUtilityTerm(41, noCarsInHouseholdFlag); alternative.AddUtilityTerm(43, carsLessThanWorkersFlag); alternative.AddUtilityTerm(48, onePersonHouseholdFlag); alternative.AddUtilityTerm(133, escortPercentage); alternative.AddUtilityTerm(134, nonEscortPercentage); alternative.AddUtilityTerm(136, shoppingTourFlag); alternative.AddUtilityTerm(137, mealTourFlag); alternative.AddUtilityTerm(138, socialOrRecreationTourFlag); } else if (mode == Global.Settings.Modes.Sov) { alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient)); alternative.AddUtilityTerm(50, 1); alternative.AddUtilityTerm(52, carsLessThanDriversFlag); alternative.AddUtilityTerm(54, income0To25KFlag); alternative.AddUtilityTerm(131, escortPercentage); alternative.AddUtilityTerm(132, nonEscortPercentage); } else if (mode == Global.Settings.Modes.Bike) { double class1Dist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? ImpedanceRoster.GetValue("class1distance", mode, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0; double class2Dist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? ImpedanceRoster.GetValue("class2distance", mode, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0; double worstDist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? ImpedanceRoster.GetValue("worstdistance", mode, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0; alternative.AddUtilityTerm(60, 1); alternative.AddUtilityTerm(61, maleFlag); alternative.AddUtilityTerm(63, ageBetween51And98Flag); alternative.AddUtilityTerm(67, noCarsInHouseholdFlag); //for calibration alternative.AddUtilityTerm(68, carsLessThanDriversFlag); //for calibration alternative.AddUtilityTerm(160, socialOrRecreationTourFlag); alternative.AddUtilityTerm(169, destinationParcel.MixedUse4Index1()); alternative.AddUtilityTerm(168, destinationParcel.TotalEmploymentDensity1()); alternative.AddUtilityTerm(167, destinationParcel.NetIntersectionDensity1()); alternative.AddUtilityTerm(166, originParcel.NetIntersectionDensity1()); alternative.AddUtilityTerm(165, originParcel.HouseholdDensity1()); alternative.AddUtilityTerm(164, originParcel.MixedUse4Index1()); alternative.AddUtilityTerm(161, (class1Dist > 0).ToFlag()); alternative.AddUtilityTerm(162, (class2Dist > 0).ToFlag()); alternative.AddUtilityTerm(163, (worstDist > 0).ToFlag()); alternative.AddUtilityTerm(170, 1.0 * destinationParcel.MixedUse4Index1() + 0.00002 * destinationParcel.TotalEmploymentDensity1() + 0.001 * destinationParcel.NetIntersectionDensity1() + 0.001 * originParcel.NetIntersectionDensity1() + 0.0002 * originParcel.HouseholdDensity1() + 1.0 * originParcel.MixedUse4Index1()); } else if (mode == Global.Settings.Modes.Walk) { alternative.AddUtilityTerm(70, 1); alternative.AddUtilityTerm(73, ageBetween51And98Flag); alternative.AddUtilityTerm(77, noCarsInHouseholdFlag); //for calibration alternative.AddUtilityTerm(78, carsLessThanDriversFlag); //for calibration alternative.AddUtilityTerm(171, mealTourFlag); alternative.AddUtilityTerm(172, socialOrRecreationTourFlag); alternative.AddUtilityTerm(179, destinationParcel.MixedUse4Index1()); alternative.AddUtilityTerm(178, destinationParcel.HouseholdDensity1()); alternative.AddUtilityTerm(177, destinationParcel.NetIntersectionDensity1()); alternative.AddUtilityTerm(176, originParcel.NetIntersectionDensity1()); alternative.AddUtilityTerm(175, originParcel.HouseholdDensity1()); alternative.AddUtilityTerm(174, originParcel.MixedUse4Index1()); alternative.AddUtilityTerm(181, 1.0 * destinationParcel.MixedUse4Index1() + 0.00001 * destinationParcel.TotalEmploymentDensity1() + 0.001 * destinationParcel.NetIntersectionDensity1() + 0.001 * originParcel.NetIntersectionDensity1() + 0.0001 * originParcel.HouseholdDensity1() + 1.0 * originParcel.MixedUse4Index1()); } else if (mode == Global.Settings.Modes.PaidRideShare) { if (Global.Configuration.PaidRideshare_UseEstimatedInsteadOfAssertedCoefficients) { alternative.AddUtilityTerm(80, 1.0); //alternative.AddUtilityTerm(81, tour.Person.AgeIsBetween26And35.ToFlag()); //alternative.AddUtilityTerm(82, tour.Person.AgeIsBetween18And25.ToFlag()); alternative.AddUtilityTerm(81, noCarsInHouseholdFlag); //for calibration alternative.AddUtilityTerm(82, carsLessThanDriversFlag); //for calibration alternative.AddUtilityTerm(83, (tour.Person.Age >= 65).ToFlag()); alternative.AddUtilityTerm(84, originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2); alternative.AddUtilityTerm(85, destinationParcel.HouseholdsBuffer2 + destinationParcel.StudentsUniversityBuffer2 + destinationParcel.EmploymentTotalBuffer2); alternative.AddUtilityTerm(86, income0To25KFlag); alternative.AddUtilityTerm(87, incomeOver100Flag); alternative.AddUtilityTerm(88, mealTourFlag); alternative.AddUtilityTerm(89, shoppingTourFlag); } else { double modeConstant = Global.Configuration.AV_PaidRideShareModeUsesAVs ? Global.Configuration.AV_PaidRideShare_ModeConstant + Global.Configuration.AV_PaidRideShare_DensityCoefficient * Math.Min(originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2, (Global.Configuration.PaidRideShare_DensityMeasureCapValue > 0) ? Global.Configuration.PaidRideShare_DensityMeasureCapValue : 6000) + Global.Configuration.AV_PaidRideShare_AVOwnerCoefficient * (household.OwnsAutomatedVehicles > 0).ToFlag() : Global.Configuration.PaidRideShare_ModeConstant + Global.Configuration.PaidRideShare_DensityCoefficient * Math.Min(originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2, (Global.Configuration.PaidRideShare_DensityMeasureCapValue > 0) ? Global.Configuration.PaidRideShare_DensityMeasureCapValue : 6000); alternative.AddUtilityTerm(90, modeConstant); alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_Age26to35Coefficient * tour.Person.AgeIsBetween26And35.ToFlag()); alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_Age18to25Coefficient * tour.Person.AgeIsBetween18And25.ToFlag()); alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_AgeOver65Coefficient * (tour.Person.Age >= 65).ToFlag()); } } RegionSpecificCustomizations(alternative, tour, pathTypeModel.PathType, mode, destinationParcel); } }
public void SetUtilities(ISampleItem sampleItem, int sampleFrequency) { if (sampleItem == null) { throw new ArgumentNullException("sampleItem"); } ChoiceProbabilityCalculator.Alternative alternative = sampleItem.Alternative; if (!alternative.Available) { return; } IHouseholdWrapper household = _tour.Household; IPersonWrapper person = _tour.Person; //var personDay = _tour.PersonDay; bool householdHasChildren = household.HasChildren; bool householdHasNoChildren = householdHasChildren ? false : true; IParcelWrapper destinationParcel = ChoiceModelFactory.Parcels[sampleItem.ParcelId]; int jointTourFlag = (_tour.JointTourSequence > 0).ToFlag(); double fastestTravelTime = ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Hov3, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, _fastestAvailableTimeOfDay, _tour.OriginParcel, destinationParcel).Variable + ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Hov3, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, _fastestAvailableTimeOfDay, destinationParcel, _tour.OriginParcel).Variable; if (fastestTravelTime >= _maxAvailableMinutes) { alternative.Available = false; return; } alternative.Choice = destinationParcel; //double tourLogsum = 0; double jointTourLogsum = 0; double workTourLogsum = 0; double otherTourLogsum = 0; double subtourLogsum = 0; if (_tour.IsHomeBasedTour) { if (_tour.DestinationPurpose == Global.Settings.Purposes.Work) { //var destinationArrivalTime = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.WorkTourModeModel); //var destinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.WorkTourModeModel); ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().RunNested(_tour, destinationParcel, _tour.Household.VehiclesAvailable, _tour.Person.GetTransitFareDiscountFraction()); workTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } // else if (_tour.DestinationPurpose == Global.Settings.Purposes.Escort) { // var nestedAlternative = (Global.ChoiceModelDictionary.Get("HEscortTourModeModel") as HEscortTourModeModel).RunNested(_tour, destinationParcel); // tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); // } else { ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <OtherHomeBasedTourModeTimeModel>().RunNested(_tour, destinationParcel, _tour.Household.VehiclesAvailable, _tour.Person.GetTransitFareDiscountFraction()); if (_tour.JointTourSequence > 0) { jointTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } else { otherTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } } } else { ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <WorkBasedSubtourModeTimeModel>().RunNested(_tour, destinationParcel, _tour.Household.VehiclesAvailable, _tour.Person.GetTransitFareDiscountFraction()); subtourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } //var purpose = _tour.TourPurposeSegment; //var carOwnership = person.CarOwnershipSegment; //var votSegment = _tour.VotALSegment; //var transitAccess = destinationParcel.TransitAccessSegment(); //var aggregateLogsum = Global.AggregateLogsums[destinationParcel.ZoneId][purpose][carOwnership][votSegment][transitAccess]; //var aggregateLogsumHomeBased = Global.AggregateLogsums[destinationParcel.ZoneId][Global.Settings.Purposes.HomeBasedComposite][carOwnership][votSegment][transitAccess]; //var aggregateLogsumWorkBased = Global.AggregateLogsums[destinationParcel.ZoneId][Global.Settings.Purposes.Work_BASED][carOwnership][votSegment][transitAccess]; double distanceFromOrigin = _tour.OriginParcel.DistanceFromOrigin(destinationParcel, _tour.DestinationArrivalTime); double piecewiseDistanceFrom5To10Miles = Math.Max(0, Math.Min(distanceFromOrigin - .5, 1 - .5)); double piecewiseDistanceFrom10MilesToInfinity = Math.Max(0, distanceFromOrigin - 1); double piecewiseDistanceFrom0To1Mile = Math.Min(distanceFromOrigin, .10); double piecewiseDistanceFrom1To5Miles = Math.Max(0, Math.Min(distanceFromOrigin - .1, .5 - .1)); double piecewiseDistanceFrom1To3AndAHalfMiles = Math.Max(0, Math.Min(distanceFromOrigin - .1, .35 - .1)); double piecewiseDistanceFrom3AndAHalfTo10Miles = Math.Max(0, Math.Min(distanceFromOrigin - .35, 1 - .35)); double distanceFromOriginLog = Math.Log(1 + distanceFromOrigin); //var distanceFromWorkLog = person.UsualWorkParcel.DistanceFromWorkLog(destinationParcel, 1); double distanceFromSchoolLog = person.UsualSchoolParcel.DistanceFromSchoolLog(destinationParcel, 1); double timePressure = Math.Log(1 - fastestTravelTime / _maxAvailableMinutes); // log transforms of buffers for Neighborhood effects double logOfOnePlusEmploymentEducationBuffer1 = Math.Log(destinationParcel.EmploymentEducationBuffer1 + 1.0); double logOfOnePlusEmploymentFoodBuffer1 = Math.Log(destinationParcel.EmploymentFoodBuffer1 + 1.0); double logOfOnePlusEmploymentGovernmentBuffer1 = Math.Log(destinationParcel.EmploymentGovernmentBuffer1 + 1.0); double logOfOnePlusEmploymentOfficeBuffer1 = Math.Log(destinationParcel.EmploymentOfficeBuffer1 + 1.0); double logOfOnePlusEmploymentRetailBuffer1 = Math.Log(destinationParcel.EmploymentRetailBuffer1 + 1.0); double logOfOnePlusEmploymentServiceBuffer1 = Math.Log(destinationParcel.EmploymentServiceBuffer1 + 1.0); double logOfOnePlusEmploymentMedicalBuffer1 = Math.Log(destinationParcel.EmploymentMedicalBuffer1 + 1.0); double logOfOnePlusEmploymentIndustrial_Ag_ConstructionBuffer1 = Math.Log(destinationParcel.EmploymentIndustrialBuffer1 + destinationParcel.EmploymentAgricultureConstructionBuffer1 + 1.0); double logOfOnePlusEmploymentTotalBuffer1 = Math.Log(destinationParcel.EmploymentTotalBuffer1 + 1.0); double logOfOnePlusHouseholdsBuffer1 = Math.Log(destinationParcel.HouseholdsBuffer1 + 1.0); double logOfOnePlusStudentsK12Buffer1 = Math.Log(destinationParcel.StudentsK8Buffer1 + destinationParcel.StudentsHighSchoolBuffer1 + 1.0); double logOfOnePlusStudentsUniversityBuffer1 = Math.Log(destinationParcel.StudentsUniversityBuffer1 + 1.0); // var EMPHOU_B = Math.Log(destinationParcel.EmploymentTotalBuffer1 + destinationParcel.HouseholdsBuffer1 + 1.0); //var logOfOnePlusParkingOffStreetDailySpacesBuffer1 = Math.Log(1 + destinationParcel.ParkingOffStreetPaidDailySpacesBuffer1); // connectivity attributes //var c34Ratio = destinationParcel.C34RatioBuffer1(); //var carCompetitionFlag = FlagUtility.GetCarCompetitionFlag(carOwnership); // exludes no cars //var noCarCompetitionFlag = FlagUtility.GetNoCarCompetitionFlag(carOwnership); //var noCarsFlag = FlagUtility.GetNoCarsFlag(carOwnership); alternative.AddUtilityTerm(2, sampleItem.AdjustmentFactor); alternative.AddUtilityTerm(3, workTourLogsum); alternative.AddUtilityTerm(4, otherTourLogsum); alternative.AddUtilityTerm(5, jointTourLogsum); alternative.AddUtilityTerm(6, subtourLogsum); //subpopulation-specific terms //alternative.AddUtilityTerm(260, _secondaryFlag * _workOrSchoolPatternFlag * piecewiseDistanceFrom0To1Mile); //alternative.AddUtilityTerm(261, _secondaryFlag * _workOrSchoolPatternFlag * piecewiseDistanceFrom1To5Miles); //alternative.AddUtilityTerm(262, _secondaryFlag * _workOrSchoolPatternFlag * piecewiseDistanceFrom5To10Miles); //alternative.AddUtilityTerm(263, _secondaryFlag * _workOrSchoolPatternFlag * piecewiseDistanceFrom10MilesToInfinity); alternative.AddUtilityTerm(260, _secondaryFlag * _workOrSchoolPatternFlag * distanceFromOriginLog); //alternative.AddUtilityTerm(264, _secondaryFlag * _otherPatternFlag * piecewiseDistanceFrom0To1Mile); //alternative.AddUtilityTerm(265, _secondaryFlag * _otherPatternFlag * piecewiseDistanceFrom1To5Miles); //alternative.AddUtilityTerm(266, _secondaryFlag * _otherPatternFlag * piecewiseDistanceFrom5To10Miles); //alternative.AddUtilityTerm(267, _secondaryFlag * _otherPatternFlag * piecewiseDistanceFrom10MilesToInfinity); alternative.AddUtilityTerm(264, _secondaryFlag * _otherPatternFlag * distanceFromOriginLog); alternative.AddUtilityTerm(268, (!_tour.IsHomeBasedTour).ToFlag() * distanceFromOriginLog); //alternative.AddUtilityTerm(269, household.Has0To15KIncome.ToFlag() * distanceFromOriginLog); //alternative.AddUtilityTerm(270, household.HasMissingIncome.ToFlag() * distanceFromOriginLog); //alternative.AddUtilityTerm(271, person.IsRetiredAdult.ToFlag() * distanceFromOriginLog); //alternative.AddUtilityTerm(272, person.IsUniversityStudent.ToFlag() * distanceFromOriginLog); alternative.AddUtilityTerm(273, person.IsChildAge5Through15.ToFlag() * distanceFromOriginLog); //alternative.AddUtilityTerm(274, person.IsChildUnder5.ToFlag() * distanceFromOriginLog); alternative.AddUtilityTerm(275, (_tour.IsHomeBasedTour).ToFlag() * timePressure); alternative.AddUtilityTerm(276, (_tour.IsHomeBasedTour).ToFlag() * distanceFromSchoolLog); //alternative.AddUtilityTerm(14, distanceFromWorkLog); //alternative.AddUtilityTerm(277, (carCompetitionFlag + noCarCompetitionFlag) * destinationParcel.ParkingHourlyEmploymentCommercialMixInParcel()); //alternative.AddUtilityTerm(278, noCarCompetitionFlag * destinationParcel.ParkingHourlyEmploymentCommercialMixInParcel()); //alternative.AddUtilityTerm(279, carCompetitionFlag * destinationParcel.ParkingHourlyEmploymentCommercialMixBuffer1()); //alternative.AddUtilityTerm(280, noCarCompetitionFlag * destinationParcel.ParkingHourlyEmploymentCommercialMixBuffer1()); //alternative.AddUtilityTerm(281, noCarsFlag * c34Ratio); //alternative.AddUtilityTerm(282, noCarCompetitionFlag * c34Ratio); //alternative.AddUtilityTerm(283, (carCompetitionFlag + noCarCompetitionFlag) * logOfOnePlusParkingOffStreetDailySpacesBuffer1); alternative.AddUtilityTerm(284, jointTourFlag * piecewiseDistanceFrom0To1Mile); alternative.AddUtilityTerm(285, jointTourFlag * piecewiseDistanceFrom1To5Miles); alternative.AddUtilityTerm(286, jointTourFlag * piecewiseDistanceFrom5To10Miles); alternative.AddUtilityTerm(287, jointTourFlag * piecewiseDistanceFrom10MilesToInfinity); if (_tour.DestinationPurpose == Global.Settings.Purposes.Work) { alternative.AddUtilityTerm(10, piecewiseDistanceFrom0To1Mile); alternative.AddUtilityTerm(11, piecewiseDistanceFrom1To3AndAHalfMiles); alternative.AddUtilityTerm(12, piecewiseDistanceFrom3AndAHalfTo10Miles); alternative.AddUtilityTerm(13, piecewiseDistanceFrom10MilesToInfinity); //alternative.AddUtilityTerm(14, aggregateLogsumWorkBased); // Neighborhood alternative.AddUtilityTerm(20, logOfOnePlusEmploymentEducationBuffer1); //alternative.AddUtilityTerm(21, logOfOnePlusEmploymentGovernmentBuffer1); alternative.AddUtilityTerm(22, logOfOnePlusEmploymentOfficeBuffer1); //alternative.AddUtilityTerm(23, logOfOnePlusEmploymentServiceBuffer1); alternative.AddUtilityTerm(24, logOfOnePlusEmploymentMedicalBuffer1); alternative.AddUtilityTerm(25, logOfOnePlusHouseholdsBuffer1); alternative.AddUtilityTerm(26, logOfOnePlusStudentsUniversityBuffer1); alternative.AddUtilityTerm(27, logOfOnePlusStudentsK12Buffer1); alternative.AddUtilityTerm(28, logOfOnePlusEmploymentIndustrial_Ag_ConstructionBuffer1); // Size terms alternative.AddUtilityTerm(30, destinationParcel.EmploymentEducation); alternative.AddUtilityTerm(31, destinationParcel.EmploymentFood); alternative.AddUtilityTerm(32, destinationParcel.EmploymentGovernment); alternative.AddUtilityTerm(33, destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(34, destinationParcel.EmploymentRetail); alternative.AddUtilityTerm(35, destinationParcel.EmploymentService); alternative.AddUtilityTerm(36, destinationParcel.EmploymentMedical); alternative.AddUtilityTerm(37, destinationParcel.EmploymentIndustrial + destinationParcel.EmploymentAgricultureConstruction); alternative.AddUtilityTerm(38, destinationParcel.Households); alternative.AddUtilityTerm(39, destinationParcel.GetStudentsK12()); //(for application) alternative.AddUtilityTerm(40, destinationParcel.StudentsUniversity); } else if (_tour.DestinationPurpose == Global.Settings.Purposes.Escort) { alternative.AddUtilityTerm(50, piecewiseDistanceFrom0To1Mile); alternative.AddUtilityTerm(51, piecewiseDistanceFrom1To3AndAHalfMiles); alternative.AddUtilityTerm(52, piecewiseDistanceFrom3AndAHalfTo10Miles); alternative.AddUtilityTerm(53, piecewiseDistanceFrom10MilesToInfinity); //alternative.AddUtilityTerm(54, aggregateLogsumHomeBased); // Neighborhood alternative.AddUtilityTerm(60, householdHasNoChildren.ToFlag() * logOfOnePlusEmploymentGovernmentBuffer1); alternative.AddUtilityTerm(61, householdHasNoChildren.ToFlag() * logOfOnePlusHouseholdsBuffer1); //alternative.AddUtilityTerm(62, householdHasChildren.ToFlag() * logOfOnePlusHouseholdsBuffer1); alternative.AddUtilityTerm(63, householdHasChildren.ToFlag() * logOfOnePlusStudentsK12Buffer1); alternative.AddUtilityTerm(64, logOfOnePlusEmploymentTotalBuffer1); // Size terms alternative.AddUtilityTerm(70, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentEducation); alternative.AddUtilityTerm(71, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentFood); alternative.AddUtilityTerm(72, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentGovernment); alternative.AddUtilityTerm(73, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(74, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentRetail); alternative.AddUtilityTerm(75, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentService); alternative.AddUtilityTerm(76, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentMedical); alternative.AddUtilityTerm(77, (!householdHasChildren).ToFlag() * (destinationParcel.EmploymentIndustrial + destinationParcel.EmploymentAgricultureConstruction)); alternative.AddUtilityTerm(78, (!householdHasChildren).ToFlag() * destinationParcel.Households); alternative.AddUtilityTerm(79, (!householdHasChildren).ToFlag() * destinationParcel.GetStudentsK12()); alternative.AddUtilityTerm(80, householdHasChildren.ToFlag() * destinationParcel.EmploymentEducation); alternative.AddUtilityTerm(81, householdHasChildren.ToFlag() * destinationParcel.EmploymentFood); alternative.AddUtilityTerm(82, householdHasChildren.ToFlag() * destinationParcel.EmploymentGovernment); alternative.AddUtilityTerm(83, householdHasChildren.ToFlag() * destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(84, householdHasChildren.ToFlag() * destinationParcel.EmploymentRetail); alternative.AddUtilityTerm(85, householdHasChildren.ToFlag() * destinationParcel.EmploymentService); alternative.AddUtilityTerm(86, householdHasChildren.ToFlag() * destinationParcel.EmploymentMedical); alternative.AddUtilityTerm(87, householdHasChildren.ToFlag() * (destinationParcel.EmploymentIndustrial + destinationParcel.EmploymentAgricultureConstruction)); alternative.AddUtilityTerm(88, householdHasChildren.ToFlag() * destinationParcel.Households); alternative.AddUtilityTerm(89, householdHasChildren.ToFlag() * destinationParcel.GetStudentsK12()); } else if (_tour.DestinationPurpose == Global.Settings.Purposes.PersonalBusiness) { alternative.AddUtilityTerm(90, piecewiseDistanceFrom0To1Mile); alternative.AddUtilityTerm(91, piecewiseDistanceFrom1To3AndAHalfMiles); alternative.AddUtilityTerm(92, piecewiseDistanceFrom3AndAHalfTo10Miles); alternative.AddUtilityTerm(93, piecewiseDistanceFrom10MilesToInfinity); //alternative.AddUtilityTerm(94, aggregateLogsumHomeBased); // Neighborhood alternative.AddUtilityTerm(100, logOfOnePlusEmploymentEducationBuffer1); alternative.AddUtilityTerm(101, logOfOnePlusEmploymentOfficeBuffer1); //alternative.AddUtilityTerm(102, logOfOnePlusEmploymentServiceBuffer1); //alternative.AddUtilityTerm(103, logOfOnePlusEmploymentMedicalBuffer1); alternative.AddUtilityTerm(104, logOfOnePlusHouseholdsBuffer1); //alternative.AddUtilityTerm(105, logOfOnePlusStudentsUniversityBuffer1); alternative.AddUtilityTerm(106, logOfOnePlusEmploymentGovernmentBuffer1); alternative.AddUtilityTerm(107, logOfOnePlusEmploymentRetailBuffer1); // Size terms alternative.AddUtilityTerm(110, destinationParcel.EmploymentEducation); alternative.AddUtilityTerm(111, destinationParcel.EmploymentFood); alternative.AddUtilityTerm(112, destinationParcel.EmploymentGovernment); alternative.AddUtilityTerm(113, destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(114, destinationParcel.EmploymentRetail); alternative.AddUtilityTerm(115, destinationParcel.EmploymentService); alternative.AddUtilityTerm(116, destinationParcel.EmploymentMedical); alternative.AddUtilityTerm(117, destinationParcel.EmploymentIndustrial + destinationParcel.EmploymentAgricultureConstruction); alternative.AddUtilityTerm(118, destinationParcel.Households); //(for application) alternative.AddUtilityTerm(119, destinationParcel.GetStudentsK12()); } else if (_tour.DestinationPurpose == Global.Settings.Purposes.Shopping) { alternative.AddUtilityTerm(120, piecewiseDistanceFrom0To1Mile); alternative.AddUtilityTerm(121, piecewiseDistanceFrom1To3AndAHalfMiles); alternative.AddUtilityTerm(122, piecewiseDistanceFrom3AndAHalfTo10Miles); alternative.AddUtilityTerm(123, piecewiseDistanceFrom10MilesToInfinity); //alternative.AddUtilityTerm(124, aggregateLogsumHomeBased); // Neighborhood alternative.AddUtilityTerm(130, logOfOnePlusEmploymentEducationBuffer1); alternative.AddUtilityTerm(131, logOfOnePlusEmploymentRetailBuffer1); // Size terms alternative.AddUtilityTerm(140, destinationParcel.EmploymentFood); alternative.AddUtilityTerm(141, destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(142, destinationParcel.EmploymentRetail); alternative.AddUtilityTerm(143, destinationParcel.EmploymentService); } else if (_tour.DestinationPurpose == Global.Settings.Purposes.Meal) { alternative.AddUtilityTerm(150, piecewiseDistanceFrom0To1Mile); alternative.AddUtilityTerm(151, piecewiseDistanceFrom1To3AndAHalfMiles); alternative.AddUtilityTerm(152, piecewiseDistanceFrom3AndAHalfTo10Miles); alternative.AddUtilityTerm(153, piecewiseDistanceFrom10MilesToInfinity); //alternative.AddUtilityTerm(154, aggregateLogsumHomeBased); // Neighborhood alternative.AddUtilityTerm(156, logOfOnePlusEmploymentFoodBuffer1); //alternative.AddUtilityTerm(157, logOfOnePlusEmploymentRetailBuffer1); alternative.AddUtilityTerm(158, logOfOnePlusEmploymentServiceBuffer1); // Size terms alternative.AddUtilityTerm(160, destinationParcel.EmploymentFood); //(for application) alternative.AddUtilityTerm(161, destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(162, destinationParcel.EmploymentTotal); alternative.AddUtilityTerm(163, destinationParcel.Households); } else if (_tour.DestinationPurpose == Global.Settings.Purposes.Social) { alternative.AddUtilityTerm(170, piecewiseDistanceFrom0To1Mile); alternative.AddUtilityTerm(171, piecewiseDistanceFrom1To3AndAHalfMiles); alternative.AddUtilityTerm(172, piecewiseDistanceFrom3AndAHalfTo10Miles); alternative.AddUtilityTerm(173, piecewiseDistanceFrom10MilesToInfinity); //alternative.AddUtilityTerm(174, aggregateLogsumHomeBased); // Neighborhood //alternative.AddUtilityTerm(180, logOfOnePlusEmploymentOfficeBuffer1); //alternative.AddUtilityTerm(181, logOfOnePlusEmploymentServiceBuffer1); //alternative.AddUtilityTerm(182, logOfOnePlusHouseholdsBuffer1); //alternative.AddUtilityTerm(183, logOfOnePlusStudentsK12Buffer1); //alternative.AddUtilityTerm(184, logOfOnePlusStudentsUniversityBuffer1); //alternative.AddUtilityTerm(185, logOfOnePlusEmploymentTotalBuffer1); // Size terms alternative.AddUtilityTerm(190, destinationParcel.EmploymentEducation); alternative.AddUtilityTerm(191, destinationParcel.EmploymentFood); alternative.AddUtilityTerm(192, destinationParcel.EmploymentGovernment); alternative.AddUtilityTerm(193, destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(194, destinationParcel.EmploymentRetail); alternative.AddUtilityTerm(195, destinationParcel.EmploymentService); alternative.AddUtilityTerm(196, destinationParcel.EmploymentMedical); alternative.AddUtilityTerm(197, destinationParcel.Households); alternative.AddUtilityTerm(198, destinationParcel.StudentsUniversity); //(for application) alternative.AddUtilityTerm(199, destinationParcel.GetStudentsK12()); } else if (_tour.DestinationPurpose == Global.Settings.Purposes.Recreation) { alternative.AddUtilityTerm(200, piecewiseDistanceFrom0To1Mile); alternative.AddUtilityTerm(201, piecewiseDistanceFrom1To3AndAHalfMiles); alternative.AddUtilityTerm(202, piecewiseDistanceFrom3AndAHalfTo10Miles); alternative.AddUtilityTerm(203, piecewiseDistanceFrom10MilesToInfinity); //alternative.AddUtilityTerm(204, aggregateLogsumHomeBased); // Neighborhood alternative.AddUtilityTerm(210, logOfOnePlusEmploymentOfficeBuffer1); alternative.AddUtilityTerm(211, logOfOnePlusEmploymentServiceBuffer1); alternative.AddUtilityTerm(212, logOfOnePlusHouseholdsBuffer1); //alternative.AddUtilityTerm(213, logOfOnePlusStudentsK12Buffer1); alternative.AddUtilityTerm(214, logOfOnePlusStudentsUniversityBuffer1); //alternative.AddUtilityTerm(215, logOfOnePlusEmploymentTotalBuffer1); // Size terms alternative.AddUtilityTerm(220, destinationParcel.EmploymentEducation); alternative.AddUtilityTerm(221, destinationParcel.EmploymentFood); alternative.AddUtilityTerm(222, destinationParcel.EmploymentGovernment); alternative.AddUtilityTerm(223, destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(224, destinationParcel.EmploymentRetail); alternative.AddUtilityTerm(225, destinationParcel.EmploymentService); alternative.AddUtilityTerm(226, destinationParcel.EmploymentMedical); alternative.AddUtilityTerm(227, destinationParcel.Households); alternative.AddUtilityTerm(228, destinationParcel.StudentsUniversity); alternative.AddUtilityTerm(229, destinationParcel.GetStudentsK12()); } else if (_tour.DestinationPurpose == Global.Settings.Purposes.Medical) { alternative.AddUtilityTerm(230, piecewiseDistanceFrom0To1Mile); alternative.AddUtilityTerm(231, piecewiseDistanceFrom1To3AndAHalfMiles); alternative.AddUtilityTerm(232, piecewiseDistanceFrom3AndAHalfTo10Miles); alternative.AddUtilityTerm(233, piecewiseDistanceFrom10MilesToInfinity); //alternative.AddUtilityTerm(234, aggregateLogsumHomeBased); // Neighborhood //alternative.AddUtilityTerm(240, logOfOnePlusEmploymentEducationBuffer1); //alternative.AddUtilityTerm(241, logOfOnePlusEmploymentOfficeBuffer1); //alternative.AddUtilityTerm(242, logOfOnePlusEmploymentServiceBuffer1); //alternative.AddUtilityTerm(243, logOfOnePlusEmploymentMedicalBuffer1); alternative.AddUtilityTerm(244, logOfOnePlusHouseholdsBuffer1); //alternative.AddUtilityTerm(245, logOfOnePlusStudentsUniversityBuffer1); //alternative.AddUtilityTerm(246, logOfOnePlusEmploymentGovernmentBuffer1); alternative.AddUtilityTerm(247, logOfOnePlusEmploymentRetailBuffer1); // Size terms //(for application) alternative.AddUtilityTerm(250, destinationParcel.EmploymentEducation); //(for application) alternative.AddUtilityTerm(251, destinationParcel.EmploymentFood); //(for application) alternative.AddUtilityTerm(252, destinationParcel.EmploymentGovernment); //(for application) alternative.AddUtilityTerm(253, destinationParcel.EmploymentOffice); //(for application) alternative.AddUtilityTerm(254, destinationParcel.EmploymentRetail); //(for application) alternative.AddUtilityTerm(255, destinationParcel.EmploymentService); alternative.AddUtilityTerm(256, destinationParcel.EmploymentMedical); //(for application) alternative.AddUtilityTerm(257, destinationParcel.EmploymentIndustrial + destinationParcel.EmploymentAgricultureConstruction); //(for application) alternative.AddUtilityTerm(258, destinationParcel.Households); //(for application) alternative.AddUtilityTerm(259, destinationParcel.GetStudentsK12()); } }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITourWrapper tour, IEnumerable <dynamic> pathTypeModels, IParcelWrapper destinationParcel, int choice = Constants.DEFAULT_VALUE) { var household = tour.Household; var householdTotals = household.HouseholdTotals; var person = tour.Person; var personDay = tour.PersonDay; // household inputs var income0To25KFlag = household.Has0To25KIncome.ToFlag(); var childrenUnder5 = householdTotals.ChildrenUnder5; var childrenAge5Through15 = householdTotals.ChildrenAge5Through15; var nonworkingAdults = householdTotals.NonworkingAdults; var retiredAdults = householdTotals.RetiredAdults; var onePersonHouseholdFlag = household.IsOnePersonHousehold.ToFlag(); var twoPersonHouseholdFlag = household.IsTwoPersonHousehold.ToFlag(); var noCarsInHouseholdFlag = household.GetFlagForNoCarsInHousehold(household.VehiclesAvailable); var carsLessThanDriversFlag = household.GetFlagForCarsLessThanDrivers(household.VehiclesAvailable); var carsLessThanWorkersFlag = household.GetFlagForCarsLessThanWorkers(household.VehiclesAvailable); // person inputs var maleFlag = person.IsMale.ToFlag(); var ageBetween51And98Flag = person.AgeIsBetween51And98.ToFlag(); // tour inputs var shoppingTourFlag = (tour.DestinationPurpose == Global.Settings.Purposes.Shopping).ToFlag(); var mealTourFlag = (tour.DestinationPurpose == Global.Settings.Purposes.Meal).ToFlag(); var socialOrRecreationTourFlag = (tour.DestinationPurpose == Global.Settings.Purposes.Social).ToFlag(); // remaining inputs var originParcel = tour.OriginParcel; var parkingDuration = ChoiceModelUtility.GetParkingDuration(person.IsFulltimeWorker); var destinationParkingCost = destinationParcel.ParkingCostBuffer1(parkingDuration); double escortPercentage; double nonEscortPercentage; ChoiceModelUtility.SetEscortPercentages(personDay, out escortPercentage, out nonEscortPercentage, true); //foreach (var pathTypeModel in pathTypeModels) { foreach (dynamic pathTypeModel in pathTypeModels) { IPathTypeModel ipathTypeModel = pathTypeModel; var mode = pathTypeModel.Mode; var available = pathTypeModel.Mode != Global.Settings.Modes.ParkAndRide && pathTypeModel.Available; var generalizedTimeLogsum = pathTypeModel.GeneralizedTimeLogsum; var alternative = choiceProbabilityCalculator.GetAlternative(mode, available, choice == mode); alternative.Choice = mode; alternative.AddNestedAlternative(_nestedAlternativeIds[pathTypeModel.Mode], _nestedAlternativeIndexes[pathTypeModel.Mode], THETA_PARAMETER); if (!available) { continue; } alternative.AddUtilityTerm(2, generalizedTimeLogsum * tour.TimeCoefficient); if (mode == Global.Settings.Modes.Transit) { alternative.AddUtilityTerm(20, 1); alternative.AddUtilityTerm(21, noCarsInHouseholdFlag); alternative.AddUtilityTerm(120, shoppingTourFlag); // alternative.AddUtility(121, mealTourFlag); // alternative.AddUtility(129, destinationParcel.MixedUse2Index1()); alternative.AddUtilityTerm(128, destinationParcel.TotalEmploymentDensity1()); // alternative.AddUtility(127, destinationParcel.NetIntersectionDensity1()); // alternative.AddUtility(126, originParcel.NetIntersectionDensity1()); // alternative.AddUtility(125, originParcel.HouseholdDensity1()); alternative.AddUtilityTerm(124, originParcel.MixedUse2Index1()); // alternative.AddUtility(123, Math.Log(destinationParcel.StopsTransitBuffer1+1)); // alternative.AddUtility(122, Math.Log(originParcel.StopsTransitBuffer1+1)); } else if (mode == Global.Settings.Modes.Hov3) { alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / ChoiceModelUtility.CPFACT3)); alternative.AddUtilityTerm(30, 1); alternative.AddUtilityTerm(31, childrenUnder5); alternative.AddUtilityTerm(32, childrenAge5Through15); alternative.AddUtilityTerm(34, nonworkingAdults + retiredAdults); alternative.AddUtilityTerm(35, ((double)pathTypeModel.PathDistance).AlmostEquals(0) ? 0 : Math.Log(pathTypeModel.PathDistance)); alternative.AddUtilityTerm(38, onePersonHouseholdFlag); alternative.AddUtilityTerm(39, twoPersonHouseholdFlag); alternative.AddUtilityTerm(41, noCarsInHouseholdFlag); alternative.AddUtilityTerm(43, carsLessThanWorkersFlag); alternative.AddUtilityTerm(133, escortPercentage); alternative.AddUtilityTerm(134, nonEscortPercentage); alternative.AddUtilityTerm(136, shoppingTourFlag); alternative.AddUtilityTerm(137, mealTourFlag); alternative.AddUtilityTerm(138, socialOrRecreationTourFlag); } else if (mode == Global.Settings.Modes.Hov2) { alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / ChoiceModelUtility.CPFACT2)); alternative.AddUtilityTerm(31, childrenUnder5); alternative.AddUtilityTerm(32, childrenAge5Through15); alternative.AddUtilityTerm(34, nonworkingAdults + retiredAdults); alternative.AddUtilityTerm(35, ((double)pathTypeModel.PathDistance).AlmostEquals(0) ? 0 : Math.Log(pathTypeModel.PathDistance)); alternative.AddUtilityTerm(40, 1); alternative.AddUtilityTerm(41, noCarsInHouseholdFlag); alternative.AddUtilityTerm(43, carsLessThanWorkersFlag); alternative.AddUtilityTerm(48, onePersonHouseholdFlag); alternative.AddUtilityTerm(133, escortPercentage); alternative.AddUtilityTerm(134, nonEscortPercentage); alternative.AddUtilityTerm(136, shoppingTourFlag); alternative.AddUtilityTerm(137, mealTourFlag); alternative.AddUtilityTerm(138, socialOrRecreationTourFlag); } else if (mode == Global.Settings.Modes.Sov) { alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient)); alternative.AddUtilityTerm(50, 1); alternative.AddUtilityTerm(52, carsLessThanDriversFlag); alternative.AddUtilityTerm(54, income0To25KFlag); alternative.AddUtilityTerm(131, escortPercentage); alternative.AddUtilityTerm(132, nonEscortPercentage); } else if (mode == Global.Settings.Modes.Bike) { double class1Dist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? ImpedanceRoster.GetValue("class1distance", mode, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0; double class2Dist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? ImpedanceRoster.GetValue("class2distance", mode, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0; double worstDist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? ImpedanceRoster.GetValue("worstdistance", mode, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0; alternative.AddUtilityTerm(60, 1); alternative.AddUtilityTerm(61, maleFlag); alternative.AddUtilityTerm(63, ageBetween51And98Flag); alternative.AddUtilityTerm(160, socialOrRecreationTourFlag); alternative.AddUtilityTerm(169, destinationParcel.MixedUse4Index1()); alternative.AddUtilityTerm(168, destinationParcel.TotalEmploymentDensity1()); // alternative.AddUtility(167, destinationParcel.NetIntersectionDensity1()); // alternative.AddUtility(166, originParcel.NetIntersectionDensity1()); alternative.AddUtilityTerm(165, originParcel.HouseholdDensity1()); alternative.AddUtilityTerm(164, originParcel.MixedUse4Index1()); alternative.AddUtilityTerm(161, (class1Dist > 0).ToFlag()); alternative.AddUtilityTerm(162, (class2Dist > 0).ToFlag()); alternative.AddUtilityTerm(163, (worstDist > 0).ToFlag()); } else if (mode == Global.Settings.Modes.Walk) { alternative.AddUtilityTerm(73, ageBetween51And98Flag); alternative.AddUtilityTerm(171, mealTourFlag); alternative.AddUtilityTerm(172, socialOrRecreationTourFlag); // alternative.AddUtility(179, destinationParcel.MixedUse4Index1()); alternative.AddUtilityTerm(178, destinationParcel.HouseholdDensity1()); // alternative.AddUtility(177, destinationParcel.NetIntersectionDensity1()); // alternative.AddUtility(176, originParcel.NetIntersectionDensity1()); alternative.AddUtilityTerm(175, originParcel.HouseholdDensity1()); // alternative.AddUtility(174, originParcel.MixedUse4Index1()); } } }
public void Run(IPersonWrapper person, int sampleSize) { if (person == null) { throw new ArgumentNullException("person"); } person.ResetRandom(1); if (Global.Configuration.IsInEstimationMode) { if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME) { return; } } var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator(person.Id); if (_helpers[ParallelUtility.GetBatchFromThreadId()].ModelIsInEstimationMode) { if (person.UsualSchoolParcel == null) { return; } var choseHome = person.UsualSchoolParcelId == person.Household.ResidenceParcelId; // JLB 20120403 added these two lines var chosenParcel = choseHome ? null : person.UsualSchoolParcel; //RunModel(choiceProbabilityCalculator, person, sampleSize, person.UsualSchoolParcel); RunModel(choiceProbabilityCalculator, person, sampleSize, chosenParcel, choseHome); // JLB 20120403 replaced above line // when chosenParcel is null: // DestinationSampler doesn't try to assign one of the sampled destinations as chosen // choseHome is NOT null, and RunModel sets the oddball location as chosen choiceProbabilityCalculator.WriteObservation(); } else { if (person.Household.HouseholdTotals.AllStudents > 1) { //determine if student goes to the same school as a sibling SiblingModel(person, person.Household.RandomUtility); } if (!(person.UsualSchoolParcelId > 0)) { RunModel(choiceProbabilityCalculator, person, sampleSize); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(person.Household.RandomUtility); var choice = (ParcelWrapper)chosenAlternative.Choice; person.UsualSchoolParcelId = choice.Id; person.UsualSchoolParcel = choice; person.UsualSchoolZoneKey = ChoiceModelFactory.ZoneKeys[choice.ZoneId]; var skimValue = ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, 1, person.Household.ResidenceParcel, choice); person.AutoTimeToUsualSchool = skimValue.Variable; person.AutoDistanceToUsualSchool = skimValue.BlendVariable; person.SetSchoolParcelPredictions(); } } }
public void SiblingModel(IPersonWrapper person, IRandomUtility random) { string ageGroup1 = "0"; string ageGroup2 = "0"; double thisPr = 0.0; if (person.Age < 6) { ageGroup1 = "15"; } else if (person.Age < 12) { ageGroup1 = "611"; } else if (person.Age < 14) { ageGroup1 = "1214"; } else if (person.Age <= 18) { ageGroup1 = "1518"; } foreach (PersonWrapper otherStu in person.Household.Persons) { if (otherStu.UsualSchoolParcelId > 0) { if (otherStu.Age < 6) { ageGroup2 = "15"; } else if (otherStu.Age < 12) { ageGroup2 = "611"; } if (otherStu.Age < 14) { ageGroup2 = "1214"; } else if (otherStu.Age <= 18) { ageGroup2 = "1518"; } if (prMatch.ContainsKey(ageGroup1 + ageGroup2)) { thisPr = prMatch[ageGroup1 + ageGroup2]; } if (random.Uniform01() < thisPr) { person.UsualSchoolParcelId = otherStu.UsualSchoolParcelId; person.UsualSchoolParcel = otherStu.UsualSchoolParcel; person.UsualSchoolZoneKey = ChoiceModelFactory.ZoneKeys[person.UsualSchoolParcel.ZoneId]; var skimValue = ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, 1, person.Household.ResidenceParcel, person.UsualSchoolParcel); person.AutoTimeToUsualSchool = skimValue.Variable; person.AutoDistanceToUsualSchool = skimValue.BlendVariable; person.SetSchoolParcelPredictions(); break; } } } }
public void SetUtilities(ISampleItem sampleItem, int sampleFrequency) { if (sampleItem == null) { throw new ArgumentNullException("sampleItem"); } var alternative = sampleItem.Alternative; if (!alternative.Available) { return; } var household = _tour.Household; var person = _tour.Person; // var personDay = _tour.PersonDay; var householdHasChildren = household.HasChildren; var destinationParcel = ChoiceModelFactory.Parcels[sampleItem.ParcelId]; var fastestTravelTime = ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Hov3, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, _fastestAvailableTimeOfDay, _tour.OriginParcel, destinationParcel).Variable + ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Hov3, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, _fastestAvailableTimeOfDay, destinationParcel, _tour.OriginParcel).Variable; if (fastestTravelTime >= _maxAvailableMinutes) { alternative.Available = false; return; } alternative.Choice = destinationParcel; double tourLogsum; if (_tour.IsHomeBasedTour) { if (_tour.DestinationPurpose == Global.Settings.Purposes.Escort) { var nestedAlternative = Global.ChoiceModelSession.Get <EscortTourModeModel>().RunNested(_tour, destinationParcel); tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } else { var nestedAlternative = Global.ChoiceModelSession.Get <OtherHomeBasedTourModeModel>().RunNested(_tour, destinationParcel); tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } } else { var nestedAlternative = Global.ChoiceModelSession.Get <WorkBasedSubtourModeModel>().RunNested(_tour, destinationParcel); tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } //var purpose = _tour.TourPurposeSegment; var carOwnership = person.GetCarOwnershipSegment(); //var votSegment = _tour.VotALSegment; //var transitAccess = destinationParcel.TransitAccessSegment(); //var aggregateLogsum = Global.AggregateLogsums[destinationParcel.ZoneId][purpose][carOwnership][votSegment][transitAccess]; //var aggregateLogsumHomeBased = Global.AggregateLogsums[destinationParcel.ZoneId][Global.Settings.Purposes.HomeBasedComposite][carOwnership][votSegment][transitAccess]; //var aggregateLogsumWorkBased = Global.AggregateLogsums[destinationParcel.ZoneId][Global.Settings.Purposes.Work_BASED][carOwnership][votSegment][transitAccess]; var distanceFromOrigin = _tour.OriginParcel.DistanceFromOrigin(destinationParcel, _tour.DestinationArrivalTime); var distanceFromOrigin0 = Math.Max(0, Math.Min(distanceFromOrigin - .5, 1 - .5)); var distanceFromOrigin3 = Math.Max(0, distanceFromOrigin - 1); var distanceFromOrigin4 = Math.Min(distanceFromOrigin, .10); var distanceFromOrigin5 = Math.Max(0, Math.Min(distanceFromOrigin - .1, .5 - .1)); var distanceFromOrigin8 = Math.Max(0, Math.Min(distanceFromOrigin - .1, .35 - .1)); var distanceFromOrigin9 = Math.Max(0, Math.Min(distanceFromOrigin - .35, 1 - .35)); var distanceFromOriginLog = Math.Log(1 + distanceFromOrigin); var distanceFromWorkLog = person.UsualWorkParcel.DistanceFromWorkLog(destinationParcel, 1); var distanceFromSchoolLog = person.UsualSchoolParcel.DistanceFromSchoolLog(destinationParcel, 1); var timePressure = Math.Log(1 - fastestTravelTime / _maxAvailableMinutes); // log transforms of buffers for Neighborhood effects var empEduBuffer = Math.Log(destinationParcel.EmploymentEducationBuffer1 + 1.0); var empFooBuffer = Math.Log(destinationParcel.EmploymentFoodBuffer1 + 1.0); // var EMPGOV_B = Math.Log(destinationParcel.EmploymentGovernmentBuffer1 + 1.0); var empOfcBuffer = Math.Log(destinationParcel.EmploymentOfficeBuffer1 + 1.0); var empRetBuffer = Math.Log(destinationParcel.EmploymentRetailBuffer1 + 1.0); var empSvcBuffer = Math.Log(destinationParcel.EmploymentServiceBuffer1 + 1.0); var empMedBuffer = Math.Log(destinationParcel.EmploymentMedicalBuffer1 + 1.0); // var EMPIND_B = Math.Log(destinationParcel.EmploymentIndustrialBuffer1 + destinationParcel.EmploymentAgricultureConstructionBuffer1 + 1.0); var empTotBuffer = Math.Log(destinationParcel.EmploymentTotalBuffer1 + 1.0); var housesBuffer = Math.Log(destinationParcel.HouseholdsBuffer1 + 1.0); var studK12Buffer = Math.Log(destinationParcel.StudentsK8Buffer1 + destinationParcel.StudentsHighSchoolBuffer1 + 1.0); var studUniBuffer = Math.Log(destinationParcel.StudentsUniversityBuffer1 + 1.0); // var EMPHOU_B = Math.Log(destinationParcel.EmploymentTotalBuffer1 + destinationParcel.HouseholdsBuffer1 + 1.0); // connectivity attributes var c34Ratio = destinationParcel.C34RatioBuffer1(); var carCompetitionFlag = FlagUtility.GetCarCompetitionFlag(carOwnership); // exludes no cars var noCarCompetitionFlag = FlagUtility.GetNoCarCompetitionFlag(carOwnership); var noCarsFlag = FlagUtility.GetNoCarsFlag(carOwnership); alternative.AddUtilityTerm(1, sampleItem.AdjustmentFactor); alternative.AddUtilityTerm(2, (_tour.IsHomeBasedTour).ToFlag() * timePressure); alternative.AddUtilityTerm(3, _secondaryFlag * _workOrSchoolPatternFlag * distanceFromOrigin0); alternative.AddUtilityTerm(4, _secondaryFlag * _otherPatternFlag * distanceFromOrigin5); alternative.AddUtilityTerm(5, _secondaryFlag * _otherPatternFlag * distanceFromOrigin0); alternative.AddUtilityTerm(6, _secondaryFlag * _otherPatternFlag * distanceFromOrigin3); alternative.AddUtilityTerm(7, (!_tour.IsHomeBasedTour).ToFlag() * distanceFromOriginLog); alternative.AddUtilityTerm(8, household.Has0To15KIncome.ToFlag() * distanceFromOriginLog); alternative.AddUtilityTerm(9, household.HasMissingIncome.ToFlag() * distanceFromOriginLog); alternative.AddUtilityTerm(10, person.IsRetiredAdult.ToFlag() * distanceFromOriginLog); alternative.AddUtilityTerm(11, person.IsChildAge5Through15.ToFlag() * distanceFromOriginLog); alternative.AddUtilityTerm(12, person.IsChildUnder5.ToFlag() * distanceFromOriginLog); alternative.AddUtilityTerm(13, (_tour.IsHomeBasedTour).ToFlag() * distanceFromSchoolLog); alternative.AddUtilityTerm(14, distanceFromWorkLog); alternative.AddUtilityTerm(15, carCompetitionFlag * destinationParcel.ParkingHourlyEmploymentCommercialMixInParcel()); alternative.AddUtilityTerm(16, noCarCompetitionFlag * destinationParcel.ParkingHourlyEmploymentCommercialMixInParcel()); alternative.AddUtilityTerm(17, carCompetitionFlag * destinationParcel.ParkingHourlyEmploymentCommercialMixBuffer1()); alternative.AddUtilityTerm(18, noCarCompetitionFlag * destinationParcel.ParkingHourlyEmploymentCommercialMixBuffer1()); alternative.AddUtilityTerm(19, noCarsFlag * c34Ratio); if (_tour.DestinationPurpose == Global.Settings.Purposes.Escort) { alternative.AddUtilityTerm(20, tourLogsum); alternative.AddUtilityTerm(21, distanceFromOrigin4); alternative.AddUtilityTerm(22, distanceFromOrigin8); alternative.AddUtilityTerm(23, distanceFromOrigin9); // Neighborhood alternative.AddUtilityTerm(24, householdHasChildren.ToFlag() * studK12Buffer); alternative.AddUtilityTerm(25, empTotBuffer); // Size terms alternative.AddUtilityTerm(71, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentEducation); alternative.AddUtilityTerm(72, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentFood); alternative.AddUtilityTerm(73, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentGovernment); alternative.AddUtilityTerm(74, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(75, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentRetail); alternative.AddUtilityTerm(76, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentService); alternative.AddUtilityTerm(77, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentMedical); alternative.AddUtilityTerm(78, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentIndustrial + destinationParcel.EmploymentAgricultureConstruction); alternative.AddUtilityTerm(79, (!householdHasChildren).ToFlag() * destinationParcel.Households); alternative.AddUtilityTerm(80, householdHasChildren.ToFlag() * destinationParcel.EmploymentEducation); alternative.AddUtilityTerm(81, householdHasChildren.ToFlag() * destinationParcel.EmploymentGovernment); alternative.AddUtilityTerm(82, householdHasChildren.ToFlag() * destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(83, householdHasChildren.ToFlag() * destinationParcel.EmploymentRetail); alternative.AddUtilityTerm(84, householdHasChildren.ToFlag() * destinationParcel.EmploymentService); alternative.AddUtilityTerm(85, householdHasChildren.ToFlag() * destinationParcel.EmploymentMedical); alternative.AddUtilityTerm(86, householdHasChildren.ToFlag() * destinationParcel.EmploymentIndustrial + destinationParcel.EmploymentAgricultureConstruction); alternative.AddUtilityTerm(87, householdHasChildren.ToFlag() * destinationParcel.Households); alternative.AddUtilityTerm(88, householdHasChildren.ToFlag() * destinationParcel.GetStudentsK12()); } else if (_tour.DestinationPurpose == Global.Settings.Purposes.PersonalBusiness || _tour.DestinationPurpose == Global.Settings.Purposes.Medical) { alternative.AddUtilityTerm(26, tourLogsum); alternative.AddUtilityTerm(27, distanceFromOrigin4); alternative.AddUtilityTerm(28, distanceFromOrigin8); alternative.AddUtilityTerm(29, distanceFromOrigin9); alternative.AddUtilityTerm(30, distanceFromOrigin3); // Neighborhood alternative.AddUtilityTerm(31, empEduBuffer); alternative.AddUtilityTerm(32, empSvcBuffer); alternative.AddUtilityTerm(33, empMedBuffer); alternative.AddUtilityTerm(34, housesBuffer); // also psrc alternative.AddUtilityTerm(35, studUniBuffer); // Size terms alternative.AddUtilityTerm(89, destinationParcel.EmploymentEducation); alternative.AddUtilityTerm(90, destinationParcel.EmploymentFood); alternative.AddUtilityTerm(91, destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(92, destinationParcel.EmploymentRetail); alternative.AddUtilityTerm(93, destinationParcel.EmploymentService); alternative.AddUtilityTerm(94, destinationParcel.EmploymentMedical); alternative.AddUtilityTerm(95, destinationParcel.EmploymentIndustrial + destinationParcel.EmploymentAgricultureConstruction); alternative.AddUtilityTerm(96, destinationParcel.Households); alternative.AddUtilityTerm(97, destinationParcel.GetStudentsK12()); } else if (_tour.DestinationPurpose == Global.Settings.Purposes.Shopping) { alternative.AddUtilityTerm(36, tourLogsum); alternative.AddUtilityTerm(37, distanceFromOrigin4); alternative.AddUtilityTerm(38, distanceFromOrigin8); alternative.AddUtilityTerm(39, distanceFromOrigin9); alternative.AddUtilityTerm(40, distanceFromOrigin3); // Neighborhood alternative.AddUtilityTerm(41, empEduBuffer); // also psrc alternative.AddUtilityTerm(42, empRetBuffer); // also psrc // Size terms alternative.AddUtilityTerm(98, destinationParcel.EmploymentFood); alternative.AddUtilityTerm(99, destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(100, destinationParcel.EmploymentRetail); alternative.AddUtilityTerm(101, destinationParcel.EmploymentService); } else if (_tour.DestinationPurpose == Global.Settings.Purposes.Meal) { alternative.AddUtilityTerm(43, tourLogsum); alternative.AddUtilityTerm(44, distanceFromOrigin4); alternative.AddUtilityTerm(45, distanceFromOrigin8); alternative.AddUtilityTerm(46, distanceFromOrigin9); alternative.AddUtilityTerm(47, distanceFromOrigin3); // Neighborhood alternative.AddUtilityTerm(48, empFooBuffer); // psrc // Size terms alternative.AddUtilityTerm(102, destinationParcel.EmploymentFood); alternative.AddUtilityTerm(103, destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(104, destinationParcel.EmploymentTotal); alternative.AddUtilityTerm(105, destinationParcel.Households); } else if (_tour.DestinationPurpose == Global.Settings.Purposes.Social || _tour.DestinationPurpose == Global.Settings.Purposes.Recreation) { alternative.AddUtilityTerm(49, tourLogsum); alternative.AddUtilityTerm(50, distanceFromOrigin4); alternative.AddUtilityTerm(51, distanceFromOrigin8); alternative.AddUtilityTerm(52, distanceFromOrigin9); alternative.AddUtilityTerm(53, distanceFromOrigin3); // Neighborhood alternative.AddUtilityTerm(54, empOfcBuffer); // also psrc alternative.AddUtilityTerm(55, empSvcBuffer); // also psrc alternative.AddUtilityTerm(56, housesBuffer); // also psrc alternative.AddUtilityTerm(57, studUniBuffer); // psrc // Size terms alternative.AddUtilityTerm(106, destinationParcel.EmploymentFood); alternative.AddUtilityTerm(107, destinationParcel.EmploymentGovernment); alternative.AddUtilityTerm(108, destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(109, destinationParcel.EmploymentRetail); alternative.AddUtilityTerm(110, destinationParcel.EmploymentService); alternative.AddUtilityTerm(111, destinationParcel.Households); alternative.AddUtilityTerm(112, destinationParcel.StudentsUniversity); alternative.AddUtilityTerm(113, destinationParcel.GetStudentsK12()); } //add any region-specific new terms in region-specific class, using coefficient numbers 114-120, or other unused variable # _parentClass.RegionSpecificOtherTourDistrictCoefficients(alternative, _tour, destinationParcel); // OD shadow pricing if (Global.Configuration.ShouldUseODShadowPricing) { var ori = _tour.OriginParcel.District; var des = destinationParcel.District; //var first = res <= des? res : des; //var second = res <= des? des : res; var shadowPriceConfigurationParameter = ori == des ? Global.Configuration.OtherTourDestinationOOShadowPriceCoefficient : Global.Configuration.OtherTourDestinationODShadowPriceCoefficient; var odShadowPriceF12Value = MAX_REGULAR_PARAMETER + Global.Configuration.NumberOfODShadowPricingDistricts * (ori - 1) + des; alternative.AddUtilityTerm(odShadowPriceF12Value, shadowPriceConfigurationParameter); } }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITourWrapper tour, IEnumerable <IPathTypeModel> pathTypeModels, IParcelWrapper destinationParcel, int householdCars, int choice = Constants.DEFAULT_VALUE) { IHouseholdWrapper household = tour.Household; IPersonWrapper person = tour.Person; IPersonDayWrapper personDay = tour.PersonDay; // household inputs int income0To25KFlag = household.Has0To25KIncome.ToFlag(); int income25To50KFlag = household.Has25To50KIncome.ToFlag(); int income75KPlusFlag = household.Has75KPlusIncome.ToFlag(); int incomeOver100Flag = household.Has100KPlusIncome.ToFlag(); int onePersonHouseholdFlag = household.IsOnePersonHousehold.ToFlag(); int twoPersonHouseholdFlag = household.IsTwoPersonHousehold.ToFlag(); int noCarsInHouseholdFlag = household.GetFlagForNoCarsInHousehold(householdCars); int carsLessThanDriversFlag = household.GetFlagForCarsLessThanDrivers(householdCars); int carsLessThanWorkersFlag = household.GetFlagForCarsLessThanWorkers(householdCars); // person inputs int childUnder5Flag = person.IsChildUnder5.ToFlag(); int adultFlag = person.IsAdult.ToFlag(); int drivingAgeStudentFlag = person.IsDrivingAgeStudent.ToFlag(); int maleFlag = person.IsMale.ToFlag(); // remaining inputs IParcelWrapper originParcel = tour.OriginParcel; double destinationParkingCost = destinationParcel.ParkingCostBuffer1(6); ChoiceModelUtility.SetEscortPercentages(personDay, out double escortPercentage, out double nonEscortPercentage); // school bus is a special case - use HOV3 impedance { IPathTypeModel pathTypeExtra = pathTypeModels.First(x => x.Mode == Global.Settings.Modes.Hov3); int modeExtra = Global.Settings.Modes.SchoolBus; bool availableExtra = pathTypeExtra.Available; double generalizedTimeLogsumExtra = pathTypeExtra.GeneralizedTimeLogsum; ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(modeExtra, availableExtra, choice == modeExtra); alternative.Choice = modeExtra; alternative.AddNestedAlternative(_nestedAlternativeIds[modeExtra], _nestedAlternativeIndexes[modeExtra], THETA_PARAMETER); if (availableExtra) { // case Global.Settings.Modes.SchoolBus: alternative.AddUtilityTerm(2, generalizedTimeLogsumExtra * tour.TimeCoefficient); alternative.AddUtilityTerm(10, 1); alternative.AddUtilityTerm(11, noCarsInHouseholdFlag); // for calibration alternative.AddUtilityTerm(13, carsLessThanDriversFlag); // for calibration alternative.AddUtilityTerm(17, childUnder5Flag); alternative.AddUtilityTerm(18, adultFlag); } } foreach (IPathTypeModel pathTypeModel in pathTypeModels) { int mode = pathTypeModel.Mode; bool available = (pathTypeModel.Mode != Global.Settings.Modes.ParkAndRide || Global.Configuration.IncludeParkAndRideInSchoolTourModeModel) && (pathTypeModel.Mode != Global.Settings.Modes.PaidRideShare || Global.Configuration.PaidRideShareModeIsAvailable) && pathTypeModel.Available; double generalizedTimeLogsum = pathTypeModel.GeneralizedTimeLogsum; ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(mode, available, choice == mode); alternative.Choice = mode; alternative.AddNestedAlternative(_nestedAlternativeIds[mode], _nestedAlternativeIndexes[mode], THETA_PARAMETER); if (!available) { continue; } double modeTimeCoefficient = (Global.Configuration.AV_IncludeAutoTypeChoice && household.OwnsAutomatedVehicles > 0 && mode >= Global.Settings.Modes.Sov && mode <= Global.Settings.Modes.Hov3) ? tour.TimeCoefficient * (1.0 - Global.Configuration.AV_InVehicleTimeCoefficientDiscountFactor) : (mode == Global.Settings.Modes.PaidRideShare && Global.Configuration.AV_PaidRideShareModeUsesAVs) ? tour.TimeCoefficient * (1.0 - Global.Configuration.AV_InVehicleTimeCoefficientDiscountFactor) : tour.TimeCoefficient; alternative.AddUtilityTerm(2, generalizedTimeLogsum * modeTimeCoefficient); if (mode == Global.Settings.Modes.ParkAndRide) { alternative.AddUtilityTerm(5, 1); alternative.AddUtilityTerm(6, noCarsInHouseholdFlag); alternative.AddUtilityTerm(7, carsLessThanWorkersFlag); alternative.AddUtilityTerm(129, destinationParcel.MixedUse2Index1()); } else if (mode == Global.Settings.Modes.Transit) { alternative.AddUtilityTerm(20, 1); alternative.AddUtilityTerm(21, noCarsInHouseholdFlag); alternative.AddUtilityTerm(22, carsLessThanDriversFlag); alternative.AddUtilityTerm(27, childUnder5Flag); alternative.AddUtilityTerm(28, adultFlag); alternative.AddUtilityTerm(29, drivingAgeStudentFlag); alternative.AddUtilityTerm(129, destinationParcel.MixedUse2Index1()); alternative.AddUtilityTerm(128, destinationParcel.TotalEmploymentDensity1()); alternative.AddUtilityTerm(123, (tour.OriginParcel.DistanceToFerry > 0 && tour.OriginParcel.DistanceToFerry <= 0.5).ToFlag()); alternative.AddUtilityTerm(124, (destinationParcel.DistanceToFerry > 0 && destinationParcel.DistanceToFerry <= 0.5).ToFlag()); //alternative.AddUtilityTerm(125, 0.001 * originParcel.NetIntersectionDensity1() // + 0.0001 * originParcel.HouseholdDensity1() // + 1.0 * originParcel.MixedUse4Index1()); //alternative.AddUtilityTerm(126, 1.0 * destinationParcel.MixedUse4Index1() // + 0.00001 * destinationParcel.TotalEmploymentDensity1() // + 0.001 * destinationParcel.NetIntersectionDensity1()); // alternative.AddUtilityTerm(127, destinationParcel.NetIntersectionDensity1()); // alternative.AddUtilityTerm(126, originParcel.NetIntersectionDensity1()); // alternative.AddUtilityTerm(125, originParcel.HouseholdDensity1()); // alternative.AddUtilityTerm(124, originParcel.MixedUse2Index1()); // alternative.AddUtilityTerm(123, Math.Log(destinationParcel.StopsTransitBuffer1+1)); alternative.AddUtilityTerm(122, Math.Log(originParcel.StopsTransitBuffer1 + 1)); } else if (mode == Global.Settings.Modes.Hov3) { alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / ChoiceModelUtility.CPFACT3)); alternative.AddUtilityTerm(30, 1); alternative.AddUtilityTerm(37, twoPersonHouseholdFlag); alternative.AddUtilityTerm(37, onePersonHouseholdFlag); alternative.AddUtilityTerm(36, noCarsInHouseholdFlag); // for calibration of hov3 vs hov2 alternative.AddUtilityTerm(35, carsLessThanDriversFlag); // for calibration of hov3 vs hov2 alternative.AddUtilityTerm(41, noCarsInHouseholdFlag); alternative.AddUtilityTerm(44, income0To25KFlag); alternative.AddUtilityTerm(45, income25To50KFlag); alternative.AddUtilityTerm(47, childUnder5Flag); alternative.AddUtilityTerm(133, escortPercentage); alternative.AddUtilityTerm(134, nonEscortPercentage); } else if (mode == Global.Settings.Modes.Hov2) { alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / ChoiceModelUtility.CPFACT2)); alternative.AddUtilityTerm(38, onePersonHouseholdFlag); alternative.AddUtilityTerm(40, 1); alternative.AddUtilityTerm(41, noCarsInHouseholdFlag); alternative.AddUtilityTerm(42, carsLessThanDriversFlag); // for calibration alternative.AddUtilityTerm(44, income0To25KFlag); alternative.AddUtilityTerm(45, income25To50KFlag); alternative.AddUtilityTerm(47, childUnder5Flag); alternative.AddUtilityTerm(133, escortPercentage); alternative.AddUtilityTerm(134, nonEscortPercentage); } else if (mode == Global.Settings.Modes.Sov) { alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient)); alternative.AddUtilityTerm(50, 1); alternative.AddUtilityTerm(52, carsLessThanDriversFlag); alternative.AddUtilityTerm(54, income0To25KFlag); alternative.AddUtilityTerm(56, income75KPlusFlag); alternative.AddUtilityTerm(59, drivingAgeStudentFlag); alternative.AddUtilityTerm(131, escortPercentage); alternative.AddUtilityTerm(132, nonEscortPercentage); } else if (mode == Global.Settings.Modes.Bike) { double class1Dist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? ImpedanceRoster.GetValue("class1distance", mode, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0; double class2Dist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? ImpedanceRoster.GetValue("class2distance", mode, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0; double worstDist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? ImpedanceRoster.GetValue("worstdistance", mode, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0; alternative.AddUtilityTerm(60, 1); alternative.AddUtilityTerm(61, maleFlag); alternative.AddUtilityTerm(67, noCarsInHouseholdFlag); //for calibration alternative.AddUtilityTerm(68, carsLessThanDriversFlag); //for calibration alternative.AddUtilityTerm(69, adultFlag); alternative.AddUtilityTerm(169, destinationParcel.MixedUse4Index1()); alternative.AddUtilityTerm(168, destinationParcel.TotalEmploymentDensity1()); alternative.AddUtilityTerm(167, destinationParcel.NetIntersectionDensity1()); alternative.AddUtilityTerm(166, originParcel.NetIntersectionDensity1()); alternative.AddUtilityTerm(165, originParcel.HouseholdDensity1()); alternative.AddUtilityTerm(164, originParcel.MixedUse4Index1()); alternative.AddUtilityTerm(161, (class1Dist > 0).ToFlag()); alternative.AddUtilityTerm(162, (class2Dist > 0).ToFlag()); alternative.AddUtilityTerm(163, (worstDist > 0).ToFlag()); alternative.AddUtilityTerm(170, 1.0 * destinationParcel.MixedUse4Index1() + 0.00002 * destinationParcel.TotalEmploymentDensity1() + 0.001 * destinationParcel.NetIntersectionDensity1() + 0.001 * originParcel.NetIntersectionDensity1() + 0.0002 * originParcel.HouseholdDensity1() + 1.0 * originParcel.MixedUse4Index1()); } else if (mode == Global.Settings.Modes.Walk) { alternative.AddUtilityTerm(70, 1); alternative.AddUtilityTerm(77, noCarsInHouseholdFlag); //for calibration alternative.AddUtilityTerm(78, carsLessThanDriversFlag); //for calibration alternative.AddUtilityTerm(79, adultFlag); alternative.AddUtilityTerm(179, destinationParcel.MixedUse4Index1()); alternative.AddUtilityTerm(178, destinationParcel.TotalEmploymentDensity1()); alternative.AddUtilityTerm(177, destinationParcel.NetIntersectionDensity1()); alternative.AddUtilityTerm(176, originParcel.NetIntersectionDensity1()); alternative.AddUtilityTerm(175, originParcel.HouseholdDensity1()); alternative.AddUtilityTerm(179, originParcel.MixedUse4Index1()); alternative.AddUtilityTerm(181, 1.0 * destinationParcel.MixedUse4Index1() + 0.00001 * destinationParcel.TotalEmploymentDensity1() + 0.001 * destinationParcel.NetIntersectionDensity1() + 0.001 * originParcel.NetIntersectionDensity1() + 0.0001 * originParcel.HouseholdDensity1() + 1.0 * originParcel.MixedUse4Index1()); } else if (mode == Global.Settings.Modes.PaidRideShare) { if (Global.Configuration.PaidRideshare_UseEstimatedInsteadOfAssertedCoefficients) { alternative.AddUtilityTerm(80, 1.0); alternative.AddUtilityTerm(81, noCarsInHouseholdFlag); //for calibration alternative.AddUtilityTerm(82, carsLessThanDriversFlag); //for calibration alternative.AddUtilityTerm(83, tour.Person.AgeIsBetween26And35.ToFlag()); alternative.AddUtilityTerm(83, tour.Person.AgeIsBetween18And25.ToFlag()); alternative.AddUtilityTerm(84, (tour.Person.Age < 18).ToFlag()); //alternative.AddUtilityTerm(81, tour.Person.AgeIsBetween26And35.ToFlag()); alternative.AddUtilityTerm(85, originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2); alternative.AddUtilityTerm(86, destinationParcel.HouseholdsBuffer2 + destinationParcel.StudentsUniversityBuffer2 + destinationParcel.EmploymentTotalBuffer2); alternative.AddUtilityTerm(87, income0To25KFlag); alternative.AddUtilityTerm(88, incomeOver100Flag); } else { double modeConstant = Global.Configuration.AV_PaidRideShareModeUsesAVs ? Global.Configuration.AV_PaidRideShare_ModeConstant + Global.Configuration.AV_PaidRideShare_DensityCoefficient * Math.Min(originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2, (Global.Configuration.PaidRideShare_DensityMeasureCapValue > 0) ? Global.Configuration.PaidRideShare_DensityMeasureCapValue : 6000) + Global.Configuration.AV_PaidRideShare_AVOwnerCoefficient * (household.OwnsAutomatedVehicles > 0).ToFlag() : Global.Configuration.PaidRideShare_ModeConstant + Global.Configuration.PaidRideShare_DensityCoefficient * Math.Min(originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2, (Global.Configuration.PaidRideShare_DensityMeasureCapValue > 0) ? Global.Configuration.PaidRideShare_DensityMeasureCapValue : 6000); alternative.AddUtilityTerm(90, modeConstant); alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_Age26to35Coefficient * tour.Person.AgeIsBetween26And35.ToFlag()); alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_Age18to25Coefficient * tour.Person.AgeIsBetween18And25.ToFlag()); alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_AgeOver65Coefficient * (tour.Person.Age >= 65).ToFlag()); } } RegionSpecificCustomizations(alternative, tour, pathTypeModel.PathType, mode, destinationParcel); } }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITourWrapper tour, IEnumerable <IPathTypeModel> pathTypeModels, IParcelWrapper destinationParcel, int householdCars, int choice = Constants.DEFAULT_VALUE) { var household = tour.Household; var person = tour.Person; var personDay = tour.PersonDay; // household inputs var income0To25KFlag = household.Has0To25KIncome.ToFlag(); var income25To50KFlag = household.Has25To50KIncome.ToFlag(); var income75KPlusFlag = household.Has75KPlusIncome.ToFlag(); var onePersonHouseholdFlag = household.IsOnePersonHousehold.ToFlag(); var twoPersonHouseholdFlag = household.IsTwoPersonHousehold.ToFlag(); var noCarsInHouseholdFlag = household.GetFlagForNoCarsInHousehold(householdCars); var carsLessThanDriversFlag = household.GetFlagForCarsLessThanDrivers(householdCars); // person inputs var childUnder5Flag = person.IsChildUnder5.ToFlag(); var adultFlag = person.IsAdult.ToFlag(); var drivingAgeStudentFlag = person.IsDrivingAgeStudent.ToFlag(); var maleFlag = person.IsMale.ToFlag(); // remaining inputs var originParcel = tour.OriginParcel; var destinationParkingCost = destinationParcel.ParkingCostBuffer1(6); double escortPercentage; double nonEscortPercentage; ChoiceModelUtility.SetEscortPercentages(personDay, out escortPercentage, out nonEscortPercentage); // school bus is a special case - use HOV3 impedance { var pathTypeExtra = pathTypeModels.First(x => x.Mode == Global.Settings.Modes.Hov3); var modeExtra = Global.Settings.Modes.SchoolBus; var availableExtra = pathTypeExtra.Available; var generalizedTimeLogsumExtra = pathTypeExtra.GeneralizedTimeLogsum; var alternative = choiceProbabilityCalculator.GetAlternative(modeExtra, availableExtra, choice == modeExtra); alternative.Choice = modeExtra; alternative.AddNestedAlternative(_nestedAlternativeIds[modeExtra], _nestedAlternativeIndexes[modeExtra], THETA_PARAMETER); if (availableExtra) { // case Global.Settings.Modes.SchoolBus: alternative.AddUtilityTerm(2, generalizedTimeLogsumExtra * tour.TimeCoefficient); alternative.AddUtilityTerm(10, 1); alternative.AddUtilityTerm(17, childUnder5Flag); alternative.AddUtilityTerm(18, adultFlag); } } // paidRideShare is another special case if (Global.Configuration.PaidRideShareModeIsAvailable) { var pathTypeExtra = pathTypeModels.First(x => x.Mode == Global.Settings.Modes.PaidRideShare); var modeExtra = Global.Settings.Modes.PaidRideShare; var availableExtra = pathTypeExtra.Available; var generalizedTimeLogsumExtra = pathTypeExtra.GeneralizedTimeLogsum; var distanceExtra = pathTypeExtra.PathDistance; var alternative = choiceProbabilityCalculator.GetAlternative(modeExtra - 2, availableExtra, choice == modeExtra); alternative.Choice = modeExtra; alternative.AddNestedAlternative(_nestedAlternativeIds[modeExtra], _nestedAlternativeIndexes[modeExtra], THETA_PARAMETER); if (availableExtra) { var extraCostPerMile = Global.Configuration.AV_PaidRideShareModeUsesAVs ? Global.Configuration.AV_PaidRideShare_ExtraCostPerDistanceUnit : Global.Configuration.PaidRideShare_ExtraCostPerDistanceUnit; var fixedCostPerRide = Global.Configuration.AV_PaidRideShareModeUsesAVs ? Global.Configuration.AV_PaidRideShare_FixedCostPerRide : Global.Configuration.PaidRideShare_FixedCostPerRide; var autoTimeCoefficient = Global.Configuration.AV_PaidRideShareModeUsesAVs ? tour.TimeCoefficient * (1.0 - Global.Configuration.AV_InVehicleTimeCoefficientDiscountFactor) : tour.TimeCoefficient; alternative.AddUtilityTerm(2, generalizedTimeLogsumExtra * autoTimeCoefficient); alternative.AddUtilityTerm(2, distanceExtra * extraCostPerMile * tour.CostCoefficient); alternative.AddUtilityTerm(2, fixedCostPerRide * tour.CostCoefficient); var modeConstant = Global.Configuration.AV_PaidRideShareModeUsesAVs ? Global.Configuration.AV_PaidRideShare_ModeConstant + Global.Configuration.AV_PaidRideShare_DensityCoefficient * Math.Min(originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2, 6000) + Global.Configuration.AV_PaidRideShare_AVOwnerCoefficient * (household.OwnsAutomatedVehicles > 0).ToFlag() : Global.Configuration.PaidRideShare_ModeConstant + Global.Configuration.PaidRideShare_DensityCoefficient * Math.Min(originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2, 6000); alternative.AddUtilityTerm(90, modeConstant); alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_Age26to35Coefficient * tour.Person.AgeIsBetween26And35.ToFlag()); alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_Age18to25Coefficient * tour.Person.AgeIsBetween18And25.ToFlag()); alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_AgeOver65Coefficient * (tour.Person.Age < 16).ToFlag()); } } foreach (var pathTypeModel in pathTypeModels) { var mode = pathTypeModel.Mode; var available = pathTypeModel.Available; var generalizedTimeLogsum = pathTypeModel.GeneralizedTimeLogsum; var alternative = choiceProbabilityCalculator.GetAlternative(mode, available, choice == mode); alternative.Choice = mode; alternative.AddNestedAlternative(_nestedAlternativeIds[mode], _nestedAlternativeIndexes[mode], THETA_PARAMETER); if (!available) { continue; } var modeTimeCoefficient = (Global.Configuration.AV_IncludeAutoTypeChoice && household.OwnsAutomatedVehicles > 0 && mode >= Global.Settings.Modes.Sov && mode <= Global.Settings.Modes.Hov3) ? tour.TimeCoefficient * (1.0 - Global.Configuration.AV_InVehicleTimeCoefficientDiscountFactor) : tour.TimeCoefficient; alternative.AddUtilityTerm(2, generalizedTimeLogsum * modeTimeCoefficient); if (mode == Global.Settings.Modes.Transit) { alternative.AddUtilityTerm(20, 1); alternative.AddUtilityTerm(21, noCarsInHouseholdFlag); alternative.AddUtilityTerm(22, carsLessThanDriversFlag); alternative.AddUtilityTerm(27, childUnder5Flag); alternative.AddUtilityTerm(28, adultFlag); alternative.AddUtilityTerm(29, drivingAgeStudentFlag); alternative.AddUtilityTerm(129, destinationParcel.MixedUse2Index1()); // alternative.AddUtilityTerm(128, destinationParcel.TotalEmploymentDensity1()); // alternative.AddUtilityTerm(127, destinationParcel.NetIntersectionDensity1()); // alternative.AddUtilityTerm(126, originParcel.NetIntersectionDensity1()); // alternative.AddUtilityTerm(125, originParcel.HouseholdDensity1()); // alternative.AddUtilityTerm(124, originParcel.MixedUse2Index1()); // alternative.AddUtilityTerm(123, Math.Log(destinationParcel.StopsTransitBuffer1+1)); alternative.AddUtilityTerm(122, Math.Log(originParcel.StopsTransitBuffer1 + 1)); } else if (mode == Global.Settings.Modes.Hov3) { alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / ChoiceModelUtility.CPFACT3)); alternative.AddUtilityTerm(30, 1); alternative.AddUtilityTerm(37, twoPersonHouseholdFlag); alternative.AddUtilityTerm(37, onePersonHouseholdFlag); alternative.AddUtilityTerm(41, noCarsInHouseholdFlag); alternative.AddUtilityTerm(44, income0To25KFlag); alternative.AddUtilityTerm(45, income25To50KFlag); alternative.AddUtilityTerm(47, childUnder5Flag); alternative.AddUtilityTerm(133, escortPercentage); alternative.AddUtilityTerm(134, nonEscortPercentage); } else if (mode == Global.Settings.Modes.Hov2) { alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / ChoiceModelUtility.CPFACT2)); alternative.AddUtilityTerm(38, onePersonHouseholdFlag); alternative.AddUtilityTerm(40, 1); alternative.AddUtilityTerm(41, noCarsInHouseholdFlag); alternative.AddUtilityTerm(44, income0To25KFlag); alternative.AddUtilityTerm(45, income25To50KFlag); alternative.AddUtilityTerm(47, childUnder5Flag); alternative.AddUtilityTerm(133, escortPercentage); alternative.AddUtilityTerm(134, nonEscortPercentage); } else if (mode == Global.Settings.Modes.Sov) { alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient)); alternative.AddUtilityTerm(50, 1); alternative.AddUtilityTerm(52, carsLessThanDriversFlag); alternative.AddUtilityTerm(54, income0To25KFlag); alternative.AddUtilityTerm(56, income75KPlusFlag); alternative.AddUtilityTerm(59, drivingAgeStudentFlag); alternative.AddUtilityTerm(131, escortPercentage); alternative.AddUtilityTerm(132, nonEscortPercentage); } else if (mode == Global.Settings.Modes.Bike) { double class1Dist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? ImpedanceRoster.GetValue("class1distance", mode, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0; double class2Dist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? ImpedanceRoster.GetValue("class2distance", mode, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0; double worstDist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? ImpedanceRoster.GetValue("worstdistance", mode, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0; alternative.AddUtilityTerm(60, 1); alternative.AddUtilityTerm(61, maleFlag); alternative.AddUtilityTerm(69, adultFlag); alternative.AddUtilityTerm(169, destinationParcel.MixedUse4Index1()); alternative.AddUtilityTerm(168, destinationParcel.TotalEmploymentDensity1()); // alternative.AddUtilityTerm(167, destinationParcel.NetIntersectionDensity1()); // alternative.AddUtilityTerm(166, originParcel.NetIntersectionDensity1()); // alternative.AddUtilityTerm(165, originParcel.HouseholdDensity1()); alternative.AddUtilityTerm(164, originParcel.MixedUse4Index1()); alternative.AddUtilityTerm(161, (class1Dist > 0).ToFlag()); alternative.AddUtilityTerm(162, (class2Dist > 0).ToFlag()); alternative.AddUtilityTerm(163, (worstDist > 0).ToFlag()); } else if (mode == Global.Settings.Modes.Walk) { alternative.AddUtilityTerm(70, 1); alternative.AddUtilityTerm(79, adultFlag); alternative.AddUtilityTerm(179, destinationParcel.MixedUse4Index1()); // alternative.AddUtilityTerm(178, destinationParcel.TotalEmploymentDensity1()); // alternative.AddUtilityTerm(177, destinationParcel.NetIntersectionDensity1()); // alternative.AddUtilityTerm(176, originParcel.NetIntersectionDensity1()); // alternative.AddUtilityTerm(175, originParcel.HouseholdDensity1()); alternative.AddUtilityTerm(179, originParcel.MixedUse4Index1()); } RegionSpecificCustomizations(alternative, tour, pathTypeModel.PathType, mode, destinationParcel); } }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, TourWrapper tour, HouseholdDayWrapper householdDay, int sampleSize, IParcelWrapper choice = null) { timesStartedRunModel++; HouseholdWrapper household = (HouseholdWrapper)tour.Household; PersonWrapper person = (PersonWrapper)tour.Person; PersonDayWrapper personDay = (PersonDayWrapper)tour.PersonDay; // var totalAvailableMinutes = // tour.ParentTour == null // ? personDay.TimeWindow.TotalAvailableMinutes(1, Global.Settings.Times.MinutesInADay) // : tour.ParentTour.TimeWindow.TotalAvailableMinutes(1, Global.Settings.Times.MinutesInADay); TimeWindow timeWindow = new TimeWindow(); if (tour.JointTourSequence > 0) { foreach (PersonDayWrapper pDay in householdDay.PersonDays) { TourWrapper tInJoint = (TourWrapper)pDay.Tours.Find(t => t.JointTourSequence == tour.JointTourSequence); if (!(tInJoint == null)) { // set jointTour time window timeWindow.IncorporateAnotherTimeWindow(tInJoint.PersonDay.TimeWindow); } } } else if (tour.ParentTour == null) { timeWindow.IncorporateAnotherTimeWindow(personDay.TimeWindow); } timeWindow.SetBusyMinutes(Global.Settings.Times.EndOfRelevantWindow, Global.Settings.Times.MinutesInADay + 1); var maxAvailableMinutes = (tour.JointTourSequence > 0 || tour.ParentTour == null) ? timeWindow.MaxAvailableMinutesAfter(Global.Settings.Times.FiveAM) : tour.ParentTour.DestinationDepartureTime - tour.ParentTour.DestinationArrivalTime; // var hoursAvailableInverse = // tour.IsHomeBasedTour // ? (personDay.HomeBasedTours - personDay.SimulatedHomeBasedTours + 1) / (Math.Max(totalAvailableMinutes - 360, 30) / 60D) // : 1 / (Math.Max(totalAvailableMinutes, 1) / 60D); var householdHasChildren = household.HasChildren; var householdHasNoChildren = householdHasChildren ? false : true; var fastestAvailableTimeOfDay = tour.IsHomeBasedTour || tour.ParentTour == null ? 1 : tour.ParentTour.DestinationArrivalTime + (tour.ParentTour.DestinationDepartureTime - tour.ParentTour.DestinationArrivalTime) / 2; var tourCategory = tour.GetTourCategory(); // var primaryFlag = ChoiceModelUtility.GetPrimaryFlag(tourCategory); var secondaryFlag = ChoiceModelUtility.GetSecondaryFlag(tourCategory); var workOrSchoolPatternFlag = personDay.GetIsWorkOrSchoolPattern().ToFlag(); var otherPatternFlag = personDay.GetIsOtherPattern().ToFlag(); int jointTourFlag = (tour.JointTourSequence > 0).ToFlag(); ChoiceModelUtility.DrawRandomTourTimePeriods(tour, tourCategory); if (tour.Household.Id == 80049 && tour.PersonDay.Day == 1 && tour.Person.Sequence == 2 && tour.Sequence == 4) { bool testbreak = true; } var segment = Global.Kernel.Get <SamplingWeightsSettingsFactory>().SamplingWeightsSettings.GetTourDestinationSegment(tour.DestinationPurpose, tour.IsHomeBasedTour ? Global.Settings.TourPriorities.HomeBasedTour : Global.Settings.TourPriorities.WorkBasedTour, Global.Settings.Modes.Sov, person.PersonType); var destinationSampler = new DestinationSampler(choiceProbabilityCalculator, segment, sampleSize, tour.OriginParcel, choice); var tourDestinationUtilities = new TourDestinationUtilities(tour, sampleSize, secondaryFlag, personDay.GetIsWorkOrSchoolPattern().ToFlag(), personDay.GetIsOtherPattern().ToFlag(), fastestAvailableTimeOfDay, maxAvailableMinutes); // get destination sample and perform code that used to be in SetUtilities below var sampleItems = destinationSampler.SampleAndReturnTourDestinations(tourDestinationUtilities); int index = 0; foreach (var sampleItem in sampleItems) { bool available = sampleItem.Key.Available; bool isChosen = sampleItem.Key.IsChosen; double adjustmentFactor = sampleItem.Key.AdjustmentFactor; var destinationParcel = ChoiceModelFactory.Parcels[sampleItem.Key.ParcelId]; if (isChosen) { Global.PrintFile.WriteLine("Sequence {0}: Chosen parcel {1} Available {2} Sample item {3} of {4}", timesStartedRunModel, destinationParcel.Id, available, index, sampleItems.Count); } var alternative = choiceProbabilityCalculator.GetAlternative(index++, available, isChosen); if (!available) { continue; } var fastestTravelTime = ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Hov3, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, fastestAvailableTimeOfDay, tour.OriginParcel, destinationParcel).Variable + ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Hov3, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, fastestAvailableTimeOfDay, destinationParcel, tour.OriginParcel).Variable; if (fastestTravelTime >= maxAvailableMinutes) { alternative.Available = false; continue; } alternative.Choice = destinationParcel; double tourLogsum; if (tour.IsHomeBasedTour) { if (tour.DestinationPurpose == Global.Settings.Purposes.Work) { //JLB 201406 //var nestedAlternative = Global.ChoiceModelSession.Get<WorkTourModeModel>().RunNested(tour, destinationParcel); // JLB 201602 //var nestedAlternative = Global.ChoiceModelSession.Get<WorkTourModeTimeModel>().RunNested(tour, destinationParcel, tour.Household.VehiclesAvailable, tour.Person.GetTransitFareDiscountFraction()); var nestedAlternative = Global.ChoiceModelSession.Get <TourModeTimeModel>().RunNested(tour, destinationParcel, tour.Household.VehiclesAvailable, tour.Person.GetTransitFareDiscountFraction()); tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } // JLB201406 //else if (tour.DestinationPurpose == Global.Settings.Purposes.Escort) { // var nestedAlternative = Global.ChoiceModelSession.Get<EscortTourModeModel>().RunNested(tour, destinationParcel); // tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); //} else { // JLB201406 //var nestedAlternative = Global.ChoiceModelSession.Get<OtherHomeBasedTourModeModel>().RunNested(tour, destinationParcel); // JLB 201602 //var nestedAlternative = Global.ChoiceModelSession.Get<OtherHomeBasedTourModeTimeModel>().RunNested(tour, destinationParcel, tour.Household.VehiclesAvailable, tour.Person.GetTransitFareDiscountFraction()); var nestedAlternative = Global.ChoiceModelSession.Get <TourModeTimeModel>().RunNested(tour, destinationParcel, tour.Household.VehiclesAvailable, tour.Person.GetTransitFareDiscountFraction()); tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } } else { // JLB201406 //var nestedAlternative = Global.ChoiceModelSession.Get<WorkBasedSubtourModeModel>().RunNested(tour, destinationParcel); // JLB 201602 //var nestedAlternative = Global.ChoiceModelSession.Get<WorkBasedSubtourModeTimeModel>().RunNested(tour, destinationParcel, tour.Household.VehiclesAvailable, tour.Person.GetTransitFareDiscountFraction()); var nestedAlternative = Global.ChoiceModelSession.Get <TourModeTimeModel>().RunNested(tour, destinationParcel, tour.Household.VehiclesAvailable, tour.Person.GetTransitFareDiscountFraction()); tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } //var purpose = tour.TourPurposeSegment; var carOwnership = person.GetCarOwnershipSegment(); var votSegment = tour.GetVotALSegment(); var transitAccess = destinationParcel.TransitAccessSegment(); //var aggregateLogsum = Global.AggregateLogsums[destinationParcel.ZoneId][purpose][carOwnership][votSegment][transitAccess]; var aggregateLogsumHomeBased = Global.AggregateLogsums[destinationParcel.ZoneId][Global.Settings.Purposes.HomeBasedComposite][carOwnership][votSegment][transitAccess]; var aggregateLogsumWorkBased = Global.AggregateLogsums[destinationParcel.ZoneId][Global.Settings.Purposes.WorkBased][carOwnership][votSegment][transitAccess]; var distanceFromOrigin = tour.OriginParcel.DistanceFromOrigin(destinationParcel, tour.DestinationArrivalTime); // 1. new from GV: Cph KM-distances var piecewiseDistanceFrom0To1Km = Math.Min(distanceFromOrigin, .10); var piecewiseDistanceFrom0To2Km = Math.Min(distanceFromOrigin, .20); //GV: added July 7th var piecewiseDistanceFrom0To5Km = Math.Min(distanceFromOrigin, .50); //GV: added July 7th var piecewiseDistanceFrom1To2Km = Math.Max(0, Math.Min(distanceFromOrigin - .1, .2 - .1)); var piecewiseDistanceFrom2To5Km = Math.Max(0, Math.Min(distanceFromOrigin - .2, .5 - .2)); var piecewiseDistanceFrom5To10Km = Math.Max(0, Math.Min(distanceFromOrigin - .5, 1 - .5)); var piecewiseDistanceFrom10To20Km = Math.Max(0, Math.Min(distanceFromOrigin - 1, 2 - 1)); var piecewiseDistanceFrom20KmToInfinity = Math.Max(0, distanceFromOrigin - 2); var piecewiseDistanceFrom10KmToInfinity = Math.Max(0, distanceFromOrigin - 1); // 1. finished var distanceFromOriginLog = Math.Log(1 + distanceFromOrigin); var distanceFromWorkLog = person.UsualWorkParcel.DistanceFromWorkLog(destinationParcel, 1); var distanceFromSchoolLog = person.UsualSchoolParcel.DistanceFromSchoolLog(destinationParcel, 1); var timePressure = Math.Log(1 - fastestTravelTime / maxAvailableMinutes); // 2. new from GV: Cph buffers for neighborhood effects // log transforms of buffers for Neighborhood effects var logOfOnePlusEducationK8Buffer2 = Math.Log(destinationParcel.StudentsK8Buffer2 + 1.0); var logOfOnePlusEducationUniStuBuffer2 = Math.Log(destinationParcel.StudentsUniversityBuffer2 + 1.0); var logOfOnePlusEmploymentEducationBuffer2 = Math.Log(destinationParcel.EmploymentEducationBuffer2 + 1.0); var logOfOnePlusEmploymentGovernmentBuffer2 = Math.Log(destinationParcel.EmploymentGovernmentBuffer2 + 1.0); var logOfOnePlusEmploymentIndustrialBuffer2 = Math.Log(destinationParcel.EmploymentIndustrialBuffer2 + 1.0); var logOfOnePlusEmploymentOfficeBuffer2 = Math.Log(destinationParcel.EmploymentOfficeBuffer2 + 1.0); var logOfOnePlusEmploymentRetailBuffer2 = Math.Log(destinationParcel.EmploymentRetailBuffer2 + 1.0); var logOfOnePlusEmploymentServiceBuffer2 = Math.Log(destinationParcel.EmploymentServiceBuffer2 + 1.0); var logOfOnePlusEmploymentAgrConstrBuffer2 = Math.Log(destinationParcel.EmploymentAgricultureConstructionBuffer2 + 1.0); var logOfOnePlusEmploymentJobsBuffer2 = Math.Log(destinationParcel.EmploymentTotalBuffer2 + 1.0); var logOfOnePlusHouseholdsBuffer2 = Math.Log(destinationParcel.HouseholdsBuffer2 + 1.0); // 2. finished var logOfOnePlusParkingOffStreetDailySpacesBuffer1 = Math.Log(1 + destinationParcel.ParkingOffStreetPaidDailySpacesBuffer1); // connectivity attributes var c34Ratio = destinationParcel.C34RatioBuffer1(); var carCompetitionFlag = FlagUtility.GetCarCompetitionFlag(carOwnership); // exludes no cars var noCarCompetitionFlag = FlagUtility.GetNoCarCompetitionFlag(carOwnership); var noCarsFlag = FlagUtility.GetNoCarsFlag(carOwnership); alternative.AddUtilityTerm(2, household.Id); alternative.AddUtilityTerm(3, personDay.Day); alternative.AddUtilityTerm(4, person.Sequence); alternative.AddUtilityTerm(5, tour.Sequence); alternative.AddUtilityTerm(8, adjustmentFactor); alternative.AddUtilityTerm(9, tourLogsum); // 3. new from GV: definition of Cph variables //alternative.AddUtilityTerm(260, secondaryFlag * workOrSchoolPatternFlag * piecewiseDistanceFrom0To1Km); alternative.AddUtilityTerm(260, secondaryFlag * workOrSchoolPatternFlag * piecewiseDistanceFrom0To2Km); //GV: added July 7th //alternative.AddUtilityTerm(261, secondaryFlag * workOrSchoolPatternFlag * piecewiseDistanceFrom1To2Km); alternative.AddUtilityTerm(262, secondaryFlag * workOrSchoolPatternFlag * piecewiseDistanceFrom2To5Km); alternative.AddUtilityTerm(263, secondaryFlag * workOrSchoolPatternFlag * piecewiseDistanceFrom5To10Km); alternative.AddUtilityTerm(264, secondaryFlag * workOrSchoolPatternFlag * piecewiseDistanceFrom10To20Km); alternative.AddUtilityTerm(265, secondaryFlag * workOrSchoolPatternFlag * piecewiseDistanceFrom20KmToInfinity); //alternative.AddUtilityTerm(266, secondaryFlag * otherPatternFlag * piecewiseDistanceFrom0To1Km); alternative.AddUtilityTerm(266, secondaryFlag * otherPatternFlag * piecewiseDistanceFrom0To2Km); //GV: added July 7th //alternative.AddUtilityTerm(267, secondaryFlag * otherPatternFlag * piecewiseDistanceFrom1To2Km); alternative.AddUtilityTerm(268, secondaryFlag * otherPatternFlag * piecewiseDistanceFrom2To5Km); alternative.AddUtilityTerm(269, secondaryFlag * otherPatternFlag * piecewiseDistanceFrom5To10Km); alternative.AddUtilityTerm(270, secondaryFlag * otherPatternFlag * piecewiseDistanceFrom10To20Km); alternative.AddUtilityTerm(271, secondaryFlag * otherPatternFlag * piecewiseDistanceFrom20KmToInfinity); //alternative.AddUtilityTerm(268, (!_tour.IsHomeBasedTour).ToFlag() * distanceFromOriginLog); //alternative.AddUtilityTerm(269, household.Has0To15KIncome.ToFlag() * distanceFromOriginLog); //alternative.AddUtilityTerm(270, household.HasMissingIncome.ToFlag() * distanceFromOriginLog); //alternative.AddUtilityTerm(271, person.IsRetiredAdult.ToFlag() * distanceFromOriginLog); //alternative.AddUtilityTerm(272, person.IsUniversityStudent.ToFlag() * distanceFromOriginLog); //alternative.AddUtilityTerm(273, person.IsChildAge5Through15.ToFlag() * distanceFromOriginLog); //alternative.AddUtilityTerm(274, person.IsChildUnder5.ToFlag() * distanceFromOriginLog); alternative.AddUtilityTerm(272, (!tour.IsHomeBasedTour).ToFlag() * distanceFromOriginLog); alternative.AddUtilityTerm(273, (household.Income >= 300000 && household.Income < 600000).ToFlag() * distanceFromOriginLog); alternative.AddUtilityTerm(274, (household.Income >= 600000 && household.Income < 900000).ToFlag() * distanceFromOriginLog); alternative.AddUtilityTerm(275, (household.Income >= 900000).ToFlag() * distanceFromOriginLog); //alternative.AddUtilityTerm(276, person.IsChildUnder5.ToFlag() * distanceFromOriginLog); // commented out by GV, July 7th //alternative.AddUtilityTerm(277, person.IsChildAge5Through15.ToFlag() * distanceFromOriginLog); // commented out by GV, July 7th //alternative.AddUtilityTerm(278, person.IsChildUnder16.ToFlag() * distanceFromOriginLog); // commented out by GV, July 7th alternative.AddUtilityTerm(279, person.IsUniversityStudent.ToFlag() * distanceFromOriginLog); //GV: 17. june 2015 male commented out //alternative.AddUtilityTerm(280, person.IsAdultMale.ToFlag() * distanceFromOriginLog); alternative.AddUtilityTerm(281, person.IsAdultFemale.ToFlag() * distanceFromOriginLog); alternative.AddUtilityTerm(282, person.IsRetiredAdult.ToFlag() * distanceFromOriginLog); //alternative.AddUtilityTerm(283, (tour.IsHomeBasedTour).ToFlag() * timePressure); //commented out by GV: 7th July 2013 alternative.AddUtilityTerm(284, (tour.IsHomeBasedTour).ToFlag() * distanceFromSchoolLog); //alternative.AddUtilityTerm(14, distanceFromWorkLog); // GV commented out this - on TO DO list //alternative.AddUtilityTerm(277, (carCompetitionFlag + noCarCompetitionFlag) * destinationParcel.ParkingHourlyEmploymentCommercialMixInParcel()); //alternative.AddUtilityTerm(278, noCarCompetitionFlag * destinationParcel.ParkingHourlyEmploymentCommercialMixInParcel()); //alternative.AddUtilityTerm(279, carCompetitionFlag * destinationParcel.ParkingHourlyEmploymentCommercialMixBuffer1()); //alternative.AddUtilityTerm(280, noCarCompetitionFlag * destinationParcel.ParkingHourlyEmploymentCommercialMixBuffer1()); //alternative.AddUtilityTerm(281, noCarsFlag * c34Ratio); //alternative.AddUtilityTerm(282, noCarCompetitionFlag * c34Ratio); //alternative.AddUtilityTerm(283, (carCompetitionFlag + noCarCompetitionFlag) * logOfOnePlusParkingOffStreetDailySpacesBuffer1); //alternative.AddUtilityTerm(285, jointTourFlag * piecewiseDistanceFrom0To1Km); //alternative.AddUtilityTerm(286, jointTourFlag * piecewiseDistanceFrom1To2Km); alternative.AddUtilityTerm(286, jointTourFlag * piecewiseDistanceFrom0To2Km); alternative.AddUtilityTerm(287, jointTourFlag * piecewiseDistanceFrom2To5Km); alternative.AddUtilityTerm(288, jointTourFlag * piecewiseDistanceFrom5To10Km); alternative.AddUtilityTerm(289, jointTourFlag * piecewiseDistanceFrom10To20Km); alternative.AddUtilityTerm(290, jointTourFlag * piecewiseDistanceFrom20KmToInfinity); // 3. finished //4. new from GV: purpose utilities // COMPAS puposes are: Work, Education, Escort, Shopping, Leisure, Personal business, business // You need NO "Work" and "Education", their destinations are known in the synthetic population if (tour.DestinationPurpose == Global.Settings.Purposes.Business) { //alternative.AddUtilityTerm(10, piecewiseDistanceFrom0To1Km); //alternative.AddUtilityTerm(11, piecewiseDistanceFrom1To2Km); //alternative.AddUtilityTerm(12, piecewiseDistanceFrom2To5Km); alternative.AddUtilityTerm(12, piecewiseDistanceFrom0To5Km); alternative.AddUtilityTerm(13, piecewiseDistanceFrom5To10Km); alternative.AddUtilityTerm(14, piecewiseDistanceFrom10To20Km); alternative.AddUtilityTerm(15, piecewiseDistanceFrom20KmToInfinity); //GV: june 2016 - not sign //alternative.AddUtilityTerm(16, aggregateLogsumWorkBased); // Neighborhood //GV: commented out just temp. //alternative.AddUtilityTerm(20, logOfOnePlusEducationK8Buffer2); //alternative.AddUtilityTerm(21, logOfOnePlusEducationUniStuBuffer2); //alternative.AddUtilityTerm(22, logOfOnePlusEmploymentEducationBuffer2); alternative.AddUtilityTerm(23, logOfOnePlusEmploymentGovernmentBuffer2); //alternative.AddUtilityTerm(24, logOfOnePlusEmploymentIndustrialBuffer2); //alternative.AddUtilityTerm(25, logOfOnePlusEmploymentOfficeBuffer2); //alternative.AddUtilityTerm(26, logOfOnePlusEmploymentRetailBuffer2); alternative.AddUtilityTerm(27, logOfOnePlusEmploymentServiceBuffer2); //alternative.AddUtilityTerm(28, logOfOnePlusEmploymentAgrConstrBuffer2); //alternative.AddUtilityTerm(29, logOfOnePlusEmploymentJobsBuffer2); // Size terms alternative.AddUtilityTerm(30, destinationParcel.EmploymentEducation); alternative.AddUtilityTerm(31, destinationParcel.EmploymentGovernment); alternative.AddUtilityTerm(32, destinationParcel.EmploymentIndustrial); alternative.AddUtilityTerm(33, destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(34, destinationParcel.EmploymentRetail); // GV: 35 is fixed to zero alternative.AddUtilityTerm(35, destinationParcel.EmploymentService); alternative.AddUtilityTerm(36, destinationParcel.EmploymentAgricultureConstruction); alternative.AddUtilityTerm(37, destinationParcel.EmploymentTotal); alternative.AddUtilityTerm(38, destinationParcel.Households); } else if (tour.DestinationPurpose == Global.Settings.Purposes.Escort) { //alternative.AddUtilityTerm(50, piecewiseDistanceFrom0To1Km); alternative.AddUtilityTerm(51, piecewiseDistanceFrom0To2Km); //alternative.AddUtilityTerm(52, piecewiseDistanceFrom2To5Km); alternative.AddUtilityTerm(52, piecewiseDistanceFrom2To5Km); alternative.AddUtilityTerm(53, piecewiseDistanceFrom5To10Km); //alternative.AddUtilityTerm(54, piecewiseDistanceFrom10To20Km); alternative.AddUtilityTerm(55, piecewiseDistanceFrom10KmToInfinity); //alternative.AddUtilityTerm(55, piecewiseDistanceFrom20KmToInfinity); //GV: june 2016 - not sign //alternative.AddUtilityTerm(56, aggregateLogsumHomeBased); // Neighborhood //GV: commented out just temp. alternative.AddUtilityTerm(60, householdHasNoChildren.ToFlag() * logOfOnePlusEmploymentJobsBuffer2); //alternative.AddUtilityTerm(61, householdHasNoChildren.ToFlag() * logOfOnePlusHouseholdsBuffer2); //alternative.AddUtilityTerm(62, householdHasChildren.ToFlag() * logOfOnePlusHouseholdsBuffer2); //alternative.AddUtilityTerm(64, logOfOnePlusEmploymentJobsBuffer2); // Size terms // GV: no observations alternative.AddUtilityTerm(70, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentEducation); alternative.AddUtilityTerm(71, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentGovernment); alternative.AddUtilityTerm(72, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentIndustrial); alternative.AddUtilityTerm(73, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(74, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentRetail); // GV: 75 is fixed to zero alternative.AddUtilityTerm(75, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentService); alternative.AddUtilityTerm(76, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentAgricultureConstruction); alternative.AddUtilityTerm(77, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentTotal); alternative.AddUtilityTerm(78, (!householdHasChildren).ToFlag() * destinationParcel.Households); alternative.AddUtilityTerm(80, (householdHasChildren).ToFlag() * destinationParcel.EmploymentEducation); alternative.AddUtilityTerm(81, (householdHasChildren).ToFlag() * destinationParcel.EmploymentGovernment); alternative.AddUtilityTerm(82, (householdHasChildren).ToFlag() * destinationParcel.EmploymentIndustrial); alternative.AddUtilityTerm(83, (householdHasChildren).ToFlag() * destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(84, (householdHasChildren).ToFlag() * destinationParcel.EmploymentRetail); // GV 85 is fixed to zero at the moment alternative.AddUtilityTerm(85, (householdHasChildren).ToFlag() * destinationParcel.EmploymentService); alternative.AddUtilityTerm(86, (householdHasChildren).ToFlag() * destinationParcel.EmploymentAgricultureConstruction); alternative.AddUtilityTerm(87, (householdHasChildren).ToFlag() * destinationParcel.EmploymentTotal); alternative.AddUtilityTerm(88, (householdHasChildren).ToFlag() * destinationParcel.Households); } else if (tour.DestinationPurpose == Global.Settings.Purposes.PersonalBusiness) { alternative.AddUtilityTerm(90, piecewiseDistanceFrom0To2Km); //alternative.AddUtilityTerm(91, piecewiseDistanceFrom1To2Km); alternative.AddUtilityTerm(92, piecewiseDistanceFrom2To5Km); alternative.AddUtilityTerm(93, piecewiseDistanceFrom5To10Km); alternative.AddUtilityTerm(95, piecewiseDistanceFrom10KmToInfinity); //GV: june 2016 - not sign //alternative.AddUtilityTerm(96, aggregateLogsumHomeBased); // Neighborhood //GV: commented out just temp. //alternative.AddUtilityTerm(100, logOfOnePlusEmploymentEducationBuffer2); //alternative.AddUtilityTerm(101, logOfOnePlusEmploymentGovernmentBuffer2); //alternative.AddUtilityTerm(102, logOfOnePlusEmploymentIndustrialBuffer2); alternative.AddUtilityTerm(103, logOfOnePlusEmploymentOfficeBuffer2); alternative.AddUtilityTerm(104, logOfOnePlusEmploymentRetailBuffer2); alternative.AddUtilityTerm(105, logOfOnePlusEmploymentServiceBuffer2); //alternative.AddUtilityTerm(106, logOfOnePlusEmploymentAgrConstrBuffer2); //alternative.AddUtilityTerm(107, logOfOnePlusEmploymentJobsBuffer2); // Size terms alternative.AddUtilityTerm(110, destinationParcel.EmploymentEducation); alternative.AddUtilityTerm(111, destinationParcel.EmploymentGovernment); alternative.AddUtilityTerm(112, destinationParcel.EmploymentIndustrial); alternative.AddUtilityTerm(113, destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(114, destinationParcel.EmploymentRetail); // GV 115 is fixed to zero alternative.AddUtilityTerm(115, destinationParcel.EmploymentService); alternative.AddUtilityTerm(116, destinationParcel.EmploymentAgricultureConstruction); alternative.AddUtilityTerm(117, destinationParcel.EmploymentTotal); alternative.AddUtilityTerm(118, destinationParcel.Households); } else if (tour.DestinationPurpose == Global.Settings.Purposes.Shopping) { //alternative.AddUtilityTerm(120, piecewiseDistanceFrom0To1Km); alternative.AddUtilityTerm(121, piecewiseDistanceFrom0To2Km); alternative.AddUtilityTerm(122, piecewiseDistanceFrom2To5Km); alternative.AddUtilityTerm(123, piecewiseDistanceFrom5To10Km); alternative.AddUtilityTerm(124, piecewiseDistanceFrom10To20Km); alternative.AddUtilityTerm(125, piecewiseDistanceFrom20KmToInfinity); //GV: june 2016 - not sign //alternative.AddUtilityTerm(126, aggregateLogsumHomeBased); // Neighborhood //GV: commented out just temp. //alternative.AddUtilityTerm(130, logOfOnePlusEmploymentEducationBuffer2); alternative.AddUtilityTerm(131, logOfOnePlusEmploymentRetailBuffer2); //alternative.AddUtilityTerm(132, logOfOnePlusEmploymentJobsBuffer2); // Size terms alternative.AddUtilityTerm(140, destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(141, destinationParcel.EmploymentRetail); // GV 142 is fixed to zero alternative.AddUtilityTerm(142, destinationParcel.EmploymentService); alternative.AddUtilityTerm(143, destinationParcel.EmploymentTotal); } else if (tour.DestinationPurpose == Global.Settings.Purposes.Social) { //alternative.AddUtilityTerm(170, piecewiseDistanceFrom0To1Km); //alternative.AddUtilityTerm(171, piecewiseDistanceFrom1To2Km); alternative.AddUtilityTerm(170, piecewiseDistanceFrom0To2Km); alternative.AddUtilityTerm(172, piecewiseDistanceFrom2To5Km); alternative.AddUtilityTerm(173, piecewiseDistanceFrom5To10Km); alternative.AddUtilityTerm(174, piecewiseDistanceFrom10To20Km); alternative.AddUtilityTerm(175, piecewiseDistanceFrom20KmToInfinity); //GV: june 2016 - not sign //alternative.AddUtilityTerm(176, aggregateLogsumHomeBased); // Neighborhood //GV: commented out just temp. //alternative.AddUtilityTerm(180, logOfOnePlusEmploymentOfficeBuffer2); alternative.AddUtilityTerm(181, logOfOnePlusEmploymentRetailBuffer2); alternative.AddUtilityTerm(182, logOfOnePlusEmploymentServiceBuffer2); //alternative.AddUtilityTerm(183, logOfOnePlusEmploymentJobsBuffer2); // Size terms alternative.AddUtilityTerm(190, destinationParcel.EmploymentEducation); alternative.AddUtilityTerm(191, destinationParcel.EmploymentGovernment); alternative.AddUtilityTerm(192, destinationParcel.EmploymentIndustrial); alternative.AddUtilityTerm(193, destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(194, destinationParcel.EmploymentRetail); // GV 195 is fixed to zero alternative.AddUtilityTerm(195, destinationParcel.EmploymentService); alternative.AddUtilityTerm(196, destinationParcel.EmploymentAgricultureConstruction); alternative.AddUtilityTerm(197, destinationParcel.EmploymentTotal); alternative.AddUtilityTerm(198, destinationParcel.Households); } } }
public void SetUtilities(ISampleItem sampleItem, int sampleFrequency) { if (sampleItem == null) { throw new ArgumentNullException("sampleItem"); } var alternative = sampleItem.Alternative; var household = _tour.Household; var person = _tour.Person; var personDay = _tour.PersonDay; // var householdHasChildren = household.HasChildren; var destinationParcel = ChoiceModelFactory.Parcels[sampleItem.ParcelId]; var excludedParcel = person.UsualWorkParcel == null || person.UsualWorkParcelId == household.ResidenceParcelId || _tour.DestinationPurpose != Global.Settings.Purposes.Work || _tour.GetTourCategory() == Global.Settings.TourCategories.WorkBased ? null : person.UsualWorkParcel; var usualWorkParcel = (excludedParcel != null && excludedParcel.Id == destinationParcel.Id); // only 1 for oddball alternative on tours with oddball alternative var usualWorkParcelFlag = usualWorkParcel.ToFlag(); // Comment out these nesting calls when estimating the conditional flat model // model is NL with oddball alternative if (usualWorkParcelFlag == 0) { // this alternative is in the non-oddball nest alternative.AddNestedAlternative(_sampleSize + 2, 0, 60); // associates alternative with non-oddball nest } else { // this is the oddball alternative alternative.AddNestedAlternative(_sampleSize + 3, 1, 60); // associates alternative with oddball nest } if (!alternative.Available) { return; } // use this block of code to eliminate the oddball alternative for estimation of the conditional model //if (usualWorkParcelFlag == 1) { // alternative.Available = false; // // return; //} var fastestTravelTime = ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Hov3, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, _fastestAvailableTimeOfDay, _tour.OriginParcel, destinationParcel).Variable + ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Hov3, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, _fastestAvailableTimeOfDay, destinationParcel, _tour.OriginParcel).Variable; if (fastestTravelTime >= _maxAvailableMinutes) { alternative.Available = false; return; } alternative.Choice = destinationParcel; double tourLogsum; if (_tour.IsHomeBasedTour) { var nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeModel>().RunNested(_tour, destinationParcel, household.VehiclesAvailable, person.GetTransitFareDiscountFraction()); tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } else { var nestedAlternative = Global.ChoiceModelSession.Get <WorkBasedSubtourModeModel>().RunNested(_tour, destinationParcel); tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } //var purpose = _tour.TourPurposeSegment; //var nonWorkPurpose = _tour.DestinationPurpose != Global.Settings.Purposes.Work; var carOwnership = person.GetCarOwnershipSegment(); //var votSegment = _tour.VotALSegment; //var transitAccess = destinationParcel.TransitAccessSegment(); //var aggregateLogsum = Global.AggregateLogsums[destinationParcel.ZoneId][purpose][carOwnership][votSegment][transitAccess]; //var aggregateLogsumHomeBased = Global.AggregateLogsums[destinationParcel.ZoneId][Global.Settings.Purposes.HomeBasedComposite][carOwnership][votSegment][transitAccess]; //var aggregateLogsumWorkBased = Global.AggregateLogsums[destinationParcel.ZoneId][Global.Settings.Purposes.Work_BASED][carOwnership][votSegment][transitAccess]; var distanceFromOrigin = _tour.OriginParcel.DistanceFromOrigin(destinationParcel, _tour.DestinationArrivalTime); // var distanceFromOrigin0 = Math.Max(0, Math.Min(distanceFromOrigin - .5, 1 - .5)); // var distanceFromOrigin3 = Math.Max(0, distanceFromOrigin - 1); // var distanceFromOrigin4 = Math.Min(distanceFromOrigin, .10); // var distanceFromOrigin5 = Math.Max(0, Math.Min(distanceFromOrigin - .1, .5 - .1)); // var distanceFromOrigin8 = Math.Max(0, Math.Min(distanceFromOrigin - .1, .35 - .1)); // var distanceFromOrigin9 = Math.Max(0, Math.Min(distanceFromOrigin - .35, 1 - .35)); var distanceFromOriginLog = Math.Log(1 + distanceFromOrigin); var distanceFromWorkLog = person.UsualWorkParcel.DistanceFromWorkLog(destinationParcel, 1); var distanceFromSchoolLog = person.UsualSchoolParcel.DistanceFromSchoolLog(destinationParcel, 1); // var millionsSquareFeet = destinationZoneTotals.MillionsSquareFeet(); var timePressure = Math.Log(1 - fastestTravelTime / _maxAvailableMinutes); // log transforms of buffers for Neighborhood effects var empEduBuffer = Math.Log(destinationParcel.EmploymentEducationBuffer1 + 1.0); // var EMPFOO_B = Math.Log(destinationParcel.EmploymentFoodBuffer1 + 1.0); // var EMPGOV_B = Math.Log(destinationParcel.EmploymentGovernmentBuffer1 + 1.0); var empOfcBuffer = Math.Log(destinationParcel.EmploymentOfficeBuffer1 + 1.0); // var EMPRET_B = Math.Log(destinationParcel.EmploymentRetailBuffer1 + 1.0); // var EMPSVC_B = Math.Log(destinationParcel.EmploymentServiceBuffer1 + 1.0); // var EMPMED_B = Math.Log(destinationParcel.EmploymentMedicalBuffer1 + 1.0); var empIndBuffer = Math.Log(destinationParcel.EmploymentIndustrialBuffer1 + destinationParcel.EmploymentAgricultureConstructionBuffer1 + 1.0); // var EMPTOT_B = Math.Log(destinationParcel.EmploymentTotalBuffer1 + 1.0); var housesBuffer = Math.Log(destinationParcel.HouseholdsBuffer1 + 1.0); // var STUDK12B = Math.Log(destinationParcel.StudentsK8Buffer1 + destinationParcel.StudentsHighSchoolBuffer1 + 1.0); // var STUDUNIB = Math.Log(destinationParcel.StudentsUniversityBuffer1 + 1.0); // var EMPHOU_B = Math.Log(destinationParcel.EmploymentTotalBuffer1 + destinationParcel.HouseholdsBuffer1 + 1.0); // parking attributes // var parcelParkingDensity = destinationParcel.ParcelParkingPerTotalEmployment(); // var zoneParkingDensity = destinationParcel.ZoneParkingPerTotalEmploymentAndK12UniversityStudents(destinationZoneTotals, millionsSquareFeet); // var ParkingPaidDailyLogBuffer1 = Math.Log(1 + destinationParcel.ParkingOffStreetPaidDailySpacesBuffer1); // connectivity attributes // var c34Ratio = destinationParcel.C34RatioBuffer1(); // var carDeficitFlag = FlagUtility.GetCarDeficitFlag(carOwnership); // includes no cars // var carCompetitionFlag = FlagUtility.GetCarCompetitionFlag(carOwnership); // exludes no cars var noCarCompetitionFlag = FlagUtility.GetNoCarCompetitionFlag(carOwnership); // var noCarsFlag = FlagUtility.GetNoCarsFlag(carOwnership); // Usual location attributes alternative.AddUtilityTerm(1, usualWorkParcelFlag); alternative.AddUtilityTerm(2, person.IsPartTimeWorker.ToFlag() * usualWorkParcelFlag); alternative.AddUtilityTerm(3, person.IsStudentAge.ToFlag() * usualWorkParcelFlag); alternative.AddUtilityTerm(4, _primaryFlag * personDay.TwoOrMoreWorkToursExist().ToFlag() * usualWorkParcelFlag); alternative.AddUtilityTerm(5, personDay.WorkStopsExist().ToFlag() * usualWorkParcelFlag); alternative.AddUtilityTerm(6, _secondaryFlag * usualWorkParcelFlag); // non-usual location attributes alternative.AddUtilityTerm(11, (!usualWorkParcel).ToFlag() * sampleItem.AdjustmentFactor); alternative.AddUtilityTerm(12, _tour.IsHomeBasedTour.ToFlag() * (!usualWorkParcel).ToFlag() * timePressure); alternative.AddUtilityTerm(13, (!usualWorkParcel).ToFlag() * person.IsFulltimeWorker.ToFlag() * tourLogsum); alternative.AddUtilityTerm(14, (!usualWorkParcel).ToFlag() * person.IsPartTimeWorker.ToFlag() * tourLogsum); alternative.AddUtilityTerm(15, (!usualWorkParcel).ToFlag() * person.IsNotFullOrPartTimeWorker.ToFlag() * tourLogsum); alternative.AddUtilityTerm(16, (!usualWorkParcel).ToFlag() * person.IsRetiredAdult.ToFlag() * distanceFromOriginLog); alternative.AddUtilityTerm(17, (!usualWorkParcel).ToFlag() * distanceFromWorkLog); alternative.AddUtilityTerm(18, (!usualWorkParcel).ToFlag() * person.IsStudentAge.ToFlag() * distanceFromSchoolLog); alternative.AddUtilityTerm(19, (!usualWorkParcel).ToFlag() * noCarCompetitionFlag * destinationParcel.ParkingHourlyEmploymentCommercialMixBuffer1()); // non-usual location Neighborhood attributes alternative.AddUtilityTerm(31, (!usualWorkParcel).ToFlag() * empEduBuffer); alternative.AddUtilityTerm(32, (!usualWorkParcel).ToFlag() * empOfcBuffer); alternative.AddUtilityTerm(33, (!usualWorkParcel).ToFlag() * housesBuffer); alternative.AddUtilityTerm(34, (!usualWorkParcel).ToFlag() * empIndBuffer); // non-usual location Size terms (consider conditioning these by fulltime, parttime, notFTPT, an income (see original sacog spec) alternative.AddUtilityTerm(40, (!usualWorkParcel).ToFlag() * destinationParcel.EmploymentEducation); alternative.AddUtilityTerm(41, (!usualWorkParcel).ToFlag() * destinationParcel.EmploymentFood); alternative.AddUtilityTerm(42, (!usualWorkParcel).ToFlag() * destinationParcel.EmploymentGovernment); alternative.AddUtilityTerm(43, (!usualWorkParcel).ToFlag() * destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(44, (!usualWorkParcel).ToFlag() * destinationParcel.EmploymentRetail); alternative.AddUtilityTerm(45, (!usualWorkParcel).ToFlag() * destinationParcel.EmploymentService); alternative.AddUtilityTerm(46, (!usualWorkParcel).ToFlag() * destinationParcel.EmploymentMedical); alternative.AddUtilityTerm(47, (!usualWorkParcel).ToFlag() * destinationParcel.EmploymentIndustrial + destinationParcel.EmploymentAgricultureConstruction); alternative.AddUtilityTerm(48, (!usualWorkParcel).ToFlag() * destinationParcel.Households); alternative.AddUtilityTerm(49, (!usualWorkParcel).ToFlag() * destinationParcel.StudentsUniversity); // // usual location size term // alternative.AddUtilityTerm(50, usualWorkParcelFlag * 1); // // Comment out these nesting calls when estimating the conditional flat model // // model is NL with oddball alternative // if (usualWorkParcelFlag == 0) { // // this alternative is in the non-oddball nest // alternative.AddNestedAlternative(_sampleSize + 2, 0, 60); // associates alternative with non-oddball nest // } // else { // // this is the oddball alternative // alternative.AddNestedAlternative(_sampleSize + 3, 1, 60); // associates alternative with oddball nest // } }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITourWrapper tour, IEnumerable <IPathTypeModel> pathTypeModels, IParcelWrapper destinationParcel, int choice = Constants.DEFAULT_VALUE) { var household = tour.Household; var householdTotals = household.HouseholdTotals; var person = tour.Person; var personDay = tour.PersonDay; // household inputs var income0To25KFlag = household.Has0To25KIncome.ToFlag(); var childrenUnder5 = householdTotals.ChildrenUnder5; var childrenAge5Through15 = householdTotals.ChildrenAge5Through15; var nonworkingAdults = householdTotals.NonworkingAdults; var retiredAdults = householdTotals.RetiredAdults; var onePersonHouseholdFlag = household.IsOnePersonHousehold.ToFlag(); var twoPersonHouseholdFlag = household.IsTwoPersonHousehold.ToFlag(); var noCarsInHouseholdFlag = household.GetFlagForNoCarsInHousehold(household.VehiclesAvailable); var carsLessThanDriversFlag = household.GetFlagForCarsLessThanDrivers(household.VehiclesAvailable); var carsLessThanWorkersFlag = household.GetFlagForCarsLessThanWorkers(household.VehiclesAvailable); // person inputs var maleFlag = person.IsMale.ToFlag(); var ageBetween51And98Flag = person.AgeIsBetween51And98.ToFlag(); var univStudentFlag = person.IsUniversityStudent.ToFlag(); // tour inputs var shoppingTourFlag = (tour.DestinationPurpose == Global.Settings.Purposes.Shopping).ToFlag(); var mealTourFlag = (tour.DestinationPurpose == Global.Settings.Purposes.Meal).ToFlag(); var socialOrRecreationTourFlag = (tour.DestinationPurpose == Global.Settings.Purposes.Social).ToFlag(); // remaining inputs var originParcel = tour.OriginParcel; var parkingDuration = ChoiceModelUtility.GetParkingDuration(person.IsFulltimeWorker); var destinationParkingCost = destinationParcel.ParkingCostBuffer1(parkingDuration); double escortPercentage; double nonEscortPercentage; ChoiceModelUtility.SetEscortPercentages(personDay, out escortPercentage, out nonEscortPercentage, true); // paidRideShare is another special case - set in config file - use HOV2 impedance if (Global.Configuration.PaidRideShareModeIsAvailable) { var pathTypeExtra = pathTypeModels.First(x => x.Mode == Global.Settings.Modes.PaidRideShare); var modeExtra = Global.Settings.Modes.PaidRideShare; var availableExtra = pathTypeExtra.Available; var generalizedTimeLogsumExtra = pathTypeExtra.GeneralizedTimeLogsum; var distanceExtra = pathTypeExtra.PathDistance; var alternative = choiceProbabilityCalculator.GetAlternative(modeExtra - 2, availableExtra, choice == modeExtra); alternative.Choice = modeExtra; alternative.AddNestedAlternative(_nestedAlternativeIds[modeExtra], _nestedAlternativeIndexes[modeExtra], THETA_PARAMETER); if (availableExtra) { var extraCostPerMile = Global.Configuration.AV_PaidRideShareModeUsesAVs ? Global.Configuration.AV_PaidRideShare_ExtraCostPerDistanceUnit : Global.Configuration.PaidRideShare_ExtraCostPerDistanceUnit; var fixedCostPerRide = Global.Configuration.AV_PaidRideShareModeUsesAVs ? Global.Configuration.AV_PaidRideShare_FixedCostPerRide : Global.Configuration.PaidRideShare_FixedCostPerRide; var autoTimeCoefficient = Global.Configuration.AV_PaidRideShareModeUsesAVs ? tour.TimeCoefficient * (1.0 - Global.Configuration.AV_InVehicleTimeCoefficientDiscountFactor) : tour.TimeCoefficient; alternative.AddUtilityTerm(2, generalizedTimeLogsumExtra * autoTimeCoefficient); alternative.AddUtilityTerm(2, distanceExtra * extraCostPerMile * tour.CostCoefficient); alternative.AddUtilityTerm(2, fixedCostPerRide * tour.CostCoefficient); var modeConstant = Global.Configuration.AV_PaidRideShareModeUsesAVs ? Global.Configuration.AV_PaidRideShare_ModeConstant + Global.Configuration.AV_PaidRideShare_DensityCoefficient * Math.Min(originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2, 6000) + Global.Configuration.AV_PaidRideShare_AVOwnerCoefficient * (household.OwnsAutomatedVehicles > 0).ToFlag() : Global.Configuration.PaidRideShare_ModeConstant + Global.Configuration.PaidRideShare_DensityCoefficient * Math.Min(originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2, 6000); alternative.AddUtilityTerm(90, modeConstant); alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_Age26to35Coefficient * tour.Person.AgeIsBetween26And35.ToFlag()); alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_Age18to25Coefficient * tour.Person.AgeIsBetween18And25.ToFlag()); alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_AgeOver65Coefficient * (tour.Person.Age >= 65).ToFlag()); } } //foreach (var pathTypeModel in pathTypeModels) { foreach (IPathTypeModel pathTypeModel in pathTypeModels) { IPathTypeModel ipathTypeModel = pathTypeModel; var mode = pathTypeModel.Mode; var available = pathTypeModel.Mode != Global.Settings.Modes.ParkAndRide && pathTypeModel.Available; var generalizedTimeLogsum = pathTypeModel.GeneralizedTimeLogsum; var alternative = choiceProbabilityCalculator.GetAlternative(mode, available, choice == mode); alternative.Choice = mode; alternative.AddNestedAlternative(_nestedAlternativeIds[pathTypeModel.Mode], _nestedAlternativeIndexes[pathTypeModel.Mode], THETA_PARAMETER); if (!available) { continue; } var modeTimeCoefficient = (Global.Configuration.AV_IncludeAutoTypeChoice && household.OwnsAutomatedVehicles > 0 && mode >= Global.Settings.Modes.Sov && mode <= Global.Settings.Modes.Hov3) ? tour.TimeCoefficient * (1.0 - Global.Configuration.AV_InVehicleTimeCoefficientDiscountFactor) : tour.TimeCoefficient; alternative.AddUtilityTerm(2, generalizedTimeLogsum * modeTimeCoefficient); if (mode == Global.Settings.Modes.Transit) { alternative.AddUtilityTerm(20, 1); alternative.AddUtilityTerm(21, noCarsInHouseholdFlag); alternative.AddUtilityTerm(120, shoppingTourFlag); // alternative.AddUtility(121, mealTourFlag); // alternative.AddUtility(129, destinationParcel.MixedUse2Index1()); alternative.AddUtilityTerm(128, destinationParcel.TotalEmploymentDensity1()); // alternative.AddUtility(127, destinationParcel.NetIntersectionDensity1()); // alternative.AddUtility(126, originParcel.NetIntersectionDensity1()); // alternative.AddUtility(125, originParcel.HouseholdDensity1()); alternative.AddUtilityTerm(124, originParcel.MixedUse2Index1()); // alternative.AddUtility(123, Math.Log(destinationParcel.StopsTransitBuffer1+1)); // alternative.AddUtility(122, Math.Log(originParcel.StopsTransitBuffer1+1)); alternative.AddUtilityTerm(180, univStudentFlag); } else if (mode == Global.Settings.Modes.Hov3) { alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / ChoiceModelUtility.CPFACT3)); alternative.AddUtilityTerm(30, 1); alternative.AddUtilityTerm(31, childrenUnder5); alternative.AddUtilityTerm(32, childrenAge5Through15); alternative.AddUtilityTerm(34, nonworkingAdults + retiredAdults); alternative.AddUtilityTerm(35, ((double)pathTypeModel.PathDistance).AlmostEquals(0) ? 0 : Math.Log(pathTypeModel.PathDistance)); alternative.AddUtilityTerm(38, onePersonHouseholdFlag); alternative.AddUtilityTerm(39, twoPersonHouseholdFlag); alternative.AddUtilityTerm(41, noCarsInHouseholdFlag); alternative.AddUtilityTerm(43, carsLessThanWorkersFlag); alternative.AddUtilityTerm(133, escortPercentage); alternative.AddUtilityTerm(134, nonEscortPercentage); alternative.AddUtilityTerm(136, shoppingTourFlag); alternative.AddUtilityTerm(137, mealTourFlag); alternative.AddUtilityTerm(138, socialOrRecreationTourFlag); } else if (mode == Global.Settings.Modes.Hov2) { alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / ChoiceModelUtility.CPFACT2)); alternative.AddUtilityTerm(31, childrenUnder5); alternative.AddUtilityTerm(32, childrenAge5Through15); alternative.AddUtilityTerm(34, nonworkingAdults + retiredAdults); alternative.AddUtilityTerm(35, ((double)pathTypeModel.PathDistance).AlmostEquals(0) ? 0 : Math.Log(pathTypeModel.PathDistance)); alternative.AddUtilityTerm(40, 1); alternative.AddUtilityTerm(41, noCarsInHouseholdFlag); alternative.AddUtilityTerm(43, carsLessThanWorkersFlag); alternative.AddUtilityTerm(48, onePersonHouseholdFlag); alternative.AddUtilityTerm(133, escortPercentage); alternative.AddUtilityTerm(134, nonEscortPercentage); alternative.AddUtilityTerm(136, shoppingTourFlag); alternative.AddUtilityTerm(137, mealTourFlag); alternative.AddUtilityTerm(138, socialOrRecreationTourFlag); } else if (mode == Global.Settings.Modes.Sov) { alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient)); alternative.AddUtilityTerm(50, 1); alternative.AddUtilityTerm(52, carsLessThanDriversFlag); alternative.AddUtilityTerm(54, income0To25KFlag); alternative.AddUtilityTerm(131, escortPercentage); alternative.AddUtilityTerm(132, nonEscortPercentage); } else if (mode == Global.Settings.Modes.Bike) { double class1Dist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? ImpedanceRoster.GetValue("class1distance", mode, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0; double class2Dist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? ImpedanceRoster.GetValue("class2distance", mode, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0; double worstDist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? ImpedanceRoster.GetValue("worstdistance", mode, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0; alternative.AddUtilityTerm(60, 1); alternative.AddUtilityTerm(61, maleFlag); alternative.AddUtilityTerm(63, ageBetween51And98Flag); alternative.AddUtilityTerm(160, socialOrRecreationTourFlag); alternative.AddUtilityTerm(169, destinationParcel.MixedUse4Index1()); alternative.AddUtilityTerm(168, destinationParcel.TotalEmploymentDensity1()); // alternative.AddUtility(167, destinationParcel.NetIntersectionDensity1()); // alternative.AddUtility(166, originParcel.NetIntersectionDensity1()); alternative.AddUtilityTerm(165, originParcel.HouseholdDensity1()); alternative.AddUtilityTerm(164, originParcel.MixedUse4Index1()); alternative.AddUtilityTerm(161, (class1Dist > 0).ToFlag()); alternative.AddUtilityTerm(162, (class2Dist > 0).ToFlag()); alternative.AddUtilityTerm(163, (worstDist > 0).ToFlag()); } else if (mode == Global.Settings.Modes.Walk) { alternative.AddUtilityTerm(70, 1); alternative.AddUtilityTerm(73, ageBetween51And98Flag); alternative.AddUtilityTerm(171, mealTourFlag); alternative.AddUtilityTerm(172, socialOrRecreationTourFlag); // alternative.AddUtility(179, destinationParcel.MixedUse4Index1()); alternative.AddUtilityTerm(178, destinationParcel.HouseholdDensity1()); // alternative.AddUtility(177, destinationParcel.NetIntersectionDensity1()); // alternative.AddUtility(176, originParcel.NetIntersectionDensity1()); alternative.AddUtilityTerm(175, originParcel.HouseholdDensity1()); // alternative.AddUtility(174, originParcel.MixedUse4Index1()); } RegionSpecificCustomizations(alternative, tour, pathTypeModel.PathType, mode, destinationParcel); } }
private double[][][][] ComputeZone(IRandomUtility randomUtility, int id) { var purposes = new double[Global.Settings.Purposes.TotalPurposes][][][]; for (var purpose = Global.Settings.Purposes.HomeBasedComposite; purpose <= Global.Settings.Purposes.Social; purpose++) { var carOwnerships = new double[Global.Settings.CarOwnerships.TotalCarOwnerships][][]; purposes[purpose] = carOwnerships; for (var carOwnership = Global.Settings.CarOwnerships.Child; carOwnership < Global.Settings.CarOwnerships.TotalCarOwnerships; carOwnership++) { var votALSegments = new double[Global.Settings.VotALSegments.TotalVotALSegments][]; carOwnerships[carOwnership] = votALSegments; for (var votALSegment = Global.Settings.VotALSegments.Low; votALSegment < Global.Settings.VotALSegments.TotalVotALSegments; votALSegment++) { var transitAccesses = new double[Global.Settings.TransitAccesses.TotalTransitAccesses]; votALSegments[votALSegment] = transitAccesses; for (var transitAccess = Global.Settings.TransitAccesses.Gt0AndLteQtrMi; transitAccess < Global.Settings.TransitAccesses.TotalTransitAccesses; transitAccess++) { transitAccesses[transitAccess] = Constants.EPSILON; } } } } IZone origin; if (!_eligibleZones.TryGetValue(id, out origin)) { return(purposes); } foreach (var destination in _eligibleZones.Values) { var setImpedance = true; var subzones = _zoneSubzones[destination.Id]; //const double parkingCost = 0; // mode impedance var sovInVehicleTimeFromOrigin = ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, _middayStartMinute, id, destination.Id).Variable; var scaledSovDistanceFromOrigin = 0D; var transitGenTime = 0D; var walkGenTime = 0D; var sovGenTime = 0D; var hov2GenTime = 0D; for (var purpose = Global.Settings.Purposes.HomeBasedComposite; purpose <= Global.Settings.Purposes.Social; purpose++) { var carOwnerships = purposes[purpose]; var distanceParameters = _distanceParameters[purpose]; // set purpose inputs var escortFlag = (purpose == Global.Settings.Purposes.Escort).ToFlag(); var personalBusinessFlag = (purpose == Global.Settings.Purposes.PersonalBusiness).ToFlag(); var shoppingFlag = (purpose == Global.Settings.Purposes.Shopping).ToFlag(); var mealFlag = (purpose == Global.Settings.Purposes.Meal).ToFlag(); var socialFlag = (purpose == Global.Settings.Purposes.Social).ToFlag(); var p01 = _p01[purpose]; var p02 = _p02[purpose]; var p03 = _p03[purpose]; var p11 = _p11[purpose]; var p14 = _p14[purpose]; var p21 = _p21[purpose]; var p22 = _p22[purpose]; var p23 = _p23[purpose]; var p24 = _p24[purpose]; var p31 = _p31[purpose]; var p32 = _p32[purpose]; var p33 = _p33[purpose]; var p34 = _p34[purpose]; var p37 = _p37[purpose]; for (var carOwnership = Global.Settings.CarOwnerships.Child; carOwnership < Global.Settings.CarOwnerships.TotalCarOwnerships; carOwnership++) { var votALSegments = carOwnerships[carOwnership]; // set car ownership inputs var childFlag = FlagUtility.GetChildFlag(carOwnership); var noCarsFlag = FlagUtility.GetNoCarsFlag(carOwnership); var carCompetitionFlag = FlagUtility.GetCarCompetitionFlag(carOwnership); var noCarCompetitionFlag = FlagUtility.GetNoCarCompetitionFlag(carOwnership); var carDeficitFlag = FlagUtility.GetCarDeficitFlag(carOwnership); var distanceParameter = distanceParameters[carOwnership][1] / 100D; // converts hundreths of minutes to minutes for (var votALSegment = Global.Settings.VotALSegments.Low; votALSegment < Global.Settings.VotALSegments.TotalVotALSegments; votALSegment++) { var transitAccesses = votALSegments[votALSegment]; // set vot specific variables double timeCoefficient = Global.Settings.VotALSegments.TimeCoefficient; var costCoefficient = (votALSegment == Global.Settings.VotALSegments.Low) ? Global.Settings.VotALSegments.CostCoefficientLow : (votALSegment == Global.Settings.VotALSegments.Medium) ? Global.Settings.VotALSegments.CostCoefficientMedium : Global.Settings.VotALSegments.CostCoefficientHigh; for (var transitAccess = Global.Settings.TransitAccesses.Gt0AndLteQtrMi; transitAccess < Global.Settings.TransitAccesses.TotalTransitAccesses; transitAccess++) { var purposeUtility = 0D; // set transit access flags var hasNearTransitAccessFlag = (transitAccess == Global.Settings.TransitAccesses.Gt0AndLteQtrMi).ToFlag(); var hasNoTransitAccessFlag = (transitAccess == Global.Settings.TransitAccesses.None).ToFlag(); foreach (var subzone in subzones) { var size = subzone.GetSize(purpose); if (size <= -50 || sovInVehicleTimeFromOrigin <= 0 || (2 * sovInVehicleTimeFromOrigin) > distanceParameter) { continue; } // set subzone flags var hasNoTransitEgressFlag = 1 - (subzone.Sequence == 0 ? 1 : 0); if (setImpedance) { setImpedance = false; // intermediate variable of type IEnumerable<IPathTypeModel> is needed to acquire First() method as extension IEnumerable <IPathTypeModel> pathTypeModels; pathTypeModels = PathTypeModelFactory.Singleton.Run(randomUtility, id, destination.Id, _middayStartMinute, _middayStartMinute, Global.Settings.Purposes.PersonalBusiness, costCoefficient, timeCoefficient, true, 1, false, 0.0, false, Global.Settings.Modes.Walk); var walkPath = pathTypeModels.First(); walkGenTime = walkPath.GeneralizedTimeLogsum; pathTypeModels = PathTypeModelFactory.Singleton.Run(randomUtility, id, destination.Id, _middayStartMinute, _middayStartMinute, Global.Settings.Purposes.PersonalBusiness, costCoefficient, timeCoefficient, true, 1, false, 0.0, false, Global.Settings.Modes.Sov); var sovPath = pathTypeModels.First(); var sovDistanceFromOrigin = (sovPath.PathDistance / Global.Settings.DistanceUnitsPerMile) / 2D; scaledSovDistanceFromOrigin = sovDistanceFromOrigin / 10D; sovGenTime = sovPath.GeneralizedTimeLogsum; pathTypeModels = PathTypeModelFactory.Singleton.Run(randomUtility, id, destination.Id, _middayStartMinute, _middayStartMinute, Global.Settings.Purposes.PersonalBusiness, costCoefficient, timeCoefficient, true, 1, false, 0.0, false, Global.Settings.Modes.Hov2); var hov2Path = pathTypeModels.First(); hov2GenTime = hov2Path.GeneralizedTimeLogsum; //if using stop areas, use stop area nearest to the zone centroid var transitOid = (!Global.StopAreaIsEnabled) ? id : (origin.NearestStopAreaId > 0) ? Global.TransitStopAreaMapping[origin.NearestStopAreaId] : id; var transitDid = (!Global.StopAreaIsEnabled) ? destination.Id : (destination.NearestStopAreaId > 0) ? Global.TransitStopAreaMapping[destination.NearestStopAreaId] : id; pathTypeModels = PathTypeModelFactory.Singleton.Run(randomUtility, transitOid, transitDid, _middayStartMinute, _middayStartMinute, Global.Settings.Purposes.PersonalBusiness, costCoefficient, timeCoefficient, true, 1, false, Global.Configuration.Policy_UniversalTransitFareDiscountFraction, false, Global.Settings.Modes.Transit); var transitPath = pathTypeModels.First(); transitGenTime = transitPath.GeneralizedTimeLogsum; } var modeUtilitySum = 0D; // SOV if (childFlag == 0 && noCarsFlag == 0 && sovGenTime != Global.Settings.GeneralizedTimeUnavailable) { modeUtilitySum += ComputeUtility( //p01 * (OPERATING_COST_PER_MILE * sovDistance + sovToll) + //p01 * parkingCost + //p02 * sovInVehicleTime + timeCoefficient * sovGenTime + p11 + p14 * carCompetitionFlag); } // HOV if (hov2GenTime != Global.Settings.GeneralizedTimeUnavailable) { modeUtilitySum += ComputeUtility( //p01 * ((OPERATING_COST_PER_MILE * hov2Distance + hov2Toll) / CP_FACTOR) + //p01 * parkingCost / CP_FACTOR + //p02 * hov2InVehicleTime + timeCoefficient * hov2GenTime + p21 + p22 * childFlag + p23 * noCarsFlag + p24 * carCompetitionFlag); } // TRANSIT if (transitGenTime != Global.Settings.GeneralizedTimeUnavailable && hasNoTransitAccessFlag == 0 && hasNoTransitEgressFlag == 0) { modeUtilitySum += ComputeUtility( //p01 * transitFare + //p02 * transitInVehicleTime + //p03 * transitInitialWaitTime + //p03 * transitNumberOfBoards + timeCoefficient * transitGenTime + p31 + p32 * childFlag + p33 * noCarsFlag + p34 * carCompetitionFlag + p37 * hasNoTransitAccessFlag); } // WALK if (walkGenTime != Global.Settings.GeneralizedTimeUnavailable) { modeUtilitySum += ComputeUtility( //p03 * walkDistance * 20); timeCoefficient * walkGenTime); } var modeLogsum = modeUtilitySum > Constants.EPSILON ? Math.Log(modeUtilitySum) : -30D; switch (purpose) { case 1: // HOME_BASED_COMPOSITE purposeUtility += ComputeUtility( size + HBB002 * modeLogsum + HBB003 * modeLogsum * noCarsFlag + HBB007 * modeLogsum * (noCarsFlag + carCompetitionFlag) * hasNoTransitAccessFlag + HBB008 * modeLogsum * noCarCompetitionFlag * hasNoTransitAccessFlag + HBB012 * subzone.MixedUseMeasure * carCompetitionFlag + HBB013 * subzone.MixedUseMeasure * noCarCompetitionFlag + HBB014 * subzone.MixedUseMeasure * childFlag + HBB016 * scaledSovDistanceFromOrigin * noCarsFlag + HBB018 * scaledSovDistanceFromOrigin * childFlag); break; case 2: // WORK_BASED purposeUtility += ComputeUtility( size + WBB002 * modeLogsum + WBB011 * modeLogsum * noCarCompetitionFlag * hasNearTransitAccessFlag + WBB012 * subzone.MixedUseMeasure * carCompetitionFlag + WBB013 * subzone.MixedUseMeasure * noCarCompetitionFlag + WBB015 * scaledSovDistanceFromOrigin); break; default: // ESCORT, PERSONAL_BUSINESS, SHOPPING, MEAL, SOCIAL or RECREATION purposeUtility += ComputeUtility( size + PSB006 * escortFlag * modeLogsum + PSB007 * noCarsFlag * modeLogsum + PSB008 * escortFlag * carDeficitFlag * modeLogsum + PSB009 * escortFlag * childFlag * modeLogsum + PSB011 * escortFlag * carDeficitFlag * hasNoTransitAccessFlag * modeLogsum + PSB012 * escortFlag * noCarCompetitionFlag * hasNoTransitAccessFlag * modeLogsum + PSB014 * carDeficitFlag * hasNearTransitAccessFlag * modeLogsum + PSB016 * escortFlag * scaledSovDistanceFromOrigin + PSB017 * noCarsFlag * scaledSovDistanceFromOrigin + PSB018 * escortFlag * carDeficitFlag * scaledSovDistanceFromOrigin + PSB020 * escortFlag * carCompetitionFlag * subzone.MixedUseMeasure + PSB021 * escortFlag * noCarCompetitionFlag * subzone.MixedUseMeasure + PSB022 * escortFlag * childFlag * subzone.MixedUseMeasure + PSB023 * personalBusinessFlag * modeLogsum + PSB024 * personalBusinessFlag * carDeficitFlag * modeLogsum + PSB025 * personalBusinessFlag * childFlag * modeLogsum + PSB027 * personalBusinessFlag * noCarCompetitionFlag * hasNoTransitAccessFlag * modeLogsum + PSB029 * personalBusinessFlag * carDeficitFlag * scaledSovDistanceFromOrigin + PSB030 * personalBusinessFlag * childFlag * scaledSovDistanceFromOrigin + PSB031 * personalBusinessFlag * carCompetitionFlag * subzone.MixedUseMeasure + PSB032 * personalBusinessFlag * noCarCompetitionFlag * subzone.MixedUseMeasure + PSB033 * personalBusinessFlag * childFlag * subzone.MixedUseMeasure + PSB034 * shoppingFlag * modeLogsum + PSB035 * shoppingFlag * carDeficitFlag * modeLogsum + PSB036 * shoppingFlag * childFlag * modeLogsum + PSB037 * shoppingFlag * carDeficitFlag * hasNoTransitAccessFlag * modeLogsum + PSB038 * shoppingFlag * noCarCompetitionFlag * hasNoTransitAccessFlag * modeLogsum + PSB045 * mealFlag * modeLogsum + PSB047 * mealFlag * childFlag * modeLogsum + PSB049 * mealFlag * noCarCompetitionFlag * hasNoTransitAccessFlag * modeLogsum + PSB053 * mealFlag * carCompetitionFlag * subzone.MixedUseMeasure + PSB054 * mealFlag * noCarCompetitionFlag * subzone.MixedUseMeasure + PSB055 * mealFlag * childFlag * subzone.MixedUseMeasure + PSB056 * socialFlag * modeLogsum + PSB057 * socialFlag * carDeficitFlag * modeLogsum + PSB059 * socialFlag * carDeficitFlag * hasNoTransitAccessFlag * modeLogsum + PSB060 * socialFlag * noCarCompetitionFlag * hasNoTransitAccessFlag * modeLogsum + PSB063 * socialFlag * childFlag * scaledSovDistanceFromOrigin + PSB064 * socialFlag * carCompetitionFlag * subzone.MixedUseMeasure + PSB065 * socialFlag * noCarCompetitionFlag * subzone.MixedUseMeasure + PSB066 * socialFlag * childFlag * subzone.MixedUseMeasure); break; } } transitAccesses[transitAccess] += purposeUtility; } } } } } return(purposes); }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, PersonWrapper person, int choice = Constants.DEFAULT_VALUE) { Framework.DomainModels.Wrappers.IParcelWrapper homeParcel = person.Household.ResidenceParcel; Framework.DomainModels.Wrappers.IParcelWrapper workParcel = person.IsUniversityStudent ? person.UsualSchoolParcel : person.UsualWorkParcel; Framework.DomainModels.Wrappers.IParcelWrapper schoolParcel = person.IsUniversityStudent ? null : person.UsualSchoolParcel; bool workParcelMissing = workParcel == null; bool schoolParcelMissing = schoolParcel == null; const double maxTranDist = 1.5; double homeTranDist = 99.0; if (homeParcel.GetDistanceToTransit() >= 0.0001 && homeParcel.GetDistanceToTransit() <= maxTranDist) { homeTranDist = homeParcel.GetDistanceToTransit(); } double workTranDist = 99.0; if (!workParcelMissing && workParcel.GetDistanceToTransit() >= 0.0001 && workParcel.GetDistanceToTransit() <= maxTranDist) { workTranDist = workParcel.GetDistanceToTransit(); } double schoolTranDist = 99.0; if (!schoolParcelMissing && schoolParcel.GetDistanceToTransit() >= 0.0001 && schoolParcel.GetDistanceToTransit() <= maxTranDist) { schoolTranDist = schoolParcel.GetDistanceToTransit(); } double workGenTimeNoPass = -99.0; double workGenTimeWithPass = -99.0; if (!workParcelMissing && workTranDist < maxTranDist && homeTranDist < maxTranDist) { IEnumerable <IPathTypeModel> pathTypeModels = PathTypeModelFactory.Singleton.Run( person.Household.RandomUtility, homeParcel, workParcel, Global.Settings.Times.EightAM, Global.Settings.Times.FivePM, Global.Settings.Purposes.Work, Global.Coefficients_BaseCostCoefficientPerMonetaryUnit, Global.Configuration.Coefficients_MeanTimeCoefficient_Work, true, 1, 0, false, 0.0, false, Global.Settings.Modes.Transit); IPathTypeModel path = pathTypeModels.First(); workGenTimeNoPass = path.GeneralizedTimeLogsum; // intermediate variable of type IEnumerable<dynamic> is needed to acquire First() method as extension pathTypeModels = PathTypeModelFactory.Singleton.Run( person.Household.RandomUtility, homeParcel, workParcel, Global.Settings.Times.EightAM, Global.Settings.Times.FivePM, Global.Settings.Purposes.Work, Global.Coefficients_BaseCostCoefficientPerMonetaryUnit, Global.Configuration.Coefficients_MeanTimeCoefficient_Work, /* isDrivingAge */ true, /* householdCars */ 1, /* transitPassOwnership */ 1, /* carsAreAVs */ false, /* transitDiscountFraction */ 1.0, /* randomChoice */ false, Global.Settings.Modes.Transit); path = pathTypeModels.First(); workGenTimeWithPass = path.GeneralizedTimeLogsum; } // double schoolGenTimeNoPass = -99.0; double schoolGenTimeWithPass = -99.0; if (!schoolParcelMissing && schoolTranDist < maxTranDist && homeTranDist < maxTranDist) { // schoolGenTimeNoPass = path.GeneralizedTimeLogsum; IEnumerable <IPathTypeModel> pathTypeModels = PathTypeModelFactory.Singleton.Run( person.Household.RandomUtility, homeParcel, schoolParcel, Global.Settings.Times.EightAM, Global.Settings.Times.ThreePM, Global.Settings.Purposes.School, Global.Coefficients_BaseCostCoefficientPerMonetaryUnit, Global.Configuration.Coefficients_MeanTimeCoefficient_Other, true, 1, 1, false, 1.0, false, Global.Settings.Modes.Transit); IPathTypeModel path = pathTypeModels.First(); schoolGenTimeWithPass = path.GeneralizedTimeLogsum; } const double inflection = 0.50; double homeTranDist1 = Math.Pow(Math.Min(inflection, homeTranDist), 2.0); double homeTranDist2 = Math.Pow(Math.Max(homeTranDist - inflection, 0), 0.5); // var workTranDist1 = Math.Pow(Math.Min(inflection, workTranDist),2.0); // var workTranDist2 = Math.Pow(Math.Max(workTranDist - inflection, 0),0.5); const double minimumAggLogsum = -15.0; int votSegment = person.Household.GetVotALSegment(); int homeTaSegment = homeParcel.TransitAccessSegment(); double homeAggregateLogsumNoCar = Math.Max(minimumAggLogsum, Global.AggregateLogsums[homeParcel.ZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.NoCars][votSegment][homeTaSegment]); int workTaSegment = workParcelMissing ? 0 : workParcel.TransitAccessSegment(); double workAggregateLogsumNoCar = workParcelMissing ? 0 : Math.Max(minimumAggLogsum, Global.AggregateLogsums[workParcel.ZoneId][Global.Settings.Purposes.WorkBased][Global.Settings.CarOwnerships.NoCars][votSegment][workTaSegment]); int schoolTaSegment = schoolParcelMissing ? 0 : schoolParcel.TransitAccessSegment(); double schoolAggregateLogsumNoCar = schoolParcelMissing ? 0 : Math.Max(minimumAggLogsum, Global.AggregateLogsums[schoolParcel.ZoneId][Global.Settings.Purposes.WorkBased][Global.Settings.CarOwnerships.NoCars][votSegment][schoolTaSegment]); double transitPassCostChange = !Global.Configuration.IsInEstimationMode ? Global.Configuration.PathImpedance_TransitPassCostPercentChangeVersusBase : 0; double workTourLogsumDifference = 0D; // (full or part-time workers) full car ownership vs. no car ownership double schoolTourLogsumDifference = 0D; // (school) full car ownership vs. no car ownership Framework.DomainModels.Wrappers.IHouseholdWrapper household = person.Household; if (person.UsualWorkParcel != null && person.UsualWorkParcelId != household.ResidenceParcelId) { int destinationArrivalTime = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.WorkTourModeModel); int destinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.WorkTourModeModel); //JLB 201602 //var nestedAlternative1 = Global.ChoiceModelSession.Get<WorkTourModeTimeModel>().RunNested(person, household.ResidenceParcel, person.UsualWorkParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable, 1.0); //var nestedAlternative2 = Global.ChoiceModelSession.Get<WorkTourModeTimeModel>().RunNested(person, household.ResidenceParcel, person.UsualWorkParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable, 0.0); ChoiceProbabilityCalculator.Alternative nestedAlternative1 = Global.ChoiceModelSession.Get <TourModeTimeModel>().RunNested(person, household.ResidenceParcel, person.UsualWorkParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable, 1.0, Global.Settings.Purposes.Work); ChoiceProbabilityCalculator.Alternative nestedAlternative2 = Global.ChoiceModelSession.Get <TourModeTimeModel>().RunNested(person, household.ResidenceParcel, person.UsualWorkParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable, 0.0, Global.Settings.Purposes.Work); workTourLogsumDifference = nestedAlternative1 == null ? 0 : nestedAlternative1.ComputeLogsum(); workTourLogsumDifference = nestedAlternative2 == null ? 0 : nestedAlternative2.ComputeLogsum(); } if (person.UsualSchoolParcel != null && person.UsualSchoolParcelId != household.ResidenceParcelId) { int destinationArrivalTime = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.SchoolTourModeModel); int destinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.SchoolTourModeModel); //JLB 201602 //var nestedAlternative1 = Global.ChoiceModelSession.Get<SchoolTourModeTimeModel>().RunNested(person, household.ResidenceParcel, person.UsualSchoolParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable, 1.0); //var nestedAlternative2 = Global.ChoiceModelSession.Get<SchoolTourModeTimeModel>().RunNested(person, household.ResidenceParcel, person.UsualSchoolParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable, 0.0); ChoiceProbabilityCalculator.Alternative nestedAlternative1 = Global.ChoiceModelSession.Get <TourModeTimeModel>().RunNested(person, household.ResidenceParcel, person.UsualSchoolParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable, 1.0, Global.Settings.Purposes.School); ChoiceProbabilityCalculator.Alternative nestedAlternative2 = Global.ChoiceModelSession.Get <TourModeTimeModel>().RunNested(person, household.ResidenceParcel, person.UsualSchoolParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable, 0.0, Global.Settings.Purposes.School); schoolTourLogsumDifference = nestedAlternative1 == null ? 0 : nestedAlternative1.ComputeLogsum(); schoolTourLogsumDifference = nestedAlternative2 == null ? 0 : nestedAlternative2.ComputeLogsum(); } //Stefan variables double netIncomeNetCarOwnership = Math.Max(0, (person.Household.Income / 1000.0) / 2.0 - 2.441 * 15.0 * person.Household.VehiclesAvailable); //net income minus annual cost to use household's cars in 1000s of DKK //set household characteristics here that depend on person characteristics int numberAdults = 0; int numberChildren = 0; foreach (PersonWrapper p in person.Household.Persons) { if (p.Age >= 18) { numberAdults++; } else { numberChildren++; } } Framework.DomainModels.Wrappers.IParcelWrapper usualParcel = person.IsFullOrPartTimeWorker ? person.UsualWorkParcel : null; usualParcel = (usualParcel == null && person.UsualSchoolParcel != null) ? person.UsualSchoolParcel : null; int parkingSearchTime = 0; double commuteDistance = 0.0; int parkingCost = 0; int model = 3; if (usualParcel != null) { //parkingSearchTime = usualParcel.PSearchTime07_08; //uncomment when the new parcel attributes have been defined commuteDistance = ImpedanceRoster.GetValue("distance", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, 1.0, Global.Settings.Times.EightAM, household.ResidenceParcel, usualParcel).Variable; //parkingCost = usualParcel.ParkingCostPerHour8_18; //uncomment when the new parcel attributes have been defined if (person.IsFulltimeWorker && usualParcel == person.UsualWorkParcel) { parkingCost = parkingCost * 8; model = 1; } else if (person.IsPartTimeWorker && usualParcel == person.UsualWorkParcel) { parkingCost = parkingCost * 4; model = 1; } else { parkingCost = parkingCost * 6; // parking for school model = 2; } } // 0 No transit pass ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(0, true, choice == 0); alternative.Choice = 0; alternative.AddUtilityTerm(1, 0.0); // 1 Transit pass double stefanUtility = 0.0; alternative = choiceProbabilityCalculator.GetAlternative(1, true, choice == 1); alternative.Choice = 1; if (model == 1 && person.Household.VehiclesAvailable == 0) { double beta001 = -0.33; double beta002 = -0.34; double beta003 = -1.15; double beta004 = -0.34; double beta005 = 0.0; double beta006 = 0.0; double beta007 = 0.0; double beta008 = 0.0; double beta009 = 0.0; double beta010 = 0.0; double beta011 = 0.0; double beta012 = 0.0; stefanUtility = beta001 * 1.0 + beta002 * numberChildren + beta003 * netIncomeNetCarOwnership + beta004 * person.IsMale.ToFlag() + beta005 * (person.IsAdultFemale && numberAdults == 1).ToFlag() + beta006 * (person.IsAdultFemale && numberAdults > 1).ToFlag() + beta007 * person.Age + beta008 * Math.Pow(person.Age, 2.0) + beta009 * (person.Household.VehiclesAvailable >= 2).ToFlag() + beta010 * (person.IsAdultMale && numberAdults == 1).ToFlag() + beta011 * Math.Min(person.Household.ResidenceParcel.DistanceToLocalBus, 2.0) + beta012 * Math.Min(5.0, person.Household.ResidenceParcel.DistanceToExpressBus) + 0.0; //Stefan utility //alternative.AddUtilityTerm(1, 1.0); //alternative.AddUtilityTerm(2, numberChildren); //alternative.AddUtilityTerm(3, netIncomeNetCarOwnership); //alternative.AddUtilityTerm(4, person.IsMale.ToFlag()); //alternative.AddUtilityTerm(5, (person.IsAdultFemale && numberAdults == 1).ToFlag()); //alternative.AddUtilityTerm(6, (person.IsAdultFemale && numberAdults > 1).ToFlag()); //alternative.AddUtilityTerm(7, person.Age); //alternative.AddUtilityTerm(8, Math.Pow(person.Age, 2.0)); //non-worker/non-student models only //alternative.AddUtilityTerm(9, (person.Household.VehiclesAvailable >= 2).ToFlag()); //alternative.AddUtilityTerm(10, (person.IsAdultMale && numberAdults == 1).ToFlag()); //alternative.AddUtilityTerm(11, Math.Min(person.Household.ResidenceParcel.DistanceToLocalBus, 2.0)); //alternative.AddUtilityTerm(12, Math.Min(5.0, person.Household.ResidenceParcel.DistanceToExpressBus)); alternative.AddUtilityTerm(1, stefanUtility); // this composite replaces terms *1-*12 above //Stefan impedance (try replacign these with logsums) alternative.AddUtilityTerm(13, Math.Min(person.Household.ResidenceParcel.DistanceToLocalBus, person.Household.ResidenceParcel.DistanceToExpressBus)); alternative.AddUtilityTerm(14, (commuteDistance > 0 && commuteDistance < 3).ToFlag()); alternative.AddUtilityTerm(15, (commuteDistance >= 7 && commuteDistance < 13).ToFlag()); alternative.AddUtilityTerm(16, (commuteDistance >= 13).ToFlag()); alternative.AddUtilityTerm(17, parkingCost); alternative.AddUtilityTerm(18, parkingSearchTime); //commute logsum difference variable (with and without transit pass) alternative.AddUtilityTerm(19, workTourLogsumDifference); } else if (model == 1 && person.Household.VehiclesAvailable == 1) { double beta101 = -1.16; int beta102 = 0; int beta103 = 0; int beta104 = 0; int beta105 = 0; double beta106 = 0.63; double beta107 = -0.76; double beta108 = 0.09; int beta109 = 0; int beta110 = 0; int beta111 = 0; int beta112 = 0; stefanUtility = beta101 * 1.0 + beta102 * numberChildren + beta103 * netIncomeNetCarOwnership + beta104 * person.IsMale.ToFlag() + beta105 * (person.IsAdultFemale && numberAdults == 1).ToFlag() + beta106 * (person.IsAdultFemale && numberAdults > 1).ToFlag() + beta107 * person.Age + beta108 * Math.Pow(person.Age, 2.0) + beta109 * (person.Household.VehiclesAvailable >= 2).ToFlag() + beta110 * (person.IsAdultMale && numberAdults == 1).ToFlag() + beta111 * Math.Min(person.Household.ResidenceParcel.DistanceToLocalBus, 2.0) + beta112 * Math.Min(5.0, person.Household.ResidenceParcel.DistanceToExpressBus) + 0.0; //Stefan utility //alternative.AddUtilityTerm(101, 1.0); //alternative.AddUtilityTerm(102, numberChildren); //alternative.AddUtilityTerm(103, netIncomeNetCarOwnership); //alternative.AddUtilityTerm(104, person.IsMale.ToFlag()); //alternative.AddUtilityTerm(105, (person.IsAdultFemale && numberAdults == 1).ToFlag()); //alternative.AddUtilityTerm(106, (person.IsAdultFemale && numberAdults > 1).ToFlag()); //alternative.AddUtilityTerm(107, person.Age); //alternative.AddUtilityTerm(108, Math.Pow(person.Age, 2.0)); ////non-worker/non-student models only //alternative.AddUtilityTerm(109, (person.Household.VehiclesAvailable >= 2).ToFlag()); //alternative.AddUtilityTerm(110, (person.IsAdultMale && numberAdults == 1).ToFlag()); //alternative.AddUtilityTerm(111, Math.Min(person.Household.ResidenceParcel.DistanceToLocalBus, 2.0)); //alternative.AddUtilityTerm(112, Math.Min(5.0, person.Household.ResidenceParcel.DistanceToExpressBus)); alternative.AddUtilityTerm(101, stefanUtility); // this composite replaces terms *1-*12 above //Stefan impedance (try replacign these with logsums) alternative.AddUtilityTerm(113, Math.Min(person.Household.ResidenceParcel.DistanceToLocalBus, person.Household.ResidenceParcel.DistanceToExpressBus)); alternative.AddUtilityTerm(114, (commuteDistance > 0 && commuteDistance < 3).ToFlag()); alternative.AddUtilityTerm(115, (commuteDistance >= 7 && commuteDistance < 13).ToFlag()); alternative.AddUtilityTerm(116, (commuteDistance >= 13).ToFlag()); alternative.AddUtilityTerm(117, parkingCost); alternative.AddUtilityTerm(118, parkingSearchTime); //commute logsum difference variable (with and without transit pass) alternative.AddUtilityTerm(119, workTourLogsumDifference); } else if (model == 1 && person.Household.VehiclesAvailable >= 2) { double beta201 = -0.54; int beta202 = 0; int beta203 = 0; int beta204 = 0; double beta205 = 1.35; double beta206 = 0.42; double beta207 = -1.5; double beta208 = 0.17; int beta209 = 0; int beta210 = 0; int beta211 = 0; int beta212 = 0; stefanUtility = beta201 * 1.0 + beta202 * numberChildren + beta203 * netIncomeNetCarOwnership + beta204 * person.IsMale.ToFlag() + beta205 * (person.IsAdultFemale && numberAdults == 1).ToFlag() + beta206 * (person.IsAdultFemale && numberAdults > 1).ToFlag() + beta207 * person.Age + beta208 * Math.Pow(person.Age, 2.0) + beta209 * (person.Household.VehiclesAvailable >= 2).ToFlag() + beta210 * (person.IsAdultMale && numberAdults == 1).ToFlag() + beta211 * Math.Min(person.Household.ResidenceParcel.DistanceToLocalBus, 2.0) + beta212 * Math.Min(5.0, person.Household.ResidenceParcel.DistanceToExpressBus) + 0.0; //Stefan utility //alternative.AddUtilityTerm(201, 1.0); //alternative.AddUtilityTerm(202, numberChildren); //alternative.AddUtilityTerm(203, netIncomeNetCarOwnership); //alternative.AddUtilityTerm(204, person.IsMale.ToFlag()); //alternative.AddUtilityTerm(205, (person.IsAdultFemale && numberAdults == 1).ToFlag()); //alternative.AddUtilityTerm(206, (person.IsAdultFemale && numberAdults > 1).ToFlag()); //alternative.AddUtilityTerm(207, person.Age); //alternative.AddUtilityTerm(208, Math.Pow(person.Age, 2.0)); //non-worker/non-student models only //alternative.AddUtilityTerm(209, (person.Household.VehiclesAvailable >= 2).ToFlag()); //alternative.AddUtilityTerm(210, (person.IsAdultMale && numberAdults == 1).ToFlag()); //alternative.AddUtilityTerm(211, Math.Min(person.Household.ResidenceParcel.DistanceToLocalBus, 2.0)); //alternative.AddUtilityTerm(212, Math.Min(5.0, person.Household.ResidenceParcel.DistanceToExpressBus)); alternative.AddUtilityTerm(201, stefanUtility); // this composite replaces terms *1-*12 above //Stefan impedance (try replacign these with logsums) alternative.AddUtilityTerm(213, Math.Min(person.Household.ResidenceParcel.DistanceToLocalBus, person.Household.ResidenceParcel.DistanceToExpressBus)); alternative.AddUtilityTerm(214, (commuteDistance > 0 && commuteDistance < 3).ToFlag()); alternative.AddUtilityTerm(215, (commuteDistance >= 7 && commuteDistance < 13).ToFlag()); alternative.AddUtilityTerm(216, (commuteDistance >= 13).ToFlag()); alternative.AddUtilityTerm(217, parkingCost); alternative.AddUtilityTerm(218, parkingSearchTime); //commute logsum difference variable (with and without transit pass) alternative.AddUtilityTerm(219, workTourLogsumDifference); } else if (model == 2 && person.Household.VehiclesAvailable == 0) { double beta301 = 4.74; double beta302 = 0.39; int beta303 = 0; int beta304 = 0; int beta305 = 0; int beta306 = 0; double beta307 = -3.95; double beta308 = 0.62; int beta309 = 0; int beta310 = 0; int beta311 = 0; int beta312 = 0; stefanUtility = beta301 * 1.0 + beta302 * numberChildren + beta303 * netIncomeNetCarOwnership + beta304 * person.IsMale.ToFlag() + beta305 * (person.IsAdultFemale && numberAdults == 1).ToFlag() + beta306 * (person.IsAdultFemale && numberAdults > 1).ToFlag() + beta307 * person.Age + beta308 * Math.Pow(person.Age, 2.0) + beta309 * (person.Household.VehiclesAvailable >= 2).ToFlag() + beta310 * (person.IsAdultMale && numberAdults == 1).ToFlag() + beta311 * Math.Min(person.Household.ResidenceParcel.DistanceToLocalBus, 2.0) + beta312 * Math.Min(5.0, person.Household.ResidenceParcel.DistanceToExpressBus) + 0.0; //Stefan utility //alternative.AddUtilityTerm(301, 1.0); //alternative.AddUtilityTerm(302, numberChildren); //alternative.AddUtilityTerm(303, netIncomeNetCarOwnership); //alternative.AddUtilityTerm(304, person.IsMale.ToFlag()); //alternative.AddUtilityTerm(305, (person.IsAdultFemale && numberAdults == 1).ToFlag()); //alternative.AddUtilityTerm(306, (person.IsAdultFemale && numberAdults > 1).ToFlag()); //alternative.AddUtilityTerm(307, person.Age); //alternative.AddUtilityTerm(308, Math.Pow(person.Age, 2.0)); ////non-worker/non-student models only //alternative.AddUtilityTerm(309, (person.Household.VehiclesAvailable >= 2).ToFlag()); //alternative.AddUtilityTerm(310, (person.IsAdultMale && numberAdults == 1).ToFlag()); //alternative.AddUtilityTerm(311, Math.Min(person.Household.ResidenceParcel.DistanceToLocalBus, 2.0)); //alternative.AddUtilityTerm(312, Math.Min(5.0, person.Household.ResidenceParcel.DistanceToExpressBus)); alternative.AddUtilityTerm(301, stefanUtility); // this composite replaces terms *1-*12 above //Stefan impedance (try replacign these with logsums) alternative.AddUtilityTerm(313, Math.Min(person.Household.ResidenceParcel.DistanceToLocalBus, person.Household.ResidenceParcel.DistanceToExpressBus)); alternative.AddUtilityTerm(314, (commuteDistance > 0 && commuteDistance < 3).ToFlag()); alternative.AddUtilityTerm(315, (commuteDistance >= 7 && commuteDistance < 13).ToFlag()); alternative.AddUtilityTerm(316, (commuteDistance >= 13).ToFlag()); alternative.AddUtilityTerm(317, parkingCost); alternative.AddUtilityTerm(318, parkingSearchTime); //commute logsum difference variable (with and without transit pass) alternative.AddUtilityTerm(319, schoolTourLogsumDifference); } else if (model == 2 && person.Household.VehiclesAvailable >= 1) { double beta401 = 3.75; int beta402 = 0; int beta403 = 0; int beta404 = 0; int beta405 = 0; int beta406 = 0; double beta407 = 2.81; double beta408 = 0.33; int beta409 = 0; int beta410 = 0; int beta411 = 0; int beta412 = 0; stefanUtility = beta401 * 1.0 + beta402 * numberChildren + beta403 * netIncomeNetCarOwnership + beta404 * person.IsMale.ToFlag() + beta405 * (person.IsAdultFemale && numberAdults == 1).ToFlag() + beta406 * (person.IsAdultFemale && numberAdults > 1).ToFlag() + beta407 * person.Age + beta408 * Math.Pow(person.Age, 2.0) + beta409 * (person.Household.VehiclesAvailable >= 2).ToFlag() + beta410 * (person.IsAdultMale && numberAdults == 1).ToFlag() + beta411 * Math.Min(person.Household.ResidenceParcel.DistanceToLocalBus, 2.0) + beta412 * Math.Min(5.0, person.Household.ResidenceParcel.DistanceToExpressBus) + 0.0; //Stefan utility //alternative.AddUtilityTerm(401, 1.0); //alternative.AddUtilityTerm(402, numberChildren); //alternative.AddUtilityTerm(403, netIncomeNetCarOwnership); //alternative.AddUtilityTerm(404, person.IsMale.ToFlag()); //alternative.AddUtilityTerm(405, (person.IsAdultFemale && numberAdults == 1).ToFlag()); //alternative.AddUtilityTerm(406, (person.IsAdultFemale && numberAdults > 1).ToFlag()); //alternative.AddUtilityTerm(407, person.Age); //alternative.AddUtilityTerm(408, Math.Pow(person.Age, 2.0)); ////non-worker/non-student models only //alternative.AddUtilityTerm(409, (person.Household.VehiclesAvailable >= 2).ToFlag()); //alternative.AddUtilityTerm(410, (person.IsAdultMale && numberAdults == 1).ToFlag()); //alternative.AddUtilityTerm(411, Math.Min(person.Household.ResidenceParcel.DistanceToLocalBus, 2.0)); //alternative.AddUtilityTerm(412, Math.Min(5.0, person.Household.ResidenceParcel.DistanceToExpressBus)); alternative.AddUtilityTerm(401, stefanUtility); // this composite replaces terms *1-*12 above //Stefan impedance (try replacign these with logsums) alternative.AddUtilityTerm(413, Math.Min(person.Household.ResidenceParcel.DistanceToLocalBus, person.Household.ResidenceParcel.DistanceToExpressBus)); alternative.AddUtilityTerm(414, (commuteDistance > 0 && commuteDistance < 3).ToFlag()); alternative.AddUtilityTerm(415, (commuteDistance >= 7 && commuteDistance < 13).ToFlag()); alternative.AddUtilityTerm(416, (commuteDistance >= 13).ToFlag()); alternative.AddUtilityTerm(417, parkingCost); alternative.AddUtilityTerm(418, parkingSearchTime); //commute logsum difference variable (with and without transit pass) alternative.AddUtilityTerm(419, schoolTourLogsumDifference); } else if (model == 3 && person.Household.VehiclesAvailable == 0) { double beta501 = 0.05; int beta502 = 0; int beta503 = 0; int beta504 = 0; double beta505 = 0.56; double beta506 = 0.41; int beta507 = 0; int beta508 = 0; int beta509 = 0; int beta510 = 0; double beta511 = -0.45; int beta512 = 0; stefanUtility = beta501 * 1.0 + beta502 * numberChildren + beta503 * netIncomeNetCarOwnership + beta504 * person.IsMale.ToFlag() + beta505 * (person.IsAdultFemale && numberAdults == 1).ToFlag() + beta506 * (person.IsAdultFemale && numberAdults > 1).ToFlag() + beta507 * person.Age + beta508 * Math.Pow(person.Age, 2.0) + beta509 * (person.Household.VehiclesAvailable >= 2).ToFlag() + beta510 * (person.IsAdultMale && numberAdults == 1).ToFlag() + beta511 * Math.Min(person.Household.ResidenceParcel.DistanceToLocalBus, 2.0) + beta512 * Math.Min(5.0, person.Household.ResidenceParcel.DistanceToExpressBus) + 0.0; //Stefan utility //alternative.AddUtilityTerm(501, 1.0); //alternative.AddUtilityTerm(502, numberChildren); //alternative.AddUtilityTerm(503, netIncomeNetCarOwnership); //alternative.AddUtilityTerm(504, person.IsMale.ToFlag()); //alternative.AddUtilityTerm(505, (person.IsAdultFemale && numberAdults == 1).ToFlag()); //alternative.AddUtilityTerm(506, (person.IsAdultFemale && numberAdults > 1).ToFlag()); //alternative.AddUtilityTerm(507, person.Age); //alternative.AddUtilityTerm(508, Math.Pow(person.Age, 2.0)); ////non-worker/non-student models only //alternative.AddUtilityTerm(509, (person.Household.VehiclesAvailable >= 2).ToFlag()); //alternative.AddUtilityTerm(510, (person.IsAdultMale && numberAdults == 1).ToFlag()); //alternative.AddUtilityTerm(511, Math.Min(person.Household.ResidenceParcel.DistanceToLocalBus, 2.0)); //alternative.AddUtilityTerm(512, Math.Min(5.0, person.Household.ResidenceParcel.DistanceToExpressBus)); alternative.AddUtilityTerm(501, stefanUtility); // this composite replaces terms *1-*12 above } else //(model == 3 && person.Household.VehiclesAvailable >= 1) { double beta601 = -1.7; int beta602 = 0; double beta603 = 0.47; int beta604 = 0; double beta605 = 0.63; double beta606 = 0.46; int beta607 = 0; int beta608 = 0; double beta609 = -0.32; double beta610 = 0.35; double beta611 = -0.37; double beta612 = -0.09; stefanUtility = beta601 * 1.0 + beta602 * numberChildren + beta603 * netIncomeNetCarOwnership + beta604 * person.IsMale.ToFlag() + beta605 * (person.IsAdultFemale && numberAdults == 1).ToFlag() + beta606 * (person.IsAdultFemale && numberAdults > 1).ToFlag() + beta607 * person.Age + beta608 * Math.Pow(person.Age, 2.0) + beta609 * (person.Household.VehiclesAvailable >= 2).ToFlag() + beta610 * (person.IsAdultMale && numberAdults == 1).ToFlag() + beta611 * Math.Min(person.Household.ResidenceParcel.DistanceToLocalBus, 2.0) + beta612 * Math.Min(5.0, person.Household.ResidenceParcel.DistanceToExpressBus) + 0.0; //Stefan utility //alternative.AddUtilityTerm(601, 1.0); //alternative.AddUtilityTerm(602, numberChildren); //alternative.AddUtilityTerm(603, netIncomeNetCarOwnership); //alternative.AddUtilityTerm(604, person.IsMale.ToFlag()); //alternative.AddUtilityTerm(605, (person.IsAdultFemale && numberAdults == 1).ToFlag()); //alternative.AddUtilityTerm(606, (person.IsAdultFemale && numberAdults > 1).ToFlag()); //alternative.AddUtilityTerm(607, person.Age); //alternative.AddUtilityTerm(608, Math.Pow(person.Age, 2.0)); //non-worker/non-student models only //alternative.AddUtilityTerm(609, (person.Household.VehiclesAvailable >= 2).ToFlag()); //alternative.AddUtilityTerm(610, (person.IsAdultMale && numberAdults == 1).ToFlag()); //alternative.AddUtilityTerm(611, Math.Min(person.Household.ResidenceParcel.DistanceToLocalBus, 2.0)); //alternative.AddUtilityTerm(612, Math.Min(5.0, person.Household.ResidenceParcel.DistanceToExpressBus)); alternative.AddUtilityTerm(601, stefanUtility); // this composite replaces terms *1-*12 above } //alternative.AddUtilityTerm(2, person.IsPartTimeWorker.ToFlag()); //alternative.AddUtilityTerm(3, (person.IsWorker && person.IsNotFullOrPartTimeWorker).ToFlag()); //alternative.AddUtilityTerm(4, person.IsUniversityStudent.ToFlag()); //alternative.AddUtilityTerm(5, person.IsRetiredAdult.ToFlag()); //alternative.AddUtilityTerm(6, person.IsNonworkingAdult.ToFlag()); //alternative.AddUtilityTerm(7, person.IsDrivingAgeStudent.ToFlag()); //alternative.AddUtilityTerm(8, person.IsChildUnder16.ToFlag()); //alternative.AddUtilityTerm(9, Math.Log(Math.Max(1, person.Household.Income))); //alternative.AddUtilityTerm(10, person.Household.HasMissingIncome.ToFlag()); //alternative.AddUtilityTerm(11, workParcelMissing.ToFlag()); //alternative.AddUtilityTerm(12, schoolParcelMissing.ToFlag()); //alternative.AddUtilityTerm(13, (homeTranDist < 90.0) ? homeTranDist1 : 0); //alternative.AddUtilityTerm(14, (homeTranDist < 90.0) ? homeTranDist2 : 0); //alternative.AddUtilityTerm(15, (homeTranDist > 90.0) ? 1 : 0); // //alternative.AddUtility(16, (workTranDist < 90.0) ? workTranDist : 0); // //alternative.AddUtility(17, (workTranDist < 90.0) ? workTranDist2 : 0); // //alternative.AddUtility(18, (workTranDist > 90.0) ? 1 : 0); // //alternative.AddUtility(19, (schoolTranDist < 90.0) ? schoolTranDist : 0); // //alternative.AddUtility(20, (schoolTranDist > 90.0) ? 1 : 0); // //alternative.AddUtility(21, (!workParcelMissing && workGenTimeWithPass > -90 ) ? workGenTimeWithPass : 0); //alternative.AddUtilityTerm(22, (!workParcelMissing && workGenTimeWithPass <= -90) ? 1 : 0); //alternative.AddUtilityTerm(23, (!workParcelMissing && workGenTimeWithPass > -90 && workGenTimeNoPass > -90) ? workGenTimeNoPass - workGenTimeWithPass : 0); // //alternative.AddUtility(24, (!schoolParcelMissing && schoolGenTimeWithPass > -90 ) ? schoolGenTimeWithPass : 0); //alternative.AddUtilityTerm(25, (!schoolParcelMissing && schoolGenTimeWithPass <= -90) ? 1 : 0); //alternative.AddUtilityTerm(26, homeAggregateLogsumNoCar * (person.IsFullOrPartTimeWorker || person.IsUniversityStudent).ToFlag()); //alternative.AddUtilityTerm(27, homeAggregateLogsumNoCar * (person.IsDrivingAgeStudent || person.IsChildUnder16).ToFlag()); //alternative.AddUtilityTerm(28, homeAggregateLogsumNoCar * (person.IsNonworkingAdult).ToFlag()); //alternative.AddUtilityTerm(29, homeAggregateLogsumNoCar * (person.IsRetiredAdult).ToFlag()); //alternative.AddUtilityTerm(30, workParcelMissing ? 0 : workAggregateLogsumNoCar); //alternative.AddUtilityTerm(31, schoolParcelMissing ? 0 : schoolAggregateLogsumNoCar); //alternative.AddUtilityTerm(32, transitPassCostChange); }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITourWrapper tour, IEnumerable <IPathTypeModel> pathTypeModels, IParcelWrapper destinationParcel, int householdCars, int choice = Constants.DEFAULT_VALUE) { IHouseholdWrapper household = tour.Household; Framework.DomainModels.Models.IHouseholdTotals householdTotals = household.HouseholdTotals; IPersonDayWrapper personDay = tour.PersonDay; IPersonWrapper person = tour.Person; // household inputs int childrenUnder5 = householdTotals.ChildrenUnder5; int childrenAge5Through15 = householdTotals.ChildrenAge5Through15; // var nonworkingAdults = householdTotals.NonworkingAdults; // var retiredAdults = householdTotals.RetiredAdults; int onePersonHouseholdFlag = household.IsOnePersonHousehold.ToFlag(); int twoPersonHouseholdFlag = household.IsTwoPersonHousehold.ToFlag(); int noCarsInHouseholdFlag = household.GetFlagForNoCarsInHousehold(householdCars); int carsLessThanDriversFlag = household.GetFlagForCarsLessThanDrivers(householdCars); int carsLessThanWorkersFlag = household.GetFlagForCarsLessThanWorkers(householdCars); int income0To25KFlag = household.Has0To25KIncome.ToFlag(); int income75kPlusFlag = household.Has75KPlusIncome.ToFlag(); int incomeOver100Flag = household.Has100KPlusIncome.ToFlag(); // person inputs int maleFlag = person.IsMale.ToFlag(); int ageBetween51And98Flag = person.AgeIsBetween51And98.ToFlag(); int univStudentFlag = person.IsUniversityStudent.ToFlag(); IParcelWrapper originParcel = tour.OriginParcel; int parkingDuration = ChoiceModelUtility.GetParkingDuration(person.IsFulltimeWorker); // parking at work is free if no paid parking at work and tour goes to usual workplace double destinationParkingCost = (Global.Configuration.ShouldRunPayToParkAtWorkplaceModel && tour.Person.UsualWorkParcel != null && destinationParcel == tour.Person.UsualWorkParcel && person.PaidParkingAtWorkplace == 0) ? 0.0 : destinationParcel.ParkingCostBuffer1(parkingDuration); ChoiceModelUtility.SetEscortPercentages(personDay, out double escortPercentage, out double nonEscortPercentage); foreach (IPathTypeModel pathTypeModel in pathTypeModels) { int mode = pathTypeModel.Mode; double generalizedTimeLogsum = pathTypeModel.GeneralizedTimeLogsum; bool available = (pathTypeModel.Mode != Global.Settings.Modes.PaidRideShare || Global.Configuration.PaidRideShareModeIsAvailable) && pathTypeModel.Available; ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(mode, available, choice == mode); alternative.Choice = mode; alternative.AddNestedAlternative(_nestedAlternativeIds[pathTypeModel.Mode], _nestedAlternativeIndexes[pathTypeModel.Mode], THETA_PARAMETER); if (!available) { continue; } double modeTimeCoefficient = (Global.Configuration.AV_IncludeAutoTypeChoice && household.OwnsAutomatedVehicles > 0 && mode >= Global.Settings.Modes.Sov && mode <= Global.Settings.Modes.Hov3) ? tour.TimeCoefficient * (1.0 - Global.Configuration.AV_InVehicleTimeCoefficientDiscountFactor) : (mode == Global.Settings.Modes.PaidRideShare && Global.Configuration.AV_PaidRideShareModeUsesAVs) ? tour.TimeCoefficient * (1.0 - Global.Configuration.AV_InVehicleTimeCoefficientDiscountFactor) : tour.TimeCoefficient; alternative.AddUtilityTerm(2, generalizedTimeLogsum * modeTimeCoefficient); if (mode == Global.Settings.Modes.ParkAndRide) { alternative.AddUtilityTerm(10, 1); alternative.AddUtilityTerm(11, noCarsInHouseholdFlag); alternative.AddUtilityTerm(13, carsLessThanWorkersFlag); // alternative.AddUtility(129, destinationParcel.MixedUse2Index1()); alternative.AddUtilityTerm(130, Math.Log(destinationParcel.TotalEmploymentDensity1() + 1) * 2553.0 / Math.Log(2553.0)); alternative.AddUtilityTerm(128, destinationParcel.TotalEmploymentDensity1()); alternative.AddUtilityTerm(127, destinationParcel.NetIntersectionDensity1()); alternative.AddUtilityTerm(123, Math.Log(destinationParcel.StopsTransitBuffer1 + 1)); //alternative.AddUtilityTerm(120, Math.Log(destinationParcel.TotalEmploymentDensity1() + 1) * 2553.0 / Math.Log(2553.0)); alternative.AddUtilityTerm(118, destinationParcel.TotalEmploymentDensity1()); //alternative.AddUtilityTerm(117, destinationParcel.NetIntersectionDensity1()); alternative.AddUtilityTerm(113, Math.Log(destinationParcel.StopsTransitBuffer1 + 1)); alternative.AddUtilityTerm(112, Math.Log(originParcel.StopsTransitBuffer1 + 1)); alternative.AddUtilityTerm(115, Math.Log(pathTypeModel.PathParkAndRideNodeCapacity + 1)); } else if (mode == Global.Settings.Modes.Transit) { alternative.AddUtilityTerm(20, 1); alternative.AddUtilityTerm(21, noCarsInHouseholdFlag); //for calibration alternative.AddUtilityTerm(22, carsLessThanDriversFlag); //for calibration // alternative.AddUtility(129, destinationParcel.MixedUse2Index1()); alternative.AddUtilityTerm(130, Math.Log(destinationParcel.TotalEmploymentDensity1() + 1) * 2553.0 / Math.Log(2553.0)); alternative.AddUtilityTerm(128, destinationParcel.TotalEmploymentDensity1()); alternative.AddUtilityTerm(127, destinationParcel.NetIntersectionDensity1()); alternative.AddUtilityTerm(126, originParcel.NetIntersectionDensity1()); //alternative.AddUtilityTerm(125, originParcel.HouseholdDensity1()); //alternative.AddUtilityTerm(124, originParcel.MixedUse2Index1()); alternative.AddUtilityTerm(123, Math.Log(destinationParcel.StopsTransitBuffer1 + 1)); alternative.AddUtilityTerm(122, Math.Log(originParcel.StopsTransitBuffer1 + 1)); alternative.AddUtilityTerm(180, univStudentFlag); alternative.AddUtilityTerm(100, income75kPlusFlag); } else if (mode == Global.Settings.Modes.Hov3) { alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / Global.Configuration.Coefficients_HOV3CostDivisor_Work)); alternative.AddUtilityTerm(30, 1); alternative.AddUtilityTerm(31, childrenUnder5); alternative.AddUtilityTerm(32, childrenAge5Through15); // alternative.AddUtilityTerm(34, nonworkingAdults + retiredAdults); alternative.AddUtilityTerm(35, pathTypeModel.PathDistance.AlmostEquals(0) ? 0 : Math.Log(pathTypeModel.PathDistance)); alternative.AddUtilityTerm(36, noCarsInHouseholdFlag); // for calibration of hov3 vs hov2 alternative.AddUtilityTerm(37, carsLessThanDriversFlag); // for calibration of hov3 vs hov2 alternative.AddUtilityTerm(38, onePersonHouseholdFlag); alternative.AddUtilityTerm(39, twoPersonHouseholdFlag); alternative.AddUtilityTerm(41, noCarsInHouseholdFlag); alternative.AddUtilityTerm(42, carsLessThanDriversFlag); alternative.AddUtilityTerm(133, escortPercentage); alternative.AddUtilityTerm(134, nonEscortPercentage); } else if (mode == Global.Settings.Modes.Hov2) { alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / Global.Configuration.Coefficients_HOV2CostDivisor_Work)); alternative.AddUtilityTerm(31, childrenUnder5); alternative.AddUtilityTerm(32, childrenAge5Through15); // alternative.AddUtilityTerm(34, nonworkingAdults + retiredAdults); alternative.AddUtilityTerm(35, pathTypeModel.PathDistance.AlmostEquals(0) ? 0 : Math.Log(pathTypeModel.PathDistance)); alternative.AddUtilityTerm(40, 1); alternative.AddUtilityTerm(41, noCarsInHouseholdFlag); alternative.AddUtilityTerm(42, carsLessThanDriversFlag); alternative.AddUtilityTerm(48, onePersonHouseholdFlag); alternative.AddUtilityTerm(133, escortPercentage); alternative.AddUtilityTerm(134, nonEscortPercentage); } else if (mode == Global.Settings.Modes.Sov) { alternative.AddUtilityTerm(1, (destinationParkingCost) * tour.CostCoefficient); alternative.AddUtilityTerm(50, 1); alternative.AddUtilityTerm(53, carsLessThanWorkersFlag); alternative.AddUtilityTerm(54, income0To25KFlag); alternative.AddUtilityTerm(131, escortPercentage); alternative.AddUtilityTerm(132, nonEscortPercentage); } else if (mode == Global.Settings.Modes.Bike) { double class1Dist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? ImpedanceRoster.GetValue("class1distance", mode, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0; double class2Dist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? ImpedanceRoster.GetValue("class2distance", mode, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0; // double worstDist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ? // ImpedanceRoster.GetValue("worstdistance", mode, Global.Settings.PathTypes.FullNetwork, // Global.Settings.VotGroups.Medium, tour.DestinationArrivalTime,originParcel, destinationParcel).Variable : 0; alternative.AddUtilityTerm(60, 1); alternative.AddUtilityTerm(61, maleFlag); alternative.AddUtilityTerm(63, ageBetween51And98Flag); alternative.AddUtilityTerm(67, noCarsInHouseholdFlag); //for calibration alternative.AddUtilityTerm(68, carsLessThanDriversFlag); //for calibration alternative.AddUtilityTerm(169, destinationParcel.MixedUse4Index1()); alternative.AddUtilityTerm(168, destinationParcel.TotalEmploymentDensity1()); alternative.AddUtilityTerm(167, destinationParcel.NetIntersectionDensity1()); alternative.AddUtilityTerm(166, originParcel.NetIntersectionDensity1()); alternative.AddUtilityTerm(165, originParcel.HouseholdDensity1()); alternative.AddUtilityTerm(164, originParcel.MixedUse4Index1()); alternative.AddUtilityTerm(162, (class1Dist > 0).ToFlag()); alternative.AddUtilityTerm(162, (class2Dist > 0).ToFlag()); // alternative.AddUtility(163, (worstDist > 0).ToFlag()); alternative.AddUtilityTerm(170, 1.0 * destinationParcel.MixedUse4Index1() + 0.00002 * destinationParcel.TotalEmploymentDensity1() + 0.001 * destinationParcel.NetIntersectionDensity1() + 0.001 * originParcel.NetIntersectionDensity1() + 0.0002 * originParcel.HouseholdDensity1() + 1.0 * originParcel.MixedUse4Index1()); //alternative.AddUtilityTerm(261, originParcel.PCA_DensityTerm_Buffer1()); //alternative.AddUtilityTerm(262, originParcel.PCA_WalkabilityTerm_Buffer1()); //alternative.AddUtilityTerm(263, originParcel.PCA_MixedUseTerm_Buffer1()); //alternative.AddUtilityTerm(264, originParcel.PCA_TransitAccessTerm_Buffer1()); //alternative.AddUtilityTerm(261, destinationParcel.PCA_DensityTerm_Buffer1()); //alternative.AddUtilityTerm(262, destinationParcel.PCA_WalkabilityTerm_Buffer1()); //alternative.AddUtilityTerm(263, destinationParcel.PCA_MixedUseTerm_Buffer1()); //alternative.AddUtilityTerm(264, destinationParcel.PCA_TransitAccessTerm_Buffer1()); //alternative.AddUtilityTerm(265, destinationParcel.PCA_DensityTerm_Buffer1()); //alternative.AddUtilityTerm(266, destinationParcel.PCA_WalkabilityTerm_Buffer1()); //alternative.AddUtilityTerm(267, destinationParcel.PCA_MixedUseTerm_Buffer1()); //alternative.AddUtilityTerm(268, destinationParcel.PCA_TransitAccessTerm_Buffer1()); } else if (mode == Global.Settings.Modes.Walk) { alternative.AddUtilityTerm(70, 1); //for calibration alternative.AddUtilityTerm(71, maleFlag); alternative.AddUtilityTerm(73, ageBetween51And98Flag); alternative.AddUtilityTerm(75, pathTypeModel.PathDistance * pathTypeModel.PathDistance); alternative.AddUtilityTerm(77, noCarsInHouseholdFlag); //for calibration alternative.AddUtilityTerm(78, carsLessThanDriversFlag); //for calibration alternative.AddUtilityTerm(179, destinationParcel.MixedUse4Index1()); alternative.AddUtilityTerm(178, destinationParcel.TotalEmploymentDensity1()); alternative.AddUtilityTerm(177, destinationParcel.NetIntersectionDensity1()); alternative.AddUtilityTerm(176, originParcel.NetIntersectionDensity1()); alternative.AddUtilityTerm(175, originParcel.HouseholdDensity1()); alternative.AddUtilityTerm(179, originParcel.MixedUse4Index1()); alternative.AddUtilityTerm(181, 1.0 * destinationParcel.MixedUse4Index1() + 0.00001 * destinationParcel.TotalEmploymentDensity1() + 0.001 * destinationParcel.NetIntersectionDensity1() + 0.001 * originParcel.NetIntersectionDensity1() + 0.0001 * originParcel.HouseholdDensity1() + 1.0 * originParcel.MixedUse4Index1()); //alternative.AddUtilityTerm(271, originParcel.PCA_DensityTerm_Buffer1()); //alternative.AddUtilityTerm(272, originParcel.PCA_WalkabilityTerm_Buffer1()); //alternative.AddUtilityTerm(273, originParcel.PCA_MixedUseTerm_Buffer1()); //alternative.AddUtilityTerm(274, originParcel.PCA_TransitAccessTerm_Buffer1()); //alternative.AddUtilityTerm(271, destinationParcel.PCA_DensityTerm_Buffer1()); //alternative.AddUtilityTerm(272, destinationParcel.PCA_WalkabilityTerm_Buffer1()); //alternative.AddUtilityTerm(273, destinationParcel.PCA_MixedUseTerm_Buffer1()); //alternative.AddUtilityTerm(274, destinationParcel.PCA_TransitAccessTerm_Buffer1()); //alternative.AddUtilityTerm(275, destinationParcel.PCA_DensityTerm_Buffer1()); //alternative.AddUtilityTerm(276, destinationParcel.PCA_WalkabilityTerm_Buffer1()); //alternative.AddUtilityTerm(277, destinationParcel.PCA_MixedUseTerm_Buffer1()); //alternative.AddUtilityTerm(278, destinationParcel.PCA_TransitAccessTerm_Buffer1()); } else if (mode == Global.Settings.Modes.PaidRideShare) { if (Global.Configuration.PaidRideshare_UseEstimatedInsteadOfAssertedCoefficients) { alternative.AddUtilityTerm(80, 1.0); alternative.AddUtilityTerm(81, noCarsInHouseholdFlag); //for calibration alternative.AddUtilityTerm(82, carsLessThanDriversFlag); //for calibration alternative.AddUtilityTerm(83, tour.Person.AgeIsBetween26And35.ToFlag()); alternative.AddUtilityTerm(83, tour.Person.AgeIsBetween18And25.ToFlag()); alternative.AddUtilityTerm(84, (tour.Person.Age >= 65).ToFlag()); //alternative.AddUtilityTerm(81, tour.Person.AgeIsBetween26And35.ToFlag()); alternative.AddUtilityTerm(85, originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2); alternative.AddUtilityTerm(86, destinationParcel.HouseholdsBuffer2 + destinationParcel.StudentsUniversityBuffer2 + destinationParcel.EmploymentTotalBuffer2); alternative.AddUtilityTerm(87, income0To25KFlag); alternative.AddUtilityTerm(88, incomeOver100Flag); } else { double modeConstant = Global.Configuration.AV_PaidRideShareModeUsesAVs ? Global.Configuration.AV_PaidRideShare_ModeConstant + Global.Configuration.AV_PaidRideShare_DensityCoefficient * Math.Min(originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2, (Global.Configuration.PaidRideShare_DensityMeasureCapValue > 0) ? Global.Configuration.PaidRideShare_DensityMeasureCapValue : 6000) + Global.Configuration.AV_PaidRideShare_AVOwnerCoefficient * (household.OwnsAutomatedVehicles > 0).ToFlag() : Global.Configuration.PaidRideShare_ModeConstant + Global.Configuration.PaidRideShare_DensityCoefficient * Math.Min(originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2, (Global.Configuration.PaidRideShare_DensityMeasureCapValue > 0) ? Global.Configuration.PaidRideShare_DensityMeasureCapValue : 6000); alternative.AddUtilityTerm(90, modeConstant); alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_Age26to35Coefficient * tour.Person.AgeIsBetween26And35.ToFlag()); alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_Age18to25Coefficient * tour.Person.AgeIsBetween18And25.ToFlag()); alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_AgeOver65Coefficient * (tour.Person.Age >= 65).ToFlag()); } } RegionSpecificCustomizations(alternative, tour, pathTypeModel.PathType, mode, destinationParcel); } }