Пример #1
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITourWrapper tour, int nCallsForTour, int choice = Constants.DEFAULT_VALUE)
        {
            IPersonWrapper    person    = tour.Person;
            IPersonDayWrapper personDay = tour.PersonDay;

            //            var foodRetailServiceMedicalQtrMileLog = tour.DestinationParcel.FoodRetailServiceMedicalQtrMileLogBuffer1();
            //            var mixedUseIndex = tour.DestinationParcel.MixedUse4Index1();
            double k8HighSchoolQtrMileLog = tour.DestinationParcel.K8HighSchoolQtrMileLogBuffer1();
            int    carOwnership           = person.GetCarOwnershipSegment();

            int noCarsFlag         = FlagUtility.GetNoCarsFlag(carOwnership);
            int carCompetitionFlag = FlagUtility.GetCarCompetitionFlag(carOwnership);
            //            var notUsualWorkParcelFlag = tour.DestinationParcel.NotUsualWorkParcelFlag(person.UsualWorkParcelId);

            int votALSegment = tour.GetVotALSegment();

            int    workTaSegment       = tour.DestinationParcel.TransitAccessSegment();
            double workAggregateLogsum = Global.AggregateLogsums[tour.DestinationParcel.ZoneId]
                                         [Global.Settings.Purposes.WorkBased][carOwnership][votALSegment][workTaSegment];

            // 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(15, (nCallsForTour > 1).ToFlag());
            alternative.AddUtilityTerm(16, Math.Log(personDay.HomeBasedTours));
            alternative.AddUtilityTerm(18, personDay.TwoOrMoreWorkToursExist().ToFlag());
            //            alternative.AddUtility(19, notUsualWorkParcelFlag);
            alternative.AddUtilityTerm(22, noCarsFlag);
            alternative.AddUtilityTerm(23, carCompetitionFlag);
            alternative.AddUtilityTerm(32, workAggregateLogsum);
            //            alternative.AddUtility(32, mixedUseIndex);

            alternative.AddNestedAlternative(11, 0, 50);

            // WORK

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

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

            alternative.AddUtilityTerm(1, 1);

            alternative.AddNestedAlternative(12, 1, 50);

            // SCHOOL

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

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

            alternative.AddUtilityTerm(3, 1);

            alternative.AddNestedAlternative(12, 1, 50);

            // ESCORT

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

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

            alternative.AddUtilityTerm(4, 1);
            alternative.AddUtilityTerm(39, k8HighSchoolQtrMileLog);

            alternative.AddNestedAlternative(12, 1, 50);

            // 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(6, 1);

            alternative.AddNestedAlternative(12, 1, 50);

            // SHOPPING

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

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

            alternative.AddUtilityTerm(8, 1);

            alternative.AddNestedAlternative(12, 1, 50);

            // MEAL

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

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

            alternative.AddUtilityTerm(10, 1);

            alternative.AddNestedAlternative(12, 1, 50);

            // SOCIAL

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

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

            alternative.AddUtilityTerm(13, 1);

            alternative.AddNestedAlternative(12, 1, 50);
        }
Пример #2
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, PersonDayWrapper personDay, HouseholdDayWrapper householdDay, int choice = Constants.DEFAULT_VALUE)
        {
            var household = householdDay.Household;

            // set household characteristics here that don't depend on person characteristics
            var available = (householdDay.Household.Size > 1);

            int hasAdultEducLevel12 = 0;
            //int allAdultEducLevel12 = 1;
            int youngestAge = 999;

            foreach (PersonWrapper person in householdDay.Household.Persons)
            {
                // set characteristics here that depend on person characteristics
                if (person.Age >= 18 && person.EducationLevel >= 12)
                {
                    hasAdultEducLevel12 = 1;
                }
                //if (person.Age >= 18 && person.EducationLevel < 12) allAdultEducLevel12 = 0;
                if (person.Age < youngestAge)
                {
                    youngestAge = person.Age;
                }
            }


            Double workTourLogsum;

            if (personDay.Person.UsualWorkParcelId != Constants.DEFAULT_VALUE && personDay.Person.UsualWorkParcelId != Global.Settings.OutOfRegionParcelId)
            {
                //JLB 201406
                //var nestedAlternative = Global.ChoiceModelSession.Get<WorkTourModeModel>().RunNested(personDay.Person, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualWorkParcel, Global.Settings.Times.EightAM, Global.Settings.Times.FivePM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers);
                var nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().RunNested(personDay, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualWorkParcel, Global.Settings.Times.EightAM, Global.Settings.Times.FivePM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers);
                workTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
            }
            else
            {
                workTourLogsum = 0;
            }

            int atHomeDay           = personDay.PatternType == 3 ? 1 : 0;
            int nonMandatoryTourDay = personDay.PatternType == 2 ? 1 : 0;
            int MandatoryTourDay    = personDay.PatternType == 1 ? 1 : 0;



            var carOwnership =
                household.VehiclesAvailable == 0
                                                                 ? Global.Settings.CarOwnerships.NoCars
                                                                 : household.VehiclesAvailable < household.HouseholdTotals.DrivingAgeMembers
                                                                          ? Global.Settings.CarOwnerships.LtOneCarPerAdult
                                                                          : Global.Settings.CarOwnerships.OneOrMoreCarsPerAdult;

            var noCarsFlag         = FlagUtility.GetNoCarsFlag(carOwnership);
            var carCompetitionFlag = FlagUtility.GetCarCompetitionFlag(carOwnership);

            var votALSegment                    = Global.Settings.VotALSegments.Medium; // TODO:  calculate a VOT segment that depends on household income
            var transitAccessSegment            = household.ResidenceParcel.TransitAccessSegment();
            var personalBusinessAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                                  [Global.Settings.Purposes.PersonalBusiness][carOwnership][votALSegment][transitAccessSegment];
            var shoppingAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                          [Global.Settings.Purposes.Shopping][carOwnership][votALSegment][transitAccessSegment];
            var mealAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                      [Global.Settings.Purposes.Meal][carOwnership][votALSegment][transitAccessSegment];
            var socialAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                        [Global.Settings.Purposes.Social][carOwnership][votALSegment][transitAccessSegment];
            //var compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][carOwnership][votALSegment][transitAccessSegment];

            var compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.NoCars][votALSegment][transitAccessSegment];

            //var householdDay = (LDHouseholdDayWrapper)tour.HouseholdDay;
            //var household = householdDay.Household;



            // 0 Person doesn't work at home more than specified number of minutes
            var alternative = choiceProbabilityCalculator.GetAlternative(0, true, choice == 0);

            alternative.Choice = 0;

            alternative.AddUtilityTerm(1, 0.0);

            // 1 Works at home
            alternative        = choiceProbabilityCalculator.GetAlternative(1, true, choice == 1);
            alternative.Choice = 1;

            alternative.AddUtilityTerm(1, 1.0);

            alternative.AddUtilityTerm(2, householdDay.Household.HasChildrenUnder5.ToFlag());
            alternative.AddUtilityTerm(3, householdDay.Household.HasChildrenAge5Through15.ToFlag());
            alternative.AddUtilityTerm(4, (householdDay.Household.Size == 2 && householdDay.AdultsInSharedHomeStay == 2).ToFlag());
            alternative.AddUtilityTerm(5, (householdDay.AdultsInSharedHomeStay == 1 && householdDay.Household.HasChildrenUnder16).ToFlag());
            alternative.AddUtilityTerm(6, (householdDay.AdultsInSharedHomeStay == 2 && householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag());
            alternative.AddUtilityTerm(7, (householdDay.AdultsInSharedHomeStay == 2 && hasAdultEducLevel12 == 1).ToFlag());
            alternative.AddUtilityTerm(8, (youngestAge >= 40).ToFlag());

            alternative.AddUtilityTerm(10, (householdDay.Household.Income >= 300000 && householdDay.Household.Income < 600000).ToFlag());
            alternative.AddUtilityTerm(11, (householdDay.Household.Income >= 600000 && householdDay.Household.Income < 900000).ToFlag());
            alternative.AddUtilityTerm(12, (householdDay.Household.Income >= 900000).ToFlag());

            alternative.AddUtilityTerm(15, householdDay.PrimaryPriorityTimeFlag);

            alternative.AddUtilityTerm(16, (householdDay.Household.Size == 2).ToFlag());
            alternative.AddUtilityTerm(17, (householdDay.Household.Size == 3).ToFlag());
            alternative.AddUtilityTerm(18, (householdDay.Household.Size >= 4).ToFlag());
            //alternative.AddUtilityTerm(18, (householdDay.Household.Size >= 5).ToFlag());

            alternative.AddUtilityTerm(21, personDay.Person.IsPartTimeWorker.ToFlag());
            //alternative.AddUtilityTerm(2, personDay.Person.IsFulltimeWorker.ToFlag());

            alternative.AddUtilityTerm(22, (personDay.Person.Gender == 1).ToFlag());
            alternative.AddUtilityTerm(23, (hasAdultEducLevel12 == 1).ToFlag());

            //alternative.AddUtilityTerm(24, MandatoryTourDay);
            alternative.AddUtilityTerm(25, nonMandatoryTourDay);

            alternative.AddUtilityTerm(26, atHomeDay);

            //alternative.AddUtilityTerm(27, workTourLogsum);

            //alternative.AddUtilityTerm(26, workTourLogsum * MandatoryTourDay);
            //alternative.AddUtilityTerm(27, workTourLogsum * nonMandatoryTourDay);

            alternative.AddUtilityTerm(27, compositeLogsum);

            //alternative.AddUtilityTerm(27, (householdDay.Household.VehiclesAvailable == 1 && household.Has2Drivers).ToFlag()); //GV not significant
            //alternative.AddUtilityTerm(28, (householdDay.Household.VehiclesAvailable >= 2 && household.Has2Drivers).ToFlag()); //GV not significant
        }
Пример #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
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, IPersonDayWrapper personDay, IHouseholdDayWrapper householdDay, int choice = Constants.DEFAULT_VALUE)
        {
            IEnumerable <PersonDayWrapper> orderedPersonDays = householdDay.PersonDays.OrderBy(p => p.GetJointTourParticipationPriority()).ToList().Cast <PersonDayWrapper>();

            double workTourLogsum;

            if (personDay.Person.UsualWorkParcelId != Constants.DEFAULT_VALUE && personDay.Person.UsualWorkParcelId != Global.Settings.OutOfRegionParcelId)
            {
                if (personDay.Person.UsualDeparturePeriodFromWork != Constants.DEFAULT_VALUE && personDay.Person.UsualArrivalPeriodToWork != Constants.DEFAULT_VALUE)
                {
                    ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().RunNested(personDay, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualWorkParcel, (int)personDay.Person.UsualArrivalPeriodToWork, (int)personDay.Person.UsualDeparturePeriodFromWork, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers);
                    workTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                }
                else
                {
                    ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().RunNested(personDay, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualWorkParcel, Global.Settings.Times.EightAM, Global.Settings.Times.FivePM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers);
                    workTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                }
            }
            else
            {
                workTourLogsum = 0;
            }

            int noUsualWorkLocation = 0;

            if (personDay.Person.UsualWorkParcelId == Constants.DEFAULT_VALUE || personDay.Person.UsualWorkParcelId == Global.Settings.OutOfRegionParcelId)
            {
                noUsualWorkLocation = 1;
            }

            int atHomeDay               = personDay.PatternType == 3 ? 1 : 0;
            int nonMandatoryTourDay     = personDay.PatternType == 2 ? 1 : 0;
            int mandatoryTourDay        = personDay.PatternType == 1 ? 1 : 0;
            IHouseholdWrapper household = householdDay.Household;
            int carOwnership            =
                household.VehiclesAvailable == 0
                                        ? Global.Settings.CarOwnerships.NoCars
                                        : household.VehiclesAvailable < household.HouseholdTotals.DrivingAgeMembers
                                              ? Global.Settings.CarOwnerships.LtOneCarPerAdult
                                              : Global.Settings.CarOwnerships.OneOrMoreCarsPerAdult;



            int usualWorkAtHome  = household.ResidenceParcelId == personDay.Person.UsualWorkParcelId ? 1 : 0;
            int usualWorkOutside = usualWorkAtHome == 1 ? 0 : 1;

            int noCarsFlag         = FlagUtility.GetNoCarsFlag(carOwnership);
            int carCompetitionFlag = FlagUtility.GetCarCompetitionFlag(carOwnership);

            int countMandatory    = (from personDayHH in orderedPersonDays where personDayHH.PatternType == 1 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();

            // 0 Person doesn't work at home more than specified number of minutes
            ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(0, true, choice == 0);
            alternative.Choice = 0;

            alternative.AddUtilityTerm(1, 0.0);

            // 1 Works at home
            alternative        = choiceProbabilityCalculator.GetAlternative(1, true, choice == 1);
            alternative.Choice = 1;

            double adjustedConstant = Global.Configuration.IsInEstimationMode ? 1.0 :
                                      (-2.0 + Math.Log(1.0 + Global.Configuration.Policy_FractionIncreaseInWorkAtHomeShare)) / -2.0;

            alternative.AddUtilityTerm(1, adjustedConstant);

            alternative.AddUtilityTerm(2, personDay.Person.IsPartTimeWorker.ToFlag());
            alternative.AddUtilityTerm(4, nonMandatoryTourDay * usualWorkOutside);
            alternative.AddUtilityTerm(7, atHomeDay * usualWorkOutside);
            alternative.AddUtilityTerm(8, (personDay.Person.Age < 30).ToFlag());
            alternative.AddUtilityTerm(9, (personDay.Person.Age >= 30 && personDay.Person.Age < 35).ToFlag());
            alternative.AddUtilityTerm(10, noUsualWorkLocation);
            alternative.AddUtilityTerm(11, countMandatory - mandatoryTourDay);
            alternative.AddUtilityTerm(12, countAtHome - atHomeDay);
            alternative.AddUtilityTerm(14, householdDay.Household.HouseholdTotals.ChildrenAge5Through15);
            alternative.AddUtilityTerm(16, usualWorkAtHome);
            alternative.AddUtilityTerm(17, ((householdDay.Household.Has0To25KIncome).ToFlag()));
            alternative.AddUtilityTerm(18, ((householdDay.Household.Has100KPlusIncome).ToFlag()));
            alternative.AddUtilityTerm(19, workTourLogsum);
            alternative.AddUtilityTerm(20, (personDay.Person.IsStudent.ToFlag()));
            alternative.AddUtilityTerm(31, carCompetitionFlag + noCarsFlag);
        }
Пример #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 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));
        }
Пример #6
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, PersonDayWrapper personDay, HouseholdDayWrapper householdDay, int nCallsForTour, int[] simulatedMandatoryTours, int choice = Constants.DEFAULT_VALUE)
        {
            var household = personDay.Household;

            Double workTourLogsum;

            if (personDay.Person.UsualWorkParcelId != Constants.DEFAULT_VALUE && personDay.Person.UsualWorkParcelId != Global.Settings.OutOfRegionParcelId)
            {
                //JLB 201406
                //var nestedAlternative = Global.ChoiceModelSession.Get<WorkTourModeModel>().RunNested(personDay.Person, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualWorkParcel, Global.Settings.Times.EightAM, Global.Settings.Times.FivePM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers);
                var nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().RunNested(personDay, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualWorkParcel, Global.Settings.Times.EightAM, Global.Settings.Times.FivePM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers);
                workTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
            }
            else
            {
                workTourLogsum = 0;
            }

            Double schoolTourLogsum;

            if (personDay.Person.UsualSchoolParcelId != Constants.DEFAULT_VALUE && personDay.Person.UsualSchoolParcelId != Global.Settings.OutOfRegionParcelId)
            {
                //JLB
                //var nestedAlternative = Global.ChoiceModelSession.Get<SchoolTourModeModel>().RunNested(personDay.Person, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualSchoolParcel, Global.Settings.Times.EightAM, Global.Settings.Times.FivePM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers);
                var nestedAlternative = Global.ChoiceModelSession.Get <SchoolTourModeTimeModel>().RunNested(personDay, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualSchoolParcel, Global.Settings.Times.EightAM, Global.Settings.Times.FivePM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers);
                schoolTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
            }
            else
            {
                schoolTourLogsum = 0;
            }

            var carOwnership =
                household.VehiclesAvailable == 0
                                                        ? Global.Settings.CarOwnerships.NoCars
                                                        : household.VehiclesAvailable < household.HouseholdTotals.DrivingAgeMembers
                                                                ? Global.Settings.CarOwnerships.LtOneCarPerAdult
                                                                : Global.Settings.CarOwnerships.OneOrMoreCarsPerAdult;

            var noCarsFlag         = FlagUtility.GetNoCarsFlag(carOwnership);
            var carCompetitionFlag = FlagUtility.GetCarCompetitionFlag(carOwnership);

            var votALSegment                    = Global.Settings.VotALSegments.Medium; // TODO:  calculate a VOT segment that depends on household income
            var transitAccessSegment            = household.ResidenceParcel.TransitAccessSegment();
            var personalBusinessAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                                  [Global.Settings.Purposes.PersonalBusiness][carOwnership][votALSegment][transitAccessSegment];
            var shoppingAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                          [Global.Settings.Purposes.Shopping][carOwnership][votALSegment][transitAccessSegment];
            var mealAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                      [Global.Settings.Purposes.Meal][carOwnership][votALSegment][transitAccessSegment];
            var socialAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                        [Global.Settings.Purposes.Social][carOwnership][votALSegment][transitAccessSegment];
            //var compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][carOwnership][votALSegment][transitAccessSegment];
            var compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.NoCars][votALSegment][transitAccessSegment];

            //int hasAdultEducLevel12 = 0;
            //int allAdultEducLevel12 = 1;
            int youngestAge = 999;

            foreach (PersonWrapper person in personDay.Household.Persons)
            {
                // set characteristics here that depend on person characteristics
                //if (person.Age >= 18 && person.EducationLevel >= 12) hasAdultEducLevel12 = 1;
                //if (person.Age >= 18 && person.EducationLevel < 12) allAdultEducLevel12 = 0;
                if (person.Age < youngestAge)
                {
                    youngestAge = person.Age;
                }
            }

            bool schoolAvailableFlag = true;

            if ((!personDay.Person.IsStudent) || (!Global.Configuration.IsInEstimationMode && personDay.Person.UsualSchoolParcel == null))
            {
                schoolAvailableFlag = false;
            }

            // NONE_OR_HOME

            var alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.NoneOrHome, nCallsForTour > 1, choice == Global.Settings.Purposes.NoneOrHome);

            alternative.Choice = Global.Settings.Purposes.NoneOrHome;
            //alternative.AddUtilityTerm(1, (nCallsForTour > 2).ToFlag()); // GV; 16.april 2013 - cannot be estimated

            //alternative.AddUtilityTerm(2, householdDay.Household.HasChildren.ToFlag());
            alternative.AddUtilityTerm(3, householdDay.Household.HasChildrenUnder5.ToFlag());
            alternative.AddUtilityTerm(4, householdDay.Household.HasChildrenAge5Through15.ToFlag());
            //alternative.AddUtilityTerm(6, householdDay.Household.HasChildrenUnder16.ToFlag());

            //alternative.AddUtilityTerm(10, (householdDay.Household.Size == 2).ToFlag()); // GV; 16. april 2013 - cannot be estimated
            alternative.AddUtilityTerm(11, (householdDay.Household.Size == 3).ToFlag());
            alternative.AddUtilityTerm(12, (householdDay.Household.Size >= 4).ToFlag());

            //alternative.AddUtilityTerm(14, (householdDay.Household.Income >= 300000 && householdDay.Household.Income < 600000).ToFlag());
            //alternative.AddUtilityTerm(15, (householdDay.Household.Income >= 600000 && householdDay.Household.Income < 900000).ToFlag());
            //alternative.AddUtilityTerm(16, (householdDay.Household.Income >= 900000).ToFlag());

            //alternative.AddNestedAlternative(11, 0, 60);


            // USUAL WORK
            alternative        = choiceProbabilityCalculator.GetAlternative(1, (personDay.Person.UsualWorkParcelId > 0 && simulatedMandatoryTours[2] == 0), choice == 1);
            alternative.Choice = 1;
            alternative.AddUtilityTerm(21, 1);

            //alternative.AddUtilityTerm(22, personDay.Person.IsChildUnder5.ToFlag());
            alternative.AddUtilityTerm(23, personDay.Person.WorksAtHome.ToFlag());
            alternative.AddUtilityTerm(24, personDay.Person.IsFulltimeWorker.ToFlag());
            alternative.AddUtilityTerm(25, personDay.Person.IsMale.ToFlag());
            //alternative.AddUtilityTerm(4, person.IsPartTimeWorker.ToFlag());

            alternative.AddUtilityTerm(26, (householdDay.AdultsInSharedHomeStay == 2 && householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag());
            //alternative.AddUtilityTerm(14, (householdDay.AdultsInSharedHomeStay == 2).ToFlag());
            //alternative.AddUtilityTerm(15, (householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag());
            alternative.AddUtilityTerm(27, (householdDay.AdultsInSharedHomeStay == 1 && householdDay.Household.HasChildren).ToFlag());

            alternative.AddUtilityTerm(28, workTourLogsum);

            //alternative.AddUtilityTerm(28, (householdDay.Household.VehiclesAvailable == 1 && household.Has2Drivers).ToFlag());
            alternative.AddUtilityTerm(29, (householdDay.Household.VehiclesAvailable >= 2 && household.Has2Drivers).ToFlag());

            alternative.AddUtilityTerm(30, householdDay.PrimaryPriorityTimeFlag);

            //alternative.AddNestedAlternative(12, 1, 60);

            // BUSINESS
            alternative        = choiceProbabilityCalculator.GetAlternative(2, (personDay.Person.IsWorker && simulatedMandatoryTours[3] == 0), choice == 2);
            alternative.Choice = 2;
            alternative.AddUtilityTerm(31, 1);

            //alternative.AddUtilityTerm(32, personDay.Person.IsChildUnder5.ToFlag());
            alternative.AddUtilityTerm(33, personDay.Person.WorksAtHome.ToFlag());
            alternative.AddUtilityTerm(34, personDay.Person.IsFulltimeWorker.ToFlag());
            alternative.AddUtilityTerm(35, personDay.Person.IsMale.ToFlag());
            //alternative.AddUtilityTerm(4, person.IsPartTimeWorker.ToFlag());

            alternative.AddUtilityTerm(36, (householdDay.AdultsInSharedHomeStay == 2 && householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag());
            //alternative.AddUtilityTerm(14, (householdDay.AdultsInSharedHomeStay == 2).ToFlag());
            //alternative.AddUtilityTerm(15, (householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag());
            alternative.AddUtilityTerm(37, (householdDay.AdultsInSharedHomeStay == 1 && householdDay.Household.HasChildren).ToFlag());

            alternative.AddUtilityTerm(38, workTourLogsum);

            //alternative.AddUtilityTerm(38, (householdDay.Household.VehiclesAvailable == 1 && household.Has2Drivers).ToFlag());
            alternative.AddUtilityTerm(39, (householdDay.Household.VehiclesAvailable >= 2 && household.Has2Drivers).ToFlag());

            alternative.AddUtilityTerm(40, householdDay.PrimaryPriorityTimeFlag);

            //alternative.AddNestedAlternative(12, 1, 60);

            // SCHOOL
            alternative        = choiceProbabilityCalculator.GetAlternative(3, schoolAvailableFlag, choice == 3);
            alternative.Choice = 3;
            alternative.AddUtilityTerm(41, 1);

            alternative.AddUtilityTerm(42, personDay.Person.IsNonworkingAdult.ToFlag());
            //alternative.AddUtilityTerm(43, personDay.Person.IsPartTimeWorker.ToFlag());
            alternative.AddUtilityTerm(43, personDay.Person.IsYouth.ToFlag());

            //alternative.AddUtilityTerm(46, (householdDay.AdultsInSharedHomeStay == 2 && householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag());
            //alternative.AddUtilityTerm(14, (householdDay.AdultsInSharedHomeStay == 2).ToFlag());
            //alternative.AddUtilityTerm(15, (householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag());
            //alternative.AddUtilityTerm(47, (householdDay.AdultsInSharedHomeStay == 1 && householdDay.Household.HasChildren).ToFlag());

            alternative.AddUtilityTerm(48, workTourLogsum);
            alternative.AddUtilityTerm(49, schoolTourLogsum);

            //alternative.AddUtilityTerm(48, (householdDay.Household.VehiclesAvailable == 1 && household.Has2Drivers).ToFlag());
            //alternative.AddUtilityTerm(49, (householdDay.Household.VehiclesAvailable >= 2 && household.Has2Drivers).ToFlag());

            alternative.AddUtilityTerm(50, householdDay.PrimaryPriorityTimeFlag);

            //alternative.AddNestedAlternative(12, 1, 60);
        }
Пример #7
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, IPersonDayWrapper personDay, IHouseholdDayWrapper householdDay, int nCallsForTour, int[] simulatedMandatoryTours, int choice = Constants.DEFAULT_VALUE)
        {
            var household = personDay.Household;

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


            var carOwnership =
                household.VehiclesAvailable == 0
                                 ? Global.Settings.CarOwnerships.NoCars
                                 : household.VehiclesAvailable < household.HouseholdTotals.DrivingAgeMembers
                                      ? Global.Settings.CarOwnerships.LtOneCarPerAdult
                                      : Global.Settings.CarOwnerships.OneOrMoreCarsPerAdult;

            var noCarsFlag         = FlagUtility.GetNoCarsFlag(carOwnership);
            var carCompetitionFlag = FlagUtility.GetCarCompetitionFlag(carOwnership);

            var votALSegment         = household.GetVotALSegment();
            var transitAccessSegment = household.ResidenceParcel.TransitAccessSegment();

            Double workTourLogsum    = 0;
            Double schoolTourLogsum  = 0;
            Double schoolPclUniStu   = 0;
            Double schoolPclStudents = 0;
            Double schoolIntrDens    = 0;
            Double workPclWrkrs      = 0;
            Double workIntrDens      = 0;
            int    noUsualWorkZone   = 1;


            if (personDay.Person.UsualWorkParcelId != Constants.DEFAULT_VALUE && personDay.Person.UsualWorkParcelId != Global.Settings.OutOfRegionParcelId)
            {
                if (personDay.Person.UsualDeparturePeriodFromWork != Constants.DEFAULT_VALUE && personDay.Person.UsualArrivalPeriodToWork != Constants.DEFAULT_VALUE)
                {
                    var nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().RunNested(personDay, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualWorkParcel, (int)personDay.Person.UsualArrivalPeriodToWork, (int)personDay.Person.UsualDeparturePeriodFromWork, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers);
                    workTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                    workPclWrkrs   = Math.Log(1 + (personDay.Person.UsualWorkParcel.EmploymentTotalBuffer2)) / 10;
                    workIntrDens   = Math.Log(1 + personDay.Person.UsualWorkParcel.C34RatioBuffer1());
                }
                else
                {
                    var nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().RunNested(personDay, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualWorkParcel, Global.Settings.Times.EightAM, Global.Settings.Times.FivePM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers);
                    workTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                }

                noUsualWorkZone = 0;
            }


            if (personDay.Person.UsualSchoolParcelId != 0 && personDay.Person.UsualSchoolParcelId != -1 && personDay.Person.UsualSchoolParcelId != Global.Settings.OutOfRegionParcelId)
            {
                schoolPclUniStu = Math.Log(1 + (personDay.Person.UsualSchoolParcel.StudentsUniversityBuffer2)) / 10;
                var schoolNestedAlternative = Global.ChoiceModelSession.Get <SchoolTourModeTimeModel>().RunNested(personDay, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualSchoolParcel, Global.Settings.Times.EightAM, Global.Settings.Times.TwoPM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers);
                schoolTourLogsum = schoolNestedAlternative == null ? 0 : schoolNestedAlternative.ComputeLogsum();
            }


            int countNonMandatory = (from personDayHH in orderedPersonDays where personDayHH.PatternType == 2 select personDayHH.PatternType).Count();

            bool schoolAvailableFlag = true;

            if (!personDay.Person.IsStudent || (!Global.Configuration.IsInEstimationMode && personDay.Person.UsualSchoolParcel == null))
            {
                schoolAvailableFlag = false;
            }

            // NONE_OR_HOME

            var alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.NoneOrHome, nCallsForTour > 1, choice == Global.Settings.Purposes.NoneOrHome);

            alternative.Choice = Global.Settings.Purposes.NoneOrHome;
            alternative.AddUtilityTerm(3, (nCallsForTour > 2).ToFlag());


            // USUAL WORK
            alternative        = choiceProbabilityCalculator.GetAlternative(1, (personDay.Person.UsualWorkParcelId > 0 && simulatedMandatoryTours[2] == 0 && simulatedMandatoryTours[3] == 0), choice == 1);
            alternative.Choice = 1;
            alternative.AddUtilityTerm(21, 1);
            alternative.AddUtilityTerm(23, workTourLogsum);
            alternative.AddUtilityTerm(25, (personDay.Person.IsPartTimeWorker).ToFlag());
            alternative.AddUtilityTerm(26, (personDay.Person.IsUniversityStudent).ToFlag());
            alternative.AddUtilityTerm(28, (personDay.Person.Household.Has100KPlusIncome).ToFlag());
            alternative.AddUtilityTerm(29, personDay.Person.Household.ResidenceParcel.MixedUse2Index1());
            alternative.AddUtilityTerm(30, (personDay.Person.Age <= 30).ToFlag());
            alternative.AddUtilityTerm(31, workPclWrkrs);
            alternative.AddUtilityTerm(32, ((simulatedMandatoryTours[1] > 0).ToFlag()));
            alternative.AddUtilityTerm(33, workIntrDens);
            alternative.AddUtilityTerm(36, (personDay.WorksAtHomeFlag));
            alternative.AddUtilityTerm(38, (personDay.Person.Household.ResidenceParcel.GetDistanceToTransit() > 1).ToFlag());

            // OTHER WORK
            alternative        = choiceProbabilityCalculator.GetAlternative(2, (personDay.Person.IsWorker && simulatedMandatoryTours[3] == 0), choice == 2);
            alternative.Choice = 2;
            alternative.AddUtilityTerm(41, 1);
            alternative.AddUtilityTerm(42, (personDay.Person.IsPartTimeWorker).ToFlag());
            alternative.AddUtilityTerm(43, (personDay.Person.IsUniversityStudent).ToFlag());
            alternative.AddUtilityTerm(45, personDay.Person.Household.ResidenceParcel.MixedUse2Index1());
            alternative.AddUtilityTerm(47, (personDay.Person.Age <= 30).ToFlag());
            alternative.AddUtilityTerm(48, noUsualWorkZone);
            alternative.AddUtilityTerm(49, workIntrDens);
            alternative.AddUtilityTerm(50, workPclWrkrs);
            alternative.AddUtilityTerm(51, countNonMandatory);
            alternative.AddUtilityTerm(52, ((simulatedMandatoryTours[2] > 0).ToFlag()));
            alternative.AddUtilityTerm(53, (household.HouseholdTotals.AllWorkers == 1).ToFlag());
            alternative.AddUtilityTerm(55, noCarsFlag + carCompetitionFlag);
            alternative.AddUtilityTerm(56, (personDay.Person.Household.ResidenceParcel.GetDistanceToTransit() > 1).ToFlag());
            alternative.AddUtilityTerm(57, (personDay.Person.Household.Has0To25KIncome).ToFlag());

            // SCHOOL
            alternative        = choiceProbabilityCalculator.GetAlternative(3, schoolAvailableFlag, choice == 3);
            alternative.Choice = 3;
            alternative.AddUtilityTerm(61, 1);
            alternative.AddUtilityTerm(62, schoolTourLogsum);
            alternative.AddUtilityTerm(63, noCarsFlag + carCompetitionFlag);
            alternative.AddUtilityTerm(64, personDay.Person.Household.ResidenceParcel.MixedUse2Index1());
            alternative.AddUtilityTerm(65, (personDay.Person.IsChildUnder5).ToFlag());
            alternative.AddUtilityTerm(66, (personDay.Person.IsUniversityStudent).ToFlag());
            alternative.AddUtilityTerm(67, (personDay.Person.IsDrivingAgeStudent).ToFlag());
            alternative.AddUtilityTerm(68, schoolPclUniStu);
            alternative.AddUtilityTerm(69, schoolPclStudents);
            alternative.AddUtilityTerm(71, ((simulatedMandatoryTours[3] > 0).ToFlag()));
            alternative.AddUtilityTerm(72, schoolIntrDens);
            alternative.AddUtilityTerm(73, (personDay.Person.Age > 25).ToFlag());
            alternative.AddUtilityTerm(74, (personDay.Person.Household.ResidenceParcel.GetDistanceToTransit() > 1).ToFlag());
        }
