private static void GenerateSubtours(ITourWrapper tour, int batchNumber) { // when the tour is to the usual work location then subtours for a work-based tour are created if (tour.Person.UsualWorkParcel == null || tour.DestinationParcel == null || tour.DestinationParcel != tour.Person.UsualWorkParcel || !Global.Configuration.ShouldRunWorkBasedSubtourGenerationModel) { return; } if (Global.Configuration.IsInEstimationMode) { var nCallsForTour = 0; foreach (var subtour in tour.Subtours) { // -- in estimation mode -- // sets the destination purpose of the subtour when in application mode ChoiceModelFactory.TotalTimesWorkBasedSubtourGenerationModelRun[batchNumber]++; nCallsForTour++; Global.ChoiceModelSession.Get <WorkBasedSubtourGenerationModel>().Run(tour, nCallsForTour, subtour.DestinationPurpose); } nCallsForTour++; ChoiceModelFactory.TotalTimesWorkBasedSubtourGenerationModelRun[batchNumber]++; Global.ChoiceModelSession.Get <WorkBasedSubtourGenerationModel>().Run(tour, nCallsForTour); } else { // creates the subtours for work tour var nCallsForTour = 0; while (tour.Subtours.Count < 4) { // -- in application mode -- // sets the destination purpose of the subtour ChoiceModelFactory.TotalTimesWorkBasedSubtourGenerationModelRun[batchNumber]++; nCallsForTour++; var destinationPurposeForSubtour = Global.ChoiceModelSession.Get <WorkBasedSubtourGenerationModel>().Run(tour, nCallsForTour); if (destinationPurposeForSubtour == Global.Settings.Purposes.NoneOrHome) { break; } // the subtour is added to the tour's Subtours collection when the subtour's purpose is not NONE_OR_HOME tour.Subtours.Add(tour.CreateSubtour(tour.DestinationAddressType, tour.DestinationParcelId, tour.DestinationZoneKey, destinationPurposeForSubtour)); } tour.PersonDay.WorkBasedTours += tour.Subtours.Count; } }