private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, TourWrapper tour, int nCallsForTour, HouseholdDayWrapper householdDay, int choice = Constants.DEFAULT_VALUE)
        {
            IEnumerable <PersonDayWrapper> orderedPersonDays = householdDay.PersonDays.OrderBy(p => p.GetJointTourParticipationPriority()).ToList().Cast <PersonDayWrapper>();

            Framework.DomainModels.Wrappers.IPersonWrapper    person    = tour.Person;
            Framework.DomainModels.Wrappers.IPersonDayWrapper personDay = tour.PersonDay;

            int adultFemaleFlag    = person.IsAdultFemale.ToFlag();
            int partTimeWorkerFlag = person.IsPartTimeWorker.ToFlag();

            double foodBuffer2      = tour.DestinationParcel.EmploymentFoodBuffer2;
            double medBuffer2       = tour.DestinationParcel.EmploymentMedicalBuffer2;
            double intDensBuffer2   = tour.DestinationParcel.IntersectionDensity34Buffer2();
            double serviceBuffer2   = tour.DestinationParcel.EmploymentServiceBuffer2;
            double totEmpBuffer2    = tour.DestinationParcel.EmploymentTotalBuffer2;
            double totHHBuffer2     = tour.DestinationParcel.HouseholdsBuffer2;
            double openSpaceBuffer2 = tour.DestinationParcel.OpenSpaceType1Buffer2;
            double mixedUse         = tour.DestinationParcel.MixedUse2Index2();
            //var retailBuffer2 = tour.DestinationParcel.EmploymentRetailBuffer2;
            //var retailBuffer1 = tour.DestinationParcel.EmploymentRetailBuffer1;

            int carOwnership = person.GetCarOwnershipSegment();
            int noCarsFlag   = FlagUtility.GetNoCarsFlag(carOwnership);
            //var carCompetitionFlag = AggregateLogsumsCalculator.GetCarCompetitionFlag(carOwnership);

            int votALSegment = tour.GetVotALSegment();

            int    workTaSegment       = tour.DestinationParcel.TransitAccessSegment();
            double workAggregateLogsum = Global.AggregateLogsums[tour.DestinationParcel.ZoneId]
                                         [Global.Settings.Purposes.WorkBased][carOwnership][votALSegment][workTaSegment];
            double shopAggregateLogsum = Global.AggregateLogsums[tour.DestinationParcel.ZoneId]
                                         [Global.Settings.Purposes.Shopping][carOwnership][votALSegment][workTaSegment];
            //var mealAggregateLogsum = Global.AggregateLogsums[tour.DestinationParcel.ZoneId]
            //[Global.Settings.Purposes.Meal][carOwnership][votALSegment][workTaSegment];
            //var persBusAggregateLogsum = Global.AggregateLogsums[tour.DestinationParcel.ZoneId]
            //[Global.Settings.Purposes.PersonalBusiness][carOwnership][votALSegment][workTaSegment];
            //var socialAggregateLogsum = Global.AggregateLogsums[tour.DestinationParcel.ZoneId]
            //[Global.Settings.Purposes.Social][carOwnership][votALSegment][workTaSegment];

            int numStopPurposes = (personDay.SimulatedEscortStops > 1).ToFlag() + (personDay.SimulatedShoppingStops > 1).ToFlag() + (personDay.SimulatedMealStops > 1).ToFlag() +
                                  (personDay.SimulatedPersonalBusinessStops > 1).ToFlag() + (personDay.SimulatedSocialStops > 1).ToFlag() +
                                  (personDay.SimulatedRecreationStops > 1).ToFlag() + (personDay.SimulatedMedicalStops > 1).ToFlag();

            int    workDestinationArrivalTime   = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.WorkTourModeModel);
            int    workDestinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.WorkTourModeModel);
            double workLogsum = 0;

            ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().RunNested(personDay, person.Household.ResidenceParcel, person.UsualWorkParcel, workDestinationArrivalTime, workDestinationDepartureTime, person.Household.VehiclesAvailable);
            workLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();

            //double logTimeAtWork = Math.Log(1 + (workDestinationDepartureTime - workDestinationArrivalTime) / 60);

            //int countMandatoryKids = (from personDayHH in orderedPersonDays where personDayHH.PatternType == 1 && personDayHH.Person.Age < 12 select personDayHH.PatternType).Count();
            //int countNonMandatory = (from personDayHH in orderedPersonDays where personDayHH.PatternType == 2 select personDayHH.PatternType).Count();
            //int countAtHome = (from personDayHH in orderedPersonDays where personDayHH.PatternType == 3 select personDayHH.PatternType).Count();
            int countNonMandatoryKids = (from personDayHH in orderedPersonDays where personDayHH.PatternType == 2 && personDayHH.Person.Age < 12 select personDayHH.PatternType).Count();

            // 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(3, personDay.TwoOrMoreWorkToursExist().ToFlag());
            alternative.AddUtilityTerm(4, noCarsFlag);
            //alternative.AddUtilityTerm(5, carCompetitionFlag);
            alternative.AddUtilityTerm(6, partTimeWorkerFlag);
            //alternative.AddUtilityTerm(8, (person.UsualModeToWork != Global.Settings.Modes.Sov).ToFlag());
            alternative.AddUtilityTerm(10, person.TransitPassOwnership);
            //alternative.AddUtilityTerm(15, logTimeAtWork);
            alternative.AddUtilityTerm(17, numStopPurposes);
            alternative.AddUtilityTerm(18, Math.Log(personDay.GetTotalCreatedTours() + 1));

            // WORK

            alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Work, personDay.WorkStops > 0, choice == Global.Settings.Purposes.Work);

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

            alternative.AddUtilityTerm(21, 1);
            alternative.AddUtilityTerm(22, Math.Log(1 + totEmpBuffer2));
            //alternative.AddUtilityTerm(23, (person.Household.Income<30000).ToFlag());
            alternative.AddUtilityTerm(24, (person.Household.Has100KPlusIncome).ToFlag());
            alternative.AddUtilityTerm(25, workLogsum);

            // SCHOOL
            //no observations in the PSRC dataset
            alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.School, false, choice == Global.Settings.Purposes.School);

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

            //alternative.AddUtilityTerm(3, 1);

            // ESCORT

            alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Escort, personDay.EscortStops > 0, choice == Global.Settings.Purposes.Escort);

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

            alternative.AddUtilityTerm(31, 1);
            //alternative.AddUtilityTerm(33, k8HighSchoolQtrMileLog);
            alternative.AddUtilityTerm(36, countNonMandatoryKids);
            alternative.AddUtilityTerm(37, adultFemaleFlag);
            //alternative.AddUtilityTerm(38, person.Household.Size);
            //alternative.AddUtilityTerm(39, householdDay.Household.HouseholdTotals.ChildrenAge5Through15);
            //alternative.AddUtilityTerm(40, partTimeWorkerFlag);
            alternative.AddUtilityTerm(39, workLogsum);

            // PERSONAL_BUSINESS

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

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

            alternative.AddUtilityTerm(41, 1);
            //alternative.AddUtilityTerm(43, persBusAggregateLogsum);
            alternative.AddUtilityTerm(45, Math.Log(1 + totEmpBuffer2));
            //alternative.AddUtilityTerm(48, (person.Household.Income>90000).ToFlag());
            alternative.AddUtilityTerm(49, (person.Household.HouseholdTotals.ChildrenUnder16));


            // SHOPPING

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

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

            alternative.AddUtilityTerm(51, 1);
            //alternative.AddUtilityTerm(53, retailBuffer1);
            //alternative.AddUtilityTerm(54, partTimeWorkerFlag);
            alternative.AddUtilityTerm(55, (person.Household.Has100KPlusIncome).ToFlag());
            alternative.AddUtilityTerm(57, person.Household.HouseholdTotals.ChildrenUnder16);
            alternative.AddUtilityTerm(58, shopAggregateLogsum);
            //alternative.AddUtilityTerm(59, person.Household.Size);
            //alternative.AddUtilityTerm(59, (person.Household.Income<30000).ToFlag());


            // MEAL

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

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

            alternative.AddUtilityTerm(71, 1);
            alternative.AddUtilityTerm(73, Math.Log(1 + foodBuffer2));
            alternative.AddUtilityTerm(74, mixedUse);
            alternative.AddUtilityTerm(75, intDensBuffer2);
            //alternative.AddUtilityTerm(76, (person.Household.Income<30000).ToFlag());
            //alternative.AddUtilityTerm(77, person.Household.HouseholdTotals.ChildrenUnder16);

            // SOCIAL

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

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

            alternative.AddUtilityTerm(91, 1);
            alternative.AddUtilityTerm(93, person.Household.HouseholdTotals.ChildrenUnder16);
            alternative.AddUtilityTerm(94, (person.Age < 35).ToFlag());
            //alternative.AddUtilityTerm(115, workAggregateLogsum);
            alternative.AddUtilityTerm(96, Math.Log(1 + totHHBuffer2 + totEmpBuffer2));
            alternative.AddUtilityTerm(97, (person.Household.Income < 30000).ToFlag());
            //alternative.AddUtilityTerm(118, person.Household.Has100KPlusIncome.ToFlag());

            // RECREATION

            alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Recreation, personDay.RecreationStops > 0, choice == Global.Settings.Purposes.Recreation);

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

            alternative.AddUtilityTerm(111, 1);
            alternative.AddUtilityTerm(113, person.Household.HouseholdTotals.ChildrenUnder16);
            alternative.AddUtilityTerm(114, (person.Age < 35).ToFlag());
            alternative.AddUtilityTerm(116, Math.Log(1 + totHHBuffer2 + totEmpBuffer2));
            alternative.AddUtilityTerm(117, (person.Household.Income < 30000).ToFlag());
            alternative.AddUtilityTerm(118, (person.Household.Income > 100000).ToFlag());
            alternative.AddUtilityTerm(119, Math.Log(1 + openSpaceBuffer2));

            // MEDICAL

            alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Medical, personDay.MedicalStops > 0, choice == Global.Settings.Purposes.Medical);

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

            alternative.AddUtilityTerm(121, 1);
            alternative.AddUtilityTerm(123, adultFemaleFlag);
            alternative.AddUtilityTerm(124, (person.Age > 65).ToFlag());
            alternative.AddUtilityTerm(125, Math.Log(1 + medBuffer2));
            //alternative.AddUtilityTerm(126, workAggregateLogsum);

            //alternative.AddNestedAlternative(12, 1, 60);
        }