Пример #8
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, TourWrapper tour, HouseholdDayWrapper householdDay, int nCallsForTour, int choice = Constants.DEFAULT_VALUE)
        {
            PersonWrapper    person    = (PersonWrapper)tour.Person;
            PersonDayWrapper personDay = (PersonDayWrapper)tour.PersonDay;

            //			var foodRetailServiceMedicalQtrMileLog = tour.DestinationParcel.FoodRetailServiceMedicalQtrMileLogBuffer1();
            //			var mixedUseIndex = tour.DestinationParcel.MixedUse4Index1();
            double k8HighSchoolQtrMileLog = tour.DestinationParcel.K8HighSchoolQtrMileLogBuffer1();
            //var carOwnership = person.CarOwnershipSegment;
            int carOwnership = 0;

            int noCarsFlag         = FlagUtility.GetNoCarsFlag(carOwnership);
            int carCompetitionFlag = FlagUtility.GetCarCompetitionFlag(carOwnership);
            //			var notUsualWorkParcelFlag = tour.DestinationParcel.NotUsualWorkParcelFlag(person.UsualWorkParcelId);

            int votALSegment = tour.GetVotALSegment();

            int    workTaSegment       = tour.DestinationParcel.TransitAccessSegment();
            double workAggregateLogsum = Global.AggregateLogsums[tour.DestinationParcel.ZoneId][Global.Settings.Purposes.WorkBased][carOwnership][votALSegment][workTaSegment];

            //var compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][carOwnership][votALSegment][transitAccessSegment];
            //var compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.NoCars][votALSegment][transitAccessSegment];


            // NONE_OR_HOME

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

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

            alternative.AddUtilityTerm(1, (nCallsForTour > 1).ToFlag());

            //alternative.AddUtilityTerm(2, Math.Log(personDay.HomeBasedTours));

            //alternative.AddUtilityTerm(3, personDay.HasTwoOrMoreWorkTours.ToFlag());
            //alternative.AddUtility(4, notUsualWorkParcelFlag);

            //alternative.AddUtilityTerm(5, noCarsFlag);
            //alternative.AddUtilityTerm(6, carCompetitionFlag);

            //alternative.AddUtilityTerm(7, householdDay.PrimaryPriorityTimeFlag);

            //alternative.AddUtilityTerm(9, householdDay.Household.HasChildrenUnder5.ToFlag());
            //alternative.AddUtilityTerm(10, householdDay.Household.HasChildrenAge5Through15.ToFlag());

            //alternative.AddUtilityTerm(11, (householdDay.Household.Size == 2).ToFlag());
            //alternative.AddUtilityTerm(12, (householdDay.Household.Size == 2 && householdDay.AdultsInSharedHomeStay == 2).ToFlag());

            //alternative.AddUtilityTerm(14, personDay.Person.WorksAtHome().ToFlag());
            //alternative.AddUtilityTerm(15, personDay.Person.IsNonworkingAdult.ToFlag());

            //alternative.AddUtilityTerm(15, (person.IsNonworkingAdult).ToFlag()); //out of scope, non available

            //alternative.AddUtilityTerm(32, workAggregateLogsum);
            //alternative.AddUtility(32, mixedUseIndex);

            // WORK-BASED

            alternative = choiceProbabilityCalculator.GetAlternative(1, true, choice == Global.Settings.Purposes.PersonalBusiness);

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

            alternative.AddUtilityTerm(21, 1);

            //alternative.AddUtilityTerm(30, (person.IsWorker).ToFlag());

            //alternative.AddUtilityTerm(22, (person.FlexibleWorkHours == 1).ToFlag());
            //alternative.AddUtilityTerm(23, (person.EducationLevel >= 12).ToFlag());

            //alternative.AddUtilityTerm(24, personDay.Person.IsPartTimeWorker.ToFlag());

            //GV, 16. june 2016 - cannot be estimated
            //alternative.AddUtilityTerm(24, (person.WorksAtHome).ToFlag());
            ////alternative.AddUtilityTerm(25, personDay.Person.IsFulltimeWorker.ToFlag());
            //alternative.AddUtilityTerm(26, (person.MainOccupation == 50).ToFlag()); // self employed

            alternative.AddUtilityTerm(27, (personDay.Person.Gender == 1).ToFlag());
            //alternative.AddUtilityTerm(44, (hasAdultEducLevel12 == 1).ToFlag());

            //GV. 16. june 2016 - not signif.
            //alternative.AddUtilityTerm(28, (householdDay.Household.VehiclesAvailable == 1 && householdDay.Household.Has2Drivers).ToFlag());
            //alternative.AddUtilityTerm(29, (householdDay.Household.VehiclesAvailable >= 2 && householdDay.Household.Has2Drivers).ToFlag());

            alternative.AddUtilityTerm(30, householdDay.PrimaryPriorityTimeFlag);

            //GV. 16. june 2016 - not signif.
            //alternative.AddUtilityTerm(31, (householdDay.Household.Income >= 300000 && householdDay.Household.Income < 600000).ToFlag());
            //alternative.AddUtilityTerm(32, (householdDay.Household.Income >= 600000 && householdDay.Household.Income < 900000).ToFlag());
            //alternative.AddUtilityTerm(33, (householdDay.Household.Income >= 900000).ToFlag());

            alternative.AddUtilityTerm(41, workAggregateLogsum);

            //alternative.AddUtilityTerm(36, (householdDay.Household.Size == 2).ToFlag());
            //alternative.AddUtilityTerm(37, (householdDay.Household.Size == 3).ToFlag());
            //alternative.AddUtilityTerm(38, (householdDay.Household.Size >= 4).ToFlag());
        }
Пример #9
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, IPersonDayWrapper personDay, IHouseholdDayWrapper householdDay, int maxPurpose, int choice = Constants.DEFAULT_VALUE)
        {
            IEnumerable <PersonDayWrapper> orderedPersonDays = householdDay.PersonDays.OrderBy(p => p.GetJointTourParticipationPriority()).ToList().Cast <PersonDayWrapper>();

            IPersonWrapper    person          = personDay.Person;
            IHouseholdWrapper household       = householdDay.Household;
            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[] nonMandPerstype = new int[8];
            int[] mandPerstype    = new int[8];

            //int mandatoryAdult=0;
            //int mandatoryChild=0;
            //int nonMandatoryWorker=0;
            //int nonMandatoryNonWorker=0;
            //int nonMandatoryRetired=0;
            //int nonMandatoryChild=0;

            int countNonMandatory = 0;
            int countMandatory    = 0;

            double workLogsum   = 0;
            double schoolLogsum = 0;

            //int worksAtHome=0;
            int countWorkingAtHome = 0;

            int workDestinationArrivalTime   = 0;
            int workDestinationDepartureTime = 0;

            int numStopPurposes = 0;
            int numTourPurposes = 0;

            numTourPurposes = (personDay.CreatedEscortTours > 1).ToFlag() + (personDay.CreatedShoppingTours > 1).ToFlag() + (personDay.CreatedMealTours > 1).ToFlag() +
                              (personDay.CreatedPersonalBusinessTours > 1).ToFlag() + (personDay.CreatedSocialTours > 1).ToFlag() +
                              (personDay.CreatedRecreationTours > 1).ToFlag() + (personDay.CreatedMedicalTours > 1).ToFlag();


            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();


            if (person.UsualWorkParcel == null || person.UsualWorkParcelId == household.ResidenceParcelId)
            {
                workLogsum = 0;
            }
            else
            {
                workDestinationArrivalTime   = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.WorkTourModeModel);
                workDestinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.WorkTourModeModel);
                ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().RunNested(personDay, residenceParcel, person.UsualWorkParcel, workDestinationArrivalTime, workDestinationDepartureTime, household.VehiclesAvailable);

                workLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
            }

            if (person.UsualSchoolParcel == null || person.UsualSchoolParcelId == household.ResidenceParcelId)
            {
                schoolLogsum = 0;
            }
            else
            {
                int destinationArrivalTime   = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.SchoolTourModeModel);
                int destinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.SchoolTourModeModel);
                ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <SchoolTourModeTimeModel>().RunNested(personDay, residenceParcel, person.UsualSchoolParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable);

                schoolLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
            }

            //if (personDay.WorksAtHomeFlag == 1) {
            //    worksAtHome =1;
            //}


            int count = 0;

            foreach (PersonDayWrapper pDay in orderedPersonDays)
            {
                count++;
                if (count > 8)
                {
                    break;
                }
                if (pDay.WorksAtHomeFlag == 1)
                {
                    countWorkingAtHome++;
                }
                if (pDay.PatternType == 1)
                {
                    countMandatory++;
                }
                if (pDay.PatternType == 2)
                {
                    countNonMandatory++;
                }
            }


            // 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(2, (personDay.GetTotalCreatedTours()== 2).ToFlag());
            //alternative.AddUtilityTerm(3,  (personDay.GetTotalCreatedTours()==3).ToFlag());
            alternative.AddUtilityTerm(4, (personDay.GetTotalCreatedTours() >= 4).ToFlag());
            alternative.AddUtilityTerm(5, (numStopPurposes >= 1).ToFlag());
            alternative.AddUtilityTerm(6, (numTourPurposes >= 2).ToFlag());
            alternative.AddUtilityTerm(7, personDay.CreatedWorkTours + personDay.CreatedSchoolTours);
            alternative.AddUtilityTerm(8, (personDay.JointTours));
            alternative.AddUtilityTerm(9, Math.Log(1 + (workDestinationDepartureTime - workDestinationArrivalTime) / 60));
            //alternative.AddUtilityTerm(10,  (household.Size==1).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(198, 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(199, 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(11, 1);
            alternative.AddUtilityTerm(12, (personDay.PatternType == 2).ToFlag());
            alternative.AddUtilityTerm(13, personDay.JointTours);
            alternative.AddUtilityTerm(14, (personDay.EscortStops > 0).ToFlag());
            alternative.AddUtilityTerm(15, (personDay.CreatedEscortTours > 1).ToFlag());
            alternative.AddUtilityTerm(17, (household.HouseholdType == Global.Settings.HouseholdTypes.TwoPlusWorkerStudentAdultsWithChildren).ToFlag() + (
                                           household.HouseholdType == Global.Settings.HouseholdTypes.TwoPlusAdultsOnePlusWorkersStudentsWithChildren).ToFlag());
            alternative.AddUtilityTerm(20, (household.HouseholdType == Global.Settings.HouseholdTypes.OneAdultWithChildren).ToFlag());
            alternative.AddUtilityTerm(25, (person.PersonType == Global.Settings.PersonTypes.PartTimeWorker).ToFlag());
            alternative.AddUtilityTerm(28, (person.PersonType == Global.Settings.PersonTypes.ChildUnder5).ToFlag());
            alternative.AddUtilityTerm(29, (person.PersonType == Global.Settings.PersonTypes.ChildAge5Through15).ToFlag());
            alternative.AddUtilityTerm(31, (person.PersonType == Global.Settings.PersonTypes.UniversityStudent).ToFlag());
            alternative.AddUtilityTerm(32, countMandatory);
            // alternative.AddUtilityTerm(33, personDay.CreatedWorkTours);

            //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(41, 1);
            alternative.AddUtilityTerm(42, (personDay.PatternType == 2).ToFlag());
            alternative.AddUtilityTerm(43, (personDay.PersonalBusinessStops > 0).ToFlag());
            alternative.AddUtilityTerm(44, personalBusinessAggregateLogsum);
            alternative.AddUtilityTerm(45, (household.HouseholdType == Global.Settings.HouseholdTypes.IndividualWorkerStudent).ToFlag());
            alternative.AddUtilityTerm(46, (household.HouseholdType == Global.Settings.HouseholdTypes.IndividualNonworkerNonstudent).ToFlag());
            alternative.AddUtilityTerm(47, (personDay.CreatedWorkTours + personDay.CreatedSchoolTours));


            // 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(61, 1);
            alternative.AddUtilityTerm(52, (personDay.PatternType == 2).ToFlag());
            alternative.AddUtilityTerm(54, (personDay.ShoppingStops > 0).ToFlag());
            //alternative.AddUtilityTerm(55, Math.Log(1+person.Household.ResidenceParcel.EmploymentRetailBuffer2));
            alternative.AddUtilityTerm(56, shoppingAggregateLogsum);
            alternative.AddUtilityTerm(57, (person.PersonType == Global.Settings.PersonTypes.RetiredAdult).ToFlag());
            alternative.AddUtilityTerm(58, (household.HouseholdType == Global.Settings.HouseholdTypes.OnePlusWorkerStudentAdultsAndOnePlusNonworkerNonstudentAdultsWithoutChildren).ToFlag());
            alternative.AddUtilityTerm(60, (household.HouseholdType == Global.Settings.HouseholdTypes.IndividualWorkerStudent).ToFlag());
            alternative.AddUtilityTerm(69, (person.PersonType == Global.Settings.PersonTypes.UniversityStudent).ToFlag());
            alternative.AddUtilityTerm(70, (household.Has100KPlusIncome).ToFlag());

            // MEAL
            alternative        = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Meal, maxPurpose <= Global.Settings.Purposes.Meal && personDay.CreatedMealTours > 0, choice == Global.Settings.Purposes.Meal);
            alternative.Choice = Global.Settings.Purposes.Meal;
            alternative.AddUtilityTerm(71, 1);
            alternative.AddUtilityTerm(72, (personDay.PatternType == 2).ToFlag());
            alternative.AddUtilityTerm(74, mealAggregateLogsum);
            alternative.AddUtilityTerm(80, (household.HouseholdType == Global.Settings.HouseholdTypes.IndividualWorkerStudent).ToFlag());
            alternative.AddUtilityTerm(82, (household.HouseholdType == Global.Settings.HouseholdTypes.TwoPlusNonworkerNonstudentAdultsWithoutChildren).ToFlag());
            alternative.AddUtilityTerm(85, (person.PersonType == Global.Settings.PersonTypes.RetiredAdult).ToFlag());

            // 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(111, 1);
            alternative.AddUtilityTerm(112, (personDay.PatternType == 2).ToFlag());
            alternative.AddUtilityTerm(113, household.HouseholdTotals.ChildrenUnder16);
            //alternative.AddUtilityTerm(114, socialAggregateLogsum);
            alternative.AddUtilityTerm(115, Math.Log(1 + person.Household.ResidenceParcel.HouseholdsBuffer2));
            alternative.AddUtilityTerm(122, (household.HouseholdType == Global.Settings.HouseholdTypes.TwoPlusNonworkerNonstudentAdultsWithoutChildren).ToFlag());
            alternative.AddUtilityTerm(123, (person.PersonType == Global.Settings.PersonTypes.PartTimeWorker).ToFlag());
            alternative.AddUtilityTerm(126, (person.PersonType == Global.Settings.PersonTypes.ChildUnder5).ToFlag());
            alternative.AddUtilityTerm(127, (person.PersonType == Global.Settings.PersonTypes.ChildAge5Through15).ToFlag());
            alternative.AddUtilityTerm(130, (person.PersonType == Global.Settings.PersonTypes.RetiredAdult).ToFlag());

            // RECREATION
            alternative        = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Recreation, maxPurpose <= Global.Settings.Purposes.Recreation && personDay.CreatedRecreationTours > 0, choice == Global.Settings.Purposes.Recreation);
            alternative.Choice = Global.Settings.Purposes.Recreation;
            alternative.AddUtilityTerm(111, 1);
            alternative.AddUtilityTerm(112, (personDay.PatternType == 2).ToFlag());
            alternative.AddUtilityTerm(113, household.HouseholdTotals.ChildrenUnder16);
            //alternative.AddUtilityTerm(114, totalAggregateLogsum);
            alternative.AddUtilityTerm(115, Math.Log(1 + person.Household.ResidenceParcel.HouseholdsBuffer2));
            alternative.AddUtilityTerm(122, (household.HouseholdType == Global.Settings.HouseholdTypes.TwoPlusNonworkerNonstudentAdultsWithoutChildren).ToFlag());
            alternative.AddUtilityTerm(123, (person.PersonType == Global.Settings.PersonTypes.PartTimeWorker).ToFlag());
            alternative.AddUtilityTerm(126, (person.PersonType == Global.Settings.PersonTypes.ChildUnder5).ToFlag());
            alternative.AddUtilityTerm(127, (person.PersonType == Global.Settings.PersonTypes.ChildAge5Through15).ToFlag());
            alternative.AddUtilityTerm(128, (household.Has100KPlusIncome).ToFlag());

            // MEDICAL
            alternative        = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Medical, maxPurpose <= Global.Settings.Purposes.Medical && personDay.CreatedMedicalTours > 0, choice == Global.Settings.Purposes.Medical);
            alternative.Choice = Global.Settings.Purposes.Medical;
            alternative.AddUtilityTerm(131, 1);
            alternative.AddUtilityTerm(132, Math.Log(1 + household.ResidenceParcel.EmploymentMedicalBuffer2));
            alternative.AddUtilityTerm(133, (person.PersonType == Global.Settings.PersonTypes.RetiredAdult).ToFlag());
            //alternative.AddNestedAlternative(11, 1, 60);
        }
Пример #10
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());
        }
