private static TWrapper CreateWrapper(IPersonWrapper personWrapper, IPersonDayWrapper personDayWrapper, IParcelWrapper originParcel, IParcelWrapper destinationParcel, int destinationArrivalTime, int destinationDepartureTime, int destinationPurpose) { var type = typeof(TWrapper); var instance = Activator.CreateInstance(type, new TModel(), personWrapper, personDayWrapper, originParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, destinationPurpose); return((TWrapper)instance); }
public DayPattern(IPersonDayWrapper personDay) { Tours = new int[Global.Settings.Purposes.TotalPurposes]; WorkTours = Tours[Global.Settings.Purposes.Work] = personDay.WorkTours; SchoolTours = Tours[Global.Settings.Purposes.School] = personDay.SchoolTours; EscortTours = Tours[Global.Settings.Purposes.Escort] = personDay.EscortTours; PersonalBusinessTours = Tours[Global.Settings.Purposes.PersonalBusiness] = personDay.PersonalBusinessTours; ShoppingTours = Tours[Global.Settings.Purposes.Shopping] = personDay.ShoppingTours; MealTours = Tours[Global.Settings.Purposes.Meal] = personDay.MealTours; SocialTours = Tours[Global.Settings.Purposes.Social] = personDay.SocialTours; TotalTours = personDay.GetTotalTours(); Stops = new int[Global.Settings.Purposes.TotalPurposes]; WorkStops = Stops[Global.Settings.Purposes.Work] = personDay.WorkStops; SchoolStops = Stops[Global.Settings.Purposes.School] = personDay.SchoolStops; EscortStops = Stops[Global.Settings.Purposes.Escort] = personDay.EscortStops; PersonalBusinessStops = Stops[Global.Settings.Purposes.PersonalBusiness] = personDay.PersonalBusinessStops; ShoppingStops = Stops[Global.Settings.Purposes.Shopping] = personDay.ShoppingStops; MealStops = Stops[Global.Settings.Purposes.Meal] = personDay.MealStops; SocialStops = Stops[Global.Settings.Purposes.Social] = personDay.SocialStops; TotalStops = personDay.GetTotalStops(); _hashCode = ComputeHashCode(); }
private static TWrapper CreateWrapper(ITour tour, IPersonDayWrapper personDayWrapper, int purpose, bool suppressRandomVOT) { var type = typeof(TWrapper); var instance = Activator.CreateInstance(type, tour, personDayWrapper, purpose, suppressRandomVOT); return((TWrapper)instance); }
public TourWrapper(ITour tour, IPersonDayWrapper personDayWrapper, int purpose, bool suppressRandomVOT) { _tour = tour; _exporter = Global .ContainerDaySim .GetInstance <IPersistenceFactory <ITour> >() .Exporter; _tourCreator = Global .ContainerDaySim .GetInstance <IWrapperFactory <ITourCreator> >() .Creator; // relations properties Household = personDayWrapper.Household; Person = personDayWrapper.Person; PersonDay = personDayWrapper; Subtours = new List <ITourWrapper>(); SetParcelRelationships(tour); // flags/choice model/etc. properties SetValueOfTimeCoefficients(purpose, suppressRandomVOT); IsHomeBasedTour = true; TimeWindow = new TimeWindow(); }
public int Run(IPersonDayWrapper personDay, IHouseholdDayWrapper householdDay, int maxPurpose, int choice) { if (householdDay == null) { throw new ArgumentNullException("householdDay"); } householdDay.ResetRandom(949 + personDay.GetTotalCreatedTours()); if (Global.Configuration.IsInEstimationMode) { if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME) { return(choice); } } ChoiceProbabilityCalculator choiceProbabilityCalculator = _helpers[ParallelUtility.threadLocalAssignedIndex.Value].GetChoiceProbabilityCalculator(((personDay.Person.Id * 10 + personDay.Day) * 397) ^ personDay.GetTotalCreatedTours()); if (_helpers[ParallelUtility.threadLocalAssignedIndex.Value].ModelIsInEstimationMode) { RunModel(choiceProbabilityCalculator, personDay, householdDay, maxPurpose, choice); choiceProbabilityCalculator.WriteObservation(); } else { RunModel(choiceProbabilityCalculator, personDay, householdDay, maxPurpose); ChoiceProbabilityCalculator.Alternative chosenAlternative = choiceProbabilityCalculator.SimulateChoice(householdDay.Household.RandomUtility); choice = (int)chosenAlternative.Choice; } return(choice); }
public TourWrapper(ITour tour, IPersonWrapper personWrapper, IPersonDayWrapper personDayWrapper, IParcelWrapper originParcel, IParcelWrapper destinationParcel, int destinationArrivalTime, int destinationDepartureTime, int destinationPurpose) { _tour = tour; _exporter = Global .ContainerDaySim.GetInstance <IPersistenceFactory <ITour> >() .Exporter; _tourCreator = Global .ContainerDaySim .GetInstance <IWrapperFactory <ITourCreator> >() .Creator; // relations properties Household = personWrapper.Household; Person = personWrapper; PersonDay = personDayWrapper; OriginParcel = originParcel; DestinationParcel = destinationParcel; DestinationPurpose = destinationPurpose; DestinationArrivalTime = destinationArrivalTime; DestinationDepartureTime = destinationDepartureTime; DestinationPurpose = destinationPurpose; // flags/choice model/etc. properties SetValueOfTimeCoefficients(destinationPurpose, true); }
public void Run(IPersonDayWrapper personDay, IHouseholdDayWrapper householdDay) { if (personDay == null) { throw new ArgumentNullException("personDay"); } personDay.Person.ResetRandom(961); int choice = 0; if (Global.Configuration.IsInEstimationMode) { if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME) { return; } } ChoiceProbabilityCalculator choiceProbabilityCalculator = _helpers[ParallelUtility.threadLocalAssignedIndex.Value].GetChoiceProbabilityCalculator(personDay.Person.Id * 10 + personDay.Day); if (_helpers[ParallelUtility.threadLocalAssignedIndex.Value].ModelIsInEstimationMode) { choice = Math.Min(personDay.WorkStops, 1) + 2 * Math.Min(personDay.SchoolStops, 1); RunModel(choiceProbabilityCalculator, personDay, householdDay, choice); choiceProbabilityCalculator.WriteObservation(); } else if (Global.Configuration.TestEstimationModelInApplicationMode) { Global.Configuration.IsInEstimationMode = false; RunModel(choiceProbabilityCalculator, personDay, householdDay); int observedChoice = Math.Min(personDay.WorkStops, 1) + 2 * Math.Min(personDay.SchoolStops, 1); ChoiceProbabilityCalculator.Alternative simulatedChoice = choiceProbabilityCalculator.SimulateChoice(householdDay.Household.RandomUtility, personDay.Id, observedChoice); Global.Configuration.IsInEstimationMode = true; } else { RunModel(choiceProbabilityCalculator, personDay, householdDay); ChoiceProbabilityCalculator.Alternative chosenAlternative = choiceProbabilityCalculator.SimulateChoice(householdDay.Household.RandomUtility); choice = (int)chosenAlternative.Choice; if (choice == 1 || choice == 3) { personDay.WorkStops = 1; } if (choice == 2 || choice == 3) { personDay.SchoolStops = 1; } } }
public void Run(IPersonDayWrapper personDay, IHouseholdDayWrapper householdDay) { if (personDay == null) { throw new ArgumentNullException("personDay"); } personDay.Person.ResetRandom(904); if (Global.Configuration.IsInEstimationMode) { if (personDay.WorkAtHomeDuration >= 120 && personDay.Person.IsFullOrPartTimeWorker) { personDay.WorksAtHomeFlag = 1; } else { personDay.WorksAtHomeFlag = 0; } if (!_helpers[ParallelUtility.threadLocalAssignedIndex.Value].ModelIsInEstimationMode || !personDay.Person.IsFullOrPartTimeWorker) { return; } } ChoiceProbabilityCalculator choiceProbabilityCalculator = _helpers[ParallelUtility.threadLocalAssignedIndex.Value].GetChoiceProbabilityCalculator(personDay.Person.Id * 10 + personDay.Day); if (_helpers[ParallelUtility.threadLocalAssignedIndex.Value].ModelIsInEstimationMode) { if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME) { return; } RunModel(choiceProbabilityCalculator, personDay, householdDay, personDay.WorksAtHomeFlag); choiceProbabilityCalculator.WriteObservation(); } else { int choice; if (!personDay.Person.IsFullOrPartTimeWorker) { choice = 0; } else { RunModel(choiceProbabilityCalculator, personDay, householdDay); ChoiceProbabilityCalculator.Alternative chosenAlternative = choiceProbabilityCalculator.SimulateChoice(personDay.Household.RandomUtility); choice = (int)chosenAlternative.Choice; } personDay.WorksAtHomeFlag = choice; personDay.WorkAtHomeDuration = choice * 120; //default predicted duration for output } }
public static void ResetRandom(this IPersonDayWrapper personDay, int index) { if (personDay == null) { throw new ArgumentNullException("personDay"); } ResetRandom(personDay.Household.RandomUtility, personDay.Person.SeedValues, index, personDay.AttemptedSimulations, personDay.Day); }
// foreach (var tour in tours) { // tour.DestinationParcel = personDay.Person.UsualWorkParcel; // tour.DestinationParcelId = personDay.Person.UsualWorkParcelId; // tour.DestinationZoneKey = ChoiceModelFactory.ZoneKeys[personDay.Person.UsualWorkParcel.ZoneId]; // tour.DestinationAddressType = Global.Settings.AddressTypes.UsualWorkplace; // } // // tours.AddRange(CreateToursByPurpose(Global.Settings.Purposes.Work, personDay.WorkTours - personDay.UsualWorkplaceTours)); // tours.AddRange(CreateToursByPurpose(Global.Settings.Purposes.School, personDay.SchoolTours)); // // foreach (var tour in tours.Where(tour => tour.DestinationPurpose == Global.Settings.Purposes.School)) { // tour.DestinationParcel = personDay.Person.UsualSchoolParcel; // tour.DestinationParcelId = personDay.Person.UsualSchoolParcelId; // tour.DestinationZoneKey = ChoiceModelFactory.ZoneKeys[personDay.Person.UsualSchoolParcel.ZoneId]; // tour.DestinationAddressType = Global.Settings.AddressTypes.UsualSchool; // } // } public virtual void GetIndividualTourSimulatedData(IPersonDayWrapper personDay, List <ITourWrapper> tours) { tours.AddRange(CreateToursByPurpose(Global.Settings.Purposes.Escort, CreatedEscortTours - EscortFullHalfTours)); tours.AddRange(CreateToursByPurpose(Global.Settings.Purposes.PersonalBusiness, CreatedPersonalBusinessTours)); tours.AddRange(CreateToursByPurpose(Global.Settings.Purposes.Shopping, CreatedShoppingTours)); tours.AddRange(CreateToursByPurpose(Global.Settings.Purposes.Meal, CreatedMealTours)); tours.AddRange(CreateToursByPurpose(Global.Settings.Purposes.Social, CreatedSocialTours)); tours.AddRange(CreateToursByPurpose(Global.Settings.Purposes.Recreation, CreatedRecreationTours)); tours.AddRange(CreateToursByPurpose(Global.Settings.Purposes.Medical, CreatedMedicalTours)); }
public ChoiceProbabilityCalculator.Alternative RunNested(IPersonDayWrapper personDay, IParcelWrapper originParcel, IParcelWrapper destinationParcel, int destinationArrivalTime, int destinationDepartureTime, int householdCars) { if (personDay == null) { throw new ArgumentNullException("personDay"); } ITourWrapper tour = _creator.CreateWrapper(personDay.Person, personDay, originParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, Global.Settings.Purposes.Work); return(RunNested(tour, destinationParcel, householdCars, personDay.Person.GetTransitFareDiscountFraction())); }
public void Run(IPersonDayWrapper personDay) { if (personDay == null) { throw new ArgumentNullException("personDay"); } personDay.ResetRandom(5); if (Global.Configuration.IsInEstimationMode) { if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME) { return; } } ChoiceProbabilityCalculator choiceProbabilityCalculator = _helpers[ParallelUtility.threadLocalAssignedIndex.Value].GetChoiceProbabilityCalculator(personDay.Id); if (_helpers[ParallelUtility.threadLocalAssignedIndex.Value].ModelIsInEstimationMode) { RunModel(choiceProbabilityCalculator, personDay, new DayPattern(personDay)); choiceProbabilityCalculator.WriteObservation(); } else { if (personDay.Person.UsualWorkParcelId != Global.Settings.OutOfRegionParcelId && personDay.Person.UsualSchoolParcelId != Global.Settings.OutOfRegionParcelId) { RunModel(choiceProbabilityCalculator, personDay); ChoiceProbabilityCalculator.Alternative chosenAlternative = choiceProbabilityCalculator.SimulateChoice(personDay.Household.RandomUtility); DayPattern choice = (DayPattern)chosenAlternative.Choice; personDay.WorkTours = choice.WorkTours; personDay.SchoolTours = choice.SchoolTours; personDay.EscortTours = choice.EscortTours; personDay.PersonalBusinessTours = choice.PersonalBusinessTours; personDay.ShoppingTours = choice.ShoppingTours; personDay.MealTours = choice.MealTours; personDay.SocialTours = choice.SocialTours; personDay.WorkStops = choice.WorkStops; personDay.SchoolStops = choice.SchoolStops; personDay.EscortStops = choice.EscortStops; personDay.PersonalBusinessStops = choice.PersonalBusinessStops; personDay.ShoppingStops = choice.ShoppingStops; personDay.MealStops = choice.MealStops; personDay.SocialStops = choice.SocialStops; } } }
private static void RunTourModels(IPersonDayWrapper personDay, int batchNumber) { if (!Global.Configuration.ShouldRunTourModels) { return; } // creates or adds tours to a person's day based on application or estimation mode // tours are created by purpose personDay.SetTours(); foreach (var tour in personDay.Tours) { #if RELEASE try { #endif ChoiceModelFactory.TotalTimesTourModelSuiteRun[batchNumber]++; RunTourModelSuite(tour, batchNumber); if (!personDay.IsValid) { if (Global.Configuration.IsInEstimationMode && Global.Configuration.EstimationModel == "IntermediateStopLocationModel") { Global.PrintFile.WriteEstimationRecordExclusionMessage("ChoiceModelRunner", "RunTourModels", tour.Household.Id, tour.Person.Sequence, -1, tour.Sequence, -1, -1, tour.HalfTour1Trips + tour.HalfTour2Trips); } return; } ChoiceModelFactory.TotalTimesTourTripModelsRun[batchNumber]++; RunTourTripModels(tour, batchNumber); if (!personDay.IsValid) { return; } ChoiceModelFactory.TotalTimesTourSubtourModelsRun[batchNumber]++; RunSubtourModels(tour, batchNumber); if (!personDay.IsValid) { return; } #if RELEASE } catch (Exception e) { throw new TourModelException(string.Format("Error running tour models for {0}.", tour), e); } #endif } }
public static void SetEscortPercentages(IPersonDayWrapper personDay, out double escortPercentage, out double nonEscortPercentage, bool excludeWorkAndSchool = false) { if (personDay == null || personDay.HomeBasedTours == 0) { escortPercentage = 0; nonEscortPercentage = 0; } else { var totalTours = excludeWorkAndSchool ? personDay.GetTotalToursExcludingWorkAndSchool() : personDay.GetTotalTours(); var totalStops = excludeWorkAndSchool ? personDay.GetTotalStopsExcludingWorkAndSchool() : personDay.GetTotalStops(); var escortStopFlag = (personDay.EscortStops > 0).ToFlag(); escortPercentage = escortStopFlag / Math.Max(totalTours, 1.0); nonEscortPercentage = (totalStops - escortStopFlag) / Math.Max(totalTours, 1.0); } }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITourWrapper tour, int sampleSize, IParcelWrapper choice = null) { IHouseholdWrapper household = tour.Household; IPersonWrapper person = tour.Person; IPersonDayWrapper personDay = tour.PersonDay; // var totalAvailableMinutes = // tour.ParentTour == null // ? personDay.TimeWindow.TotalAvailableMinutes(1, Global.Settings.Times.MinutesInADay) // : tour.ParentTour.TimeWindow.TotalAvailableMinutes(1, Global.Settings.Times.MinutesInADay); int maxAvailableMinutes = tour.ParentTour == null ? personDay.TimeWindow.MaxAvailableMinutesAfter(121) : 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); int fastestAvailableTimeOfDay = tour.IsHomeBasedTour || tour.ParentTour == null ? 1 : tour.ParentTour.DestinationArrivalTime + (tour.ParentTour.DestinationDepartureTime - tour.ParentTour.DestinationArrivalTime) / 2; int tourCategory = tour.GetTourCategory(); int primaryFlag = ChoiceModelUtility.GetPrimaryFlag(tourCategory); int secondaryFlag = ChoiceModelUtility.GetSecondaryFlag(tourCategory); ChoiceModelUtility.DrawRandomTourTimePeriods(tour, tourCategory); int segment = Global.ContainerDaySim.GetInstance <SamplingWeightsSettingsFactory>().SamplingWeightsSettings.GetTourDestinationSegment(tour.DestinationPurpose, tour.IsHomeBasedTour ? Global.Settings.TourPriorities.HomeBasedTour : Global.Settings.TourPriorities.WorkBasedTour, Global.Settings.Modes.Sov, person.PersonType); IParcelWrapper excludedParcel = person.UsualWorkParcel == null || person.UsualWorkParcelId == household.ResidenceParcelId || tour.DestinationPurpose != Global.Settings.Purposes.Work || tour.GetTourCategory() == Global.Settings.TourCategories.WorkBased ? null : person.UsualWorkParcel; DestinationSampler destinationSampler = new DestinationSampler(choiceProbabilityCalculator, segment, sampleSize, choice, tour.OriginParcel, excludedParcel, excludedParcel); TourDestinationUtilities tourDestinationUtilities = new TourDestinationUtilities(tour, sampleSize, primaryFlag, secondaryFlag, fastestAvailableTimeOfDay, maxAvailableMinutes); destinationSampler.SampleTourDestinations(tourDestinationUtilities); }
public override void GetMandatoryTourSimulatedData(IPersonDayWrapper personDay, List <ITourWrapper> tours) { tours.AddRange(CreateToursByPurpose(Global.Settings.Purposes.Work, personDay.UsualWorkplaceTours)); foreach (var tour in tours) { tour.DestinationParcel = personDay.Person.UsualWorkParcel; tour.DestinationParcelId = personDay.Person.UsualWorkParcelId; tour.DestinationZoneKey = ChoiceModelFactory.ZoneKeys[personDay.Person.UsualWorkParcel.ZoneId]; tour.DestinationAddressType = Global.Settings.AddressTypes.UsualWorkplace; } tours.AddRange(CreateToursByPurpose(Global.Settings.Purposes.Business, ((PersonDayWrapper)personDay).BusinessTours)); tours.AddRange(CreateToursByPurpose(Global.Settings.Purposes.School, personDay.SchoolTours)); foreach (var tour in tours.Where(tour => tour.DestinationPurpose == Global.Settings.Purposes.School)) { tour.DestinationParcel = personDay.Person.UsualSchoolParcel; tour.DestinationParcelId = personDay.Person.UsualSchoolParcelId; tour.DestinationZoneKey = ChoiceModelFactory.ZoneKeys[personDay.Person.UsualSchoolParcel.ZoneId]; tour.DestinationAddressType = Global.Settings.AddressTypes.UsualSchool; } }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITourWrapper tour, int nCallsForTour, int choice = Constants.DEFAULT_VALUE) { IPersonWrapper person = tour.Person; IPersonDayWrapper personDay = tour.PersonDay; // var foodRetailServiceMedicalQtrMileLog = tour.DestinationParcel.FoodRetailServiceMedicalQtrMileLogBuffer1(); // var mixedUseIndex = tour.DestinationParcel.MixedUse4Index1(); double k8HighSchoolQtrMileLog = tour.DestinationParcel.K8HighSchoolQtrMileLogBuffer1(); int carOwnership = person.GetCarOwnershipSegment(); int noCarsFlag = FlagUtility.GetNoCarsFlag(carOwnership); int carCompetitionFlag = FlagUtility.GetCarCompetitionFlag(carOwnership); // var notUsualWorkParcelFlag = tour.DestinationParcel.NotUsualWorkParcelFlag(person.UsualWorkParcelId); int votALSegment = tour.GetVotALSegment(); int workTaSegment = tour.DestinationParcel.TransitAccessSegment(); double workAggregateLogsum = Global.AggregateLogsums[tour.DestinationParcel.ZoneId] [Global.Settings.Purposes.WorkBased][carOwnership][votALSegment][workTaSegment]; // NONE_OR_HOME ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.NoneOrHome, true, choice == Global.Settings.Purposes.NoneOrHome); alternative.Choice = Global.Settings.Purposes.NoneOrHome; alternative.AddUtilityTerm(15, (nCallsForTour > 1).ToFlag()); alternative.AddUtilityTerm(16, Math.Log(personDay.HomeBasedTours)); alternative.AddUtilityTerm(18, personDay.TwoOrMoreWorkToursExist().ToFlag()); // alternative.AddUtility(19, notUsualWorkParcelFlag); alternative.AddUtilityTerm(22, noCarsFlag); alternative.AddUtilityTerm(23, carCompetitionFlag); alternative.AddUtilityTerm(32, workAggregateLogsum); // alternative.AddUtility(32, mixedUseIndex); alternative.AddNestedAlternative(11, 0, 50); // WORK alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Work, personDay.WorkStops > 0, choice == Global.Settings.Purposes.Work); alternative.Choice = Global.Settings.Purposes.Work; alternative.AddUtilityTerm(1, 1); alternative.AddNestedAlternative(12, 1, 50); // SCHOOL alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.School, personDay.SchoolStops > 0, choice == Global.Settings.Purposes.School); alternative.Choice = Global.Settings.Purposes.School; alternative.AddUtilityTerm(3, 1); alternative.AddNestedAlternative(12, 1, 50); // ESCORT alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Escort, personDay.EscortStops > 0, choice == Global.Settings.Purposes.Escort); alternative.Choice = Global.Settings.Purposes.Escort; alternative.AddUtilityTerm(4, 1); alternative.AddUtilityTerm(39, k8HighSchoolQtrMileLog); alternative.AddNestedAlternative(12, 1, 50); // PERSONAL_BUSINESS alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.PersonalBusiness, personDay.PersonalBusinessStops > 0, choice == Global.Settings.Purposes.PersonalBusiness); alternative.Choice = Global.Settings.Purposes.PersonalBusiness; alternative.AddUtilityTerm(6, 1); alternative.AddNestedAlternative(12, 1, 50); // SHOPPING alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Shopping, personDay.ShoppingStops > 0, choice == Global.Settings.Purposes.Shopping); alternative.Choice = Global.Settings.Purposes.Shopping; alternative.AddUtilityTerm(8, 1); alternative.AddNestedAlternative(12, 1, 50); // MEAL alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Meal, personDay.MealStops > 0, choice == Global.Settings.Purposes.Meal); alternative.Choice = Global.Settings.Purposes.Meal; alternative.AddUtilityTerm(10, 1); alternative.AddNestedAlternative(12, 1, 50); // SOCIAL alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Social, personDay.SocialStops > 0, choice == Global.Settings.Purposes.Social); alternative.Choice = Global.Settings.Purposes.Social; alternative.AddUtilityTerm(13, 1); alternative.AddNestedAlternative(12, 1, 50); }
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, IPersonDayWrapper personDay, IHouseholdDayWrapper householdDay, int choice = Constants.DEFAULT_VALUE) { IHouseholdWrapper household = personDay.Household; IPersonWrapper person = personDay.Person; IEnumerable <PersonDayWrapper> orderedPersonDays = householdDay.PersonDays.OrderBy(p => p.GetJointTourParticipationPriority()).ToList().Cast <PersonDayWrapper>(); int countMandatory = (from personDayHH in orderedPersonDays where personDayHH.PatternType == 1 select personDayHH.PatternType).Count(); int countNonMandatory = (from personDayHH in orderedPersonDays where personDayHH.PatternType == 2 select personDayHH.PatternType).Count(); int countAtHome = (from personDayHH in orderedPersonDays where personDayHH.PatternType == 3 select personDayHH.PatternType).Count(); int carOwnership = household.VehiclesAvailable == 0 ? Global.Settings.CarOwnerships.NoCars : household.VehiclesAvailable < household.HouseholdTotals.DrivingAgeMembers ? Global.Settings.CarOwnerships.LtOneCarPerAdult : Global.Settings.CarOwnerships.OneOrMoreCarsPerAdult; int noCarsFlag = FlagUtility.GetNoCarsFlag(carOwnership); int carCompetitionFlag = FlagUtility.GetCarCompetitionFlag(carOwnership); double workTourLogsum = 0; double schoolPclUniStu = 0; double schoolPclStudents = 0; int noUsualWorkZone = 1; if (personDay.Person.UsualWorkParcelId != Constants.DEFAULT_VALUE && personDay.Person.UsualWorkParcelId != Global.Settings.OutOfRegionParcelId) { if (personDay.Person.UsualDeparturePeriodFromWork != Constants.DEFAULT_VALUE && personDay.Person.UsualArrivalPeriodToWork != Constants.DEFAULT_VALUE) { ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().RunNested(personDay, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualWorkParcel, (int)personDay.Person.UsualArrivalPeriodToWork, (int)personDay.Person.UsualDeparturePeriodFromWork, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers); workTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } else { ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().RunNested(personDay, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualWorkParcel, Global.Settings.Times.EightAM, Global.Settings.Times.FivePM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers); workTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } noUsualWorkZone = 0; } if (personDay.Person.UsualSchoolParcelId != 0 && personDay.Person.UsualSchoolParcelId != -1 && personDay.Person.UsualSchoolParcelId != Global.Settings.OutOfRegionParcelId) { schoolPclUniStu = Math.Log(1 + (personDay.Person.UsualSchoolParcel.StudentsUniversityBuffer2)) / 10; ChoiceProbabilityCalculator.Alternative schoolNestedAlternative = Global.ChoiceModelSession.Get <SchoolTourModeTimeModel>().RunNested(personDay, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualSchoolParcel, Global.Settings.Times.EightAM, Global.Settings.Times.TwoPM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers); schoolPclStudents = Math.Log(1 + (personDay.Person.UsualSchoolParcel.GetStudentsK12())) / 10; } // No mandatory stops ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(0, true, choice == 0); alternative.Choice = 0; // Work stop(s) alternative = choiceProbabilityCalculator.GetAlternative(1, personDay.Person.IsWorker, choice == 1); alternative.Choice = 1; alternative.AddUtilityTerm(21, 1); alternative.AddUtilityTerm(22, (personDay.WorkTours + personDay.SchoolTours > 1).ToFlag()); alternative.AddUtilityTerm(24, workTourLogsum); alternative.AddUtilityTerm(26, household.Has0To25KIncome.ToFlag()); alternative.AddUtilityTerm(27, (person.Age < 30).ToFlag()); alternative.AddUtilityTerm(29, noUsualWorkZone); alternative.AddUtilityTerm(30, countMandatory); alternative.AddUtilityTerm(31, countAtHome); alternative.AddUtilityTerm(33, person.IsPartTimeWorker.ToFlag()); alternative.AddUtilityTerm(34, person.IsUniversityStudent.ToFlag()); alternative.AddUtilityTerm(35, household.Has100KPlusIncome.ToFlag()); // School stop(s) alternative = choiceProbabilityCalculator.GetAlternative(2, personDay.Person.IsStudent, choice == 2); alternative.Choice = 2; alternative.AddUtilityTerm(41, 1); alternative.AddUtilityTerm(42, (personDay.SchoolTours == 0).ToFlag()); alternative.AddUtilityTerm(45, person.IsChildUnder5.ToFlag()); alternative.AddUtilityTerm(46, person.IsUniversityStudent.ToFlag()); alternative.AddUtilityTerm(49, (household.HouseholdTotals.AllWorkers >= 2).ToFlag()); alternative.AddUtilityTerm(50, carCompetitionFlag + noCarsFlag); alternative.AddUtilityTerm(53, (household.HouseholdTotals.ChildrenUnder16 > 2).ToFlag()); alternative.AddUtilityTerm(54, schoolPclStudents); alternative.AddUtilityTerm(55, schoolPclUniStu); alternative.AddUtilityTerm(56, (person.Age > 25).ToFlag()); alternative.AddUtilityTerm(59, personDay.Person.Household.ResidenceParcel.C34RatioBuffer1()); // Work and school stops alternative = choiceProbabilityCalculator.GetAlternative(3, (personDay.Person.IsWorker && personDay.Person.IsStudent), choice == 3); alternative.Choice = 3; alternative.AddUtilityTerm(61, 1); }
public int Run(IPersonDayWrapper personDay, IHouseholdDayWrapper householdDay, int nCallsForTour, int[] simulatedMandatoryTours) { return(Run(personDay, householdDay, nCallsForTour, simulatedMandatoryTours, Global.Settings.Purposes.NoneOrHome)); }
public int Run(IPersonDayWrapper personDay, IHouseholdDayWrapper householdDay, int nCallsForTour, int[] simulatedMandatoryTours, int choice) { // to know what the last choice was for a person on the previous step if (personDay == null) { throw new ArgumentNullException("personDay"); } personDay.Person.ResetRandom(904 + nCallsForTour); if (Global.Configuration.IsInEstimationMode) { if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME) { return(choice); } } var choiceProbabilityCalculator = _helpers[ParallelUtility.threadLocalAssignedIndex.Value].GetChoiceProbabilityCalculator(((personDay.Person.Id * 10 + personDay.Day) * 397) ^ nCallsForTour); if (_helpers[ParallelUtility.threadLocalAssignedIndex.Value].ModelIsInEstimationMode) { RunModel(choiceProbabilityCalculator, personDay, householdDay, nCallsForTour, simulatedMandatoryTours, choice); choiceProbabilityCalculator.WriteObservation(); } else if (Global.Configuration.TestEstimationModelInApplicationMode) { Global.Configuration.IsInEstimationMode = false; RunModel(choiceProbabilityCalculator, personDay, householdDay, nCallsForTour, simulatedMandatoryTours); var observedChoice = choice; var simulatedChoice = choiceProbabilityCalculator.SimulateChoice(personDay.Household.RandomUtility, personDay.Id, choice); Global.Configuration.IsInEstimationMode = true; } // else if (Global.Configuration.TestEstimationModelInApplicationMode==true){ // Global.Configuration.IsInEstimationMode = false; // if (householdDay.Household.Id == 2015) { // bool testbreak = true; // } // RunModel(choiceProbabilityCalculator, personDay, householdDay, nCallsForTour, simulatedMandatoryTours); // need to determine the choice on this particular simulated tour // int[] totalMandatoryTours = new int[4]; // totalMandatoryTours[1] = personDay.UsualWorkplaceTours; // totalMandatoryTours[2] = personDay.WorkTours - totalMandatoryTours[1]; // totalMandatoryTours[3] = personDay.SchoolTours; // totalMandatoryTours[0] = totalMandatoryTours[1] + totalMandatoryTours[2] + totalMandatoryTours[3]; // if (personDay.UsualWorkplaceTours + personDay.SchoolTours > 0) { // personDay.HasMandatoryTourToUsualLocation = true; // } //using nCallsForTour - 1 will give the choice // if (nCallsForTour - 1 < totalMandatoryTours[1]) { choice = 1; } // else if (nCallsForTour - 1 < totalMandatoryTours[1] + totalMandatoryTours[2]) { choice = 2; } // else if (nCallsForTour - 1 < totalMandatoryTours[0]) { choice = 3; } // else { choice = 0; } // var observedChoice = choice ; // var simulatedChoice =choiceProbabilityCalculator.SimulateChoice(personDay.Household.RandomUtility, personDay.Id, observedChoice); // int tourPurpose =0; // if ( simulatedChoice!= null) // { // tourPurpose = (int) simulatedChoice.Choice; // } // choice = tourPurpose; // Global.Configuration.IsInEstimationMode = true; // } else { if (householdDay.Household.Id == 2015) { bool testbreak = true; } RunModel(choiceProbabilityCalculator, personDay, householdDay, nCallsForTour, simulatedMandatoryTours); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(personDay.Household.RandomUtility); int tourPurpose = (int)chosenAlternative.Choice; if (tourPurpose == 1) { personDay.UsualWorkplaceTours++; personDay.WorkTours++; } else if (tourPurpose == 2) { personDay.WorkTours++; } else if (tourPurpose == 3) { personDay.SchoolTours++; } choice = tourPurpose; } return(choice); }
public TourWrapper(ITour tour, IPersonWrapper personWrapper, IPersonDayWrapper personDayWrapper, IParcelWrapper originParcel, IParcelWrapper destinationParcel, int destinationArrivalTime, int destinationDepartureTime, int destinationPurpose) : base(tour, personWrapper, personDayWrapper, originParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, destinationPurpose) { _tour = (ILDTour)tour; }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, IPersonDayWrapper personDay, IHouseholdDayWrapper householdDay, int nCallsForTour, int[] simulatedMandatoryTours, int choice = Constants.DEFAULT_VALUE) { var household = personDay.Household; IEnumerable <PersonDayWrapper> orderedPersonDays = householdDay.PersonDays.OrderBy(p => p.GetJointTourParticipationPriority()).ToList().Cast <PersonDayWrapper>(); var carOwnership = household.VehiclesAvailable == 0 ? Global.Settings.CarOwnerships.NoCars : household.VehiclesAvailable < household.HouseholdTotals.DrivingAgeMembers ? Global.Settings.CarOwnerships.LtOneCarPerAdult : Global.Settings.CarOwnerships.OneOrMoreCarsPerAdult; var noCarsFlag = FlagUtility.GetNoCarsFlag(carOwnership); var carCompetitionFlag = FlagUtility.GetCarCompetitionFlag(carOwnership); var votALSegment = household.GetVotALSegment(); var transitAccessSegment = household.ResidenceParcel.TransitAccessSegment(); Double workTourLogsum = 0; Double schoolTourLogsum = 0; Double schoolPclUniStu = 0; Double schoolPclStudents = 0; Double schoolIntrDens = 0; Double workPclWrkrs = 0; Double workIntrDens = 0; int noUsualWorkZone = 1; if (personDay.Person.UsualWorkParcelId != Constants.DEFAULT_VALUE && personDay.Person.UsualWorkParcelId != Global.Settings.OutOfRegionParcelId) { if (personDay.Person.UsualDeparturePeriodFromWork != Constants.DEFAULT_VALUE && personDay.Person.UsualArrivalPeriodToWork != Constants.DEFAULT_VALUE) { var nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().RunNested(personDay, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualWorkParcel, (int)personDay.Person.UsualArrivalPeriodToWork, (int)personDay.Person.UsualDeparturePeriodFromWork, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers); workTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); workPclWrkrs = Math.Log(1 + (personDay.Person.UsualWorkParcel.EmploymentTotalBuffer2)) / 10; workIntrDens = Math.Log(1 + personDay.Person.UsualWorkParcel.C34RatioBuffer1()); } else { var nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().RunNested(personDay, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualWorkParcel, Global.Settings.Times.EightAM, Global.Settings.Times.FivePM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers); workTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } noUsualWorkZone = 0; } if (personDay.Person.UsualSchoolParcelId != 0 && personDay.Person.UsualSchoolParcelId != -1 && personDay.Person.UsualSchoolParcelId != Global.Settings.OutOfRegionParcelId) { schoolPclUniStu = Math.Log(1 + (personDay.Person.UsualSchoolParcel.StudentsUniversityBuffer2)) / 10; var schoolNestedAlternative = Global.ChoiceModelSession.Get <SchoolTourModeTimeModel>().RunNested(personDay, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualSchoolParcel, Global.Settings.Times.EightAM, Global.Settings.Times.TwoPM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers); schoolTourLogsum = schoolNestedAlternative == null ? 0 : schoolNestedAlternative.ComputeLogsum(); } int countNonMandatory = (from personDayHH in orderedPersonDays where personDayHH.PatternType == 2 select personDayHH.PatternType).Count(); bool schoolAvailableFlag = true; if (!personDay.Person.IsStudent || (!Global.Configuration.IsInEstimationMode && personDay.Person.UsualSchoolParcel == null)) { schoolAvailableFlag = false; } // NONE_OR_HOME var alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.NoneOrHome, nCallsForTour > 1, choice == Global.Settings.Purposes.NoneOrHome); alternative.Choice = Global.Settings.Purposes.NoneOrHome; alternative.AddUtilityTerm(3, (nCallsForTour > 2).ToFlag()); // USUAL WORK alternative = choiceProbabilityCalculator.GetAlternative(1, (personDay.Person.UsualWorkParcelId > 0 && simulatedMandatoryTours[2] == 0 && simulatedMandatoryTours[3] == 0), choice == 1); alternative.Choice = 1; alternative.AddUtilityTerm(21, 1); alternative.AddUtilityTerm(23, workTourLogsum); alternative.AddUtilityTerm(25, (personDay.Person.IsPartTimeWorker).ToFlag()); alternative.AddUtilityTerm(26, (personDay.Person.IsUniversityStudent).ToFlag()); alternative.AddUtilityTerm(28, (personDay.Person.Household.Has100KPlusIncome).ToFlag()); alternative.AddUtilityTerm(29, personDay.Person.Household.ResidenceParcel.MixedUse2Index1()); alternative.AddUtilityTerm(30, (personDay.Person.Age <= 30).ToFlag()); alternative.AddUtilityTerm(31, workPclWrkrs); alternative.AddUtilityTerm(32, ((simulatedMandatoryTours[1] > 0).ToFlag())); alternative.AddUtilityTerm(33, workIntrDens); alternative.AddUtilityTerm(36, (personDay.WorksAtHomeFlag)); alternative.AddUtilityTerm(38, (personDay.Person.Household.ResidenceParcel.GetDistanceToTransit() > 1).ToFlag()); // OTHER WORK alternative = choiceProbabilityCalculator.GetAlternative(2, (personDay.Person.IsWorker && simulatedMandatoryTours[3] == 0), choice == 2); alternative.Choice = 2; alternative.AddUtilityTerm(41, 1); alternative.AddUtilityTerm(42, (personDay.Person.IsPartTimeWorker).ToFlag()); alternative.AddUtilityTerm(43, (personDay.Person.IsUniversityStudent).ToFlag()); alternative.AddUtilityTerm(45, personDay.Person.Household.ResidenceParcel.MixedUse2Index1()); alternative.AddUtilityTerm(47, (personDay.Person.Age <= 30).ToFlag()); alternative.AddUtilityTerm(48, noUsualWorkZone); alternative.AddUtilityTerm(49, workIntrDens); alternative.AddUtilityTerm(50, workPclWrkrs); alternative.AddUtilityTerm(51, countNonMandatory); alternative.AddUtilityTerm(52, ((simulatedMandatoryTours[2] > 0).ToFlag())); alternative.AddUtilityTerm(53, (household.HouseholdTotals.AllWorkers == 1).ToFlag()); alternative.AddUtilityTerm(55, noCarsFlag + carCompetitionFlag); alternative.AddUtilityTerm(56, (personDay.Person.Household.ResidenceParcel.GetDistanceToTransit() > 1).ToFlag()); alternative.AddUtilityTerm(57, (personDay.Person.Household.Has0To25KIncome).ToFlag()); // SCHOOL alternative = choiceProbabilityCalculator.GetAlternative(3, schoolAvailableFlag, choice == 3); alternative.Choice = 3; alternative.AddUtilityTerm(61, 1); alternative.AddUtilityTerm(62, schoolTourLogsum); alternative.AddUtilityTerm(63, noCarsFlag + carCompetitionFlag); alternative.AddUtilityTerm(64, personDay.Person.Household.ResidenceParcel.MixedUse2Index1()); alternative.AddUtilityTerm(65, (personDay.Person.IsChildUnder5).ToFlag()); alternative.AddUtilityTerm(66, (personDay.Person.IsUniversityStudent).ToFlag()); alternative.AddUtilityTerm(67, (personDay.Person.IsDrivingAgeStudent).ToFlag()); alternative.AddUtilityTerm(68, schoolPclUniStu); alternative.AddUtilityTerm(69, schoolPclStudents); alternative.AddUtilityTerm(71, ((simulatedMandatoryTours[3] > 0).ToFlag())); alternative.AddUtilityTerm(72, schoolIntrDens); alternative.AddUtilityTerm(73, (personDay.Person.Age > 25).ToFlag()); alternative.AddUtilityTerm(74, (personDay.Person.Household.ResidenceParcel.GetDistanceToTransit() > 1).ToFlag()); }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, IPersonDayWrapper personDay, DayPattern choice = null) { IHouseholdWrapper household = personDay.Household; IParcelWrapper residenceParcel = household.ResidenceParcel; IPersonWrapper person = personDay.Person; int carsPerDriver = household.GetCarsPerDriver(); double mixedDensity = residenceParcel.MixedUse3Index2(); double intersectionDensity = residenceParcel.IntersectionDensity34Minus1Buffer2(); double[] purposeLogsums = new double[Global.Settings.Purposes.TotalPurposes]; double[] atUsualLogsums = new double[3]; int carOwnership = person.GetCarOwnershipSegment(); int votSegment = person.Household.GetVotALSegment(); int transitAccess = residenceParcel.TransitAccessSegment(); if (person.UsualWorkParcel == null || person.UsualWorkParcelId == household.ResidenceParcelId) { purposeLogsums[Global.Settings.Purposes.Work] = 0; } else { int destinationArrivalTime = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.WorkTourModeModel); int destinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.WorkTourModeModel); ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeModel>().RunNested(personDay, residenceParcel, person.UsualWorkParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable); purposeLogsums[Global.Settings.Purposes.Work] = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); atUsualLogsums[Global.Settings.Purposes.Work] = Global.AggregateLogsums[person.UsualWorkParcel.ZoneId][Global.Settings.Purposes.HomeBasedComposite][carOwnership][votSegment][person.UsualWorkParcel.TransitAccessSegment()]; } if (person.UsualSchoolParcel == null || person.UsualSchoolParcelId == household.ResidenceParcelId) { purposeLogsums[Global.Settings.Purposes.School] = 0; } else { int destinationArrivalTime = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.SchoolTourModeModel); int destinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.SchoolTourModeModel); ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <SchoolTourModeModel>().RunNested(personDay, residenceParcel, person.UsualSchoolParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable); purposeLogsums[Global.Settings.Purposes.School] = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); atUsualLogsums[Global.Settings.Purposes.School] = Global.AggregateLogsums[person.UsualSchoolParcel.ZoneId][Global.Settings.Purposes.HomeBasedComposite][carOwnership][votSegment][person.UsualSchoolParcel.TransitAccessSegment()]; } double compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][carOwnership][votSegment][transitAccess]; purposeLogsums[Global.Settings.Purposes.Escort] = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.Escort][carOwnership][votSegment][transitAccess]; purposeLogsums[Global.Settings.Purposes.PersonalBusiness] = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.PersonalBusiness][carOwnership][votSegment][transitAccess]; purposeLogsums[Global.Settings.Purposes.Shopping] = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.Shopping][carOwnership][votSegment][transitAccess]; purposeLogsums[Global.Settings.Purposes.Meal] = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.Meal][carOwnership][votSegment][transitAccess]; purposeLogsums[Global.Settings.Purposes.Social] = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.Social][carOwnership][votSegment][transitAccess]; purposeLogsums[Global.Settings.Purposes.Recreation] = compositeLogsum; purposeLogsums[Global.Settings.Purposes.Medical] = compositeLogsum; for (int xPurpose = Global.Settings.Purposes.Work; xPurpose <= Global.Settings.Purposes.Social + 10; xPurpose++) { // extra components 1-5 are for 2,3,4,5,6 tour purposes // extra components 6-10 are for 2,3,4,5,6 stop puroposes // recode purpose to match coefficients int purpose = xPurpose <= Global.Settings.Purposes.Social ? xPurpose : xPurpose <= Global.Settings.Purposes.Social + 5 ? Global.Settings.Purposes.Social + 1 : Global.Settings.Purposes.Social + 2; // get correct multiplier on coefficients. double xMultiplier = xPurpose <= Global.Settings.Purposes.Social ? 1.0 : xPurpose <= Global.Settings.Purposes.Social + 5 ? Math.Log(xPurpose - Global.Settings.Purposes.Social + 1) : Math.Log(xPurpose - Global.Settings.Purposes.Social - 5 + 1); choiceProbabilityCalculator.CreateUtilityComponent(xPurpose); ChoiceProbabilityCalculator.Component component = choiceProbabilityCalculator.GetUtilityComponent(xPurpose); component.AddUtilityTerm(100 * purpose + 51, xMultiplier * person.IsFulltimeWorker.ToFlag()); component.AddUtilityTerm(100 * purpose + 2, xMultiplier * person.IsPartTimeWorker.ToFlag()); component.AddUtilityTerm(100 * purpose + 3, xMultiplier * person.IsRetiredAdult.ToFlag()); component.AddUtilityTerm(100 * purpose + 4, xMultiplier * person.IsNonworkingAdult.ToFlag()); component.AddUtilityTerm(100 * purpose + 5, xMultiplier * person.IsUniversityStudent.ToFlag()); component.AddUtilityTerm(100 * purpose + 6, xMultiplier * person.IsDrivingAgeStudent.ToFlag()); component.AddUtilityTerm(100 * purpose + 7, xMultiplier * person.IsChildAge5Through15.ToFlag()); component.AddUtilityTerm(100 * purpose + 8, xMultiplier * person.IsChildUnder5.ToFlag()); component.AddUtilityTerm(100 * purpose + 9, xMultiplier * household.Has0To25KIncome.ToFlag()); component.AddUtilityTerm(100 * purpose + 10, xMultiplier * household.Has25To45KIncome.ToFlag()); component.AddUtilityTerm(100 * purpose + 11, xMultiplier * household.Has75KPlusIncome.ToFlag()); component.AddUtilityTerm(100 * purpose + 12, xMultiplier * carsPerDriver); component.AddUtilityTerm(100 * purpose + 13, xMultiplier * person.IsOnlyAdult().ToFlag()); component.AddUtilityTerm(100 * purpose + 14, xMultiplier * person.IsOnlyFullOrPartTimeWorker().ToFlag()); component.AddUtilityTerm(100 * purpose + 15, xMultiplier * 0); component.AddUtilityTerm(100 * purpose + 16, xMultiplier * person.IsFemale.ToFlag() * person.IsAdult.ToFlag() * (!household.HasChildrenUnder16).ToFlag()); component.AddUtilityTerm(100 * purpose + 17, xMultiplier * person.IsFemale.ToFlag() * person.IsAdult.ToFlag() * household.HasChildrenUnder5.ToFlag()); component.AddUtilityTerm(100 * purpose + 18, xMultiplier * person.IsFemale.ToFlag() * person.IsAdult.ToFlag() * household.HasChildrenAge5Through15.ToFlag()); component.AddUtilityTerm(100 * purpose + 19, xMultiplier * person.IsMale.ToFlag() * person.IsAdult.ToFlag() * household.HasChildrenUnder5.ToFlag()); component.AddUtilityTerm(100 * purpose + 20, xMultiplier * person.IsMale.ToFlag() * person.IsAdult.ToFlag() * household.HasChildrenAge5Through15.ToFlag()); component.AddUtilityTerm(100 * purpose + 21, xMultiplier * person.AgeIsBetween18And25.ToFlag()); component.AddUtilityTerm(100 * purpose + 22, xMultiplier * person.AgeIsBetween26And35.ToFlag()); component.AddUtilityTerm(100 * purpose + 23, xMultiplier * person.AgeIsBetween51And65.ToFlag()); component.AddUtilityTerm(100 * purpose + 24, xMultiplier * person.WorksAtHome().ToFlag()); component.AddUtilityTerm(100 * purpose + 25, xMultiplier * mixedDensity); component.AddUtilityTerm(100 * purpose + 26, xMultiplier * intersectionDensity); component.AddUtilityTerm(100 * purpose + 27, xMultiplier * purposeLogsums[purpose]); component.AddUtilityTerm(100 * purpose + 28, xMultiplier * person.TransitPassOwnership); } // tour utility int tourComponentIndex = Global.Settings.Purposes.Social + 11; choiceProbabilityCalculator.CreateUtilityComponent(tourComponentIndex); ChoiceProbabilityCalculator.Component tourComponent = choiceProbabilityCalculator.GetUtilityComponent(tourComponentIndex); tourComponent.AddUtilityTerm(1401, carsPerDriver); tourComponent.AddUtilityTerm(1402, person.WorksAtHome().ToFlag()); tourComponent.AddUtilityTerm(1403, mixedDensity); tourComponent.AddUtilityTerm(1404, mixedDensity * person.IsChildAge5Through15.ToFlag()); tourComponent.AddUtilityTerm(1405, compositeLogsum); tourComponent.AddUtilityTerm(1406, person.TransitPassOwnership); // stop utility int stopComponentIndex = Global.Settings.Purposes.Social + 12; choiceProbabilityCalculator.CreateUtilityComponent(stopComponentIndex); ChoiceProbabilityCalculator.Component stopComponent = choiceProbabilityCalculator.GetUtilityComponent(stopComponentIndex); stopComponent.AddUtilityTerm(1411, carsPerDriver); stopComponent.AddUtilityTerm(1412, person.WorksAtHome().ToFlag()); stopComponent.AddUtilityTerm(1413, mixedDensity); stopComponent.AddUtilityTerm(1414, mixedDensity * person.IsChildAge5Through15.ToFlag()); stopComponent.AddUtilityTerm(1415, compositeLogsum); stopComponent.AddUtilityTerm(1416, person.TransitPassOwnership); for (int alternativeIndex = 0; alternativeIndex < TOTAL_ALTERNATIVES; alternativeIndex++) { DayPattern dayPattern = _dayPatterns[alternativeIndex]; bool available = // work tours and stops only available for workers (person.IsWorker || (dayPattern.WorkTours <= 0 && dayPattern.WorkStops <= 0)) && // school tours and stops only available for students with usual school parcel not at home ((person.IsStudent && person.UsualSchoolParcel != null && person.UsualSchoolParcel != person.Household.ResidenceParcel) || (dayPattern.SchoolTours <= 0 && dayPattern.SchoolStops <= 0)) && // school stops not available if usual school parcel is same as usual work parcel ((person.IsStudent && person.UsualSchoolParcel != null && person.UsualSchoolParcel != person.UsualWorkParcel) || (dayPattern.SchoolStops <= 0)); ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(alternativeIndex, available, choice != null && choice.Equals(dayPattern)); if (!Global.Configuration.IsInEstimationMode && !alternative.Available) { continue; } alternative.Choice = dayPattern; // components for the purposes for (int purpose = Global.Settings.Purposes.Work; purpose <= Global.Settings.Purposes.Social; purpose++) { if (dayPattern.Tours[purpose] > 0 || dayPattern.Stops[purpose] > 0) { alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(purpose)); if (dayPattern.Tours[purpose] > 0) { alternative.AddUtilityTerm(100 * purpose, 1); // tour purpose ASC alternative.AddUtilityTerm(100 * purpose + 29, purposeLogsums[purpose]); // tour purpose logsum alternative.AddUtilityTerm(100 * purpose + 30, person.PaidParkingAtWorkplace); // only use for work purpose } if (dayPattern.Stops[purpose] > 0) { alternative.AddUtilityTerm(100 * purpose + 1, 1); // stop purpose ASC alternative.AddUtilityTerm(100 * purpose + 31, purposeLogsums[purpose]); // stop purpose logsum } if (Global.Configuration.IsInEstimationMode) { alternative.AddUtilityTerm(100 * purpose + 32, 1 - person.PaperDiary); alternative.AddUtilityTerm(100 * purpose + 33, person.ProxyResponse); } } } // multiple tour purposes component if (dayPattern.TotalTours > 1) { alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(Global.Settings.Purposes.Social + (dayPattern.TotalTours - 1))); } // multiple stop purposes component if (dayPattern.TotalStops > 1) { alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(Global.Settings.Purposes.Social + 5 + (dayPattern.TotalStops - 1))); } for (int tourPurpose = Global.Settings.Purposes.Work; tourPurpose <= Global.Settings.Purposes.Social; tourPurpose++) { for (int stopPurpose = Global.Settings.Purposes.Work; stopPurpose <= Global.Settings.Purposes.Social - 1; stopPurpose++) { if (tourPurpose > Global.Settings.Purposes.School && stopPurpose <= Global.Settings.Purposes.School) { continue; } if (dayPattern.Tours[tourPurpose] > 0 && dayPattern.Stops[stopPurpose] > 0) { alternative.AddUtilityTerm(1000 + 10 * tourPurpose + stopPurpose, 1); // tour-stop comb. utility } } } for (int tourPurpose = Global.Settings.Purposes.Work; tourPurpose <= Global.Settings.Purposes.School; tourPurpose++) { if (dayPattern.Tours[tourPurpose] == 1 && dayPattern.TotalStops >= 1) { alternative.AddUtilityTerm(1000 + 10 * tourPurpose, purposeLogsums[tourPurpose]); // usual location logsum x presence of stops in work or school pattern alternative.AddUtilityTerm(1000 + 10 * tourPurpose + 8, compositeLogsum); // home aggregate logsum x presence of stops in work or school pattern alternative.AddUtilityTerm(1000 + 10 * tourPurpose + 9, atUsualLogsums[tourPurpose]); // at usual location aggregate logsum x presence of stops in work or school pattern } } for (int tourPurpose = Global.Settings.Purposes.Work; tourPurpose <= Global.Settings.Purposes.Social - 2; tourPurpose++) { for (int tourPurpose2 = tourPurpose + 1; tourPurpose2 <= Global.Settings.Purposes.Social; tourPurpose2++) { if (dayPattern.Tours[tourPurpose] > 0 && dayPattern.Tours[tourPurpose2] > 0) { alternative.AddUtilityTerm(1100 + 10 * tourPurpose + tourPurpose2, 1); // tour-tour comb. utility } } } for (int stopPurpose = Global.Settings.Purposes.Work; stopPurpose <= Global.Settings.Purposes.Social - 2; stopPurpose++) { for (int stopPurpose2 = stopPurpose + 1; stopPurpose2 <= Global.Settings.Purposes.Social; stopPurpose2++) { if (dayPattern.Stops[stopPurpose] > 0 && dayPattern.Stops[stopPurpose2] > 0) { alternative.AddUtilityTerm(1200 + 10 * stopPurpose + stopPurpose2, 1); // stop-stop comb. utility } } } if (dayPattern.TotalTours > 0 && dayPattern.TotalStops > 0) { int totalStops = dayPattern.TotalStops; if (totalStops > 3) { totalStops = 3; } alternative.AddUtilityTerm(1300 + 10 * dayPattern.TotalTours + totalStops, 1); // nttour-ntstop utility } if (dayPattern.TotalTours - dayPattern.Tours[Global.Settings.Purposes.Work] - dayPattern.Tours[Global.Settings.Purposes.School] > 0) { // tour utility alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(tourComponentIndex)); } if (dayPattern.TotalStops - dayPattern.Stops[Global.Settings.Purposes.Work] - dayPattern.Stops[Global.Settings.Purposes.School] > 0) { // stop utility alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(stopComponentIndex)); } } }
public TourWrapper(ITour tour, IPersonDayWrapper personDayWrapper, bool suppressRandomVOT = false) : base(tour, personDayWrapper, Global.Settings.Purposes.PersonalBusiness, suppressRandomVOT) { _tour = (ILDTour)tour; }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, IHouseholdDayWrapper householdDay, ITourWrapper tour, IParcelWrapper destinationParcel, int householdCars, int constrainedMode, int constrainedArrivalTime, int constrainedDepartureTime, HTourModeTime choice = null) { IHouseholdWrapper household = tour.Household; IPersonWrapper person = tour.Person; IPersonDayWrapper personDay = tour.PersonDay; Framework.DomainModels.Models.IHouseholdTotals householdTotals = household.HouseholdTotals; // household inputs 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(); //var householdCars = household.VehiclesAvailable; MABADD now an input parameter int noCarsInHouseholdFlag = household.GetFlagForNoCarsInHousehold(householdCars); int carsLessThanDriversFlag = household.GetFlagForCarsLessThanDrivers(householdCars); int carsLessThanWorkersFlag = household.GetFlagForCarsLessThanWorkers(householdCars); int income0To25KFlag = household.Has0To25KIncome.ToFlag(); int income100KPlusFlag = household.Has100KPlusIncome.ToFlag(); // 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 fulltimeWorkerFlag = person.IsFulltimeWorker.ToFlag(); int childAge5Through15Flag = person.IsChildAge5Through15.ToFlag(); int childUnder5Flag = person.IsChildUnder5.ToFlag(); int maleFlag = person.IsMale.ToFlag(); int ageUnder30Flag = person.AgeIsLessThan30.ToFlag(); int ageBetween51And98Flag = person.AgeIsBetween51And98.ToFlag(); int adultFlag = person.IsAdult.ToFlag(); // person-day inputs int homeBasedToursOnlyFlag = (personDay == null) ? 1 : personDay.OnlyHomeBasedToursExist().ToFlag(); int firstSimulatedHomeBasedTourFlag = (personDay == null) ? 1 : personDay.IsFirstSimulatedHomeBasedTour().ToFlag(); int laterSimulatedHomeBasedTourFlag = (personDay == null) ? 0 : personDay.IsLaterSimulatedHomeBasedTour().ToFlag(); int totalStops = (personDay == null) ? 0 : personDay.GetTotalStops(); int totalSimulatedStops = (personDay == null) ? 0 : personDay.GetTotalSimulatedStops(); int escortStops = (personDay == null) ? 0 : personDay.EscortStops; int homeBasedTours = (personDay == null) ? 1 : personDay.HomeBasedTours; int simulatedHomeBasedTours = (personDay == null) ? 0 : personDay.SimulatedHomeBasedTours; // tour inputs int escortTourFlag = tour.IsEscortPurpose().ToFlag(); int shoppingTourFlag = tour.IsShoppingPurpose().ToFlag(); int mealTourFlag = tour.IsMealPurpose().ToFlag(); int socialTourFlag = tour.IsSocialPurpose().ToFlag(); int personalBusinessTourFlag = tour.IsPersonalBusinessPurpose().ToFlag(); int recreationTourFlag = tour.IsRecreationPurpose().ToFlag(); int medicalTourFlag = tour.IsMedicalPurpose().ToFlag(); IParcelWrapper originParcel = tour.OriginParcel; //var destinationParcel = tour.DestinationParcel; MABADD now an input parameter int jointTourFlag = (tour.JointTourSequence > 0) ? 1 : 0; int partialHalfTour1Flag = (tour.PartialHalfTour1Sequence > 0) ? 1 : 0; int partialHalfTour2Flag = (tour.PartialHalfTour2Sequence > 0) ? 1 : 0; int fullHalfTour1Flag = (tour.FullHalfTour1Sequence > 0) ? 1 : 0; int fullHalfTour2Flag = (tour.FullHalfTour2Sequence > 0) ? 1 : 0; int parentTourMode = tour.ParentTour == null ? 0 : tour.ParentTour.Mode; // remaining inputs // Higher priority tour of 2+ tours for the same purpose int highPrioritySameFlag = (personDay == null) ? 1 : (tour.GetTotalToursByPurpose() > tour.GetTotalSimulatedToursByPurpose() && tour.GetTotalSimulatedToursByPurpose() == 1).ToFlag(); // Lower priority tour(s) of 2+ tours for the same purpose int lowPrioritySameFlag = (personDay == null) ? 0 : (tour.GetTotalSimulatedToursByPurpose() > 1).ToFlag(); // Higher priority tour of 2+ tours for different purposes int highPriorityDifferentFlag = (personDay == null) ? 0 : (personDay.IsFirstSimulatedHomeBasedTour() && personDay.HomeBasedToursExist()).ToFlag() * (1 - highPrioritySameFlag); // Lower priority tour of 2+ tours for different purposes int lowPriorityDifferentFlag = (personDay == null) ? 0 : (personDay.IsLaterSimulatedHomeBasedTour() && personDay.HomeBasedToursExist()).ToFlag() * (1 - lowPrioritySameFlag); ITimeWindow timeWindow = (householdDay == null) ? new TimeWindow() : tour.GetRelevantTimeWindow(householdDay); int totalMinutesAvailableInDay = timeWindow.TotalAvailableMinutes(1, 1440); int bigPeriodCount = DayPeriod.H_BIG_DAY_PERIOD_TOTAL_TOUR_TIMES; int nPeriodCombs = bigPeriodCount * (bigPeriodCount + 1) / 2; //set components int componentIndex = 0; int periodComb = -1; bool useTimeComponents = Global.Configuration.IsInEstimationMode || constrainedArrivalTime == 0 || constrainedDepartureTime == 0; if (useTimeComponents) { for (int arrivalPeriodIndex = 0; arrivalPeriodIndex < bigPeriodCount; arrivalPeriodIndex++) { MinuteSpan arrivalPeriod = DayPeriod.HBigDayPeriods[arrivalPeriodIndex]; int arrivalPeriodAvailableMinutes = timeWindow.TotalAvailableMinutes(arrivalPeriod.Start, arrivalPeriod.End); for (int departurePeriodIndex = arrivalPeriodIndex; departurePeriodIndex < bigPeriodCount; departurePeriodIndex++) { MinuteSpan departurePeriod = DayPeriod.HBigDayPeriods[departurePeriodIndex]; int departurePeriodAvailableMinutes = timeWindow.TotalAvailableMinutes(departurePeriod.Start, departurePeriod.End); if (arrivalPeriod == departurePeriod) { componentIndex = arrivalPeriodIndex; choiceProbabilityCalculator.CreateUtilityComponent(componentIndex); ChoiceProbabilityCalculator.Component arrivalComponent = choiceProbabilityCalculator.GetUtilityComponent(componentIndex); if (arrivalPeriodAvailableMinutes > 0) { double hoursArrival = arrivalPeriod.Middle / 60.0; int firstCoef = 300; arrivalComponent.AddUtilityTerm(300, Math.Log(arrivalPeriodAvailableMinutes)); //arrival shift variables arrivalComponent.AddUtilityTerm(firstCoef + 2, partTimeWorkerFlag * hoursArrival); arrivalComponent.AddUtilityTerm(firstCoef + 3, nonworkingAdultFlag * hoursArrival); arrivalComponent.AddUtilityTerm(firstCoef + 4, universityStudentFlag * hoursArrival); arrivalComponent.AddUtilityTerm(firstCoef + 5, retiredAdultFlag * hoursArrival); arrivalComponent.AddUtilityTerm(firstCoef + 6, drivingAgeStudentFlag * hoursArrival); arrivalComponent.AddUtilityTerm(firstCoef + 7, childAge5Through15Flag * hoursArrival); arrivalComponent.AddUtilityTerm(firstCoef + 8, childUnder5Flag * hoursArrival); arrivalComponent.AddUtilityTerm(firstCoef + 9, escortTourFlag * hoursArrival); arrivalComponent.AddUtilityTerm(firstCoef + 10, shoppingTourFlag * hoursArrival); arrivalComponent.AddUtilityTerm(firstCoef + 11, mealTourFlag * hoursArrival); arrivalComponent.AddUtilityTerm(firstCoef + 12, socialTourFlag * hoursArrival); arrivalComponent.AddUtilityTerm(firstCoef + 13, personalBusinessTourFlag * hoursArrival); arrivalComponent.AddUtilityTerm(firstCoef + 14, recreationTourFlag * hoursArrival); arrivalComponent.AddUtilityTerm(firstCoef + 15, medicalTourFlag * hoursArrival); arrivalComponent.AddUtilityTerm(firstCoef + 16, income0To25KFlag * hoursArrival); arrivalComponent.AddUtilityTerm(firstCoef + 17, income100KPlusFlag * hoursArrival); arrivalComponent.AddUtilityTerm(firstCoef + 18, highPrioritySameFlag * hoursArrival); arrivalComponent.AddUtilityTerm(firstCoef + 19, lowPrioritySameFlag * hoursArrival); arrivalComponent.AddUtilityTerm(firstCoef + 20, highPriorityDifferentFlag * hoursArrival); arrivalComponent.AddUtilityTerm(firstCoef + 21, lowPriorityDifferentFlag * hoursArrival); arrivalComponent.AddUtilityTerm(firstCoef + 22, jointTourFlag * hoursArrival); arrivalComponent.AddUtilityTerm(firstCoef + 23, partialHalfTour1Flag * hoursArrival); arrivalComponent.AddUtilityTerm(firstCoef + 24, fullHalfTour1Flag * hoursArrival); arrivalComponent.AddUtilityTerm(firstCoef + 25, partialHalfTour2Flag * hoursArrival); arrivalComponent.AddUtilityTerm(firstCoef + 26, fullHalfTour2Flag * hoursArrival); } componentIndex = bigPeriodCount + departurePeriodIndex; choiceProbabilityCalculator.CreateUtilityComponent(componentIndex); ChoiceProbabilityCalculator.Component departureComponent = choiceProbabilityCalculator.GetUtilityComponent(componentIndex); if (departurePeriodAvailableMinutes > 0) { departureComponent.AddUtilityTerm(300, Math.Log(departurePeriodAvailableMinutes)); } } // set period combination component periodComb++; componentIndex = 2 * bigPeriodCount + periodComb; choiceProbabilityCalculator.CreateUtilityComponent(componentIndex); ChoiceProbabilityCalculator.Component combinationComponent = choiceProbabilityCalculator.GetUtilityComponent(componentIndex); if (arrivalPeriodAvailableMinutes > 0 && departurePeriodAvailableMinutes > 0) { double hoursDuration = (departurePeriod.Middle - arrivalPeriod.Middle) / 60.0; int firstCoef = 700; //combination constants combinationComponent.AddUtilityTerm(firstCoef + periodComb, 1.0); // duration shift variables combinationComponent.AddUtilityTerm(firstCoef + 31, escortTourFlag * hoursDuration); combinationComponent.AddUtilityTerm(firstCoef + 32, shoppingTourFlag * hoursDuration); combinationComponent.AddUtilityTerm(firstCoef + 33, mealTourFlag * hoursDuration); combinationComponent.AddUtilityTerm(firstCoef + 34, socialTourFlag * hoursDuration); combinationComponent.AddUtilityTerm(firstCoef + 35, personalBusinessTourFlag * hoursDuration); combinationComponent.AddUtilityTerm(firstCoef + 36, recreationTourFlag * hoursDuration); combinationComponent.AddUtilityTerm(firstCoef + 37, medicalTourFlag * hoursDuration); combinationComponent.AddUtilityTerm(firstCoef + 38, highPrioritySameFlag * hoursDuration); combinationComponent.AddUtilityTerm(firstCoef + 39, lowPrioritySameFlag * hoursDuration); combinationComponent.AddUtilityTerm(firstCoef + 40, highPriorityDifferentFlag * hoursDuration); combinationComponent.AddUtilityTerm(firstCoef + 41, lowPriorityDifferentFlag * hoursDuration); combinationComponent.AddUtilityTerm(firstCoef + 42, partTimeWorkerFlag * hoursDuration); combinationComponent.AddUtilityTerm(firstCoef + 43, jointTourFlag * hoursDuration); combinationComponent.AddUtilityTerm(firstCoef + 44, partialHalfTour1Flag * hoursDuration); combinationComponent.AddUtilityTerm(firstCoef + 45, fullHalfTour1Flag * hoursDuration); combinationComponent.AddUtilityTerm(firstCoef + 46, partialHalfTour2Flag * hoursDuration); combinationComponent.AddUtilityTerm(firstCoef + 47, fullHalfTour2Flag * hoursDuration); // peak-to-peak variables if (arrivalPeriod.Index == DayPeriod.AM_PEAK && departurePeriod.Index == DayPeriod.PM_PEAK) { combinationComponent.AddUtilityTerm(firstCoef + 48, fulltimeWorkerFlag); combinationComponent.AddUtilityTerm(firstCoef + 49, income0To25KFlag); combinationComponent.AddUtilityTerm(firstCoef + 50, income100KPlusFlag); } } } } } for (int mode = Global.Settings.Modes.Walk; mode <= Global.Settings.Modes.SchoolBus; mode++) { componentIndex = 2 * bigPeriodCount + nPeriodCombs + mode - 1; choiceProbabilityCalculator.CreateUtilityComponent(componentIndex); ChoiceProbabilityCalculator.Component modeComponent = choiceProbabilityCalculator.GetUtilityComponent(componentIndex); if (mode == Global.Settings.Modes.SchoolBus) { modeComponent.AddUtilityTerm(10, 1); modeComponent.AddUtilityTerm(11, childUnder5Flag); modeComponent.AddUtilityTerm(12, adultFlag); } else if (mode == Global.Settings.Modes.ParkAndRide) { modeComponent.AddUtilityTerm(10, 1); modeComponent.AddUtilityTerm(16, noCarsInHouseholdFlag); modeComponent.AddUtilityTerm(17, carsLessThanWorkersFlag); modeComponent.AddUtilityTerm(129, destinationParcel.MixedUse2Index1()); modeComponent.AddUtilityTerm(129, destinationParcel.TotalEmploymentDensity1() / 5000.0); modeComponent.AddUtilityTerm(129, destinationParcel.NetIntersectionDensity1() / 50.0); //modeComponent.AddUtilityTerm(123, Math.Log(destinationParcel.StopsTransitBuffer1 + 1)); } else if (mode == Global.Settings.Modes.Transit) { modeComponent.AddUtilityTerm(20, 1); // modeComponent.AddUtilityTerm(21, maleFlag); modeComponent.AddUtilityTerm(22, ageUnder30Flag); // modeComponent.AddUtilityTerm(23, ageBetween51And98Flag); modeComponent.AddUtilityTerm(24, income0To25KFlag); // modeComponent.AddUtilityTerm(25, income100KPlusFlag); modeComponent.AddUtilityTerm(26, noCarsInHouseholdFlag); modeComponent.AddUtilityTerm(27, carsLessThanDriversFlag); modeComponent.AddUtilityTerm(129, destinationParcel.MixedUse2Index1()); modeComponent.AddUtilityTerm(129, destinationParcel.TotalEmploymentDensity1() / 5000.0); modeComponent.AddUtilityTerm(129, destinationParcel.NetIntersectionDensity1() / 50.0); // modeComponent.AddUtilityTerm(124, originParcel.NetIntersectionDensity1()/50.0); // modeComponent.AddUtilityTerm(124, originParcel.HouseholdDensity1()/1000.0); // modeComponent.AddUtilityTerm(124, originParcel.MixedUse2Index1()); //modeComponent.AddUtilityTerm(123, Math.Log(destinationParcel.StopsTransitBuffer1 + 1)); //modeComponent.AddUtilityTerm(122, Math.Log(originParcel.StopsTransitBuffer1 + 1)); } else if (mode == Global.Settings.Modes.Hov3) { modeComponent.AddUtilityTerm(30, 1); modeComponent.AddUtilityTerm(31, childrenUnder5); modeComponent.AddUtilityTerm(32, childrenAge5Through15); modeComponent.AddUtilityTerm(34, nonworkingAdults + retiredAdults); modeComponent.AddUtilityTerm(38, onePersonHouseholdFlag); modeComponent.AddUtilityTerm(39, twoPersonHouseholdFlag); modeComponent.AddUtilityTerm(36, noCarsInHouseholdFlag); modeComponent.AddUtilityTerm(37, carsLessThanDriversFlag); } else if (mode == Global.Settings.Modes.Hov2) { modeComponent.AddUtilityTerm(31, childrenUnder5); modeComponent.AddUtilityTerm(32, childrenAge5Through15); modeComponent.AddUtilityTerm(34, nonworkingAdults + retiredAdults); modeComponent.AddUtilityTerm(36, noCarsInHouseholdFlag); modeComponent.AddUtilityTerm(37, carsLessThanDriversFlag); modeComponent.AddUtilityTerm(40, 1); modeComponent.AddUtilityTerm(41, onePersonHouseholdFlag); } else if (mode == Global.Settings.Modes.Sov) { // modeComponent.AddUtilityTerm(50, 1); // modeComponent.AddUtilityTerm(54, income0To25KFlag); modeComponent.AddUtilityTerm(55, income100KPlusFlag); modeComponent.AddUtilityTerm(57, carsLessThanWorkersFlag); } else if (mode == Global.Settings.Modes.Bike) { modeComponent.AddUtilityTerm(60, 1); modeComponent.AddUtilityTerm(61, maleFlag); modeComponent.AddUtilityTerm(62, ageUnder30Flag); modeComponent.AddUtilityTerm(63, ageBetween51And98Flag); // modeComponent.AddUtilityTerm(64, income0To25KFlag); // modeComponent.AddUtilityTerm(65, income100KPlusFlag); modeComponent.AddUtilityTerm(66, noCarsInHouseholdFlag); modeComponent.AddUtilityTerm(67, carsLessThanDriversFlag); modeComponent.AddUtilityTerm(169, destinationParcel.MixedUse4Index2()); modeComponent.AddUtilityTerm(169, destinationParcel.TotalEmploymentDensity2() / 20000.0); modeComponent.AddUtilityTerm(169, destinationParcel.NetIntersectionDensity2() / 200.0); modeComponent.AddUtilityTerm(164, originParcel.NetIntersectionDensity2() / 200.0); modeComponent.AddUtilityTerm(164, originParcel.HouseholdDensity2() / 4000.0); modeComponent.AddUtilityTerm(164, originParcel.MixedUse4Index2()); } else if (mode == Global.Settings.Modes.Walk) { modeComponent.AddUtilityTerm(70, 1.0); modeComponent.AddUtilityTerm(71, maleFlag); modeComponent.AddUtilityTerm(72, ageUnder30Flag); // modeComponent.AddUtilityTerm(73, ageBetween51And98Flag); // modeComponent.AddUtilityTerm(74, income0To25KFlag); modeComponent.AddUtilityTerm(75, income100KPlusFlag); // modeComponent.AddUtilityTerm(76, noCarsInHouseholdFlag); modeComponent.AddUtilityTerm(77, carsLessThanDriversFlag); modeComponent.AddUtilityTerm(179, destinationParcel.MixedUse4Index1()); modeComponent.AddUtilityTerm(179, destinationParcel.TotalEmploymentDensity1() / 5000.0); modeComponent.AddUtilityTerm(179, destinationParcel.NetIntersectionDensity1() / 50.0); modeComponent.AddUtilityTerm(179, originParcel.NetIntersectionDensity1() / 50.0); modeComponent.AddUtilityTerm(179, originParcel.HouseholdDensity1() / 1000.0); modeComponent.AddUtilityTerm(179, originParcel.MixedUse4Index1()); } if (mode == Global.Settings.Modes.Walk || mode == Global.Settings.Modes.Bike || mode == Global.Settings.Modes.Hov2 || mode == Global.Settings.Modes.Hov3 || mode == Global.Settings.Modes.Transit) { int firstCoef = 200 + 10 * mode; //modeComponent.AddUtilityTerm(firstCoef + 0, escortTourFlag); //modeComponent.AddUtilityTerm(firstCoef + 1, shoppingTourFlag); //modeComponent.AddUtilityTerm(firstCoef + 2, mealTourFlag); //modeComponent.AddUtilityTerm(firstCoef + 3, socialTourFlag); //modeComponent.AddUtilityTerm(firstCoef + 4, personalBusinessTourFlag); //modeComponent.AddUtilityTerm(firstCoef + 5, recreationTourFlag); // modeComponent.AddUtilityTerm(firstCoef + 6, medicalTourFlag); //modeComponent.AddUtilityTerm(firstCoef + 7, jointTourFlag); modeComponent.AddUtilityTerm(firstCoef + 8, Math.Min(partialHalfTour1Flag + partialHalfTour2Flag, 1.0)); modeComponent.AddUtilityTerm(firstCoef + 9, Math.Min(fullHalfTour1Flag + fullHalfTour2Flag, 1.0)); modeComponent.AddUtilityTerm(290 + mode, mode == parentTourMode ? 1 : 0); } modeComponent.AddUtilityTerm(298, mode >= Global.Settings.Modes.Sov && mode <= Global.Settings.Modes.Hov3 && parentTourMode == Global.Settings.Modes.Sov ? 1 : 0); modeComponent.AddUtilityTerm(299, mode >= Global.Settings.Modes.Sov && mode <= Global.Settings.Modes.Hov3 && parentTourMode >= Global.Settings.Modes.Hov2 && parentTourMode <= Global.Settings.Modes.Hov3 ? 1 : 0); } //loop on all alternatives, using modeTimes objects { foreach (HTourModeTime modeTimes in HTourModeTime.ModeTimes[ParallelUtility.threadLocalAssignedIndex.Value]) { MinuteSpan arrivalPeriod = modeTimes.ArrivalPeriod; int arrivalPeriodAvailableMinutes = timeWindow.TotalAvailableMinutes(arrivalPeriod.Start, arrivalPeriod.End); MinuteSpan departurePeriod = modeTimes.DeparturePeriod; int departurePeriodAvailableMinutes = timeWindow.TotalAvailableMinutes(departurePeriod.Start, departurePeriod.End); periodComb = modeTimes.PeriodCombinationIndex; int mode = modeTimes.Mode; int altIndex = modeTimes.Index; //set availabillity based on time window variables and any constrained choices bool available = (modeTimes.LongestFeasibleWindow != null) && (mode > 0) && (mode != Global.Settings.Modes.Sov || (tour.Person.IsDrivingAge && tour.Household.VehiclesAvailable > 0)) && (constrainedMode <= 0 || constrainedMode == mode) && (constrainedArrivalTime <= 0 || (constrainedArrivalTime >= arrivalPeriod.Start && constrainedArrivalTime <= arrivalPeriod.End)) && (constrainedDepartureTime <= 0 || (constrainedDepartureTime >= departurePeriod.Start && constrainedDepartureTime <= departurePeriod.End)); ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(altIndex, available, choice != null && choice.Index == altIndex); alternative.Choice = modeTimes; // JLB added 20130420 //alternative.AddNestedAlternative(HTourModeTime.TOTAL_TOUR_MODE_TIMES + periodComb + 1, periodComb, THETA_PARAMETER); if (Global.Configuration.IsInEstimationMode && choice != null && altIndex == choice.Index) { Global.PrintFile.WriteLine("Aper Dper Mode {0} {1} {2} Travel Times {3} {4} Window {5} {6}", arrivalPeriod.Index, departurePeriod.Index, mode, modeTimes.ModeAvailableToDestination ? modeTimes.TravelTimeToDestination : -1, modeTimes.ModeAvailableFromDestination ? modeTimes.TravelTimeFromDestination : -1, modeTimes.LongestFeasibleWindow != null ? modeTimes.LongestFeasibleWindow.Start : -1, modeTimes.LongestFeasibleWindow != null ? modeTimes.LongestFeasibleWindow.End : -1); } /* if (altIndex == 0) * { * alternative.AddUtilityTerm(991, tour.Household.Id); * alternative.AddUtilityTerm(992, tour.Person.Id); * alternative.AddUtilityTerm(993, tour.PersonDay.Day); * alternative.AddUtilityTerm(994, tour.Sequence); * alternative.AddUtilityTerm(995, constrainedMode); * alternative.AddUtilityTerm(996, constrainedArrivalTime); * alternative.AddUtilityTerm(997, constrainedDepartureTime); * alternative.AddUtilityTerm(998, tour.DestinationPurpose); * alternative.AddUtilityTerm(999, (tour.ParentTour == null) ? 0 : 1); * } */ //if in application mode and combination is not available, can skip the rest if (!Global.Configuration.IsInEstimationMode && !alternative.Available) { continue; } if (useTimeComponents) { // arrival period utility component alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(arrivalPeriod.Index)); // departure period utility component alternative.AddUtilityComponent( choiceProbabilityCalculator.GetUtilityComponent(bigPeriodCount + departurePeriod.Index)); // period combination utility component alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(2 * bigPeriodCount + periodComb)); } // mode utility component alternative.AddUtilityComponent( choiceProbabilityCalculator.GetUtilityComponent(2 * bigPeriodCount + nPeriodCombs + mode - 1)); //even in estimation mode, do not need the rest of the code if not available if (!alternative.Available) { continue; } // set parking cost for period combination double parkingDuration = (departurePeriod == arrivalPeriod ? (arrivalPeriod.End - arrivalPeriod.Start) / 2.0 : departurePeriod.Middle - arrivalPeriod.Middle) / 60.0; // parking at work is free if no paid parking at work and tour goes to usual workplace double destinationParkingCost = (!Global.Configuration.IsInEstimationMode && Global.Configuration.ShouldRunPayToParkAtWorkplaceModel && tour.Person.UsualWorkParcel != null && destinationParcel == tour.Person.UsualWorkParcel && person.PaidParkingAtWorkplace == 0) ? 0.0 : destinationParcel.ParkingCostBuffer1(parkingDuration); double parkingCostFraction = (mode == Global.Settings.Modes.Sov) ? 1.0 : (mode == Global.Settings.Modes.Hov2) ? 1.0 / Global.Configuration.Coefficients_HOV2CostDivisor_Work : (mode == Global.Settings.Modes.Hov3) ? 1.0 / Global.Configuration.Coefficients_HOV3CostDivisor_Work : 0.0; double minimumTimeNeeded = modeTimes.TravelTimeToDestination + modeTimes.TravelTimeFromDestination + Global.Settings.Times.MinimumActivityDuration; alternative.AddUtilityTerm(1, modeTimes.GeneralizedTimeToDestination + modeTimes.GeneralizedTimeFromDestination); //alternative.AddUtilityTerm(2, destinationParkingCost*parkingCostFraction); //alternative.AddUtilityTerm(3, // Math.Log(Math.Min(1140, modeTimes.LongestFeasibleWindow.End - modeTimes.LongestFeasibleWindow.Start - // minimumTimeNeeded + 1.0 ))); // JLB 20140204 replaced coeff 3 with a different time window formulation: time pressure // instead of having positive utility for increasing time window, have negative utility for decreasing time window alternative.AddUtilityTerm(3, Math.Log(Math.Max(Constants.EPSILON, 1 - Math.Pow(minimumTimeNeeded / (Math.Min(1140, modeTimes.LongestFeasibleWindow.End - modeTimes.LongestFeasibleWindow.Start)), 0.3) ))); //alternative.AddUtilityTerm(4, Math.Log((totalMinutesAvailableInDay + 1.0)/(minimumTimeNeeded + 1.0))); //alternative.AddUtilityTerm(4, // Math.Log(Math.Max(Constants.EPSILON, 1 - minimumTimeNeeded/(Math.Min(1140, totalMinutesAvailableInDay))))); //alternative.AddUtilityTerm(5, // (maleFlag == 0 && mode == Global.Settings.Modes.Walk && // arrivalPeriod.Index >= DayPeriod.EVENING) // ? 1 // : 0); // alternative.AddUtilityTerm(5, // (maleFlag == 0 && mode == Global.Settings.Modes.Walk && // departurePeriod.Index >= DayPeriod.EVENING) // ? 1 // : 0); } } }
public TourWrapper(ITour tour, IPersonDayWrapper personDayWrapper, int purpose, bool suppressRandomVOT = false) : base(tour, personDayWrapper, purpose, suppressRandomVOT) { _tour = (ILDTour)tour; }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, HouseholdDayWrapper householdDay, int jHTSimulated, int genChoice, bool[,] jHTAvailable, bool[] fHTAvailable, int[][] altParticipants, int choice = Constants.DEFAULT_VALUE) { IEnumerable <PersonDayWrapper> orderedPersonDays = householdDay.PersonDays.OrderBy(p => p.GetJointHalfTourParticipationPriority()).ToList().Cast <PersonDayWrapper>(); int pairedHalfTour = genChoice == 1 ? 1 : 0; int firstHalfTour = genChoice == 2 ? 1 : 0; int secondHalfTour = genChoice == 3 ? 1 : 0; // set household characteristics here that don't depend on person characteristics var carOwnership = householdDay.Household.VehiclesAvailable == 0 ? Global.Settings.CarOwnerships.NoCars : householdDay.Household.VehiclesAvailable < householdDay.Household.HouseholdTotals.DrivingAgeMembers ? Global.Settings.CarOwnerships.LtOneCarPerAdult : Global.Settings.CarOwnerships.OneOrMoreCarsPerAdult; int hhsize = householdDay.Household.Size; var noCarsFlag = FlagUtility.GetNoCarsFlag(carOwnership); var carCompetitionFlag = FlagUtility.GetCarCompetitionFlag(carOwnership); var votALSegment = householdDay.Household.GetVotALSegment(); var transitAccessSegment = householdDay.Household.ResidenceParcel.TransitAccessSegment(); var totalAggregateLogsum = Global.AggregateLogsums[householdDay.Household.ResidenceParcel.ZoneId] [Global.Settings.Purposes.HomeBasedComposite][carOwnership][votALSegment][transitAccessSegment]; IPersonDayWrapper pPersonDay = null; IParcelWrapper[] pUsualLocation = new IParcelWrapper[6]; int[] pUsualLocationId = new int[6]; int[] pPatternType = new int[6]; int[] pConstant = new int[6]; int[,] pType = new int[9, 6]; int[] pAdult = new int[6]; int[] pChild = new int[6]; int[] pAge = new int[6]; int[] pAdultFemale = new int[6]; int[] pAdultMandatory = new int[6]; int[] pNonMandatory = new int[6]; int[] pFemaleNonMandatory = new int[6]; int[] pAdultWithChildrenUnder16 = new int[6]; int[] pType7AgeUnder12 = new int[6]; int[] pType7Age12Plus = new int[6]; int[] pAgeUnder13 = new int[6]; int[] pAge5To8 = new int[6]; int[] pAge9To12 = new int[6]; int[] pAge13To15 = new int[6]; int[] pTransitAdult = new int[6]; int[] pTransitChild = new int[6]; int[] pDrivingAge = new int[6]; bool[] pHasMandatoryTourToUsualLocation = new bool[6]; bool[] pIsDrivingAge = new bool[6]; int count = 0; foreach (PersonDayWrapper personDay in orderedPersonDays) { count++; if (count <= 5) { if (count == 1) { pPersonDay = personDay; } // set characteristics here that depend on person characteristics if (personDay.Person.IsFullOrPartTimeWorker && personDay.Person.UsualWorkParcel != null) { pUsualLocation[count] = personDay.Person.UsualWorkParcel; } else if (personDay.Person.IsStudent && personDay.Person.UsualSchoolParcel != null) { pUsualLocation[count] = personDay.Person.UsualSchoolParcel; } else if (personDay.Person.IsWorker && personDay.Person.IsNotFullOrPartTimeWorker && personDay.Person.UsualWorkParcel != null) { pUsualLocation[count] = personDay.Person.UsualWorkParcel; } else { pUsualLocation[count] = personDay.Household.ResidenceParcel; } for (int i = 1; i < 9; i++) { pType[personDay.Person.PersonType, count] = 1; } pPatternType[count] = personDay.PatternType; pConstant[count] = 1; pAdult[count] = personDay.Person.IsAdult.ToFlag(); pChild[count] = (!(personDay.Person.IsAdult)).ToFlag(); pAdultWithChildrenUnder16[count] = (personDay.Person.IsAdult && personDay.Household.HasChildrenUnder16).ToFlag(); pAdultFemale[count] = personDay.Person.IsAdultFemale.ToFlag(); pAdultMandatory[count] = personDay.Person.IsAdult.ToFlag() * (personDay.PatternType == Global.Settings.PatternTypes.Mandatory).ToFlag(); pNonMandatory[count] = (personDay.PatternType == Global.Settings.PatternTypes.Optional).ToFlag(); pFemaleNonMandatory[count] = personDay.Person.IsAdultFemale.ToFlag() * (personDay.PatternType == Global.Settings.PatternTypes.Optional).ToFlag(); pType7AgeUnder12[count] = (personDay.Person.IsChildAge5Through15 && personDay.Person.Age < 12).ToFlag(); pType7Age12Plus[count] = (personDay.Person.IsChildAge5Through15 && personDay.Person.Age >= 12).ToFlag(); pAgeUnder13[count] = (personDay.Person.Age < 13).ToFlag(); pAge5To8[count] = (personDay.Person.Age >= 5 && personDay.Person.Age <= 8).ToFlag(); pAge9To12[count] = (personDay.Person.Age >= 9 && personDay.Person.Age <= 12).ToFlag(); pAge13To15[count] = (personDay.Person.Age >= 13 && personDay.Person.Age <= 15).ToFlag(); pTransitAdult[count] = (personDay.Person.TransitPassOwnership == 1 ? 1 : 0) * (personDay.Person.IsAdult.ToFlag()); pTransitChild[count] = (personDay.Person.TransitPassOwnership == 1 ? 1 : 0) * ((!personDay.Person.IsAdult).ToFlag()); pDrivingAge[count] = personDay.Person.IsDrivingAge.ToFlag(); pHasMandatoryTourToUsualLocation[count] = personDay.HasMandatoryTourToUsualLocation; pIsDrivingAge[count] = personDay.Person.IsDrivingAge; } } var componentIndex = 0; //Create person utility components int[] componentPerson = new int[6]; for (var p = 1; p <= 5; p++) { // create component for basic person-purposes componentIndex++; componentPerson[p] = componentIndex; choiceProbabilityCalculator.CreateUtilityComponent(componentPerson[p]); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(01, pType[1, p]); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(02, pType[2, p]); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(03, pType[3, p]); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(04, pType[4, p]); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(05, pType[5, p]); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(06, pType[6, p]); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(07, pType[7, p]); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(08, pType[8, p]); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(09, pAge5To8[p]); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(10, pAge9To12[p]); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(11, pAdultFemale[p]); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(12, pNonMandatory[p]); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(13, pFemaleNonMandatory[p]); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(14, pTransitAdult[p]); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(15, pTransitChild[p]); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(21, pType[1, p] * secondHalfTour); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(22, pType[2, p] * secondHalfTour); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(23, pType[3, p] * secondHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(24, pType[4, p] * secondHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(25, pType[5, p] * secondHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(26, pType[6, p] * secondHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(27, pType[7, p] * secondHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(28, pType[8, p] * secondHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(29, pAge5To8[p] * secondHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(30, pAge9To12[p] * secondHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(31, pAdultFemale[p] * secondHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(32, pNonMandatory[p] * secondHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(33, pFemaleNonMandatory[p] * secondHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(34, pTransitAdult[p] * secondHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(35, pTransitChild[p] * secondHalfTour); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(41, pType[1, p] * pairedHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(42, pType[2, p] * pairedHalfTour); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(43, pType[3, p] * pairedHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(44, pType[4, p] * pairedHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(45, pType[5, p] * pairedHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(46, pType[6, p] * pairedHalfTour); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(47, pType[7, p] * pairedHalfTour); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(48, pType[8, p] * pairedHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(49, pAge5To8[p] * pairedHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(50, pAge9To12[p] * pairedHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(51, pAdultFemale[p] * pairedHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(52, pNonMandatory[p] * pairedHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(53, pFemaleNonMandatory[p] * pairedHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(54, pTransitAdult[p] * pairedHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(55, pTransitChild[p] * pairedHalfTour); } //create two-way match interaction utility components int[,] componentMatch = new int[6, 6]; int[,] iMatchAgeUnder13 = new int[6, 6]; int[,] iMatchAdult = new int[6, 6]; int[,] iMatchAdultWithChildrenUnder16 = new int[6, 6]; int[,] iMatchMandatoryAdults = new int[6, 6]; int[,] iMatchChild = new int[6, 6]; int[,] iMatchNonMandatory = new int[6, 6]; int[,] iMatchAdultsCarDeficit = new int[6, 6]; int[,] iMatchAdultCountAtHome = new int[6, 6]; for (var t2 = 1; t2 <= 5; t2++) { for (var t1 = 1; t1 < t2; t1++) { //populate match variables iMatchAgeUnder13[t1, t2] = pAgeUnder13[t1] * pAgeUnder13[t2]; iMatchAdult[t1, t2] = pAdult[t1] * pAdult[t2]; iMatchAdultWithChildrenUnder16[t1, t2] = pAdultWithChildrenUnder16[t1] * pAdultWithChildrenUnder16[t2]; iMatchMandatoryAdults[t1, t2] = pAdultMandatory[t1] * pAdultMandatory[t2]; iMatchChild[t1, t2] = (1 - pAdult[t1]) * (1 - pAdult[t2]); iMatchNonMandatory[t1, t2] = pNonMandatory[t1] * pNonMandatory[t2]; iMatchAdultsCarDeficit[t1, t2] = pAdult[t1] * pAdult[t2] * (carCompetitionFlag + noCarsFlag); //create and populate components componentIndex++; componentMatch[t1, t2] = componentIndex; choiceProbabilityCalculator.CreateUtilityComponent(componentMatch[t1, t2]); choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(61, iMatchAgeUnder13[t1, t2]); choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(62, iMatchAdult[t1, t2]); choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(63, iMatchMandatoryAdults[t1, t2]); choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(64, iMatchNonMandatory[t1, t2]); //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(65, iMatchAdultWithChildrenUnder16[t1, t2]); choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(66, iMatchChild[t1, t2]); //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(67, iMatchAdultsCarDeficit[t1, t2]); //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(71, iMatchAgeUnder13[t1, t2] * secondHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(72, iMatchAdult[t1, t2] * secondHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(73, iMatchMandatoryAdults[t1, t2] * secondHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(74, iMatchNonMandatory[t1, t2] * secondHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(75, iMatchAdultWithChildrenUnder16[t1, t2] * secondHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(76, iMatchChild[t1, t2] * secondHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(77, iMatchAdultsCarDeficit[t1, t2] * secondHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(81, iMatchAgeUnder13[t1, t2] * pairedHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(82, iMatchAdult[t1, t2] * pairedHalfTour); choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(83, iMatchMandatoryAdults[t1, t2] * pairedHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(84, iMatchNonMandatory[t1, t2] * pairedHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(85, iMatchAdultWithChildrenUnder16[t1, t2] * pairedHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(86, iMatchChild[t1, t2] * pairedHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(87, iMatchAdultsCarDeficit[t1, t2] * pairedHalfTour); } } //create two-way cross interaction utility components int[,] componentCross = new int[6, 6]; int iCrossAgeUnder5AndNonMandatory; int iCrossAge5To12AndNonMandatory; int iCrossAge13To15AndNonMandatory; int iCrossDrivingAgeChildAndNonMandatory; for (var t2 = 1; t2 <= 5; t2++) { for (var t1 = 1; t1 <= 5; t1++) { if (!(t1 == t2)) { //populate cross variables iCrossAge5To12AndNonMandatory = pNonMandatory[t1] * (pAge5To8[t2] + pAge9To12[t2]); iCrossAgeUnder5AndNonMandatory = pNonMandatory[t1] * pType[8, t2]; iCrossAge13To15AndNonMandatory = pNonMandatory[t1] * pAge13To15[t2]; iCrossDrivingAgeChildAndNonMandatory = pNonMandatory[t1] * pType[6, t2]; //create and populate cross components componentIndex++; componentCross[t1, t2] = componentIndex; choiceProbabilityCalculator.CreateUtilityComponent(componentCross[t1, t2]); choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(91, iCrossAgeUnder5AndNonMandatory); //choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(92, iCrossAge5To12AndNonMandatory); choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(93, iCrossAge13To15AndNonMandatory); //choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(94, iCrossDrivingAgeChildAndNonMandatory); //choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(95, iCrossAgeUnder5AndNonMandatory * secondHalfTour); //choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(96, iCrossAgeUnder5AndNonMandatory * pairedHalfTour); } } } //Generate utility funtions for the alternatives bool[] available = new bool[32]; bool[] chosen = new bool[32]; int numberOfParticipants; int workersParticipating; int numberOfParticipatingChildren; int numberOfParticipatingAdults; int numberOfAvailableChildren; int numberOfAvailablePersons; int numberOfAvailableAdults; for (int alt = 0; alt < 32; alt++) { available[alt] = false; chosen[alt] = false; // set availability based on household size if (hhsize >= altParticipants[alt][6]) { available[alt] = true; } // restrict availability based on person unavailability for (int i = 1; i <= 5; i++) { if (altParticipants[alt][i] == 1 && (jHTAvailable[genChoice - 1, i] == false || fHTAvailable[i] == false)) { available[alt] = false; } } // restrict availability to cases where all non-driving age participants have same usual location // first determine first non-adult's usual location IParcelWrapper sameUsualLocation = householdDay.Household.ResidenceParcel; for (int i = 1; i <= 5; i++) { if (altParticipants[alt][i] == 1 && pPatternType[i] == 1 && pUsualLocation[i].Id > 0 && !(pDrivingAge[i] == 1)) { sameUsualLocation = pUsualLocation[i]; break; } } // then make alt unavailable if any M-Usual participant has a different usualLocation for (int i = 1; i <= 5; i++) { if (altParticipants[alt][i] == 1 && pHasMandatoryTourToUsualLocation[i] && !(pUsualLocation[i].Id == sameUsualLocation.Id) && !(pDrivingAge[i] == 1)) { available[alt] = false; break; } } // restrict availability of alts that include less than 2 participants if (altParticipants[alt][7] < 2) { available[alt] = false; } // restrict availability if 2+ participants lack tour to usual location int numberLackMandatoryTourToUsualLocation = 0; for (int i = 1; i <= 5; i++) { if (altParticipants[alt][i] == 1 && !pHasMandatoryTourToUsualLocation[i]) { numberLackMandatoryTourToUsualLocation++; } } if (numberLackMandatoryTourToUsualLocation > 1) { available[alt] = false; } //JLB 20140404 remove the drivign age requirement because children can walk, bik or take bus to/from school without an adult. // require at least one driving age (as chauffeur) //int numberDrivingAge = 0; //for (int i = 1; i <= 5; i++) { // if (altParticipants[alt][i] == 1 && pIsDrivingAge[i]) { // numberDrivingAge++; // } //} //if (numberDrivingAge == 0) { // available[alt] = false; //} // Generate alt-specific variables numberOfParticipants = 0; workersParticipating = 0; numberOfParticipatingChildren = 0; numberOfParticipatingAdults = 0; numberOfAvailableChildren = 0; numberOfAvailablePersons = 0; numberOfAvailableAdults = 0; if (available[alt] == true) { for (int i = 1; i <= 5; i++) { if (pChild[i] == 1 && pUsualLocation[i].Id == sameUsualLocation.Id) { numberOfAvailableChildren++; numberOfAvailablePersons++; } if (pAdult[i] == 1 && (pPatternType[i] == Global.Settings.PatternTypes.Optional || pUsualLocation[i].Id == sameUsualLocation.Id)) { numberOfAvailableChildren++; numberOfAvailableAdults++; } if (altParticipants[alt][i] == 1) { numberOfParticipants++; if (pType[0, i] == 1 || pType[1, i] == 1) { workersParticipating++; } if (pAdult[i] == 1) { numberOfParticipatingAdults++; } if (pChild[i] == 1) { numberOfParticipatingChildren++; } } } } double tourLogsum = 0; var destinationArrivalTime = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.WorkTourModeModel); var destinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.WorkTourModeModel); var nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().RunNested(pPersonDay, pPersonDay.Household.ResidenceParcel, sameUsualLocation, destinationArrivalTime, destinationDepartureTime, pPersonDay.Household.VehiclesAvailable); tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); // determine choice if (choice == alt) { chosen[alt] = true; } //Get the alternative var alternative = choiceProbabilityCalculator.GetAlternative(alt, available[alt], chosen[alt]); alternative.Choice = alt; //Add alt-specific utility terms alternative.AddUtilityTerm(101, (numberOfParticipatingAdults > 1 && numberOfParticipatingChildren > 0) ? 1 : 0); alternative.AddUtilityTerm(102, (numberOfParticipatingChildren < numberOfAvailableChildren) ? 1 : 0); alternative.AddUtilityTerm(103, (numberOfParticipatingAdults == 0) ? 1 : 0); //alternative.AddUtilityTerm(104, (numberOfParticipants < numberOfAvailablePersons) ? 1 : 0); alternative.AddUtilityTerm(105, tourLogsum); //alternative.AddUtilityTerm(105, ((numberOfParticipatingAdults > 1 && numberOfParticipatingChildren > 0) ? 1 : 0) * secondHalfTour); //alternative.AddUtilityTerm(106, ((numberOfParticipatingAdults > 1 && numberOfParticipatingChildren > 0) ? 1 : 0) * pairedHalfTour); //Add utility components for (int p = 1; p <= 5; p++) { if (altParticipants[alt][p] == 1) { alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p])); } } for (var t2 = 1; t2 <= 5; t2++) { for (var t1 = 1; t1 < t2; t1++) { if (altParticipants[alt][t1] == 1 && altParticipants[alt][t2] == 1) { alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2])); } } } for (var t2 = 1; t2 <= 5; t2++) { for (var t1 = 1; t1 <= 5; t1++) { if (!(t1 == t2)) { if (altParticipants[alt][t1] == 1 && altParticipants[alt][t2] == 1) { alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2])); } } } } } }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITourWrapper tour, IHouseholdDayWrapper householdDay, int sampleSize, IParcelWrapper choice = null) { // var household = tour.Household; IPersonWrapper person = tour.Person; IPersonDayWrapper personDay = 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) { ITourWrapper tInJoint = 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); int 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); int fastestAvailableTimeOfDay = tour.IsHomeBasedTour || tour.ParentTour == null ? 1 : tour.ParentTour.DestinationArrivalTime + (tour.ParentTour.DestinationDepartureTime - tour.ParentTour.DestinationArrivalTime) / 2; int tourCategory = tour.GetTourCategory(); // var primaryFlag = ChoiceModelUtility.GetPrimaryFlag(tourCategory); int secondaryFlag = ChoiceModelUtility.GetSecondaryFlag(tourCategory); ChoiceModelUtility.DrawRandomTourTimePeriodsActum(tour, tourCategory); int segment = Global.ContainerDaySim.GetInstance <SamplingWeightsSettingsFactory>().SamplingWeightsSettings.GetTourDestinationSegment(tour.DestinationPurpose, tour.IsHomeBasedTour ? Global.Settings.TourPriorities.HomeBasedTour : Global.Settings.TourPriorities.WorkBasedTour, Global.Settings.Modes.Sov, person.PersonType); DestinationSampler destinationSampler = new DestinationSampler(choiceProbabilityCalculator, segment, sampleSize, choice, tour.OriginParcel); TourDestinationUtilities tourDestinationUtilities = new TourDestinationUtilities(tour, sampleSize, secondaryFlag, personDay.GetIsWorkOrSchoolPattern().ToFlag(), personDay.GetIsOtherPattern().ToFlag(), fastestAvailableTimeOfDay, maxAvailableMinutes); destinationSampler.SampleTourDestinations(tourDestinationUtilities); }
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); } }