public DayPattern(PersonDayWrapper personDay) { Tours = new int[Global.Settings.Purposes.TotalPurposes]; WorkTours = Tours[Global.Settings.Purposes.Work] = personDay.WorkTours > 0 ? 1 : 0; SchoolTours = Tours[Global.Settings.Purposes.School] = personDay.SchoolTours > 0 ? 1 : 0; BusinessTours = Tours[Global.Settings.Purposes.Business] = personDay.BusinessTours > 0 ? 1 : 0; EscortTours = Tours[Global.Settings.Purposes.Escort] = personDay.EscortTours > 0 ? 1 : 0; PersonalBusinessTours = Tours[Global.Settings.Purposes.PersonalBusiness] = personDay.PersonalBusinessTours > 0 ? 1 : 0; ShoppingTours = Tours[Global.Settings.Purposes.Shopping] = personDay.ShoppingTours > 0 ? 1 : 0; SocialTours = Tours[Global.Settings.Purposes.Social] = personDay.SocialTours > 0 ? 1 : 0; TotalTourPurposes = WorkTours + SchoolTours + BusinessTours + EscortTours + PersonalBusinessTours + ShoppingTours + SocialTours; Stops = new int[Global.Settings.Purposes.TotalPurposes]; WorkStops = Stops[Global.Settings.Purposes.Work] = personDay.WorkStops > 0 ? 1 : 0; SchoolStops = Stops[Global.Settings.Purposes.School] = personDay.SchoolStops > 0 ? 1 : 0; BusinessStops = Stops[Global.Settings.Purposes.Business] = personDay.BusinessStops > 0 ? 1 : 0; EscortStops = Stops[Global.Settings.Purposes.Escort] = personDay.EscortStops > 0 ? 1 : 0; PersonalBusinessStops = Stops[Global.Settings.Purposes.PersonalBusiness] = personDay.PersonalBusinessStops > 0 ? 1 : 0; ShoppingStops = Stops[Global.Settings.Purposes.Shopping] = personDay.ShoppingStops > 0 ? 1 : 0; SocialStops = Stops[Global.Settings.Purposes.Social] = personDay.SocialStops > 0 ? 1 : 0; TotalStopPurposes = WorkStops + SchoolStops + BusinessStops + EscortStops + PersonalBusinessStops + ShoppingStops + SocialStops; Available = true; _hashCode = ComputeHashCode(); }
public static void SignalShutdown() { if (ThreadQueue == null) { return; } ThreadQueue.Shutdown(); HouseholdWrapper.Close(); PersonWrapper.Close(); HouseholdDayWrapper.Close(); PersonDayWrapper.Close(); TourWrapper.Close(); TripWrapper.Close(); if (!string.IsNullOrEmpty(Global.Configuration.OutputJointTourPath)) { JointTourWrapper.Close(); } if (!string.IsNullOrEmpty(Global.Configuration.OutputFullHalfTourPath)) { FullHalfTourWrapper.Close(); } if (!string.IsNullOrEmpty(Global.Configuration.OutputPartialHalfTourPath)) { PartialHalfTourWrapper.Close(); } }
public void Run(PersonDayWrapper personDay, HouseholdDayWrapper 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; } } var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetChoiceProbabilityCalculator(personDay.Person.Id * 10 + personDay.Day); if (_helpers[ParallelUtility.GetBatchFromThreadId()].ModelIsInEstimationMode) { choice = Math.Min(personDay.BusinessStops, 1) + 2 * Math.Min(personDay.SchoolStops, 1); RunModel(choiceProbabilityCalculator, personDay, householdDay, 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, personDay, householdDay); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(householdDay.Household.RandomUtility, personDay.Id, choice); Global.Configuration.IsInEstimationMode = true; } else { RunModel(choiceProbabilityCalculator, personDay, householdDay); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(householdDay.Household.RandomUtility); choice = (int)chosenAlternative.Choice; if (choice == 1 || choice == 3) { personDay.BusinessStops = 1; } if (choice == 2 || choice == 3) { personDay.SchoolStops = 1; } } }
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.threadLocalAssignedIndex.Value].GetChoiceProbabilityCalculator(personDay.Person.Id * 10 + personDay.Day); if (_helpers[ParallelUtility.threadLocalAssignedIndex.Value].ModelIsInEstimationMode) { choice = personDay.PatternType; RunModel(choiceProbabilityCalculator, personDay, householdDay, choice); choiceProbabilityCalculator.WriteObservation(); } else if (Global.Configuration.TestEstimationModelInApplicationMode) { Global.Configuration.IsInEstimationMode = false; //choice = personDay.PatternType; RunModel(choiceProbabilityCalculator, personDay, householdDay); //var observedChoice = new HTourModeTime(tour.Mode, tour.DestinationArrivalTime, tour.DestinationDepartureTime); //var simulatedChoice = choiceProbabilityCalculator.SimulateChoice(householdDay.Household.RandomUtility, householdDay.Household.Id, altPTypes.); //var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(householdDay.Household.RandomUtility, householdDay.Household.Id, choice); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(householdDay.Household.RandomUtility, personDay.Id, personDay.PatternType - 1); Global.Configuration.IsInEstimationMode = true; } else { RunModel(choiceProbabilityCalculator, personDay, householdDay); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(householdDay.Household.RandomUtility); choice = (int)chosenAlternative.Choice; personDay.PatternType = choice; } }
public void TestPersonDayWrapper() { Global.Configuration = new Configuration { HouseholdSamplingRateOneInX = 1 }; PersonDayWrapper wrapper = TestHelper.GetPersonDayWrapper(); }
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.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 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(PersonDayWrapper personDay, HouseholdDayWrapper 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 if (Global.Configuration.TestEstimationModelInApplicationMode) { Global.Configuration.IsInEstimationMode = false; RunModel(choiceProbabilityCalculator, personDay, householdDay); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(householdDay.Household.RandomUtility, personDay.Id, personDay.WorksAtHomeFlag); Global.Configuration.IsInEstimationMode = true; } 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 TestTourWrapper2() { Global.Configuration = new Configuration { HouseholdSamplingRateOneInX = 1 }; PersonWrapper person = TestHelper.GetPersonWrapper(); PersonDayWrapper personDay = TestHelper.GetPersonDayWrapper(personWrapper: person, income: -1); CondensedParcel originParcel = new CondensedParcel(); CondensedParcel destinationParcel = new CondensedParcel(); int destinationDepartureTime = 1; int destinationPurpose = Constants.Purpose.BUSINESS; int destinationArrivalTime = 3; Global.Configuration.Coefficients_BaseCostCoefficientIncomeLevel = 25000; Global.Configuration.Coefficients_StdDeviationTimeCoefficient_Other = .75; Global.Configuration.Coefficients_MeanTimeCoefficient_Other = .45; Global.Configuration.Coefficients_BaseCostCoefficientPerMonetaryUnit = 5; Tour subtour = new Tour(); TourWrapper tour = new TourWrapper(person, personDay, originParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, destinationPurpose); TourWrapper wrapper = new TourWrapper(subtour, tour); Assert.Equal(tour, wrapper.ParentTour); Assert.Equal(1261, wrapper.DestinationDepartureTime); Assert.Equal(1261, wrapper.DestinationArrivalTime); Assert.Equal(0, wrapper.DestinationPurpose); Assert.Equal(null, wrapper.DestinationParcel); Assert.Equal(null, wrapper.OriginParcel); Assert.Equal(person, wrapper.Person); Assert.Equal(personDay, wrapper.PersonDay); Assert.Equal(0, wrapper.DestinationAddressType); Assert.Equal(null, wrapper.DestinationArrivalBigPeriod); Assert.Equal(false, wrapper.DestinationModeAndTimeHaveBeenSimulated); Assert.Equal(0, wrapper.DestinationParcelId); Assert.Equal(0, wrapper.DestinationZoneKey); Assert.Equal(0, wrapper.EarliestOriginDepartureTime); Assert.Equal(0, wrapper.FullHalfTour1Sequence); Assert.Equal(0, wrapper.FullHalfTour2Sequence); Assert.Equal(null, wrapper.GetHalfTour(Constants.TourDirection.DESTINATION_TO_ORIGIN)); Assert.Equal(null, wrapper.GetHalfTour(Constants.TourDirection.ORIGIN_TO_DESTINATION)); Assert.Equal(false, wrapper.HalfTour1HasBeenSimulated); Assert.Equal(0, wrapper.HalfTour1Trips); Assert.Equal(false, wrapper.HalfTour2HasBeenSimulated); Assert.Equal(0, wrapper.HalfTour2Trips); // Assert.Equal(false, wrapper.HasSubtours); Assert.Equal(0, wrapper.IndicatedTravelTimeFromDestination); Assert.Equal(0, wrapper.IndicatedTravelTimeToDestination); Assert.Equal(false, wrapper.IsHomeBasedTour); Assert.Equal(false, wrapper.IsMissingData); Assert.Equal(false, wrapper.IsParkAndRideMode); }
public ChoiceProbabilityCalculator.Alternative RunNested(PersonDayWrapper personDay, IParcelWrapper originParcel, IParcelWrapper destinationParcel, int destinationArrivalTime, int destinationDepartureTime, int householdCars, int purpose) { if (personDay == null) { throw new ArgumentNullException("personDay"); } //var tour = (TourWrapper)_creator.CreateWrapper(personDay.Person, personDay, originParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, Global.Settings.Purposes.Work); TourWrapper tour = (TourWrapper)_creator.CreateWrapper(personDay.Person, personDay, originParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, purpose); return(RunNested(tour, destinationParcel, householdCars, personDay.Person.GetTransitFareDiscountFraction())); }
public void TestTourWrapperTimeCoefficient() { Global.Configuration = new Configuration { HouseholdSamplingRateOneInX = 1 }; PersonWrapper person = TestHelper.GetPersonWrapper(); PersonDayWrapper personDay = TestHelper.GetPersonDayWrapper(personWrapper: person, income: -1); CondensedParcel originParcel = new CondensedParcel(); CondensedParcel destinationParcel = new CondensedParcel(); int destinationDepartureTime = 1; int destinationPurpose = Constants.Purpose.SCHOOL; int destinationArrivalTime = 3; Global.Configuration.Coefficients_BaseCostCoefficientIncomeLevel = 25000; Global.Configuration.Coefficients_StdDeviationTimeCoefficient_Other = .75; Global.Configuration.Coefficients_MeanTimeCoefficient_Other = .45; Global.Configuration.Coefficients_StdDeviationTimeCoefficient_Work = .76; Global.Configuration.Coefficients_MeanTimeCoefficient_Work = .46; Global.Configuration.Coefficients_BaseCostCoefficientPerMonetaryUnit = 5; TourWrapper wrapper = new TourWrapper(person, personDay, originParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, destinationPurpose); Assert.Equal(.45, wrapper.TimeCoefficient); destinationPurpose = Constants.Purpose.WORK; wrapper = new TourWrapper(person, personDay, originParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, destinationPurpose); Assert.Equal(.46, wrapper.TimeCoefficient); Global.Configuration.UseRandomVotDistribution = true; wrapper = new TourWrapper(person, personDay, originParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, destinationPurpose); Assert.Equal(.46, wrapper.TimeCoefficient); //This constructor suppresses randomVOT person = TestHelper.GetPersonWrapper(); personDay = TestHelper.GetPersonDayWrapper(personWrapper: person, income: -1); destinationPurpose = Constants.Purpose.BUSINESS; Tour tour = new Tour(); wrapper = new TourWrapper(tour, personDay, destinationPurpose, false); Assert.Equal(-.001, wrapper.TimeCoefficient); //This constructor does not suppress randomVOT Global.Configuration.Coefficients_StdDeviationTimeCoefficient_Work = .8; Global.Configuration.Coefficients_MeanTimeCoefficient_Work = -.03; person = TestHelper.GetPersonWrapper(); personDay = TestHelper.GetPersonDayWrapper(personWrapper: person, income: -1); destinationPurpose = Constants.Purpose.WORK; tour = new Tour(); wrapper = new TourWrapper(tour, personDay, destinationPurpose, false); Assert.Equal(-.0303002, Math.Round(wrapper.TimeCoefficient, 7)); //This constructor does not suppress randomVOT }
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 static TourWrapper GetTourWrapper() { PersonWrapper person = TestHelper.GetPersonWrapper(); PersonDayWrapper personDay = TestHelper.GetPersonDayWrapper(personWrapper: person, income: -1); CondensedParcel originParcel = new CondensedParcel(); CondensedParcel destinationParcel = new CondensedParcel(); int destinationDepartureTime = 1; int destinationPurpose = Constants.Purpose.BUSINESS; int destinationArrivalTime = 3; Global.Configuration.Coefficients_BaseCostCoefficientIncomeLevel = 25000; Global.Configuration.Coefficients_StdDeviationTimeCoefficient_Other = .75; Global.Configuration.Coefficients_MeanTimeCoefficient_Other = .45; Global.Configuration.Coefficients_BaseCostCoefficientPerMonetaryUnit = 5; TourWrapper wrapper = new TourWrapper(person, personDay, originParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, destinationPurpose); return(wrapper); }
public void TestTourWrapperCostCoefficient() { Global.Configuration = new Configuration { HouseholdSamplingRateOneInX = 1 }; PersonWrapper person = TestHelper.GetPersonWrapper(); PersonDayWrapper personDay = TestHelper.GetPersonDayWrapper(personWrapper: person, income: -1); CondensedParcel originParcel = new CondensedParcel(); CondensedParcel destinationParcel = new CondensedParcel(); int destinationDepartureTime = 1; int destinationPurpose = Constants.Purpose.BUSINESS; int destinationArrivalTime = 3; Global.Configuration.Coefficients_BaseCostCoefficientIncomeLevel = 25000; Global.Configuration.Coefficients_StdDeviationTimeCoefficient_Other = .75; Global.Configuration.Coefficients_MeanTimeCoefficient_Other = .45; Global.Configuration.Coefficients_BaseCostCoefficientPerMonetaryUnit = 5; TourWrapper wrapper = new TourWrapper(person, personDay, originParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, destinationPurpose); Assert.Equal(5, wrapper.CostCoefficient); Global.Configuration.Coefficients_CostCoefficientIncomePower_Other = 2; wrapper = new TourWrapper(person, personDay, originParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, destinationPurpose); Assert.Equal(5, wrapper.CostCoefficient); person = TestHelper.GetPersonWrapper(income: 50000); personDay = TestHelper.GetPersonDayWrapper(income: 50000); wrapper = new TourWrapper(person, personDay, originParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, destinationPurpose); Assert.Equal(1.25, wrapper.CostCoefficient); Global.Configuration.Coefficients_CostCoefficientIncomePower_Other = 8; wrapper = new TourWrapper(person, personDay, originParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, destinationPurpose); Assert.Equal(5.0 / 256.0, wrapper.CostCoefficient); }
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; } } ChoiceProbabilityCalculator choiceProbabilityCalculator = _helpers[ParallelUtility.threadLocalAssignedIndex.Value].GetChoiceProbabilityCalculator(personDay.Person.Id * 10 + personDay.Day); if (_helpers[ParallelUtility.threadLocalAssignedIndex.Value].ModelIsInEstimationMode) { choice = personDay.PatternType; RunModel(choiceProbabilityCalculator, personDay, householdDay, choice); choiceProbabilityCalculator.WriteObservation(); } else { RunModel(choiceProbabilityCalculator, personDay, householdDay); ChoiceProbabilityCalculator.Alternative chosenAlternative = choiceProbabilityCalculator.SimulateChoice(householdDay.Household.RandomUtility); choice = (int)chosenAlternative.Choice; personDay.PatternType = choice; } }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, PersonDayWrapper personDay, HouseholdDayWrapper householdDay, int choice = Constants.DEFAULT_VALUE) { Framework.DomainModels.Wrappers.IHouseholdWrapper household = personDay.Household; Framework.DomainModels.Wrappers.IPersonWrapper person = personDay.Person; IEnumerable <PersonDayWrapper> personTypeOrderedPersonDays = householdDay.PersonDays.OrderBy(p => p.Person.PersonType).ToList().Cast <PersonDayWrapper>(); int mandatoryCount = 0; int nonMandatoryCount = 0; int homeCount = 0; int i = 0; foreach (PersonDayWrapper pDay in personTypeOrderedPersonDays) { i++; if (i <= 5) { if (pDay.PatternType == Global.Settings.PatternTypes.Mandatory) { mandatoryCount++; } else if (pDay.PatternType == Global.Settings.PatternTypes.Optional) { nonMandatoryCount++; } else { homeCount++; } } } bool mandatoryAvailableFlag = true; if (personDay.Person.IsNonworkingAdult || personDay.Person.IsRetiredAdult || (!personDay.Person.IsWorker && !personDay.Person.IsStudent) || (!Global.Configuration.IsInEstimationMode && !personDay.Person.IsWorker && personDay.Person.UsualSchoolParcel == null) ) { mandatoryAvailableFlag = false; } 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); int votALSegment = Global.Settings.VotALSegments.Medium; // TODO: calculate a VOT segment that depends on household income int transitAccessSegment = household.ResidenceParcel.TransitAccessSegment(); double personalBusinessAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId] [Global.Settings.Purposes.PersonalBusiness][carOwnership][votALSegment][transitAccessSegment]; double shoppingAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId] [Global.Settings.Purposes.Shopping][carOwnership][votALSegment][transitAccessSegment]; double mealAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId] [Global.Settings.Purposes.Meal][carOwnership][votALSegment][transitAccessSegment]; double socialAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId] [Global.Settings.Purposes.Social][carOwnership][votALSegment][transitAccessSegment]; //var compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][carOwnership][votALSegment][transitAccessSegment]; double compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.NoCars][votALSegment][transitAccessSegment]; // Pattern Type Mandatory on tour (at least one work or school tour) ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(0, mandatoryAvailableFlag, choice == 1); alternative.Choice = 1; alternative.AddUtilityTerm(1, 1); alternative.AddUtilityTerm(2, person.IsChildUnder5.ToFlag()); alternative.AddUtilityTerm(3, person.IsChildAge5Through15.ToFlag()); alternative.AddUtilityTerm(4, person.IsFulltimeWorker.ToFlag()); alternative.AddUtilityTerm(5, person.IsMale.ToFlag()); //alternative.AddUtilityTerm(4, person.IsPartTimeWorker.ToFlag()); alternative.AddUtilityTerm(7, householdDay.Household.HasChildrenUnder5.ToFlag()); alternative.AddUtilityTerm(8, householdDay.Household.HasChildrenAge5Through15.ToFlag()); alternative.AddUtilityTerm(10, (householdDay.AdultsInSharedHomeStay == 2 && householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag()); //alternative.AddUtilityTerm(14, (householdDay.AdultsInSharedHomeStay == 2).ToFlag()); //alternative.AddUtilityTerm(15, (householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag()); alternative.AddUtilityTerm(11, (householdDay.AdultsInSharedHomeStay == 1 && householdDay.Household.HasChildren).ToFlag()); //alternative.AddUtilityTerm(12, (householdDay.Household.Size == 2).ToFlag()); //GV; 16. april 2013, not significant //alternative.AddUtilityTerm(13, (householdDay.Household.Size == 3).ToFlag()); //GV; 16. april 2013, not significant //alternative.AddUtilityTerm(14, (householdDay.Household.Size >= 4).ToFlag()); //GV; 16. april 2013, not significant //alternative.AddUtilityTerm(12, (householdDay.Household.VehiclesAvailable == 1).ToFlag()); //alternative.AddUtilityTerm(13, (householdDay.Household.VehiclesAvailable >= 2).ToFlag()); //GV: not sign. 10. juni 2016 //alternative.AddUtilityTerm(15, (householdDay.Household.VehiclesAvailable == 1 && household.Has2Drivers).ToFlag()); alternative.AddUtilityTerm(16, (householdDay.Household.VehiclesAvailable >= 2 && household.Has2Drivers).ToFlag()); //GV: introduced again - 10. june 2016 //GV: logsum for mandatory - wrong sign //alternative.AddUtilityTerm(17, compositeLogsum); //alternative.AddUtilityTerm(17, (householdDay.Household.Income >= 300000 && householdDay.Household.Income < 600000).ToFlag()); //GV; 16. april 2013, not significant //alternative.AddUtilityTerm(18, (householdDay.Household.Income >= 600000 && householdDay.Household.Income < 900000).ToFlag()); //GV; 16. april 2013, not significant //alternative.AddUtilityTerm(19, (householdDay.Household.Income >= 900000).ToFlag()); //GV; 16. april 2013, not significant alternative.AddUtilityTerm(20, householdDay.PrimaryPriorityTimeFlag); //alternative.AddUtilityTerm(19, (mandatoryCount == 0)? 1 : 0); //GV - goes to infinity // PatternType NonMandatory on tour (tours, but none for work or school) alternative = choiceProbabilityCalculator.GetAlternative(1, true, choice == 2); alternative.Choice = 2; alternative.AddUtilityTerm(22, person.IsRetiredAdult.ToFlag()); alternative.AddUtilityTerm(23, person.IsNonworkingAdult.ToFlag()); //GV: not sign. 10. june 2016 //alternative.AddUtilityTerm(24, householdDay.Household.HasChildrenUnder5.ToFlag()); //alternative.AddUtilityTerm(25, householdDay.Household.HasChildrenAge5Through15.ToFlag()); //alternative.AddUtilityTerm(31, (householdDay.AdultsInSharedHomeStay == 2).ToFlag()); //alternative.AddUtilityTerm(33, (householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag()); alternative.AddUtilityTerm(26, (householdDay.AdultsInSharedHomeStay == 2 && householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag()); alternative.AddUtilityTerm(27, (householdDay.AdultsInSharedHomeStay == 1 && householdDay.Household.HasChildren).ToFlag()); //alternative.AddUtilityTerm(28, (householdDay.Household.Size == 2).ToFlag()); //GV; 16. april 2013, not significant //alternative.AddUtilityTerm(29, (householdDay.Household.Size == 3).ToFlag()); //GV; 16. april 2013, not significant //alternative.AddUtilityTerm(30, (householdDay.Household.Size >= 4).ToFlag()); //GV; 16. april 2013, not significant //alternative.AddUtilityTerm(27, (householdDay.Household.VehiclesAvailable == 1).ToFlag()); //alternative.AddUtilityTerm(28, (householdDay.Household.VehiclesAvailable >= 2).ToFlag()); alternative.AddUtilityTerm(31, (householdDay.Household.VehiclesAvailable == 1 && household.Has2Drivers).ToFlag()); alternative.AddUtilityTerm(32, (householdDay.Household.VehiclesAvailable >= 2 && household.Has2Drivers).ToFlag()); //alternative.AddUtilityTerm(33, compositeLogsum); //GV: logsum for non-mandatory //alternative.AddUtilityTerm(33, (householdDay.Household.Income >= 300000 && householdDay.Household.Income < 600000).ToFlag()); //GV; 16. april 2013, not significant //alternative.AddUtilityTerm(34, (householdDay.Household.Income >= 600000 && householdDay.Household.Income < 900000).ToFlag()); //GV; 16. april 2013, not significant //alternative.AddUtilityTerm(35, (householdDay.Household.Income >= 900000).ToFlag()); //GV; 16. april 2013, not significant alternative.AddUtilityTerm(36, householdDay.PrimaryPriorityTimeFlag); //alternative.AddUtilityTerm(24, person.IsChildUnder5.ToFlag()); //alternative.AddUtilityTerm(25, person.IsNonworkingAdult.ToFlag()); // PatternType Home (all day) alternative = choiceProbabilityCalculator.GetAlternative(2, true, choice == 3); alternative.Choice = 3; alternative.AddUtilityTerm(41, 1); alternative.AddUtilityTerm(42, person.WorksAtHome().ToFlag()); //GV: introduced again - 10. june 2016; not sign. //alternative.AddUtilityTerm(43, person.IsUniversityStudent.ToFlag()); //alternative.AddUtilityTerm(54, (homeCount > 0)? 1 : 0); //GV: can be estimated but the valus is huge }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, TourWrapper tour, HouseholdDayWrapper householdDay, int nCallsForTour, int choice = Constants.DEFAULT_VALUE) { PersonWrapper person = (PersonWrapper)tour.Person; PersonDayWrapper personDay = (PersonDayWrapper)tour.PersonDay; // var foodRetailServiceMedicalQtrMileLog = tour.DestinationParcel.FoodRetailServiceMedicalQtrMileLogBuffer1(); // var mixedUseIndex = tour.DestinationParcel.MixedUse4Index1(); double k8HighSchoolQtrMileLog = tour.DestinationParcel.K8HighSchoolQtrMileLogBuffer1(); //var carOwnership = person.CarOwnershipSegment; int carOwnership = 0; 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]; //var compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][carOwnership][votALSegment][transitAccessSegment]; //var compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.NoCars][votALSegment][transitAccessSegment]; // 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(1, (nCallsForTour > 1).ToFlag()); //alternative.AddUtilityTerm(2, Math.Log(personDay.HomeBasedTours)); //alternative.AddUtilityTerm(3, personDay.HasTwoOrMoreWorkTours.ToFlag()); //alternative.AddUtility(4, notUsualWorkParcelFlag); //alternative.AddUtilityTerm(5, noCarsFlag); //alternative.AddUtilityTerm(6, carCompetitionFlag); //alternative.AddUtilityTerm(7, householdDay.PrimaryPriorityTimeFlag); //alternative.AddUtilityTerm(9, householdDay.Household.HasChildrenUnder5.ToFlag()); //alternative.AddUtilityTerm(10, householdDay.Household.HasChildrenAge5Through15.ToFlag()); //alternative.AddUtilityTerm(11, (householdDay.Household.Size == 2).ToFlag()); //alternative.AddUtilityTerm(12, (householdDay.Household.Size == 2 && householdDay.AdultsInSharedHomeStay == 2).ToFlag()); //alternative.AddUtilityTerm(14, personDay.Person.WorksAtHome().ToFlag()); //alternative.AddUtilityTerm(15, personDay.Person.IsNonworkingAdult.ToFlag()); //alternative.AddUtilityTerm(15, (person.IsNonworkingAdult).ToFlag()); //out of scope, non available //alternative.AddUtilityTerm(32, workAggregateLogsum); //alternative.AddUtility(32, mixedUseIndex); // WORK-BASED alternative = choiceProbabilityCalculator.GetAlternative(1, true, choice == Global.Settings.Purposes.PersonalBusiness); alternative.Choice = Global.Settings.Purposes.PersonalBusiness; alternative.AddUtilityTerm(21, 1); //alternative.AddUtilityTerm(30, (person.IsWorker).ToFlag()); //alternative.AddUtilityTerm(22, (person.FlexibleWorkHours == 1).ToFlag()); //alternative.AddUtilityTerm(23, (person.EducationLevel >= 12).ToFlag()); //alternative.AddUtilityTerm(24, personDay.Person.IsPartTimeWorker.ToFlag()); //GV, 16. june 2016 - cannot be estimated //alternative.AddUtilityTerm(24, (person.WorksAtHome).ToFlag()); ////alternative.AddUtilityTerm(25, personDay.Person.IsFulltimeWorker.ToFlag()); //alternative.AddUtilityTerm(26, (person.MainOccupation == 50).ToFlag()); // self employed alternative.AddUtilityTerm(27, (personDay.Person.Gender == 1).ToFlag()); //alternative.AddUtilityTerm(44, (hasAdultEducLevel12 == 1).ToFlag()); //GV. 16. june 2016 - not signif. //alternative.AddUtilityTerm(28, (householdDay.Household.VehiclesAvailable == 1 && householdDay.Household.Has2Drivers).ToFlag()); //alternative.AddUtilityTerm(29, (householdDay.Household.VehiclesAvailable >= 2 && householdDay.Household.Has2Drivers).ToFlag()); alternative.AddUtilityTerm(30, householdDay.PrimaryPriorityTimeFlag); //GV. 16. june 2016 - not signif. //alternative.AddUtilityTerm(31, (householdDay.Household.Income >= 300000 && householdDay.Household.Income < 600000).ToFlag()); //alternative.AddUtilityTerm(32, (householdDay.Household.Income >= 600000 && householdDay.Household.Income < 900000).ToFlag()); //alternative.AddUtilityTerm(33, (householdDay.Household.Income >= 900000).ToFlag()); alternative.AddUtilityTerm(41, workAggregateLogsum); //alternative.AddUtilityTerm(36, (householdDay.Household.Size == 2).ToFlag()); //alternative.AddUtilityTerm(37, (householdDay.Household.Size == 3).ToFlag()); //alternative.AddUtilityTerm(38, (householdDay.Household.Size >= 4).ToFlag()); }
public void Run(PersonDayWrapper personDay, HouseholdDayWrapper householdDay) { DayPattern[] dayPatterns = new DayPattern[TOTAL_ALTERNATIVES]; if (householdDay.Household.Id == 80170 && personDay.Person.Sequence == 1) { bool testbreak = true; } if (personDay == null) { throw new ArgumentNullException("personDay"); } personDay.ResetRandom(948); if (Global.Configuration.IsInEstimationMode) { if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME) { DayPattern dayPattern = new DayPattern(personDay); if (dayPattern.EscortTours > 0 && personDay.CreatedEscortTours == 0) { personDay.CreatedEscortTours++; } if (dayPattern.PersonalBusinessTours > 0 && personDay.CreatedPersonalBusinessTours == 0) { personDay.CreatedPersonalBusinessTours++; } if (dayPattern.ShoppingTours > 0 && personDay.CreatedShoppingTours == 0) { personDay.CreatedShoppingTours++; } if (dayPattern.SocialTours > 0 && personDay.CreatedSocialTours == 0) { personDay.CreatedSocialTours++; } return; } } InitializeDayPatterns(personDay, dayPatterns); var choiceProbabilityCalculator = _helpers[ParallelUtility.threadLocalAssignedIndex.Value].GetChoiceProbabilityCalculator(personDay.Person.Id * 10 + personDay.Day); if (_helpers[ParallelUtility.threadLocalAssignedIndex.Value].ModelIsInEstimationMode) { DayPattern dayPattern = new DayPattern(personDay); RunModel(choiceProbabilityCalculator, personDay, householdDay, dayPatterns, dayPattern); if (dayPattern.EscortTours > 0 && personDay.CreatedEscortTours == 0) { personDay.CreatedEscortTours++; } if (dayPattern.PersonalBusinessTours > 0 && personDay.CreatedPersonalBusinessTours == 0) { personDay.CreatedPersonalBusinessTours++; } if (dayPattern.ShoppingTours > 0 && personDay.CreatedShoppingTours == 0) { personDay.CreatedShoppingTours++; } if (dayPattern.SocialTours > 0 && personDay.CreatedSocialTours == 0) { personDay.CreatedSocialTours++; } choiceProbabilityCalculator.WriteObservation(); } else { if (personDay.Person.UsualWorkParcelId != Global.Settings.OutOfRegionParcelId && personDay.Person.UsualSchoolParcelId != Global.Settings.OutOfRegionParcelId) { RunModel(choiceProbabilityCalculator, personDay, householdDay, dayPatterns); var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(personDay.Household.RandomUtility); if (chosenAlternative == null) { personDay.IsValid = false; householdDay.IsValid = false; return; } var dayPattern = (DayPattern)chosenAlternative.Choice; if (dayPattern.EscortTours > 0 && personDay.CreatedEscortTours == 0) { personDay.GetNewTour(Global.Settings.AddressTypes.Home, personDay.Household.ResidenceParcelId, personDay.Household.ResidenceZoneKey, Global.Settings.Purposes.Escort); personDay.CreatedEscortTours++; } if (dayPattern.PersonalBusinessTours > 0 && personDay.CreatedPersonalBusinessTours == 0) { personDay.GetNewTour(Global.Settings.AddressTypes.Home, personDay.Household.ResidenceParcelId, personDay.Household.ResidenceZoneKey, Global.Settings.Purposes.PersonalBusiness); personDay.CreatedPersonalBusinessTours++; } if (dayPattern.ShoppingTours > 0 && personDay.CreatedShoppingTours == 0) { personDay.GetNewTour(Global.Settings.AddressTypes.Home, personDay.Household.ResidenceParcelId, personDay.Household.ResidenceZoneKey, Global.Settings.Purposes.Shopping); personDay.CreatedShoppingTours++; } if (dayPattern.SocialTours > 0 && personDay.CreatedSocialTours == 0) { personDay.GetNewTour(Global.Settings.AddressTypes.Home, personDay.Household.ResidenceParcelId, personDay.Household.ResidenceZoneKey, Global.Settings.Purposes.Social); personDay.CreatedSocialTours++; } personDay.EscortStops = dayPattern.EscortStops; personDay.PersonalBusinessStops = dayPattern.PersonalBusinessStops; personDay.ShoppingStops = dayPattern.ShoppingStops; personDay.SocialStops = dayPattern.SocialStops; } } }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, PersonDayWrapper personDay, HouseholdDayWrapper householdDay, DayPattern[] dayPatterns, DayPattern choice = null) { var household = personDay.Household; var residenceParcel = household.ResidenceParcel; var person = personDay.Person; var carsPerDriver = household.GetCarsPerDriver(); var mixedDensity = residenceParcel.MixedUse3Index2(); var intersectionDensity = residenceParcel.IntersectionDensity34Minus1Buffer2(); var purposeLogsums = new double[Global.Settings.Purposes.TotalPurposes + 2]; var atUsualLogsums = new double[3]; //var carOwnership = person.CarOwnershipSegment; //GV: sat car ownership not to impact logsums var carOwnership = 0; var votSegment = person.Household.GetVotALSegment(); var transitAccess = residenceParcel.TransitAccessSegment(); //GV: input 26. july 2013 // 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; //var noCarsInHouseholdFlag = HouseholdWrapper.GetNoCarsInHouseholdFlag(householdCars); //var carsLessThanDriversFlag = household.GetCarsLessThanDriversFlag(householdCars); //var carsLessThanWorkersFlag = household.GetCarsLessThanWorkersFlag(householdCars); var HHwithChildrenFlag = household.HasChildren.ToFlag(); var HHwithSmallChildrenFlag = household.HasChildrenUnder5.ToFlag(); var HHwithLowIncomeFlag = (household.Income >= 300000 && household.Income < 600000).ToFlag(); var HHwithMidleIncomeFlag = (household.Income >= 600000 && household.Income < 900000).ToFlag(); var HHwithHighIncomeFlag = (household.Income >= 900000).ToFlag(); var primaryFamilyTimeFlag = householdDay.PrimaryPriorityTimeFlag; //GV: input 26. july 2013 // person inputs var partTimeWorkerFlag = person.IsPartTimeWorker.ToFlag(); var nonworkingAdultFlag = person.IsNonworkingAdult.ToFlag(); var universityStudentFlag = person.IsUniversityStudent.ToFlag(); var retiredAdultFlag = person.IsRetiredAdult.ToFlag(); var fullTimeWorkerFlag = person.IsFulltimeWorker.ToFlag(); var childAge5Through15Flag = person.IsChildAge5Through15.ToFlag(); var childUnder5Flag = person.IsChildUnder5.ToFlag(); var adultFlag = person.IsAdult.ToFlag(); var maleFlag = person.IsMale.ToFlag(); var femaleFlag = person.IsFemale.ToFlag(); if (person.UsualWorkParcel == null || person.UsualWorkParcelId == household.ResidenceParcelId) { purposeLogsums[Global.Settings.Purposes.Work] = 0; } else { var destinationArrivalTime = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.WorkTourModeModel); var destinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.WorkTourModeModel); //JLB 201406 //var nestedAlternative = Global.ChoiceModelSession.Get<WorkTourModeModel>().RunNested(personDay, residenceParcel, person.UsualWorkParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable); var nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().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 { var destinationArrivalTime = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.SchoolTourModeModel); var destinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.SchoolTourModeModel); //JLB 201406 //var nestedAlternative = Global.ChoiceModelSession.Get<SchoolTourModeModel>().RunNested(personDay, residenceParcel, person.UsualSchoolParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable); var nestedAlternative = Global.ChoiceModelSession.Get <SchoolTourModeTimeModel>().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()]; } var 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.Social] = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.Social][carOwnership][votSegment][transitAccess]; for (var xPurpose = Global.Settings.Purposes.Escort; 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 var 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. var 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); var component = choiceProbabilityCalculator.GetUtilityComponent(xPurpose); component.AddUtilityTerm(100 * purpose + 1, 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 * HHwithLowIncomeFlag); component.AddUtilityTerm(100 * purpose + 10, xMultiplier * HHwithMidleIncomeFlag); component.AddUtilityTerm(100 * purpose + 11, xMultiplier * HHwithHighIncomeFlag); //component.AddUtilityTerm(100 * purpose + 12, xMultiplier * carsPerDriver); component.AddUtilityTerm(100 * purpose + 12, xMultiplier * householdCars); 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 * primaryFamilyTimeFlag); //GV: wrong sign //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]); //GV: 17.08.2013, the logsums are wrong //component.AddUtilityTerm(100 * purpose + 28, xMultiplier * person.TransitPassOwnershipFlag); } // tour utility const int tourComponentIndex = 18; choiceProbabilityCalculator.CreateUtilityComponent(tourComponentIndex); var tourComponent = choiceProbabilityCalculator.GetUtilityComponent(tourComponentIndex); //tourComponent.AddUtilityTerm(1701, carsPerDriver); tourComponent.AddUtilityTerm(1701, householdCars); tourComponent.AddUtilityTerm(1702, person.WorksAtHome.ToFlag()); tourComponent.AddUtilityTerm(1703, mixedDensity); tourComponent.AddUtilityTerm(1704, mixedDensity * person.IsChildAge5Through15.ToFlag()); tourComponent.AddUtilityTerm(1705, compositeLogsum); //tourComponent.AddUtilityTerm(1706, person.TransitPassOwnershipFlag); tourComponent.AddUtilityTerm(1706, primaryFamilyTimeFlag); // stop utility const int stopComponentIndex = 19; choiceProbabilityCalculator.CreateUtilityComponent(stopComponentIndex); var stopComponent = choiceProbabilityCalculator.GetUtilityComponent(stopComponentIndex); //stopComponent.AddUtilityTerm(1711, carsPerDriver); stopComponent.AddUtilityTerm(1711, householdCars); stopComponent.AddUtilityTerm(1712, person.WorksAtHome.ToFlag()); stopComponent.AddUtilityTerm(1713, mixedDensity); stopComponent.AddUtilityTerm(1714, mixedDensity * person.IsChildAge5Through15.ToFlag()); stopComponent.AddUtilityTerm(1715, compositeLogsum); //stopComponent.AddUtilityTerm(1716, person.TransitPassOwnershipFlag); //stopComponent.AddUtilityTerm(1716, primaryFamilyTimeFlag); //GV: 17.08.2013, the logsums are wrong for (var alternativeIndex = 0; alternativeIndex < TOTAL_ALTERNATIVES; alternativeIndex++) { var dayPattern = dayPatterns[alternativeIndex]; var available = dayPattern.Available; var 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 (var purpose = Global.Settings.Purposes.Escort; 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 + 50, 1); // tour purpose ASC //alternative.AddUtilityTerm(100 * purpose + 51, purposeLogsums[purpose]); // tour purpose logsum GV: 17.08.2013, the logsums are wrong } if (dayPattern.Stops[purpose] > 0) { alternative.AddUtilityTerm(100 * purpose + 60, 1); // stop purpose ASC //alternative.AddUtilityTerm(100 * purpose + 61, purposeLogsums[purpose]); // stop purpose logsum GV: 17.08.2013, the logsums are wrong } if (Global.Configuration.IsInEstimationMode) { //GV commented out //alternative.AddUtilityTerm(100 * purpose + 70, 1 - person.PaperDiary); //GV commented out //alternative.AddUtilityTerm(100 * purpose + 71, person.ProxyResponse); } } } // multiple tour purposes component if (dayPattern.TotalTourPurposes > 1) { alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(Global.Settings.Purposes.Social + (dayPattern.TotalTourPurposes - 1))); } // multiple stop purposes component if (dayPattern.TotalStopPurposes > 1) { alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(Global.Settings.Purposes.Social + 5 + (dayPattern.TotalStopPurposes - 1))); } for (var tourPurpose = Global.Settings.Purposes.Work; tourPurpose <= Global.Settings.Purposes.Social; tourPurpose++) { for (var 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(1200 + 10 * tourPurpose + stopPurpose, 1); // tour-stop comb. utility } } } for (var tourPurpose = Global.Settings.Purposes.Work; tourPurpose <= Global.Settings.Purposes.School; tourPurpose++) { if (dayPattern.Tours[tourPurpose] == 1 && dayPattern.TotalStopPurposes >= 1) { alternative.AddUtilityTerm(1300 + 10 * tourPurpose, purposeLogsums[tourPurpose]); // usual location logsum x presence of stops in work or school pattern alternative.AddUtilityTerm(1300 + 10 * tourPurpose + 1, compositeLogsum); // home aggregate logsum x presence of stops in work or school pattern //alternative.AddUtilityTerm(1300 + 10 * tourPurpose + 2, atUsualLogsums[tourPurpose]); // at usual location aggregate logsum x presence of stops in work or school pattern GV: commented out as the sign is wrong } } for (var tourPurpose = Global.Settings.Purposes.Work; tourPurpose <= Global.Settings.Purposes.Social - 2; tourPurpose++) { for (var tourPurpose2 = tourPurpose + 1; tourPurpose2 <= Global.Settings.Purposes.Social; tourPurpose2++) { if (dayPattern.Tours[tourPurpose] > 0 && dayPattern.Tours[tourPurpose2] > 0) { alternative.AddUtilityTerm(1400 + 10 * tourPurpose + tourPurpose2, 1); // tour-tour comb. utility } } } for (var tourPurpose = Global.Settings.Purposes.Business; tourPurpose <= Global.Settings.Purposes.Business; tourPurpose++) { for (var tourPurpose2 = Global.Settings.Purposes.Escort; tourPurpose2 <= Global.Settings.Purposes.Social; tourPurpose2++) { if (dayPattern.Tours[tourPurpose] > 0 && dayPattern.Tours[tourPurpose2] > 0) { alternative.AddUtilityTerm(1461, 1); // tour-tour comb. utility for business combos } } } for (var stopPurpose = Global.Settings.Purposes.Work; stopPurpose <= Global.Settings.Purposes.Social - 2; stopPurpose++) { for (var stopPurpose2 = stopPurpose + 1; stopPurpose2 <= Global.Settings.Purposes.Social; stopPurpose2++) { if (dayPattern.Stops[stopPurpose] > 0 && dayPattern.Stops[stopPurpose2] > 0) { alternative.AddUtilityTerm(1500 + 10 * stopPurpose + stopPurpose2, 1); // stop-stop comb. utility } } } if (dayPattern.TotalTourPurposes > 0 && dayPattern.TotalStopPurposes > 0) { var totalStopPurposes = dayPattern.TotalStopPurposes; if (totalStopPurposes > 3) { totalStopPurposes = 3; } alternative.AddUtilityTerm(1600 + 10 * dayPattern.TotalTourPurposes + totalStopPurposes, 1); // nttour-ntstop utility } if (dayPattern.TotalTourPurposes - dayPattern.Tours[Global.Settings.Purposes.Work] - dayPattern.Tours[Global.Settings.Purposes.Business] - dayPattern.Tours[Global.Settings.Purposes.School] > 0) { // tour utility alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(tourComponentIndex)); } if (dayPattern.TotalStopPurposes - dayPattern.Stops[Global.Settings.Purposes.Work] - dayPattern.Stops[Global.Settings.Purposes.Business] - dayPattern.Stops[Global.Settings.Purposes.School] > 0) { // stop utility alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(stopComponentIndex)); } } }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, HouseholdDayWrapper householdDay, int nCallsForTour, int[] purpose, int[][] altParticipants, int choice = Constants.DEFAULT_VALUE) { IEnumerable<PersonDayWrapper> orderedPersonDays = householdDay.PersonDays.OrderBy(p => p.GetJointTourParticipationPriority()).ToList().Cast<PersonDayWrapper>(); // set household characteristics here that don't depend on person characteristics int 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; int noCarsFlag = FlagUtility.GetNoCarsFlag(carOwnership); int carCompetitionFlag = FlagUtility.GetCarCompetitionFlag(carOwnership); int tourPurpose = purpose[nCallsForTour]; int escortPurpose = purpose[nCallsForTour] == Global.Settings.Purposes.Escort ? 1 : 0; int shopPurpose = purpose[nCallsForTour] == Global.Settings.Purposes.Shopping ? 1 : 0; int socialPurpose = (purpose[nCallsForTour] == Global.Settings.Purposes.Social ? 1 : 0); int recreationPurpose = (purpose[nCallsForTour] == Global.Settings.Purposes.Recreation) ? 1 : 0; int personalBusinessMedicalPurpose = (purpose[nCallsForTour] == Global.Settings.Purposes.PersonalBusiness || purpose[nCallsForTour] == Global.Settings.Purposes.Medical) ? 1 : 0; int meal = (purpose[nCallsForTour] == Global.Settings.Purposes.Meal) ? 1 : 0; int socialRecreationPurpose = (purpose[nCallsForTour] == Global.Settings.Purposes.Social || purpose[nCallsForTour] == Global.Settings.Purposes.Recreation) ? 1 : 0; //nt recreationPurpose = (purpose[nCallsForTour] == Global.Settings.Purposes.Recreation) ? 1 : 0; int votALSegment = householdDay.Household.GetVotALSegment(); int transitAccessSegment = householdDay.Household.ResidenceParcel.TransitAccessSegment(); double totalAggregateLogsum = Global.AggregateLogsums[householdDay.Household.ResidenceParcel.ZoneId] [Global.Settings.Purposes.HomeBasedComposite][carOwnership][votALSegment][transitAccessSegment]; PersonDayWrapper pPersonDay = null; bool[] pLessThan3NonMandatoryTours = new bool[6]; bool[] pLessThan3TourPurposes = new bool[6]; int[] pUsualLocationParcelId = new int[6]; int[] pUsualLocationZoneId = new int[6]; IParcelWrapper[] pUsualLocationParcel = new IParcelWrapper[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[] pAdultMale = new int[6]; int[] pAdultFemale = new int[6]; int[] pAdultMandatory = new int[6]; int[] pNonMandatory = new int[6]; int[] pMandatory = new int[6]; int[] pAdultNonMandatory = new int[6]; int[] pAdultWithChildrenUnder16 = new int[6]; int[] pAge5To8 = new int[6]; int[] pAge9To12 = new int[6]; int[] pAge13To15 = new int[6]; int[] pAgeUnder13 = new int[6]; int[] pTransit = new int[6]; //int[] pJointNonMandatoryTours = new int[6]; int[] pJointEscortTours = new int[6]; int[] pMandatoryTours = new int[6]; int[] pJointSocialRecreationTours = new int[6]; //int[] pJointPersMedtours = new int[6]; int[] pNonMandatoryChild = new int[6]; int[] pMandatoryChild = new int[6]; //int[] pJointShopTours = new int[6]; int[] pJointMealTours = new int[6]; int count = 0; foreach (PersonDayWrapper personDay in orderedPersonDays) { count++; if (count <= 5) { if (count == 1) { pPersonDay = personDay; } for (int i = 1; i < 9; i++) { pType[personDay.Person.PersonType, count] = 1; } if (personDay.Person.IsFullOrPartTimeWorker && personDay.Person.UsualWorkParcel != null) { pUsualLocationParcelId[count] = personDay.Person.UsualWorkParcelId; pUsualLocationParcel[count] = personDay.Person.UsualWorkParcel; pUsualLocationZoneId[count] = personDay.Person.UsualWorkParcel.ZoneId; } else if (personDay.Person.IsStudent && personDay.Person.UsualSchoolParcel != null) { pUsualLocationParcelId[count] = personDay.Person.UsualSchoolParcelId; pUsualLocationParcel[count] = personDay.Person.UsualSchoolParcel; pUsualLocationZoneId[count] = personDay.Person.UsualSchoolParcel.ZoneId; } else if (personDay.Person.IsWorker && personDay.Person.IsNotFullOrPartTimeWorker && personDay.Person.UsualWorkParcel != null) { pUsualLocationParcelId[count] = personDay.Person.UsualWorkParcelId; pUsualLocationParcel[count] = personDay.Person.UsualWorkParcel; pUsualLocationZoneId[count] = personDay.Person.UsualWorkParcel.ZoneId; } else { pUsualLocationParcelId[count] = personDay.Household.ResidenceParcelId; pUsualLocationParcel[count] = personDay.Household.ResidenceParcel; pUsualLocationZoneId[count] = personDay.Household.ResidenceZoneId; } pLessThan3NonMandatoryTours[count] = personDay.GetCreatedNonMandatoryTours() < 3; pLessThan3TourPurposes[count] = personDay.GetTotalCreatedTourPurposes() < 3; 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(); //pAdultMale[count] = personDay.Person.IsAdultMale.ToFlag(); pAdultMandatory[count] = personDay.Person.IsAdult.ToFlag() * (personDay.PatternType == Global.Settings.PatternTypes.Mandatory).ToFlag(); pNonMandatory[count] = (personDay.PatternType == Global.Settings.PatternTypes.Optional).ToFlag(); pAdultNonMandatory[count] = (personDay.PatternType == Global.Settings.PatternTypes.Optional).ToFlag() * personDay.Person.IsAdult.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(); pTransit[count] = (personDay.Person.TransitPassOwnership == 1 ? 1 : 0); pMandatory[count] = (personDay.PatternType == Global.Settings.PatternTypes.Mandatory).ToFlag(); pMandatoryTours[count] = personDay.WorkTours + personDay.SchoolTours; pJointEscortTours[count] = personDay.CreatedEscortTours; pJointMealTours[count] = personDay.CreatedMealTours; //pJointShopTours[count]= personDay.CreatedShoppingTours; pJointSocialRecreationTours[count] = personDay.CreatedSocialTours + personDay.CreatedRecreationTours; pNonMandatoryChild[count] = (personDay.PatternType == Global.Settings.PatternTypes.Optional).ToFlag() * personDay.Person.IsChildUnder16.ToFlag(); pMandatoryChild[count] = (personDay.PatternType == Global.Settings.PatternTypes.Mandatory).ToFlag() * personDay.Person.IsChildUnder16.ToFlag(); } } int componentIndex = 0; //Create person utility components int[] componentPerson = new int[6]; for (int 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, pAge5To8[p]); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(02, pAdultFemale[p]); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(03, pAge9To12[p]); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(05, (pMandatoryTours[p] > 1).ToFlag()); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(06, (pJointNonMandatoryTours[p]>1).ToFlag()); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(07, pAdultMandatory[p]); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(08, pTransit[p]); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(21, pAdult[p] * escortPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(26, pType[6, p] * pNonMandatory[p] * escortPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(28, pType[8, p] * pNonMandatory[p] * escortPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(29, pType[6, p] * pMandatory[p] * escortPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(30, pType[7, p] * pMandatory[p] * escortPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(31, pType[8, p] * pMandatory[p] * escortPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(32, (pJointEscortTours[p] == 1).ToFlag() * escortPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(33, (pJointEscortTours[p] >= 2).ToFlag() * escortPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(41, pAdult[p] * personalBusinessMedicalPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(44, pNonMandatoryChild[p] * personalBusinessMedicalPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(45, pMandatoryChild[p] * personalBusinessMedicalPurpose); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(51, pAdultMandatory[p]* shopPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(52, pAdultNonMandatory[p] * shopPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(54, pNonMandatoryChild[p] * shopPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(56, pType[6, p] * pMandatory[p] * shopPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(57, pType[7, p] * pMandatory[p] * shopPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(58, pType[8, p] * pMandatory[p] * shopPurpose); //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(59, (pJointShopTours[p]>1).ToFlag() * shopPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(71, pAdult[p] * meal); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(77, (pJointMealTours[p] > 0).ToFlag() * meal); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(92, pAdult[p] * socialRecreationPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(96, pType[6, p] * pMandatory[p] * socialRecreationPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(97, pType[7, p] * pMandatory[p] * socialRecreationPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(98, pType[8, p] * pMandatory[p] * socialRecreationPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(99, (pJointSocialRecreationTours[p] >= 1).ToFlag() * socialRecreationPurpose); } //create two-way match interaction utility components int[,] componentMatch = new int[6, 6]; int[,] iMatchAdult = new int[6, 6]; int[,] iMatchAdultWithChildrenUnder16 = new int[6, 6]; int[,] iMatchMandatoryAdults = new int[6, 6]; int[,] iMatchNonMandatoryAdults = new int[6, 6]; int[,] iMatchChild = new int[6, 6]; int[,] iMatchNonMandatoryKids = new int[6, 6]; int[,] iMatchMandatoryKids = new int[6, 6]; int[,] iMatchNonMandatory = new int[6, 6]; int[,] iMatchUsualLocation = new int[6, 6]; for (int t2 = 1; t2 <= 5; t2++) { for (int t1 = 1; t1 < t2; t1++) { //populate match variables iMatchAdultWithChildrenUnder16[t1, t2] = pAdultWithChildrenUnder16[t1] * pAdultWithChildrenUnder16[t2]; iMatchNonMandatoryAdults[t1, t2] = pAdultNonMandatory[t1] * pAdultNonMandatory[t2]; iMatchMandatoryAdults[t1, t2] = pAdultMandatory[t1] * pAdultMandatory[t2]; iMatchNonMandatory[t1, t2] = pNonMandatory[t1] * pNonMandatory[t2]; iMatchUsualLocation[t1, t2] = (pUsualLocationParcelId[t1] == pUsualLocationParcelId[t2]) ? 1 : 0; iMatchChild[t1, t2] = (1 - pAdult[t1]) * (1 - pAdult[t2]); iMatchNonMandatoryKids[t1, t2] = pNonMandatory[t1] * pAgeUnder13[t1] * pNonMandatory[t2] * pAgeUnder13[t2]; iMatchMandatoryKids[t1, t2] = pMandatory[t1] * pAgeUnder13[t1] * pMandatory[t2] * pAgeUnder13[t2]; //create and populate components componentIndex++; componentMatch[t1, t2] = componentIndex; choiceProbabilityCalculator.CreateUtilityComponent(componentMatch[t1, t2]); choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(109, iMatchNonMandatoryKids[t1, t2]); choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(110, iMatchMandatoryKids[t1, t2]); choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(111, iMatchMandatoryAdults[t1, t2]); //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(113, iMatchAdultNonMandatorys[t1, t2]); choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(114, iMatchAdultWithChildrenUnder16[t1, t2]); choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(116, iMatchNonMandatory[t1, t2] * socialRecreationPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(124, iMatchChild[t1, t2] * shopPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(125, iMatchUsualLocation[t1, t2]); } } //create two-way cross interaction utility components int[,] componentCross = new int[6, 6]; int iCrossAgeUnder5AndNonMandatory; int iCrossAge5To12AndNonMandatory; int iCrossAge13To15AndNonMandatory; int iCrossDrivingAgeChildAndNonMandatory; int iCrossMandatoryAdAndChild; for (int t2 = 1; t2 <= 5; t2++) { for (int t1 = 1; t1 <= 5; t1++) { if (!(t1 == t2)) { //populate cross variables iCrossAge5To12AndNonMandatory = pAdultNonMandatory[t1] * (pAge5To8[t2] + pAge9To12[t2]); iCrossAgeUnder5AndNonMandatory = pAdultNonMandatory[t1] * pType[8, t2]; iCrossAge13To15AndNonMandatory = pNonMandatory[t1] * pAge13To15[t2]; iCrossDrivingAgeChildAndNonMandatory = pNonMandatory[t1] * pType[6, t2]; iCrossMandatoryAdAndChild = pAdultMandatory[t1] * pChild[t2]; //create and populate cross components componentIndex++; componentCross[t1, t2] = componentIndex; choiceProbabilityCalculator.CreateUtilityComponent(componentCross[t1, t2]); choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(133, iCrossAge13To15AndNonMandatory); choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(135, iCrossAgeUnder5AndNonMandatory * escortPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(136, iCrossAgeUnder5AndNonMandatory * personalBusinessMedicalPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(137, iCrossAgeUnder5AndNonMandatory * shopPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(138, iCrossAgeUnder5AndNonMandatory * meal); choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(139, iCrossAgeUnder5AndNonMandatory * socialRecreationPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(144, iCrossAge5To12AndNonMandatory * socialRecreationPurpose); //choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(145, iCrossMandatoryAdAndChild*escortPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(146, iCrossMandatoryAdAndChild * personalBusinessMedicalPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(147, iCrossMandatoryAdAndChild * shopPurpose); choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(148, iCrossMandatoryAdAndChild * meal); choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(149, iCrossMandatoryAdAndChild * socialRecreationPurpose); } } } //Generate utility funtions for the alternatives bool[] available = new bool[32]; bool[] chosen = new bool[32]; 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 of alts that include less than 2 participants if (altParticipants[alt][7] < 2) { available[alt] = false; } // restrict availability if any participant has at-home patternType int numberAtHomePatternTypes = 0; for (int i = 1; i <= 5; i++) { if (altParticipants[alt][i] == 1 && pPatternType[i] == Global.Settings.PatternTypes.Home) { numberAtHomePatternTypes++; } } if (numberAtHomePatternTypes > 0) { available[alt] = false; } // restrict availability if any participant has 3 or more nonmandatory tours already for (int i = 1; i <= 5; i++) { if (altParticipants[alt][i] == 1 && !pLessThan3NonMandatoryTours[i]) { available[alt] = false; } } // restrict availability if any participant has 3 or more tour purposes already for (int i = 1; i <= 5; i++) { if (altParticipants[alt][i] == 1 && !pLessThan3TourPurposes[i]) { available[alt] = false; } } int numberOfParticipants = 0; int workersParticipating = 0; int numberOfParticipatingChildren = 0; int numberOfParticipatingAdults = 0; int numberOfAvailableChildren = 0; int numberOfAvailablePersons = 0; int numberOfAvailableAdults = 0; if (available[alt] == true) { for (int i = 1; i <= 5; i++) { if (pChild[i] == 1) { numberOfAvailableChildren++; numberOfAvailablePersons++; } if (pAdult[i] == 1) { 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++; } } } } // determine choice if (choice == alt) { chosen[alt] = true; } //Get the alternative ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(alt, available[alt], chosen[alt]); alternative.Choice = alt; //Add alt-specific utility terms alternative.AddUtilityTerm(160, (numberOfParticipatingAdults > 1 && numberOfParticipatingChildren > 0) ? 1 : 0); //alternative.AddUtilityTerm(161, (numberOfParticipatingChildren < numberOfAvailableChildren) ? 1 : 0); //alternative.AddUtilityTerm(162, (numberOfParticipatingAdults >1).ToFlag() *socialRecreationPurpose); //alternative.AddUtilityTerm(163, (numberOfParticipatingAdults == 1).ToFlag() *personalBusinessMedicalPurpose); for (int p = 1; p <= 5; p++) { if (altParticipants[alt][p] == 1) { alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p])); } } for (int t2 = 1; t2 <= 5; t2++) { for (int t1 = 1; t1 < t2; t1++) { if (altParticipants[alt][t1] == 1 && altParticipants[alt][t2] == 1) { alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2])); } } } for (int t2 = 1; t2 <= 5; t2++) { for (int 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, PersonDayWrapper personDay, HouseholdDayWrapper householdDay, int choice = Constants.DEFAULT_VALUE) { var household = householdDay.Household; // set household characteristics here that don't depend on person characteristics var available = (householdDay.Household.Size > 1); int hasAdultEducLevel12 = 0; //int allAdultEducLevel12 = 1; int youngestAge = 999; foreach (PersonWrapper person in householdDay.Household.Persons) { // set characteristics here that depend on person characteristics if (person.Age >= 18 && person.EducationLevel >= 12) { hasAdultEducLevel12 = 1; } //if (person.Age >= 18 && person.EducationLevel < 12) allAdultEducLevel12 = 0; if (person.Age < youngestAge) { youngestAge = person.Age; } } Double workTourLogsum; if (personDay.Person.UsualWorkParcelId != Constants.DEFAULT_VALUE && personDay.Person.UsualWorkParcelId != Global.Settings.OutOfRegionParcelId) { //JLB 201406 //var nestedAlternative = Global.ChoiceModelSession.Get<WorkTourModeModel>().RunNested(personDay.Person, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualWorkParcel, Global.Settings.Times.EightAM, Global.Settings.Times.FivePM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers); 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(); } else { workTourLogsum = 0; } int atHomeDay = personDay.PatternType == 3 ? 1 : 0; int nonMandatoryTourDay = personDay.PatternType == 2 ? 1 : 0; int MandatoryTourDay = personDay.PatternType == 1 ? 1 : 0; 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 = Global.Settings.VotALSegments.Medium; // TODO: calculate a VOT segment that depends on household income var transitAccessSegment = household.ResidenceParcel.TransitAccessSegment(); var personalBusinessAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId] [Global.Settings.Purposes.PersonalBusiness][carOwnership][votALSegment][transitAccessSegment]; var shoppingAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId] [Global.Settings.Purposes.Shopping][carOwnership][votALSegment][transitAccessSegment]; var mealAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId] [Global.Settings.Purposes.Meal][carOwnership][votALSegment][transitAccessSegment]; var socialAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId] [Global.Settings.Purposes.Social][carOwnership][votALSegment][transitAccessSegment]; //var compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][carOwnership][votALSegment][transitAccessSegment]; var compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.NoCars][votALSegment][transitAccessSegment]; //var householdDay = (LDHouseholdDayWrapper)tour.HouseholdDay; //var household = householdDay.Household; // 0 Person doesn't work at home more than specified number of minutes var alternative = choiceProbabilityCalculator.GetAlternative(0, true, choice == 0); alternative.Choice = 0; alternative.AddUtilityTerm(1, 0.0); // 1 Works at home alternative = choiceProbabilityCalculator.GetAlternative(1, true, choice == 1); alternative.Choice = 1; alternative.AddUtilityTerm(1, 1.0); alternative.AddUtilityTerm(2, householdDay.Household.HasChildrenUnder5.ToFlag()); alternative.AddUtilityTerm(3, householdDay.Household.HasChildrenAge5Through15.ToFlag()); alternative.AddUtilityTerm(4, (householdDay.Household.Size == 2 && householdDay.AdultsInSharedHomeStay == 2).ToFlag()); alternative.AddUtilityTerm(5, (householdDay.AdultsInSharedHomeStay == 1 && householdDay.Household.HasChildrenUnder16).ToFlag()); alternative.AddUtilityTerm(6, (householdDay.AdultsInSharedHomeStay == 2 && householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag()); alternative.AddUtilityTerm(7, (householdDay.AdultsInSharedHomeStay == 2 && hasAdultEducLevel12 == 1).ToFlag()); alternative.AddUtilityTerm(8, (youngestAge >= 40).ToFlag()); alternative.AddUtilityTerm(10, (householdDay.Household.Income >= 300000 && householdDay.Household.Income < 600000).ToFlag()); alternative.AddUtilityTerm(11, (householdDay.Household.Income >= 600000 && householdDay.Household.Income < 900000).ToFlag()); alternative.AddUtilityTerm(12, (householdDay.Household.Income >= 900000).ToFlag()); alternative.AddUtilityTerm(15, householdDay.PrimaryPriorityTimeFlag); alternative.AddUtilityTerm(16, (householdDay.Household.Size == 2).ToFlag()); alternative.AddUtilityTerm(17, (householdDay.Household.Size == 3).ToFlag()); alternative.AddUtilityTerm(18, (householdDay.Household.Size >= 4).ToFlag()); //alternative.AddUtilityTerm(18, (householdDay.Household.Size >= 5).ToFlag()); alternative.AddUtilityTerm(21, personDay.Person.IsPartTimeWorker.ToFlag()); //alternative.AddUtilityTerm(2, personDay.Person.IsFulltimeWorker.ToFlag()); alternative.AddUtilityTerm(22, (personDay.Person.Gender == 1).ToFlag()); alternative.AddUtilityTerm(23, (hasAdultEducLevel12 == 1).ToFlag()); //alternative.AddUtilityTerm(24, MandatoryTourDay); alternative.AddUtilityTerm(25, nonMandatoryTourDay); alternative.AddUtilityTerm(26, atHomeDay); //alternative.AddUtilityTerm(27, workTourLogsum); //alternative.AddUtilityTerm(26, workTourLogsum * MandatoryTourDay); //alternative.AddUtilityTerm(27, workTourLogsum * nonMandatoryTourDay); alternative.AddUtilityTerm(27, compositeLogsum); //alternative.AddUtilityTerm(27, (householdDay.Household.VehiclesAvailable == 1 && household.Has2Drivers).ToFlag()); //GV not significant //alternative.AddUtilityTerm(28, (householdDay.Household.VehiclesAvailable >= 2 && household.Has2Drivers).ToFlag()); //GV not significant }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, PersonDayWrapper personDay, HouseholdDayWrapper householdDay, int maxPurpose, int choice = Constants.DEFAULT_VALUE) { IEnumerable <PersonDayWrapper> orderedPersonDays = householdDay.PersonDays.OrderBy(p => p.GetJointTourParticipationPriority()).ToList().Cast <PersonDayWrapper>(); var household = householdDay.Household; var residenceParcel = household.ResidenceParcel; 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(); var personalBusinessAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId] [Global.Settings.Purposes.PersonalBusiness][carOwnership][votALSegment][transitAccessSegment]; var shoppingAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId] [Global.Settings.Purposes.Shopping][Global.Settings.CarOwnerships.NoCars][votALSegment][transitAccessSegment]; //var mealAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId] // [Global.Settings.Purposes.Meal][carOwnership][votALSegment][transitAccessSegment]; var socialAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId] [Global.Settings.Purposes.Social][carOwnership][votALSegment][transitAccessSegment]; var totalAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId] [Global.Settings.Purposes.HomeBasedComposite][carOwnership][votALSegment][transitAccessSegment]; // var recreationAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId] // [Global.Settings.Purposes.Recreation][carOwnership][votALSegment][transitAccessSegment]; // var medicalAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId] // [Global.Settings.Purposes.Medical][carOwnership][votALSegment][transitAccessSegment]; //var compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][carOwnership][votALSegment][transitAccessSegment]; var compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.NoCars][votALSegment][transitAccessSegment]; int countNonMandatory = 0; int countMandatory = 0; int countWorkingAtHome = 0; double totalTimeWork = 0; int[] mandPerstype = new int[8]; int[] nonMandPerstype = new int[8]; double[] workLogsum = new double[8]; double[] schoolLogsum = new double[8]; int count = 0; foreach (PersonDayWrapper pDay in orderedPersonDays) { var person = pDay.Person; count++; if (count > 8) { break; } if (pDay.WorksAtHomeFlag == 1) { countWorkingAtHome++; } if (pDay.PatternType == 1) { countMandatory++; mandPerstype[pDay.Person.PersonType - 1]++; } if (pDay.PatternType == 2) { countNonMandatory++; nonMandPerstype[pDay.Person.PersonType - 1]++; } if (person.UsualWorkParcel == null || person.UsualWorkParcelId == household.ResidenceParcelId) { workLogsum[count - 1] = 0; } else { var destinationArrivalTime = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.WorkTourModeModel); var destinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.WorkTourModeModel); //JLB 201406 //var nestedAlternative = Global.ChoiceModelSession.Get<WorkTourModeModel>().RunNested(pDay, residenceParcel, person.UsualWorkParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable); //JLB 201602 //var nestedAlternative = Global.ChoiceModelSession.Get<WorkTourModeTimeModel>().RunNested(pDay, residenceParcel, person.UsualWorkParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable); var nestedAlternative = Global.ChoiceModelSession.Get <TourModeTimeModel>().RunNested(pDay, residenceParcel, person.UsualWorkParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable, Global.Settings.Purposes.Work); workLogsum[count - 1] = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } if (person.UsualSchoolParcel == null || person.UsualSchoolParcelId == household.ResidenceParcelId) { schoolLogsum[count - 1] = 0; } else { var destinationArrivalTime = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.SchoolTourModeModel); var destinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.SchoolTourModeModel); //JLB 201406 //var nestedAlternative = Global.ChoiceModelSession.Get<SchoolTourModeModel>().RunNested(pDay, residenceParcel, person.UsualSchoolParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable); //JLB 201602 //var nestedAlternative = Global.ChoiceModelSession.Get<SchoolTourModeTimeModel>().RunNested(pDay, residenceParcel, person.UsualSchoolParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable); var nestedAlternative = Global.ChoiceModelSession.Get <TourModeTimeModel>().RunNested(pDay, residenceParcel, person.UsualSchoolParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable, Global.Settings.Purposes.School); schoolLogsum[count - 1] = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } } // NONE_OR_HOME var alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.NoneOrHome, true, choice == Global.Settings.Purposes.NoneOrHome); alternative.Choice = Global.Settings.Purposes.NoneOrHome; //alternative.AddUtilityTerm(1, (personDay.TotalCreatedTours == 1).ToFlag()); alternative.AddUtilityTerm(2, (personDay.GetTotalCreatedTours() == 2).ToFlag()); alternative.AddUtilityTerm(3, (personDay.GetTotalCreatedTours() >= 3).ToFlag()); //alternative.AddUtilityTerm(4, (personDay.TotalCreatedTours >= 4).ToFlag()); //alternative.AddUtilityTerm(5, householdDay.PrimaryPriorityTimeFlag); //alternative.AddUtilityTerm(6, householdDay.Household.HasChildren.ToFlag()); alternative.AddUtilityTerm(4, householdDay.Household.HasChildrenUnder5.ToFlag()); alternative.AddUtilityTerm(5, householdDay.Household.HasChildrenAge5Through15.ToFlag()); //alternative.AddUtilityTerm(6, (householdDay.Household.Size == 2 && householdDay.AdultsInSharedHomeStay == 2).ToFlag()); //alternative.AddUtilityTerm(7, (householdDay.AdultsInSharedHomeStay == 1 && householdDay.Household.HasChildrenUnder16).ToFlag()); //alternative.AddUtilityTerm(8, (householdDay.AdultsInSharedHomeStay == 2 && householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag()); //alternative.AddUtilityTerm(10, (householdDay.Household.Income >= 300000 && householdDay.Household.Income < 600000).ToFlag()); //alternative.AddUtilityTerm(11, (householdDay.Household.Income >= 600000 && householdDay.Household.Income < 900000).ToFlag()); //alternative.AddUtilityTerm(12, (householdDay.Household.Income >= 900000).ToFlag()); alternative.AddUtilityTerm(13, householdDay.PrimaryPriorityTimeFlag); alternative.AddUtilityTerm(14, personDay.Person.IsPartTimeWorker.ToFlag()); alternative.AddUtilityTerm(15, personDay.Person.WorksAtHome.ToFlag()); //alternative.AddUtilityTerm(16, personDay.Person.IsFulltimeWorker.ToFlag()); //alternative.AddUtilityTerm(15, (personDay.Person.Gender == 1).ToFlag()); //alternative.AddUtilityTerm(10, (householdDay.Household.Size == 3).ToFlag()); //alternative.AddUtilityTerm(11, (householdDay.Household.Size == 4).ToFlag()); //alternative.AddUtilityTerm(12, (householdDay.Household.Size >= 5).ToFlag()); //alternative.AddNestedAlternative(11, 0, 200); // WORK alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Work, false, choice == Global.Settings.Purposes.Work); alternative.Choice = Global.Settings.Purposes.Work; alternative.AddUtilityTerm(202, 1); //alternative.AddNestedAlternative(12, 1, 200); // SCHOOL alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.School, false, choice == Global.Settings.Purposes.School); alternative.Choice = Global.Settings.Purposes.School; alternative.AddUtilityTerm(203, 1); //alternative.AddNestedAlternative(12, 1, 200); // ESCORT alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Escort, maxPurpose <= Global.Settings.Purposes.Escort && personDay.CreatedEscortTours > 0, choice == Global.Settings.Purposes.Escort); alternative.Choice = Global.Settings.Purposes.Escort; alternative.AddUtilityTerm(151, 1); alternative.AddUtilityTerm(152, (personDay.CreatedEscortTours > 1).ToFlag()); //alternative.AddUtilityTerm(152, householdDay.PrimaryPriorityTimeFlag); //alternative.AddUtilityTerm(153, (householdDay.Household.Size == 3).ToFlag()); //alternative.AddUtilityTerm(154, (householdDay.Household.Size >= 4).ToFlag()); //alternative.AddUtilityTerm(155, (householdDay.Household.Size > 4).ToFlag()); alternative.AddUtilityTerm(155, compositeLogsum); //alternative.AddUtilityTerm(156, (householdDay.Household.VehiclesAvailable == 0).ToFlag()); //alternative.AddNestedAlternative(12, 1, 200); // PERSONAL_BUSINESS alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.PersonalBusiness, maxPurpose <= Global.Settings.Purposes.PersonalBusiness && personDay.CreatedPersonalBusinessTours > 0, choice == Global.Settings.Purposes.PersonalBusiness); alternative.Choice = Global.Settings.Purposes.PersonalBusiness; alternative.AddUtilityTerm(21, 1); //alternative.AddUtilityTerm(22, (personDay.CreatedPersonalBusinessTours > 1).ToFlag()); //GV: 30. april 2013 - goes to infinity alternative.AddUtilityTerm(156, compositeLogsum); //alternative.AddNestedAlternative(12, 1, 200); // SHOPPING alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Shopping, maxPurpose <= Global.Settings.Purposes.Shopping && personDay.CreatedShoppingTours > 0, choice == Global.Settings.Purposes.Shopping); alternative.Choice = Global.Settings.Purposes.Shopping; alternative.AddUtilityTerm(41, 1); //alternative.AddUtilityTerm(42, (personDay.CreatedShoppingTours > 1).ToFlag()); //GV: cannot be estimated //alternative.AddUtilityTerm(42, householdDay.PrimaryPriorityTimeFlag); //alternative.AddUtilityTerm(43, (householdDay.Household.Size == 3).ToFlag()); //alternative.AddUtilityTerm(44, (householdDay.Household.Size == 4).ToFlag()); //alternative.AddUtilityTerm(45, (householdDay.Household.Size > 4).ToFlag()); //alternative.AddUtilityTerm(46, (householdDay.Household.VehiclesAvailable == 0).ToFlag()); //alternative.AddUtilityTerm(157, compositeLogsum); //GV wrong sign //alternative.AddUtilityTerm(157, shoppingAggregateLogsum); //GV wrong sign //alternative.AddNestedAlternative(12, 1, 200); // MEAL alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Meal, false, choice == Global.Settings.Purposes.Meal); alternative.Choice = Global.Settings.Purposes.Meal; alternative.AddUtilityTerm(61, 1); alternative.AddUtilityTerm(62, (personDay.CreatedMealTours > 1).ToFlag()); //alternative.AddNestedAlternative(12, 1, 200); // SOCIAL alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Social, maxPurpose <= Global.Settings.Purposes.Social && personDay.CreatedSocialTours > 0, choice == Global.Settings.Purposes.Social); alternative.Choice = Global.Settings.Purposes.Social; alternative.AddUtilityTerm(81, 1); alternative.AddUtilityTerm(82, (personDay.CreatedSocialTours > 1).ToFlag()); //alternative.AddUtilityTerm(82, householdDay.PrimaryPriorityTimeFlag); //alternative.AddUtilityTerm(83, (householdDay.Household.Size == 3).ToFlag()); //alternative.AddUtilityTerm(84, (householdDay.Household.Size == 4).ToFlag()); //alternative.AddUtilityTerm(85, (householdDay.Household.Size > 4).ToFlag()); alternative.AddUtilityTerm(158, compositeLogsum); //alternative.AddNestedAlternative(12, 1, 200); // RECREATION alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Recreation, false, choice == Global.Settings.Purposes.Recreation); alternative.Choice = Global.Settings.Purposes.Recreation; alternative.AddUtilityTerm(101, 1); //alternative.AddUtilityTerm(102, (personDay.CreatedRecreationTours > 1).ToFlag()); //alternative.AddNestedAlternative(12, 1, 60); // MEDICAL alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Medical, false, choice == Global.Settings.Purposes.Medical); alternative.Choice = Global.Settings.Purposes.Medical; alternative.AddUtilityTerm(121, 1); //alternative.AddUtilityTerm(122, (personDay.CreatedMedicalTours > 1).ToFlag()); //alternative.AddNestedAlternative(11, 1, 60); }
public int Run(PersonDayWrapper personDay, HouseholdDayWrapper householdDay, int maxPurpose) { return(Run(personDay, householdDay, maxPurpose, Global.Settings.Purposes.NoneOrHome)); }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, PersonDayWrapper personDay, HouseholdDayWrapper householdDay, int choice = Constants.DEFAULT_VALUE) { Framework.DomainModels.Wrappers.IHouseholdWrapper household = personDay.Household; Framework.DomainModels.Wrappers.IPersonWrapper person = personDay.Person; IEnumerable <PersonDayWrapper> personTypeOrderedPersonDays = householdDay.PersonDays.OrderBy(p => p.Person.PersonType).ToList().Cast <PersonDayWrapper>(); int mandatoryCount = 0; int nonMandatoryCount = 0; int homeCount = 0; // int mandatoryKids = 0; //int kidsAtHome = 0; //int nonMandatoryKids = 0; //int adultsAtHome = 0; double mandatoryLogsum = 0.0; int i = 0; foreach (PersonDayWrapper pDay in personTypeOrderedPersonDays) { i++; if (i <= 4) { if (pDay.PatternType == Global.Settings.PatternTypes.Mandatory) { mandatoryCount++; } else if (pDay.PatternType == Global.Settings.PatternTypes.Optional) { nonMandatoryCount++; } else { homeCount++; } } } /*int oldestAge = (from persons in household.Persons select persons.Age).Max(); * int youngestAge = (from persons in household.Persons select persons.Age).Min(); * int countTransitPassses = (from persons in household.Persons * where persons.TransitPassOwnershipFlag == 1 * select persons.TransitPassOwnershipFlag).Count();*/ Framework.DomainModels.Wrappers.IParcelWrapper residenceParcel = household.ResidenceParcel; 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); int votALSegment = household.GetVotALSegment(); int transitAccessSegment = household.ResidenceParcel.TransitAccessSegment(); double totalAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId] [Global.Settings.Purposes.HomeBasedComposite][carOwnership][votALSegment][transitAccessSegment]; double distanceToStop = household.ResidenceParcel.GetDistanceToTransit() > 0 ? Math.Min(household.ResidenceParcel.GetDistanceToTransit(), 2 * Global.Settings.DistanceUnitsPerMile) // JLBscale : 2 * Global.Settings.DistanceUnitsPerMile; if (person.PersonType <= Global.Settings.PersonTypes.PartTimeWorker) { if (person.UsualWorkParcelId != Constants.DEFAULT_VALUE && person.UsualWorkParcelId != Global.Settings.OutOfRegionParcelId) { if (person.UsualDeparturePeriodFromWork != Constants.DEFAULT_VALUE && person.UsualArrivalPeriodToWork != Constants.DEFAULT_VALUE) { ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().RunNested(personDay, person.Household.ResidenceParcel, person.UsualWorkParcel, (int)person.UsualArrivalPeriodToWork, (int)person.UsualDeparturePeriodFromWork, person.Household.HouseholdTotals.DrivingAgeMembers); mandatoryLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } else { ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().RunNested(personDay, person.Household.ResidenceParcel, person.UsualWorkParcel, Global.Settings.Times.EightAM, Global.Settings.Times.FivePM, person.Household.HouseholdTotals.DrivingAgeMembers); mandatoryLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } } else { mandatoryLogsum = 0; } } else if (person.PersonType >= Global.Settings.PersonTypes.UniversityStudent) { if (person.UsualSchoolParcelId != 0 && person.UsualSchoolParcelId != -1 && person.UsualSchoolParcelId != Global.Settings.OutOfRegionParcelId) { ChoiceProbabilityCalculator.Alternative schoolNestedAlternative = Global.ChoiceModelSession.Get <SchoolTourModeTimeModel>().RunNested(personDay, person.Household.ResidenceParcel, person.UsualSchoolParcel, Global.Settings.Times.EightAM, Global.Settings.Times.TwoPM, person.Household.HouseholdTotals.DrivingAgeMembers); mandatoryLogsum = schoolNestedAlternative == null ? 0 : schoolNestedAlternative.ComputeLogsum(); } else { mandatoryLogsum = 0; } } bool mandatoryAvailableFlag = true; if (personDay.Person.IsNonworkingAdult || personDay.Person.IsRetiredAdult || (!personDay.Person.IsWorker && !personDay.Person.IsStudent) || (!Global.Configuration.IsInEstimationMode && !personDay.Person.IsWorker && personDay.Person.UsualSchoolParcel == null) ) { mandatoryAvailableFlag = false; } // Pattern Type Mandatory on tour (at least one work or school tour) ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(0, mandatoryAvailableFlag, choice == 1); alternative.Choice = 1; //alternative.AddUtilityTerm(1, 1); //alternative.AddUtilityTerm(3, (person.IsStudent && person.IsWorker).ToFlag()); //alternative.AddUtilityTerm(4, person.IsPartTimeWorker.ToFlag()); alternative.AddUtilityTerm(6, (person.Age > 5).ToFlag() * (person.Age <= 18).ToFlag()); // alternative.AddUtilityTerm(10, (mandatoryCount == 2).ToFlag()); alternative.AddUtilityTerm(11, (mandatoryCount >= 3).ToFlag()); alternative.AddUtilityTerm(12, mandatoryLogsum); //alternative.AddUtilityTerm(13, totalAggregateLogsum); alternative.AddUtilityTerm(15, household.Has100KPlusIncome.ToFlag()); // PatternType NonMandatory on tour (tours, but none for work or school) alternative = choiceProbabilityCalculator.GetAlternative(1, true, choice == 2); alternative.Choice = 2; alternative.AddUtilityTerm(21, 1); alternative.AddUtilityTerm(23, person.IsPartTimeWorker.ToFlag()); alternative.AddUtilityTerm(24, person.IsDrivingAgeStudent.ToFlag()); alternative.AddUtilityTerm(25, person.IsUniversityStudent.ToFlag()); alternative.AddUtilityTerm(26, person.IsNonworkingAdult.ToFlag()); //alternative.AddUtilityTerm(28, person.IsRetiredAdult.ToFlag()); alternative.AddUtilityTerm(29, (nonMandatoryCount == 0).ToFlag()); //alternative.AddUtilityTerm(30, (nonMandatoryKids==1).ToFlag()); alternative.AddUtilityTerm(31, ((nonMandatoryCount == 2).ToFlag())); alternative.AddUtilityTerm(32, ((nonMandatoryCount >= 3).ToFlag())); alternative.AddUtilityTerm(34, totalAggregateLogsum); alternative.AddUtilityTerm(35, person.IsAdultFemale.ToFlag()); //alternative.AddUtilityTerm(37, household.Has75KPlusIncome.ToFlag()); // PatternType Home (all day) alternative = choiceProbabilityCalculator.GetAlternative(2, true, choice == 3); alternative.Choice = 3; alternative.AddUtilityTerm(41, 1); alternative.AddUtilityTerm(42, person.IsPartTimeWorker.ToFlag()); alternative.AddUtilityTerm(45, person.IsDrivingAgeStudent.ToFlag()); alternative.AddUtilityTerm(48, person.IsUniversityStudent.ToFlag()); alternative.AddUtilityTerm(52, (person.Age > 75).ToFlag()); alternative.AddUtilityTerm(53, (homeCount == 0).ToFlag()); alternative.AddUtilityTerm(57, (homeCount >= 2).ToFlag()); //alternative.AddUtilityTerm(58, person.IsAdultFemale.ToFlag()); // alternative.AddUtilityTerm(60, noCarsFlag + carCompetitionFlag); alternative.AddUtilityTerm(62, distanceToStop); //alternative.AddUtilityTerm(63, totalAggregateLogsum); alternative.AddUtilityTerm(64, mandatoryLogsum); //alternative.AddUtilityTerm(65, Math.Log(1+youngestAge)); //alternative.AddUtilityTerm(66, Math.Log(1+oldestAge)); }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, PersonDayWrapper personDay, HouseholdDayWrapper householdDay, int choice = Constants.DEFAULT_VALUE) { var household = personDay.Household; var person = personDay.Person; Double workTourLogsum; if (personDay.Person.UsualWorkParcelId != Constants.DEFAULT_VALUE && personDay.Person.UsualWorkParcelId != Global.Settings.OutOfRegionParcelId) { //JLB 201406 //var nestedAlternative = Global.ChoiceModelSession.Get<WorkTourModeModel>().RunNested(personDay.Person, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualWorkParcel, Global.Settings.Times.EightAM, Global.Settings.Times.FivePM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers); //JLB 201602 //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); var nestedAlternative = Global.ChoiceModelSession.Get <TourModeTimeModel>().RunNested(personDay, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualWorkParcel, Global.Settings.Times.EightAM, Global.Settings.Times.FivePM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers, Global.Settings.Purposes.Work); workTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); workTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } else { workTourLogsum = 0; } Double schoolTourLogsum; if (personDay.Person.UsualSchoolParcelId != Constants.DEFAULT_VALUE && personDay.Person.UsualSchoolParcelId != Global.Settings.OutOfRegionParcelId) { //JLB 201406 //var nestedAlternative = Global.ChoiceModelSession.Get<SchoolTourModeModel>().RunNested(personDay.Person, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualSchoolParcel, Global.Settings.Times.EightAM, Global.Settings.Times.FivePM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers); //JLB 201602 //var nestedAlternative = Global.ChoiceModelSession.Get<SchoolTourModeTimeModel>().RunNested(personDay, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualSchoolParcel, Global.Settings.Times.EightAM, Global.Settings.Times.FivePM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers); var nestedAlternative = Global.ChoiceModelSession.Get <TourModeTimeModel>().RunNested(personDay, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualSchoolParcel, Global.Settings.Times.EightAM, Global.Settings.Times.FivePM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers, Global.Settings.Purposes.School); schoolTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } else { schoolTourLogsum = 0; } // No mandatory stops var alternative = choiceProbabilityCalculator.GetAlternative(0, true, choice == 0); alternative.Choice = 0; //alternative.AddUtilityTerm(2, householdDay.Household.HasChildren.ToFlag()); alternative.AddUtilityTerm(3, householdDay.Household.HasChildrenUnder5.ToFlag()); //alternative.AddUtilityTerm(4, householdDay.Household.HasChildrenAge5Through15.ToFlag()); //alternative.AddUtilityTerm(6, householdDay.Household.HasChildrenUnder16.ToFlag()); //alternative.AddNestedAlternative(11, 0, 60); //GV: added 14. june 2016 alternative.AddUtilityTerm(4, householdDay.PrimaryPriorityTimeFlag); //alternative.AddUtilityTerm(5, (householdDay.Household.VehiclesAvailable >= 1).ToFlag()); // Business stop(s) alternative = choiceProbabilityCalculator.GetAlternative(1, personDay.Person.IsWorker, choice == 1); alternative.Choice = 1; alternative.AddUtilityTerm(21, 1); //alternative.AddUtilityTerm(22, personDay.Person.IsChildUnder5.ToFlag()); alternative.AddUtilityTerm(23, personDay.Person.WorksAtHome.ToFlag()); alternative.AddUtilityTerm(24, personDay.Person.IsFulltimeWorker.ToFlag()); //alternative.AddUtilityTerm(25, personDay.Person.IsPartTimeWorker.ToFlag()); alternative.AddUtilityTerm(25, personDay.Person.IsMale.ToFlag()); //alternative.AddUtilityTerm(4, person.IsPartTimeWorker.ToFlag()); //GV: 15. june 2016, not sign. //alternative.AddUtilityTerm(26, (householdDay.AdultsInSharedHomeStay == 2 && householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag()); //alternative.AddUtilityTerm(14, (householdDay.AdultsInSharedHomeStay == 2).ToFlag()); //alternative.AddUtilityTerm(15, (householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag()); alternative.AddUtilityTerm(27, (householdDay.AdultsInSharedHomeStay == 1 && householdDay.Household.HasChildren).ToFlag()); alternative.AddUtilityTerm(28, workTourLogsum); //alternative.AddUtilityTerm(28, (householdDay.Household.VehiclesAvailable == 1 && household.Has2Drivers).ToFlag()); alternative.AddUtilityTerm(29, (householdDay.Household.VehiclesAvailable >= 2 && household.Has2Drivers).ToFlag()); // School stop(s) alternative = choiceProbabilityCalculator.GetAlternative(2, personDay.Person.IsStudent, choice == 2); alternative.Choice = 2; alternative.AddUtilityTerm(41, 1); //alternative.AddUtilityTerm(43, personDay.Person.WorksAtHome.ToFlag()); //alternative.AddUtilityTerm(44, personDay.Person.IsFulltimeWorker.ToFlag()); //alternative.AddUtilityTerm(45, personDay.Person.IsPartTimeWorker.ToFlag()); //alternative.AddUtilityTerm(46, personDay.Person.IsMale.ToFlag()); alternative.AddUtilityTerm(47, personDay.Person.IsYouth.ToFlag()); //GV: 15. june 2016, not sign. //alternative.AddUtilityTerm(48, schoolTourLogsum); // Business and school stops alternative = choiceProbabilityCalculator.GetAlternative(3, (personDay.Person.IsWorker && personDay.Person.IsStudent), choice == 3); alternative.Choice = 3; alternative.AddUtilityTerm(61, 1); alternative.AddUtilityTerm(28, workTourLogsum); //GV: 15. june 2016, not sign. //alternative.AddUtilityTerm(48, schoolTourLogsum); }
public int Run(PersonDayWrapper personDay, HouseholdDayWrapper householdDay, int nCallsForTour, int[] simulatedMandatoryTours) { return(Run(personDay, householdDay, nCallsForTour, simulatedMandatoryTours, Global.Settings.Purposes.NoneOrHome)); }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, TripWrapper trip, HouseholdDayWrapper householdDay, int choice = Constants.DEFAULT_VALUE) { HouseholdWrapper household = (HouseholdWrapper)trip.Household; PersonWrapper person = (PersonWrapper)trip.Person; PersonDayWrapper personDay = (PersonDayWrapper)trip.PersonDay; TourWrapper tour = (TourWrapper)trip.Tour; TourWrapper.HalfTour halfTour = (TourWrapper.HalfTour)trip.HalfTour; List <Framework.DomainModels.Wrappers.IPersonDayWrapper> personDays = householdDay.PersonDays; int isJointTour = tour.JointTourSequence > 0 ? 1 : 0; int isIndividualTour = isJointTour == 1 ? 0 : 1; Framework.DomainModels.Wrappers.IParcelWrapper destinationParcel = tour.DestinationParcel; int jointHalfOfFullJointHalfTour = ((trip.Direction == Global.Settings.TourDirections.OriginToDestination && tour.FullHalfTour1Sequence > 0) || (trip.Direction == Global.Settings.TourDirections.DestinationToOrigin && tour.FullHalfTour2Sequence > 0)).ToFlag(); int individualHalfOfFullJointHalfTour = ((trip.Direction == Global.Settings.TourDirections.OriginToDestination && tour.FullHalfTour1Sequence == 0 && tour.FullHalfTour2Sequence > 0) || (trip.Direction == Global.Settings.TourDirections.DestinationToOrigin && tour.FullHalfTour2Sequence == 0 && tour.FullHalfTour1Sequence > 0)).ToFlag(); int individualHalfTour = (isIndividualTour == 1 || individualHalfOfFullJointHalfTour == 1) ? 1 : 0; int jointHalfTour = 1 - individualHalfTour; //destination parcel variables double foodBuffer2 = 0.0; double totEmpBuffer2 = 0.0; double retailBuffer2 = 0.0; if (destinationParcel != null) { foodBuffer2 = Math.Log(1 + destinationParcel.EmploymentFoodBuffer2); totEmpBuffer2 = Math.Log(1 + destinationParcel.EmploymentTotalBuffer2); retailBuffer2 = Math.Log(1 + destinationParcel.EmploymentRetailBuffer2); } int carOwnership = person.GetCarOwnershipSegment(); // household inputs int onePersonHouseholdFlag = household.IsOnePersonHousehold.ToFlag(); //var householdInc75KP = household.Has75KPlusIncome; int votALSegment = tour.GetVotALSegment(); int transitAccessSegment = household.ResidenceParcel.TransitAccessSegment(); double totalAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId] [Global.Settings.Purposes.HomeBasedComposite][carOwnership][votALSegment][transitAccessSegment]; double homeFoodBuffer2 = Math.Log(1 + household.ResidenceParcel.EmploymentFoodBuffer2); double homeTotEmpBuffer2 = Math.Log(1 + household.ResidenceParcel.EmploymentTotalBuffer2); double homeRetailBuffer2 = Math.Log(1 + household.ResidenceParcel.EmploymentRetailBuffer2); // person-day inputs int homeBasedTours = personDay.HomeBasedTours; int simulatedToursFlag = personDay.SimulatedToursExist().ToFlag(); int simulatedBusinessStops = personDay.SimulatedBusinessStops; int simulatedBusinessStopsFlag = simulatedBusinessStops > 0 ? 1 : 0; int simulatedSchoolStops = personDay.SimulatedSchoolStops; int simulatedEscortStops = personDay.SimulatedEscortStops; int simulatedPersonalBusinessStops = personDay.SimulatedPersonalBusinessStops; int simulatedShoppingStops = personDay.SimulatedShoppingStops; int simulatedMealStops = personDay.SimulatedMealStops; int simulatedSocialStops = personDay.SimulatedSocialStops; int simulatedRecreationStops = personDay.SimulatedRecreationStops; int simulatedMedicalStops = personDay.SimulatedMedicalStops; int primaryFamilyTimeFlag = householdDay.PrimaryPriorityTimeFlag; // tour inputs int hovDriverTourFlag = tour.IsHovDriverMode().ToFlag(); int hovPassengerTourFlag = tour.IsHovPassengerMode().ToFlag(); int transitTourFlag = tour.IsTransitMode().ToFlag(); int walkTourFlag = tour.IsWalkMode().ToFlag(); int bikeTourFlag = tour.IsBikeMode().ToFlag(); int autoTourFlag = tour.IsAnAutoMode().ToFlag(); int notHomeBasedTourFlag = (!tour.IsHomeBasedTour).ToFlag(); int workTourFlag = tour.IsWorkPurpose().ToFlag(); int businessTourFlag = tour.IsBusinessPurpose().ToFlag(); int personalBusinessTourFlag = tour.IsPersonalBusinessPurpose().ToFlag(); int socialTourFlag = tour.IsSocialPurpose().ToFlag(); int socialOrRecreationTourFlag = tour.IsSocialOrRecreationPurpose().ToFlag(); int schoolTourFlag = tour.IsSchoolPurpose().ToFlag(); int escortTourFlag = tour.IsEscortPurpose().ToFlag(); int shoppingTourFlag = tour.IsShoppingPurpose().ToFlag(); // trip inputs int oneSimulatedTripFlag = halfTour.OneSimulatedTripFlag; int twoSimulatedTripsFlag = halfTour.TwoSimulatedTripsFlag; int threeSimulatedTripsFlag = halfTour.ThreeSimulatedTripsFlag; int fourSimulatedTripsFlag = halfTour.FourSimulatedTripsFlag; int fivePlusSimulatedTripsFlag = halfTour.FivePlusSimulatedTripsFlag; int twoPlusSimulatedTripsFlag = twoSimulatedTripsFlag + threeSimulatedTripsFlag + fourSimulatedTripsFlag + fivePlusSimulatedTripsFlag; int halfTourFromOriginFlag = trip.IsHalfTourFromOrigin.ToFlag(); int halfTourFromDestinationFlag = (!trip.IsHalfTourFromOrigin).ToFlag(); int beforeMandatoryDestinationFlag = trip.IsBeforeMandatoryDestination().ToFlag(); // remaining inputs, including joint tour variables int remainingToursCount = personDay.HomeBasedTours - personDay.GetTotalSimulatedTours(); int destinationDepartureTime = trip.IsHalfTourFromOrigin // first trip in half tour, use tour destination time ? trip.Sequence == 1 ? tour.DestinationArrivalTime : trip.GetPreviousTrip().ArrivalTime : trip.Sequence == 1 ? tour.DestinationDepartureTime : trip.GetPreviousTrip().ArrivalTime; //var time = trip.IsHalfTourFromOrigin ? tour.DestinationArrivalTime : tour.DestinationDepartureTime; int time = destinationDepartureTime; bool timeIsAvailableForAnotherTrip = true; if ((trip.IsHalfTourFromOrigin && time < Global.Settings.Times.FourAM) || (!trip.IsHalfTourFromOrigin && time > Global.Settings.Times.TwoAM)) { timeIsAvailableForAnotherTrip = false; } bool stopsNeeded = false; //if ((halfTour.SimulatedTrips <= 5) // && (timeIsAvailableForAnotherTrip) // && (trip.Direction == 2) // &&((trip.Tour.Sequence == trip.PersonDay.TotalCreatedTours) // && ((simulatedSchoolStops == 0 && personDay.SchoolStops > 0) // ||(simulatedBusinessStops == 0 && personDay.BusinessStops > 0) // ||(simulatedEscortStops == 0 && personDay.EscortStops > 0) // ||(simulatedPersonalBusinessStops == 0 && personDay.PersonalBusinessStops > 0) // ||(simulatedShoppingStops == 0 && personDay.ShoppingStops > 0) // ||(simulatedSocialStops == 0 && personDay.SocialStops > 0)))) { // stopsNeeded = true; //} int from7AMto9AMFlag = (time >= Global.Settings.Times.SevenAM && time < Global.Settings.Times.NineAM).ToFlag(); int from9AMto3PMFlag = (time >= Global.Settings.Times.NineAM && time < Global.Settings.Times.ThreePM).ToFlag(); int from3PMto6PMFlag = (time >= Global.Settings.Times.ThreePM && time < Global.Settings.Times.SixPM).ToFlag(); int from6PMto10PMFlag = (time >= Global.Settings.Times.SixPM && time < Global.Settings.Times.TenPM).ToFlag(); int from10PMto7AMFlag = (time >= Global.Settings.Times.TenPM).ToFlag(); int from9AMto11AMFlag = (time >= Global.Settings.Times.NineAM && time < Global.Settings.Times.ElevenAM).ToFlag(); int from11AMto1PMFlag = (time >= Global.Settings.Times.ElevenAM && time < Global.Settings.Times.OnePM).ToFlag(); int from1PMto3PMFlag = (time >= Global.Settings.Times.OnePM && time < Global.Settings.Times.ThreePM).ToFlag(); int from3PMto5PMFlag = (time >= Global.Settings.Times.ThreePM && time < Global.Settings.Times.FivePM).ToFlag(); int from7PMto9PMFlag = (time >= Global.Settings.Times.SevenPM && time < Global.Settings.Times.NinePM).ToFlag(); int from9PMto11PMFlag = (time >= Global.Settings.Times.NinePM && time < Global.Settings.Times.ElevenPM).ToFlag(); int from11PMto7AMFlag = (time >= Global.Settings.Times.ElevenPM).ToFlag(); IEnumerable <PersonDayWrapper> orderedPersonDays = householdDay.PersonDays.OrderBy(p => p.GetJointTourParticipationPriority()).ToList().Cast <PersonDayWrapper>(); int numChildrenOnJointTour = 0; int numAdultsOnJointTour = 0; int totHHToursJT = 0; //int totHHStopsJT=0; TimeWindow timeWindow = new TimeWindow(); if (tour.JointTourSequence > 0) { foreach (PersonDayWrapper pDay in householdDay.PersonDays) { TourWrapper tInJoint = (TourWrapper)pDay.Tours.Find(t => t.JointTourSequence == tour.JointTourSequence); if (!(tInJoint == null)) { // set jointTour time window timeWindow.IncorporateAnotherTimeWindow(tInJoint.PersonDay.TimeWindow); totHHToursJT = personDay.HomeBasedTours + totHHToursJT; if (pDay.Person.Age < 18) { numChildrenOnJointTour++; } if (pDay.Person.Age >= 18) { numAdultsOnJointTour++; } } } } else if (trip.Direction == Global.Settings.TourDirections.OriginToDestination && tour.FullHalfTour1Sequence > 0) { foreach (PersonDayWrapper pDay in householdDay.PersonDays) { TourWrapper tInJoint = (TourWrapper)pDay.Tours.Find(t => t.FullHalfTour1Sequence == tour.FullHalfTour1Sequence); if (!(tInJoint == null)) { // set jointTour time window timeWindow.IncorporateAnotherTimeWindow(tInJoint.PersonDay.TimeWindow); timeWindow.IncorporateAnotherTimeWindow(tInJoint.PersonDay.TimeWindow); totHHToursJT = personDay.HomeBasedTours + totHHToursJT; if (pDay.Person.Age < 18) { numChildrenOnJointTour++; } if (pDay.Person.Age >= 18) { numAdultsOnJointTour++; } } } } else if (trip.Direction == Global.Settings.TourDirections.DestinationToOrigin && tour.FullHalfTour2Sequence > 0) { foreach (PersonDayWrapper pDay in householdDay.PersonDays) { TourWrapper tInJoint = (TourWrapper)pDay.Tours.Find(t => t.FullHalfTour2Sequence == tour.FullHalfTour2Sequence); if (!(tInJoint == null)) { // set jointTour time window timeWindow.IncorporateAnotherTimeWindow(tInJoint.PersonDay.TimeWindow); timeWindow.IncorporateAnotherTimeWindow(tInJoint.PersonDay.TimeWindow); totHHToursJT = personDay.HomeBasedTours + totHHToursJT; if (pDay.Person.Age < 18) { numChildrenOnJointTour++; } if (pDay.Person.Age >= 18) { numAdultsOnJointTour++; } } } } else if (tour.ParentTour == null) { timeWindow.IncorporateAnotherTimeWindow(personDay.TimeWindow); } else { timeWindow.IncorporateAnotherTimeWindow(tour.ParentTour.TimeWindow); } timeWindow.SetBusyMinutes(Global.Settings.Times.EndOfRelevantWindow, Global.Settings.Times.MinutesInADay + 1); // time window in minutes for yet unmodeled portion of halftour, only consider persons on this trip int availableWindow = timeWindow.AvailableWindow(destinationDepartureTime, Global.Settings.TimeDirections.Both); double timePressure = 1000 * remainingToursCount / (Math.Max(1D, availableWindow)); //alternative.AddUtilityTerm(98, 1000 * remainingToursCount / (Math.Max(1D, maxWindowRemaining))); //var duration = availableWindow / 60D; // connectivity attributes //var c34Ratio = trip.OriginParcel.C34RatioBuffer1(); double adis = 0.0; double logDist = 0.0; int minute = DayPeriod.BigDayPeriods[DayPeriod.MIDDAY].Start; //distance from origin to destination if (tour.OriginParcel != null && tour.DestinationParcel != null) { if (trip.Direction == Global.Settings.TourDirections.OriginToDestination) { adis = ImpedanceRoster.GetValue("distance", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, minute, tour.OriginParcel, destinationParcel).Variable; } else { adis = ImpedanceRoster.GetValue("distance", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, minute, destinationParcel, tour.OriginParcel).Variable; } logDist = Math.Log(1 + adis); } // 0 - NO MORE STOPS ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.NoneOrHome, !stopsNeeded, choice == Global.Settings.Purposes.NoneOrHome); alternative.Choice = Global.Settings.Purposes.NoneOrHome; //alternative.AddNestedAlternative(_nestedAlternativeIds[0], _nestedAlternativeIndexes[0], THETA_PARAMETER); alternative.AddUtilityTerm(1, oneSimulatedTripFlag); alternative.AddUtilityTerm(2, twoSimulatedTripsFlag); alternative.AddUtilityTerm(2, threeSimulatedTripsFlag); alternative.AddUtilityTerm(2, fourSimulatedTripsFlag); alternative.AddUtilityTerm(2, fivePlusSimulatedTripsFlag); //GV: 21. june 2016, not sign. //alternative.AddUtilityTerm(6, transitTourFlag); alternative.AddUtilityTerm(7, bikeTourFlag); alternative.AddUtilityTerm(8, walkTourFlag); alternative.AddUtilityTerm(9, jointHalfTour); alternative.AddUtilityTerm(10, halfTourFromOriginFlag); //GV: june 2016 - not sign //alternative.AddUtilityTerm(11, totalAggregateLogsum); alternative.AddUtilityTerm(12, businessTourFlag); alternative.AddUtilityTerm(13, personalBusinessTourFlag); alternative.AddUtilityTerm(14, socialTourFlag); //alternative.AddUtilityTerm(15, schoolTourFlag); alternative.AddUtilityTerm(16, escortTourFlag); alternative.AddUtilityTerm(17, shoppingTourFlag); alternative.AddUtilityTerm(18, timePressure); //GV: 21. june 2016, try to estimate again alternative.AddUtilityTerm(19, primaryFamilyTimeFlag); alternative.AddUtilityTerm(20, person.IsChildUnder5.ToFlag()); //alternative.AddUtilityTerm(15, from11PMto7AMFlag); //alternative.AddUtilityTerm(1, twoSimulatedTripsFlag * halfTourFromOriginFlag * isIndividualTour); //alternative.AddUtilityTerm(2, threeSimulatedTripsFlag * halfTourFromOriginFlag * isIndividualTour); //alternative.AddUtilityTerm(3, fourSimulatedTripsFlag * halfTourFromOriginFlag * isIndividualTour); //alternative.AddUtilityTerm(4, fivePlusSimulatedTripsFlag * halfTourFromOriginFlag * isIndividualTour); //alternative.AddUtilityTerm(5, twoSimulatedTripsFlag * halfTourFromDestinationFlag * isIndividualTour); //alternative.AddUtilityTerm(6, threeSimulatedTripsFlag * halfTourFromDestinationFlag * isIndividualTour); //alternative.AddUtilityTerm(7, fourSimulatedTripsFlag * halfTourFromDestinationFlag * isIndividualTour); //alternative.AddUtilityTerm(8, fivePlusSimulatedTripsFlag * halfTourFromDestinationFlag * isIndividualTour); //alternative.AddUtilityTerm(9, homeBasedTours * isIndividualTour); //alternative.AddUtilityTerm(10, homeBasedTours * isJointTour); //alternative.AddUtilityTerm(11, notHomeBasedTourFlag); //alternative.AddUtilityTerm(12, beforeMandatoryDestinationFlag*isJointTour); //alternative.AddUtilityTerm(13, beforeMandatoryDestinationFlag); //alternative.AddUtilityTerm(14, numAdultsOnJointTour); //alternative.AddUtilityTerm(15, numChildrenOnJointTour); //alternative.AddUtilityTerm(16, totHHToursJT); // alternative.AddUtilityTerm(17, totHHStopsJT); //alternative.AddUtilityTerm(22, (threeSimulatedTripsFlag + fourSimulatedTripsFlag + fivePlusSimulatedTripsFlag) * halfTourFromOriginFlag * isJointTour); //alternative.AddUtilityTerm(26, threeSimulatedTripsFlag * halfTourFromDestinationFlag * isJointTour); //alternative.AddUtilityTerm(27, fourSimulatedTripsFlag * halfTourFromDestinationFlag * isJointTour); //alternative.AddUtilityTerm(28, fivePlusSimulatedTripsFlag * halfTourFromDestinationFlag * isJointTour); // 1 - BUSINESS STOP //if (personDay.BusinessStops > 0 && (tour.DestinationPurpose <= Global.Settings.Purposes.School || tour.DestinationPurpose == Global.Settings.Purposes.Business)) { // JLB 20130704 business stops are allowed on escort tours per data prep alternative = choiceProbabilityCalculator.GetAlternative(1, (personDay.BusinessStops > 0 && (tour.DestinationPurpose <= Global.Settings.Purposes.Escort || tour.DestinationPurpose == Global.Settings.Purposes.Business) && (halfTour.SimulatedTrips <= 5) && timeIsAvailableForAnotherTrip), choice == Global.Settings.Purposes.Business); alternative.Choice = Global.Settings.Purposes.Business; //alternative.AddNestedAlternative(_nestedAlternativeIds[1], _nestedAlternativeIndexes[1], THETA_PARAMETER); //alternative.AddUtilityTerm(32, isIndividualTour); alternative.AddUtilityTerm(32, 1.0); //GV: june 2016 - not sign //alternative.AddUtilityTerm(33, businessTourFlag); //alternative.AddUtilityTerm(34, schoolTourFlag); //alternative.AddUtilityTerm(35, halfTourFromOriginFlag); //alternative.AddUtilityTerm(36, simulatedBusinessStops); //alternative.AddUtilityTerm(37, simulatedBusinessStopsFlag); //alternative.AddUtilityTerm(39, duration); //alternative.AddUtilityTerm(40, from9AMto11AMFlag + from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag); alternative.AddUtilityTerm(40, from9AMto3PMFlag + from3PMto6PMFlag); //alternative.AddUtilityTerm(42, logDist); //alternative.AddUtilityTerm(43, transitTourFlag); //alternative.AddUtilityTerm(44, (person.IsPartTimeWorker).ToFlag()); //GV: 21. aug - I commented out as it is the only logsum in the model //alternative.AddUtilityTerm(46, totalAggregateLogsum); //alternative.AddUtilityTerm(47,totEmpBuffer2); //alternative.AddUtilityTerm(48, hovDriverTourFlag + hovPassengerTourFlag); // 2 - SCHOOL STOP alternative = choiceProbabilityCalculator.GetAlternative(2, (((personDay.SchoolStops > 0 && tour.DestinationPurpose <= Global.Settings.Purposes.School) || (isJointTour == 1)) && halfTour.SimulatedTrips <= 5 && timeIsAvailableForAnotherTrip), choice == Global.Settings.Purposes.School); alternative.Choice = Global.Settings.Purposes.School; //alternative.AddNestedAlternative(_nestedAlternativeIds[2], _nestedAlternativeIndexes[2], THETA_PARAMETER); //alternative.AddUtilityTerm(51, workTourFlag); alternative.AddUtilityTerm(51, 1.0); //alternative.AddUtilityTerm(52, schoolTourFlag); //alternative.AddUtilityTerm(53, halfTourFromOriginFlag); //alternative.AddUtilityTerm(54, simulatedSchoolStops); //alternative.AddUtilityTerm(55, remainingToursCount); //alternative.AddUtilityTerm(56, duration); //alternative.AddUtilityTerm(57, from7AMto9AMFlag + from7PMto9PMFlag + from9PMto11PMFlag + from11PMto7AMFlag); alternative.AddUtilityTerm(57, from7AMto9AMFlag + from9AMto3PMFlag + from10PMto7AMFlag); //alternative.AddUtilityTerm(58, oneSimulatedTripFlag); //alternative.AddUtilityTerm(59, logDist); alternative.AddUtilityTerm(61, jointHalfOfFullJointHalfTour * numChildrenOnJointTour); //alternative.AddUtilityTerm(65, (person.Age < 12).ToFlag()); //alternative.AddUtilityTerm(66, (person.IsUniversityStudent).ToFlag()); // 3 - ESCORT STOP //if ((personDay.EscortStops > 0 && (tour.DestinationPurpose <= Global.Settings.Purposes.Escort || tour.DestinationPurpose == Global.Settings.Purposes.Business)) || (isJointTour==1)) { // JLB 20130704 no escort stops allowed on business tours per data prep alternative = choiceProbabilityCalculator.GetAlternative(3, (((personDay.EscortStops > 0 && tour.DestinationPurpose <= Global.Settings.Purposes.Escort) || (isJointTour == 1)) && halfTour.SimulatedTrips <= 5 && timeIsAvailableForAnotherTrip), choice == Global.Settings.Purposes.Escort); alternative.Choice = Global.Settings.Purposes.Escort; //alternative.AddNestedAlternative(_nestedAlternativeIds[3], _nestedAlternativeIndexes[3], THETA_PARAMETER); alternative.AddUtilityTerm(71, 1.0); //alternative.AddUtilityTerm(72, workTourFlag + schoolTourFlag); //alternative.AddUtilityTerm(72, isJointTour); //alternative.AddUtilityTerm(74, escortTourFlag); //alternative.AddUtilityTerm(75, socialOrRecreationTourFlag); //alternative.AddUtilityTerm(76, remainingToursCount); //alternative.AddUtilityTerm(77, duration); alternative.AddUtilityTerm(78, from7AMto9AMFlag); //alternative.AddUtilityTerm(79, from9AMto11AMFlag + from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag); //alternative.AddUtilityTerm(81, hovDriverTourFlag); //alternative.AddUtilityTerm(82, hovPassengerTourFlag); //alternative.AddUtilityTerm(83, simulatedEscortStops * isJointTour); //alternative.AddUtilityTerm(84, simulatedEscortStops * isIndividualTour); //alternative.AddUtilityTerm(85, totalAggregateLogsum); //alternative.AddUtilityTerm(86, jointHalfOfFullJointHalfTour); //alternative.AddUtilityTerm(88, enrollmentK8Buffer2); //alternative.AddUtilityTerm(89, numChildrenOnJointTour); //alternative.AddUtilityTerm(90, halfTourFromOriginFlag); // 4 - PERSONAL BUSINESS STOP alternative = choiceProbabilityCalculator.GetAlternative(4, ((personDay.PersonalBusinessStops > 0 || isJointTour == 1) && halfTour.SimulatedTrips <= 5 && timeIsAvailableForAnotherTrip), choice == Global.Settings.Purposes.PersonalBusiness); alternative.Choice = Global.Settings.Purposes.PersonalBusiness; //alternative.AddNestedAlternative(_nestedAlternativeIds[4], _nestedAlternativeIndexes[4], THETA_PARAMETER); alternative.AddUtilityTerm(91, 1.0); //alternative.AddUtilityTerm(92, (workTourFlag + schoolTourFlag + businessTourFlag)); //alternative.AddUtilityTerm(92, isJointTour); //alternative.AddUtilityTerm(93, escortTourFlag); //alternative.AddUtilityTerm(94, personalBusinessOrMedicalTourFlag * isIndividualTour); //alternative.AddUtilityTerm(95, shoppingTourFlag); //alternative.AddUtilityTerm(96, mealTourFlag); //alternative.AddUtilityTerm(97, socialOrRecreationTourFlag); //alternative.AddUtilityTerm(98, halfTourFromOriginFlag); //alternative.AddUtilityTerm(99, simulatedPersonalBusinessStops * isIndividualTour); //alternative.AddUtilityTerm(100, simulatedPersonalBusinessStops * isJointTour); //alternative.AddUtilityTerm(101, duration); //alternative.AddUtilityTerm(102, (from7AMto9AMFlag + from7PMto9PMFlag + from9PMto11PMFlag + from11PMto7AMFlag)); //alternative.AddUtilityTerm(103, from9AMto11AMFlag + from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag); alternative.AddUtilityTerm(103, from9AMto3PMFlag + from3PMto6PMFlag); //alternative.AddUtilityTerm(105, hovDriverTourFlag); //alternative.AddUtilityTerm(106, hovPassengerTourFlag); //alternative.AddUtilityTerm(109, jointHalfOfFullJointHalfTour); //alternative.AddUtilityTerm(110, totEmpBuffer2); //alternative.AddUtilityTerm(111, totalAggregateLogsum); //alternative.AddUtilityTerm(112, personalBusinessOrMedicalTourFlag * isJointTour); // 5 - SHOPPING STOP alternative = choiceProbabilityCalculator.GetAlternative(5, ((personDay.ShoppingStops > 0 || isJointTour == 1) && halfTour.SimulatedTrips <= 5 && timeIsAvailableForAnotherTrip), choice == Global.Settings.Purposes.Shopping); alternative.Choice = Global.Settings.Purposes.Shopping; //alternative.AddNestedAlternative(_nestedAlternativeIds[5], _nestedAlternativeIndexes[5], THETA_PARAMETER); alternative.AddUtilityTerm(121, 1.0); //alternative.AddUtilityTerm(122, workTourFlag + schoolTourFlag + businessTourFlag); //alternative.AddUtilityTerm(122, isJointTour); //alternative.AddUtilityTerm(123, escortTourFlag); //alternative.AddUtilityTerm(124, personalBusinessOrMedicalTourFlag); //alternative.AddUtilityTerm(125, shoppingTourFlag * isIndividualTour); //alternative.AddUtilityTerm(125, shoppingTourFlag); //alternative.AddUtilityTerm(126, mealTourFlag); //alternative.AddUtilityTerm(127, socialOrRecreationTourFlag); //alternative.AddUtilityTerm(128, halfTourFromOriginFlag); //alternative.AddUtilityTerm(129, simulatedShoppingStops * isIndividualTour); //alternative.AddUtilityTerm(130, simulatedShoppingStops * isJointTour); //alternative.AddUtilityTerm(131, duration); //alternative.AddUtilityTerm(132, from7AMto9AMFlag + from9PMto11PMFlag + from11PMto7AMFlag); //alternative.AddUtilityTerm(133, (from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag)); //alternative.AddUtilityTerm(132, from7AMto9AMFlag + from6PMto10PMFlag); alternative.AddUtilityTerm(133, (from9AMto3PMFlag + from3PMto6PMFlag + from6PMto10PMFlag)); //alternative.AddUtilityTerm(134, adultFemaleOnJointTour); //alternative.AddUtilityTerm(135, hovDriverTourFlag); //alternative.AddUtilityTerm(136, hovPassengerTourFlag); //alternative.AddUtilityTerm(137, Math.Log(1 + adis)); //alternative.AddUtilityTerm(138, shoppingTourFlag * isJointTour); //alternative.AddUtilityTerm(140, shoppingAggregateLogsum); //alternative.AddUtilityTerm(141, retailBuffer2); //alternative.AddUtilityTerm(142, numChildrenOnJointTour); //alternative.AddUtilityTerm(143, (household.Has100KPlusIncome).ToFlag()); //GV: 21. june 2016, not sign. //alternative.AddUtilityTerm(134, primaryFamilyTimeFlag); // 6 - MEAL STOP //alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Meal, false, choice == Global.Settings.Purposes.Meal); //alternative.Choice = Global.Settings.Purposes.Meal; //alternative.AddNestedAlternative(12, 2, THETA_PARAMETER); // 6 - SOCIAL (OR RECREATION) STOP alternative = choiceProbabilityCalculator.GetAlternative(6, ((personDay.SocialStops > 0 || isJointTour == 1) && halfTour.SimulatedTrips <= 5 && timeIsAvailableForAnotherTrip), choice == Global.Settings.Purposes.Social); alternative.Choice = Global.Settings.Purposes.Social; //alternative.AddNestedAlternative(_nestedAlternativeIds[6], _nestedAlternativeIndexes[6], THETA_PARAMETER); alternative.AddUtilityTerm(181, 1.0); //alternative.AddUtilityTerm(182, workTourFlag + schoolTourFlag + businessTourFlag); //alternative.AddUtilityTerm(182, isJointTour); //alternative.AddUtilityTerm(183, escortTourFlag); //alternative.AddUtilityTerm(184, personalBusinessOrMedicalTourFlag); //alternative.AddUtilityTerm(185, shoppingTourFlag); //alternative.AddUtilityTerm(186, mealTourFlag); //alternative.AddUtilityTerm(187, socialOrRecreationTourFlag); //alternative.AddUtilityTerm(188, halfTourFromOriginFlag); //alternative.AddUtilityTerm(189, simulatedSocialStops * isIndividualTour); //alternative.AddUtilityTerm(197, simulatedSocialStops * isJointTour); //alternative.AddUtilityTerm(190, remainingToursCount); //alternative.AddUtilityTerm(191, duration); //alternative.AddUtilityTerm(192, from7AMto9AMFlag + from11PMto7AMFlag); //alternative.AddUtilityTerm(192, from7AMto9AMFlag); alternative.AddUtilityTerm(192, from9AMto3PMFlag + from3PMto6PMFlag + from6PMto10PMFlag); //alternative.AddUtilityTerm(194, hovDriverTourFlag); //alternative.AddUtilityTerm(195, hovPassengerTourFlag); //alternative.AddUtilityTerm(196, logDist); //alternative.AddUtilityTerm(200, numAdultsOnJointTour); // 8 - RECREATION STOP //alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Recreation, false, choice == Global.Settings.Purposes.Recreation); //alternative.Choice = Global.Settings.Purposes.Recreation; //alternative.AddNestedAlternative(12, 2, THETA_PARAMETER); // 9 - MEDICAL STOP //alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Medical, false, choice == Global.Settings.Purposes.Medical); //alternative.Choice = Global.Settings.Purposes.Medical; //alternative.AddNestedAlternative(12, 2, THETA_PARAMETER); }
private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, PersonDayWrapper personDay, HouseholdDayWrapper householdDay, int nCallsForTour, int[] simulatedMandatoryTours, int choice = Constants.DEFAULT_VALUE) { var household = personDay.Household; Double workTourLogsum; if (personDay.Person.UsualWorkParcelId != Constants.DEFAULT_VALUE && personDay.Person.UsualWorkParcelId != Global.Settings.OutOfRegionParcelId) { //JLB 201406 //var nestedAlternative = Global.ChoiceModelSession.Get<WorkTourModeModel>().RunNested(personDay.Person, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualWorkParcel, Global.Settings.Times.EightAM, Global.Settings.Times.FivePM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers); 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(); } else { workTourLogsum = 0; } Double schoolTourLogsum; if (personDay.Person.UsualSchoolParcelId != Constants.DEFAULT_VALUE && personDay.Person.UsualSchoolParcelId != Global.Settings.OutOfRegionParcelId) { //JLB //var nestedAlternative = Global.ChoiceModelSession.Get<SchoolTourModeModel>().RunNested(personDay.Person, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualSchoolParcel, Global.Settings.Times.EightAM, Global.Settings.Times.FivePM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers); var nestedAlternative = Global.ChoiceModelSession.Get <SchoolTourModeTimeModel>().RunNested(personDay, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualSchoolParcel, Global.Settings.Times.EightAM, Global.Settings.Times.FivePM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers); schoolTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } else { schoolTourLogsum = 0; } 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 = Global.Settings.VotALSegments.Medium; // TODO: calculate a VOT segment that depends on household income var transitAccessSegment = household.ResidenceParcel.TransitAccessSegment(); var personalBusinessAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId] [Global.Settings.Purposes.PersonalBusiness][carOwnership][votALSegment][transitAccessSegment]; var shoppingAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId] [Global.Settings.Purposes.Shopping][carOwnership][votALSegment][transitAccessSegment]; var mealAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId] [Global.Settings.Purposes.Meal][carOwnership][votALSegment][transitAccessSegment]; var socialAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId] [Global.Settings.Purposes.Social][carOwnership][votALSegment][transitAccessSegment]; //var compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][carOwnership][votALSegment][transitAccessSegment]; var compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.NoCars][votALSegment][transitAccessSegment]; //int hasAdultEducLevel12 = 0; //int allAdultEducLevel12 = 1; int youngestAge = 999; foreach (PersonWrapper person in personDay.Household.Persons) { // set characteristics here that depend on person characteristics //if (person.Age >= 18 && person.EducationLevel >= 12) hasAdultEducLevel12 = 1; //if (person.Age >= 18 && person.EducationLevel < 12) allAdultEducLevel12 = 0; if (person.Age < youngestAge) { youngestAge = person.Age; } } 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(1, (nCallsForTour > 2).ToFlag()); // GV; 16.april 2013 - cannot be estimated //alternative.AddUtilityTerm(2, householdDay.Household.HasChildren.ToFlag()); alternative.AddUtilityTerm(3, householdDay.Household.HasChildrenUnder5.ToFlag()); alternative.AddUtilityTerm(4, householdDay.Household.HasChildrenAge5Through15.ToFlag()); //alternative.AddUtilityTerm(6, householdDay.Household.HasChildrenUnder16.ToFlag()); //alternative.AddUtilityTerm(10, (householdDay.Household.Size == 2).ToFlag()); // GV; 16. april 2013 - cannot be estimated alternative.AddUtilityTerm(11, (householdDay.Household.Size == 3).ToFlag()); alternative.AddUtilityTerm(12, (householdDay.Household.Size >= 4).ToFlag()); //alternative.AddUtilityTerm(14, (householdDay.Household.Income >= 300000 && householdDay.Household.Income < 600000).ToFlag()); //alternative.AddUtilityTerm(15, (householdDay.Household.Income >= 600000 && householdDay.Household.Income < 900000).ToFlag()); //alternative.AddUtilityTerm(16, (householdDay.Household.Income >= 900000).ToFlag()); //alternative.AddNestedAlternative(11, 0, 60); // USUAL WORK alternative = choiceProbabilityCalculator.GetAlternative(1, (personDay.Person.UsualWorkParcelId > 0 && simulatedMandatoryTours[2] == 0), choice == 1); alternative.Choice = 1; alternative.AddUtilityTerm(21, 1); //alternative.AddUtilityTerm(22, personDay.Person.IsChildUnder5.ToFlag()); alternative.AddUtilityTerm(23, personDay.Person.WorksAtHome.ToFlag()); alternative.AddUtilityTerm(24, personDay.Person.IsFulltimeWorker.ToFlag()); alternative.AddUtilityTerm(25, personDay.Person.IsMale.ToFlag()); //alternative.AddUtilityTerm(4, person.IsPartTimeWorker.ToFlag()); alternative.AddUtilityTerm(26, (householdDay.AdultsInSharedHomeStay == 2 && householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag()); //alternative.AddUtilityTerm(14, (householdDay.AdultsInSharedHomeStay == 2).ToFlag()); //alternative.AddUtilityTerm(15, (householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag()); alternative.AddUtilityTerm(27, (householdDay.AdultsInSharedHomeStay == 1 && householdDay.Household.HasChildren).ToFlag()); alternative.AddUtilityTerm(28, workTourLogsum); //alternative.AddUtilityTerm(28, (householdDay.Household.VehiclesAvailable == 1 && household.Has2Drivers).ToFlag()); alternative.AddUtilityTerm(29, (householdDay.Household.VehiclesAvailable >= 2 && household.Has2Drivers).ToFlag()); alternative.AddUtilityTerm(30, householdDay.PrimaryPriorityTimeFlag); //alternative.AddNestedAlternative(12, 1, 60); // BUSINESS alternative = choiceProbabilityCalculator.GetAlternative(2, (personDay.Person.IsWorker && simulatedMandatoryTours[3] == 0), choice == 2); alternative.Choice = 2; alternative.AddUtilityTerm(31, 1); //alternative.AddUtilityTerm(32, personDay.Person.IsChildUnder5.ToFlag()); alternative.AddUtilityTerm(33, personDay.Person.WorksAtHome.ToFlag()); alternative.AddUtilityTerm(34, personDay.Person.IsFulltimeWorker.ToFlag()); alternative.AddUtilityTerm(35, personDay.Person.IsMale.ToFlag()); //alternative.AddUtilityTerm(4, person.IsPartTimeWorker.ToFlag()); alternative.AddUtilityTerm(36, (householdDay.AdultsInSharedHomeStay == 2 && householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag()); //alternative.AddUtilityTerm(14, (householdDay.AdultsInSharedHomeStay == 2).ToFlag()); //alternative.AddUtilityTerm(15, (householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag()); alternative.AddUtilityTerm(37, (householdDay.AdultsInSharedHomeStay == 1 && householdDay.Household.HasChildren).ToFlag()); alternative.AddUtilityTerm(38, workTourLogsum); //alternative.AddUtilityTerm(38, (householdDay.Household.VehiclesAvailable == 1 && household.Has2Drivers).ToFlag()); alternative.AddUtilityTerm(39, (householdDay.Household.VehiclesAvailable >= 2 && household.Has2Drivers).ToFlag()); alternative.AddUtilityTerm(40, householdDay.PrimaryPriorityTimeFlag); //alternative.AddNestedAlternative(12, 1, 60); // SCHOOL alternative = choiceProbabilityCalculator.GetAlternative(3, schoolAvailableFlag, choice == 3); alternative.Choice = 3; alternative.AddUtilityTerm(41, 1); alternative.AddUtilityTerm(42, personDay.Person.IsNonworkingAdult.ToFlag()); //alternative.AddUtilityTerm(43, personDay.Person.IsPartTimeWorker.ToFlag()); alternative.AddUtilityTerm(43, personDay.Person.IsYouth.ToFlag()); //alternative.AddUtilityTerm(46, (householdDay.AdultsInSharedHomeStay == 2 && householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag()); //alternative.AddUtilityTerm(14, (householdDay.AdultsInSharedHomeStay == 2).ToFlag()); //alternative.AddUtilityTerm(15, (householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag()); //alternative.AddUtilityTerm(47, (householdDay.AdultsInSharedHomeStay == 1 && householdDay.Household.HasChildren).ToFlag()); alternative.AddUtilityTerm(48, workTourLogsum); alternative.AddUtilityTerm(49, schoolTourLogsum); //alternative.AddUtilityTerm(48, (householdDay.Household.VehiclesAvailable == 1 && household.Has2Drivers).ToFlag()); //alternative.AddUtilityTerm(49, (householdDay.Household.VehiclesAvailable >= 2 && household.Has2Drivers).ToFlag()); alternative.AddUtilityTerm(50, householdDay.PrimaryPriorityTimeFlag); //alternative.AddNestedAlternative(12, 1, 60); }
public void TestFullHalfTourSetParticipantTourSequence() { Global.Configuration = new Configuration(); Global.Configuration.HouseholdSamplingRateOneInX = 256; const int id = 1; const int householdDayId = 2; const int householdId = 3; const int day = 4; const int sequence = 5; const int direction = 6; const int participants = 7; const int personSequence1 = 8; const int tourSequence1 = 9; const int personSequence2 = 10; const int tourSequence2 = 11; const int personSequence3 = 12; const int tourSequence3 = 13; const int personSequence4 = 14; const int tourSequence4 = 15; const int personSequence5 = 16; const int tourSequence5 = 17; const int personSequence6 = 18; const int tourSequence6 = 19; const int personSequence7 = 20; const int tourSequence7 = 21; const int personSequence8 = 22; const int tourSequence8 = 23; FullHalfTour tour = new FullHalfTour { Day = day, Direction = direction, HouseholdDayId = householdDayId, HouseholdId = householdId, Id = id, Participants = participants, PersonSequence1 = personSequence1, TourSequence1 = tourSequence1, PersonSequence2 = personSequence2, TourSequence2 = tourSequence2, PersonSequence3 = personSequence3, TourSequence3 = tourSequence3, PersonSequence4 = personSequence4, TourSequence4 = tourSequence4, PersonSequence5 = personSequence5, TourSequence5 = tourSequence5, PersonSequence6 = personSequence6, TourSequence6 = tourSequence6, PersonSequence7 = personSequence7, TourSequence7 = tourSequence7, PersonSequence8 = personSequence8, TourSequence8 = tourSequence8, Sequence = sequence }; List <IPerson> persons = new List <IPerson> { new Person() }; HouseholdWrapper householdWrapper = TestHelper.GetHouseholdWrapper(persons); householdWrapper.Init(); //HouseholdDayWrapper householdDayWrapper = new HouseholdDayWrapper(new HouseholdDay(), householdWrapper, new PersonDayWrapperFactory()); HouseholdDayWrapper householdDayWrapper = TestHelper.GetHouseholdDayWrapper(householdWrapper); FullHalfTourWrapper.SetPersister(new PersisterWithHDF5 <FullHalfTour>(new TestFullHalfTourExporter())); FullHalfTourWrapper wrapper = new FullHalfTourWrapper(tour, householdDayWrapper); int[] sequences = new[] { 1, 2, 3, 4, 5, 6, 7, 8 }; int[] pSequences = new[] { personSequence1, personSequence2, personSequence3, personSequence4, personSequence5, personSequence6, personSequence7, personSequence8 }; for (int x = 0; x < 8; x++) { PersonWrapper person = TestHelper.GetPersonWrapper(sequence: pSequences[x]); PersonDayWrapper personDay = TestHelper.GetPersonDayWrapper(personWrapper: person, income: -1); const int destinationPurpose = Constants.Purpose.BUSINESS; Global.Configuration.Coefficients_BaseCostCoefficientIncomeLevel = 25000; Global.Configuration.Coefficients_StdDeviationTimeCoefficient_Other = .75; Global.Configuration.Coefficients_MeanTimeCoefficient_Other = .45; Global.Configuration.Coefficients_BaseCostCoefficientPerMonetaryUnit = 5; Tour ptour = new Tour(); TourWrapper tourWrapper = new TourWrapper(ptour, personDay, destinationPurpose, false) { Sequence = sequences[x] }; wrapper.SetParticipantTourSequence(tourWrapper); Assert.Equal(sequences[x], GetWrapperTourSequence(wrapper, x)); } }
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>(); PersonDayWrapper pPersonDay = null; // set household characteristics here that don't depend on person characteristics int hhsize = householdDay.Household.Size; int hhinc1 = householdDay.Household.Income <= 300000 ? 1 : 0; int hhinc2 = (householdDay.Household.Income > 300000 && householdDay.Household.Income <= 600000) ? 1 : 0; int hhinc3 = (householdDay.Household.Income > 600000 && householdDay.Household.Income <= 900000) ? 1 : 0; //int hhinc4 = (householdDay.Household.Income > 900000 && householdDay.Household.Income <= 1200000) ? 1 : 0; int hhinc4 = (householdDay.Household.Income > 900000) ? 1 : 0; IParcelWrapper[] pUsualLocation = new IParcelWrapper[6]; int[] pPatternType = new int[6]; int[] pConstant = new int[6]; int[] pType9 = new int[6]; int[] pType8 = new int[6]; int[] pType7 = new int[6]; int[] pType6 = new int[6]; int[] pType5 = new int[6]; int[] pType4 = new int[6]; int[] pType3 = new int[6]; int[] pType2 = new int[6]; int[] pType1 = new int[6]; int[] pAdult = new int[6]; int[] pAdultWithChildrenUnder16 = new int[6]; int[] pAdultFemale = new int[6]; int[] pAdultNonMandatory = new int[6]; int[] pType7AgeUnder12 = new int[6]; int[] pType7Age12Plus = new int[6]; int[] pAgeUnder12 = new int[6]; int[] pType8Mandatory = new int[6]; int[] pType8NonMandatory = new int[6]; int[] pType7Mandatory = new int[6]; int[] pType7NonMandatory = new int[6]; int[] pAgeUnder16 = new int[6]; int[] pYouthMandatory = new int[6]; int[] pYouthNonMandatory = new int[6]; int[] pYouth = new int[6]; int[] pAdultMandatory = new int[6]; int[] pMandatory = new int[6]; int[] pNonMandatory = 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) { pUsualLocation[count] = personDay.Person.UsualWorkParcel; } else if (personDay.Person.IsStudent) { pUsualLocation[count] = personDay.Person.UsualSchoolParcel; } else if (personDay.Person.IsWorker && personDay.Person.IsNotFullOrPartTimeWorker) { pUsualLocation[count] = personDay.Person.UsualWorkParcel; } else { pUsualLocation[count] = personDay.Household.ResidenceParcel; } pPatternType[count] = personDay.PatternType; pConstant[count] = 1; pType9[count] = personDay.Person.IsChildUnder16.ToFlag(); // not one og Type 1 to 8 pType8[count] = personDay.Person.IsChildUnder5.ToFlag(); // All ACTUM TU persons are one of Type 1 to 8 pType7[count] = personDay.Person.IsChildAge5Through15.ToFlag(); pType6[count] = personDay.Person.IsDrivingAgeStudent.ToFlag(); pType5[count] = personDay.Person.IsUniversityStudent.ToFlag(); pType4[count] = personDay.Person.IsNonworkingAdult.ToFlag(); pType3[count] = personDay.Person.IsRetiredAdult.ToFlag(); pType2[count] = personDay.Person.IsPartTimeWorker.ToFlag(); pType1[count] = personDay.Person.IsFulltimeWorker.ToFlag(); pAdult[count] = personDay.Person.IsAdult.ToFlag(); pAdultWithChildrenUnder16[count] = (personDay.Person.IsAdult && personDay.Household.HasChildrenUnder16).ToFlag(); // THIS person is adult and HH has child. under 16 pAdultFemale[count] = personDay.Person.IsAdultFemale.ToFlag(); pAdultNonMandatory[count] = (personDay.Person.IsAdult && personDay.PatternType == Global.Settings.PatternTypes.Optional).ToFlag(); pType7AgeUnder12[count] = (personDay.Person.IsChildAge5Through15 && personDay.Person.Age < 12).ToFlag(); // THIS person is both 5-15 AND below 12 pType7Age12Plus[count] = (personDay.Person.IsChildAge5Through15 && personDay.Person.Age >= 12).ToFlag(); pAgeUnder12[count] = (personDay.Person.Age < 12).ToFlag(); pAgeUnder16[count] = (personDay.Person.Age < 16).ToFlag(); pType8Mandatory[count] = (personDay.Person.IsChildUnder5 && personDay.PatternType == Global.Settings.PatternTypes.Mandatory).ToFlag(); pType8NonMandatory[count] = (personDay.Person.IsChildUnder5 && personDay.PatternType == Global.Settings.PatternTypes.Optional).ToFlag(); pType7Mandatory[count] = (personDay.Person.IsChildAge5Through15 && personDay.PatternType == Global.Settings.PatternTypes.Mandatory).ToFlag(); pType7NonMandatory[count] = (personDay.Person.IsChildAge5Through15 && personDay.PatternType == Global.Settings.PatternTypes.Optional).ToFlag(); pYouthMandatory[count] = (!personDay.Person.IsChildUnder5 && !personDay.Person.IsAdult && personDay.PatternType == Global.Settings.PatternTypes.Mandatory).ToFlag(); pYouthNonMandatory[count] = (!personDay.Person.IsChildUnder5 && !personDay.Person.IsAdult && personDay.PatternType == Global.Settings.PatternTypes.Optional).ToFlag(); pYouth[count] = (!personDay.Person.IsChildUnder5 && !personDay.Person.IsAdult).ToFlag(); pAdultMandatory[count] = (personDay.Person.IsAdult && personDay.PatternType == Global.Settings.PatternTypes.Mandatory).ToFlag(); pMandatory[count] = (personDay.PatternType == Global.Settings.PatternTypes.Mandatory).ToFlag(); pNonMandatory[count] = (personDay.PatternType == Global.Settings.PatternTypes.Optional).ToFlag(); pHasMandatoryTourToUsualLocation[count] = personDay.HasMandatoryTourToUsualLocation; pIsDrivingAge[count] = personDay.Person.IsDrivingAge; } } int componentIndex = 0; //Create person utility components int[] componentPerson = new int[6]; for (int p = 1; p <= 5; p++) { // create component for basic person-purposes componentIndex++; componentPerson[p] = componentIndex; choiceProbabilityCalculator.CreateUtilityComponent(componentPerson[p]); // these are dummies compared to base one, i.e. Type 5+6 in one. // OBS! - We apply "Adult Mandatory" as the base //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(1, pAdultMandatory[p]); // impact of adult with mandatory travel choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(2, pAdultNonMandatory[p]); // impact of adult with non-mandatory travel choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(3, pType8Mandatory[p]); // impact of child under 5 with mandatory travel //GV: not significant, 14. june 2016 //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(4, pType8NonMandatory[p]); // impact of child under 5 with non-mandatory travel //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(04, pYouthMandatory[p]); // impact of youth with mandatory travel //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(05, pYouthNonMandatory[p]); // impact of youth with non-mandatory travel choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(5, pType7Mandatory[p]); // impact of Child5-16 with mandatory travel //GV: not significant, 14. june 2016 //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(6, pType7NonMandatory[p]); // impact of Child5-16 with non-mandatory travel choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(7, pAdultFemale[p]); //female } //create two-way match interaction utility components int[,] componentMatch = new int[6, 6]; int[,] iMatchAgeUnder12 = new int[6, 6]; int[,] iMatchAgeUnder16 = new int[6, 6]; int[,] iMatchAgeUnder5 = new int[6, 6]; int[,] iMatchAge5to16 = new int[6, 6]; int[,] iMatchAdult = new int[6, 6]; int[,] iMatchAdultWithChildrenUnder16 = new int[6, 6]; int[,] iMatchAdultWithChildrenUnder5 = new int[6, 6]; int[,] iMatchAdultMandatory = new int[6, 6]; int[,] iMatchAdultNonMandatory = new int[6, 6]; int[,] iMatchMandatory = new int[6, 6]; int[,] iMatchNonMandatory = new int[6, 6]; int[,] iMatchAdultMandatoryAndAdultMandatory = new int[6, 6]; int[,] iMatchAdultNonMandatoryAndAdultNonMandatory = new int[6, 6]; for (int t2 = 1; t2 <= 5; t2++) { for (int t1 = 1; t1 < t2; t1++) { // iMatch joints only persons of the same type // lets the base alt, be adult*adult iMatchAgeUnder12[t1, t2] = pAgeUnder12[t1] * pAgeUnder12[t2]; // children under 12 iMatchAgeUnder16[t1, t2] = pAgeUnder16[t1] * pAgeUnder16[t2]; // children under 16 iMatchAgeUnder5[t1, t2] = pType8[t1] * pType8[t2]; // children under 5 iMatchAge5to16[t1, t2] = pType7[t1] * pType7[t2]; // children 5 to 16 iMatchAdult[t1, t2] = pAdult[t1] * pAdult[t2]; // two adults (very important but difficult to understand) iMatchAdultMandatory[t1, t2] = pAdultMandatory[t1] * pAdultMandatory[t2]; // two adults with mandatory travel iMatchAdultNonMandatory[t1, t2] = pAdultNonMandatory[t1] * pAdultNonMandatory[t2]; // two adults with non-mandatory travel iMatchMandatory[t1, t2] = pMandatory[t1] * pMandatory[t2]; //those with mandatory iMatchNonMandatory[t1, t2] = pNonMandatory[t1] * pNonMandatory[t2]; //those tith non-mandatory //iMatchAdultWithChildrenUnder16[t1, t2] = pAdultWithChildrenUnder16[t1] * pAdultWithChildrenUnder16[t2]; iMatchAdultWithChildrenUnder16[t1, t2] = pAdult[t1] * pType7[t2]; //adult plus child 5-16 iMatchAdultWithChildrenUnder5[t1, t2] = pAdult[t1] * pType8[t2]; //adult plus child5 iMatchAdultMandatoryAndAdultMandatory[t1, t2] = pAdultMandatory[t1] * pAdultMandatory[t2]; //2 adults with Mandatory iMatchAdultNonMandatoryAndAdultNonMandatory[t1, t2] = pAdultNonMandatory[t1] * pAdultNonMandatory[t2]; //2 adults with Mandatory //create and populate components // OBS! - We apply "Adult * Adult" as the base componentIndex++; componentMatch[t1, t2] = componentIndex; choiceProbabilityCalculator.CreateUtilityComponent(componentMatch[t1, t2]); choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(21, iMatchAgeUnder5[t1, t2]); //GV: 14. jine 2016, not sign. //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(22, iMatchAge5to16[t1, t2]); //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(23, iMatchAdultMandatoryAndAdultMandatory[t1, t2]); //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(24, iMatchAdultNonMandatoryAndAdultNonMandatory[t1, t2]); //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(23, iMatchAdult[t1, t2]); //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(24, iMatchAdultMandatory[t1, t2]); //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(25, iMatchAdultNonMandatory[t1, t2]); // commented out 22nd, but they work well //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(26, iMatchMandatory[t1, t2]); //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(27, iMatchNonMandatory[t1, t2]); } } //create two-way cross interaction utility components int[,] componentCross = new int[6, 6]; int[,] iCrossAgeUnderTwelveAndAdult = new int[6, 6]; int[,] iCrossAgeUnderTwelveAndAdultNonMandatory = new int[6, 6]; int[,] iCrossAdultWithChildUnder5 = new int[6, 6]; int[,] iCrossAdultWithChild5to16 = new int[6, 6]; int[,] iCrossAdultFemaleWithChildUnder5 = new int[6, 6]; int[,] iCrossAdultFemaleWithChild5to16 = new int[6, 6]; int[,] iCrossAdultMandatoryAndAdultNonMandatory = new int[6, 6]; int[,] iCrossAdultMandatoryAndAdultMandatory = new int[6, 6]; int[,] iCrossAdultNonMandatoryAndAdultNonMandatory = new int[6, 6]; int[,] iCrossYouthAndChildUnder5 = new int[6, 6]; int[,] iCrossChild5to16AndChildUnder5 = new int[6, 6]; for (int t2 = 1; t2 <= 5; t2++) { for (int t1 = 1; t1 <= 5; t1++) { if (!(t1 == t2)) { //populate cross variables // again, one is base, all others are dummies iCrossAdultWithChildUnder5[t1, t2] = pAdult[t1] * pType8[t2]; //adult plus child5 iCrossAdultWithChild5to16[t1, t2] = pAdult[t1] * pType7[t2]; //adult plus child 5-16 iCrossAdultFemaleWithChildUnder5[t1, t2] = pAdultFemale[t1] * pType8[t2]; //adult mom plus child5 iCrossAdultFemaleWithChild5to16[t1, t2] = pAdult[t1] * pType7[t2]; //adult mom plus child 5-16 iCrossAgeUnderTwelveAndAdult[t1, t2] = pAgeUnder12[t1] * pAdult[t2]; iCrossAgeUnderTwelveAndAdultNonMandatory[t1, t2] = pAgeUnder12[t1] * pAdultNonMandatory[t2]; iCrossAdultMandatoryAndAdultNonMandatory[t1, t2] = pAdultMandatory[t1] * pAdultNonMandatory[t2]; iCrossAdultMandatoryAndAdultMandatory[t1, t2] = pAdultMandatory[t1] * pAdultMandatory[t2]; iCrossAdultNonMandatoryAndAdultNonMandatory[t1, t2] = pAdultNonMandatory[t1] * pAdultNonMandatory[t2]; iCrossYouthAndChildUnder5[t1, t2] = pYouth[t1] * pType8[t2]; iCrossChild5to16AndChildUnder5[t1, t2] = pType7[t1] * pType8[t2]; //create and populate cross components // OBS! - We apply "Adult Mandatory * Adult Non-mandatory" as the base componentIndex++; componentCross[t1, t2] = componentIndex; choiceProbabilityCalculator.CreateUtilityComponent(componentCross[t1, t2]); choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(41, iCrossAdultWithChildUnder5[t1, t2]); choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(42, iCrossAdultWithChild5to16[t1, t2]); //choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(43, iCrossAdultMandatoryAndAdultNonMandatory[t1, t2]); //GV: 14. june 2016, not sign. //choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(46, iCrossAdultFemaleWithChildUnder5[t1, t2]); //choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(47, iCrossYouthAndChildUnder5[t1, t2]); choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(47, iCrossChild5to16AndChildUnder5[t1, t2]); //choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(45, iCrossAdultFemaleWithChild5to16[t1, t2]); //choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(41, iCrossAgeUnderTwelveAndAdult[t1, t2]); //choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(42, iCrossAgeUnderTwelveAndAdultNonMandatory[t1, t2]); } } } //Generate utility funtions for the alternatives bool[] available = new bool[32]; bool[] chosen = new bool[32]; bool[] threeParticipants = new bool[32]; bool[] fourPlusParticipants = new bool[32]; 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-adult 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] != null && pUsualLocation[i].Id > 0 && !(pAdult[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] == sameUsualLocation) && !(pAdult[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; } // require at least one driving age (as chauffeur) //GV:out july 2013 //int numberDrivingAge = 0; //for (int i = 1; i <= 5; i++) { // if (altParticipants[alt][i] == 1 && pIsDrivingAge[i]) { // numberDrivingAge++; // } //} //if (numberDrivingAge == 0) { // available[alt] = false; //} double tourLogsum; int destinationArrivalTime = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.WorkTourModeModel); int destinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.WorkTourModeModel); //var nestedAlternative = ActumWorkTourModeModel.RunNested(pPersonDay, pPersonDay.Household.ResidenceParcel, sameUsualLocation, destinationArrivalTime, destinationDepartureTime, pPersonDay.Household.VehiclesAvailable); //var nestedAlternative = (Global.ChoiceModelDictionary.Get("ActumWorkTourModeModel") as ActumWorkTourModeModel).RunNested(personDay, residenceParcel, person.UsualWorkParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable); //JLB 201406 //var nestedAlternative = Global.ChoiceModelSession.Get<WorkTourModeModel>().RunNested(pPersonDay, pPersonDay.Household.ResidenceParcel, sameUsualLocation, destinationArrivalTime, destinationDepartureTime, pPersonDay.Household.VehiclesAvailable); //JLB 201602 //var nestedAlternative = Global.ChoiceModelSession.Get<WorkTourModeTimeModel>().RunNested(pPersonDay, pPersonDay.Household.ResidenceParcel, sameUsualLocation, destinationArrivalTime, destinationDepartureTime, pPersonDay.Household.VehiclesAvailable); ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <TourModeTimeModel>().RunNested(pPersonDay, pPersonDay.Household.ResidenceParcel, sameUsualLocation, destinationArrivalTime, destinationDepartureTime, pPersonDay.Household.VehiclesAvailable, Global.Settings.Purposes.Work); tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); // determine choice if (choice == alt) { chosen[alt] = true; } //Get the alternative ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(alt, available[alt], chosen[alt]); alternative.Choice = alt; //Add utility terms that are not in components //alternative.AddUtilityTerm(399, 0); // OBS!!! This is new - 21nd January 2013 - it sais that these tris are less expected to be done with 3 or 4+ persons (compared to to people) alternative.AddUtilityTerm(59, altParticipants[alt][7] >= 3 ? 1 : 0); //alternative.AddUtilityTerm(60, altParticipants[alt][7] >= 4 ? 1 : 0); // OBS! no observations with 4+ HHsize alternative.AddUtilityTerm(58, tourLogsum); //Add utility components for (int p = 1; p <= 5; p++) { if (altParticipants[alt][p] == 1) { alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p])); } } for (int t2 = 1; t2 <= 5; t2++) { for (int t1 = 1; t1 < t2; t1++) { if (altParticipants[alt][t1] == 1 && altParticipants[alt][t2] == 1) { alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2])); } } } for (int t2 = 1; t2 <= 5; t2++) { for (int 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 InitializeDayPatterns(PersonDayWrapper personDay, DayPattern[] dayPatterns) { // if (_dayPatterns != null) { // return; // } var workTours = personDay.WorkTours > 0 ? 1 : 0; var schoolTours = personDay.SchoolTours > 0 ? 1 : 0; var businessTours = personDay.BusinessTours > 0 ? 1 : 0; var workStops = personDay.WorkStops > 0 ? 1 : 0; var schoolStops = personDay.SchoolStops > 0 ? 1 : 0; var businessStops = personDay.BusinessStops > 0 ? 1 : 0; var priorEscortTours = (personDay.EscortFullHalfTours > 0 || personDay.EscortJointTours > 0) ? 1 : 0; var priorPersonalBusinessTours = personDay.PersonalBusinessJointTours > 0 ? 1 : 0; var priorShoppingTours = personDay.ShoppingJointTours > 0 ? 1 : 0; var priorSocialTours = personDay.SocialJointTours > 0 ? 1 : 0; var alternativeIndex = -1; for (var escortTours = 0; escortTours <= 1; escortTours++) { for (var personalBusinessTours = 0; personalBusinessTours <= 1; personalBusinessTours++) { for (var shoppingTours = 0; shoppingTours <= 1; shoppingTours++) { for (var socialTours = 0; socialTours <= 1; socialTours++) { for (var escortStops = 0; escortStops <= 1; escortStops++) { for (var personalBusinessStops = 0; personalBusinessStops <= 1; personalBusinessStops++) { for (var shoppingStops = 0; shoppingStops <= 1; shoppingStops++) { for (var socialStops = 0; socialStops <= 1; socialStops++) { var totalNonMandatoryTourPurposes = escortTours + personalBusinessTours + shoppingTours + socialTours; var totalNonMandatoryStopPurposes = escortStops + personalBusinessStops + shoppingStops + socialStops; var totalTourPurposes = totalNonMandatoryTourPurposes + workTours + schoolTours + businessTours; var totalStopPurposes = totalNonMandatoryStopPurposes + workStops + schoolStops + businessStops; // checks for: // three tours or less // four stops or less // five stops total or less if (totalNonMandatoryTourPurposes > 3 || totalNonMandatoryStopPurposes > 4 || totalNonMandatoryTourPurposes + totalNonMandatoryStopPurposes > 5) { continue; } alternativeIndex++; // next alternative var tours = new int[Global.Settings.Purposes.TotalPurposes]; tours[Global.Settings.Purposes.Work] = workTours; tours[Global.Settings.Purposes.School] = schoolTours; tours[Global.Settings.Purposes.Business] = businessTours; tours[Global.Settings.Purposes.Escort] = escortTours; tours[Global.Settings.Purposes.PersonalBusiness] = personalBusinessTours; tours[Global.Settings.Purposes.Shopping] = shoppingTours; tours[Global.Settings.Purposes.Social] = socialTours; var stops = new int[Global.Settings.Purposes.TotalPurposes]; stops[Global.Settings.Purposes.Work] = workStops; stops[Global.Settings.Purposes.School] = schoolStops; stops[Global.Settings.Purposes.Business] = businessStops; stops[Global.Settings.Purposes.Escort] = escortStops; stops[Global.Settings.Purposes.PersonalBusiness] = personalBusinessStops; stops[Global.Settings.Purposes.Shopping] = shoppingStops; stops[Global.Settings.Purposes.Social] = socialStops; bool available = totalNonMandatoryStopPurposes > 0 && totalTourPurposes == 0 ? false : priorEscortTours > 0 && escortTours == 0 ? false : priorPersonalBusinessTours > 0 && personalBusinessTours == 0 ? false : priorShoppingTours > 0 && shoppingTours == 0 ? false : priorSocialTours > 0 && socialTours == 0 ? false : totalTourPurposes > 3 || totalStopPurposes > 4 || totalTourPurposes + totalStopPurposes > 5 ? false : Math.Min(totalStopPurposes, 1) > totalTourPurposes ? false : true; dayPatterns[alternativeIndex] = new DayPattern(tours, totalTourPurposes, stops, totalStopPurposes, available); } } } } } } } } }