Пример #11
0
        private double[][][][] ComputeZone(IRandomUtility randomUtility, int id)
        {
            var purposes = new double[Global.Settings.Purposes.TotalPurposes][][][];

            for (var purpose = Global.Settings.Purposes.HomeBasedComposite; purpose <= Global.Settings.Purposes.Social; purpose++)
            {
                var carOwnerships = new double[Global.Settings.CarOwnerships.TotalCarOwnerships][][];

                purposes[purpose] = carOwnerships;

                for (var carOwnership = Global.Settings.CarOwnerships.Child; carOwnership < Global.Settings.CarOwnerships.TotalCarOwnerships; carOwnership++)
                {
                    var votALSegments = new double[Global.Settings.VotALSegments.TotalVotALSegments][];

                    carOwnerships[carOwnership] = votALSegments;

                    for (var votALSegment = Global.Settings.VotALSegments.Low; votALSegment < Global.Settings.VotALSegments.TotalVotALSegments; votALSegment++)
                    {
                        var transitAccesses = new double[Global.Settings.TransitAccesses.TotalTransitAccesses];

                        votALSegments[votALSegment] = transitAccesses;

                        for (var transitAccess = Global.Settings.TransitAccesses.Gt0AndLteQtrMi; transitAccess < Global.Settings.TransitAccesses.TotalTransitAccesses; transitAccess++)
                        {
                            transitAccesses[transitAccess] = Constants.EPSILON;
                        }
                    }
                }
            }

            IZone origin;

            if (!_eligibleZones.TryGetValue(id, out origin))
            {
                return(purposes);
            }

            foreach (var destination in _eligibleZones.Values)
            {
                var setImpedance = true;
                var subzones     = _zoneSubzones[destination.Id];

                //const double parkingCost = 0;

                // mode impedance
                var sovInVehicleTimeFromOrigin  = ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, _middayStartMinute, id, destination.Id).Variable;
                var scaledSovDistanceFromOrigin = 0D;
                var transitGenTime = 0D;
                var walkGenTime    = 0D;
                var sovGenTime     = 0D;
                var hov2GenTime    = 0D;

                for (var purpose = Global.Settings.Purposes.HomeBasedComposite; purpose <= Global.Settings.Purposes.Social; purpose++)
                {
                    var carOwnerships      = purposes[purpose];
                    var distanceParameters = _distanceParameters[purpose];

                    // set purpose inputs
                    var escortFlag           = (purpose == Global.Settings.Purposes.Escort).ToFlag();
                    var personalBusinessFlag = (purpose == Global.Settings.Purposes.PersonalBusiness).ToFlag();
                    var shoppingFlag         = (purpose == Global.Settings.Purposes.Shopping).ToFlag();
                    var mealFlag             = (purpose == Global.Settings.Purposes.Meal).ToFlag();
                    var socialFlag           = (purpose == Global.Settings.Purposes.Social).ToFlag();

                    var p01 = _p01[purpose];
                    var p02 = _p02[purpose];
                    var p03 = _p03[purpose];
                    var p11 = _p11[purpose];
                    var p14 = _p14[purpose];
                    var p21 = _p21[purpose];
                    var p22 = _p22[purpose];
                    var p23 = _p23[purpose];
                    var p24 = _p24[purpose];
                    var p31 = _p31[purpose];
                    var p32 = _p32[purpose];
                    var p33 = _p33[purpose];
                    var p34 = _p34[purpose];
                    var p37 = _p37[purpose];

                    for (var carOwnership = Global.Settings.CarOwnerships.Child; carOwnership < Global.Settings.CarOwnerships.TotalCarOwnerships; carOwnership++)
                    {
                        var votALSegments = carOwnerships[carOwnership];

                        // set car ownership inputs
                        var childFlag            = FlagUtility.GetChildFlag(carOwnership);
                        var noCarsFlag           = FlagUtility.GetNoCarsFlag(carOwnership);
                        var carCompetitionFlag   = FlagUtility.GetCarCompetitionFlag(carOwnership);
                        var noCarCompetitionFlag = FlagUtility.GetNoCarCompetitionFlag(carOwnership);
                        var carDeficitFlag       = FlagUtility.GetCarDeficitFlag(carOwnership);

                        var distanceParameter = distanceParameters[carOwnership][1] / 100D; // converts hundreths of minutes to minutes

                        for (var votALSegment = Global.Settings.VotALSegments.Low; votALSegment < Global.Settings.VotALSegments.TotalVotALSegments; votALSegment++)
                        {
                            var transitAccesses = votALSegments[votALSegment];

                            // set vot specific variables
                            double timeCoefficient = Global.Settings.VotALSegments.TimeCoefficient;
                            var    costCoefficient = (votALSegment == Global.Settings.VotALSegments.Low)
                                                      ? Global.Settings.VotALSegments.CostCoefficientLow
                                                      : (votALSegment == Global.Settings.VotALSegments.Medium)
                                                            ? Global.Settings.VotALSegments.CostCoefficientMedium
                                                            : Global.Settings.VotALSegments.CostCoefficientHigh;

                            for (var transitAccess = Global.Settings.TransitAccesses.Gt0AndLteQtrMi; transitAccess < Global.Settings.TransitAccesses.TotalTransitAccesses; transitAccess++)
                            {
                                var purposeUtility = 0D;

                                // set transit access flags
                                var hasNearTransitAccessFlag = (transitAccess == Global.Settings.TransitAccesses.Gt0AndLteQtrMi).ToFlag();
                                var hasNoTransitAccessFlag   = (transitAccess == Global.Settings.TransitAccesses.None).ToFlag();

                                foreach (var subzone in subzones)
                                {
                                    var size = subzone.GetSize(purpose);

                                    if (size <= -50 || sovInVehicleTimeFromOrigin <= 0 || (2 * sovInVehicleTimeFromOrigin) > distanceParameter)
                                    {
                                        continue;
                                    }

                                    // set subzone flags
                                    var hasNoTransitEgressFlag = 1 - (subzone.Sequence == 0 ? 1 : 0);

                                    if (setImpedance)
                                    {
                                        setImpedance = false;

                                        // intermediate variable of type IEnumerable<IPathTypeModel> is needed to acquire First() method as extension
                                        IEnumerable <IPathTypeModel> pathTypeModels;

                                        pathTypeModels = PathTypeModelFactory.Singleton.Run(randomUtility, id, destination.Id, _middayStartMinute, _middayStartMinute, Global.Settings.Purposes.PersonalBusiness,
                                                                                            costCoefficient, timeCoefficient, true, 1, false, 0.0, false, Global.Settings.Modes.Walk);
                                        var walkPath = pathTypeModels.First();

                                        walkGenTime = walkPath.GeneralizedTimeLogsum;


                                        pathTypeModels = PathTypeModelFactory.Singleton.Run(randomUtility, id, destination.Id, _middayStartMinute, _middayStartMinute, Global.Settings.Purposes.PersonalBusiness,
                                                                                            costCoefficient, timeCoefficient, true, 1, false, 0.0, false, Global.Settings.Modes.Sov);
                                        var sovPath = pathTypeModels.First();

                                        var sovDistanceFromOrigin = (sovPath.PathDistance / Global.Settings.DistanceUnitsPerMile) / 2D;
                                        scaledSovDistanceFromOrigin = sovDistanceFromOrigin / 10D;

                                        sovGenTime = sovPath.GeneralizedTimeLogsum;

                                        pathTypeModels = PathTypeModelFactory.Singleton.Run(randomUtility, id, destination.Id, _middayStartMinute, _middayStartMinute, Global.Settings.Purposes.PersonalBusiness,
                                                                                            costCoefficient, timeCoefficient, true, 1, false, 0.0, false, Global.Settings.Modes.Hov2);
                                        var hov2Path = pathTypeModels.First();

                                        hov2GenTime = hov2Path.GeneralizedTimeLogsum;

                                        //if using stop areas, use stop area nearest to the zone centroid
                                        var transitOid = (!Global.StopAreaIsEnabled) ? id
                                                                : (origin.NearestStopAreaId > 0) ? Global.TransitStopAreaMapping[origin.NearestStopAreaId]
                                                                : id;
                                        var transitDid = (!Global.StopAreaIsEnabled) ? destination.Id
                                            : (destination.NearestStopAreaId > 0) ? Global.TransitStopAreaMapping[destination.NearestStopAreaId]
                                            : id;

                                        pathTypeModels = PathTypeModelFactory.Singleton.Run(randomUtility, transitOid, transitDid, _middayStartMinute, _middayStartMinute, Global.Settings.Purposes.PersonalBusiness,
                                                                                            costCoefficient, timeCoefficient, true, 1, false, Global.Configuration.Policy_UniversalTransitFareDiscountFraction, false, Global.Settings.Modes.Transit);
                                        var transitPath = pathTypeModels.First();

                                        transitGenTime = transitPath.GeneralizedTimeLogsum;
                                    }

                                    var modeUtilitySum = 0D;

                                    // SOV
                                    if (childFlag == 0 && noCarsFlag == 0 && sovGenTime != Global.Settings.GeneralizedTimeUnavailable)
                                    {
                                        modeUtilitySum += ComputeUtility(
                                            //p01 * (OPERATING_COST_PER_MILE * sovDistance + sovToll) +
                                            //p01 * parkingCost +
                                            //p02 * sovInVehicleTime +
                                            timeCoefficient * sovGenTime +
                                            p11 +
                                            p14 * carCompetitionFlag);
                                    }

                                    // HOV
                                    if (hov2GenTime != Global.Settings.GeneralizedTimeUnavailable)
                                    {
                                        modeUtilitySum += ComputeUtility(
                                            //p01 * ((OPERATING_COST_PER_MILE * hov2Distance + hov2Toll) / CP_FACTOR) +
                                            //p01 * parkingCost / CP_FACTOR +
                                            //p02 * hov2InVehicleTime +
                                            timeCoefficient * hov2GenTime +
                                            p21 +
                                            p22 * childFlag +
                                            p23 * noCarsFlag +
                                            p24 * carCompetitionFlag);
                                    }

                                    // TRANSIT
                                    if (transitGenTime != Global.Settings.GeneralizedTimeUnavailable && hasNoTransitAccessFlag == 0 && hasNoTransitEgressFlag == 0)
                                    {
                                        modeUtilitySum += ComputeUtility(
                                            //p01 * transitFare +
                                            //p02 * transitInVehicleTime +
                                            //p03 * transitInitialWaitTime +
                                            //p03 * transitNumberOfBoards +
                                            timeCoefficient * transitGenTime +
                                            p31 +
                                            p32 * childFlag +
                                            p33 * noCarsFlag +
                                            p34 * carCompetitionFlag +
                                            p37 * hasNoTransitAccessFlag);
                                    }

                                    // WALK
                                    if (walkGenTime != Global.Settings.GeneralizedTimeUnavailable)
                                    {
                                        modeUtilitySum += ComputeUtility(
                                            //p03 * walkDistance * 20);
                                            timeCoefficient * walkGenTime);
                                    }

                                    var modeLogsum = modeUtilitySum > Constants.EPSILON ? Math.Log(modeUtilitySum) : -30D;

                                    switch (purpose)
                                    {
                                    case 1:     // HOME_BASED_COMPOSITE
                                        purposeUtility += ComputeUtility(
                                            size +
                                            HBB002 * modeLogsum +
                                            HBB003 * modeLogsum * noCarsFlag +
                                            HBB007 * modeLogsum * (noCarsFlag + carCompetitionFlag) * hasNoTransitAccessFlag +
                                            HBB008 * modeLogsum * noCarCompetitionFlag * hasNoTransitAccessFlag +
                                            HBB012 * subzone.MixedUseMeasure * carCompetitionFlag +
                                            HBB013 * subzone.MixedUseMeasure * noCarCompetitionFlag +
                                            HBB014 * subzone.MixedUseMeasure * childFlag +
                                            HBB016 * scaledSovDistanceFromOrigin * noCarsFlag +
                                            HBB018 * scaledSovDistanceFromOrigin * childFlag);

                                        break;

                                    case 2:     // WORK_BASED
                                        purposeUtility += ComputeUtility(
                                            size +
                                            WBB002 * modeLogsum +
                                            WBB011 * modeLogsum * noCarCompetitionFlag * hasNearTransitAccessFlag +
                                            WBB012 * subzone.MixedUseMeasure * carCompetitionFlag +
                                            WBB013 * subzone.MixedUseMeasure * noCarCompetitionFlag +
                                            WBB015 * scaledSovDistanceFromOrigin);

                                        break;

                                    default:     // ESCORT, PERSONAL_BUSINESS, SHOPPING, MEAL, SOCIAL or RECREATION
                                        purposeUtility += ComputeUtility(
                                            size +
                                            PSB006 * escortFlag * modeLogsum +
                                            PSB007 * noCarsFlag * modeLogsum +
                                            PSB008 * escortFlag * carDeficitFlag * modeLogsum +
                                            PSB009 * escortFlag * childFlag * modeLogsum +
                                            PSB011 * escortFlag * carDeficitFlag * hasNoTransitAccessFlag * modeLogsum +
                                            PSB012 * escortFlag * noCarCompetitionFlag * hasNoTransitAccessFlag * modeLogsum +
                                            PSB014 * carDeficitFlag * hasNearTransitAccessFlag * modeLogsum +
                                            PSB016 * escortFlag * scaledSovDistanceFromOrigin +
                                            PSB017 * noCarsFlag * scaledSovDistanceFromOrigin +
                                            PSB018 * escortFlag * carDeficitFlag * scaledSovDistanceFromOrigin +
                                            PSB020 * escortFlag * carCompetitionFlag * subzone.MixedUseMeasure +
                                            PSB021 * escortFlag * noCarCompetitionFlag * subzone.MixedUseMeasure +
                                            PSB022 * escortFlag * childFlag * subzone.MixedUseMeasure +
                                            PSB023 * personalBusinessFlag * modeLogsum +
                                            PSB024 * personalBusinessFlag * carDeficitFlag * modeLogsum +
                                            PSB025 * personalBusinessFlag * childFlag * modeLogsum +
                                            PSB027 * personalBusinessFlag * noCarCompetitionFlag * hasNoTransitAccessFlag * modeLogsum +
                                            PSB029 * personalBusinessFlag * carDeficitFlag * scaledSovDistanceFromOrigin +
                                            PSB030 * personalBusinessFlag * childFlag * scaledSovDistanceFromOrigin +
                                            PSB031 * personalBusinessFlag * carCompetitionFlag * subzone.MixedUseMeasure +
                                            PSB032 * personalBusinessFlag * noCarCompetitionFlag * subzone.MixedUseMeasure +
                                            PSB033 * personalBusinessFlag * childFlag * subzone.MixedUseMeasure +
                                            PSB034 * shoppingFlag * modeLogsum +
                                            PSB035 * shoppingFlag * carDeficitFlag * modeLogsum +
                                            PSB036 * shoppingFlag * childFlag * modeLogsum +
                                            PSB037 * shoppingFlag * carDeficitFlag * hasNoTransitAccessFlag * modeLogsum +
                                            PSB038 * shoppingFlag * noCarCompetitionFlag * hasNoTransitAccessFlag * modeLogsum +
                                            PSB045 * mealFlag * modeLogsum +
                                            PSB047 * mealFlag * childFlag * modeLogsum +
                                            PSB049 * mealFlag * noCarCompetitionFlag * hasNoTransitAccessFlag * modeLogsum +
                                            PSB053 * mealFlag * carCompetitionFlag * subzone.MixedUseMeasure +
                                            PSB054 * mealFlag * noCarCompetitionFlag * subzone.MixedUseMeasure +
                                            PSB055 * mealFlag * childFlag * subzone.MixedUseMeasure +
                                            PSB056 * socialFlag * modeLogsum +
                                            PSB057 * socialFlag * carDeficitFlag * modeLogsum +
                                            PSB059 * socialFlag * carDeficitFlag * hasNoTransitAccessFlag * modeLogsum +
                                            PSB060 * socialFlag * noCarCompetitionFlag * hasNoTransitAccessFlag * modeLogsum +
                                            PSB063 * socialFlag * childFlag * scaledSovDistanceFromOrigin +
                                            PSB064 * socialFlag * carCompetitionFlag * subzone.MixedUseMeasure +
                                            PSB065 * socialFlag * noCarCompetitionFlag * subzone.MixedUseMeasure +
                                            PSB066 * socialFlag * childFlag * subzone.MixedUseMeasure);

                                        break;
                                    }
                                }

                                transitAccesses[transitAccess] += purposeUtility;
                            }
                        }
                    }
                }
            }

            return(purposes);
        }
Пример #12
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, HouseholdDayWrapper householdDay, int choice = Constants.DEFAULT_VALUE)
        {
            var household       = householdDay.Household;
            var residenceParcel = household.ResidenceParcel;

            // set household characteristics here that don't depend on person characteristics

            int hasAdultEducLevel12 = 0;
            int allAdultEducLevel12 = 1;
            int youngestAge         = 999;


            double firstWorkLogsum       = 0;
            double secondWorkLogsum      = 0;
            bool   firstWorkLogsumIsSet  = false;
            bool   secondWorkLogsumIsSet = false;
            int    numberWorkers         = 0;
            int    numberAdults          = 0;
            int    numberChildren        = 0;
            int    numberChildrenUnder5  = 0;


            // set characteristics here that depend on person characteristics
            foreach (PersonDayWrapper personDay in householdDay.PersonDays)
            {
                double workLogsum = 0;
                var    person     = (PersonWrapper)personDay.Person;
                if (person.UsualWorkParcel == null || person.UsualWorkParcelId == household.ResidenceParcelId ||
                    (person.PersonType != Global.Settings.PersonTypes.FullTimeWorker &&
                     person.PersonType != Global.Settings.PersonTypes.PartTimeWorker))
                //    || household.VehiclesAvailable == 0)
                {
                }
                else
                {
                    var destinationArrivalTime   = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.WorkTourModeModel);
                    var destinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.WorkTourModeModel);
                    //JLB 201406
                    //var nestedAlternative = Global.ChoiceModelSession.Get<WorkTourModeModel>().RunNested(personDay, residenceParcel, person.UsualWorkParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable);
                    var nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().RunNested(personDay, residenceParcel, person.UsualWorkParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable);
                    workLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                }
                if (person.Age >= 18 && person.EducationLevel >= 12)
                {
                    hasAdultEducLevel12 = 1;
                }
                if (person.Age >= 18 && person.EducationLevel < 12)
                {
                    allAdultEducLevel12 = 0;
                }
                if (person.Age < youngestAge)
                {
                    youngestAge = person.Age;
                }
                if (workLogsum != 0 && !firstWorkLogsumIsSet)
                {
                    firstWorkLogsum      = workLogsum;
                    firstWorkLogsumIsSet = true;
                }
                else if (workLogsum != 0 && !secondWorkLogsumIsSet)
                {
                    secondWorkLogsum      = workLogsum;
                    secondWorkLogsumIsSet = true;
                }
                if (person.Age >= 18)
                {
                    numberAdults++;
                    if (person.PersonType == Global.Settings.PersonTypes.FullTimeWorker
                        //|| person.PersonType == Constants.PersonType.PART_TIME_WORKER
                        )
                    {
                        numberWorkers++;
                    }
                }
                else
                {
                    numberChildren++;
                    if (person.PersonType == Global.Settings.PersonTypes.ChildUnder5)
                    {
                        numberChildrenUnder5++;
                    }
                }
            }
            var singleWorkerWithChildUnder5 = (numberAdults == numberWorkers && numberAdults == 1 &&
                                               numberChildrenUnder5 > 0) ? true : false;
            var workingCoupleNoChildren = (numberAdults == numberWorkers && numberAdults == 2 &&
                                           numberChildren == 0) ? true : false;
            var workingCoupleAllChildrenUnder5 = (numberAdults == numberWorkers && numberAdults == 2 &&
                                                  numberChildren > 0 && numberChildren == numberChildrenUnder5) ? true : false;
            var otherHouseholdWithPTFTWorkers = false;

            if (!workingCoupleNoChildren && !workingCoupleAllChildrenUnder5 && firstWorkLogsum != 0)
            {
                otherHouseholdWithPTFTWorkers = true;
            }
            var nonWorkingHousehold = false;

            if (!workingCoupleNoChildren && !workingCoupleAllChildrenUnder5 && !otherHouseholdWithPTFTWorkers)
            {
                nonWorkingHousehold = true;
            }


            // var votSegment = household.VotALSegment;
            //var taSegment = household.ResidenceParcel.TransitAccessSegment();

            //var aggregateLogsumDifference = // full car ownership vs. no car ownership
            //    Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.OneOrMoreCarsPerAdult][votSegment][taSegment] -
            //    Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.NoCars][votSegment][taSegment];


            //var householdDay = (ActumHouseholdDayWrapper)tour.HouseholdDay;

            var carOwnership =
                household.VehiclesAvailable == 0
                                 ? Global.Settings.CarOwnerships.NoCars
                                 : household.VehiclesAvailable < household.HouseholdTotals.DrivingAgeMembers
                                      ? Global.Settings.CarOwnerships.LtOneCarPerAdult
                                      : Global.Settings.CarOwnerships.OneOrMoreCarsPerAdult;

            var noCarsFlag         = FlagUtility.GetNoCarsFlag(carOwnership);
            var carCompetitionFlag = FlagUtility.GetCarCompetitionFlag(carOwnership);

            var votALSegment                    = Global.Settings.VotALSegments.Medium; // TODO:  calculate a VOT segment that depends on household income
            var transitAccessSegment            = household.ResidenceParcel.TransitAccessSegment();
            var personalBusinessAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                                  [Global.Settings.Purposes.PersonalBusiness][carOwnership][votALSegment][transitAccessSegment];
            var shoppingAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                          [Global.Settings.Purposes.Shopping][carOwnership][votALSegment][transitAccessSegment];
            var mealAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                      [Global.Settings.Purposes.Meal][carOwnership][votALSegment][transitAccessSegment];
            var socialAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                        [Global.Settings.Purposes.Social][carOwnership][votALSegment][transitAccessSegment];
            //var compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][carOwnership][votALSegment][transitAccessSegment];
            var compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.NoCars][votALSegment][transitAccessSegment];

            var componentIndex = 0;

            for (int pfpt = 0; pfpt < 2; pfpt++)
            {
                if (pfpt == 1)
                {
                    componentIndex = 1;
                    choiceProbabilityCalculator.CreateUtilityComponent(componentIndex);
                    var pfptComponent = choiceProbabilityCalculator.GetUtilityComponent(componentIndex);
                    pfptComponent.AddUtilityTerm(1, (householdDay.Household.Size == 3).ToFlag());
                    pfptComponent.AddUtilityTerm(2, (householdDay.Household.Size >= 4).ToFlag());
                    pfptComponent.AddUtilityTerm(3, householdDay.Household.HasChildrenUnder5.ToFlag());
                    pfptComponent.AddUtilityTerm(4, (householdDay.AdultsInSharedHomeStay == 1 && householdDay.Household.HasChildrenAge5Through15).ToFlag());
                    pfptComponent.AddUtilityTerm(5, (householdDay.AdultsInSharedHomeStay == 2 && householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag());
                    pfptComponent.AddUtilityTerm(6, (householdDay.AdultsInSharedHomeStay == 2 && hasAdultEducLevel12 == 1).ToFlag());
                    pfptComponent.AddUtilityTerm(7, (householdDay.Household.VehiclesAvailable == 1 && household.Has2Drivers).ToFlag());
                    pfptComponent.AddUtilityTerm(8, (householdDay.Household.VehiclesAvailable >= 2 && household.Has2Drivers).ToFlag());
                    //pfptComponent.AddUtilityTerm(29, (householdDay.Household.Income >= 300000 && householdDay.Household.Income < 600000).ToFlag());
                    //pfptComponent.AddUtilityTerm(30, (householdDay.Household.Income >= 600000 && householdDay.Household.Income < 900000).ToFlag());
                    //pfptComponent.AddUtilityTerm(31, (householdDay.Household.Income >= 900000).ToFlag());
                    pfptComponent.AddUtilityTerm(9, (firstWorkLogsum + secondWorkLogsum) * (workingCoupleNoChildren || workingCoupleAllChildrenUnder5).ToFlag());
                    pfptComponent.AddUtilityTerm(9, (firstWorkLogsum + secondWorkLogsum) * otherHouseholdWithPTFTWorkers.ToFlag());
                    pfptComponent.AddUtilityTerm(10, compositeLogsum);
                }
            }
            for (var jointTourFlag = 0; jointTourFlag < 2; jointTourFlag++)
            {
                if (jointTourFlag == 1)
                {
                    componentIndex = 2;
                    choiceProbabilityCalculator.CreateUtilityComponent(componentIndex);
                    var jointComponent = choiceProbabilityCalculator.GetUtilityComponent(componentIndex);
                    jointComponent.AddUtilityTerm(21, householdDay.Household.HasChildrenUnder5.ToFlag());
                    jointComponent.AddUtilityTerm(22, householdDay.Household.HasChildrenAge5Through15.ToFlag());
                    jointComponent.AddUtilityTerm(23, (youngestAge >= 40).ToFlag());
                    //noJointComponent.AddUtilityTerm(50, (householdDay.Household.Income >= 300000 && householdDay.Household.Income < 600000).ToFlag());
                    //noJointComponent.AddUtilityTerm(51, (householdDay.Household.Income >= 600000 && householdDay.Household.Income < 900000).ToFlag());
                    //noJointComponent.AddUtilityTerm(52, (householdDay.Household.Income >= 900000).ToFlag());
                    jointComponent.AddUtilityTerm(24, compositeLogsum);
                }
            }

            var available = true;

            for (int pfpt = 0; pfpt < 2; pfpt++)
            {
                for (var jointTourFlag = 0; jointTourFlag < 2; jointTourFlag++)
                {
                    var altIndex = pfpt + jointTourFlag * 2;
                    if (household.Size < 2 && altIndex > 0)
                    {
                        available = false;
                    }
                    else
                    {
                        available = true;
                    }
                    var alternative = choiceProbabilityCalculator.GetAlternative(altIndex, available, choice != null && choice == altIndex);

                    alternative.Choice = altIndex;

                    //NESTING WAS REJECTED BY TESTS
                    //alternative.AddNestedAlternative(5 + pfpt,          pfpt, THETA_PARAMETER);  // pfpt on top
                    //alternative.AddNestedAlternative(5 + jointTourFlag, jointTourFlag, THETA_PARAMETER); //jointTourFlag on top

                    if (pfpt == 1)
                    {
                        alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(1));
                        //alternative.AddUtilityTerm(20, 1);
                    }
                    if (jointTourFlag == 0)
                    {
                        alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(2));
                        //alternative.AddUtilityTerm(40, 1);
                    }

                    if (pfpt == 0 && jointTourFlag == 0)
                    {
                    }
                    else if (pfpt == 1 && jointTourFlag == 0)
                    {
                        alternative.AddUtilityTerm(51, 1);
                    }
                    else if (pfpt == 0 && jointTourFlag == 1)
                    {
                        alternative.AddUtilityTerm(61, 1);
                    }
                    else if (pfpt == 1 && jointTourFlag == 1)
                    {
                        alternative.AddUtilityTerm(71, 1);
                        //alternative.AddUtilityTerm(72, (householdDay.Household.Size == 2 && householdDay.AdultsInSharedHomeStay == 2).ToFlag());
                        //alternative.AddUtilityTerm(73, (householdDay.AdultsInSharedHomeStay == 1 && householdDay.Household.HasChildrenUnder16).ToFlag());
                        //alternative.AddUtilityTerm(74, (householdDay.AdultsInSharedHomeStay == 2 && householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag());
                        //alternative.AddUtilityTerm(75, (householdDay.AdultsInSharedHomeStay == 2 && hasAdultEducLevel12 == 1).ToFlag());
                    }
                }
            }
        }