예제 #2
0
        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));
        }
예제 #3
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, HouseholdDayWrapper householdDay, int nCallsForTour, int choice = Constants.DEFAULT_VALUE)
        {
            IEnumerable <PersonDayWrapper> orderedPersonDays = householdDay.PersonDays.OrderBy(p => p.GetJointTourParticipationPriority()).ToList().Cast <PersonDayWrapper>();

            Framework.DomainModels.Wrappers.IHouseholdWrapper household       = householdDay.Household;
            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 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];
            double 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];

            int countNonMandatory  = 0;
            int countMandatory     = 0;
            int countWorkingAtHome = 0;
            int countAge5to8       = 0;
            int countAge9to12      = 0;
            int countAge13to15     = 0;
            int countAdultFemale   = 0;
            int countAdultMale     = 0;

            int youngestAge = 150;
            int oldestAge   = 0;

            int mandatoryHTours = 0;
            int mandatoryHStops = 0;

            int[] mandPerstype    = new int[8];
            int[] nonMandPerstype = new int[8];
            int[] atHomePersType  = new int[8];

            List <KeyValuePair <int, double> > hhSchools = new List <KeyValuePair <int, double> >();
            List <KeyValuePair <int, double> > hhJobs    = new List <KeyValuePair <int, double> >();


            int count = 0;

            foreach (PersonDayWrapper personDay in orderedPersonDays)
            {
                Framework.DomainModels.Wrappers.IPersonWrapper person = personDay.Person;
                count++;
                if (count > 8)
                {
                    break;
                }
                if (personDay.Person.Age >= 5 && personDay.Person.Age <= 8)
                {
                    countAge5to8++;
                }

                if (personDay.Person.Age >= 9 && personDay.Person.Age <= 12)
                {
                    countAge9to12++;
                }

                if (personDay.Person.Age >= 13 && personDay.Person.Age <= 15)
                {
                    countAge13to15++;
                }

                if (personDay.Person.IsAdultFemale)
                {
                    countAdultFemale++;
                }
                else if (personDay.Person.IsAdultMale)
                {
                    countAdultMale++;
                }

                if (personDay.Person.Age < youngestAge)
                {
                    youngestAge = personDay.Person.Age;
                }

                if (personDay.Person.Age > oldestAge)
                {
                    oldestAge = personDay.Person.Age;
                }

                mandatoryHTours = mandatoryHTours + personDay.WorkTours + personDay.SchoolTours;
                mandatoryHStops = mandatoryHStops + (personDay.WorkStops > 0).ToFlag() + (personDay.SchoolTours > 0).ToFlag();

                if (personDay.WorksAtHomeFlag == 1)
                {
                    countWorkingAtHome++;
                }
                if (personDay.PatternType == 1)
                {
                    countMandatory++;
                    mandPerstype[personDay.Person.PersonType - 1]++;
                }
                if (personDay.PatternType == 2)
                {
                    countNonMandatory++;
                    nonMandPerstype[personDay.Person.PersonType - 1]++;
                }
                if (personDay.PatternType == 3)
                {
                    atHomePersType[personDay.Person.PersonType - 1]++;
                }
            }


            youngestAge = youngestAge == 150 ? 0 : youngestAge;

            // 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, (nCallsForTour == 2).ToFlag());
            alternative.AddUtilityTerm(3, (nCallsForTour >= 3).ToFlag());
            alternative.AddUtilityTerm(12, atHomePersType[4]);
            // alternative.AddUtilityTerm(15, Math.Log(1+aveWorkTime));
            //  alternative.AddUtilityTerm(16, Math.Log(1+aveSchoolTime));

            // WORK
            alternative        = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Work, false, choice == Global.Settings.Purposes.Work);
            alternative.Choice = Global.Settings.Purposes.Work;
            alternative.AddUtilityTerm(202, 1);


            //  SCHOOL
            alternative        = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.School, false, choice == Global.Settings.Purposes.School);
            alternative.Choice = Global.Settings.Purposes.School;
            alternative.AddUtilityTerm(203, 1);


            // ESCORT
            alternative        = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Escort, true, choice == Global.Settings.Purposes.Escort);
            alternative.Choice = Global.Settings.Purposes.Escort;

            alternative.AddUtilityTerm(151, 1);
            alternative.AddUtilityTerm(152, nonMandPerstype[0]);
            alternative.AddUtilityTerm(153, nonMandPerstype[1]);
            alternative.AddUtilityTerm(154, nonMandPerstype[2]);
            alternative.AddUtilityTerm(155, nonMandPerstype[3]);
            alternative.AddUtilityTerm(156, nonMandPerstype[4]);
            alternative.AddUtilityTerm(157, nonMandPerstype[5]);
            alternative.AddUtilityTerm(158, nonMandPerstype[6]);
            alternative.AddUtilityTerm(159, nonMandPerstype[7]);
            alternative.AddUtilityTerm(160, countMandatory);
            alternative.AddUtilityTerm(162, countWorkingAtHome);
            alternative.AddUtilityTerm(165, countAdultFemale);
            alternative.AddUtilityTerm(166, countAdultMale);
            alternative.AddUtilityTerm(167, countAge5to8);
            alternative.AddUtilityTerm(168, countAge9to12);
            alternative.AddUtilityTerm(169, countAge13to15);
            alternative.AddUtilityTerm(170, Math.Log(1 + youngestAge));
            alternative.AddUtilityTerm(173, Math.Log(1 + household.ResidenceParcel.HouseholdsBuffer2));


            // PERSONAL_BUSINESS
            alternative        = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.PersonalBusiness, true, choice == Global.Settings.Purposes.PersonalBusiness);
            alternative.Choice = Global.Settings.Purposes.PersonalBusiness;

            alternative.AddUtilityTerm(21, 1);
            alternative.AddUtilityTerm(22, nonMandPerstype[0]);
            alternative.AddUtilityTerm(23, nonMandPerstype[1]);
            alternative.AddUtilityTerm(24, nonMandPerstype[2]);
            alternative.AddUtilityTerm(25, nonMandPerstype[3]);
            alternative.AddUtilityTerm(26, nonMandPerstype[4]);
            alternative.AddUtilityTerm(27, nonMandPerstype[5]);
            alternative.AddUtilityTerm(28, nonMandPerstype[6]);
            alternative.AddUtilityTerm(29, nonMandPerstype[7]);
            alternative.AddUtilityTerm(30, countMandatory);
            alternative.AddUtilityTerm(37, Math.Log(1 + oldestAge));


            // SHOPPING
            alternative        = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Shopping, true, choice == Global.Settings.Purposes.Shopping);
            alternative.Choice = Global.Settings.Purposes.Shopping;

            alternative.AddUtilityTerm(41, 1);
            alternative.AddUtilityTerm(42, nonMandPerstype[0]);
            alternative.AddUtilityTerm(43, nonMandPerstype[1]);
            alternative.AddUtilityTerm(44, nonMandPerstype[2]);
            alternative.AddUtilityTerm(45, nonMandPerstype[3]);
            alternative.AddUtilityTerm(46, nonMandPerstype[4]);
            alternative.AddUtilityTerm(47, nonMandPerstype[5]);
            alternative.AddUtilityTerm(48, nonMandPerstype[6]);
            alternative.AddUtilityTerm(49, nonMandPerstype[7]);
            alternative.AddUtilityTerm(50, countMandatory);
            alternative.AddUtilityTerm(51, shoppingAggregateLogsum);
            alternative.AddUtilityTerm(52, householdDay.Household.Has0To25KIncome.ToFlag());
            alternative.AddUtilityTerm(58, Math.Log(1 + youngestAge));
            alternative.AddUtilityTerm(59, Math.Log(1 + oldestAge));


            // MEAL
            alternative        = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Meal, true, choice == Global.Settings.Purposes.Meal);
            alternative.Choice = Global.Settings.Purposes.Meal;

            alternative.AddUtilityTerm(61, 1);

            alternative.AddUtilityTerm(62, nonMandPerstype[0]);
            alternative.AddUtilityTerm(63, nonMandPerstype[1]);
            alternative.AddUtilityTerm(64, nonMandPerstype[2]);
            alternative.AddUtilityTerm(65, nonMandPerstype[3]);
            alternative.AddUtilityTerm(66, nonMandPerstype[4]);
            alternative.AddUtilityTerm(67, nonMandPerstype[5]);
            alternative.AddUtilityTerm(68, nonMandPerstype[6]);
            alternative.AddUtilityTerm(69, nonMandPerstype[7]);
            alternative.AddUtilityTerm(70, countMandatory);
            alternative.AddUtilityTerm(71, mealAggregateLogsum);
            alternative.AddUtilityTerm(78, Math.Log(1 + youngestAge));
            alternative.AddUtilityTerm(79, Math.Log(1 + oldestAge));
            alternative.AddUtilityTerm(80, Math.Log(1 + household.ResidenceParcel.HouseholdsBuffer2));


            // SOCIAL
            alternative        = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Social, true, choice == Global.Settings.Purposes.Social);
            alternative.Choice = Global.Settings.Purposes.Social;

            alternative.AddUtilityTerm(81, 1);
            alternative.AddUtilityTerm(82, nonMandPerstype[0]);
            alternative.AddUtilityTerm(83, nonMandPerstype[1]);
            alternative.AddUtilityTerm(84, nonMandPerstype[2]);
            alternative.AddUtilityTerm(85, nonMandPerstype[3]);
            alternative.AddUtilityTerm(86, nonMandPerstype[4]);
            alternative.AddUtilityTerm(87, nonMandPerstype[5]);
            alternative.AddUtilityTerm(88, nonMandPerstype[6]);
            alternative.AddUtilityTerm(89, nonMandPerstype[7]);
            alternative.AddUtilityTerm(90, countMandatory);
            alternative.AddUtilityTerm(91, socialAggregateLogsum);
            alternative.AddUtilityTerm(93, Math.Log(1 + householdDay.Household.ResidenceParcel.HouseholdsBuffer1));
            alternative.AddUtilityTerm(96, countAge5to8);
            alternative.AddUtilityTerm(97, countAge9to12);
            alternative.AddUtilityTerm(98, countAge13to15);
            alternative.AddUtilityTerm(100, Math.Log(1 + oldestAge));

            // RECREATION
            alternative        = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Recreation, true, choice == Global.Settings.Purposes.Recreation);
            alternative.Choice = Global.Settings.Purposes.Recreation;

            alternative.AddUtilityTerm(101, 1);

            alternative.AddUtilityTerm(102, nonMandPerstype[0]);
            alternative.AddUtilityTerm(103, nonMandPerstype[1]);
            alternative.AddUtilityTerm(104, nonMandPerstype[2]);
            alternative.AddUtilityTerm(105, nonMandPerstype[3]);
            alternative.AddUtilityTerm(106, nonMandPerstype[4]);
            alternative.AddUtilityTerm(107, nonMandPerstype[5]);
            alternative.AddUtilityTerm(108, nonMandPerstype[6]);
            alternative.AddUtilityTerm(109, nonMandPerstype[7]);
            alternative.AddUtilityTerm(110, countMandatory);
            alternative.AddUtilityTerm(111, totalAggregateLogsum);
            alternative.AddUtilityTerm(112, Math.Log(1 + householdDay.Household.ResidenceParcel.OpenSpaceType1Buffer1));
            alternative.AddUtilityTerm(113, countAdultFemale);
            alternative.AddUtilityTerm(114, countAdultMale);
            alternative.AddUtilityTerm(115, countAge5to8);
            alternative.AddUtilityTerm(116, countAge9to12);
            alternative.AddUtilityTerm(117, countAge13to15);
            alternative.AddUtilityTerm(118, Math.Log(1 + youngestAge));



            // MEDICAL
            alternative        = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Medical, true, choice == Global.Settings.Purposes.Medical);
            alternative.Choice = Global.Settings.Purposes.Medical;

            alternative.AddUtilityTerm(121, 1);

            alternative.AddUtilityTerm(122, nonMandPerstype[0]);
            alternative.AddUtilityTerm(123, nonMandPerstype[1]);
            alternative.AddUtilityTerm(124, nonMandPerstype[2]);
            alternative.AddUtilityTerm(125, nonMandPerstype[3]);
            alternative.AddUtilityTerm(126, nonMandPerstype[4]);
            alternative.AddUtilityTerm(127, nonMandPerstype[5]);
            alternative.AddUtilityTerm(128, nonMandPerstype[6]);
            alternative.AddUtilityTerm(129, nonMandPerstype[7]);
            alternative.AddUtilityTerm(130, countMandatory);
            alternative.AddUtilityTerm(131, totalAggregateLogsum);
        }
