private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITripWrapper trip, int choice = Constants.DEFAULT_VALUE)
        {
            IHouseholdWrapper household = trip.Household;
            IPersonWrapper    person    = trip.Person;
            IPersonDayWrapper personDay = trip.PersonDay;
            ITourWrapper      tour      = trip.Tour;

            Framework.DomainModels.Models.IHalfTour halfTour = trip.HalfTour;

            // household inputs
            int childrenFlag           = household.HasChildren.ToFlag();
            int onePersonHouseholdFlag = household.IsOnePersonHousehold.ToFlag();

            // person inputs
            int adultMaleFlag          = person.IsAdultMale.ToFlag();
            int adultFemaleFlag        = person.IsAdultFemale.ToFlag();
            int partTimeWorkerFlag     = person.IsPartTimeWorker.ToFlag();
            int retiredAdultFlag       = person.IsRetiredAdult.ToFlag();
            int drivingAgeStudentFlag  = person.IsDrivingAgeStudent.ToFlag();
            int nonworkingAdultFlag    = person.IsNonworkingAdult.ToFlag();
            int childAge5Through15Flag = person.IsChildAge5Through15.ToFlag();
            int childUnder5Flag        = person.IsChildUnder5.ToFlag();

            // person-day inputs
            int homeBasedTours     = personDay.HomeBasedTours;
            int simulatedToursFlag = personDay.SimulatedToursExist().ToFlag();

            int simulatedWorkStops     = personDay.SimulatedWorkStops;
            int simulatedWorkStopsFlag = personDay.SimulatedWorkStopsExist().ToFlag();

            int simulatedSchoolStops = personDay.SimulatedSchoolStops;
            //            var simulatedSchoolStopsFlag = personDay.HasSimulatedSchoolStops.ToFlag();

            int simulatedEscortStops = personDay.SimulatedEscortStops;
            //            var simulatedEscortStopsFlag = personDay.HasSimulatedEscortStops.ToFlag();

            int simulatedPersonalBusinessStops = personDay.SimulatedPersonalBusinessStops;
            //            var simulatedPersonalBusinessStopsFlag = personDay.HasSimulatedPersonalBusinessStops.ToFlag();

            int simulatedShoppingStops = personDay.SimulatedShoppingStops;
            //            var simulatedShoppingStopsFlag = personDay.HasSimulatedShoppingStops.ToFlag();

            int simulatedMealStops = personDay.SimulatedMealStops;
            //            var simulatedMealStopsFlag = personDay.HasSimulatedMealStops.ToFlag();

            int simulatedSocialStops = personDay.SimulatedSocialStops;
            //            var simulatedSocialStopsFlag = personDay.HasSimulatedSocialStops.ToFlag();

            // tour inputs
            int hov2TourFlag         = tour.IsHov2Mode().ToFlag();
            int hov3TourFlag         = tour.IsHov3Mode().ToFlag();
            int transitTourFlag      = tour.IsTransitMode().ToFlag();
            int bikeTourFlag         = tour.IsBikeMode().ToFlag();
            int walkTourFlag         = tour.IsWalkMode().ToFlag();
            int notHomeBasedTourFlag = (!tour.IsHomeBasedTour).ToFlag();
            int workTourFlag         = tour.IsWorkPurpose().ToFlag();
            int personalBusinessOrMedicalTourFlag = tour.IsPersonalBusinessOrMedicalPurpose().ToFlag();
            int socialOrRecreationTourFlag        = tour.IsSocialOrRecreationPurpose().ToFlag();
            int schoolTourFlag   = tour.IsSchoolPurpose().ToFlag();
            int escortTourFlag   = tour.IsEscortPurpose().ToFlag();
            int shoppingTourFlag = tour.IsShoppingPurpose().ToFlag();
            int mealTourFlag     = tour.IsMealPurpose().ToFlag();

            // trip inputs
            int oneSimulatedTripFlag           = halfTour.OneSimulatedTripFlag;
            int twoSimulatedTripsFlag          = halfTour.TwoSimulatedTripsFlag;
            int threeSimulatedTripsFlag        = halfTour.ThreeSimulatedTripsFlag;
            int fourSimulatedTripsFlag         = halfTour.FourSimulatedTripsFlag;
            int fiveSimulatedTripsFlag         = halfTour.FiveSimulatedTripsFlag;
            int halfTourFromOriginFlag         = trip.IsHalfTourFromOrigin.ToFlag();
            int halfTourFromDestinationFlag    = (!trip.IsHalfTourFromOrigin).ToFlag();
            int beforeMandatoryDestinationFlag = trip.IsBeforeMandatoryDestination().ToFlag();

            // remaining inputs
            int time = trip.IsHalfTourFromOrigin ? tour.DestinationArrivalTime : tour.DestinationDepartureTime;

            int from7AMto9AMFlag  = (time >= Global.Settings.Times.SevenAM && time < Global.Settings.Times.NineAM).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();

            double foodRetailServiceMedicalQtrMileLog = household.ResidenceParcel.FoodRetailServiceMedicalLogBuffer1();
            int    remainingToursCount = personDay.HomeBasedTours - personDay.GetTotalSimulatedTours();

            // time-of-day for trip window calculations
            int startTime = trip.GetStartTime();

            // time window in minutes and in hours for yet unmodeled portion of half-tour, only consider persons on this trip
            int timeWindow =
                tour.IsHomeBasedTour
                    ? personDay.TimeWindow.AvailableWindow(startTime, Global.Settings.TimeDirections.Both)
                    : tour.ParentTour.TimeWindow.AvailableWindow(startTime, Global.Settings.TimeDirections.Both);

            double duration = timeWindow / 60D;

            // connectivity attributes
            double c34Ratio = trip.OriginParcel.C34RatioBuffer1();

            // 0 - NO MORE STOPS

            ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.NoneOrHome, true, choice == Global.Settings.Purposes.NoneOrHome);

            alternative.Choice = Global.Settings.Purposes.NoneOrHome;

            alternative.AddUtilityTerm(1, twoSimulatedTripsFlag * halfTourFromOriginFlag);
            alternative.AddUtilityTerm(2, threeSimulatedTripsFlag * halfTourFromOriginFlag);
            alternative.AddUtilityTerm(3, fourSimulatedTripsFlag * halfTourFromOriginFlag);
            alternative.AddUtilityTerm(4, fiveSimulatedTripsFlag * halfTourFromOriginFlag);
            alternative.AddUtilityTerm(5, twoSimulatedTripsFlag * halfTourFromDestinationFlag);
            alternative.AddUtilityTerm(6, threeSimulatedTripsFlag * halfTourFromDestinationFlag);
            alternative.AddUtilityTerm(7, fourSimulatedTripsFlag * halfTourFromDestinationFlag);
            alternative.AddUtilityTerm(8, fiveSimulatedTripsFlag * halfTourFromDestinationFlag);
            alternative.AddUtilityTerm(9, homeBasedTours);
            alternative.AddUtilityTerm(10, simulatedToursFlag);
            alternative.AddUtilityTerm(11, notHomeBasedTourFlag);
            alternative.AddUtilityTerm(12, beforeMandatoryDestinationFlag);
            alternative.AddUtilityTerm(16, (transitTourFlag + walkTourFlag + bikeTourFlag) * c34Ratio * foodRetailServiceMedicalQtrMileLog);
            alternative.AddUtilityTerm(17, transitTourFlag);
            alternative.AddUtilityTerm(40, schoolTourFlag);

            // 1 - WORK STOP

            if (personDay.WorkStops > 0 && tour.DestinationPurpose <= Global.Settings.Purposes.School)
            {
                alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Work, true, choice == Global.Settings.Purposes.Work);

                alternative.Choice = Global.Settings.Purposes.Work;

                alternative.AddUtilityTerm(33, workTourFlag + schoolTourFlag);
                //                alternative.AddUtility(47, escortTourFlag);
                //                alternative.AddUtility(54, personalBusinessOrMedicalTourFlag);
                //                alternative.AddUtility(61, shoppingTourFlag);
                //                alternative.AddUtility(68, mealTourFlag);
                //                alternative.AddUtility(75, socialOrRecreationTourFlag);
                alternative.AddUtilityTerm(82, halfTourFromOriginFlag);
                alternative.AddUtilityTerm(89, simulatedWorkStops);
                alternative.AddUtilityTerm(96, simulatedWorkStopsFlag);
                alternative.AddUtilityTerm(103, remainingToursCount);
                alternative.AddUtilityTerm(110, duration);
                alternative.AddUtilityTerm(131, from9AMto11AMFlag + from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag);
                alternative.AddUtilityTerm(175, adultMaleFlag);
            }
            else
            {
                choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Work, false, choice == Global.Settings.Purposes.Work);
            }

            // 2 - SCHOOL STOP

            if (personDay.SchoolStops > 0 && tour.DestinationPurpose <= Global.Settings.Purposes.School)
            {
                alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.School, true, choice == Global.Settings.Purposes.School);

                alternative.Choice = Global.Settings.Purposes.School;

                alternative.AddUtilityTerm(34, workTourFlag + schoolTourFlag);
                //                alternative.AddUtility(48, escortTourFlag);
                //                alternative.AddUtility(55, personalBusinessOrMedicalTourFlag);
                //                alternative.AddUtility(62, shoppingTourFlag);
                //                alternative.AddUtility(69, mealTourFlag);
                //                alternative.AddUtility(76, socialOrRecreationTourFlag);
                alternative.AddUtilityTerm(83, halfTourFromOriginFlag);
                alternative.AddUtilityTerm(90, simulatedSchoolStops);
                //                alternative.AddUtility(97, simulatedSchoolStopsFlag);
                alternative.AddUtilityTerm(104, remainingToursCount);
                alternative.AddUtilityTerm(111, duration);
                alternative.AddUtilityTerm(138, from7AMto9AMFlag + from7PMto9PMFlag + from9PMto11PMFlag + from11PMto7AMFlag);
                alternative.AddUtilityTerm(237, oneSimulatedTripFlag);
            }
            else
            {
                choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.School, false, choice == Global.Settings.Purposes.School);
            }

            // 3 - ESCORT STOP

            if (personDay.EscortStops > 0 && tour.DestinationPurpose <= Global.Settings.Purposes.Escort)
            {
                alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Escort, true, choice == Global.Settings.Purposes.Escort);

                alternative.Choice = Global.Settings.Purposes.Escort;

                alternative.AddUtilityTerm(35, workTourFlag + schoolTourFlag);
                alternative.AddUtilityTerm(49, escortTourFlag);
                //                alternative.AddUtility(56, personalBusinessOrMedicalTourFlag);
                //                alternative.AddUtility(63, shoppingTourFlag);
                //                alternative.AddUtility(70, mealTourFlag);
                //                alternative.AddUtility(77, socialOrRecreationTourFlag);
                alternative.AddUtilityTerm(84, halfTourFromOriginFlag);
                alternative.AddUtilityTerm(91, simulatedEscortStops);
                //                alternative.AddUtility(98, simulatedEscortStopsFlag);
                alternative.AddUtilityTerm(105, remainingToursCount);
                alternative.AddUtilityTerm(112, duration);
                alternative.AddUtilityTerm(146, from7AMto9AMFlag);
                alternative.AddUtilityTerm(147, from9AMto11AMFlag + from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag);
                alternative.AddUtilityTerm(181, childrenFlag * adultFemaleFlag);
                alternative.AddUtilityTerm(183, hov2TourFlag);
                alternative.AddUtilityTerm(184, hov3TourFlag);
                alternative.AddUtilityTerm(238, oneSimulatedTripFlag);
            }
            else
            {
                choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Escort, false, choice == Global.Settings.Purposes.Escort);
            }

            // 4 - PERSONAL BUSINESS STOP

            if (personDay.PersonalBusinessStops > 0)
            {
                alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.PersonalBusiness, true, choice == Global.Settings.Purposes.PersonalBusiness);

                alternative.Choice = Global.Settings.Purposes.PersonalBusiness;

                alternative.AddUtilityTerm(36, workTourFlag + schoolTourFlag);
                alternative.AddUtilityTerm(50, escortTourFlag);
                alternative.AddUtilityTerm(57, personalBusinessOrMedicalTourFlag);
                alternative.AddUtilityTerm(64, shoppingTourFlag);
                alternative.AddUtilityTerm(71, mealTourFlag);
                alternative.AddUtilityTerm(78, socialOrRecreationTourFlag);
                alternative.AddUtilityTerm(85, halfTourFromOriginFlag);
                alternative.AddUtilityTerm(92, simulatedPersonalBusinessStops);
                //                alternative.AddUtility(99, simulatedPersonalBusinessStopsFlag);
                alternative.AddUtilityTerm(106, remainingToursCount);
                alternative.AddUtilityTerm(113, duration);
                alternative.AddUtilityTerm(154, from7AMto9AMFlag + from7PMto9PMFlag + from9PMto11PMFlag + from11PMto7AMFlag);
                alternative.AddUtilityTerm(155, from9AMto11AMFlag + from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag);
                alternative.AddUtilityTerm(195, onePersonHouseholdFlag);
                alternative.AddUtilityTerm(196, hov2TourFlag);
                alternative.AddUtilityTerm(197, hov3TourFlag);
            }
            else
            {
                choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.PersonalBusiness, false, choice == Global.Settings.Purposes.PersonalBusiness);
            }

            // 5 - SHOPPING STOP

            if (personDay.ShoppingStops > 0)
            {
                alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Shopping, true, choice == Global.Settings.Purposes.Shopping);

                alternative.Choice = Global.Settings.Purposes.Shopping;

                alternative.AddUtilityTerm(37, workTourFlag + schoolTourFlag);
                alternative.AddUtilityTerm(51, escortTourFlag);
                alternative.AddUtilityTerm(58, personalBusinessOrMedicalTourFlag);
                alternative.AddUtilityTerm(65, shoppingTourFlag);
                alternative.AddUtilityTerm(72, mealTourFlag);
                alternative.AddUtilityTerm(79, socialOrRecreationTourFlag);
                alternative.AddUtilityTerm(86, halfTourFromOriginFlag);
                alternative.AddUtilityTerm(93, simulatedShoppingStops);
                //                alternative.AddUtility(100, simulatedShoppingStopsFlag);
                alternative.AddUtilityTerm(107, remainingToursCount);
                alternative.AddUtilityTerm(114, duration);
                alternative.AddUtilityTerm(162, from7AMto9AMFlag + from9PMto11PMFlag + from11PMto7AMFlag);
                alternative.AddUtilityTerm(164, from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag);
                alternative.AddUtilityTerm(207, childrenFlag * adultFemaleFlag);
                alternative.AddUtilityTerm(209, hov2TourFlag);
                alternative.AddUtilityTerm(210, hov3TourFlag);
            }
            else
            {
                choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Shopping, false, choice == Global.Settings.Purposes.Shopping);
            }

            // 6 - MEAL STOP

            if (personDay.MealStops > 0)
            {
                alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Meal, true, choice == Global.Settings.Purposes.Meal);

                alternative.Choice = Global.Settings.Purposes.Meal;

                alternative.AddUtilityTerm(38, workTourFlag);
                alternative.AddUtilityTerm(46, schoolTourFlag);
                alternative.AddUtilityTerm(52, escortTourFlag);
                alternative.AddUtilityTerm(59, personalBusinessOrMedicalTourFlag);
                alternative.AddUtilityTerm(66, shoppingTourFlag);
                alternative.AddUtilityTerm(73, mealTourFlag);
                alternative.AddUtilityTerm(80, socialOrRecreationTourFlag);
                alternative.AddUtilityTerm(87, halfTourFromOriginFlag);
                alternative.AddUtilityTerm(94, simulatedMealStops);
                //                alternative.AddUtility(101, simulatedMealStopsFlag);
                alternative.AddUtilityTerm(108, remainingToursCount);
                alternative.AddUtilityTerm(115, duration);
                alternative.AddUtilityTerm(170, from7AMto9AMFlag + from11PMto7AMFlag);
                alternative.AddUtilityTerm(171, from11AMto1PMFlag + from1PMto3PMFlag);
                alternative.AddUtilityTerm(172, from7PMto9PMFlag);
                alternative.AddUtilityTerm(221, onePersonHouseholdFlag);
                alternative.AddUtilityTerm(222, hov2TourFlag);
                alternative.AddUtilityTerm(223, hov3TourFlag);
                alternative.AddUtilityTerm(226, partTimeWorkerFlag + retiredAdultFlag + drivingAgeStudentFlag);
                alternative.AddUtilityTerm(228, nonworkingAdultFlag + childAge5Through15Flag + childUnder5Flag);
                alternative.AddUtilityTerm(239, oneSimulatedTripFlag);
            }
            else
            {
                choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Meal, false, choice == Global.Settings.Purposes.Meal);
            }

            // 7 - SOCIAL (OR RECREATION) STOP

            if (personDay.SocialStops > 0)
            {
                alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Social, true, choice == Global.Settings.Purposes.Social);

                alternative.Choice = Global.Settings.Purposes.Social;

                alternative.AddUtilityTerm(39, workTourFlag + schoolTourFlag);
                alternative.AddUtilityTerm(53, escortTourFlag);
                alternative.AddUtilityTerm(60, personalBusinessOrMedicalTourFlag);
                alternative.AddUtilityTerm(67, shoppingTourFlag);
                alternative.AddUtilityTerm(74, mealTourFlag);
                alternative.AddUtilityTerm(81, socialOrRecreationTourFlag);
                alternative.AddUtilityTerm(88, halfTourFromOriginFlag);
                alternative.AddUtilityTerm(95, simulatedSocialStops);
                //                alternative.AddUtility(102, simulatedSocialStopsFlag);
                alternative.AddUtilityTerm(109, remainingToursCount);
                alternative.AddUtilityTerm(116, duration);
                alternative.AddUtilityTerm(173, from7AMto9AMFlag + from11PMto7AMFlag);
                alternative.AddUtilityTerm(174, from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag);
                alternative.AddUtilityTerm(235, hov2TourFlag);
                alternative.AddUtilityTerm(236, hov3TourFlag);
            }
            else
            {
                choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Social, false, choice == Global.Settings.Purposes.Social);
            }
        }
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITripWrapper trip, IHouseholdDayWrapper householdDay, int choice = Constants.DEFAULT_VALUE)
        {
            IHouseholdWrapper household = trip.Household;
            IPersonWrapper    person    = trip.Person;
            IPersonDayWrapper personDay = trip.PersonDay;
            ITourWrapper      tour      = trip.Tour;

            Framework.DomainModels.Models.IHalfTour halfTour = trip.HalfTour;
            List <IPersonDayWrapper> personDays = householdDay.PersonDays;

            int            isJointTour       = tour.JointTourSequence > 0 ? 1 : 0;
            IParcelWrapper destinationParcel = tour.DestinationParcel;
            int            fullJointHalfTour = ((trip.Direction == Global.Settings.TourDirections.OriginToDestination && tour.FullHalfTour1Sequence > 0) ||
                                                (trip.Direction == Global.Settings.TourDirections.DestinationToOrigin && tour.FullHalfTour2Sequence > 0)).ToFlag();
            int partialJointHalfTour = ((trip.Direction == Global.Settings.TourDirections.OriginToDestination && tour.PartialHalfTour1Sequence > 0) ||
                                        (trip.Direction == Global.Settings.TourDirections.DestinationToOrigin && tour.PartialHalfTour2Sequence > 0)).ToFlag();
            int isJoint      = (isJointTour + fullJointHalfTour + partialJointHalfTour > 0) ? 1 : 0;
            int isIndividual = 1 - isJoint;

            //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 simulatedWorkStops             = personDay.SimulatedWorkStops;
            int simulatedWorkStopsFlag         = personDay.SimulatedWorkStopsExist().ToFlag();
            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;

            // tour inputs
            int hov2TourFlag         = tour.IsHov2Mode().ToFlag();
            int hov3TourFlag         = tour.IsHov3Mode().ToFlag();
            int transitTourFlag      = tour.IsTransitMode().ToFlag();
            int notHomeBasedTourFlag = (!tour.IsHomeBasedTour).ToFlag();
            int workTourFlag         = tour.IsWorkPurpose().ToFlag();
            int personalBusinessOrMedicalTourFlag = tour.IsPersonalBusinessOrMedicalPurpose().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();
            int mealTourFlag = tour.IsMealPurpose().ToFlag();

            // trip inputs
            int oneSimulatedTripFlag           = halfTour.OneSimulatedTripFlag;
            int twoSimulatedTripsFlag          = halfTour.TwoSimulatedTripsFlag;
            int threeSimulatedTripsFlag        = halfTour.ThreeSimulatedTripsFlag;
            int fourSimulatedTripsFlag         = halfTour.FourSimulatedTripsFlag;
            int fivePlusSimulatedTripsFlag     = halfTour.FivePlusSimulatedTripsFlag; //JLB changed 5 to 5Plus
            int halfTourFromOriginFlag         = trip.IsHalfTourFromOrigin.ToFlag();
            int halfTourFromDestinationFlag    = (!trip.IsHalfTourFromOrigin).ToFlag();
            int beforeMandatoryDestinationFlag = trip.IsBeforeMandatoryDestination().ToFlag();

            // remaining inputs, including joint tour variables
            int time = trip.IsHalfTourFromOrigin ? tour.DestinationArrivalTime : tour.DestinationDepartureTime;

            int from7AMto9AMFlag  = (time >= Global.Settings.Times.SevenAM && time < Global.Settings.Times.NineAM).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();

            int remainingToursCount = personDay.HomeBasedTours - personDay.GetTotalSimulatedTours();

            // connectivity attributes
            double 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, tour.DestinationParcel).Variable;
                }
                else
                {
                    adis = ImpedanceRoster.GetValue("distance", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, minute, destinationParcel, tour.OriginParcel).Variable;
                }
                logDist = Math.Log(1 + adis);
            }

            double shortestTravelTime = 0D;

            if (trip.Sequence > 1 && tour.OriginParcel != null && trip.OriginParcel != null)
            {
                if (trip.Direction == Global.Settings.TourDirections.OriginToDestination)
                {
                    shortestTravelTime = ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Hov2, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, minute, tour.OriginParcel, trip.OriginParcel).Variable;
                }
                else
                {
                    shortestTravelTime = ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Hov2, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, minute, trip.OriginParcel, tour.OriginParcel).Variable;
                }
            }

            double windowDuration = Math.Max(1.0,
                                             trip.IsHalfTourFromOrigin // first trip in half tour, use tour destination time
                    ? trip.Sequence == 1
                          ? tour.DestinationArrivalTime - tour.EarliestOriginDepartureTime - tour.IndicatedTravelTimeToDestination
                          : trip.GetPreviousTrip().ArrivalTime - tour.EarliestOriginDepartureTime - shortestTravelTime
                    : trip.Sequence == 1
                          ? tour.LatestOriginArrivalTime - tour.DestinationDepartureTime - tour.IndicatedTravelTimeFromDestination
                          : tour.LatestOriginArrivalTime - trip.GetPreviousTrip().ArrivalTime - shortestTravelTime);

            double duration = windowDuration / 60D;

            IEnumerable <PersonDayWrapper> orderedPersonDays = householdDay.PersonDays.OrderBy(p => p.GetJointTourParticipationPriority()).ToList().Cast <PersonDayWrapper>();
            int numChildrenOnJointTour = 0;
            int numAdultsOnJointTour   = 0;
            int totHHToursJT           = 0;

            //int totHHStopsJT=0;

            //MB use calculated variables at tour level rather than redoing time window
            //TimeWindow timeWindow = new TimeWindow();
            if (tour.JointTourSequence > 0)
            {
                foreach (PersonDayWrapper pDay in householdDay.PersonDays)
                {
                    ITourWrapper tInJoint = pDay.Tours.Find(t => t.JointTourSequence == tour.JointTourSequence);
                    if (!(tInJoint == null))
                    {
                        // set jointTour time window
                        //timeWindow.IncorporateAnotherTimeWindow(tInJoint.PersonDay.TimeWindow);
                        totHHToursJT = personDay.HomeBasedTours + totHHToursJT;

                        if (pDay.Person.Age < 18)
                        {
                            numChildrenOnJointTour++;
                        }

                        if (pDay.Person.Age >= 18)
                        {
                            numAdultsOnJointTour++;
                        }
                    }
                }
            }
            else if (trip.Direction == Global.Settings.TourDirections.OriginToDestination && tour.FullHalfTour1Sequence > 0)
            {
                foreach (PersonDayWrapper pDay in householdDay.PersonDays)
                {
                    ITourWrapper tInJoint = pDay.Tours.Find(t => t.FullHalfTour1Sequence == tour.FullHalfTour1Sequence);
                    if (!(tInJoint == null))
                    {
                        // set jointTour time window
                        //timeWindow.IncorporateAnotherTimeWindow(tInJoint.PersonDay.TimeWindow);
                        totHHToursJT = personDay.HomeBasedTours + totHHToursJT;

                        if (pDay.Person.Age < 18)
                        {
                            numChildrenOnJointTour++;
                        }

                        if (pDay.Person.Age >= 18)
                        {
                            numAdultsOnJointTour++;
                        }
                    }
                }
            }
            else if (trip.Direction == Global.Settings.TourDirections.DestinationToOrigin && tour.FullHalfTour2Sequence > 0)
            {
                foreach (PersonDayWrapper pDay in householdDay.PersonDays)
                {
                    ITourWrapper tInJoint = pDay.Tours.Find(t => t.FullHalfTour2Sequence == tour.FullHalfTour2Sequence);
                    if (!(tInJoint == null))
                    {
                        // set jointTour time window
                        //timeWindow.IncorporateAnotherTimeWindow(tInJoint.PersonDay.TimeWindow);
                        totHHToursJT = personDay.HomeBasedTours + totHHToursJT;

                        if (pDay.Person.Age < 18)
                        {
                            numChildrenOnJointTour++;
                        }

                        if (pDay.Person.Age >= 18)
                        {
                            numAdultsOnJointTour++;
                        }
                    }
                }
            }
            else if (tour.ParentTour == null)
            {
                //timeWindow.IncorporateAnotherTimeWindow(personDay.TimeWindow);
            }
            else
            {
                //timeWindow.IncorporateAnotherTimeWindow(tour.ParentTour.TimeWindow);
            }

            //timeWindow.SetBusyMinutes(Global.Settings.Times.EndOfRelevantWindow, Global.Settings.Times.MinutesInADay + 1);

            // time window in minutes for yet unmodeled portion of halftour, only consider persons on this trip
            //var availableWindow = timeWindow.AvailableWindow(destinationDepartureTime, Global.Settings.TimeDirections.Both);

            //var duration = availableWindow/ 60D;


            // 0 - NO MORE STOPS

            ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.NoneOrHome, true, choice == Global.Settings.Purposes.NoneOrHome);

            alternative.Choice = Global.Settings.Purposes.NoneOrHome;

            alternative.AddUtilityTerm(1, twoSimulatedTripsFlag * halfTourFromOriginFlag * isIndividual);
            alternative.AddUtilityTerm(2, threeSimulatedTripsFlag * halfTourFromOriginFlag * isIndividual);
            alternative.AddUtilityTerm(3, fourSimulatedTripsFlag * halfTourFromOriginFlag * isIndividual);
            alternative.AddUtilityTerm(4, fivePlusSimulatedTripsFlag * halfTourFromOriginFlag * isIndividual);
            alternative.AddUtilityTerm(5, twoSimulatedTripsFlag * halfTourFromDestinationFlag * isIndividual);
            alternative.AddUtilityTerm(6, threeSimulatedTripsFlag * halfTourFromDestinationFlag * isIndividual);
            alternative.AddUtilityTerm(7, fourSimulatedTripsFlag * halfTourFromDestinationFlag * isIndividual);
            alternative.AddUtilityTerm(8, fivePlusSimulatedTripsFlag * halfTourFromDestinationFlag * isIndividual);
            alternative.AddUtilityTerm(9, homeBasedTours * isIndividual);
            alternative.AddUtilityTerm(10, homeBasedTours * isJointTour);
            alternative.AddUtilityTerm(11, notHomeBasedTourFlag);
            //alternative.AddUtilityTerm(12, beforeMandatoryDestinationFlag*isJointTour);
            alternative.AddUtilityTerm(13, beforeMandatoryDestinationFlag);
            alternative.AddUtilityTerm(14, numAdultsOnJointTour);
            alternative.AddUtilityTerm(15, numChildrenOnJointTour);
            alternative.AddUtilityTerm(16, totHHToursJT);
            //alternative.AddUtilityTerm(17, totHHStopsJT);
            alternative.AddUtilityTerm(22, (threeSimulatedTripsFlag + fourSimulatedTripsFlag + fivePlusSimulatedTripsFlag) * halfTourFromOriginFlag * isJoint);
            alternative.AddUtilityTerm(26, threeSimulatedTripsFlag * halfTourFromDestinationFlag * isJoint);
            alternative.AddUtilityTerm(27, fourSimulatedTripsFlag * halfTourFromDestinationFlag * isJoint);
            alternative.AddUtilityTerm(28, fivePlusSimulatedTripsFlag * halfTourFromDestinationFlag * isJoint);
            alternative.AddUtilityTerm(29, totalAggregateLogsum);

            // 1 - WORK STOP

            if ((personDay.WorkStops > 0 && tour.DestinationPurpose <= Global.Settings.Purposes.School) || isJoint > 0)
            {
                alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Work, true, choice == Global.Settings.Purposes.Work);

                alternative.Choice = Global.Settings.Purposes.Work;

                //alternative.AddUtilityTerm(32, isIndividualTour);
                alternative.AddUtilityTerm(33, workTourFlag);
                alternative.AddUtilityTerm(34, schoolTourFlag);
                alternative.AddUtilityTerm(35, halfTourFromOriginFlag);
                alternative.AddUtilityTerm(36, Math.Log(1 + simulatedWorkStops));
                alternative.AddUtilityTerm(37, simulatedWorkStopsFlag);
                alternative.AddUtilityTerm(38, (5 - simulatedWorkStops));
                alternative.AddUtilityTerm(39, duration);
                alternative.AddUtilityTerm(40, from9AMto11AMFlag + from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag);
                //alternative.AddUtilityTerm(42, logDist);
                //alternative.AddUtilityTerm(43, transitTourFlag);
                //alternative.AddUtilityTerm(44, (person.IsPartTimeWorker).ToFlag());
                alternative.AddUtilityTerm(46, totalAggregateLogsum);
                //alternative.AddUtilityTerm(47,totEmpBuffer2);
                alternative.AddUtilityTerm(48, hov2TourFlag + hov3TourFlag);
            }
            else
            {
                choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Work, false, choice == Global.Settings.Purposes.Work);
            }

            // 2 - SCHOOL STOP

            if ((personDay.SchoolStops > 0 && tour.DestinationPurpose <= Global.Settings.Purposes.School) || isJoint > 0)
            {
                alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.School, true, choice == Global.Settings.Purposes.School);

                alternative.Choice = Global.Settings.Purposes.School;

                alternative.AddUtilityTerm(51, workTourFlag);
                alternative.AddUtilityTerm(52, schoolTourFlag);
                //alternative.AddUtilityTerm(53, halfTourFromOriginFlag);
                alternative.AddUtilityTerm(54, Math.Log(1 + simulatedSchoolStops));
                alternative.AddUtilityTerm(55, (3 - simulatedSchoolStops));
                //alternative.AddUtilityTerm(55, remainingToursCount);
                alternative.AddUtilityTerm(56, duration);
                alternative.AddUtilityTerm(57, from7AMto9AMFlag + from7PMto9PMFlag + from9PMto11PMFlag + from11PMto7AMFlag);
                alternative.AddUtilityTerm(58, oneSimulatedTripFlag);
                //alternative.AddUtilityTerm(59, logDist);
                alternative.AddUtilityTerm(61, fullJointHalfTour * numChildrenOnJointTour);
                alternative.AddUtilityTerm(65, (person.Age < 12).ToFlag());
                alternative.AddUtilityTerm(66, totalAggregateLogsum);
                //alternative.AddUtilityTerm(66,  (person.IsUniversityStudent).ToFlag());
            }
            else
            {
                choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.School, false, choice == Global.Settings.Purposes.School);
            }

            // 3 - ESCORT STOP

            if ((personDay.EscortStops > 0 && tour.DestinationPurpose <= Global.Settings.Purposes.Escort) || isJoint > 0)
            {
                alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Escort, true, choice == Global.Settings.Purposes.Escort);

                alternative.Choice = Global.Settings.Purposes.Escort;

                alternative.AddUtilityTerm(71, workTourFlag + schoolTourFlag);
                alternative.AddUtilityTerm(72, isJointTour);
                alternative.AddUtilityTerm(74, escortTourFlag);
                //alternative.AddUtilityTerm(75, socialOrRecreationTourFlag);
                //alternative.AddUtilityTerm(76, remainingToursCount);
                alternative.AddUtilityTerm(77, duration);
                alternative.AddUtilityTerm(78, from7AMto9AMFlag);
                //alternative.AddUtilityTerm(79, from9AMto11AMFlag + from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag);
                alternative.AddUtilityTerm(81, hov2TourFlag);
                alternative.AddUtilityTerm(82, hov3TourFlag);
                alternative.AddUtilityTerm(83, Math.Log(1 + simulatedEscortStops * isJointTour));
                alternative.AddUtilityTerm(84, Math.Log(1 + simulatedEscortStops * isIndividual));
                //alternative.AddUtilityTerm(85, (3 - simulatedEscortStops));

                alternative.AddUtilityTerm(85, totalAggregateLogsum);
                alternative.AddUtilityTerm(86, fullJointHalfTour);
                //alternative.AddUtilityTerm(88, enrollmentK8Buffer2);
                alternative.AddUtilityTerm(89, numChildrenOnJointTour);
                alternative.AddUtilityTerm(90, halfTourFromOriginFlag);
            }
            else
            {
                choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Escort, false, choice == Global.Settings.Purposes.Escort);
            }

            // 4 - PERSONAL BUSINESS STOP

            if (personDay.PersonalBusinessStops > 0 || isJoint > 0)
            {
                alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.PersonalBusiness, true, choice == Global.Settings.Purposes.PersonalBusiness);

                alternative.Choice = Global.Settings.Purposes.PersonalBusiness;

                alternative.AddUtilityTerm(91, (workTourFlag + schoolTourFlag));
                alternative.AddUtilityTerm(92, isJointTour);
                alternative.AddUtilityTerm(93, escortTourFlag);
                alternative.AddUtilityTerm(94, personalBusinessOrMedicalTourFlag * isIndividual);
                alternative.AddUtilityTerm(95, shoppingTourFlag);
                alternative.AddUtilityTerm(96, mealTourFlag);
                alternative.AddUtilityTerm(97, socialOrRecreationTourFlag);
                alternative.AddUtilityTerm(98, halfTourFromOriginFlag);
                alternative.AddUtilityTerm(99, Math.Log(1 + simulatedPersonalBusinessStops * isIndividual));
                alternative.AddUtilityTerm(100, Math.Log(1 + simulatedPersonalBusinessStops * isJointTour));
                alternative.AddUtilityTerm(104, (3 - simulatedPersonalBusinessStops));
                alternative.AddUtilityTerm(101, duration);
                alternative.AddUtilityTerm(102, (from7AMto9AMFlag + from7PMto9PMFlag + from9PMto11PMFlag + from11PMto7AMFlag));
                alternative.AddUtilityTerm(103, from9AMto11AMFlag + from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag);
                alternative.AddUtilityTerm(105, hov2TourFlag);
                alternative.AddUtilityTerm(106, hov3TourFlag);
                alternative.AddUtilityTerm(109, fullJointHalfTour);
                alternative.AddUtilityTerm(110, totEmpBuffer2);
                alternative.AddUtilityTerm(111, totalAggregateLogsum);
                alternative.AddUtilityTerm(112, personalBusinessOrMedicalTourFlag * isJointTour);
            }
            else
            {
                choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.PersonalBusiness, false, choice == Global.Settings.Purposes.PersonalBusiness);
            }

            // 5 - SHOPPING STOP

            if (personDay.ShoppingStops > 0 || isJoint > 0)
            {
                alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Shopping, true, choice == Global.Settings.Purposes.Shopping);

                alternative.Choice = Global.Settings.Purposes.Shopping;

                alternative.AddUtilityTerm(121, workTourFlag + schoolTourFlag);
                alternative.AddUtilityTerm(122, isJointTour);
                alternative.AddUtilityTerm(123, escortTourFlag);
                alternative.AddUtilityTerm(124, personalBusinessOrMedicalTourFlag);
                alternative.AddUtilityTerm(125, shoppingTourFlag * isIndividual);
                alternative.AddUtilityTerm(126, mealTourFlag);
                alternative.AddUtilityTerm(127, socialOrRecreationTourFlag);
                alternative.AddUtilityTerm(128, halfTourFromOriginFlag);
                alternative.AddUtilityTerm(129, Math.Log(1 + simulatedShoppingStops * isIndividual));
                alternative.AddUtilityTerm(130, Math.Log(1 + simulatedShoppingStops * isJointTour));
                alternative.AddUtilityTerm(131, duration);
                alternative.AddUtilityTerm(132, from7AMto9AMFlag + from9PMto11PMFlag + from11PMto7AMFlag);
                alternative.AddUtilityTerm(133, (from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag));
                //alternative.AddUtilityTerm(134, adultFemaleOnJointTour);
                alternative.AddUtilityTerm(135, hov2TourFlag);
                alternative.AddUtilityTerm(136, hov3TourFlag);
                alternative.AddUtilityTerm(137, Math.Log(1 + adis));
                alternative.AddUtilityTerm(138, shoppingTourFlag * isJointTour);
                alternative.AddUtilityTerm(140, totalAggregateLogsum);
                //alternative.AddUtilityTerm(141, retailBuffer2);
                //alternative.AddUtilityTerm(142, numChildrenOnJointTour);
                //alternative.AddUtilityTerm(143, (household.Has100KPlusIncome).ToFlag());
            }
            else
            {
                choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Shopping, false, choice == Global.Settings.Purposes.Shopping);
            }

            // 6 - MEAL STOP

            if (personDay.MealStops > 0 || isJoint > 0)
            {
                alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Meal, true, choice == Global.Settings.Purposes.Meal);

                alternative.Choice = Global.Settings.Purposes.Meal;

                alternative.AddUtilityTerm(151, workTourFlag);
                //alternative.AddUtilityTerm(152, isJointTour);
                alternative.AddUtilityTerm(153, schoolTourFlag);
                alternative.AddUtilityTerm(154, escortTourFlag);
                alternative.AddUtilityTerm(155, personalBusinessOrMedicalTourFlag);
                alternative.AddUtilityTerm(156, shoppingTourFlag);
                alternative.AddUtilityTerm(157, mealTourFlag);
                alternative.AddUtilityTerm(158, socialOrRecreationTourFlag);
                alternative.AddUtilityTerm(159, halfTourFromOriginFlag);
                alternative.AddUtilityTerm(160, Math.Log(1 + simulatedMealStops * isIndividual));
                alternative.AddUtilityTerm(161, Math.Log(1 + simulatedMealStops * isJointTour));
                alternative.AddUtilityTerm(162, duration);
                alternative.AddUtilityTerm(164, from11AMto1PMFlag + from1PMto3PMFlag);
                alternative.AddUtilityTerm(166, onePersonHouseholdFlag);
                alternative.AddUtilityTerm(167, hov2TourFlag);
                alternative.AddUtilityTerm(168, hov3TourFlag);
                alternative.AddUtilityTerm(170, numChildrenOnJointTour);
                alternative.AddUtilityTerm(171, oneSimulatedTripFlag);
                alternative.AddUtilityTerm(172, Math.Log(1 + adis));
                alternative.AddUtilityTerm(174, fullJointHalfTour);
                alternative.AddUtilityTerm(175, foodBuffer2);
                //alternative.AddUtilityTerm(176, homeFoodBuffer2);
                //alternative.AddUtilityTerm(177, (household.Has100KPlusIncome).ToFlag());
                alternative.AddUtilityTerm(178, numAdultsOnJointTour);
                alternative.AddUtilityTerm(179, totalAggregateLogsum);
            }
            else
            {
                choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Meal, false, choice == Global.Settings.Purposes.Meal);
            }

            // 7 - SOCIAL STOP

            if (personDay.SocialStops > 0 || isJoint > 0)
            {
                alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Social, true, choice == Global.Settings.Purposes.Social);

                alternative.Choice = Global.Settings.Purposes.Social;

                alternative.AddUtilityTerm(181, workTourFlag + schoolTourFlag);
                alternative.AddUtilityTerm(182, isJointTour);
                alternative.AddUtilityTerm(183, escortTourFlag);
                alternative.AddUtilityTerm(184, personalBusinessOrMedicalTourFlag);
                alternative.AddUtilityTerm(185, shoppingTourFlag);
                alternative.AddUtilityTerm(186, mealTourFlag);
                alternative.AddUtilityTerm(187, socialOrRecreationTourFlag);
                alternative.AddUtilityTerm(188, halfTourFromOriginFlag);
                alternative.AddUtilityTerm(189, Math.Log(1 + simulatedSocialStops * isIndividual));
                alternative.AddUtilityTerm(197, Math.Log(1 + simulatedSocialStops * isJointTour));
                alternative.AddUtilityTerm(190, remainingToursCount);
                alternative.AddUtilityTerm(191, duration);
                alternative.AddUtilityTerm(192, from7AMto9AMFlag + from11PMto7AMFlag);
                alternative.AddUtilityTerm(194, hov2TourFlag);
                alternative.AddUtilityTerm(195, hov3TourFlag);
                alternative.AddUtilityTerm(196, logDist);
                alternative.AddUtilityTerm(198, totalAggregateLogsum);
                alternative.AddUtilityTerm(200, numAdultsOnJointTour);
            }
            else
            {
                choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Social, false, choice == Global.Settings.Purposes.Social);
            }


            // 8 - RECREATION STOP

            if (personDay.RecreationStops > 0 || isJoint > 0)
            {
                alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Recreation, true, choice == Global.Settings.Purposes.Recreation);

                alternative.Choice = Global.Settings.Purposes.Recreation;

                alternative.AddUtilityTerm(211, workTourFlag + schoolTourFlag);
                alternative.AddUtilityTerm(212, isJointTour);
                alternative.AddUtilityTerm(213, escortTourFlag);
                alternative.AddUtilityTerm(214, personalBusinessOrMedicalTourFlag);
                alternative.AddUtilityTerm(215, shoppingTourFlag);
                alternative.AddUtilityTerm(216, mealTourFlag);
                alternative.AddUtilityTerm(217, socialOrRecreationTourFlag);
                alternative.AddUtilityTerm(218, halfTourFromOriginFlag);
                alternative.AddUtilityTerm(219, Math.Log(1 + simulatedRecreationStops * isIndividual));
                alternative.AddUtilityTerm(229, Math.Log(1 + simulatedRecreationStops * isJointTour));
                alternative.AddUtilityTerm(220, remainingToursCount);
                alternative.AddUtilityTerm(221, duration);
                alternative.AddUtilityTerm(222, from7AMto9AMFlag + from11PMto7AMFlag);
                alternative.AddUtilityTerm(223, from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag);
                alternative.AddUtilityTerm(225, hov3TourFlag);
                alternative.AddUtilityTerm(226, numChildrenOnJointTour);
                alternative.AddUtilityTerm(227, numAdultsOnJointTour);
                //alternative.AddUtilityTerm(228, fullJointHalfTour);
                //alternative.AddUtilityTerm(229, openSpaceBuffer2);
                alternative.AddUtilityTerm(228, totalAggregateLogsum);
            }
            else
            {
                choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Recreation, false, choice == Global.Settings.Purposes.Recreation);
            }

            // 9 - MEDICAL STOP

            if (personDay.MedicalStops > 0 || isJoint > 0)
            {
                alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Medical, true, choice == Global.Settings.Purposes.Medical);

                alternative.Choice = Global.Settings.Purposes.Medical;

                alternative.AddUtilityTerm(231, workTourFlag + schoolTourFlag + escortTourFlag);
                alternative.AddUtilityTerm(232, isJointTour);
                alternative.AddUtilityTerm(233, personalBusinessOrMedicalTourFlag * isIndividual);
                alternative.AddUtilityTerm(234, personalBusinessOrMedicalTourFlag * isJointTour);
                alternative.AddUtilityTerm(235, shoppingTourFlag);
                alternative.AddUtilityTerm(236, mealTourFlag);
                alternative.AddUtilityTerm(237, socialOrRecreationTourFlag);
                alternative.AddUtilityTerm(238, halfTourFromOriginFlag);
                alternative.AddUtilityTerm(239, Math.Log(1 + simulatedMedicalStops * isJointTour));
                alternative.AddUtilityTerm(240, Math.Log(1 + simulatedMedicalStops * isIndividual));
                //alternative.AddUtilityTerm(240, fullJointHalfTour);
                alternative.AddUtilityTerm(241, duration);
                alternative.AddUtilityTerm(242, from7AMto9AMFlag + from11PMto7AMFlag);
                alternative.AddUtilityTerm(243, from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag);
                //alternative.AddUtilityTerm(248, numChildrenOnJointTour);
                //alternative.AddUtilityTerm(249, adultFemaleOnJointTour);
                alternative.AddUtilityTerm(244, totalAggregateLogsum);
            }
            else
            {
                choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Medical, false, choice == Global.Settings.Purposes.Medical);
            }
        }