Пример #13
0
            public void SetUtilities(ISampleItem sampleItem, int sampleFrequency)
            {
                if (sampleItem == null)
                {
                    throw new ArgumentNullException("sampleItem");
                }

                var alternative = sampleItem.Alternative;

                if (!alternative.Available)
                {
                    return;
                }

                var household = _tour.Household;
                var person    = _tour.Person;
                //                var personDay = _tour.PersonDay;
                var householdHasChildren = household.HasChildren;

                var destinationParcel = ChoiceModelFactory.Parcels[sampleItem.ParcelId];

                var fastestTravelTime =
                    ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Hov3, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, _fastestAvailableTimeOfDay, _tour.OriginParcel, destinationParcel).Variable +
                    ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Hov3, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, _fastestAvailableTimeOfDay, destinationParcel, _tour.OriginParcel).Variable;

                if (fastestTravelTime >= _maxAvailableMinutes)
                {
                    alternative.Available = false;

                    return;
                }

                alternative.Choice = destinationParcel;

                double tourLogsum;

                if (_tour.IsHomeBasedTour)
                {
                    if (_tour.DestinationPurpose == Global.Settings.Purposes.Escort)
                    {
                        var nestedAlternative = Global.ChoiceModelSession.Get <EscortTourModeModel>().RunNested(_tour, destinationParcel);
                        tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                    }
                    else
                    {
                        var nestedAlternative = Global.ChoiceModelSession.Get <OtherHomeBasedTourModeModel>().RunNested(_tour, destinationParcel);
                        tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                    }
                }
                else
                {
                    var nestedAlternative = Global.ChoiceModelSession.Get <WorkBasedSubtourModeModel>().RunNested(_tour, destinationParcel);
                    tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                }

                //var purpose = _tour.TourPurposeSegment;
                var carOwnership = person.GetCarOwnershipSegment();
                //var votSegment = _tour.VotALSegment;
                //var transitAccess = destinationParcel.TransitAccessSegment();
                //var aggregateLogsum = Global.AggregateLogsums[destinationParcel.ZoneId][purpose][carOwnership][votSegment][transitAccess];
                //var aggregateLogsumHomeBased = Global.AggregateLogsums[destinationParcel.ZoneId][Global.Settings.Purposes.HomeBasedComposite][carOwnership][votSegment][transitAccess];
                //var aggregateLogsumWorkBased = Global.AggregateLogsums[destinationParcel.ZoneId][Global.Settings.Purposes.Work_BASED][carOwnership][votSegment][transitAccess];

                var distanceFromOrigin    = _tour.OriginParcel.DistanceFromOrigin(destinationParcel, _tour.DestinationArrivalTime);
                var distanceFromOrigin0   = Math.Max(0, Math.Min(distanceFromOrigin - .5, 1 - .5));
                var distanceFromOrigin3   = Math.Max(0, distanceFromOrigin - 1);
                var distanceFromOrigin4   = Math.Min(distanceFromOrigin, .10);
                var distanceFromOrigin5   = Math.Max(0, Math.Min(distanceFromOrigin - .1, .5 - .1));
                var distanceFromOrigin8   = Math.Max(0, Math.Min(distanceFromOrigin - .1, .35 - .1));
                var distanceFromOrigin9   = Math.Max(0, Math.Min(distanceFromOrigin - .35, 1 - .35));
                var distanceFromOriginLog = Math.Log(1 + distanceFromOrigin);
                var distanceFromWorkLog   = person.UsualWorkParcel.DistanceFromWorkLog(destinationParcel, 1);
                var distanceFromSchoolLog = person.UsualSchoolParcel.DistanceFromSchoolLog(destinationParcel, 1);

                var timePressure = Math.Log(1 - fastestTravelTime / _maxAvailableMinutes);

                // log transforms of buffers for Neighborhood effects
                var empEduBuffer = Math.Log(destinationParcel.EmploymentEducationBuffer1 + 1.0);
                var empFooBuffer = Math.Log(destinationParcel.EmploymentFoodBuffer1 + 1.0);
                //                var EMPGOV_B = Math.Log(destinationParcel.EmploymentGovernmentBuffer1 + 1.0);
                var empOfcBuffer = Math.Log(destinationParcel.EmploymentOfficeBuffer1 + 1.0);
                var empRetBuffer = Math.Log(destinationParcel.EmploymentRetailBuffer1 + 1.0);
                var empSvcBuffer = Math.Log(destinationParcel.EmploymentServiceBuffer1 + 1.0);
                var empMedBuffer = Math.Log(destinationParcel.EmploymentMedicalBuffer1 + 1.0);
                //                var EMPIND_B = Math.Log(destinationParcel.EmploymentIndustrialBuffer1 + destinationParcel.EmploymentAgricultureConstructionBuffer1 + 1.0);
                var empTotBuffer  = Math.Log(destinationParcel.EmploymentTotalBuffer1 + 1.0);
                var housesBuffer  = Math.Log(destinationParcel.HouseholdsBuffer1 + 1.0);
                var studK12Buffer = Math.Log(destinationParcel.StudentsK8Buffer1 + destinationParcel.StudentsHighSchoolBuffer1 + 1.0);
                var studUniBuffer = Math.Log(destinationParcel.StudentsUniversityBuffer1 + 1.0);
                //                var EMPHOU_B = Math.Log(destinationParcel.EmploymentTotalBuffer1 + destinationParcel.HouseholdsBuffer1 + 1.0);

                // connectivity attributes
                var c34Ratio = destinationParcel.C34RatioBuffer1();

                var carCompetitionFlag   = FlagUtility.GetCarCompetitionFlag(carOwnership); // exludes no cars
                var noCarCompetitionFlag = FlagUtility.GetNoCarCompetitionFlag(carOwnership);
                var noCarsFlag           = FlagUtility.GetNoCarsFlag(carOwnership);

                alternative.AddUtilityTerm(1, sampleItem.AdjustmentFactor);
                alternative.AddUtilityTerm(2, (_tour.IsHomeBasedTour).ToFlag() * timePressure);

                alternative.AddUtilityTerm(3, _secondaryFlag * _workOrSchoolPatternFlag * distanceFromOrigin0);
                alternative.AddUtilityTerm(4, _secondaryFlag * _otherPatternFlag * distanceFromOrigin5);
                alternative.AddUtilityTerm(5, _secondaryFlag * _otherPatternFlag * distanceFromOrigin0);
                alternative.AddUtilityTerm(6, _secondaryFlag * _otherPatternFlag * distanceFromOrigin3);

                alternative.AddUtilityTerm(7, (!_tour.IsHomeBasedTour).ToFlag() * distanceFromOriginLog);
                alternative.AddUtilityTerm(8, household.Has0To15KIncome.ToFlag() * distanceFromOriginLog);
                alternative.AddUtilityTerm(9, household.HasMissingIncome.ToFlag() * distanceFromOriginLog);
                alternative.AddUtilityTerm(10, person.IsRetiredAdult.ToFlag() * distanceFromOriginLog);
                alternative.AddUtilityTerm(11, person.IsChildAge5Through15.ToFlag() * distanceFromOriginLog);
                alternative.AddUtilityTerm(12, person.IsChildUnder5.ToFlag() * distanceFromOriginLog);

                alternative.AddUtilityTerm(13, (_tour.IsHomeBasedTour).ToFlag() * distanceFromSchoolLog);
                alternative.AddUtilityTerm(14, distanceFromWorkLog);

                alternative.AddUtilityTerm(15, carCompetitionFlag * destinationParcel.ParkingHourlyEmploymentCommercialMixInParcel());
                alternative.AddUtilityTerm(16, noCarCompetitionFlag * destinationParcel.ParkingHourlyEmploymentCommercialMixInParcel());
                alternative.AddUtilityTerm(17, carCompetitionFlag * destinationParcel.ParkingHourlyEmploymentCommercialMixBuffer1());
                alternative.AddUtilityTerm(18, noCarCompetitionFlag * destinationParcel.ParkingHourlyEmploymentCommercialMixBuffer1());

                alternative.AddUtilityTerm(19, noCarsFlag * c34Ratio);


                if (_tour.DestinationPurpose == Global.Settings.Purposes.Escort)
                {
                    alternative.AddUtilityTerm(20, tourLogsum);
                    alternative.AddUtilityTerm(21, distanceFromOrigin4);
                    alternative.AddUtilityTerm(22, distanceFromOrigin8);
                    alternative.AddUtilityTerm(23, distanceFromOrigin9);

                    // Neighborhood
                    alternative.AddUtilityTerm(24, householdHasChildren.ToFlag() * studK12Buffer);
                    alternative.AddUtilityTerm(25, empTotBuffer);

                    // Size terms
                    alternative.AddUtilityTerm(71, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentEducation);
                    alternative.AddUtilityTerm(72, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentFood);
                    alternative.AddUtilityTerm(73, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentGovernment);
                    alternative.AddUtilityTerm(74, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentOffice);
                    alternative.AddUtilityTerm(75, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentRetail);
                    alternative.AddUtilityTerm(76, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentService);
                    alternative.AddUtilityTerm(77, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentMedical);
                    alternative.AddUtilityTerm(78, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentIndustrial + destinationParcel.EmploymentAgricultureConstruction);
                    alternative.AddUtilityTerm(79, (!householdHasChildren).ToFlag() * destinationParcel.Households);

                    alternative.AddUtilityTerm(80, householdHasChildren.ToFlag() * destinationParcel.EmploymentEducation);
                    alternative.AddUtilityTerm(81, householdHasChildren.ToFlag() * destinationParcel.EmploymentGovernment);
                    alternative.AddUtilityTerm(82, householdHasChildren.ToFlag() * destinationParcel.EmploymentOffice);
                    alternative.AddUtilityTerm(83, householdHasChildren.ToFlag() * destinationParcel.EmploymentRetail);
                    alternative.AddUtilityTerm(84, householdHasChildren.ToFlag() * destinationParcel.EmploymentService);
                    alternative.AddUtilityTerm(85, householdHasChildren.ToFlag() * destinationParcel.EmploymentMedical);
                    alternative.AddUtilityTerm(86, householdHasChildren.ToFlag() * destinationParcel.EmploymentIndustrial + destinationParcel.EmploymentAgricultureConstruction);
                    alternative.AddUtilityTerm(87, householdHasChildren.ToFlag() * destinationParcel.Households);
                    alternative.AddUtilityTerm(88, householdHasChildren.ToFlag() * destinationParcel.GetStudentsK12());
                }
                else if (_tour.DestinationPurpose == Global.Settings.Purposes.PersonalBusiness || _tour.DestinationPurpose == Global.Settings.Purposes.Medical)
                {
                    alternative.AddUtilityTerm(26, tourLogsum);
                    alternative.AddUtilityTerm(27, distanceFromOrigin4);
                    alternative.AddUtilityTerm(28, distanceFromOrigin8);
                    alternative.AddUtilityTerm(29, distanceFromOrigin9);
                    alternative.AddUtilityTerm(30, distanceFromOrigin3);

                    // Neighborhood
                    alternative.AddUtilityTerm(31, empEduBuffer);
                    alternative.AddUtilityTerm(32, empSvcBuffer);
                    alternative.AddUtilityTerm(33, empMedBuffer);
                    alternative.AddUtilityTerm(34, housesBuffer); // also psrc
                    alternative.AddUtilityTerm(35, studUniBuffer);


                    // Size terms
                    alternative.AddUtilityTerm(89, destinationParcel.EmploymentEducation);
                    alternative.AddUtilityTerm(90, destinationParcel.EmploymentFood);
                    alternative.AddUtilityTerm(91, destinationParcel.EmploymentOffice);
                    alternative.AddUtilityTerm(92, destinationParcel.EmploymentRetail);
                    alternative.AddUtilityTerm(93, destinationParcel.EmploymentService);
                    alternative.AddUtilityTerm(94, destinationParcel.EmploymentMedical);
                    alternative.AddUtilityTerm(95, destinationParcel.EmploymentIndustrial + destinationParcel.EmploymentAgricultureConstruction);
                    alternative.AddUtilityTerm(96, destinationParcel.Households);
                    alternative.AddUtilityTerm(97, destinationParcel.GetStudentsK12());
                }
                else if (_tour.DestinationPurpose == Global.Settings.Purposes.Shopping)
                {
                    alternative.AddUtilityTerm(36, tourLogsum);
                    alternative.AddUtilityTerm(37, distanceFromOrigin4);
                    alternative.AddUtilityTerm(38, distanceFromOrigin8);
                    alternative.AddUtilityTerm(39, distanceFromOrigin9);
                    alternative.AddUtilityTerm(40, distanceFromOrigin3);

                    // Neighborhood
                    alternative.AddUtilityTerm(41, empEduBuffer); // also psrc
                    alternative.AddUtilityTerm(42, empRetBuffer); // also psrc

                    // Size terms
                    alternative.AddUtilityTerm(98, destinationParcel.EmploymentFood);
                    alternative.AddUtilityTerm(99, destinationParcel.EmploymentOffice);
                    alternative.AddUtilityTerm(100, destinationParcel.EmploymentRetail);
                    alternative.AddUtilityTerm(101, destinationParcel.EmploymentService);
                }
                else if (_tour.DestinationPurpose == Global.Settings.Purposes.Meal)
                {
                    alternative.AddUtilityTerm(43, tourLogsum);
                    alternative.AddUtilityTerm(44, distanceFromOrigin4);
                    alternative.AddUtilityTerm(45, distanceFromOrigin8);
                    alternative.AddUtilityTerm(46, distanceFromOrigin9);
                    alternative.AddUtilityTerm(47, distanceFromOrigin3);

                    // Neighborhood
                    alternative.AddUtilityTerm(48, empFooBuffer); // psrc

                    // Size terms
                    alternative.AddUtilityTerm(102, destinationParcel.EmploymentFood);
                    alternative.AddUtilityTerm(103, destinationParcel.EmploymentOffice);
                    alternative.AddUtilityTerm(104, destinationParcel.EmploymentTotal);
                    alternative.AddUtilityTerm(105, destinationParcel.Households);
                }
                else if (_tour.DestinationPurpose == Global.Settings.Purposes.Social || _tour.DestinationPurpose == Global.Settings.Purposes.Recreation)
                {
                    alternative.AddUtilityTerm(49, tourLogsum);
                    alternative.AddUtilityTerm(50, distanceFromOrigin4);
                    alternative.AddUtilityTerm(51, distanceFromOrigin8);
                    alternative.AddUtilityTerm(52, distanceFromOrigin9);
                    alternative.AddUtilityTerm(53, distanceFromOrigin3);

                    // Neighborhood
                    alternative.AddUtilityTerm(54, empOfcBuffer);  // also psrc
                    alternative.AddUtilityTerm(55, empSvcBuffer);  // also psrc
                    alternative.AddUtilityTerm(56, housesBuffer);  // also psrc
                    alternative.AddUtilityTerm(57, studUniBuffer); // psrc

                    // Size terms
                    alternative.AddUtilityTerm(106, destinationParcel.EmploymentFood);
                    alternative.AddUtilityTerm(107, destinationParcel.EmploymentGovernment);
                    alternative.AddUtilityTerm(108, destinationParcel.EmploymentOffice);
                    alternative.AddUtilityTerm(109, destinationParcel.EmploymentRetail);
                    alternative.AddUtilityTerm(110, destinationParcel.EmploymentService);
                    alternative.AddUtilityTerm(111, destinationParcel.Households);
                    alternative.AddUtilityTerm(112, destinationParcel.StudentsUniversity);
                    alternative.AddUtilityTerm(113, destinationParcel.GetStudentsK12());
                }

                //add any region-specific new terms in region-specific class, using coefficient numbers 114-120, or other unused variable #
                _parentClass.RegionSpecificOtherTourDistrictCoefficients(alternative, _tour, destinationParcel);

                // OD shadow pricing
                if (Global.Configuration.ShouldUseODShadowPricing)
                {
                    var ori = _tour.OriginParcel.District;
                    var des = destinationParcel.District;
                    //var first = res <= des? res : des;
                    //var second = res <= des? des : res;
                    var shadowPriceConfigurationParameter = ori == des ? Global.Configuration.OtherTourDestinationOOShadowPriceCoefficient : Global.Configuration.OtherTourDestinationODShadowPriceCoefficient;
                    var odShadowPriceF12Value             = MAX_REGULAR_PARAMETER + Global.Configuration.NumberOfODShadowPricingDistricts * (ori - 1) + des;
                    alternative.AddUtilityTerm(odShadowPriceF12Value, shadowPriceConfigurationParameter);
                }
            }
Пример #14
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>();

            var household       = householdDay.Household;
            var residenceParcel = household.ResidenceParcel;

            var carOwnership =
                household.VehiclesAvailable == 0
                                                                 ? Global.Settings.CarOwnerships.NoCars
                                                                 : household.VehiclesAvailable < household.HouseholdTotals.DrivingAgeMembers
                                                                          ? Global.Settings.CarOwnerships.LtOneCarPerAdult
                                                                          : Global.Settings.CarOwnerships.OneOrMoreCarsPerAdult;

            var noCarsFlag         = FlagUtility.GetNoCarsFlag(carOwnership);
            var carCompetitionFlag = FlagUtility.GetCarCompetitionFlag(carOwnership);

            var votALSegment                    = household.GetVotALSegment();
            var transitAccessSegment            = household.ResidenceParcel.TransitAccessSegment();
            var personalBusinessAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                                  [Global.Settings.Purposes.PersonalBusiness][carOwnership][votALSegment][transitAccessSegment];
            var shoppingAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                          [Global.Settings.Purposes.Shopping][Global.Settings.CarOwnerships.NoCars][votALSegment][transitAccessSegment];
            //var mealAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
            //	 [Global.Settings.Purposes.Meal][carOwnership][votALSegment][transitAccessSegment];
            var socialAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                        [Global.Settings.Purposes.Social][carOwnership][votALSegment][transitAccessSegment];
            var totalAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                       [Global.Settings.Purposes.HomeBasedComposite][carOwnership][votALSegment][transitAccessSegment];
            // var recreationAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
            // [Global.Settings.Purposes.Recreation][carOwnership][votALSegment][transitAccessSegment];
            //  var medicalAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
            //  [Global.Settings.Purposes.Medical][carOwnership][votALSegment][transitAccessSegment];
            //var compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][carOwnership][votALSegment][transitAccessSegment];
            var compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.NoCars][votALSegment][transitAccessSegment];


            int countNonMandatory  = 0;
            int countMandatory     = 0;
            int countWorkingAtHome = 0;


            double totalTimeWork = 0;


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

            double[] workLogsum   = new double[8];
            double[] schoolLogsum = new double[8];
            int      count        = 0;

            foreach (PersonDayWrapper pDay in orderedPersonDays)
            {
                var person = pDay.Person;
                count++;
                if (count > 8)
                {
                    break;
                }
                if (pDay.WorksAtHomeFlag == 1)
                {
                    countWorkingAtHome++;
                }
                if (pDay.PatternType == 1)
                {
                    countMandatory++;
                    mandPerstype[pDay.Person.PersonType - 1]++;
                }
                if (pDay.PatternType == 2)
                {
                    countNonMandatory++;
                    nonMandPerstype[pDay.Person.PersonType - 1]++;
                }

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

                    workLogsum[count - 1] = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                }

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

                    schoolLogsum[count - 1] = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                }
            }


            // NONE_OR_HOME

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

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

            //alternative.AddUtilityTerm(1, (personDay.TotalCreatedTours == 1).ToFlag());
            alternative.AddUtilityTerm(2, (personDay.GetTotalCreatedTours() == 2).ToFlag());
            alternative.AddUtilityTerm(3, (personDay.GetTotalCreatedTours() >= 3).ToFlag());
            //alternative.AddUtilityTerm(4, (personDay.TotalCreatedTours >= 4).ToFlag());

            //alternative.AddUtilityTerm(5, householdDay.PrimaryPriorityTimeFlag);

            //alternative.AddUtilityTerm(6, householdDay.Household.HasChildren.ToFlag());

            alternative.AddUtilityTerm(4, householdDay.Household.HasChildrenUnder5.ToFlag());
            alternative.AddUtilityTerm(5, householdDay.Household.HasChildrenAge5Through15.ToFlag());
            //alternative.AddUtilityTerm(6, (householdDay.Household.Size == 2 && householdDay.AdultsInSharedHomeStay == 2).ToFlag());
            //alternative.AddUtilityTerm(7, (householdDay.AdultsInSharedHomeStay == 1 && householdDay.Household.HasChildrenUnder16).ToFlag());
            //alternative.AddUtilityTerm(8, (householdDay.AdultsInSharedHomeStay == 2 && householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag());

            //alternative.AddUtilityTerm(10, (householdDay.Household.Income >= 300000 && householdDay.Household.Income < 600000).ToFlag());
            //alternative.AddUtilityTerm(11, (householdDay.Household.Income >= 600000 && householdDay.Household.Income < 900000).ToFlag());
            //alternative.AddUtilityTerm(12, (householdDay.Household.Income >= 900000).ToFlag());

            alternative.AddUtilityTerm(13, householdDay.PrimaryPriorityTimeFlag);

            alternative.AddUtilityTerm(14, personDay.Person.IsPartTimeWorker.ToFlag());
            alternative.AddUtilityTerm(15, personDay.Person.WorksAtHome.ToFlag());
            //alternative.AddUtilityTerm(16, personDay.Person.IsFulltimeWorker.ToFlag());

            //alternative.AddUtilityTerm(15, (personDay.Person.Gender == 1).ToFlag());

            //alternative.AddUtilityTerm(10, (householdDay.Household.Size == 3).ToFlag());
            //alternative.AddUtilityTerm(11, (householdDay.Household.Size == 4).ToFlag());
            //alternative.AddUtilityTerm(12, (householdDay.Household.Size >= 5).ToFlag());

            //alternative.AddNestedAlternative(11, 0, 200);


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

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

            // ESCORT
            alternative        = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Escort, maxPurpose <= Global.Settings.Purposes.Escort && personDay.CreatedEscortTours > 0, choice == Global.Settings.Purposes.Escort);
            alternative.Choice = Global.Settings.Purposes.Escort;

            alternative.AddUtilityTerm(151, 1);
            alternative.AddUtilityTerm(152, (personDay.CreatedEscortTours > 1).ToFlag());

            //alternative.AddUtilityTerm(152, householdDay.PrimaryPriorityTimeFlag);

            //alternative.AddUtilityTerm(153, (householdDay.Household.Size == 3).ToFlag());
            //alternative.AddUtilityTerm(154, (householdDay.Household.Size >= 4).ToFlag());

            //alternative.AddUtilityTerm(155, (householdDay.Household.Size > 4).ToFlag());

            alternative.AddUtilityTerm(155, compositeLogsum);

            //alternative.AddUtilityTerm(156, (householdDay.Household.VehiclesAvailable == 0).ToFlag());

            //alternative.AddNestedAlternative(12, 1, 200);


            // PERSONAL_BUSINESS
            alternative        = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.PersonalBusiness, maxPurpose <= Global.Settings.Purposes.PersonalBusiness && personDay.CreatedPersonalBusinessTours > 0, choice == Global.Settings.Purposes.PersonalBusiness);
            alternative.Choice = Global.Settings.Purposes.PersonalBusiness;

            alternative.AddUtilityTerm(21, 1);
            //alternative.AddUtilityTerm(22, (personDay.CreatedPersonalBusinessTours > 1).ToFlag()); //GV: 30. april 2013 - goes to infinity

            alternative.AddUtilityTerm(156, compositeLogsum);

            //alternative.AddNestedAlternative(12, 1, 200);

            // SHOPPING
            alternative        = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Shopping, maxPurpose <= Global.Settings.Purposes.Shopping && personDay.CreatedShoppingTours > 0, choice == Global.Settings.Purposes.Shopping);
            alternative.Choice = Global.Settings.Purposes.Shopping;

            alternative.AddUtilityTerm(41, 1);
            //alternative.AddUtilityTerm(42, (personDay.CreatedShoppingTours > 1).ToFlag()); //GV: cannot be estimated

            //alternative.AddUtilityTerm(42, householdDay.PrimaryPriorityTimeFlag);

            //alternative.AddUtilityTerm(43, (householdDay.Household.Size == 3).ToFlag());
            //alternative.AddUtilityTerm(44, (householdDay.Household.Size == 4).ToFlag());
            //alternative.AddUtilityTerm(45, (householdDay.Household.Size > 4).ToFlag());

            //alternative.AddUtilityTerm(46, (householdDay.Household.VehiclesAvailable == 0).ToFlag());

            //alternative.AddUtilityTerm(157, compositeLogsum); //GV wrong sign
            //alternative.AddUtilityTerm(157, shoppingAggregateLogsum); //GV wrong sign

            //alternative.AddNestedAlternative(12, 1, 200);


            // MEAL

            alternative        = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Meal, false, choice == Global.Settings.Purposes.Meal);
            alternative.Choice = Global.Settings.Purposes.Meal;

            alternative.AddUtilityTerm(61, 1);
            alternative.AddUtilityTerm(62, (personDay.CreatedMealTours > 1).ToFlag());

            //alternative.AddNestedAlternative(12, 1, 200);

            // SOCIAL

            alternative        = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Social, maxPurpose <= Global.Settings.Purposes.Social && personDay.CreatedSocialTours > 0, choice == Global.Settings.Purposes.Social);
            alternative.Choice = Global.Settings.Purposes.Social;

            alternative.AddUtilityTerm(81, 1);
            alternative.AddUtilityTerm(82, (personDay.CreatedSocialTours > 1).ToFlag());

            //alternative.AddUtilityTerm(82, householdDay.PrimaryPriorityTimeFlag);

            //alternative.AddUtilityTerm(83, (householdDay.Household.Size == 3).ToFlag());
            //alternative.AddUtilityTerm(84, (householdDay.Household.Size == 4).ToFlag());
            //alternative.AddUtilityTerm(85, (householdDay.Household.Size > 4).ToFlag());

            alternative.AddUtilityTerm(158, compositeLogsum);

            //alternative.AddNestedAlternative(12, 1, 200);

            // RECREATION

            alternative        = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Recreation, false, choice == Global.Settings.Purposes.Recreation);
            alternative.Choice = Global.Settings.Purposes.Recreation;

            alternative.AddUtilityTerm(101, 1);
            //alternative.AddUtilityTerm(102, (personDay.CreatedRecreationTours > 1).ToFlag());

            //alternative.AddNestedAlternative(12, 1, 60);

            // MEDICAL

            alternative        = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Medical, false, choice == Global.Settings.Purposes.Medical);
            alternative.Choice = Global.Settings.Purposes.Medical;

            alternative.AddUtilityTerm(121, 1);
            //alternative.AddUtilityTerm(122, (personDay.CreatedMedicalTours > 1).ToFlag());

            //alternative.AddNestedAlternative(11, 1, 60);
        }