예제 #4
0
 public PersonDayWrapper(Framework.DomainModels.Models.IPersonDay personDay, Framework.DomainModels.Wrappers.IPersonWrapper personWrapper, Framework.DomainModels.Wrappers.IHouseholdDayWrapper householdDayWrapper)
     : base(personDay, personWrapper, householdDayWrapper)
 {
     _personDay = (IActumPersonDay)personDay;
 }
예제 #5
0
        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
        }
예제 #6
0
 public TourWrapper(Framework.DomainModels.Models.ITour tour, Framework.DomainModels.Wrappers.IPersonWrapper personWrapper, Framework.DomainModels.Wrappers.IPersonDayWrapper personDayWrapper, Framework.DomainModels.Wrappers.IParcelWrapper originParcel, Framework.DomainModels.Wrappers.IParcelWrapper destinationParcel, int destinationArrivalTime, int destinationDepartureTime, int destinationPurpose) : base(tour, personWrapper, personDayWrapper, originParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, destinationPurpose)
 {
     _tour = (IActumTour)tour;
 }
예제 #7
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, HouseholdDayWrapper householdDay, int nCallsForTour, bool[] available, int choice = Constants.DEFAULT_VALUE)
        {
            if (available[4])
            {
            }



            Framework.DomainModels.Wrappers.IHouseholdWrapper household = householdDay.Household;

            IEnumerable <PersonDayWrapper> orderedPersonDays = householdDay.PersonDays.OrderBy(p => p.GetJointHalfTourParticipationPriority()).ToList().Cast <PersonDayWrapper>();

            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 carsGrAdults       = household.VehiclesAvailable > household.HouseholdTotals.DrivingAgeMembers ? 1 : 0;

            int    votALSegment         = household.GetVotALSegment();
            int    transitAccessSegment = household.ResidenceParcel.TransitAccessSegment();
            double totAggregateLogsum   = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                          [Global.Settings.Purposes.HomeBasedComposite][carOwnership][votALSegment][transitAccessSegment];

            int countWorkingAtHome   = 0;
            int transitPassOwnership = 0;
            int oldestChild          = 0;
            int payParkWork          = 0;
            int numSchoolMatch       = 0;


            int count = 0;
            List <KeyValuePair <int, double> > hhSchools = new List <KeyValuePair <int, double> >();
            List <KeyValuePair <int, double> > hhJobs    = new List <KeyValuePair <int, double> >();


            foreach (PersonDayWrapper personDay in orderedPersonDays)
            {
                Framework.DomainModels.Wrappers.IPersonWrapper person = personDay.Person;
                count++;
                if (count > 8)
                {
                    break;
                }
                if (person.UsualSchoolParcelId > 0)
                {
                    hhSchools.Add(new KeyValuePair <int, double>(person.UsualSchoolParcelId, person.AutoTimeToUsualSchool));
                }

                if (person.UsualWorkParcelId > 0)
                {
                    hhJobs.Add(new KeyValuePair <int, double>(person.UsualWorkParcelId, person.AutoTimeToUsualWork));
                }

                if (personDay.WorksAtHomeFlag == 1)
                {
                    countWorkingAtHome++;
                }
                if (person.TransitPassOwnership == 1)
                {
                    transitPassOwnership++;
                }

                if (person.TransitPassOwnership == 1)
                {
                    payParkWork++;
                }
            }



            int countMandatoryAdults = (from personDayHH in orderedPersonDays
                                        where personDayHH.PatternType == 1 && personDayHH.Person.IsAdult
                                        select personDayHH.PatternType).Count();
            int countMandatoryChildren = (from personDayHH in orderedPersonDays
                                          where personDayHH.PatternType == 1 && personDayHH.Person.IsChildUnder16
                                          select personDayHH.PatternType).Count();
            int countNonMandatoryAdults = (from personDayHH in orderedPersonDays
                                           where personDayHH.PatternType == 2 && personDayHH.Person.IsAdult
                                           select personDayHH.PatternType).Count();
            int countKidsAtHome = (from personDayHH in orderedPersonDays
                                   where personDayHH.PatternType == 3 && personDayHH.Person.Age < 12
                                   select personDayHH.PatternType).Count();

            int youngestAge = (from person in household.Persons
                               select person.Age).Min();


            if (youngestAge <= 18)
            {
                oldestChild = (from person in household.Persons
                               where person.Age <= 18
                               select person.Age).Max();
            }


            if (hhSchools.Count > 1)
            {
                //number of schools - number of unique schools gives matches
                numSchoolMatch = hhSchools.Count - (from schoolm in hhSchools
                                                    select schoolm).Distinct().Count();
            }

            double lnYoungestAge = Math.Log(1 + youngestAge);
            double lnOldestChild = Math.Log(1 + oldestChild);
            int    noStudents    = household.HouseholdTotals.AllStudents == 0 ? 1 : 0;
            int    noWorkers     = household.HouseholdTotals.AllWorkers == 0 ? 1 : 0;

            // NONE_OR_HOME
            ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.NoneOrHome, available[0], choice == Global.Settings.Purposes.NoneOrHome);

            alternative.Choice = Global.Settings.Purposes.NoneOrHome;
            alternative.AddUtilityTerm(1, (nCallsForTour == 2).ToFlag());
            alternative.AddUtilityTerm(2, (nCallsForTour == 3).ToFlag());
            alternative.AddUtilityTerm(3, (nCallsForTour >= 4).ToFlag());
            alternative.AddUtilityTerm(4, noCarsFlag);
            alternative.AddUtilityTerm(5, carsGrAdults);
            alternative.AddUtilityTerm(6, (countKidsAtHome > 0).ToFlag());
            alternative.AddUtilityTerm(7, noStudents);
            alternative.AddUtilityTerm(8, noWorkers);


            // FULL PAIRED
            // base is two person- two worker household
            alternative        = choiceProbabilityCalculator.GetAlternative(1, available[1], choice == 1);
            alternative.Choice = 1;
            alternative.AddUtilityTerm(11, 1);
            alternative.AddUtilityTerm(20, (countMandatoryAdults > 2).ToFlag());
            alternative.AddUtilityTerm(13, (household.Has0To25KIncome).ToFlag());
            alternative.AddUtilityTerm(12, (countMandatoryAdults == household.HouseholdTotals.Adults).ToFlag() * (countMandatoryChildren == 1).ToFlag());
            alternative.AddUtilityTerm(14, (countMandatoryAdults == household.HouseholdTotals.Adults).ToFlag() * (countMandatoryChildren == 2).ToFlag());
            alternative.AddUtilityTerm(15, (countMandatoryChildren >= 3).ToFlag());
            alternative.AddUtilityTerm(16, (countNonMandatoryAdults > 0).ToFlag() * (countMandatoryChildren == 0).ToFlag());
            alternative.AddUtilityTerm(17, (countNonMandatoryAdults > 0).ToFlag() * (countMandatoryChildren == 1).ToFlag());
            alternative.AddUtilityTerm(18, (countNonMandatoryAdults > 0).ToFlag() * (countMandatoryChildren == 2).ToFlag());
            alternative.AddUtilityTerm(19, numSchoolMatch);
            alternative.AddUtilityTerm(21, lnYoungestAge);
            alternative.AddUtilityTerm(22, (household.HouseholdTotals.DrivingAgeStudents > 0).ToFlag());


            // FULL HalfTour 1
            alternative        = choiceProbabilityCalculator.GetAlternative(2, available[2], choice == 2);
            alternative.Choice = 2;
            alternative.AddUtilityTerm(31, 1);
            alternative.AddUtilityTerm(32, (countMandatoryAdults > 2).ToFlag());
            alternative.AddUtilityTerm(39, (countMandatoryAdults == household.HouseholdTotals.Adults).ToFlag() * (countMandatoryChildren == 1).ToFlag());
            alternative.AddUtilityTerm(40, (countMandatoryAdults == household.HouseholdTotals.Adults).ToFlag() * (countMandatoryChildren == 2).ToFlag());
            alternative.AddUtilityTerm(41, (countMandatoryChildren >= 3).ToFlag());
            alternative.AddUtilityTerm(42, (countNonMandatoryAdults > 0).ToFlag() * (countMandatoryChildren == 0).ToFlag());
            alternative.AddUtilityTerm(43, (countNonMandatoryAdults > 0).ToFlag() * (countMandatoryChildren == 1).ToFlag());
            alternative.AddUtilityTerm(44, (countNonMandatoryAdults > 0).ToFlag() * (countMandatoryChildren == 2).ToFlag());
            alternative.AddUtilityTerm(45, numSchoolMatch);
            alternative.AddUtilityTerm(46, (household.HouseholdTotals.DrivingAgeStudents > 0).ToFlag());
            alternative.AddUtilityTerm(47, lnOldestChild);
            alternative.AddUtilityTerm(49, totAggregateLogsum);
            alternative.AddUtilityTerm(53, (household.HouseholdTotals.ChildrenUnder5 > 1).ToFlag());
            alternative.AddUtilityTerm(54, countWorkingAtHome);



            // Full HalfTour 2
            alternative        = choiceProbabilityCalculator.GetAlternative(3, available[3], choice == 3);
            alternative.Choice = 3;
            alternative.AddUtilityTerm(51, 1);
            alternative.AddUtilityTerm(32, (countMandatoryAdults > 2).ToFlag());
            alternative.AddUtilityTerm(39, (countMandatoryAdults == household.HouseholdTotals.Adults).ToFlag() * (countMandatoryChildren == 1).ToFlag());
            alternative.AddUtilityTerm(40, (countMandatoryAdults == household.HouseholdTotals.Adults).ToFlag() * (countMandatoryChildren == 2).ToFlag());
            alternative.AddUtilityTerm(41, (countMandatoryChildren >= 3).ToFlag());
            alternative.AddUtilityTerm(42, (countNonMandatoryAdults > 0).ToFlag() * (countMandatoryChildren == 0).ToFlag());
            alternative.AddUtilityTerm(43, (countNonMandatoryAdults > 0).ToFlag() * (countMandatoryChildren == 1).ToFlag());
            alternative.AddUtilityTerm(44, (countNonMandatoryAdults > 0).ToFlag() * (countMandatoryChildren == 2).ToFlag());
            alternative.AddUtilityTerm(45, numSchoolMatch);
            alternative.AddUtilityTerm(46, (household.HouseholdTotals.DrivingAgeStudents > 0).ToFlag());
            alternative.AddUtilityTerm(47, lnOldestChild);
            alternative.AddUtilityTerm(49, totAggregateLogsum);
            alternative.AddUtilityTerm(53, (household.HouseholdTotals.ChildrenUnder5 > 1).ToFlag());
            alternative.AddUtilityTerm(54, countWorkingAtHome);

            // PARTIAL PAIRED
            alternative        = choiceProbabilityCalculator.GetAlternative(4, available[4], choice == 4);
            alternative.Choice = 4;
            alternative.AddUtilityTerm(61, 1);
            alternative.AddUtilityTerm(62, (countMandatoryAdults > 2).ToFlag());
            alternative.AddUtilityTerm(69, (countMandatoryAdults == household.HouseholdTotals.Adults).ToFlag() * (countMandatoryChildren == 1).ToFlag());
            alternative.AddUtilityTerm(70, (countMandatoryAdults == household.HouseholdTotals.Adults).ToFlag() * (countMandatoryChildren == 2).ToFlag());
            alternative.AddUtilityTerm(72, (countNonMandatoryAdults > 0).ToFlag() * (countMandatoryChildren == 0).ToFlag());
            alternative.AddUtilityTerm(73, (countNonMandatoryAdults > 0).ToFlag() * (countMandatoryChildren == 1).ToFlag());
            alternative.AddUtilityTerm(74, (countNonMandatoryAdults > 0).ToFlag() * (countMandatoryChildren == 2).ToFlag());
            alternative.AddUtilityTerm(75, lnYoungestAge);
            alternative.AddUtilityTerm(78, household.Has75KPlusIncome.ToFlag());
            alternative.AddUtilityTerm(86, (household.HouseholdTotals.DrivingAgeStudents > 0).ToFlag());
            alternative.AddUtilityTerm(87, (countMandatoryChildren >= 3).ToFlag());

            // PARTIAL HalfTour 1
            alternative        = choiceProbabilityCalculator.GetAlternative(5, available[5], choice == 5);
            alternative.Choice = 5;
            alternative.AddUtilityTerm(91, 1);
            alternative.AddUtilityTerm(92, (countMandatoryAdults > 2).ToFlag());
            alternative.AddUtilityTerm(98, (countMandatoryAdults == household.HouseholdTotals.Adults).ToFlag() * (countMandatoryChildren == 1).ToFlag());
            alternative.AddUtilityTerm(99, (countMandatoryAdults == household.HouseholdTotals.Adults).ToFlag() * (countMandatoryChildren == 2).ToFlag());
            alternative.AddUtilityTerm(102, (countNonMandatoryAdults > 0).ToFlag() * (countMandatoryChildren == 0).ToFlag());
            alternative.AddUtilityTerm(103, (countNonMandatoryAdults > 0).ToFlag() * (countMandatoryChildren == 1).ToFlag());
            alternative.AddUtilityTerm(104, (countNonMandatoryAdults > 0).ToFlag() * (countMandatoryChildren == 2).ToFlag());
            alternative.AddUtilityTerm(105, (countMandatoryChildren >= 3).ToFlag());
            alternative.AddUtilityTerm(108, lnYoungestAge);
            alternative.AddUtilityTerm(109, lnOldestChild);
            alternative.AddUtilityTerm(114, (household.Has0To25KIncome).ToFlag());
            alternative.AddUtilityTerm(115, (household.Has100KPlusIncome).ToFlag());
            alternative.AddUtilityTerm(117, (household.HouseholdTotals.ChildrenAge5Through15 > 1).ToFlag());
            alternative.AddUtilityTerm(118, (household.HouseholdTotals.PartTimeWorkers > 0).ToFlag());

            // PARTIAL HalfTour 2
            alternative        = choiceProbabilityCalculator.GetAlternative(6, available[6], choice == 6);
            alternative.Choice = 6;
            alternative.AddUtilityTerm(101, 1);
            alternative.AddUtilityTerm(92, (countMandatoryAdults > 2).ToFlag());
            alternative.AddUtilityTerm(98, (countMandatoryAdults == household.HouseholdTotals.Adults).ToFlag() * (countMandatoryChildren == 1).ToFlag());
            alternative.AddUtilityTerm(99, (countMandatoryAdults == household.HouseholdTotals.Adults).ToFlag() * (countMandatoryChildren == 2).ToFlag());
            alternative.AddUtilityTerm(102, (countNonMandatoryAdults > 0).ToFlag() * (countMandatoryChildren == 0).ToFlag());
            alternative.AddUtilityTerm(103, (countNonMandatoryAdults > 0).ToFlag() * (countMandatoryChildren == 1).ToFlag());
            alternative.AddUtilityTerm(104, (countNonMandatoryAdults > 0).ToFlag() * (countMandatoryChildren == 2).ToFlag());
            alternative.AddUtilityTerm(105, (countMandatoryChildren >= 3).ToFlag());
            alternative.AddUtilityTerm(108, lnYoungestAge);
            alternative.AddUtilityTerm(109, lnOldestChild);
            alternative.AddUtilityTerm(114, (household.Has0To25KIncome).ToFlag());
            alternative.AddUtilityTerm(115, (household.Has100KPlusIncome).ToFlag());
            alternative.AddUtilityTerm(117, (household.HouseholdTotals.ChildrenAge5Through15 > 1).ToFlag());
            alternative.AddUtilityTerm(118, (household.HouseholdTotals.PartTimeWorkers > 0).ToFlag());
        }
