public int Run(PersonDayWrapper personDay, HouseholdDayWrapper householdDay, int nCallsForTour, int[] simulatedMandatoryTours, int choice) { 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.GetBatchFromThreadId()].GetChoiceProbabilityCalculator(((personDay.Person.Id * 10 + personDay.Day) * 397) ^ nCallsForTour); if (_helpers[ParallelUtility.GetBatchFromThreadId()].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 chosenAlternative = choiceProbabilityCalculator.SimulateChoice(householdDay.Household.RandomUtility, personDay.Id, choice); Global.Configuration.IsInEstimationMode = true; } else { RunModel(choiceProbabilityCalculator, personDay, householdDay, nCallsForTour, simulatedMandatoryTours); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(personDay.Household.RandomUtility); choice = (int)chosenAlternative.Choice; if (choice == 1) { personDay.UsualWorkplaceTours++; personDay.WorkTours++; } else if (choice == 2) { personDay.BusinessTours++; } else if (choice == 3) { personDay.SchoolTours++; } } return(choice); }
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.GetBatchFromThreadId()].ModelIsInEstimationMode || !personDay.Person.IsFullOrPartTimeWorker) { return; } } var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator(personDay.Person.Id * 10 + personDay.Day); if (_helpers[ParallelUtility.GetBatchFromThreadId()].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); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(personDay.Household.RandomUtility); choice = (int)chosenAlternative.Choice; } personDay.WorksAtHomeFlag = choice; personDay.WorkAtHomeDuration = choice * 120; //default predicted duration for output } }
public void Run(ITourWrapper tour, int sampleSize) { if (tour == null) { throw new ArgumentNullException("tour"); } tour.PersonDay.ResetRandom(20 + tour.Sequence - 1); if (Global.Configuration.IsInEstimationMode) { if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME) { return; } if (!TourDestinationUtilities.ShouldRunInEstimationModeForModel(tour)) { return; } } var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator(tour.Id); if (_helpers[ParallelUtility.GetBatchFromThreadId()].ModelIsInEstimationMode) { RunModel(choiceProbabilityCalculator, tour, sampleSize, tour.DestinationParcel); choiceProbabilityCalculator.WriteObservation(); } else { RunModel(choiceProbabilityCalculator, tour, sampleSize); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(tour.Household.RandomUtility); if (chosenAlternative == null) { Global.PrintFile.WriteNoAlternativesAvailableWarning(CHOICE_MODEL_NAME, "Run", tour.PersonDay.Id); tour.PersonDay.IsValid = false; return; } var choice = (ParcelWrapper)chosenAlternative.Choice; tour.DestinationParcelId = choice.Id; tour.DestinationParcel = choice; tour.DestinationZoneKey = ChoiceModelFactory.ZoneKeys[choice.ZoneId]; tour.DestinationAddressType = choice.Id == tour.Person.UsualWorkParcelId ? Global.Settings.AddressTypes.UsualWorkplace : Global.Settings.AddressTypes.Other; if (choice.Id == tour.Person.UsualWorkParcelId) { tour.PersonDay.UsualWorkplaceTours++; } } }
public void Run(TourWrapper tour, int knownArrivalTime = 0, int knownDepartureTime = 0) { if (tour == null) { throw new ArgumentNullException("tour"); } TourTime.InitializeTourTimes(); tour.PersonDay.ResetRandom(50 + tour.Sequence - 1); if (Global.Configuration.IsInEstimationMode) { if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME) { return; } } var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator(tour.Id); if (_helpers[ParallelUtility.GetBatchFromThreadId()].ModelIsInEstimationMode) { if (tour.DestinationParcel == null || tour.OriginParcel == null || tour.Mode <= Global.Settings.Modes.None || tour.Mode >= Global.Settings.Modes.SchoolBus) { return; } RunModel(choiceProbabilityCalculator, tour, knownArrivalTime, knownDepartureTime, new TourTime(tour.DestinationArrivalTime, tour.DestinationDepartureTime)); choiceProbabilityCalculator.WriteObservation(); } else { RunModel(choiceProbabilityCalculator, tour, knownArrivalTime, knownDepartureTime); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(tour.Household.RandomUtility); if (chosenAlternative == null) { Global.PrintFile.WriteNoAlternativesAvailableWarning(CHOICE_MODEL_NAME, "Run", tour.PersonDay.Id); if (!Global.Configuration.IsInEstimationMode) { tour.PersonDay.IsValid = false; } return; } var choice = (TourTime)chosenAlternative.Choice; var destinationTimes = choice.GetDestinationTimes(tour); tour.DestinationArrivalTime = knownArrivalTime == 0 ? destinationTimes.Start : knownArrivalTime; tour.DestinationDepartureTime = knownDepartureTime == 0 ? destinationTimes.End : knownDepartureTime; } }
public void Run(PersonWrapper person, int sampleSize) { if (person == null) { throw new ArgumentNullException("person"); } person.ResetRandom(0); if (Global.Configuration.IsInEstimationMode) { if (!_helpers[ParallelUtility.GetBatchFromThreadId()].ModelIsInEstimationMode) { return; } } var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator(person.Id); if (_helpers[ParallelUtility.GetBatchFromThreadId()].ModelIsInEstimationMode) { if (person.UsualWorkParcel == null) { return; } var choseHome = person.UsualWorkParcelId == person.Household.ResidenceParcelId; // JLB 20120329 added these two lines var chosenParcel = choseHome ? null : person.UsualWorkParcel; //RunModel(choiceProbabilityCalculator, person, sampleSize, person.UsualWorkParcel); RunModel(choiceProbabilityCalculator, person, sampleSize, chosenParcel, choseHome); // JLB 20120329 replaced above line // when chosenParcel is null: // DestinationSampler doesn't try to assign one of the sampled destinations as chosen // choseHome is NOT null, and RunModel sets the oddball location as chosen choiceProbabilityCalculator.WriteObservation(); } else { RunModel(choiceProbabilityCalculator, person, sampleSize); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(person.Household.RandomUtility); var choice = (ParcelWrapper)chosenAlternative.Choice; person.UsualWorkParcelId = choice.Id; person.UsualWorkParcel = choice; person.UsualWorkZoneKey = ChoiceModelFactory.ZoneKeys[choice.ZoneId]; var skimValue = ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, 1, person.Household.ResidenceParcel, choice); person.AutoTimeToUsualWork = skimValue.Variable; person.AutoDistanceToUsualWork = skimValue.BlendVariable; person.SetWorkParcelPredictions(); } }
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; } } var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator(personDay.Id); if (_helpers[ParallelUtility.GetBatchFromThreadId()].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); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(personDay.Household.RandomUtility); var 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; } } }
public void Run(IHouseholdDayWrapper householdDay, ITripWrapper trip) { if (trip == null) { throw new ArgumentNullException("trip"); } trip.PersonDay.ResetRandom(40 * (2 * trip.Tour.Sequence - 1 + trip.Direction - 1) + 50 + trip.Sequence - 1); if (Global.Configuration.IsInEstimationMode) { if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME) { return; } } var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator(trip.Id); if (_helpers[ParallelUtility.GetBatchFromThreadId()].ModelIsInEstimationMode) { if (trip.DestinationParcel == null || trip.OriginParcel == null || trip.Mode <= Global.Settings.Modes.None || trip.Mode == Global.Settings.Modes.Other) { return; } RunModel(choiceProbabilityCalculator, householdDay, trip, new HTripTime(trip.DepartureTime)); choiceProbabilityCalculator.WriteObservation(); } else { RunModel(choiceProbabilityCalculator, householdDay, trip); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(trip.Household.RandomUtility); if (chosenAlternative == null) { Global.PrintFile.WriteNoAlternativesAvailableWarning(CHOICE_MODEL_NAME, "Run", trip.PersonDay.Id); if (!Global.Configuration.IsInEstimationMode) { trip.PersonDay.IsValid = false; } return; } var choice = (HTripTime)chosenAlternative.Choice; trip.DepartureTime = choice.GetRandomFeasibleMinute(trip, choice); } }
public int Run(HouseholdDayWrapper householdDay, int nCallsForTour, int choice) { if (householdDay == null) { throw new ArgumentNullException("householdDay"); } householdDay.ResetRandom(935 + nCallsForTour); // TODO: fix the ResetRandom call parameter if (Global.Configuration.IsInEstimationMode) { if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME) { return(choice); } } var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator(((householdDay.Household.Id * 10 + householdDay.Day) * 397) ^ nCallsForTour); if (_helpers[ParallelUtility.GetBatchFromThreadId()].ModelIsInEstimationMode) { RunModel(choiceProbabilityCalculator, householdDay, nCallsForTour, choice); choiceProbabilityCalculator.WriteObservation(); } else if (Global.Configuration.TestEstimationModelInApplicationMode) { Global.Configuration.IsInEstimationMode = false; //choice = Math.Min(personDay.BusinessStops, 1) + 2 * Math.Min(personDay.SchoolStops, 1); RunModel(choiceProbabilityCalculator, householdDay, nCallsForTour); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(householdDay.Household.RandomUtility, householdDay.Household.Id, choice); Global.Configuration.IsInEstimationMode = true; } else { RunModel(choiceProbabilityCalculator, householdDay, nCallsForTour); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(householdDay.Household.RandomUtility); choice = (int)chosenAlternative.Choice; } return(choice); }
public int Run(TourWrapper tour, HouseholdDayWrapper householdDay, int nCallsForTour, int choice) { if (tour == null) { throw new ArgumentNullException("tour"); } tour.PersonDay.Person.ResetRandom(908 + (tour.Sequence - 1) * 3 + nCallsForTour); if (Global.Configuration.IsInEstimationMode) { if (!(choice == Global.Settings.Purposes.NoneOrHome)) // simplifying choice. TODO: will need to deal with personal business subtours distinctly from home based in tour models { choice = Global.Settings.Purposes.PersonalBusiness; } if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME) { return(choice); } } var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator((tour.Id * 397) ^ nCallsForTour); if (_helpers[ParallelUtility.GetBatchFromThreadId()].ModelIsInEstimationMode) { if (tour.PersonDay.GetTotalStops() > 0) { RunModel(choiceProbabilityCalculator, tour, householdDay, nCallsForTour, choice); choiceProbabilityCalculator.WriteObservation(); } } else { if (tour.PersonDay.GetTotalStops() > 0) { RunModel(choiceProbabilityCalculator, tour, householdDay, nCallsForTour); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(tour.Household.RandomUtility); choice = (int)chosenAlternative.Choice; } else { choice = Global.Settings.Purposes.NoneOrHome; } } return(choice); }
private void FindPeriod(int departureTime) { foreach (var period in DayPeriod.HSmallDayPeriods.Where(period => departureTime.IsBetween(period.Start, period.End))) { DeparturePeriod = period; } foreach ( var time in Times[ParallelUtility.GetBatchFromThreadId()].Where(time => time.DeparturePeriod == DeparturePeriod)) { Index = time.Index; break; } }
public int Run(PersonDayWrapper personDay, HouseholdDayWrapper 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); } } var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator(((personDay.Person.Id * 10 + personDay.Day) * 397) ^ personDay.GetTotalCreatedTours()); if (_helpers[ParallelUtility.GetBatchFromThreadId()].ModelIsInEstimationMode) { RunModel(choiceProbabilityCalculator, personDay, householdDay, maxPurpose, choice); choiceProbabilityCalculator.WriteObservation(); } else if (Global.Configuration.TestEstimationModelInApplicationMode) { Global.Configuration.IsInEstimationMode = false; RunModel(choiceProbabilityCalculator, personDay, householdDay, maxPurpose); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(householdDay.Household.RandomUtility, personDay.Id, choice); Global.Configuration.IsInEstimationMode = true; } else { RunModel(choiceProbabilityCalculator, personDay, householdDay, maxPurpose); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(householdDay.Household.RandomUtility); choice = (int)chosenAlternative.Choice; } return(choice); }
public void Run(HouseholdWrapper household) { if (household == null) { throw new ArgumentNullException("household"); } household.ResetRandom(4); if (Global.Configuration.IsInEstimationMode) { if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME) { return; } } var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator(household.Id); if (household.VehiclesAvailable > 4) { household.VehiclesAvailable = 4; } if (_helpers[ParallelUtility.GetBatchFromThreadId()].ModelIsInEstimationMode) { RunModel(choiceProbabilityCalculator, household, household.VehiclesAvailable); choiceProbabilityCalculator.WriteObservation(); } else if (Global.Configuration.TestEstimationModelInApplicationMode) { Global.Configuration.IsInEstimationMode = false; RunModel(choiceProbabilityCalculator, household); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(household.RandomUtility, household.Id, household.VehiclesAvailable); Global.Configuration.IsInEstimationMode = true; } else { RunModel(choiceProbabilityCalculator, household); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(household.RandomUtility); var choice = (int)chosenAlternative.Choice; household.VehiclesAvailable = choice; } }
public int Run(ITourWrapper tour, int nCallsForTour, int choice) { if (tour == null) { throw new ArgumentNullException("tour"); } tour.PersonDay.ResetRandom(30 + tour.Sequence + nCallsForTour - 1); if (Global.Configuration.IsInEstimationMode) { if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME) { return(choice); } } var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator((tour.Id * 397) ^ nCallsForTour); if (_helpers[ParallelUtility.GetBatchFromThreadId()].ModelIsInEstimationMode) { if (tour.PersonDay.GetTotalStops() > 0) { RunModel(choiceProbabilityCalculator, tour, nCallsForTour, choice); choiceProbabilityCalculator.WriteObservation(); } } else { if (tour.PersonDay.GetTotalStops() > 0) { RunModel(choiceProbabilityCalculator, tour, nCallsForTour); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(tour.Household.RandomUtility); choice = (int)chosenAlternative.Choice; } else { choice = Global.Settings.Purposes.NoneOrHome; } } return(choice); }
public void Run(HouseholdDayWrapper householdDay) { if (householdDay == null) { throw new ArgumentNullException("householdDay"); } householdDay.ResetRandom(962); if (Global.Configuration.IsInEstimationMode) { return; } var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator(householdDay.Household.Id); //if (_helpers[ParallelUtility.GetBatchFromThreadId()].ModelIsInEstimationMode) { // // set choice variable here (derive from available household properties) // if (householdDay.SharedActivityHomeStays >= 1 // //&& householdDay.DurationMinutesSharedHomeStay >=60 // && householdDay.AdultsInSharedHomeStay >= 1 // && householdDay.NumberInLargestSharedHomeStay >= (householdDay.Household.Size) // ) // { // householdDay.PrimaryPriorityTimeFlag = 1; // } // else householdDay.PrimaryPriorityTimeFlag = 0; //RunModel(choiceProbabilityCalculator, householdDay, householdDay.PrimaryPriorityTimeFlag); //choiceProbabilityCalculator.WriteObservation(); //} //else { RunModel(choiceProbabilityCalculator, householdDay, _pfptSchedule); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(householdDay.Household.RandomUtility); var choice = (int[])chosenAlternative.Choice; householdDay.StartingMinuteSharedHomeStay = choice[1]; householdDay.DurationMinutesSharedHomeStay = choice[2]; //} }
public void Run(HouseholdWrapper household) { if (household == null) { throw new ArgumentNullException("household"); } household.ResetRandom(4); if (Global.Configuration.IsInEstimationMode) { if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME) { return; } } else if (Global.Configuration.AV_IncludeAutoTypeChoice) { var AVchoiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator(household.Id); RunAVModel(AVchoiceProbabilityCalculator, household); var chosenAlternative = AVchoiceProbabilityCalculator.SimulateChoice(household.RandomUtility); var choice = (int) chosenAlternative.Choice; household.OwnsAutomatedVehicles = choice; } var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator(household.Id); var vehicles = household.VehiclesAvailable; if (household.VehiclesAvailable > 2) { vehicles = 2; } if (_helpers[ParallelUtility.GetBatchFromThreadId()].ModelIsInEstimationMode) { RunModel(choiceProbabilityCalculator, household, vehicles); choiceProbabilityCalculator.WriteObservation(); } else { RunModel(choiceProbabilityCalculator, household); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(household.RandomUtility); var choice = (int) chosenAlternative.Choice; household.VehiclesAvailable = choice; } }
public ChoiceProbabilityCalculator.Alternative RunNested(ITourWrapper tour, IParcelWrapper destinationParcel, int householdCars, double transitDiscountFraction) { if (Global.Configuration.AvoidDisaggregateModeChoiceLogsums) { return(null); } var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetNestedChoiceProbabilityCalculator(); IHouseholdDayWrapper householdDay = (tour.PersonDay == null) ? null : tour.PersonDay.HouseholdDay; int constrainedMode = 0; int constrainedArrivalTime = (Global.Configuration.ConstrainTimesForModeChoiceLogsums) ? tour.DestinationArrivalTime : 0; int constrainedDepartureTime = (Global.Configuration.ConstrainTimesForModeChoiceLogsums) ? tour.DestinationDepartureTime : 0; tour.DestinationParcel = destinationParcel; HTourModeTime.SetModeTimeImpedances(householdDay, tour, constrainedMode, constrainedArrivalTime, constrainedDepartureTime, -1, -1.0); RunModel(choiceProbabilityCalculator, householdDay, tour, destinationParcel, householdCars, constrainedMode, constrainedArrivalTime, constrainedDepartureTime); return(choiceProbabilityCalculator.SimulateChoice(tour.Household.RandomUtility)); }
public void Run(PersonWrapper person) { if (person == null) { throw new ArgumentNullException("person"); } person.ResetRandom(3); if (Global.Configuration.IsInEstimationMode) { if (!_helpers[ParallelUtility.GetBatchFromThreadId()].ModelIsInEstimationMode) { return; } } var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator(person.Id); if (_helpers[ParallelUtility.GetBatchFromThreadId()].ModelIsInEstimationMode) { if (person.TransitPassOwnership < 0 || person.TransitPassOwnership > 1) { return; } RunModel(choiceProbabilityCalculator, person, person.TransitPassOwnership); choiceProbabilityCalculator.WriteObservation(); } else { RunModel(choiceProbabilityCalculator, person); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(person.Household.RandomUtility); var choice = (int)chosenAlternative.Choice; person.TransitPassOwnership = choice; } }
public void Run(PersonDayWrapper personDay, HouseholdDayWrapper householdDay) { if (personDay == null) { throw new ArgumentNullException("personDay"); } personDay.Person.ResetRandom(903); int choice = 0; if (Global.Configuration.IsInEstimationMode) { if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME) { return; } } var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator(personDay.Person.Id * 10 + personDay.Day); if (_helpers[ParallelUtility.GetBatchFromThreadId()].ModelIsInEstimationMode) { choice = personDay.PatternType; RunModel(choiceProbabilityCalculator, personDay, householdDay, choice); choiceProbabilityCalculator.WriteObservation(); } else { RunModel(choiceProbabilityCalculator, personDay, householdDay); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(householdDay.Household.RandomUtility); choice = (int)chosenAlternative.Choice; personDay.PatternType = choice; } }
public void Run(IPersonWrapper person) { if (person == null) { throw new ArgumentNullException("person"); } person.ResetRandom(5); if (Global.Configuration.IsInEstimationMode) { if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME) { return; } var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator(person.Id); RunModel(choiceProbabilityCalculator, person); choiceProbabilityCalculator.WriteObservation(); } else { var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator(person.Id); RunModel(choiceProbabilityCalculator, person); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(person.Household.RandomUtility); if (chosenAlternative == null) { Global.PrintFile.WriteNoAlternativesAvailableWarning(CHOICE_MODEL_NAME, "Run", person.Id); return; } var choice = (int)chosenAlternative.Choice; } }
public int Run(ITripWrapper trip, IHouseholdDayWrapper householdDay, int choice) { if (trip == null) { throw new ArgumentNullException("trip"); } trip.PersonDay.ResetRandom(40 * (2 * trip.Tour.Sequence - 1 + trip.Direction - 1) + 20 + trip.Sequence - 1); if (Global.Configuration.IsInEstimationMode) { if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME) { return(choice); } } var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator(trip.Id); if (_helpers[ParallelUtility.GetBatchFromThreadId()].ModelIsInEstimationMode) { if (trip.OriginParcel == null) { return(Constants.DEFAULT_VALUE); } RunModel(choiceProbabilityCalculator, trip, householdDay, choice); choiceProbabilityCalculator.WriteObservation(); } else { RunModel(choiceProbabilityCalculator, trip, householdDay); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(trip.Household.RandomUtility); choice = (int)chosenAlternative.Choice; } return(choice); }
public int Run(HouseholdDayWrapper householdDay, int nCallsForTour, bool[] available, int type, int subType) { if (householdDay == null) { throw new ArgumentNullException("householdDay"); } householdDay.ResetRandom(920 + nCallsForTour); int choice = 0; if (Global.Configuration.IsInEstimationMode) { choice = type == 0 ? 0 : (type - 1) * 3 + subType + 1; if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME) { return(choice); } } var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator(((householdDay.Household.Id * 10 + householdDay.Day) * 397) ^ nCallsForTour); if (_helpers[ParallelUtility.GetBatchFromThreadId()].ModelIsInEstimationMode) { RunModel(choiceProbabilityCalculator, householdDay, nCallsForTour, available, choice); choiceProbabilityCalculator.WriteObservation(); } else { RunModel(choiceProbabilityCalculator, householdDay, nCallsForTour, available); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(householdDay.Household.RandomUtility); choice = (int)chosenAlternative.Choice; } return(choice); }
private void FindIndexForModeAndPeriods(int mode, int arrivalTime, int departureTime) { foreach (var period in DayPeriod.HBigDayPeriods) { if (arrivalTime.IsBetween(period.Start, period.End)) { ArrivalPeriod = period; } if (departureTime.IsBetween(period.Start, period.End)) { DeparturePeriod = period; } } Mode = mode; { foreach ( var modeTime in ModeTimes[ParallelUtility.GetBatchFromThreadId()].Where( modeTime => modeTime.ArrivalPeriod == ArrivalPeriod && modeTime.DeparturePeriod == DeparturePeriod && modeTime.Mode == Mode)) { Index = modeTime.Index; /* * TravelTimeToDestination = modeTime.TravelTimeToDestination; * TravelTimeFromDestination = modeTime.TravelTimeFromDestination; * GeneralizedTimeToDestination = modeTime.GeneralizedTimeToDestination; * GeneralizedTimeFromDestination = modeTime.GeneralizedTimeFromDestination; * ModeAvailableToDestination = modeTime.ModeAvailableToDestination; * ModeAvailableFromDestination = modeTime.ModeAvailableFromDestination; * LongestFeasibleWindow = modeTime.LongestFeasibleWindow; */ break; } } }
public ChoiceProbabilityCalculator.Alternative RunNested(ITourWrapper tour, IParcelWrapper destinationParcel) { var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetNestedChoiceProbabilityCalculator(); var pathTypeModels = PathTypeModel.RunAll( tour.Household.RandomUtility, tour.OriginParcel, destinationParcel, tour.DestinationArrivalTime, tour.DestinationDepartureTime, tour.DestinationPurpose, tour.CostCoefficient, tour.TimeCoefficient, tour.Person.IsDrivingAge, tour.Household.VehiclesAvailable, tour.Person.GetTransitFareDiscountFraction(), false); RunModel(choiceProbabilityCalculator, tour, pathTypeModels, destinationParcel, tour.Household.VehiclesAvailable); return(choiceProbabilityCalculator.SimulateChoice(tour.Household.RandomUtility)); }
private ChoiceProbabilityCalculator.Alternative RunNested(ITourWrapper tour, IParcelWrapper destinationParcel, int householdCars, double transitDiscountFraction) { var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetNestedChoiceProbabilityCalculator(); IEnumerable <dynamic> pathTypeModels = PathTypeModelFactory.Model.RunAll( tour.Household.RandomUtility, tour.OriginParcel, destinationParcel, tour.DestinationArrivalTime, tour.DestinationDepartureTime, tour.DestinationPurpose, tour.CostCoefficient, tour.TimeCoefficient, tour.Person.IsDrivingAge, householdCars, transitDiscountFraction, false); RunModel(choiceProbabilityCalculator, tour, pathTypeModels, destinationParcel, householdCars); return(choiceProbabilityCalculator.SimulateChoice(tour.Household.RandomUtility)); }
public void Run(ITourWrapper tour, IHouseholdDayWrapper householdDay, int sampleSize) { if (tour == null) { throw new ArgumentNullException("tour"); } //timesStarted++; tour.PersonDay.ResetRandom(20 + tour.Sequence - 1); if (Global.Configuration.IsInEstimationMode) { if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME) { return; } if (tour.DestinationParcel == null || tour.OriginParcel == null || tour.Mode < Global.Settings.Modes.Walk || tour.Mode > Global.Settings.Modes.Transit) { return; } // JLB 20140421 add the following to keep from estimatign twice for the same tour //if (tour.DestinationModeAndTimeHaveBeenSimulated) { // return; //} } var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator(tour.Id); if (_helpers[ParallelUtility.GetBatchFromThreadId()].ModelIsInEstimationMode) { RunModel(choiceProbabilityCalculator, tour, householdDay, sampleSize, tour.DestinationParcel); choiceProbabilityCalculator.WriteObservation(); } }
public void Run(ITripWrapper trip) { if (trip == null) { throw new ArgumentNullException("trip"); } trip.PersonDay.ResetRandom(40 * (2 * trip.Tour.Sequence - 1 + trip.Direction - 1) + 40 + trip.Sequence - 1); if (Global.Configuration.IsInEstimationMode) { if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME) { return; } } var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator(trip.Id); var originParcel = trip.IsHalfTourFromOrigin ? trip.DestinationParcel : trip.OriginParcel; // for skims - use actual travel direction, not simulation direction var destinationParcel = trip.IsHalfTourFromOrigin ? trip.OriginParcel : trip.DestinationParcel; // if first trip in half-tour, use tour destination time var departureTime = trip.IsHalfTourFromOrigin ? trip.Sequence == 1 ? trip.Tour.DestinationArrivalTime : trip.GetPreviousTrip().ArrivalTime : trip.Sequence == 1 ? trip.Tour.DestinationDepartureTime : trip.GetPreviousTrip().ArrivalTime; if (_helpers[ParallelUtility.GetBatchFromThreadId()].ModelIsInEstimationMode) { if (destinationParcel == null || originParcel == null || trip.Mode <= Global.Settings.Modes.None || trip.Mode == Global.Settings.Modes.ParkAndRide || trip.Mode == Global.Settings.Modes.Other) { return; } IEnumerable <dynamic> pathTypeModels = PathTypeModelFactory.Model.RunAll( trip.Household.RandomUtility, originParcel, destinationParcel, departureTime, 0, trip.Tour.DestinationPurpose, trip.Tour.CostCoefficient, trip.Tour.TimeCoefficient, trip.Person.IsDrivingAge, trip.Household.VehiclesAvailable, trip.Person.GetTransitFareDiscountFraction(), false); // there is no path type model for school bus, use HOV3 var mode = trip.Mode == Global.Settings.Modes.SchoolBus ? Global.Settings.Modes.Hov3 : trip.Mode; var pathTypeModel = pathTypeModels.First(x => x.Mode == mode); if (!pathTypeModel.Available) { return; } RunModel(choiceProbabilityCalculator, trip, pathTypeModels, originParcel, destinationParcel, departureTime, trip.Mode); choiceProbabilityCalculator.WriteObservation(); } else { IEnumerable <dynamic> pathTypeModels = PathTypeModelFactory.Model.RunAll( trip.Household.RandomUtility, originParcel, destinationParcel, departureTime, 0, trip.Tour.DestinationPurpose, trip.Tour.CostCoefficient, trip.Tour.TimeCoefficient, trip.Person.IsDrivingAge, trip.Household.VehiclesAvailable, trip.Person.GetTransitFareDiscountFraction(), false); RunModel(choiceProbabilityCalculator, trip, pathTypeModels, originParcel, destinationParcel, departureTime); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(trip.Household.RandomUtility); if (chosenAlternative == null) { Global.PrintFile.WriteNoAlternativesAvailableWarning(CHOICE_MODEL_NAME, "Run", trip.PersonDay.Id); trip.Mode = Global.Settings.Modes.Hov3; trip.PersonDay.IsValid = false; return; } var choice = (int)chosenAlternative.Choice; trip.Mode = choice; if (choice == Global.Settings.Modes.SchoolBus) { trip.PathType = 0; } else { var chosenPathType = pathTypeModels.First(x => x.Mode == choice); trip.PathType = chosenPathType.PathType; // for transit trips, overwrite origin and destination zones with stop area ids if (Global.StopAreaIsEnabled && choice == Global.Settings.Modes.Transit && Global.Configuration.WriteStopAreaIDsInsteadOfZonesForTransitTrips) { trip.OriginZoneKey = chosenPathType.PathOriginStopAreaKey; trip.DestinationZoneKey = chosenPathType.PathDestinationStopAreaKey; } } } }
public int[] Run(HouseholdDayWrapper householdDay, int nCallsForTour, int[] purpose, bool[,] jTParticipation) { if (householdDay == null) { throw new ArgumentNullException("householdDay"); } // array associating alternative with the participation of each HH person in the joint half tour // also identifies minimum housheold size and number of participants for each alternative //[alt,p1,p2,p3,p4,p5,p6,p7,p8,MinHHSize,numPart] int[][] altParticipants = new int[32][]; altParticipants[0] = new int[] { 0, 0, 0, 0, 0, 0, 2, 0 }; altParticipants[1] = new int[] { 1, 1, 0, 0, 0, 0, 2, 1 }; altParticipants[2] = new int[] { 2, 0, 1, 0, 0, 0, 2, 1 }; altParticipants[3] = new int[] { 3, 1, 1, 0, 0, 0, 2, 2 }; altParticipants[4] = new int[] { 4, 0, 0, 1, 0, 0, 3, 1 }; altParticipants[5] = new int[] { 5, 1, 0, 1, 0, 0, 3, 2 }; altParticipants[6] = new int[] { 6, 0, 1, 1, 0, 0, 3, 2 }; altParticipants[7] = new int[] { 7, 1, 1, 1, 0, 0, 3, 3 }; altParticipants[8] = new int[] { 8, 0, 0, 0, 1, 0, 4, 1 }; altParticipants[9] = new int[] { 9, 1, 0, 0, 1, 0, 4, 2 }; altParticipants[10] = new int[] { 10, 0, 1, 0, 1, 0, 4, 2 }; altParticipants[11] = new int[] { 11, 1, 1, 0, 1, 0, 4, 3 }; altParticipants[12] = new int[] { 12, 0, 0, 1, 1, 0, 4, 2 }; altParticipants[13] = new int[] { 13, 1, 0, 1, 1, 0, 4, 3 }; altParticipants[14] = new int[] { 14, 0, 1, 1, 1, 0, 4, 3 }; altParticipants[15] = new int[] { 15, 1, 1, 1, 1, 0, 4, 4 }; altParticipants[16] = new int[] { 16, 0, 0, 0, 0, 1, 5, 1 }; altParticipants[17] = new int[] { 17, 1, 0, 0, 0, 1, 5, 2 }; altParticipants[18] = new int[] { 18, 0, 1, 0, 0, 1, 5, 2 }; altParticipants[19] = new int[] { 19, 1, 1, 0, 0, 1, 5, 3 }; altParticipants[20] = new int[] { 20, 0, 0, 1, 0, 1, 5, 2 }; altParticipants[21] = new int[] { 21, 1, 0, 1, 0, 1, 5, 3 }; altParticipants[22] = new int[] { 22, 0, 1, 1, 0, 1, 5, 3 }; altParticipants[23] = new int[] { 23, 1, 1, 1, 0, 1, 5, 4 }; altParticipants[24] = new int[] { 24, 0, 0, 0, 1, 1, 5, 2 }; altParticipants[25] = new int[] { 25, 1, 0, 0, 1, 1, 5, 3 }; altParticipants[26] = new int[] { 26, 0, 1, 0, 1, 1, 5, 3 }; altParticipants[27] = new int[] { 27, 1, 1, 0, 1, 1, 5, 4 }; altParticipants[28] = new int[] { 28, 0, 0, 1, 1, 1, 5, 3 }; altParticipants[29] = new int[] { 29, 1, 0, 1, 1, 1, 5, 4 }; altParticipants[30] = new int[] { 30, 0, 1, 1, 1, 1, 5, 4 }; altParticipants[31] = new int[] { 31, 1, 1, 1, 1, 1, 5, 5 }; householdDay.ResetRandom(941 + nCallsForTour); IEnumerable <PersonDayWrapper> orderedPersonDays = householdDay.PersonDays.OrderBy(p => p.GetJointTourParticipationPriority()).ToList().Cast <PersonDayWrapper>(); int choice = 0; var hhsize = householdDay.Household.Size; if (Global.Configuration.IsInEstimationMode) { int i = 0; foreach (PersonDayWrapper personDay in orderedPersonDays) { i++; if (i <= 5) { choice = choice + (jTParticipation[nCallsForTour, personDay.Person.Sequence] == true ? 1 : 0) * (int)Math.Pow(2, i - 1); } } if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME) { return(altParticipants[choice]); } } var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator(((householdDay.Household.Id * 10 + householdDay.Day) * 397) ^ nCallsForTour); if (_helpers[ParallelUtility.GetBatchFromThreadId()].ModelIsInEstimationMode) { RunModel(choiceProbabilityCalculator, householdDay, nCallsForTour, purpose, altParticipants, choice); choiceProbabilityCalculator.WriteObservation(); return(altParticipants[choice]); } else if (Global.Configuration.TestEstimationModelInApplicationMode) { Global.Configuration.IsInEstimationMode = false; //choice = Math.Min(personDay.BusinessStops, 1) + 2 * Math.Min(personDay.SchoolStops, 1); RunModel(choiceProbabilityCalculator, householdDay, nCallsForTour, purpose, altParticipants); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(householdDay.Household.RandomUtility, householdDay.Household.Id, choice); Global.Configuration.IsInEstimationMode = true; return(altParticipants[choice]); } else { RunModel(choiceProbabilityCalculator, householdDay, nCallsForTour, purpose, altParticipants); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(householdDay.Household.RandomUtility); if (chosenAlternative == null) { Global.PrintFile.WriteNoAlternativesAvailableWarning(CHOICE_MODEL_NAME, "Run", householdDay.Household.Id); if (!Global.Configuration.IsInEstimationMode) { householdDay.IsValid = false; } return(null); } choice = (int)chosenAlternative.Choice; return(altParticipants[choice]); } }
public void Run(IHouseholdDayWrapper householdDay, ITourWrapper tour, int constrainedMode, int constrainedArrivalTime, int constrainedDepartureTime) { if (tour == null) { throw new ArgumentNullException("tour"); } //HTourModeTime.InitializeTourModeTimes(); tour.PersonDay.ResetRandom(50 + tour.Sequence - 1); if (Global.Configuration.IsInEstimationMode) { if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME) { return; } // JLB 20140421 add the following to keep from estimatign twice for the same tour if (tour.DestinationModeAndTimeHaveBeenSimulated) { return; } if (tour.DestinationParcel == null || tour.OriginParcel == null || tour.Mode < Global.Settings.Modes.Walk || tour.Mode > Global.Settings.Modes.SchoolBus) { return; } } // set remaining inputs HTourModeTime.SetModeTimeImpedances(householdDay, tour, constrainedMode, constrainedArrivalTime, constrainedDepartureTime, -1, -1.0); var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator(tour.Id); if (_helpers[ParallelUtility.GetBatchFromThreadId()].ModelIsInEstimationMode) { var observedChoice = new HTourModeTime(tour.Mode, tour.DestinationArrivalTime, tour.DestinationDepartureTime); RunModel(choiceProbabilityCalculator, householdDay, tour, tour.DestinationParcel, tour.Household.VehiclesAvailable, constrainedMode, constrainedArrivalTime, constrainedDepartureTime, observedChoice); choiceProbabilityCalculator.WriteObservation(); } else if (Global.Configuration.TestEstimationModelInApplicationMode) { Global.Configuration.IsInEstimationMode = false; RunModel(choiceProbabilityCalculator, householdDay, tour, tour.DestinationParcel, tour.Household.VehiclesAvailable, constrainedMode, constrainedArrivalTime, constrainedDepartureTime); var observedChoice = new HTourModeTime(tour.Mode, tour.DestinationArrivalTime, tour.DestinationDepartureTime); var simulatedChoice = choiceProbabilityCalculator.SimulateChoice(tour.Household.RandomUtility, tour.Id, observedChoice.Index); Global.Configuration.IsInEstimationMode = true; } else { HTourModeTime choice; if (constrainedMode > 0 && constrainedArrivalTime > 0 && constrainedDepartureTime > 0) { choice = new HTourModeTime(constrainedMode, constrainedArrivalTime, constrainedDepartureTime); } else { RunModel(choiceProbabilityCalculator, householdDay, tour, tour.DestinationParcel, tour.Household.VehiclesAvailable, constrainedMode, constrainedArrivalTime, constrainedDepartureTime); var simulatedChoice = choiceProbabilityCalculator.SimulateChoice(tour.Household.RandomUtility); if (simulatedChoice == null) { Global.PrintFile.WriteNoAlternativesAvailableWarning(CHOICE_MODEL_NAME, "Run", tour.PersonDay.Id); if (!Global.Configuration.IsInEstimationMode) { tour.PersonDay.IsValid = false; tour.PersonDay.HouseholdDay.IsValid = false; } return; } choice = (HTourModeTime)simulatedChoice.Choice; } tour.Mode = choice.Mode; var arrivalPeriod = choice.ArrivalPeriod; var departurePeriod = choice.DeparturePeriod; //use constrained times to set temporary arrival and departure times with minimum duration of stay for time window calculations if (constrainedArrivalTime > 0 || constrainedDepartureTime > 0) { if (constrainedArrivalTime > 0) { tour.DestinationArrivalTime = constrainedArrivalTime; } else { tour.DestinationArrivalTime = Math.Min(arrivalPeriod.End, constrainedDepartureTime - Global.Settings.Times.MinimumActivityDuration); } if (constrainedDepartureTime > 0) { tour.DestinationDepartureTime = constrainedDepartureTime; } else { tour.DestinationDepartureTime = Math.Max(departurePeriod.Start, constrainedArrivalTime + Global.Settings.Times.MinimumActivityDuration); } } //or if times aren't constrained use periods to set temporary arrival and departure times with minimum duration of stay for time window calculations else if (arrivalPeriod == departurePeriod) { var departureTime = Math.Max(choice.GetRandomDepartureTime(householdDay, tour), departurePeriod.Start + Global.Settings.Times.MinimumActivityDuration); tour.DestinationArrivalTime = departureTime - Global.Settings.Times.MinimumActivityDuration; tour.DestinationDepartureTime = departureTime; } else if (arrivalPeriod.End == departurePeriod.Start - 1) { tour.DestinationArrivalTime = arrivalPeriod.End; tour.DestinationDepartureTime = arrivalPeriod.End + Global.Settings.Times.MinimumActivityDuration; } else { tour.DestinationArrivalTime = arrivalPeriod.End; tour.DestinationDepartureTime = departurePeriod.Start; } } }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, IHouseholdDayWrapper householdDay, ITourWrapper tour, IParcelWrapper destinationParcel, int householdCars, int constrainedMode, int constrainedArrivalTime, int constrainedDepartureTime, HTourModeTime choice = null) { var household = tour.Household; var person = tour.Person; var personDay = tour.PersonDay; var householdTotals = household.HouseholdTotals; // household inputs var childrenUnder5 = householdTotals.ChildrenUnder5; var childrenAge5Through15 = householdTotals.ChildrenAge5Through15; var nonworkingAdults = householdTotals.NonworkingAdults; var retiredAdults = householdTotals.RetiredAdults; var onePersonHouseholdFlag = household.IsOnePersonHousehold.ToFlag(); var twoPersonHouseholdFlag = household.IsTwoPersonHousehold.ToFlag(); //var householdCars = household.VehiclesAvailable; MABADD now an input parameter var noCarsInHouseholdFlag = household.GetFlagForNoCarsInHousehold(householdCars); var carsLessThanDriversFlag = household.GetFlagForCarsLessThanDrivers(householdCars); var carsLessThanWorkersFlag = household.GetFlagForCarsLessThanWorkers(householdCars); var income0To25KFlag = household.Has0To25KIncome.ToFlag(); var income100KPlusFlag = household.Has100KPlusIncome.ToFlag(); // person inputs var partTimeWorkerFlag = person.IsPartTimeWorker.ToFlag(); var nonworkingAdultFlag = person.IsNonworkingAdult.ToFlag(); var universityStudentFlag = person.IsUniversityStudent.ToFlag(); var retiredAdultFlag = person.IsRetiredAdult.ToFlag(); var drivingAgeStudentFlag = person.IsDrivingAgeStudent.ToFlag(); var fulltimeWorkerFlag = person.IsFulltimeWorker.ToFlag(); var childAge5Through15Flag = person.IsChildAge5Through15.ToFlag(); var childUnder5Flag = person.IsChildUnder5.ToFlag(); var maleFlag = person.IsMale.ToFlag(); var ageUnder30Flag = person.AgeIsLessThan30.ToFlag(); var ageBetween51And98Flag = person.AgeIsBetween51And98.ToFlag(); var adultFlag = person.IsAdult.ToFlag(); // person-day inputs var homeBasedToursOnlyFlag = (personDay == null)? 1 : personDay.OnlyHomeBasedToursExist().ToFlag(); var firstSimulatedHomeBasedTourFlag = (personDay == null)? 1 : personDay.IsFirstSimulatedHomeBasedTour().ToFlag(); var laterSimulatedHomeBasedTourFlag = (personDay == null)? 0 : personDay.IsLaterSimulatedHomeBasedTour().ToFlag(); var totalStops = (personDay == null)? 0 : personDay.GetTotalStops(); var totalSimulatedStops = (personDay == null)? 0 : personDay.GetTotalSimulatedStops(); var escortStops = (personDay == null)? 0 : personDay.EscortStops; var homeBasedTours = (personDay == null)? 1 : personDay.HomeBasedTours; var simulatedHomeBasedTours = (personDay == null)? 0 : personDay.SimulatedHomeBasedTours; // tour inputs var escortTourFlag = tour.IsEscortPurpose().ToFlag(); var shoppingTourFlag = tour.IsShoppingPurpose().ToFlag(); var mealTourFlag = tour.IsMealPurpose().ToFlag(); var socialTourFlag = tour.IsSocialPurpose().ToFlag(); var personalBusinessTourFlag = tour.IsPersonalBusinessPurpose().ToFlag(); var recreationTourFlag = tour.IsRecreationPurpose().ToFlag(); var medicalTourFlag = tour.IsMedicalPurpose().ToFlag(); var originParcel = tour.OriginParcel; //var destinationParcel = tour.DestinationParcel; MABADD now an input parameter var jointTourFlag = (tour.JointTourSequence > 0) ? 1 : 0; var partialHalfTour1Flag = (tour.PartialHalfTour1Sequence > 0) ? 1 : 0; var partialHalfTour2Flag = (tour.PartialHalfTour2Sequence > 0) ? 1 : 0; var fullHalfTour1Flag = (tour.FullHalfTour1Sequence > 0) ? 1 : 0; var fullHalfTour2Flag = (tour.FullHalfTour2Sequence > 0) ? 1 : 0; var parentTourMode = tour.ParentTour == null ? 0 : tour.ParentTour.Mode; // remaining inputs // Higher priority tour of 2+ tours for the same purpose var highPrioritySameFlag = (personDay == null)? 1 : (tour.GetTotalToursByPurpose() > tour.GetTotalSimulatedToursByPurpose() && tour.GetTotalSimulatedToursByPurpose() == 1).ToFlag(); // Lower priority tour(s) of 2+ tours for the same purpose var lowPrioritySameFlag = (personDay == null)? 0 : (tour.GetTotalSimulatedToursByPurpose() > 1).ToFlag(); // Higher priority tour of 2+ tours for different purposes var highPriorityDifferentFlag = (personDay == null)? 0 : (personDay.IsFirstSimulatedHomeBasedTour() && personDay.HomeBasedToursExist()).ToFlag() * (1 - highPrioritySameFlag); // Lower priority tour of 2+ tours for different purposes var lowPriorityDifferentFlag = (personDay == null)? 0 : (personDay.IsLaterSimulatedHomeBasedTour() && personDay.HomeBasedToursExist()).ToFlag() * (1 - lowPrioritySameFlag); var timeWindow = (householdDay == null) ? new TimeWindow() : tour.GetRelevantTimeWindow(householdDay); var 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 (var arrivalPeriodIndex = 0; arrivalPeriodIndex < bigPeriodCount; arrivalPeriodIndex++) { var arrivalPeriod = DayPeriod.HBigDayPeriods[arrivalPeriodIndex]; var arrivalPeriodAvailableMinutes = timeWindow.TotalAvailableMinutes(arrivalPeriod.Start, arrivalPeriod.End); for (var departurePeriodIndex = arrivalPeriodIndex; departurePeriodIndex < bigPeriodCount; departurePeriodIndex++) { var departurePeriod = DayPeriod.HBigDayPeriods[departurePeriodIndex]; var departurePeriodAvailableMinutes = timeWindow.TotalAvailableMinutes(departurePeriod.Start, departurePeriod.End); if (arrivalPeriod == departurePeriod) { componentIndex = arrivalPeriodIndex; choiceProbabilityCalculator.CreateUtilityComponent(componentIndex); var arrivalComponent = choiceProbabilityCalculator.GetUtilityComponent(componentIndex); if (arrivalPeriodAvailableMinutes > 0) { var hoursArrival = arrivalPeriod.Middle / 60.0; var 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); var 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); var combinationComponent = choiceProbabilityCalculator.GetUtilityComponent(componentIndex); if (arrivalPeriodAvailableMinutes > 0 && departurePeriodAvailableMinutes > 0) { var hoursDuration = (departurePeriod.Middle - arrivalPeriod.Middle) / 60.0; var 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 (var mode = Global.Settings.Modes.Walk; mode <= Global.Settings.Modes.SchoolBus; mode++) { componentIndex = 2 * bigPeriodCount + nPeriodCombs + mode - 1; choiceProbabilityCalculator.CreateUtilityComponent(componentIndex); var 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) { var 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 (var modeTimes in HTourModeTime.ModeTimes[ParallelUtility.GetBatchFromThreadId()]) { var arrivalPeriod = modeTimes.ArrivalPeriod; var arrivalPeriodAvailableMinutes = timeWindow.TotalAvailableMinutes(arrivalPeriod.Start, arrivalPeriod.End); var departurePeriod = modeTimes.DeparturePeriod; var departurePeriodAvailableMinutes = timeWindow.TotalAvailableMinutes(departurePeriod.Start, departurePeriod.End); periodComb = modeTimes.PeriodCombinationIndex; var mode = modeTimes.Mode; var 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)); var alternative = choiceProbabilityCalculator.GetAlternative(altIndex, available, choice != null && choice.Index == altIndex); alternative.Choice = modeTimes; // JLB added 20130420 alternative.AddNestedAlternative(HTourModeTime.TotalTourModeTimes + 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 var 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 var destinationParkingCost = (!Global.Configuration.IsInEstimationMode && Global.Configuration.ShouldRunPayToParkAtWorkplaceModel && tour.Person.UsualWorkParcel != null && destinationParcel == tour.Person.UsualWorkParcel && person.PaidParkingAtWorkplace == 0) ? 0.0 : destinationParcel.ParkingCostBuffer1(parkingDuration); var 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; var 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(840, 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(840, modeTimes.LongestFeasibleWindow.End - modeTimes.LongestFeasibleWindow.Start)), 1.2) ))); //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 void Run(ITourWrapper tour) { if (tour == null) { throw new ArgumentNullException("tour"); } tour.PersonDay.ResetRandom(40 + tour.Sequence - 1); if (Global.Configuration.IsInEstimationMode) { if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME) { return; } } var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator(tour.Id); if (_helpers[ParallelUtility.GetBatchFromThreadId()].ModelIsInEstimationMode) { if (tour.DestinationParcel == null || tour.Mode <= Global.Settings.Modes.None || tour.Mode > Global.Settings.Modes.Transit) { return; } IEnumerable <dynamic> pathTypeModels = PathTypeModelFactory.Model.RunAll( tour.Household.RandomUtility, tour.OriginParcel, tour.DestinationParcel, tour.DestinationArrivalTime, tour.DestinationDepartureTime, tour.DestinationPurpose, tour.CostCoefficient, tour.TimeCoefficient, tour.Person.IsDrivingAge, tour.Household.VehiclesAvailable, tour.Person.GetTransitFareDiscountFraction(), false); var pathTypeModel = pathTypeModels.First(x => x.Mode == tour.Mode); if (!pathTypeModel.Available) { return; } RunModel(choiceProbabilityCalculator, tour, pathTypeModels, tour.DestinationParcel, tour.Mode); choiceProbabilityCalculator.WriteObservation(); } else { IEnumerable <dynamic> pathTypeModels = PathTypeModelFactory.Model.RunAll( tour.Household.RandomUtility, tour.OriginParcel, tour.DestinationParcel, tour.DestinationArrivalTime, tour.DestinationDepartureTime, tour.DestinationPurpose, tour.CostCoefficient, tour.TimeCoefficient, tour.Person.IsDrivingAge, tour.Household.VehiclesAvailable, tour.Person.GetTransitFareDiscountFraction(), false); RunModel(choiceProbabilityCalculator, tour, pathTypeModels, tour.DestinationParcel); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(tour.Household.RandomUtility); if (chosenAlternative == null) { Global.PrintFile.WriteNoAlternativesAvailableWarning(CHOICE_MODEL_NAME, "Run", tour.PersonDay.Id); tour.Mode = Global.Settings.Modes.Hov3; tour.PersonDay.IsValid = false; return; } var choice = (int)chosenAlternative.Choice; tour.Mode = choice; var chosenPathType = pathTypeModels.First(x => x.Mode == choice); tour.PathType = chosenPathType.PathType; tour.ParkAndRideNodeId = choice == Global.Settings.Modes.ParkAndRide ? chosenPathType.PathParkAndRideNodeId : 0; } }