Пример #15
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, TourWrapper tour, HouseholdDayWrapper householdDay, int sampleSize, IParcelWrapper choice = null)
        {
            timesStartedRunModel++;
            HouseholdWrapper household = (HouseholdWrapper)tour.Household;
            PersonWrapper    person    = (PersonWrapper)tour.Person;
            PersonDayWrapper personDay = (PersonDayWrapper)tour.PersonDay;

            //			var totalAvailableMinutes =
            //				tour.ParentTour == null
            //					? personDay.TimeWindow.TotalAvailableMinutes(1, Global.Settings.Times.MinutesInADay)
            //					: tour.ParentTour.TimeWindow.TotalAvailableMinutes(1, Global.Settings.Times.MinutesInADay);


            TimeWindow timeWindow = new TimeWindow();

            if (tour.JointTourSequence > 0)
            {
                foreach (PersonDayWrapper pDay in householdDay.PersonDays)
                {
                    TourWrapper tInJoint = (TourWrapper)pDay.Tours.Find(t => t.JointTourSequence == tour.JointTourSequence);
                    if (!(tInJoint == null))
                    {
                        // set jointTour time window
                        timeWindow.IncorporateAnotherTimeWindow(tInJoint.PersonDay.TimeWindow);
                    }
                }
            }
            else if (tour.ParentTour == null)
            {
                timeWindow.IncorporateAnotherTimeWindow(personDay.TimeWindow);
            }

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

            var maxAvailableMinutes =
                (tour.JointTourSequence > 0 || tour.ParentTour == null)
                                 ? timeWindow.MaxAvailableMinutesAfter(Global.Settings.Times.FiveAM)
                                          : tour.ParentTour.DestinationDepartureTime - tour.ParentTour.DestinationArrivalTime;


            //			var hoursAvailableInverse =
            //				tour.IsHomeBasedTour
            //					? (personDay.HomeBasedTours - personDay.SimulatedHomeBasedTours + 1) / (Math.Max(totalAvailableMinutes - 360, 30) / 60D)
            //					: 1 / (Math.Max(totalAvailableMinutes, 1) / 60D);

            var householdHasChildren   = household.HasChildren;
            var householdHasNoChildren = householdHasChildren ? false : true;

            var fastestAvailableTimeOfDay =
                tour.IsHomeBasedTour || tour.ParentTour == null
                                          ? 1
                                          : tour.ParentTour.DestinationArrivalTime + (tour.ParentTour.DestinationDepartureTime - tour.ParentTour.DestinationArrivalTime) / 2;

            var tourCategory = tour.GetTourCategory();
            //			var primaryFlag = ChoiceModelUtility.GetPrimaryFlag(tourCategory);
            var secondaryFlag           = ChoiceModelUtility.GetSecondaryFlag(tourCategory);
            var workOrSchoolPatternFlag = personDay.GetIsWorkOrSchoolPattern().ToFlag();
            var otherPatternFlag        = personDay.GetIsOtherPattern().ToFlag();
            int jointTourFlag           = (tour.JointTourSequence > 0).ToFlag();



            ChoiceModelUtility.DrawRandomTourTimePeriods(tour, tourCategory);

            if (tour.Household.Id == 80049 && tour.PersonDay.Day == 1 && tour.Person.Sequence == 2 && tour.Sequence == 4)
            {
                bool testbreak = true;
            }

            var segment = Global.Kernel.Get <SamplingWeightsSettingsFactory>().SamplingWeightsSettings.GetTourDestinationSegment(tour.DestinationPurpose, tour.IsHomeBasedTour ? Global.Settings.TourPriorities.HomeBasedTour : Global.Settings.TourPriorities.WorkBasedTour, Global.Settings.Modes.Sov, person.PersonType);


            var destinationSampler       = new DestinationSampler(choiceProbabilityCalculator, segment, sampleSize, tour.OriginParcel, choice);
            var tourDestinationUtilities = new TourDestinationUtilities(tour, sampleSize, secondaryFlag, personDay.GetIsWorkOrSchoolPattern().ToFlag(), personDay.GetIsOtherPattern().ToFlag(), fastestAvailableTimeOfDay, maxAvailableMinutes);

            // get destination sample and perform code that used to be in SetUtilities below
            var sampleItems = destinationSampler.SampleAndReturnTourDestinations(tourDestinationUtilities);

            int index = 0;

            foreach (var sampleItem in sampleItems)
            {
                bool   available         = sampleItem.Key.Available;
                bool   isChosen          = sampleItem.Key.IsChosen;
                double adjustmentFactor  = sampleItem.Key.AdjustmentFactor;
                var    destinationParcel = ChoiceModelFactory.Parcels[sampleItem.Key.ParcelId];

                if (isChosen)
                {
                    Global.PrintFile.WriteLine("Sequence {0}: Chosen parcel {1} Available {2} Sample item {3} of {4}", timesStartedRunModel, destinationParcel.Id, available, index, sampleItems.Count);
                }

                var alternative = choiceProbabilityCalculator.GetAlternative(index++, available, isChosen);


                if (!available)
                {
                    continue;
                }

                var fastestTravelTime =
                    ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Hov3, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, fastestAvailableTimeOfDay, tour.OriginParcel, destinationParcel).Variable +
                    ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Hov3, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, fastestAvailableTimeOfDay, destinationParcel, tour.OriginParcel).Variable;

                if (fastestTravelTime >= maxAvailableMinutes)
                {
                    alternative.Available = false;

                    continue;
                }

                alternative.Choice = destinationParcel;

                double tourLogsum;

                if (tour.IsHomeBasedTour)
                {
                    if (tour.DestinationPurpose == Global.Settings.Purposes.Work)
                    {
                        //JLB 201406
                        //var nestedAlternative = Global.ChoiceModelSession.Get<WorkTourModeModel>().RunNested(tour, destinationParcel);
                        // JLB 201602
                        //var nestedAlternative = Global.ChoiceModelSession.Get<WorkTourModeTimeModel>().RunNested(tour, destinationParcel, tour.Household.VehiclesAvailable, tour.Person.GetTransitFareDiscountFraction());
                        var nestedAlternative = Global.ChoiceModelSession.Get <TourModeTimeModel>().RunNested(tour, destinationParcel, tour.Household.VehiclesAvailable, tour.Person.GetTransitFareDiscountFraction());
                        tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                    }

                    // JLB201406
                    //else if (tour.DestinationPurpose == Global.Settings.Purposes.Escort) {
                    //	var nestedAlternative = Global.ChoiceModelSession.Get<EscortTourModeModel>().RunNested(tour, destinationParcel);
                    //	tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                    //}
                    else
                    {
                        // JLB201406
                        //var nestedAlternative = Global.ChoiceModelSession.Get<OtherHomeBasedTourModeModel>().RunNested(tour, destinationParcel);
                        // JLB 201602
                        //var nestedAlternative = Global.ChoiceModelSession.Get<OtherHomeBasedTourModeTimeModel>().RunNested(tour, destinationParcel, tour.Household.VehiclesAvailable, tour.Person.GetTransitFareDiscountFraction());
                        var nestedAlternative = Global.ChoiceModelSession.Get <TourModeTimeModel>().RunNested(tour, destinationParcel, tour.Household.VehiclesAvailable, tour.Person.GetTransitFareDiscountFraction());
                        tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                    }
                }
                else
                {
                    // JLB201406
                    //var nestedAlternative = Global.ChoiceModelSession.Get<WorkBasedSubtourModeModel>().RunNested(tour, destinationParcel);
                    // JLB 201602
                    //var nestedAlternative = Global.ChoiceModelSession.Get<WorkBasedSubtourModeTimeModel>().RunNested(tour, destinationParcel, tour.Household.VehiclesAvailable, tour.Person.GetTransitFareDiscountFraction());
                    var nestedAlternative = Global.ChoiceModelSession.Get <TourModeTimeModel>().RunNested(tour, destinationParcel, tour.Household.VehiclesAvailable, tour.Person.GetTransitFareDiscountFraction());
                    tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                }

                //var purpose = tour.TourPurposeSegment;
                var carOwnership  = person.GetCarOwnershipSegment();
                var votSegment    = tour.GetVotALSegment();
                var transitAccess = destinationParcel.TransitAccessSegment();
                //var aggregateLogsum = Global.AggregateLogsums[destinationParcel.ZoneId][purpose][carOwnership][votSegment][transitAccess];
                var aggregateLogsumHomeBased = Global.AggregateLogsums[destinationParcel.ZoneId][Global.Settings.Purposes.HomeBasedComposite][carOwnership][votSegment][transitAccess];
                var aggregateLogsumWorkBased = Global.AggregateLogsums[destinationParcel.ZoneId][Global.Settings.Purposes.WorkBased][carOwnership][votSegment][transitAccess];

                var distanceFromOrigin = tour.OriginParcel.DistanceFromOrigin(destinationParcel, tour.DestinationArrivalTime);


                // 1. new from GV: Cph KM-distances
                var piecewiseDistanceFrom0To1Km = Math.Min(distanceFromOrigin, .10);

                var piecewiseDistanceFrom0To2Km = Math.Min(distanceFromOrigin, .20);                 //GV: added July 7th
                var piecewiseDistanceFrom0To5Km = Math.Min(distanceFromOrigin, .50);                 //GV: added July 7th

                var piecewiseDistanceFrom1To2Km         = Math.Max(0, Math.Min(distanceFromOrigin - .1, .2 - .1));
                var piecewiseDistanceFrom2To5Km         = Math.Max(0, Math.Min(distanceFromOrigin - .2, .5 - .2));
                var piecewiseDistanceFrom5To10Km        = Math.Max(0, Math.Min(distanceFromOrigin - .5, 1 - .5));
                var piecewiseDistanceFrom10To20Km       = Math.Max(0, Math.Min(distanceFromOrigin - 1, 2 - 1));
                var piecewiseDistanceFrom20KmToInfinity = Math.Max(0, distanceFromOrigin - 2);

                var piecewiseDistanceFrom10KmToInfinity = Math.Max(0, distanceFromOrigin - 1);
                // 1. finished

                var distanceFromOriginLog = Math.Log(1 + distanceFromOrigin);
                var distanceFromWorkLog   = person.UsualWorkParcel.DistanceFromWorkLog(destinationParcel, 1);
                var distanceFromSchoolLog = person.UsualSchoolParcel.DistanceFromSchoolLog(destinationParcel, 1);

                var timePressure = Math.Log(1 - fastestTravelTime / maxAvailableMinutes);


                // 2. new from GV: Cph buffers for neighborhood effects
                // log transforms of buffers for Neighborhood effects
                var logOfOnePlusEducationK8Buffer2          = Math.Log(destinationParcel.StudentsK8Buffer2 + 1.0);
                var logOfOnePlusEducationUniStuBuffer2      = Math.Log(destinationParcel.StudentsUniversityBuffer2 + 1.0);
                var logOfOnePlusEmploymentEducationBuffer2  = Math.Log(destinationParcel.EmploymentEducationBuffer2 + 1.0);
                var logOfOnePlusEmploymentGovernmentBuffer2 = Math.Log(destinationParcel.EmploymentGovernmentBuffer2 + 1.0);
                var logOfOnePlusEmploymentIndustrialBuffer2 = Math.Log(destinationParcel.EmploymentIndustrialBuffer2 + 1.0);
                var logOfOnePlusEmploymentOfficeBuffer2     = Math.Log(destinationParcel.EmploymentOfficeBuffer2 + 1.0);
                var logOfOnePlusEmploymentRetailBuffer2     = Math.Log(destinationParcel.EmploymentRetailBuffer2 + 1.0);
                var logOfOnePlusEmploymentServiceBuffer2    = Math.Log(destinationParcel.EmploymentServiceBuffer2 + 1.0);
                var logOfOnePlusEmploymentAgrConstrBuffer2  = Math.Log(destinationParcel.EmploymentAgricultureConstructionBuffer2 + 1.0);
                var logOfOnePlusEmploymentJobsBuffer2       = Math.Log(destinationParcel.EmploymentTotalBuffer2 + 1.0);
                var logOfOnePlusHouseholdsBuffer2           = Math.Log(destinationParcel.HouseholdsBuffer2 + 1.0);
                // 2. finished


                var logOfOnePlusParkingOffStreetDailySpacesBuffer1 = Math.Log(1 + destinationParcel.ParkingOffStreetPaidDailySpacesBuffer1);
                // connectivity attributes
                var c34Ratio = destinationParcel.C34RatioBuffer1();

                var carCompetitionFlag   = FlagUtility.GetCarCompetitionFlag(carOwnership);               // exludes no cars
                var noCarCompetitionFlag = FlagUtility.GetNoCarCompetitionFlag(carOwnership);
                var noCarsFlag           = FlagUtility.GetNoCarsFlag(carOwnership);

                alternative.AddUtilityTerm(2, household.Id);
                alternative.AddUtilityTerm(3, personDay.Day);
                alternative.AddUtilityTerm(4, person.Sequence);
                alternative.AddUtilityTerm(5, tour.Sequence);

                alternative.AddUtilityTerm(8, adjustmentFactor);
                alternative.AddUtilityTerm(9, tourLogsum);

                // 3. new from GV: definition of Cph variables

                //alternative.AddUtilityTerm(260, secondaryFlag * workOrSchoolPatternFlag * piecewiseDistanceFrom0To1Km);
                alternative.AddUtilityTerm(260, secondaryFlag * workOrSchoolPatternFlag * piecewiseDistanceFrom0To2Km);                 //GV: added July 7th
                //alternative.AddUtilityTerm(261, secondaryFlag * workOrSchoolPatternFlag * piecewiseDistanceFrom1To2Km);
                alternative.AddUtilityTerm(262, secondaryFlag * workOrSchoolPatternFlag * piecewiseDistanceFrom2To5Km);
                alternative.AddUtilityTerm(263, secondaryFlag * workOrSchoolPatternFlag * piecewiseDistanceFrom5To10Km);
                alternative.AddUtilityTerm(264, secondaryFlag * workOrSchoolPatternFlag * piecewiseDistanceFrom10To20Km);
                alternative.AddUtilityTerm(265, secondaryFlag * workOrSchoolPatternFlag * piecewiseDistanceFrom20KmToInfinity);

                //alternative.AddUtilityTerm(266, secondaryFlag * otherPatternFlag * piecewiseDistanceFrom0To1Km);
                alternative.AddUtilityTerm(266, secondaryFlag * otherPatternFlag * piecewiseDistanceFrom0To2Km);                 //GV: added July 7th
                //alternative.AddUtilityTerm(267, secondaryFlag * otherPatternFlag * piecewiseDistanceFrom1To2Km);
                alternative.AddUtilityTerm(268, secondaryFlag * otherPatternFlag * piecewiseDistanceFrom2To5Km);
                alternative.AddUtilityTerm(269, secondaryFlag * otherPatternFlag * piecewiseDistanceFrom5To10Km);
                alternative.AddUtilityTerm(270, secondaryFlag * otherPatternFlag * piecewiseDistanceFrom10To20Km);
                alternative.AddUtilityTerm(271, secondaryFlag * otherPatternFlag * piecewiseDistanceFrom20KmToInfinity);

                //alternative.AddUtilityTerm(268, (!_tour.IsHomeBasedTour).ToFlag() * distanceFromOriginLog);
                //alternative.AddUtilityTerm(269, household.Has0To15KIncome.ToFlag() * distanceFromOriginLog);
                //alternative.AddUtilityTerm(270, household.HasMissingIncome.ToFlag() * distanceFromOriginLog);
                //alternative.AddUtilityTerm(271, person.IsRetiredAdult.ToFlag() * distanceFromOriginLog);
                //alternative.AddUtilityTerm(272, person.IsUniversityStudent.ToFlag() * distanceFromOriginLog);
                //alternative.AddUtilityTerm(273, person.IsChildAge5Through15.ToFlag() * distanceFromOriginLog);
                //alternative.AddUtilityTerm(274, person.IsChildUnder5.ToFlag() * distanceFromOriginLog);

                alternative.AddUtilityTerm(272, (!tour.IsHomeBasedTour).ToFlag() * distanceFromOriginLog);
                alternative.AddUtilityTerm(273, (household.Income >= 300000 && household.Income < 600000).ToFlag() * distanceFromOriginLog);
                alternative.AddUtilityTerm(274, (household.Income >= 600000 && household.Income < 900000).ToFlag() * distanceFromOriginLog);
                alternative.AddUtilityTerm(275, (household.Income >= 900000).ToFlag() * distanceFromOriginLog);

                //alternative.AddUtilityTerm(276, person.IsChildUnder5.ToFlag() * distanceFromOriginLog); // commented out by GV, July 7th
                //alternative.AddUtilityTerm(277, person.IsChildAge5Through15.ToFlag() * distanceFromOriginLog); // commented out by GV, July 7th
                //alternative.AddUtilityTerm(278, person.IsChildUnder16.ToFlag() * distanceFromOriginLog); // commented out by GV, July 7th
                alternative.AddUtilityTerm(279, person.IsUniversityStudent.ToFlag() * distanceFromOriginLog);

                //GV: 17. june 2015 male commented out
                //alternative.AddUtilityTerm(280, person.IsAdultMale.ToFlag() * distanceFromOriginLog);
                alternative.AddUtilityTerm(281, person.IsAdultFemale.ToFlag() * distanceFromOriginLog);

                alternative.AddUtilityTerm(282, person.IsRetiredAdult.ToFlag() * distanceFromOriginLog);

                //alternative.AddUtilityTerm(283, (tour.IsHomeBasedTour).ToFlag() * timePressure); //commented out by GV: 7th July 2013
                alternative.AddUtilityTerm(284, (tour.IsHomeBasedTour).ToFlag() * distanceFromSchoolLog);
                //alternative.AddUtilityTerm(14, distanceFromWorkLog);

                // GV commented out this - on TO DO list
                //alternative.AddUtilityTerm(277, (carCompetitionFlag + noCarCompetitionFlag) * destinationParcel.ParkingHourlyEmploymentCommercialMixInParcel());
                //alternative.AddUtilityTerm(278, noCarCompetitionFlag * destinationParcel.ParkingHourlyEmploymentCommercialMixInParcel());
                //alternative.AddUtilityTerm(279, carCompetitionFlag * destinationParcel.ParkingHourlyEmploymentCommercialMixBuffer1());
                //alternative.AddUtilityTerm(280, noCarCompetitionFlag * destinationParcel.ParkingHourlyEmploymentCommercialMixBuffer1());
                //alternative.AddUtilityTerm(281, noCarsFlag * c34Ratio);
                //alternative.AddUtilityTerm(282, noCarCompetitionFlag * c34Ratio);
                //alternative.AddUtilityTerm(283, (carCompetitionFlag + noCarCompetitionFlag) * logOfOnePlusParkingOffStreetDailySpacesBuffer1);


                //alternative.AddUtilityTerm(285, jointTourFlag * piecewiseDistanceFrom0To1Km);
                //alternative.AddUtilityTerm(286, jointTourFlag * piecewiseDistanceFrom1To2Km);
                alternative.AddUtilityTerm(286, jointTourFlag * piecewiseDistanceFrom0To2Km);
                alternative.AddUtilityTerm(287, jointTourFlag * piecewiseDistanceFrom2To5Km);
                alternative.AddUtilityTerm(288, jointTourFlag * piecewiseDistanceFrom5To10Km);
                alternative.AddUtilityTerm(289, jointTourFlag * piecewiseDistanceFrom10To20Km);
                alternative.AddUtilityTerm(290, jointTourFlag * piecewiseDistanceFrom20KmToInfinity);
                // 3. finished


                //4. new from GV: purpose utilities
                // COMPAS puposes are: Work, Education, Escort, Shopping, Leisure, Personal business, business
                // You need NO "Work" and "Education", their destinations are known in the synthetic population
                if (tour.DestinationPurpose == Global.Settings.Purposes.Business)
                {
                    //alternative.AddUtilityTerm(10, piecewiseDistanceFrom0To1Km);
                    //alternative.AddUtilityTerm(11, piecewiseDistanceFrom1To2Km);
                    //alternative.AddUtilityTerm(12, piecewiseDistanceFrom2To5Km);
                    alternative.AddUtilityTerm(12, piecewiseDistanceFrom0To5Km);
                    alternative.AddUtilityTerm(13, piecewiseDistanceFrom5To10Km);
                    alternative.AddUtilityTerm(14, piecewiseDistanceFrom10To20Km);
                    alternative.AddUtilityTerm(15, piecewiseDistanceFrom20KmToInfinity);

                    //GV: june 2016 - not sign
                    //alternative.AddUtilityTerm(16, aggregateLogsumWorkBased);

                    // Neighborhood
                    //GV: commented out just temp.
                    //alternative.AddUtilityTerm(20, logOfOnePlusEducationK8Buffer2);
                    //alternative.AddUtilityTerm(21, logOfOnePlusEducationUniStuBuffer2);
                    //alternative.AddUtilityTerm(22, logOfOnePlusEmploymentEducationBuffer2);
                    alternative.AddUtilityTerm(23, logOfOnePlusEmploymentGovernmentBuffer2);
                    //alternative.AddUtilityTerm(24, logOfOnePlusEmploymentIndustrialBuffer2);
                    //alternative.AddUtilityTerm(25, logOfOnePlusEmploymentOfficeBuffer2);
                    //alternative.AddUtilityTerm(26, logOfOnePlusEmploymentRetailBuffer2);
                    alternative.AddUtilityTerm(27, logOfOnePlusEmploymentServiceBuffer2);
                    //alternative.AddUtilityTerm(28, logOfOnePlusEmploymentAgrConstrBuffer2);
                    //alternative.AddUtilityTerm(29, logOfOnePlusEmploymentJobsBuffer2);

                    // Size terms
                    alternative.AddUtilityTerm(30, destinationParcel.EmploymentEducation);
                    alternative.AddUtilityTerm(31, destinationParcel.EmploymentGovernment);
                    alternative.AddUtilityTerm(32, destinationParcel.EmploymentIndustrial);
                    alternative.AddUtilityTerm(33, destinationParcel.EmploymentOffice);
                    alternative.AddUtilityTerm(34, destinationParcel.EmploymentRetail);
                    // GV: 35 is fixed to zero
                    alternative.AddUtilityTerm(35, destinationParcel.EmploymentService);
                    alternative.AddUtilityTerm(36, destinationParcel.EmploymentAgricultureConstruction);
                    alternative.AddUtilityTerm(37, destinationParcel.EmploymentTotal);
                    alternative.AddUtilityTerm(38, destinationParcel.Households);
                }
                else if (tour.DestinationPurpose == Global.Settings.Purposes.Escort)
                {
                    //alternative.AddUtilityTerm(50, piecewiseDistanceFrom0To1Km);
                    alternative.AddUtilityTerm(51, piecewiseDistanceFrom0To2Km);
                    //alternative.AddUtilityTerm(52, piecewiseDistanceFrom2To5Km);
                    alternative.AddUtilityTerm(52, piecewiseDistanceFrom2To5Km);
                    alternative.AddUtilityTerm(53, piecewiseDistanceFrom5To10Km);
                    //alternative.AddUtilityTerm(54, piecewiseDistanceFrom10To20Km);
                    alternative.AddUtilityTerm(55, piecewiseDistanceFrom10KmToInfinity);
                    //alternative.AddUtilityTerm(55, piecewiseDistanceFrom20KmToInfinity);

                    //GV: june 2016 - not sign
                    //alternative.AddUtilityTerm(56, aggregateLogsumHomeBased);

                    // Neighborhood
                    //GV: commented out just temp.
                    alternative.AddUtilityTerm(60, householdHasNoChildren.ToFlag() * logOfOnePlusEmploymentJobsBuffer2);
                    //alternative.AddUtilityTerm(61, householdHasNoChildren.ToFlag() * logOfOnePlusHouseholdsBuffer2);
                    //alternative.AddUtilityTerm(62, householdHasChildren.ToFlag() * logOfOnePlusHouseholdsBuffer2);
                    //alternative.AddUtilityTerm(64, logOfOnePlusEmploymentJobsBuffer2);

                    // Size terms
                    // GV: no observations
                    alternative.AddUtilityTerm(70, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentEducation);
                    alternative.AddUtilityTerm(71, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentGovernment);
                    alternative.AddUtilityTerm(72, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentIndustrial);
                    alternative.AddUtilityTerm(73, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentOffice);
                    alternative.AddUtilityTerm(74, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentRetail);
                    // GV: 75 is fixed to zero
                    alternative.AddUtilityTerm(75, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentService);
                    alternative.AddUtilityTerm(76, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentAgricultureConstruction);
                    alternative.AddUtilityTerm(77, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentTotal);
                    alternative.AddUtilityTerm(78, (!householdHasChildren).ToFlag() * destinationParcel.Households);

                    alternative.AddUtilityTerm(80, (householdHasChildren).ToFlag() * destinationParcel.EmploymentEducation);
                    alternative.AddUtilityTerm(81, (householdHasChildren).ToFlag() * destinationParcel.EmploymentGovernment);
                    alternative.AddUtilityTerm(82, (householdHasChildren).ToFlag() * destinationParcel.EmploymentIndustrial);
                    alternative.AddUtilityTerm(83, (householdHasChildren).ToFlag() * destinationParcel.EmploymentOffice);
                    alternative.AddUtilityTerm(84, (householdHasChildren).ToFlag() * destinationParcel.EmploymentRetail);
                    // GV 85 is fixed to zero at the moment
                    alternative.AddUtilityTerm(85, (householdHasChildren).ToFlag() * destinationParcel.EmploymentService);
                    alternative.AddUtilityTerm(86, (householdHasChildren).ToFlag() * destinationParcel.EmploymentAgricultureConstruction);
                    alternative.AddUtilityTerm(87, (householdHasChildren).ToFlag() * destinationParcel.EmploymentTotal);
                    alternative.AddUtilityTerm(88, (householdHasChildren).ToFlag() * destinationParcel.Households);
                }
                else if (tour.DestinationPurpose == Global.Settings.Purposes.PersonalBusiness)
                {
                    alternative.AddUtilityTerm(90, piecewiseDistanceFrom0To2Km);
                    //alternative.AddUtilityTerm(91, piecewiseDistanceFrom1To2Km);
                    alternative.AddUtilityTerm(92, piecewiseDistanceFrom2To5Km);
                    alternative.AddUtilityTerm(93, piecewiseDistanceFrom5To10Km);
                    alternative.AddUtilityTerm(95, piecewiseDistanceFrom10KmToInfinity);

                    //GV: june 2016 - not sign
                    //alternative.AddUtilityTerm(96, aggregateLogsumHomeBased);

                    // Neighborhood
                    //GV: commented out just temp.
                    //alternative.AddUtilityTerm(100, logOfOnePlusEmploymentEducationBuffer2);
                    //alternative.AddUtilityTerm(101, logOfOnePlusEmploymentGovernmentBuffer2);
                    //alternative.AddUtilityTerm(102, logOfOnePlusEmploymentIndustrialBuffer2);
                    alternative.AddUtilityTerm(103, logOfOnePlusEmploymentOfficeBuffer2);
                    alternative.AddUtilityTerm(104, logOfOnePlusEmploymentRetailBuffer2);
                    alternative.AddUtilityTerm(105, logOfOnePlusEmploymentServiceBuffer2);
                    //alternative.AddUtilityTerm(106, logOfOnePlusEmploymentAgrConstrBuffer2);
                    //alternative.AddUtilityTerm(107, logOfOnePlusEmploymentJobsBuffer2);

                    // Size terms
                    alternative.AddUtilityTerm(110, destinationParcel.EmploymentEducation);
                    alternative.AddUtilityTerm(111, destinationParcel.EmploymentGovernment);
                    alternative.AddUtilityTerm(112, destinationParcel.EmploymentIndustrial);
                    alternative.AddUtilityTerm(113, destinationParcel.EmploymentOffice);
                    alternative.AddUtilityTerm(114, destinationParcel.EmploymentRetail);
                    // GV 115 is fixed to zero
                    alternative.AddUtilityTerm(115, destinationParcel.EmploymentService);
                    alternative.AddUtilityTerm(116, destinationParcel.EmploymentAgricultureConstruction);
                    alternative.AddUtilityTerm(117, destinationParcel.EmploymentTotal);
                    alternative.AddUtilityTerm(118, destinationParcel.Households);
                }
                else if (tour.DestinationPurpose == Global.Settings.Purposes.Shopping)
                {
                    //alternative.AddUtilityTerm(120, piecewiseDistanceFrom0To1Km);
                    alternative.AddUtilityTerm(121, piecewiseDistanceFrom0To2Km);
                    alternative.AddUtilityTerm(122, piecewiseDistanceFrom2To5Km);
                    alternative.AddUtilityTerm(123, piecewiseDistanceFrom5To10Km);
                    alternative.AddUtilityTerm(124, piecewiseDistanceFrom10To20Km);
                    alternative.AddUtilityTerm(125, piecewiseDistanceFrom20KmToInfinity);

                    //GV: june 2016 - not sign
                    //alternative.AddUtilityTerm(126, aggregateLogsumHomeBased);

                    // Neighborhood
                    //GV: commented out just temp.
                    //alternative.AddUtilityTerm(130, logOfOnePlusEmploymentEducationBuffer2);
                    alternative.AddUtilityTerm(131, logOfOnePlusEmploymentRetailBuffer2);
                    //alternative.AddUtilityTerm(132, logOfOnePlusEmploymentJobsBuffer2);

                    // Size terms
                    alternative.AddUtilityTerm(140, destinationParcel.EmploymentOffice);
                    alternative.AddUtilityTerm(141, destinationParcel.EmploymentRetail);
                    // GV 142 is fixed to zero
                    alternative.AddUtilityTerm(142, destinationParcel.EmploymentService);
                    alternative.AddUtilityTerm(143, destinationParcel.EmploymentTotal);
                }
                else if (tour.DestinationPurpose == Global.Settings.Purposes.Social)
                {
                    //alternative.AddUtilityTerm(170, piecewiseDistanceFrom0To1Km);
                    //alternative.AddUtilityTerm(171, piecewiseDistanceFrom1To2Km);
                    alternative.AddUtilityTerm(170, piecewiseDistanceFrom0To2Km);
                    alternative.AddUtilityTerm(172, piecewiseDistanceFrom2To5Km);
                    alternative.AddUtilityTerm(173, piecewiseDistanceFrom5To10Km);
                    alternative.AddUtilityTerm(174, piecewiseDistanceFrom10To20Km);
                    alternative.AddUtilityTerm(175, piecewiseDistanceFrom20KmToInfinity);

                    //GV: june 2016 - not sign
                    //alternative.AddUtilityTerm(176, aggregateLogsumHomeBased);

                    // Neighborhood
                    //GV: commented out just temp.
                    //alternative.AddUtilityTerm(180, logOfOnePlusEmploymentOfficeBuffer2);
                    alternative.AddUtilityTerm(181, logOfOnePlusEmploymentRetailBuffer2);
                    alternative.AddUtilityTerm(182, logOfOnePlusEmploymentServiceBuffer2);
                    //alternative.AddUtilityTerm(183, logOfOnePlusEmploymentJobsBuffer2);

                    // Size terms
                    alternative.AddUtilityTerm(190, destinationParcel.EmploymentEducation);
                    alternative.AddUtilityTerm(191, destinationParcel.EmploymentGovernment);
                    alternative.AddUtilityTerm(192, destinationParcel.EmploymentIndustrial);
                    alternative.AddUtilityTerm(193, destinationParcel.EmploymentOffice);
                    alternative.AddUtilityTerm(194, destinationParcel.EmploymentRetail);
                    // GV 195 is fixed to zero
                    alternative.AddUtilityTerm(195, destinationParcel.EmploymentService);
                    alternative.AddUtilityTerm(196, destinationParcel.EmploymentAgricultureConstruction);
                    alternative.AddUtilityTerm(197, destinationParcel.EmploymentTotal);
                    alternative.AddUtilityTerm(198, destinationParcel.Households);
                }
            }
        }