예제 #8
0
        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;

            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);
                ChoiceProbabilityCalculator.Alternative 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);
                ChoiceProbabilityCalculator.Alternative 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
            ChoiceProbabilityCalculator.Alternative 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);
        }
예제 #9
0
        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>();

            Framework.DomainModels.Wrappers.IHouseholdWrapper household       = householdDay.Household;
            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 personalBusinessAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                                     [Global.Settings.Purposes.PersonalBusiness][carOwnership][votALSegment][transitAccessSegment];
            double 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];
            double socialAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                           [Global.Settings.Purposes.Social][carOwnership][votALSegment][transitAccessSegment];
            double 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];
            double compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.NoCars][votALSegment][transitAccessSegment];


            int countNonMandatory  = 0;
            int countMandatory     = 0;
            int countWorkingAtHome = 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)
            {
                Framework.DomainModels.Wrappers.IPersonWrapper 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
                {
                    int destinationArrivalTime   = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.WorkTourModeModel);
                    int 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);
                    ChoiceProbabilityCalculator.Alternative 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
                {
                    int destinationArrivalTime   = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.SchoolTourModeModel);
                    int 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);
                    ChoiceProbabilityCalculator.Alternative 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

            ChoiceProbabilityCalculator.Alternative 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);
        }
예제 #10
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, PersonDayWrapper personDay, HouseholdDayWrapper householdDay, DayPattern[] dayPatterns, DayPattern choice = null)
        {
            Framework.DomainModels.Wrappers.IHouseholdWrapper household       = personDay.Household;
            Framework.DomainModels.Wrappers.IParcelWrapper    residenceParcel = household.ResidenceParcel;
            Framework.DomainModels.Wrappers.IPersonWrapper    person          = personDay.Person;

            int    carsPerDriver       = household.GetCarsPerDriver();
            double mixedDensity        = residenceParcel.MixedUse3Index2();
            double intersectionDensity = residenceParcel.IntersectionDensity34Minus1Buffer2();

            double[] purposeLogsums = new double[Global.Settings.Purposes.TotalPurposes + 2];
            double[] atUsualLogsums = new double[3];
            //var carOwnership = person.CarOwnershipSegment; //GV: sat car ownership not to impact logsums
            int carOwnership  = 0;
            int votSegment    = person.Household.GetVotALSegment();
            int 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;

            int onePersonHouseholdFlag = household.IsOnePersonHousehold.ToFlag();
            int twoPersonHouseholdFlag = household.IsTwoPersonHousehold.ToFlag();

            int householdCars = household.VehiclesAvailable;
            //var noCarsInHouseholdFlag = HouseholdWrapper.GetNoCarsInHouseholdFlag(householdCars);
            //var carsLessThanDriversFlag = household.GetCarsLessThanDriversFlag(householdCars);
            //var carsLessThanWorkersFlag = household.GetCarsLessThanWorkersFlag(householdCars);

            int HHwithChildrenFlag      = household.HasChildren.ToFlag();
            int HHwithSmallChildrenFlag = household.HasChildrenUnder5.ToFlag();
            int HHwithLowIncomeFlag     = (household.Income >= 300000 && household.Income < 600000).ToFlag();
            int HHwithMidleIncomeFlag   = (household.Income >= 600000 && household.Income < 900000).ToFlag();
            int HHwithHighIncomeFlag    = (household.Income >= 900000).ToFlag();

            int primaryFamilyTimeFlag = householdDay.PrimaryPriorityTimeFlag;

            //GV: input 26. july 2013
            // person inputs
            int partTimeWorkerFlag     = person.IsPartTimeWorker.ToFlag();
            int nonworkingAdultFlag    = person.IsNonworkingAdult.ToFlag();
            int universityStudentFlag  = person.IsUniversityStudent.ToFlag();
            int retiredAdultFlag       = person.IsRetiredAdult.ToFlag();
            int fullTimeWorkerFlag     = person.IsFulltimeWorker.ToFlag();
            int childAge5Through15Flag = person.IsChildAge5Through15.ToFlag();
            int childUnder5Flag        = person.IsChildUnder5.ToFlag();
            int adultFlag = person.IsAdult.ToFlag();

            int maleFlag   = person.IsMale.ToFlag();
            int femaleFlag = person.IsFemale.ToFlag();



            if (person.UsualWorkParcel == null || person.UsualWorkParcelId == household.ResidenceParcelId)
            {
                purposeLogsums[Global.Settings.Purposes.Work] = 0;
            }
            else
            {
                int destinationArrivalTime   = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.WorkTourModeModel);
                int destinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.WorkTourModeModel);
                //JLB 201406
                //var nestedAlternative = Global.ChoiceModelSession.Get<WorkTourModeModel>().RunNested(personDay, residenceParcel, person.UsualWorkParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable);
                //JLB 201602
                //var nestedAlternative = Global.ChoiceModelSession.Get<WorkTourModeTimeModel>().RunNested(personDay, residenceParcel, person.UsualWorkParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable);
                ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <TourModeTimeModel>().RunNested(personDay, residenceParcel, person.UsualWorkParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable, Global.Settings.Purposes.Work);

                purposeLogsums[Global.Settings.Purposes.Work] = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                atUsualLogsums[Global.Settings.Purposes.Work] = Global.AggregateLogsums[person.UsualWorkParcel.ZoneId][Global.Settings.Purposes.HomeBasedComposite][carOwnership][votSegment][person.UsualWorkParcel.TransitAccessSegment()];
            }

            if (person.UsualSchoolParcel == null || person.UsualSchoolParcelId == household.ResidenceParcelId)
            {
                purposeLogsums[Global.Settings.Purposes.School] = 0;
            }
            else
            {
                int destinationArrivalTime   = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.SchoolTourModeModel);
                int destinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.SchoolTourModeModel);
                //JLB 201406
                //var nestedAlternative = Global.ChoiceModelSession.Get<SchoolTourModeModel>().RunNested(personDay, residenceParcel, person.UsualSchoolParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable);
                //JLB 201602
                //var nestedAlternative = Global.ChoiceModelSession.Get<SchoolTourModeTimeModel>().RunNested(personDay, residenceParcel, person.UsualSchoolParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable);
                ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <TourModeTimeModel>().RunNested(personDay, residenceParcel, person.UsualSchoolParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable, Global.Settings.Purposes.School);

                purposeLogsums[Global.Settings.Purposes.School] = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                atUsualLogsums[Global.Settings.Purposes.School] = Global.AggregateLogsums[person.UsualSchoolParcel.ZoneId][Global.Settings.Purposes.HomeBasedComposite][carOwnership][votSegment][person.UsualSchoolParcel.TransitAccessSegment()];
            }

            double compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][carOwnership][votSegment][transitAccess];

            purposeLogsums[Global.Settings.Purposes.Escort]           = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.Escort][carOwnership][votSegment][transitAccess];
            purposeLogsums[Global.Settings.Purposes.PersonalBusiness] = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.PersonalBusiness][carOwnership][votSegment][transitAccess];
            purposeLogsums[Global.Settings.Purposes.Shopping]         = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.Shopping][carOwnership][votSegment][transitAccess];
            purposeLogsums[Global.Settings.Purposes.Social]           = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.Social][carOwnership][votSegment][transitAccess];

            for (int 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
                int purpose = xPurpose <= Global.Settings.Purposes.Social ? xPurpose :
                              xPurpose <= Global.Settings.Purposes.Social + 5 ? Global.Settings.Purposes.Social + 1 :
                              Global.Settings.Purposes.Social + 2;

                // get correct multiplier on coefficients.
                double xMultiplier = xPurpose <= Global.Settings.Purposes.Social ? 1.0 :
                                     xPurpose <= Global.Settings.Purposes.Social + 5 ? Math.Log(xPurpose - Global.Settings.Purposes.Social + 1) :
                                     Math.Log(xPurpose - Global.Settings.Purposes.Social - 5 + 1);

                choiceProbabilityCalculator.CreateUtilityComponent(xPurpose);
                ChoiceProbabilityCalculator.Component component = choiceProbabilityCalculator.GetUtilityComponent(xPurpose);

                component.AddUtilityTerm(100 * purpose + 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);
            ChoiceProbabilityCalculator.Component 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);
            ChoiceProbabilityCalculator.Component 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 (int alternativeIndex = 0; alternativeIndex < TOTAL_ALTERNATIVES; alternativeIndex++)
            {
                DayPattern dayPattern = dayPatterns[alternativeIndex];
                bool       available  = dayPattern.Available;
                ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(alternativeIndex, available, choice != null && choice.Equals(dayPattern));

                if (!Global.Configuration.IsInEstimationMode && !alternative.Available)
                {
                    continue;
                }

                alternative.Choice = dayPattern;

                // components for the purposes
                for (int purpose = Global.Settings.Purposes.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 (int tourPurpose = Global.Settings.Purposes.Work; tourPurpose <= Global.Settings.Purposes.Social; tourPurpose++)
                {
                    for (int stopPurpose = Global.Settings.Purposes.Work; stopPurpose <= Global.Settings.Purposes.Social - 1; stopPurpose++)
                    {
                        if (tourPurpose > Global.Settings.Purposes.School && stopPurpose <= Global.Settings.Purposes.School)
                        {
                            continue;
                        }

                        if (dayPattern.Tours[tourPurpose] > 0 && dayPattern.Stops[stopPurpose] > 0)
                        {
                            alternative.AddUtilityTerm(1200 + 10 * tourPurpose + stopPurpose, 1); // tour-stop comb. utility
                        }
                    }
                }

                for (int tourPurpose = Global.Settings.Purposes.Work; tourPurpose <= Global.Settings.Purposes.School; tourPurpose++)
                {
                    if (dayPattern.Tours[tourPurpose] == 1 && dayPattern.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 (int tourPurpose = Global.Settings.Purposes.Work; tourPurpose <= Global.Settings.Purposes.Social - 2; tourPurpose++)
                {
                    for (int tourPurpose2 = tourPurpose + 1; tourPurpose2 <= Global.Settings.Purposes.Social; tourPurpose2++)
                    {
                        if (dayPattern.Tours[tourPurpose] > 0 && dayPattern.Tours[tourPurpose2] > 0)
                        {
                            alternative.AddUtilityTerm(1400 + 10 * tourPurpose + tourPurpose2, 1); // tour-tour comb. utility
                        }
                    }
                }

                for (int tourPurpose = Global.Settings.Purposes.Business; tourPurpose <= Global.Settings.Purposes.Business; tourPurpose++)
                {
                    for (int 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 (int stopPurpose = Global.Settings.Purposes.Work; stopPurpose <= Global.Settings.Purposes.Social - 2; stopPurpose++)
                {
                    for (int stopPurpose2 = stopPurpose + 1; stopPurpose2 <= Global.Settings.Purposes.Social; stopPurpose2++)
                    {
                        if (dayPattern.Stops[stopPurpose] > 0 && dayPattern.Stops[stopPurpose2] > 0)
                        {
                            alternative.AddUtilityTerm(1500 + 10 * stopPurpose + stopPurpose2, 1); // stop-stop comb. utility
                        }
                    }
                }

                if (dayPattern.TotalTourPurposes > 0 && dayPattern.TotalStopPurposes > 0)
                {
                    int 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));
                }
            }
        }