Пример #16
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
        }
Пример #17
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, HouseholdDayWrapper householdDay, int jHTSimulated, int genChoice, bool[,] jHTAvailable, bool[] fHTAvailable, int[][] altParticipants, int choice = Constants.DEFAULT_VALUE)
        {
            IEnumerable <PersonDayWrapper> orderedPersonDays = householdDay.PersonDays.OrderBy(p => p.GetJointHalfTourParticipationPriority()).ToList().Cast <PersonDayWrapper>();

            int pairedHalfTour = genChoice == 1 ? 1 : 0;
            int firstHalfTour  = genChoice == 2 ? 1 : 0;
            int secondHalfTour = genChoice == 3 ? 1 : 0;

            // set household characteristics here that don't depend on person characteristics

            var carOwnership =
                householdDay.Household.VehiclesAvailable == 0
                             ? Global.Settings.CarOwnerships.NoCars
                             : householdDay.Household.VehiclesAvailable < householdDay.Household.HouseholdTotals.DrivingAgeMembers
                                  ? Global.Settings.CarOwnerships.LtOneCarPerAdult
                                  : Global.Settings.CarOwnerships.OneOrMoreCarsPerAdult;
            int hhsize             = householdDay.Household.Size;
            var noCarsFlag         = FlagUtility.GetNoCarsFlag(carOwnership);
            var carCompetitionFlag = FlagUtility.GetCarCompetitionFlag(carOwnership);

            var votALSegment         = householdDay.Household.GetVotALSegment();
            var transitAccessSegment = householdDay.Household.ResidenceParcel.TransitAccessSegment();
            var totalAggregateLogsum = Global.AggregateLogsums[householdDay.Household.ResidenceParcel.ZoneId]
                                       [Global.Settings.Purposes.HomeBasedComposite][carOwnership][votALSegment][transitAccessSegment];

            IPersonDayWrapper pPersonDay = null;

            IParcelWrapper[] pUsualLocation   = new IParcelWrapper[6];
            int[]            pUsualLocationId = new int[6];
            int[]            pPatternType     = new int[6];
            int[]            pConstant        = new int[6];
            int[,] pType = new int[9, 6];
            int[] pAdult = new int[6];
            int[] pChild = new int[6];
            int[] pAge   = new int[6];


            int[] pAdultFemale        = new int[6];
            int[] pAdultMandatory     = new int[6];
            int[] pNonMandatory       = new int[6];
            int[] pFemaleNonMandatory = new int[6];

            int[] pAdultWithChildrenUnder16 = new int[6];

            int[] pType7AgeUnder12 = new int[6];
            int[] pType7Age12Plus  = new int[6];
            int[] pAgeUnder13      = new int[6];
            int[] pAge5To8         = new int[6];
            int[] pAge9To12        = new int[6];
            int[] pAge13To15       = new int[6];

            int[]  pTransitAdult = new int[6];
            int[]  pTransitChild = new int[6];
            int[]  pDrivingAge   = new int[6];
            bool[] pHasMandatoryTourToUsualLocation = new bool[6];
            bool[] pIsDrivingAge = new bool[6];

            int count = 0;

            foreach (PersonDayWrapper personDay in orderedPersonDays)
            {
                count++;
                if (count <= 5)
                {
                    if (count == 1)
                    {
                        pPersonDay = personDay;
                    }
                    // set characteristics here that depend on person characteristics
                    if (personDay.Person.IsFullOrPartTimeWorker && personDay.Person.UsualWorkParcel != null)
                    {
                        pUsualLocation[count] = personDay.Person.UsualWorkParcel;
                    }
                    else if (personDay.Person.IsStudent && personDay.Person.UsualSchoolParcel != null)
                    {
                        pUsualLocation[count] = personDay.Person.UsualSchoolParcel;
                    }
                    else if (personDay.Person.IsWorker && personDay.Person.IsNotFullOrPartTimeWorker && personDay.Person.UsualWorkParcel != null)
                    {
                        pUsualLocation[count] = personDay.Person.UsualWorkParcel;
                    }
                    else
                    {
                        pUsualLocation[count] = personDay.Household.ResidenceParcel;
                    }

                    for (int i = 1; i < 9; i++)
                    {
                        pType[personDay.Person.PersonType, count] = 1;
                    }

                    pPatternType[count] = personDay.PatternType;
                    pConstant[count]    = 1;
                    pAdult[count]       = personDay.Person.IsAdult.ToFlag();
                    pChild[count]       = (!(personDay.Person.IsAdult)).ToFlag();
                    pAdultWithChildrenUnder16[count] = (personDay.Person.IsAdult && personDay.Household.HasChildrenUnder16).ToFlag();
                    pAdultFemale[count]        = personDay.Person.IsAdultFemale.ToFlag();
                    pAdultMandatory[count]     = personDay.Person.IsAdult.ToFlag() * (personDay.PatternType == Global.Settings.PatternTypes.Mandatory).ToFlag();
                    pNonMandatory[count]       = (personDay.PatternType == Global.Settings.PatternTypes.Optional).ToFlag();
                    pFemaleNonMandatory[count] = personDay.Person.IsAdultFemale.ToFlag() * (personDay.PatternType == Global.Settings.PatternTypes.Optional).ToFlag();
                    pType7AgeUnder12[count]    = (personDay.Person.IsChildAge5Through15 && personDay.Person.Age < 12).ToFlag();
                    pType7Age12Plus[count]     = (personDay.Person.IsChildAge5Through15 && personDay.Person.Age >= 12).ToFlag();
                    pAgeUnder13[count]         = (personDay.Person.Age < 13).ToFlag();
                    pAge5To8[count]            = (personDay.Person.Age >= 5 && personDay.Person.Age <= 8).ToFlag();
                    pAge9To12[count]           = (personDay.Person.Age >= 9 && personDay.Person.Age <= 12).ToFlag();
                    pAge13To15[count]          = (personDay.Person.Age >= 13 && personDay.Person.Age <= 15).ToFlag();
                    pTransitAdult[count]       = (personDay.Person.TransitPassOwnership == 1 ? 1 : 0) * (personDay.Person.IsAdult.ToFlag());
                    pTransitChild[count]       = (personDay.Person.TransitPassOwnership == 1 ? 1 : 0) * ((!personDay.Person.IsAdult).ToFlag());
                    pDrivingAge[count]         = personDay.Person.IsDrivingAge.ToFlag();

                    pHasMandatoryTourToUsualLocation[count] = personDay.HasMandatoryTourToUsualLocation;
                    pIsDrivingAge[count] = personDay.Person.IsDrivingAge;
                }
            }
            var componentIndex = 0;

            //Create person utility components
            int[] componentPerson = new int[6];
            for (var p = 1; p <= 5; p++)
            {
                // create component for basic person-purposes
                componentIndex++;
                componentPerson[p] = componentIndex;
                choiceProbabilityCalculator.CreateUtilityComponent(componentPerson[p]);

                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(01, pType[1, p]);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(02, pType[2, p]);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(03, pType[3, p]);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(04, pType[4, p]);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(05, pType[5, p]);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(06, pType[6, p]);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(07, pType[7, p]);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(08, pType[8, p]);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(09, pAge5To8[p]);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(10, pAge9To12[p]);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(11, pAdultFemale[p]);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(12, pNonMandatory[p]);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(13, pFemaleNonMandatory[p]);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(14, pTransitAdult[p]);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(15, pTransitChild[p]);

                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(21, pType[1, p] * secondHalfTour);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(22, pType[2, p] * secondHalfTour);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(23, pType[3, p] * secondHalfTour);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(24, pType[4, p] * secondHalfTour);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(25, pType[5, p] * secondHalfTour);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(26, pType[6, p] * secondHalfTour);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(27, pType[7, p] * secondHalfTour);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(28, pType[8, p] * secondHalfTour);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(29, pAge5To8[p] * secondHalfTour);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(30, pAge9To12[p] * secondHalfTour);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(31, pAdultFemale[p] * secondHalfTour);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(32, pNonMandatory[p] * secondHalfTour);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(33, pFemaleNonMandatory[p] * secondHalfTour);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(34, pTransitAdult[p] * secondHalfTour);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(35, pTransitChild[p] * secondHalfTour);

                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(41, pType[1, p] * pairedHalfTour);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(42, pType[2, p] * pairedHalfTour);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(43, pType[3, p] * pairedHalfTour);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(44, pType[4, p] * pairedHalfTour);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(45, pType[5, p] * pairedHalfTour);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(46, pType[6, p] * pairedHalfTour);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(47, pType[7, p] * pairedHalfTour);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(48, pType[8, p] * pairedHalfTour);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(49, pAge5To8[p] * pairedHalfTour);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(50, pAge9To12[p] * pairedHalfTour);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(51, pAdultFemale[p] * pairedHalfTour);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(52, pNonMandatory[p] * pairedHalfTour);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(53, pFemaleNonMandatory[p] * pairedHalfTour);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(54, pTransitAdult[p] * pairedHalfTour);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(55, pTransitChild[p] * pairedHalfTour);
            }

            //create two-way match interaction utility components
            int[,] componentMatch   = new int[6, 6];
            int[,] iMatchAgeUnder13 = new int[6, 6];
            int[,] iMatchAdult      = new int[6, 6];
            int[,] iMatchAdultWithChildrenUnder16 = new int[6, 6];

            int[,] iMatchMandatoryAdults  = new int[6, 6];
            int[,] iMatchChild            = new int[6, 6];
            int[,] iMatchNonMandatory     = new int[6, 6];
            int[,] iMatchAdultsCarDeficit = new int[6, 6];
            int[,] iMatchAdultCountAtHome = new int[6, 6];


            for (var t2 = 1; t2 <= 5; t2++)
            {
                for (var t1 = 1; t1 < t2; t1++)
                {
                    //populate match variables
                    iMatchAgeUnder13[t1, t2] = pAgeUnder13[t1] * pAgeUnder13[t2];
                    iMatchAdult[t1, t2]      = pAdult[t1] * pAdult[t2];
                    iMatchAdultWithChildrenUnder16[t1, t2] = pAdultWithChildrenUnder16[t1] * pAdultWithChildrenUnder16[t2];

                    iMatchMandatoryAdults[t1, t2]  = pAdultMandatory[t1] * pAdultMandatory[t2];
                    iMatchChild[t1, t2]            = (1 - pAdult[t1]) * (1 - pAdult[t2]);
                    iMatchNonMandatory[t1, t2]     = pNonMandatory[t1] * pNonMandatory[t2];
                    iMatchAdultsCarDeficit[t1, t2] = pAdult[t1] * pAdult[t2] * (carCompetitionFlag + noCarsFlag);


                    //create and populate components
                    componentIndex++;
                    componentMatch[t1, t2] = componentIndex;
                    choiceProbabilityCalculator.CreateUtilityComponent(componentMatch[t1, t2]);
                    choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(61, iMatchAgeUnder13[t1, t2]);
                    choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(62, iMatchAdult[t1, t2]);
                    choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(63, iMatchMandatoryAdults[t1, t2]);
                    choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(64, iMatchNonMandatory[t1, t2]);
                    //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(65, iMatchAdultWithChildrenUnder16[t1, t2]);
                    choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(66, iMatchChild[t1, t2]);
                    //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(67, iMatchAdultsCarDeficit[t1, t2]);

                    //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(71, iMatchAgeUnder13[t1, t2] * secondHalfTour);
                    //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(72, iMatchAdult[t1, t2] * secondHalfTour);
                    //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(73, iMatchMandatoryAdults[t1, t2] * secondHalfTour);
                    //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(74, iMatchNonMandatory[t1, t2] * secondHalfTour);
                    //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(75, iMatchAdultWithChildrenUnder16[t1, t2] * secondHalfTour);
                    //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(76, iMatchChild[t1, t2] * secondHalfTour);
                    //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(77, iMatchAdultsCarDeficit[t1, t2] * secondHalfTour);

                    //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(81, iMatchAgeUnder13[t1, t2] * pairedHalfTour);
                    //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(82, iMatchAdult[t1, t2] * pairedHalfTour);
                    choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(83, iMatchMandatoryAdults[t1, t2] * pairedHalfTour);
                    //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(84, iMatchNonMandatory[t1, t2] * pairedHalfTour);
                    //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(85, iMatchAdultWithChildrenUnder16[t1, t2] * pairedHalfTour);
                    //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(86, iMatchChild[t1, t2] * pairedHalfTour);
                    //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(87, iMatchAdultsCarDeficit[t1, t2] * pairedHalfTour);
                }
            }

            //create two-way cross interaction utility components
            int[,] componentCross = new int[6, 6];
            int iCrossAgeUnder5AndNonMandatory;
            int iCrossAge5To12AndNonMandatory;
            int iCrossAge13To15AndNonMandatory;
            int iCrossDrivingAgeChildAndNonMandatory;

            for (var t2 = 1; t2 <= 5; t2++)
            {
                for (var t1 = 1; t1 <= 5; t1++)
                {
                    if (!(t1 == t2))
                    {
                        //populate cross variables
                        iCrossAge5To12AndNonMandatory        = pNonMandatory[t1] * (pAge5To8[t2] + pAge9To12[t2]);
                        iCrossAgeUnder5AndNonMandatory       = pNonMandatory[t1] * pType[8, t2];
                        iCrossAge13To15AndNonMandatory       = pNonMandatory[t1] * pAge13To15[t2];
                        iCrossDrivingAgeChildAndNonMandatory = pNonMandatory[t1] * pType[6, t2];

                        //create and populate cross components
                        componentIndex++;
                        componentCross[t1, t2] = componentIndex;
                        choiceProbabilityCalculator.CreateUtilityComponent(componentCross[t1, t2]);
                        choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(91, iCrossAgeUnder5AndNonMandatory);
                        //choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(92, iCrossAge5To12AndNonMandatory);
                        choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(93, iCrossAge13To15AndNonMandatory);
                        //choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(94, iCrossDrivingAgeChildAndNonMandatory);

                        //choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(95, iCrossAgeUnder5AndNonMandatory * secondHalfTour);
                        //choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(96, iCrossAgeUnder5AndNonMandatory * pairedHalfTour);
                    }
                }
            }

            //Generate utility funtions for the alternatives
            bool[] available = new bool[32];
            bool[] chosen    = new bool[32];
            int    numberOfParticipants;
            int    workersParticipating;
            int    numberOfParticipatingChildren;
            int    numberOfParticipatingAdults;
            int    numberOfAvailableChildren;
            int    numberOfAvailablePersons;
            int    numberOfAvailableAdults;

            for (int alt = 0; alt < 32; alt++)
            {
                available[alt] = false;
                chosen[alt]    = false;
                // set availability based on household size
                if (hhsize >= altParticipants[alt][6])
                {
                    available[alt] = true;
                }
                // restrict availability based on person unavailability
                for (int i = 1; i <= 5; i++)
                {
                    if (altParticipants[alt][i] == 1 && (jHTAvailable[genChoice - 1, i] == false || fHTAvailable[i] == false))
                    {
                        available[alt] = false;
                    }
                }
                // restrict availability to cases where all non-driving age participants have same usual location
                // first determine first non-adult's usual location
                IParcelWrapper sameUsualLocation = householdDay.Household.ResidenceParcel;
                for (int i = 1; i <= 5; i++)
                {
                    if (altParticipants[alt][i] == 1 && pPatternType[i] == 1 && pUsualLocation[i].Id > 0 && !(pDrivingAge[i] == 1))
                    {
                        sameUsualLocation = pUsualLocation[i];
                        break;
                    }
                }
                // then make alt unavailable if any M-Usual participant has a different usualLocation
                for (int i = 1; i <= 5; i++)
                {
                    if (altParticipants[alt][i] == 1 && pHasMandatoryTourToUsualLocation[i] && !(pUsualLocation[i].Id == sameUsualLocation.Id) && !(pDrivingAge[i] == 1))
                    {
                        available[alt] = false;
                        break;
                    }
                }
                // restrict availability of alts that include less than 2 participants
                if (altParticipants[alt][7] < 2)
                {
                    available[alt] = false;
                }

                // restrict availability if 2+ participants lack tour to usual location
                int numberLackMandatoryTourToUsualLocation = 0;
                for (int i = 1; i <= 5; i++)
                {
                    if (altParticipants[alt][i] == 1 && !pHasMandatoryTourToUsualLocation[i])
                    {
                        numberLackMandatoryTourToUsualLocation++;
                    }
                }
                if (numberLackMandatoryTourToUsualLocation > 1)
                {
                    available[alt] = false;
                }

                //JLB 20140404 remove the drivign age requirement because children can walk, bik or take bus to/from school without an adult.
                // require at least one driving age (as chauffeur)
                //int numberDrivingAge = 0;
                //for (int i = 1; i <= 5; i++) {
                //    if (altParticipants[alt][i] == 1 && pIsDrivingAge[i]) {
                //        numberDrivingAge++;
                //    }
                //}
                //if (numberDrivingAge == 0) {
                //    available[alt] = false;
                //}


                // Generate alt-specific variables
                numberOfParticipants          = 0;
                workersParticipating          = 0;
                numberOfParticipatingChildren = 0;
                numberOfParticipatingAdults   = 0;
                numberOfAvailableChildren     = 0;
                numberOfAvailablePersons      = 0;
                numberOfAvailableAdults       = 0;
                if (available[alt] == true)
                {
                    for (int i = 1; i <= 5; i++)
                    {
                        if (pChild[i] == 1 && pUsualLocation[i].Id == sameUsualLocation.Id)
                        {
                            numberOfAvailableChildren++;
                            numberOfAvailablePersons++;
                        }
                        if (pAdult[i] == 1 && (pPatternType[i] == Global.Settings.PatternTypes.Optional || pUsualLocation[i].Id == sameUsualLocation.Id))
                        {
                            numberOfAvailableChildren++;
                            numberOfAvailableAdults++;
                        }

                        if (altParticipants[alt][i] == 1)
                        {
                            numberOfParticipants++;
                            if (pType[0, i] == 1 || pType[1, i] == 1)
                            {
                                workersParticipating++;
                            }
                            if (pAdult[i] == 1)
                            {
                                numberOfParticipatingAdults++;
                            }
                            if (pChild[i] == 1)
                            {
                                numberOfParticipatingChildren++;
                            }
                        }
                    }
                }

                double tourLogsum               = 0;
                var    destinationArrivalTime   = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.WorkTourModeModel);
                var    destinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.WorkTourModeModel);
                var    nestedAlternative        = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().RunNested(pPersonDay, pPersonDay.Household.ResidenceParcel, sameUsualLocation, destinationArrivalTime, destinationDepartureTime, pPersonDay.Household.VehiclesAvailable);
                tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();

                // determine choice
                if (choice == alt)
                {
                    chosen[alt] = true;
                }

                //Get the alternative
                var alternative = choiceProbabilityCalculator.GetAlternative(alt, available[alt], chosen[alt]);

                alternative.Choice = alt;

                //Add alt-specific utility terms
                alternative.AddUtilityTerm(101, (numberOfParticipatingAdults > 1 && numberOfParticipatingChildren > 0) ? 1 : 0);
                alternative.AddUtilityTerm(102, (numberOfParticipatingChildren < numberOfAvailableChildren) ? 1 : 0);
                alternative.AddUtilityTerm(103, (numberOfParticipatingAdults == 0) ? 1 : 0);
                //alternative.AddUtilityTerm(104, (numberOfParticipants < numberOfAvailablePersons) ? 1 : 0);
                alternative.AddUtilityTerm(105, tourLogsum);

                //alternative.AddUtilityTerm(105, ((numberOfParticipatingAdults > 1 && numberOfParticipatingChildren > 0) ? 1 : 0) * secondHalfTour);
                //alternative.AddUtilityTerm(106, ((numberOfParticipatingAdults > 1 && numberOfParticipatingChildren > 0) ? 1 : 0) * pairedHalfTour);



                //Add utility components

                for (int p = 1; p <= 5; p++)
                {
                    if (altParticipants[alt][p] == 1)
                    {
                        alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]));
                    }
                }
                for (var t2 = 1; t2 <= 5; t2++)
                {
                    for (var t1 = 1; t1 < t2; t1++)
                    {
                        if (altParticipants[alt][t1] == 1 && altParticipants[alt][t2] == 1)
                        {
                            alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]));
                        }
                    }
                }
                for (var t2 = 1; t2 <= 5; t2++)
                {
                    for (var t1 = 1; t1 <= 5; t1++)
                    {
                        if (!(t1 == t2))
                        {
                            if (altParticipants[alt][t1] == 1 && altParticipants[alt][t2] == 1)
                            {
                                alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]));
                            }
                        }
                    }
                }
            }
        }
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, HouseholdDayWrapper householdDay, int nCallsForTour, bool[] available, int choice = Constants.DEFAULT_VALUE)
        {
            //var householdDay = (LDHouseholdDayWrapper)tour.HouseholdDay;
            var household = householdDay.Household;

            Double workTourLogsum   = 0;
            Double schoolTourLogsum = 0;

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

            foreach (PersonDayWrapper personDay in orderedPersonDays)
            {
                //Double workTourLogsum;
                if (personDay.Person.UsualWorkParcelId != Constants.DEFAULT_VALUE && personDay.Person.UsualWorkParcelId != Global.Settings.OutOfRegionParcelId)
                {
                    //JLB 201406
                    //var nestedAlternative = Global.ChoiceModelSession.Get<WorkTourModeModel>().RunNested(personDay.Person, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualWorkParcel, Global.Settings.Times.EightAM, Global.Settings.Times.FivePM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers);
                    var nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().RunNested(personDay, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualWorkParcel, Global.Settings.Times.EightAM, Global.Settings.Times.FivePM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers);
                    workTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                }
                else
                {
                    workTourLogsum = 0;
                }

                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);
                    var nestedAlternative = Global.ChoiceModelSession.Get <SchoolTourModeTimeModel>().RunNested(personDay, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualSchoolParcel, Global.Settings.Times.EightAM, Global.Settings.Times.FivePM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers);
                    schoolTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                }
                else
                {
                    schoolTourLogsum = 0;
                }
            }

            var carOwnership =
                household.VehiclesAvailable == 0
                                                        ? Global.Settings.CarOwnerships.NoCars
                                                        : household.VehiclesAvailable < household.HouseholdTotals.DrivingAgeMembers
                                                                ? Global.Settings.CarOwnerships.LtOneCarPerAdult
                                                                : Global.Settings.CarOwnerships.OneOrMoreCarsPerAdult;

            var noCarsFlag         = FlagUtility.GetNoCarsFlag(carOwnership);
            var carCompetitionFlag = FlagUtility.GetCarCompetitionFlag(carOwnership);

            var votALSegment                    = Global.Settings.VotALSegments.Medium; // TODO:  calculate a VOT segment that depends on household income
            var transitAccessSegment            = household.ResidenceParcel.TransitAccessSegment();
            var personalBusinessAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                                  [Global.Settings.Purposes.PersonalBusiness][carOwnership][votALSegment][transitAccessSegment];
            var shoppingAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                          [Global.Settings.Purposes.Shopping][carOwnership][votALSegment][transitAccessSegment];
            var mealAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                      [Global.Settings.Purposes.Meal][carOwnership][votALSegment][transitAccessSegment];
            var socialAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                        [Global.Settings.Purposes.Social][carOwnership][votALSegment][transitAccessSegment];
            //var compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][carOwnership][votALSegment][transitAccessSegment];
            var compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.NoCars][votALSegment][transitAccessSegment];

            int youngestAge = 999;

            foreach (PersonWrapper person in householdDay.Household.Persons)
            {
                // set characteristics here that depend on person characteristics
                if (person.Age < youngestAge)
                {
                    youngestAge = person.Age;
                }
            }


            // NONE_OR_HOME

            var alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.NoneOrHome, available[0], choice == Global.Settings.Purposes.NoneOrHome);

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

            alternative.AddUtilityTerm(1, (nCallsForTour > 1).ToFlag());

            alternative.AddUtilityTerm(2, householdDay.Household.HasChildrenUnder5.ToFlag());
            alternative.AddUtilityTerm(3, householdDay.Household.HasChildrenAge5Through15.ToFlag());
            alternative.AddUtilityTerm(4, (householdDay.Household.Size == 2 && householdDay.AdultsInSharedHomeStay == 2).ToFlag());
            alternative.AddUtilityTerm(5, (householdDay.AdultsInSharedHomeStay == 1 && householdDay.Household.HasChildrenUnder16).ToFlag());
            alternative.AddUtilityTerm(6, (householdDay.AdultsInSharedHomeStay == 2 && householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag());
            //alternative.AddUtilityTerm(7, (householdDay.AdultsInSharedHomeStay == 2 && hasAdultEducLevel12 == 1).ToFlag());
            //alternative.AddUtilityTerm(8, (youngestAge >= 40).ToFlag());

            //alternative.AddUtilityTerm(10, (householdDay.Household.Income >= 300000 && householdDay.Household.Income < 600000).ToFlag());
            //alternative.AddUtilityTerm(11, (householdDay.Household.Income >= 600000 && householdDay.Household.Income < 900000).ToFlag());
            //alternative.AddUtilityTerm(12, (householdDay.Household.Income >= 900000).ToFlag());

            //alternative.AddUtilityTerm(15, householdDay.PrimaryPriorityTimeFlag);

            //alternative.AddUtilityTerm(21, personDay.Person.IsPartTimeWorker.ToFlag()); //GV - Aks John to include peson.Day in the model
            //alternative.AddUtilityTerm(2, personDay.Person.IsFulltimeWorker.ToFlag()); //GV - Aks John to include peson.Day in the model

            //alternative.AddUtilityTerm(22, (personDay.Person.Gender == 1).ToFlag()); //GV - Aks John to include peson.Day in the model
            //alternative.AddUtilityTerm(23, (hasAdultEducLevel12 == 1).ToFlag()); //GV - Aks John to include peson.Day in the model

            //alternative.AddUtilityTerm(24, MandatoryTourDay); //GV - Aks John to include peson.Day in the model
            //alternative.AddUtilityTerm(25, nonMandatoryTourDay); //GV - Aks John to include peson.Day in the model
            //alternative.AddUtilityTerm(26, atHomeDay); //GV - Aks John to include peson.Day in the model

            alternative.AddUtilityTerm(7, (householdDay.Household.VehiclesAvailable == 1 && household.Has2Drivers).ToFlag());
            alternative.AddUtilityTerm(8, (householdDay.Household.VehiclesAvailable >= 2 && household.Has2Drivers).ToFlag());

            alternative.AddUtilityTerm(9, (householdDay.Household.Size == 3).ToFlag());
            alternative.AddUtilityTerm(10, (householdDay.Household.Size >= 4).ToFlag());


            // FULL PAIRED
            alternative        = choiceProbabilityCalculator.GetAlternative(1, available[1], choice == 1);
            alternative.Choice = 1;
            alternative.AddUtilityTerm(11, 1);

            //alternative.AddUtilityTerm(12, workTourLogsum);
            alternative.AddUtilityTerm(13, schoolTourLogsum);

            //alternative.AddUtilityTerm(13, householdDay.PrimaryPriorityTimeFlag);

            //alternative.AddNestedAlternative(12, 1, 70);

            // FULL HalfTour 1
            alternative        = choiceProbabilityCalculator.GetAlternative(2, available[2], choice == 2);
            alternative.Choice = 2;
            alternative.AddUtilityTerm(21, 1);

            alternative.AddUtilityTerm(12, workTourLogsum);
            //alternative.AddUtilityTerm(13, schoolTourLogsum);

            //alternative.AddUtilityTerm(23, householdDay.PrimaryPriorityTimeFlag);

            //alternative.AddNestedAlternative(12, 1, 70);

            // Full HalfTour 2
            alternative        = choiceProbabilityCalculator.GetAlternative(3, available[3], choice == 3);
            alternative.Choice = 3;
            alternative.AddUtilityTerm(31, 1);

            alternative.AddUtilityTerm(12, workTourLogsum);
            //alternative.AddUtilityTerm(13, schoolTourLogsum);

            //alternative.AddUtilityTerm(33, householdDay.PrimaryPriorityTimeFlag);

            //alternative.AddNestedAlternative(12, 1, 70);

            // PARTIAL PAIRED
            alternative        = choiceProbabilityCalculator.GetAlternative(4, available[4], choice == 4);
            alternative.Choice = 4;
            alternative.AddUtilityTerm(41, 1);

            alternative.AddUtilityTerm(42, workTourLogsum);
            alternative.AddUtilityTerm(43, schoolTourLogsum);

            alternative.AddUtilityTerm(44, householdDay.PrimaryPriorityTimeFlag);

            //alternative.AddNestedAlternative(12, 1, 70);

            // PARTIAL HalfTour 1
            alternative        = choiceProbabilityCalculator.GetAlternative(5, available[5], choice == 5);
            alternative.Choice = 5;
            alternative.AddUtilityTerm(51, 1);

            alternative.AddUtilityTerm(42, workTourLogsum);
            //alternative.AddUtilityTerm(43, schoolTourLogsum);

            alternative.AddUtilityTerm(54, householdDay.PrimaryPriorityTimeFlag);

            //alternative.AddNestedAlternative(12, 1, 70);

            // PARTIAL HalfTour 2
            alternative        = choiceProbabilityCalculator.GetAlternative(6, available[6], choice == 6);
            alternative.Choice = 6;
            alternative.AddUtilityTerm(61, 1);

            alternative.AddUtilityTerm(42, workTourLogsum);
            //alternative.AddUtilityTerm(43, schoolTourLogsum);

            alternative.AddUtilityTerm(64, householdDay.PrimaryPriorityTimeFlag);

            //alternative.AddNestedAlternative(12, 1, 70);
        }
Пример #19
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, HouseholdDayWrapper householdDay, int nCallsForTour, int[] purpose, int[][] altParticipants, int choice = Constants.DEFAULT_VALUE)
        {
            IEnumerable<PersonDayWrapper> orderedPersonDays = householdDay.PersonDays.OrderBy(p => p.GetJointTourParticipationPriority()).ToList().Cast<PersonDayWrapper>();
              // set household characteristics here that don't depend on person characteristics

              int carOwnership =
                householdDay.Household.VehiclesAvailable == 0
                     ? Global.Settings.CarOwnerships.NoCars
                     : householdDay.Household.VehiclesAvailable < householdDay.Household.HouseholdTotals.DrivingAgeMembers
                          ? Global.Settings.CarOwnerships.LtOneCarPerAdult
                          : Global.Settings.CarOwnerships.OneOrMoreCarsPerAdult;
              int hhsize = householdDay.Household.Size;
              int noCarsFlag = FlagUtility.GetNoCarsFlag(carOwnership);
              int carCompetitionFlag = FlagUtility.GetCarCompetitionFlag(carOwnership);

              int tourPurpose = purpose[nCallsForTour];

              int escortPurpose = purpose[nCallsForTour] == Global.Settings.Purposes.Escort ? 1 : 0;
              int shopPurpose = purpose[nCallsForTour] == Global.Settings.Purposes.Shopping ? 1 : 0;
              int socialPurpose = (purpose[nCallsForTour] == Global.Settings.Purposes.Social ? 1 : 0);
              int recreationPurpose = (purpose[nCallsForTour] == Global.Settings.Purposes.Recreation) ? 1 : 0;
              int personalBusinessMedicalPurpose = (purpose[nCallsForTour] == Global.Settings.Purposes.PersonalBusiness
                                                   || purpose[nCallsForTour] == Global.Settings.Purposes.Medical) ? 1 : 0;
              int meal = (purpose[nCallsForTour] == Global.Settings.Purposes.Meal) ? 1 : 0;
              int socialRecreationPurpose = (purpose[nCallsForTour] == Global.Settings.Purposes.Social ||
                                              purpose[nCallsForTour] == Global.Settings.Purposes.Recreation) ? 1 : 0;
              //nt recreationPurpose =    (purpose[nCallsForTour] == Global.Settings.Purposes.Recreation)     ? 1 : 0;

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

              PersonDayWrapper pPersonDay = null;

              bool[] pLessThan3NonMandatoryTours = new bool[6];
              bool[] pLessThan3TourPurposes = new bool[6];
              int[] pUsualLocationParcelId = new int[6];
              int[] pUsualLocationZoneId = new int[6];
              IParcelWrapper[] pUsualLocationParcel = new IParcelWrapper[6];
              int[] pPatternType = new int[6];
              int[] pConstant = new int[6];
              int[,] pType = new int[9, 6];
              int[] pAdult = new int[6];
              int[] pChild = new int[6];
              int[] pAge = new int[6];

              //int[] pAdultMale = new int[6];
              int[] pAdultFemale = new int[6];
              int[] pAdultMandatory = new int[6];
              int[] pNonMandatory = new int[6];
              int[] pMandatory = new int[6];
              int[] pAdultNonMandatory = new int[6];
              int[] pAdultWithChildrenUnder16 = new int[6];

              int[] pAge5To8 = new int[6];
              int[] pAge9To12 = new int[6];
              int[] pAge13To15 = new int[6];
              int[] pAgeUnder13 = new int[6];

              int[] pTransit = new int[6];

              //int[] pJointNonMandatoryTours = new int[6];
              int[] pJointEscortTours = new int[6];
              int[] pMandatoryTours = new int[6];
              int[] pJointSocialRecreationTours = new int[6];
              //int[] pJointPersMedtours = new int[6];
              int[] pNonMandatoryChild = new int[6];
              int[] pMandatoryChild = new int[6];
              //int[] pJointShopTours = new int[6];
              int[] pJointMealTours = new int[6];

              int count = 0;
              foreach (PersonDayWrapper personDay in orderedPersonDays) {
            count++;
            if (count <= 5) {
              if (count == 1) {
            pPersonDay = personDay;
              }
              for (int i = 1; i < 9; i++) {
            pType[personDay.Person.PersonType, count] = 1;
              }

              if (personDay.Person.IsFullOrPartTimeWorker && personDay.Person.UsualWorkParcel != null) {
            pUsualLocationParcelId[count] = personDay.Person.UsualWorkParcelId;
            pUsualLocationParcel[count] = personDay.Person.UsualWorkParcel;
            pUsualLocationZoneId[count] = personDay.Person.UsualWorkParcel.ZoneId;
              } else if (personDay.Person.IsStudent && personDay.Person.UsualSchoolParcel != null) {
            pUsualLocationParcelId[count] = personDay.Person.UsualSchoolParcelId;
            pUsualLocationParcel[count] = personDay.Person.UsualSchoolParcel;
            pUsualLocationZoneId[count] = personDay.Person.UsualSchoolParcel.ZoneId;
              } else if (personDay.Person.IsWorker && personDay.Person.IsNotFullOrPartTimeWorker && personDay.Person.UsualWorkParcel != null) {
            pUsualLocationParcelId[count] = personDay.Person.UsualWorkParcelId;
            pUsualLocationParcel[count] = personDay.Person.UsualWorkParcel;
            pUsualLocationZoneId[count] = personDay.Person.UsualWorkParcel.ZoneId;
              } else {
            pUsualLocationParcelId[count] = personDay.Household.ResidenceParcelId;
            pUsualLocationParcel[count] = personDay.Household.ResidenceParcel;
            pUsualLocationZoneId[count] = personDay.Household.ResidenceZoneId;
              }

              pLessThan3NonMandatoryTours[count] = personDay.GetCreatedNonMandatoryTours() < 3;
              pLessThan3TourPurposes[count] = personDay.GetTotalCreatedTourPurposes() < 3;
              pPatternType[count] = personDay.PatternType;
              pConstant[count] = 1;
              pAdult[count] = personDay.Person.IsAdult.ToFlag();
              pChild[count] = (!(personDay.Person.IsAdult)).ToFlag();
              pAdultWithChildrenUnder16[count] = (personDay.Person.IsAdult && personDay.Household.HasChildrenUnder16).ToFlag();
              pAdultFemale[count] = personDay.Person.IsAdultFemale.ToFlag();
              //pAdultMale[count] = personDay.Person.IsAdultMale.ToFlag();
              pAdultMandatory[count] = personDay.Person.IsAdult.ToFlag() * (personDay.PatternType == Global.Settings.PatternTypes.Mandatory).ToFlag();
              pNonMandatory[count] = (personDay.PatternType == Global.Settings.PatternTypes.Optional).ToFlag();
              pAdultNonMandatory[count] = (personDay.PatternType == Global.Settings.PatternTypes.Optional).ToFlag() * personDay.Person.IsAdult.ToFlag();
              pAgeUnder13[count] = (personDay.Person.Age < 13).ToFlag();
              pAge5To8[count] = (personDay.Person.Age >= 5 && personDay.Person.Age <= 8).ToFlag();
              //pAge9To12[count] = (personDay.Person.Age >= 9 && personDay.Person.Age <= 12).ToFlag();
              pAge13To15[count] = (personDay.Person.Age >= 13 && personDay.Person.Age <= 15).ToFlag();
              pTransit[count] = (personDay.Person.TransitPassOwnership == 1 ? 1 : 0);
              pMandatory[count] = (personDay.PatternType == Global.Settings.PatternTypes.Mandatory).ToFlag();
              pMandatoryTours[count] = personDay.WorkTours + personDay.SchoolTours;
              pJointEscortTours[count] = personDay.CreatedEscortTours;
              pJointMealTours[count] = personDay.CreatedMealTours;
              //pJointShopTours[count]= personDay.CreatedShoppingTours;
              pJointSocialRecreationTours[count] = personDay.CreatedSocialTours + personDay.CreatedRecreationTours;
              pNonMandatoryChild[count] = (personDay.PatternType == Global.Settings.PatternTypes.Optional).ToFlag() * personDay.Person.IsChildUnder16.ToFlag();
              pMandatoryChild[count] = (personDay.PatternType == Global.Settings.PatternTypes.Mandatory).ToFlag() * personDay.Person.IsChildUnder16.ToFlag();

            }
              }
              int componentIndex = 0;
              //Create person utility components
              int[] componentPerson = new int[6];
              for (int p = 1; p <= 5; p++) {
            // create component for basic person-purposes
            componentIndex++;
            componentPerson[p] = componentIndex;
            choiceProbabilityCalculator.CreateUtilityComponent(componentPerson[p]);

            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(01, pAge5To8[p]);
            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(02, pAdultFemale[p]);
            //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(03, pAge9To12[p]);
            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(05, (pMandatoryTours[p] > 1).ToFlag());
            //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(06, (pJointNonMandatoryTours[p]>1).ToFlag());
            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(07, pAdultMandatory[p]);
            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(08, pTransit[p]);

            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(21, pAdult[p] * escortPurpose);
            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(26, pType[6, p] * pNonMandatory[p] * escortPurpose);
            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(28, pType[8, p] * pNonMandatory[p] * escortPurpose);
            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(29, pType[6, p] * pMandatory[p] * escortPurpose);
            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(30, pType[7, p] * pMandatory[p] * escortPurpose);
            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(31, pType[8, p] * pMandatory[p] * escortPurpose);
            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(32, (pJointEscortTours[p] == 1).ToFlag() * escortPurpose);
            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(33, (pJointEscortTours[p] >= 2).ToFlag() * escortPurpose);

            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(41, pAdult[p] * personalBusinessMedicalPurpose);
            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(44, pNonMandatoryChild[p] * personalBusinessMedicalPurpose);
            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(45, pMandatoryChild[p] * personalBusinessMedicalPurpose);

            //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(51, pAdultMandatory[p]*  shopPurpose);
            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(52, pAdultNonMandatory[p] * shopPurpose);
            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(54, pNonMandatoryChild[p] * shopPurpose);
            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(56, pType[6, p] * pMandatory[p] * shopPurpose);
            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(57, pType[7, p] * pMandatory[p] * shopPurpose);
            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(58, pType[8, p] * pMandatory[p] * shopPurpose);
            //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(59, (pJointShopTours[p]>1).ToFlag() *  shopPurpose);

            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(71, pAdult[p] * meal);
            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(77, (pJointMealTours[p] > 0).ToFlag() * meal);

            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(92, pAdult[p] * socialRecreationPurpose);
            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(96, pType[6, p] * pMandatory[p] * socialRecreationPurpose);
            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(97, pType[7, p] * pMandatory[p] * socialRecreationPurpose);
            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(98, pType[8, p] * pMandatory[p] * socialRecreationPurpose);
            choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(99, (pJointSocialRecreationTours[p] >= 1).ToFlag() * socialRecreationPurpose);
              }

              //create two-way match interaction utility components
              int[,] componentMatch = new int[6, 6];
              int[,] iMatchAdult = new int[6, 6];
              int[,] iMatchAdultWithChildrenUnder16 = new int[6, 6];

              int[,] iMatchMandatoryAdults = new int[6, 6];
              int[,] iMatchNonMandatoryAdults = new int[6, 6];
              int[,] iMatchChild = new int[6, 6];
              int[,] iMatchNonMandatoryKids = new int[6, 6];
              int[,] iMatchMandatoryKids = new int[6, 6];
              int[,] iMatchNonMandatory = new int[6, 6];
              int[,] iMatchUsualLocation = new int[6, 6];

              for (int t2 = 1; t2 <= 5; t2++) {
            for (int t1 = 1; t1 < t2; t1++) {
              //populate match variables
              iMatchAdultWithChildrenUnder16[t1, t2] = pAdultWithChildrenUnder16[t1] * pAdultWithChildrenUnder16[t2];
              iMatchNonMandatoryAdults[t1, t2] = pAdultNonMandatory[t1] * pAdultNonMandatory[t2];
              iMatchMandatoryAdults[t1, t2] = pAdultMandatory[t1] * pAdultMandatory[t2];

              iMatchNonMandatory[t1, t2] = pNonMandatory[t1] * pNonMandatory[t2];
              iMatchUsualLocation[t1, t2] = (pUsualLocationParcelId[t1] == pUsualLocationParcelId[t2]) ? 1 : 0;

              iMatchChild[t1, t2] = (1 - pAdult[t1]) * (1 - pAdult[t2]);
              iMatchNonMandatoryKids[t1, t2] = pNonMandatory[t1] * pAgeUnder13[t1] * pNonMandatory[t2] * pAgeUnder13[t2];
              iMatchMandatoryKids[t1, t2] = pMandatory[t1] * pAgeUnder13[t1] * pMandatory[t2] * pAgeUnder13[t2];

              //create and populate components
              componentIndex++;
              componentMatch[t1, t2] = componentIndex;
              choiceProbabilityCalculator.CreateUtilityComponent(componentMatch[t1, t2]);
              choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(109, iMatchNonMandatoryKids[t1, t2]);
              choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(110, iMatchMandatoryKids[t1, t2]);
              choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(111, iMatchMandatoryAdults[t1, t2]);
              //choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(113, iMatchAdultNonMandatorys[t1, t2]);
              choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(114, iMatchAdultWithChildrenUnder16[t1, t2]);
              choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(116, iMatchNonMandatory[t1, t2] * socialRecreationPurpose);
              choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(124, iMatchChild[t1, t2] * shopPurpose);
              choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(125, iMatchUsualLocation[t1, t2]);

            }
              }

              //create two-way cross interaction utility components
              int[,] componentCross = new int[6, 6];
              int iCrossAgeUnder5AndNonMandatory;
              int iCrossAge5To12AndNonMandatory;
              int iCrossAge13To15AndNonMandatory;
              int iCrossDrivingAgeChildAndNonMandatory;
              int iCrossMandatoryAdAndChild;

              for (int t2 = 1; t2 <= 5; t2++) {
            for (int t1 = 1; t1 <= 5; t1++) {
              if (!(t1 == t2)) {
            //populate cross variables
            iCrossAge5To12AndNonMandatory = pAdultNonMandatory[t1] * (pAge5To8[t2] + pAge9To12[t2]);
            iCrossAgeUnder5AndNonMandatory = pAdultNonMandatory[t1] * pType[8, t2];
            iCrossAge13To15AndNonMandatory = pNonMandatory[t1] * pAge13To15[t2];
            iCrossDrivingAgeChildAndNonMandatory = pNonMandatory[t1] * pType[6, t2];
            iCrossMandatoryAdAndChild = pAdultMandatory[t1] * pChild[t2];
            //create and populate cross components
            componentIndex++;
            componentCross[t1, t2] = componentIndex;
            choiceProbabilityCalculator.CreateUtilityComponent(componentCross[t1, t2]);
            choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(133, iCrossAge13To15AndNonMandatory);
            choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(135, iCrossAgeUnder5AndNonMandatory * escortPurpose);
            choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(136, iCrossAgeUnder5AndNonMandatory * personalBusinessMedicalPurpose);
            choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(137, iCrossAgeUnder5AndNonMandatory * shopPurpose);
            choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(138, iCrossAgeUnder5AndNonMandatory * meal);
            choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(139, iCrossAgeUnder5AndNonMandatory * socialRecreationPurpose);
            choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(144, iCrossAge5To12AndNonMandatory * socialRecreationPurpose);
            //choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(145, iCrossMandatoryAdAndChild*escortPurpose);
            choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(146, iCrossMandatoryAdAndChild * personalBusinessMedicalPurpose);
            choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(147, iCrossMandatoryAdAndChild * shopPurpose);
            choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(148, iCrossMandatoryAdAndChild * meal);
            choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(149, iCrossMandatoryAdAndChild * socialRecreationPurpose);

              }
            }
              }

              //Generate utility funtions for the alternatives
              bool[] available = new bool[32];
              bool[] chosen = new bool[32];
              for (int alt = 0; alt < 32; alt++) {

            available[alt] = false;
            chosen[alt] = false;
            // set availability based on household size
            if (hhsize >= altParticipants[alt][6]) {
              available[alt] = true;
            }
            // restrict availability of alts that include less than 2 participants
            if (altParticipants[alt][7] < 2) {
              available[alt] = false;
            }
            // restrict availability if any participant has at-home patternType
            int numberAtHomePatternTypes = 0;
            for (int i = 1; i <= 5; i++) {
              if (altParticipants[alt][i] == 1 && pPatternType[i] == Global.Settings.PatternTypes.Home) {
            numberAtHomePatternTypes++;
              }
            }
            if (numberAtHomePatternTypes > 0) {
              available[alt] = false;
            }
            // restrict availability if any participant has 3 or more nonmandatory tours already
            for (int i = 1; i <= 5; i++) {
              if (altParticipants[alt][i] == 1 && !pLessThan3NonMandatoryTours[i]) {
            available[alt] = false;
              }
            }

            // restrict availability if any participant has 3 or more tour purposes already
            for (int i = 1; i <= 5; i++) {
              if (altParticipants[alt][i] == 1 && !pLessThan3TourPurposes[i]) {
            available[alt] = false;
              }
            }

            int numberOfParticipants = 0;
            int workersParticipating = 0;
            int numberOfParticipatingChildren = 0;
            int numberOfParticipatingAdults = 0;
            int numberOfAvailableChildren = 0;
            int numberOfAvailablePersons = 0;
            int numberOfAvailableAdults = 0;

            if (available[alt] == true) {
              for (int i = 1; i <= 5; i++) {
            if (pChild[i] == 1) {
              numberOfAvailableChildren++;
              numberOfAvailablePersons++;
            }
            if (pAdult[i] == 1) {
              numberOfAvailableChildren++;
              numberOfAvailableAdults++;
            }

            if (altParticipants[alt][i] == 1) {
              numberOfParticipants++;
              if (pType[0, i] == 1 || pType[1, i] == 1) {
                workersParticipating++;
              }
              if (pAdult[i] == 1) { numberOfParticipatingAdults++; }
              if (pChild[i] == 1) { numberOfParticipatingChildren++; }
            }
              }
            }

            // determine choice
            if (choice == alt) { chosen[alt] = true; }

            //Get the alternative
            ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(alt, available[alt], chosen[alt]);

            alternative.Choice = alt;

            //Add alt-specific utility terms
            alternative.AddUtilityTerm(160, (numberOfParticipatingAdults > 1 && numberOfParticipatingChildren > 0) ? 1 : 0);
            //alternative.AddUtilityTerm(161, (numberOfParticipatingChildren < numberOfAvailableChildren) ? 1 : 0);
            //alternative.AddUtilityTerm(162, (numberOfParticipatingAdults >1).ToFlag() *socialRecreationPurpose);
            //alternative.AddUtilityTerm(163, (numberOfParticipatingAdults == 1).ToFlag() *personalBusinessMedicalPurpose);

            for (int p = 1; p <= 5; p++) {
              if (altParticipants[alt][p] == 1) {
            alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]));
              }
            }
            for (int t2 = 1; t2 <= 5; t2++) {
              for (int t1 = 1; t1 < t2; t1++) {
            if (altParticipants[alt][t1] == 1 && altParticipants[alt][t2] == 1) {
              alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]));

            }
              }
            }
            for (int t2 = 1; t2 <= 5; t2++) {
              for (int t1 = 1; t1 <= 5; t1++) {
            if (!(t1 == t2)) {
              if (altParticipants[alt][t1] == 1 && altParticipants[alt][t2] == 1) {
                alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]));
              }
            }
              }
            }
              }
        }
Пример #20
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, HouseholdDayWrapper householdDay,
                              int nCallsForTour, int choice = Constants.DEFAULT_VALUE)
        {
            //var householdDay = (LDHouseholdDayWrapper)tour.HouseholdDay;
            var household = householdDay.Household;

            var carOwnership =
                household.VehiclesAvailable == 0
                                        ? Global.Settings.CarOwnerships.NoCars
                                        : household.VehiclesAvailable < household.HouseholdTotals.DrivingAgeMembers
                                                  ? Global.Settings.CarOwnerships.LtOneCarPerAdult
                                                  : Global.Settings.CarOwnerships.OneOrMoreCarsPerAdult;

            var noCarsFlag         = FlagUtility.GetNoCarsFlag(carOwnership);
            var carCompetitionFlag = FlagUtility.GetCarCompetitionFlag(carOwnership);

            var votALSegment                    = Global.Settings.VotALSegments.Medium; // TODO:  calculate a VOT segment that depends on household income
            var transitAccessSegment            = household.ResidenceParcel.TransitAccessSegment();
            var personalBusinessAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                                  [Global.Settings.Purposes.PersonalBusiness][carOwnership][votALSegment][transitAccessSegment];
            var shoppingAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                          //[Global.Settings.Purposes.Shopping][carOwnership][votALSegment][transitAccessSegment];
                                          [Global.Settings.Purposes.Shopping][Global.Settings.CarOwnerships.NoCars][votALSegment][transitAccessSegment];
            var mealAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                      [Global.Settings.Purposes.Meal][carOwnership][votALSegment][transitAccessSegment];
            var socialAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                        [Global.Settings.Purposes.Social][carOwnership][votALSegment][transitAccessSegment];
            //var compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][carOwnership][votALSegment][transitAccessSegment];
            var compositeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.NoCars][votALSegment][transitAccessSegment];


            int hasAdultEducLevel12 = 0;
            //int allAdultEducLevel12 = 1;
            int youngestAge = 999;

            foreach (PersonWrapper person in householdDay.Household.Persons)
            {
                // set characteristics here that depend on person characteristics
                if (person.Age >= 18 && person.EducationLevel >= 12)
                {
                    hasAdultEducLevel12 = 1;
                }
                //if (person.Age >= 18 && person.EducationLevel < 12) allAdultEducLevel12 = 0;
                if (person.Age < youngestAge)
                {
                    youngestAge = person.Age;
                }
            }

            // NONE_OR_HOME

            var noneOrHomeAvailable = true;

            if (Global.Configuration.ShouldRunLDPrimaryPriorityTimeModel && householdDay.JointTourFlag == 1 &&
                nCallsForTour == 1)
            {
                noneOrHomeAvailable = false;
            }

            var alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.NoneOrHome, noneOrHomeAvailable, choice == Global.Settings.Purposes.NoneOrHome);

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

            alternative.AddUtilityTerm(1, (nCallsForTour == 2).ToFlag());
            alternative.AddUtilityTerm(13, (nCallsForTour > 2).ToFlag());
            //alternative.AddUtilityTerm(2, noCarsFlag);
            //alternative.AddUtilityTerm(3, carCompetitionFlag);
            //alternative.AddUtilityTerm(4, householdDay.PrimaryPriorityTimeFlag);

            //alternative.AddUtilityTerm(2, householdDay.Household.HasChildren.ToFlag());
            alternative.AddUtilityTerm(2, householdDay.Household.HasChildrenUnder5.ToFlag());
            alternative.AddUtilityTerm(3, householdDay.Household.HasChildrenAge5Through15.ToFlag());
            alternative.AddUtilityTerm(4, (householdDay.Household.Size == 2 && householdDay.AdultsInSharedHomeStay == 2).ToFlag());
            alternative.AddUtilityTerm(5, (householdDay.AdultsInSharedHomeStay == 1 && householdDay.Household.HasChildrenUnder16).ToFlag());
            alternative.AddUtilityTerm(6, (householdDay.AdultsInSharedHomeStay == 2 && householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag());
            alternative.AddUtilityTerm(7, (householdDay.AdultsInSharedHomeStay == 2 && hasAdultEducLevel12 == 1).ToFlag());
            alternative.AddUtilityTerm(8, (youngestAge >= 40).ToFlag());

            alternative.AddUtilityTerm(10, (householdDay.Household.Income >= 300000 && householdDay.Household.Income < 600000).ToFlag());
            alternative.AddUtilityTerm(11, (householdDay.Household.Income >= 600000 && householdDay.Household.Income < 900000).ToFlag());
            alternative.AddUtilityTerm(12, (householdDay.Household.Income >= 900000).ToFlag());

            //alternative.AddUtilityTerm(13, hasAdultEducLevel12);
            //alternative.AddUtilityTerm(14, allAdultEducLevel12);
            //alternative.AddUtilityTerm(15, (youngestAge >= 40).ToFlag());
            //alternative.AddUtilityTerm(10, (householdDay.AdultsInSharedHomeStay == 2 && householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag());//

            //alternative.AddUtilityTerm(11, (householdDay.AdultsInSharedHomeStay == 2 && hasAdultEducLevel12 == 1).ToFlag());
            //alternative.AddUtilityTerm(11, (householdDay.AdultsInSharedHomeStay == 2 && allAdultEducLevel12 == 1).ToFlag());

            //alternative.AddNestedAlternative(11, 0, 60);

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

            //alternative.AddNestedAlternative(12, 1, 60);

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

            //alternative.AddNestedAlternative(12, 1, 60);

            // ESCORT
            alternative        = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Escort, false, choice == Global.Settings.Purposes.Escort);
            alternative.Choice = Global.Settings.Purposes.Escort;
            alternative.AddUtilityTerm(54, 1);
            //alternative.AddUtilityTerm(22, householdDay.PrimaryPriorityTimeFlag);
            //alternative.AddUtilityTerm(23, (householdDay.Household.Size == 3).ToFlag());
            //alternative.AddUtilityTerm(24, (householdDay.Household.Size >= 4).ToFlag());
            //alternative.AddUtilityTerm(25, (householdDay.Household.VehiclesAvailable >= 2 && household.Has2Drivers).ToFlag());
            //alternative.AddUtilityTerm(58, compositeLogsum);

            // 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, householdDay.PrimaryPriorityTimeFlag);

            alternative.AddUtilityTerm(23, (householdDay.Household.Size == 3).ToFlag());
            alternative.AddUtilityTerm(24, (householdDay.Household.Size >= 4).ToFlag());
            //alternative.AddUtilityTerm(25, (householdDay.Household.Size >= 5).ToFlag());

            //alternative.AddUtilityTerm(26, (householdDay.Household.VehiclesAvailable == 0).ToFlag());
            //alternative.AddUtilityTerm(27, (householdDay.Household.VehiclesAvailable == 1 && household.Has2Drivers).ToFlag());
            alternative.AddUtilityTerm(28, (householdDay.Household.VehiclesAvailable >= 2 && household.Has2Drivers).ToFlag());

            //alternative.AddUtilityTerm(27, (householdDay.Household.Size == 2 && householdDay.AdultsInSharedHomeStay == 2).ToFlag());
            //alternative.AddUtilityTerm(28, (householdDay.AdultsInSharedHomeStay == 1 && householdDay.Household.HasChildrenUnder16).ToFlag());

            //alternative.AddUtilityTerm(56, personalBusinessAggregateLogsum);
            alternative.AddUtilityTerm(56, compositeLogsum);

            //alternative.AddNestedAlternative(12, 1, 60);

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

            alternative.AddUtilityTerm(31, 1);
            alternative.AddUtilityTerm(32, householdDay.PrimaryPriorityTimeFlag);

            alternative.AddUtilityTerm(33, (householdDay.Household.Size == 3).ToFlag());
            alternative.AddUtilityTerm(34, (householdDay.Household.Size >= 4).ToFlag());
            //alternative.AddUtilityTerm(35, (householdDay.Household.Size >= 5).ToFlag());

            //alternative.AddUtilityTerm(36, (householdDay.Household.VehiclesAvailable == 0).ToFlag());
            alternative.AddUtilityTerm(37, (householdDay.Household.VehiclesAvailable == 1 && household.Has2Drivers).ToFlag());
            alternative.AddUtilityTerm(38, (householdDay.Household.VehiclesAvailable >= 2 && household.Has2Drivers).ToFlag());

            //alternative.AddUtilityTerm(37, (householdDay.Household.Size == 2 && householdDay.AdultsInSharedHomeStay == 2).ToFlag());
            //alternative.AddUtilityTerm(38, (householdDay.AdultsInSharedHomeStay == 1 && householdDay.Household.HasChildrenUnder16).ToFlag());

            //alternative.AddUtilityTerm(57, shoppingAggregateLogsum);
            alternative.AddUtilityTerm(59, compositeLogsum);

            //alternative.AddNestedAlternative(12, 1, 60);

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

            alternative.AddUtilityTerm(55, 1);

            //alternative.AddNestedAlternative(12, 1, 60);

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

            alternative.AddUtilityTerm(41, 1);
            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 >= 5).ToFlag());

            //alternative.AddUtilityTerm(46, (householdDay.Household.VehiclesAvailable >= 1).ToFlag());
            //alternative.AddUtilityTerm(47, (householdDay.Household.VehiclesAvailable == 1 && household.Has2Drivers).ToFlag());
            alternative.AddUtilityTerm(48, (householdDay.Household.VehiclesAvailable >= 2 && household.Has2Drivers).ToFlag());

            //alternative.AddUtilityTerm(46, (householdDay.Household.VehiclesAvailable > 0 && householdDay.Household.HasChildren).ToFlag());
            //alternative.AddUtilityTerm(46, (householdDay.Household.VehiclesAvailable == 0).ToFlag()); cars have no impact on fully joint social tour

            //alternative.AddUtilityTerm(47, householdDay.Household.HasChildrenUnder5.ToFlag());
            //alternative.AddUtilityTerm(48, householdDay.Household.HasChildrenAge5Through15.ToFlag());

            //alternative.AddUtilityTerm(47, (householdDay.Household.Size == 2 && householdDay.AdultsInSharedHomeStay == 2).ToFlag());
            //alternative.AddUtilityTerm(48, (householdDay.AdultsInSharedHomeStay == 1 && householdDay.Household.HasChildrenUnder16).ToFlag());

            //alternative.AddUtilityTerm(58, socialAggregateLogsum);
            //alternative.AddUtilityTerm(58, compositeLogsum);

            //alternative.AddNestedAlternative(12, 1, 60);
        }
Пример #21
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, IPersonDayWrapper personDay, IHouseholdDayWrapper householdDay, int choice = Constants.DEFAULT_VALUE)
        {
            IHouseholdWrapper household = personDay.Household;
            IPersonWrapper    person    = personDay.Person;

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

            int countMandatory    = (from personDayHH in orderedPersonDays where personDayHH.PatternType == 1 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 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);

            double workTourLogsum    = 0;
            double schoolPclUniStu   = 0;
            double schoolPclStudents = 0;
            int    noUsualWorkZone   = 1;


            if (personDay.Person.UsualWorkParcelId != Constants.DEFAULT_VALUE && personDay.Person.UsualWorkParcelId != Global.Settings.OutOfRegionParcelId)
            {
                if (personDay.Person.UsualDeparturePeriodFromWork != Constants.DEFAULT_VALUE && personDay.Person.UsualArrivalPeriodToWork != Constants.DEFAULT_VALUE)
                {
                    ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().RunNested(personDay, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualWorkParcel, (int)personDay.Person.UsualArrivalPeriodToWork, (int)personDay.Person.UsualDeparturePeriodFromWork, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers);
                    workTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                }
                else
                {
                    ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().RunNested(personDay, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualWorkParcel, Global.Settings.Times.EightAM, Global.Settings.Times.FivePM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers);
                    workTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                }

                noUsualWorkZone = 0;
            }

            if (personDay.Person.UsualSchoolParcelId != 0 && personDay.Person.UsualSchoolParcelId != -1 && personDay.Person.UsualSchoolParcelId != Global.Settings.OutOfRegionParcelId)
            {
                schoolPclUniStu = Math.Log(1 + (personDay.Person.UsualSchoolParcel.StudentsUniversityBuffer2)) / 10;
                ChoiceProbabilityCalculator.Alternative schoolNestedAlternative = Global.ChoiceModelSession.Get <SchoolTourModeTimeModel>().RunNested(personDay, personDay.Person.Household.ResidenceParcel, personDay.Person.UsualSchoolParcel, Global.Settings.Times.EightAM, Global.Settings.Times.TwoPM, personDay.Person.Household.HouseholdTotals.DrivingAgeMembers);
                schoolPclStudents = Math.Log(1 + (personDay.Person.UsualSchoolParcel.GetStudentsK12())) / 10;
            }


            // No mandatory stops
            ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(0, true, choice == 0);
            alternative.Choice = 0;

            // Work stop(s)
            alternative        = choiceProbabilityCalculator.GetAlternative(1, personDay.Person.IsWorker, choice == 1);
            alternative.Choice = 1;
            alternative.AddUtilityTerm(21, 1);
            alternative.AddUtilityTerm(22, (personDay.WorkTours + personDay.SchoolTours > 1).ToFlag());
            alternative.AddUtilityTerm(24, workTourLogsum);
            alternative.AddUtilityTerm(26, household.Has0To25KIncome.ToFlag());
            alternative.AddUtilityTerm(27, (person.Age < 30).ToFlag());
            alternative.AddUtilityTerm(29, noUsualWorkZone);
            alternative.AddUtilityTerm(30, countMandatory);
            alternative.AddUtilityTerm(31, countAtHome);
            alternative.AddUtilityTerm(33, person.IsPartTimeWorker.ToFlag());
            alternative.AddUtilityTerm(34, person.IsUniversityStudent.ToFlag());
            alternative.AddUtilityTerm(35, household.Has100KPlusIncome.ToFlag());

            // School stop(s)
            alternative        = choiceProbabilityCalculator.GetAlternative(2, personDay.Person.IsStudent, choice == 2);
            alternative.Choice = 2;
            alternative.AddUtilityTerm(41, 1);
            alternative.AddUtilityTerm(42, (personDay.SchoolTours == 0).ToFlag());
            alternative.AddUtilityTerm(45, person.IsChildUnder5.ToFlag());
            alternative.AddUtilityTerm(46, person.IsUniversityStudent.ToFlag());
            alternative.AddUtilityTerm(49, (household.HouseholdTotals.AllWorkers >= 2).ToFlag());
            alternative.AddUtilityTerm(50, carCompetitionFlag + noCarsFlag);
            alternative.AddUtilityTerm(53, (household.HouseholdTotals.ChildrenUnder16 > 2).ToFlag());
            alternative.AddUtilityTerm(54, schoolPclStudents);
            alternative.AddUtilityTerm(55, schoolPclUniStu);
            alternative.AddUtilityTerm(56, (person.Age > 25).ToFlag());
            alternative.AddUtilityTerm(59, personDay.Person.Household.ResidenceParcel.C34RatioBuffer1());


            // Work and school stops
            alternative        = choiceProbabilityCalculator.GetAlternative(3, (personDay.Person.IsWorker && personDay.Person.IsStudent), choice == 3);
            alternative.Choice = 3;
            alternative.AddUtilityTerm(61, 1);
        }
Пример #22
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, HouseholdDayWrapper householdDay, int choice = Constants.DEFAULT_VALUE)
        {
            Framework.DomainModels.Wrappers.IHouseholdWrapper household       = householdDay.Household;
            Framework.DomainModels.Wrappers.IParcelWrapper    residenceParcel = household.ResidenceParcel;

            // set household characteristics here that don't depend on person characteristics

            int hasAdultEducLevel12 = 0;
            int youngestAge         = 999;


            double firstWorkLogsum       = 0;
            double secondWorkLogsum      = 0;
            bool   firstWorkLogsumIsSet  = false;
            bool   secondWorkLogsumIsSet = false;
            int    numberWorkers         = 0;
            int    numberAdults          = 0;
            int    numberChildren        = 0;
            int    numberChildrenUnder5  = 0;


            // set characteristics here that depend on person characteristics
            foreach (PersonDayWrapper personDay in householdDay.PersonDays)
            {
                double        workLogsum = 0;
                PersonWrapper person     = (PersonWrapper)personDay.Person;
                if (person.UsualWorkParcel == null || person.UsualWorkParcelId == household.ResidenceParcelId ||
                    (person.PersonType != Global.Settings.PersonTypes.FullTimeWorker &&
                     person.PersonType != Global.Settings.PersonTypes.PartTimeWorker))
                //	|| household.VehiclesAvailable == 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<TourModeTimeModel>().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);
                    workLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                }
                //if (person.Age >= 18 && person.EducationLevel >= 12) {
                //  hasAdultEducLevel12 = 1;
                //}

                //if (person.Age >= 18 && person.EducationLevel < 12) {
                //}

                if (person.Age < youngestAge)
                {
                    youngestAge = person.Age;
                }

                if (workLogsum != 0 && !firstWorkLogsumIsSet)
                {
                    firstWorkLogsum      = workLogsum;
                    firstWorkLogsumIsSet = true;
                }
                else if (workLogsum != 0 && !secondWorkLogsumIsSet)
                {
                    secondWorkLogsum      = workLogsum;
                    secondWorkLogsumIsSet = true;
                }
                if (person.Age >= 18)
                {
                    numberAdults++;
                    if (person.PersonType == Global.Settings.PersonTypes.FullTimeWorker
                        //|| person.PersonType == Constants.PersonType.PART_TIME_WORKER
                        )
                    {
                        numberWorkers++;
                    }
                }
                else
                {
                    numberChildren++;
                    if (person.PersonType == Global.Settings.PersonTypes.ChildUnder5)
                    {
                        numberChildrenUnder5++;
                    }
                }
            }
            bool singleWorkerWithChildUnder5 = (numberAdults == numberWorkers && numberAdults == 1 &&
                                                numberChildrenUnder5 > 0) ? true : false;
            bool workingCoupleNoChildren = (numberAdults == numberWorkers && numberAdults == 2 &&
                                            numberChildren == 0) ? true : false;
            bool workingCoupleAllChildrenUnder5 = (numberAdults == numberWorkers && numberAdults == 2 &&
                                                   numberChildren > 0 && numberChildren == numberChildrenUnder5) ? true : false;
            bool otherHouseholdWithPTFTWorkers = false;

            if (!workingCoupleNoChildren && !workingCoupleAllChildrenUnder5 && firstWorkLogsum != 0)
            {
                otherHouseholdWithPTFTWorkers = true;
            }
            if (!workingCoupleNoChildren && !workingCoupleAllChildrenUnder5 && !otherHouseholdWithPTFTWorkers)
            {
            }


            // var votSegment = household.VotALSegment;
            //var taSegment = household.ResidenceParcel.TransitAccessSegment();

            //var aggregateLogsumDifference = // full car ownership vs. no car ownership
            //	Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.OneOrMoreCarsPerAdult][votSegment][taSegment] -
            //	Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.NoCars][votSegment][taSegment];


            //var householdDay = (ActumHouseholdDayWrapper)tour.HouseholdDay;

            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];

            int componentIndex = 0;

            for (int pfpt = 0; pfpt < 2; pfpt++)
            {
                if (pfpt == 1)
                {
                    componentIndex = 1;
                    choiceProbabilityCalculator.CreateUtilityComponent(componentIndex);
                    ChoiceProbabilityCalculator.Component pfptComponent = choiceProbabilityCalculator.GetUtilityComponent(componentIndex);
                    pfptComponent.AddUtilityTerm(1, (householdDay.Household.Size == 3).ToFlag());
                    pfptComponent.AddUtilityTerm(2, (householdDay.Household.Size >= 4).ToFlag());
                    pfptComponent.AddUtilityTerm(3, householdDay.Household.HasChildrenUnder5.ToFlag());
                    pfptComponent.AddUtilityTerm(4, (householdDay.AdultsInSharedHomeStay == 1 && householdDay.Household.HasChildrenAge5Through15).ToFlag());
                    pfptComponent.AddUtilityTerm(5, (householdDay.AdultsInSharedHomeStay == 2 && householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag());
                    pfptComponent.AddUtilityTerm(6, (householdDay.AdultsInSharedHomeStay == 2 && hasAdultEducLevel12 == 1).ToFlag());
                    pfptComponent.AddUtilityTerm(7, (householdDay.Household.VehiclesAvailable == 1 && household.Has2Drivers).ToFlag());
                    pfptComponent.AddUtilityTerm(8, (householdDay.Household.VehiclesAvailable >= 2 && household.Has2Drivers).ToFlag());

                    pfptComponent.AddUtilityTerm(11, (householdDay.Household.Income >= 300000 && householdDay.Household.Income < 600000).ToFlag());
                    pfptComponent.AddUtilityTerm(12, (householdDay.Household.Income >= 600000 && householdDay.Household.Income < 900000).ToFlag());
                    pfptComponent.AddUtilityTerm(13, (householdDay.Household.Income >= 900000).ToFlag());

                    // OBS; 27. aug., work tour mode logsum does not work - see what happens in the old PFPT model
                    // GV, sep. 1st - it is not significant
                    pfptComponent.AddUtilityTerm(15, (firstWorkLogsum + secondWorkLogsum) *
                                                 (workingCoupleNoChildren || workingCoupleAllChildrenUnder5).ToFlag());
                    pfptComponent.AddUtilityTerm(15, (firstWorkLogsum + secondWorkLogsum) * otherHouseholdWithPTFTWorkers.ToFlag());

                    // dette er gamle at-work logsum - it should be plus and significant
                    //alternative.AddUtilityTerm(31, (firstWorkLogsum + secondWorkLogsum) *
                    //(workingCoupleNoChildren || workingCoupleAllChildrenUnder5).ToFlag());
                    //alternative.AddUtilityTerm(31, (firstWorkLogsum + secondWorkLogsum) * otherHouseholdWithPTFTWorkers.ToFlag());

                    // at-home logsum works
                    pfptComponent.AddUtilityTerm(16, compositeLogsum);

                    //pfpt constant
                    pfptComponent.AddUtilityTerm(51, 1);
                }
            }
            for (int jointTourFlag = 0; jointTourFlag < 2; jointTourFlag++)
            {
                if (jointTourFlag == 1)
                {
                    componentIndex = 2;
                    choiceProbabilityCalculator.CreateUtilityComponent(componentIndex);
                    ChoiceProbabilityCalculator.Component jointComponent = choiceProbabilityCalculator.GetUtilityComponent(componentIndex);

                    jointComponent.AddUtilityTerm(21, (householdDay.Household.Size == 3).ToFlag());
                    jointComponent.AddUtilityTerm(22, (householdDay.Household.Size >= 4).ToFlag());

                    // GV: 1st sep.
                    //jointComponent.AddUtilityTerm(23, (householdDay.Household.Size == 2 && householdDay.Household.HasChildren).ToFlag());
                    //jointComponent.AddUtilityTerm(23, (householdDay.Household.Size >= 2 && householdDay.Household.HasChildren).ToFlag());
                    jointComponent.AddUtilityTerm(23, (householdDay.Household.HasChildren).ToFlag());

                    //jointComponent.AddUtilityTerm(21, householdDay.Household.HasChildrenUnder5.ToFlag());
                    //jointComponent.AddUtilityTerm(22, householdDay.Household.HasChildrenAge5Through15.ToFlag());

                    //jointComponent.AddUtilityTerm(23, householdDay.Household.HasChildren.ToFlag());

                    jointComponent.AddUtilityTerm(24, (householdDay.Household.Size == 2 && householdDay.AdultsInSharedHomeStay == 2).ToFlag());
                    //jointComponent.AddUtilityTerm(25, (householdDay.AdultsInSharedHomeStay == 2 && householdDay.Household.HouseholdTotals.FullAndPartTimeWorkers >= 2).ToFlag());
                    jointComponent.AddUtilityTerm(26, (householdDay.AdultsInSharedHomeStay == 2 && hasAdultEducLevel12 == 1).ToFlag());

                    //jointComponent.AddUtilityTerm(27, (householdDay.Household.Size == 2 && householdDay.Household.HasChildrenUnder5).ToFlag());
                    //jointComponent.AddUtilityTerm(28, (householdDay.Household.Size == 2 && householdDay.Household.HasChildrenAge5Through15).ToFlag());
                    //jointComponent.AddUtilityTerm(27, (householdDay.Household.Size == 2 && householdDay.Household.HasChildrenUnder16).ToFlag());

                    jointComponent.AddUtilityTerm(29, (householdDay.AdultsInSharedHomeStay == 1 && householdDay.Household.HasChildrenUnder16).ToFlag());

                    //jointComponent.AddUtilityTerm(37, (householdDay.Household.VehiclesAvailable == 1 && household.Has2Drivers).ToFlag());
                    //jointComponent.AddUtilityTerm(38, (householdDay.Household.VehiclesAvailable >= 2 && household.Has2Drivers).ToFlag());
                    jointComponent.AddUtilityTerm(30, (householdDay.Household.VehiclesAvailable >= 1 && household.Has2Drivers).ToFlag());

                    jointComponent.AddUtilityTerm(31, (householdDay.Household.Income >= 300000 && householdDay.Household.Income < 600000).ToFlag());
                    jointComponent.AddUtilityTerm(32, (householdDay.Household.Income >= 600000 && householdDay.Household.Income < 900000).ToFlag());
                    jointComponent.AddUtilityTerm(33, (householdDay.Household.Income >= 900000).ToFlag());

                    // GV, sep. 1st - it is not significant
                    //jointComponent.AddUtilityTerm(41, compositeLogsum);

                    // joint non-mandatory tour constant
                    jointComponent.AddUtilityTerm(61, 1);
                }
            }

            bool available = true;

            for (int pfpt = 0; pfpt < 2; pfpt++)
            {
                for (int jointTourFlag = 0; jointTourFlag < 2; jointTourFlag++)
                {
                    int altIndex = pfpt + jointTourFlag * 2;
                    if (household.Size < 2 && altIndex > 0)
                    {
                        available = false;
                    }
                    else
                    {
                        available = true;
                    }
                    ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(altIndex, available, choice == altIndex);

                    alternative.Choice = altIndex;

                    //NESTING WAS REJECTED BY TESTS
                    //GV: PFPT on top - cannot be estimated
                    //alternative.AddNestedAlternative(5 + pfpt,          pfpt, THETA_PARAMETER);
                    //alternative.AddNestedAlternative(5 + jointTourFlag, jointTourFlag, THETA_PARAMETER); //jointTourFlag on top

                    if (pfpt == 1)
                    {
                        alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(1));
                        //alternative.AddUtilityTerm(20, 1);
                    }
                    if (jointTourFlag == 1)
                    {
                        alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(2));
                        //alternative.AddUtilityTerm(40, 1);
                    }

                    if (pfpt == 1 && jointTourFlag == 1)
                    {
                        alternative.AddUtilityTerm(71, 1);
                        //alternative.AddUtilityTerm(72, (householdDay.Household.Size == 2 && householdDay.AdultsInSharedHomeStay == 2).ToFlag());

                        // GV: comented out sep. 1st
                        //GV: coeff. 73 is with a wrong sign - 13. june 2016
                        //alternative.AddUtilityTerm(73, householdDay.Household.HasChildren.ToFlag());
                        //alternative.AddUtilityTerm(74, householdDay.Household.HasChildrenUnder16.ToFlag());
                    }
                }
            }
        }