Exemplo n.º 1
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, PersonWrapper person, int sampleSize, IParcelWrapper choice = null, bool choseHome = false)
        {
            int segment = Global.ContainerDaySim.GetInstance <SamplingWeightsSettingsFactory>().SamplingWeightsSettings.GetTourDestinationSegment(Global.Settings.Purposes.Work, Global.Settings.TourPriorities.HomeBasedTour, Global.Settings.Modes.Sov, person.PersonType);
            DestinationSampler destinationSampler      = new DestinationSampler(choiceProbabilityCalculator, segment, sampleSize, choice, person.Household.ResidenceParcel);
            int destinationArrivalTime                 = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.WorkTourModeModel);
            int destinationDepartureTime               = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.WorkTourModeModel);
            WorkLocationUtilities workLocationUtilites = new WorkLocationUtilities(person, sampleSize, destinationArrivalTime, destinationDepartureTime);

            Dictionary <DestinationSampler.TourSampleItem, int> sampleItems = destinationSampler.SampleAndReturnTourDestinations(workLocationUtilites);

            int index = 0;

            foreach (KeyValuePair <DestinationSampler.TourSampleItem, int> sampleItem in sampleItems)
            {
                bool           available         = sampleItem.Key.Available;
                bool           isChosen          = sampleItem.Key.IsChosen;
                double         adjustmentFactor  = sampleItem.Key.AdjustmentFactor;
                IParcelWrapper destinationParcel = ChoiceModelFactory.Parcels[sampleItem.Key.ParcelId];

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

                if (!available)
                {
                    continue;
                }

                alternative.Choice = destinationParcel;

                double workTourLogsum = 0D;
                //JLB 201602
                //var nestedAlternative = Global.ChoiceModelSession.Get<WorkTourModeTimeModel>().RunNested(person, person.Household.ResidenceParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, person.Household.HouseholdTotals.DrivingAgeMembers, 0.0);
                ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <TourModeTimeModel>().RunNested(person, person.Household.ResidenceParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, person.Household.HouseholdTotals.DrivingAgeMembers, 0.0, Global.Settings.Purposes.Work);
                workTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();

                int    votSegment      = person.Household.GetVotALSegment();
                int    taSegment       = destinationParcel.TransitAccessSegment();
                double aggregateLogsum = Global.AggregateLogsums[destinationParcel.ZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.OneOrMoreCarsPerAdult][votSegment][taSegment];

                double distanceFromOrigin = person.Household.ResidenceParcel.DistanceFromOrigin(destinationParcel, 1);
                double distance1          = Math.Min(distanceFromOrigin, .35);
                double distance2          = Math.Max(0, Math.Min(distanceFromOrigin - .35, 1 - .35));
                double distance3          = Math.Max(0, distanceFromOrigin - 1);
                double distanceLog        = Math.Log(1 + distanceFromOrigin);
                double distanceFromSchool = person.IsFullOrPartTimeWorker ? 0 : person.UsualSchoolParcel.DistanceFromSchoolLog(destinationParcel, 1);


                // parcel buffers
                double educationBuffer  = Math.Log(destinationParcel.EmploymentEducationBuffer2 + 1);
                double governmentBuffer = Math.Log(destinationParcel.EmploymentGovernmentBuffer2 + 1);
                double officeBuffer     = Math.Log(destinationParcel.EmploymentOfficeBuffer2 + 1);
                double serviceBuffer    = Math.Log(destinationParcel.EmploymentServiceBuffer2 + 1);
                double householdsBuffer = Math.Log(destinationParcel.HouseholdsBuffer2 + 1);

                //				var retailBuffer = Math.Log(destinationParcel.EmploymentRetailBuffer2 + 1);
                double industrialAgricultureConstructionBuffer = Math.Log(destinationParcel.EmploymentIndustrialBuffer2 + destinationParcel.EmploymentAgricultureConstructionBuffer2 + 1);
                double foodBuffer               = Math.Log(destinationParcel.EmploymentFoodBuffer2 + 1);
                double medicalBuffer            = Math.Log(destinationParcel.EmploymentMedicalBuffer2 + 1);
                double employmentTotalBuffer    = Math.Log(destinationParcel.EmploymentTotalBuffer2 + 1);
                double studentsUniversityBuffer = Math.Log(destinationParcel.StudentsUniversityBuffer2 + 1);
                double studentsK12Buffer        = Math.Log(destinationParcel.StudentsK8Buffer2 + destinationParcel.StudentsHighSchoolBuffer2 + 1);

                //				var mixedUse4Index = destinationParcel.MixedUse4Index2();

                //size attributes (derived)
                double employmentIndustrialAgricultureConstruction = destinationParcel.EmploymentIndustrial + destinationParcel.EmploymentAgricultureConstruction;

                // parking attributes
                double parcelParkingDensity = destinationParcel.ParcelParkingPerTotalEmployment();

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


                // Stefan
                bool   isInCopenhagenMunicipality  = true; //destinationParcel.Municipality == 101;  Need to change this after Municipality property is added to Actum parcel file
                double employmentCommercial        = destinationParcel.EmploymentRetail + destinationParcel.EmploymentService;
                double employmentCommercialBuffer1 = destinationParcel.EmploymentRetailBuffer1 + destinationParcel.EmploymentServiceBuffer1;

                double beta00002 = -2.53;
                double beta00003 = 2.65;
                double beta00004 = 1.57;
                double beta00005 = -0.18;
                double beta00006 = -0.43;
                double beta00007 = -0.19;
                double beta00008 = 0.33;
                double beta00009 = 0.007;

                double stefanUtility =
                    beta00002 * destinationParcel.Households / destinationParcel.ThousandsSquareLengthUnits +
                    beta00003 * (person.Household.Income < 300000).ToFlag() * destinationParcel.Households / destinationParcel.ThousandsSquareLengthUnits +
                    beta00004 * person.IsFemale.ToFlag() * destinationParcel.Households / destinationParcel.ThousandsSquareLengthUnits +
                    beta00005 * isInCopenhagenMunicipality.ToFlag() +
                    beta00006 * (person.Household.HasValidIncome && person.Household.Income < 300000).ToFlag() * isInCopenhagenMunicipality.ToFlag() +
                    beta00007 * (person.Household.HasValidIncome && person.Household.Income >= 300000 && person.Household.Income < 600000).ToFlag() * isInCopenhagenMunicipality.ToFlag() +
                    beta00008 * (person.Household.HasValidIncome && person.Household.Income >= 900000).ToFlag() * isInCopenhagenMunicipality.ToFlag() +
                    beta00009 * person.Age * isInCopenhagenMunicipality.ToFlag() +
                    0.0; // beta00010 * (person.Household.ResidenceParcel.Municipality == destination.Municipality).ToFlag();



                //Stefan non-size terms.
                alternative.AddUtilityTerm(1, sampleItem.Key.AdjustmentFactor);
                //alternative.AddUtilityTerm(2, destinationParcel.Households / destinationParcel.ThousandsSquareLengthUnits);
                //alternative.AddUtilityTerm(3, (person.Household.Income < 300000).ToFlag() * destinationParcel.Households / destinationParcel.ThousandsSquareLengthUnits);
                //alternative.AddUtilityTerm(4, person.IsFemale.ToFlag() * destinationParcel.Households / destinationParcel.ThousandsSquareLengthUnits);
                //alternative.AddUtilityTerm(5, isInCopenhagenMunicipality.ToFlag());
                //alternative.AddUtilityTerm(6, (person.Household.HasValidIncome && person.Household.Income < 300000).ToFlag() * isInCopenhagenMunicipality.ToFlag());
                //alternative.AddUtilityTerm(7, (person.Household.HasValidIncome && person.Household.Income >= 300000 && person.Household.Income < 600000).ToFlag() * isInCopenhagenMunicipality.ToFlag());
                //alternative.AddUtilityTerm(8, (person.Household.HasValidIncome && person.Household.Income >= 900000).ToFlag() * isInCopenhagenMunicipality.ToFlag());
                //alternative.AddUtilityTerm(9, person.Age * isInCopenhagenMunicipality.ToFlag());
                ////alternative.AddUtilityTerm(10, (person.Household.ResidenceParcel.Municipality == destination.Municipality).ToFlag());  // Acivate this after Municipality property is added to Actum parcel file
                //following logsums replace Stefan's car and public transport times
                alternative.AddUtilityTerm(11, (person.Household.HasValidIncome && person.Household.Income < 300000).ToFlag() * workTourLogsum);
                alternative.AddUtilityTerm(12, (person.Household.HasValidIncome && person.Household.Income >= 300000 && person.Household.Income < 600000).ToFlag() * workTourLogsum);
                alternative.AddUtilityTerm(13, (person.Household.HasValidIncome && person.Household.Income >= 900000).ToFlag() * workTourLogsum);
                alternative.AddUtilityTerm(14, person.Household.HasMissingIncome.ToFlag() * workTourLogsum);
                alternative.AddUtilityTerm(15, person.IsFemale.ToFlag() * workTourLogsum);
                alternative.AddUtilityTerm(16, person.Age * workTourLogsum);
                alternative.AddUtilityTerm(17, (person.MainOccupation == 50).ToFlag() * workTourLogsum); // self-employed
                                                                                                         //Stefan's composite term 18 replaces terms 2-10 above
                alternative.AddUtilityTerm(18, stefanUtility);                                           // see above for this composite function of StefanMabitt's utility function

                //alternative.AddUtilityTerm(2, person.IsFulltimeWorker.ToFlag() * workTourLogsum);
                //alternative.AddUtilityTerm(3, person.IsPartTimeWorker.ToFlag() * workTourLogsum);
                //alternative.AddUtilityTerm(4, person.IsNotFullOrPartTimeWorker.ToFlag() * workTourLogsum);
                //alternative.AddUtilityTerm(5, distanceLog); // for distance calibration
                //alternative.AddUtilityTerm(6, person.IsFulltimeWorker.ToFlag() * distance1);
                //alternative.AddUtilityTerm(7, person.IsFulltimeWorker.ToFlag() * distance2);
                //alternative.AddUtilityTerm(8, person.IsFulltimeWorker.ToFlag() * distance3);
                //alternative.AddUtilityTerm(9, person.IsPartTimeWorker.ToFlag() * distanceLog);
                //alternative.AddUtilityTerm(10, person.IsNotFullOrPartTimeWorker.ToFlag() * distanceLog);
                //alternative.AddUtilityTerm(11, person.Household.Has0To15KIncome.ToFlag() * distanceLog);
                //alternative.AddUtilityTerm(12, person.Household.Has50To75KIncome.ToFlag() * distanceLog);
                //alternative.AddUtilityTerm(13, person.Household.Has75To100KIncome.ToFlag() * distanceLog);
                //alternative.AddUtilityTerm(14, person.IsFemale.ToFlag() * distanceLog);
                //alternative.AddUtilityTerm(15, person.IsStudentAge.ToFlag() * distanceFromSchool);
                //alternative.AddUtilityTerm(16, person.IsFulltimeWorker.ToFlag() * aggregateLogsum);
                //alternative.AddUtilityTerm(17, person.IsPartTimeWorker.ToFlag() * aggregateLogsum);
                //alternative.AddUtilityTerm(18, person.IsNotFullOrPartTimeWorker.ToFlag() * aggregateLogsum);
                //alternative.AddUtilityTerm(19, parcelParkingDensity);
                //alternative.AddUtilityTerm(20, c34Ratio);

                //Neighborhood
                //alternative.AddUtilityTerm(21, person.Household.HasValidIncome.ToFlag() * serviceBuffer);
                //alternative.AddUtilityTerm(22, person.Household.HasValidIncome.ToFlag() * educationBuffer);
                //alternative.AddUtilityTerm(23, person.Household.HasValidIncome.ToFlag() * foodBuffer);
                //alternative.AddUtilityTerm(24, person.Household.HasValidIncome.ToFlag() * governmentBuffer);
                //alternative.AddUtilityTerm(25, person.Household.HasValidIncome.ToFlag() * officeBuffer);
                //alternative.AddUtilityTerm(26, person.Household.HasValidIncome.ToFlag() * medicalBuffer);
                //alternative.AddUtilityTerm(27, person.Household.HasValidIncome.ToFlag() * householdsBuffer);
                //alternative.AddUtilityTerm(28, person.Household.HasValidIncome.ToFlag() * studentsUniversityBuffer);

                //alternative.AddUtilityTerm(29, person.Household.HasValidIncome.ToFlag() * person.IsFulltimeWorker.ToFlag() * studentsK12Buffer);
                //alternative.AddUtilityTerm(30, person.Household.HasValidIncome.ToFlag() * person.IsFulltimeWorker.ToFlag() * studentsUniversityBuffer);
                //alternative.AddUtilityTerm(31, person.Household.HasValidIncome.ToFlag() * person.IsPartTimeWorker.ToFlag() * industrialAgricultureConstructionBuffer);
                //alternative.AddUtilityTerm(32, person.Household.HasValidIncome.ToFlag() * person.IsNotFullOrPartTimeWorker.ToFlag() * foodBuffer);
                //alternative.AddUtilityTerm(33, person.Household.HasValidIncome.ToFlag() * person.IsNotFullOrPartTimeWorker.ToFlag() * medicalBuffer);

                //alternative.AddUtilityTerm(34, person.IsFulltimeWorker.ToFlag() * person.Household.Has75KPlusIncome.ToFlag() * employmentTotalBuffer);
                //alternative.AddUtilityTerm(35, person.IsNotFullOrPartTimeWorker.ToFlag() * person.Household.HasIncomeUnder50K.ToFlag() * governmentBuffer);
                //alternative.AddUtilityTerm(36, person.IsNotFullOrPartTimeWorker.ToFlag() * person.Household.HasIncomeUnder50K.ToFlag() * employmentTotalBuffer);

                //Size
                // Stefan size terms.
                // Note:  the following assumes: (1) Stefan's size variables enter his utility function as a logsum, a la BAL;
                //                               (2) Jobs--commercial and Jobs--finance apply to hh w unknown incomes in Stefan's spec
                //        If his size variables enter linearly, then if I want to replicate them I should not use alogit size functions.
                //        If Jobs--commercial and Jobs--finance don't apply to missing incomes, then I need to change the size functions below
                alternative.AddUtilityTerm(51, (person.Household.HasValidIncome && person.Household.Income < 300000).ToFlag() * (destinationParcel.EmploymentTotal - employmentCommercial));
                alternative.AddUtilityTerm(52, (person.Household.HasValidIncome && person.Household.Income >= 300000 && person.Household.Income < 600000).ToFlag() * (destinationParcel.EmploymentTotal - employmentCommercial));
                alternative.AddUtilityTerm(53, (person.Household.HasValidIncome && person.Household.Income >= 600000 && person.Household.Income < 900000).ToFlag() * (destinationParcel.EmploymentTotal - employmentCommercial));
                alternative.AddUtilityTerm(54, (person.Household.HasValidIncome && person.Household.Income >= 900000).ToFlag() * (destinationParcel.EmploymentTotal - employmentCommercial));
                alternative.AddUtilityTerm(55, (person.Household.HasValidIncome && person.Household.Income >= 900000).ToFlag() * (destinationParcel.EmploymentTotal - employmentCommercial)); // second term allows first one to have base coef of 0
                alternative.AddUtilityTerm(56, (person.Household.HasMissingIncome.ToFlag() * (destinationParcel.EmploymentTotal - employmentCommercial)));
                alternative.AddUtilityTerm(57, (person.Household.HasValidIncome && person.Household.Income < 300000).ToFlag() * employmentCommercial);
                alternative.AddUtilityTerm(58, (person.Household.HasValidIncome && person.Household.Income >= 300000 && person.Household.Income < 600000).ToFlag() * employmentCommercial);
                alternative.AddUtilityTerm(59, (person.Household.HasValidIncome && person.Household.Income >= 600000 && person.Household.Income < 900000).ToFlag() * employmentCommercial);
                alternative.AddUtilityTerm(60, (person.Household.HasValidIncome && person.Household.Income >= 900000).ToFlag() * employmentCommercial);
                alternative.AddUtilityTerm(61, person.Household.HasMissingIncome.ToFlag() * employmentCommercial);
                alternative.AddUtilityTerm(62, destinationParcel.EmploymentOffice);
                //The following combine with 51-55, 56-60 and 61 to include size of entire buffer region in main size variables
                alternative.AddUtilityTerm(63, (destinationParcel.EmploymentTotalBuffer1 - destinationParcel.EmploymentTotal) - (employmentCommercialBuffer1 - employmentCommercial));
                alternative.AddUtilityTerm(64, employmentCommercialBuffer1 - employmentCommercial);
                alternative.AddUtilityTerm(65, destinationParcel.EmploymentOfficeBuffer1 - destinationParcel.EmploymentOffice);

                //alternative.AddUtilityTerm(51, person.Household.HasValidIncome.ToFlag() * destinationParcel.EmploymentService);
                //alternative.AddUtilityTerm(52, person.Household.HasValidIncome.ToFlag() * destinationParcel.EmploymentEducation);
                //alternative.AddUtilityTerm(53, person.Household.HasValidIncome.ToFlag() * destinationParcel.EmploymentFood);
                //alternative.AddUtilityTerm(54, person.Household.HasValidIncome.ToFlag() * destinationParcel.EmploymentGovernment);
                //alternative.AddUtilityTerm(55, person.Household.HasValidIncome.ToFlag() * destinationParcel.EmploymentOffice);
                //alternative.AddUtilityTerm(56, person.Household.HasValidIncome.ToFlag() * destinationParcel.EmploymentRetail);
                //alternative.AddUtilityTerm(57, person.Household.HasValidIncome.ToFlag() * destinationParcel.EmploymentMedical);
                //alternative.AddUtilityTerm(58, person.Household.HasValidIncome.ToFlag() * employmentIndustrialAgricultureConstruction);
                //alternative.AddUtilityTerm(59, person.Household.HasValidIncome.ToFlag() * destinationParcel.StudentsUniversity);

                //alternative.AddUtilityTerm(60, person.Household.HasValidIncome.ToFlag() * person.IsFulltimeWorker.ToFlag() * destinationParcel.EmploymentGovernment);
                //alternative.AddUtilityTerm(61, person.Household.HasValidIncome.ToFlag() * person.IsFulltimeWorker.ToFlag() * employmentIndustrialAgricultureConstruction);
                //alternative.AddUtilityTerm(62, person.Household.HasValidIncome.ToFlag() * person.IsPartTimeWorker.ToFlag() * employmentIndustrialAgricultureConstruction);
                //alternative.AddUtilityTerm(63, person.Household.HasValidIncome.ToFlag() * person.IsNotFullOrPartTimeWorker.ToFlag() * destinationParcel.EmploymentEducation);
                //alternative.AddUtilityTerm(64, person.Household.HasValidIncome.ToFlag() * person.IsNotFullOrPartTimeWorker.ToFlag() * destinationParcel.EmploymentFood);
                //alternative.AddUtilityTerm(65, person.Household.HasValidIncome.ToFlag() * person.IsNotFullOrPartTimeWorker.ToFlag() * destinationParcel.EmploymentRetail);

                //alternative.AddUtilityTerm(66, person.Household.HasIncomeUnder50K.ToFlag() * destinationParcel.EmploymentRetail);
                //alternative.AddUtilityTerm(67, person.Household.HasIncomeUnder50K.ToFlag() * destinationParcel.EmploymentService);
                //alternative.AddUtilityTerm(68, person.Household.Has50To75KIncome.ToFlag() * destinationParcel.EmploymentMedical);
                //alternative.AddUtilityTerm(69, person.Household.Has50To75KIncome.ToFlag() * destinationParcel.EmploymentOffice);
                //alternative.AddUtilityTerm(70, person.Household.Has75KPlusIncome.ToFlag() * destinationParcel.EmploymentEducation);
                //alternative.AddUtilityTerm(71, person.Household.Has75KPlusIncome.ToFlag() * destinationParcel.EmploymentGovernment);
                //alternative.AddUtilityTerm(72, person.Household.Has75KPlusIncome.ToFlag() * destinationParcel.EmploymentMedical);
                //alternative.AddUtilityTerm(73, person.Household.Has75KPlusIncome.ToFlag() * destinationParcel.EmploymentOffice);

                //alternative.AddUtilityTerm(74, person.IsFulltimeWorker.ToFlag() * person.Household.Has75KPlusIncome.ToFlag() * destinationParcel.EmploymentGovernment);
                //alternative.AddUtilityTerm(75, person.IsFulltimeWorker.ToFlag() * (!person.Household.Has75KPlusIncome).ToFlag() * employmentIndustrialAgricultureConstruction);
                //alternative.AddUtilityTerm(76, person.IsPartTimeWorker.ToFlag() * (!person.Household.HasIncomeUnder50K).ToFlag() * destinationParcel.EmploymentMedical);
                //alternative.AddUtilityTerm(77, (!person.IsFulltimeWorker).ToFlag() * person.Household.Has75KPlusIncome.ToFlag() * destinationParcel.EmploymentOffice);
                //alternative.AddUtilityTerm(78, person.IsNotFullOrPartTimeWorker.ToFlag() * (!person.Household.HasIncomeUnder50K).ToFlag() * destinationParcel.EmploymentRetail);

                //alternative.AddUtilityTerm(79, person.Household.HasMissingIncome.ToFlag() * destinationParcel.EmploymentTotal);
                //alternative.AddUtilityTerm(80, person.Household.HasMissingIncome.ToFlag() * destinationParcel.StudentsUniversity);

                // set shadow price depending on persontype and add it to utility
                // we are using the sampling adjustment factor assuming that it is 1
                alternative.AddUtilityTerm(1, destinationParcel.ShadowPriceForEmployment);

                //remove nesting for estimation of conditional MNL
                alternative.AddNestedAlternative(sampleSize + 2, 0, 98);
            }

            // JLB 20120329 added third call parameter to idenitfy whether this alt is chosen or not
            ChoiceProbabilityCalculator.Alternative homeAlternative = choiceProbabilityCalculator.GetAlternative(sampleSize, true, choseHome);

            homeAlternative.Choice = person.Household.ResidenceParcel;

            homeAlternative.AddUtilityTerm(41, 1);
            homeAlternative.AddUtilityTerm(42, (person.MainOccupation == 50).ToFlag()); // self-employed

            //homeAlternative.AddUtilityTerm(42, person.IsPartTimeWorker.ToFlag());
            //homeAlternative.AddUtilityTerm(43, person.IsStudentAge.ToFlag());
            //homeAlternative.AddUtilityTerm(44, person.IsFemale.ToFlag());
            homeAlternative.AddUtilityTerm(90, 1);

            //make oddball alt unavailable and remove nesting for estimation of conditional MNL
            //			alternative.Available = false;
            homeAlternative.AddNestedAlternative(sampleSize + 3, 1, 98);
        }
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, IPersonDayWrapper personDay, DayPattern choice = null)
        {
            IHouseholdWrapper household       = personDay.Household;
            IParcelWrapper    residenceParcel = household.ResidenceParcel;
            IPersonWrapper    person          = personDay.Person;

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

            double[] purposeLogsums = new double[Global.Settings.Purposes.TotalPurposes];
            double[] atUsualLogsums = new double[3];
            int      carOwnership   = person.GetCarOwnershipSegment();
            int      votSegment     = person.Household.GetVotALSegment();
            int      transitAccess  = residenceParcel.TransitAccessSegment();

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

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

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

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

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

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

            for (int xPurpose = Global.Settings.Purposes.Work; xPurpose <= Global.Settings.Purposes.Social + 10; xPurpose++)
            {
                // extra components 1-5 are for 2,3,4,5,6 tour purposes
                // extra components 6-10 are for 2,3,4,5,6 stop puroposes

                // recode purpose to match coefficients
                int purpose = xPurpose <= Global.Settings.Purposes.Social ? xPurpose :
                              xPurpose <= Global.Settings.Purposes.Social + 5 ?
                              Global.Settings.Purposes.Social + 1 : Global.Settings.Purposes.Social + 2;

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

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

                component.AddUtilityTerm(100 * purpose + 51, xMultiplier * person.IsFulltimeWorker.ToFlag());
                component.AddUtilityTerm(100 * purpose + 2, xMultiplier * person.IsPartTimeWorker.ToFlag());
                component.AddUtilityTerm(100 * purpose + 3, xMultiplier * person.IsRetiredAdult.ToFlag());
                component.AddUtilityTerm(100 * purpose + 4, xMultiplier * person.IsNonworkingAdult.ToFlag());
                component.AddUtilityTerm(100 * purpose + 5, xMultiplier * person.IsUniversityStudent.ToFlag());
                component.AddUtilityTerm(100 * purpose + 6, xMultiplier * person.IsDrivingAgeStudent.ToFlag());
                component.AddUtilityTerm(100 * purpose + 7, xMultiplier * person.IsChildAge5Through15.ToFlag());
                component.AddUtilityTerm(100 * purpose + 8, xMultiplier * person.IsChildUnder5.ToFlag());
                component.AddUtilityTerm(100 * purpose + 9, xMultiplier * household.Has0To25KIncome.ToFlag());
                component.AddUtilityTerm(100 * purpose + 10, xMultiplier * household.Has25To45KIncome.ToFlag());
                component.AddUtilityTerm(100 * purpose + 11, xMultiplier * household.Has75KPlusIncome.ToFlag());
                component.AddUtilityTerm(100 * purpose + 12, xMultiplier * carsPerDriver);
                component.AddUtilityTerm(100 * purpose + 13, xMultiplier * person.IsOnlyAdult().ToFlag());
                component.AddUtilityTerm(100 * purpose + 14, xMultiplier * person.IsOnlyFullOrPartTimeWorker().ToFlag());
                component.AddUtilityTerm(100 * purpose + 15, xMultiplier * 0);
                component.AddUtilityTerm(100 * purpose + 16, xMultiplier * person.IsFemale.ToFlag() * person.IsAdult.ToFlag() * (!household.HasChildrenUnder16).ToFlag());
                component.AddUtilityTerm(100 * purpose + 17, xMultiplier * person.IsFemale.ToFlag() * person.IsAdult.ToFlag() * household.HasChildrenUnder5.ToFlag());
                component.AddUtilityTerm(100 * purpose + 18, xMultiplier * person.IsFemale.ToFlag() * person.IsAdult.ToFlag() * household.HasChildrenAge5Through15.ToFlag());
                component.AddUtilityTerm(100 * purpose + 19, xMultiplier * person.IsMale.ToFlag() * person.IsAdult.ToFlag() * household.HasChildrenUnder5.ToFlag());
                component.AddUtilityTerm(100 * purpose + 20, xMultiplier * person.IsMale.ToFlag() * person.IsAdult.ToFlag() * household.HasChildrenAge5Through15.ToFlag());
                component.AddUtilityTerm(100 * purpose + 21, xMultiplier * person.AgeIsBetween18And25.ToFlag());
                component.AddUtilityTerm(100 * purpose + 22, xMultiplier * person.AgeIsBetween26And35.ToFlag());
                component.AddUtilityTerm(100 * purpose + 23, xMultiplier * person.AgeIsBetween51And65.ToFlag());
                component.AddUtilityTerm(100 * purpose + 24, xMultiplier * person.WorksAtHome().ToFlag());
                component.AddUtilityTerm(100 * purpose + 25, xMultiplier * mixedDensity);
                component.AddUtilityTerm(100 * purpose + 26, xMultiplier * intersectionDensity);
                component.AddUtilityTerm(100 * purpose + 27, xMultiplier * purposeLogsums[purpose]);
                component.AddUtilityTerm(100 * purpose + 28, xMultiplier * person.TransitPassOwnership);
            }

            // tour utility
            int tourComponentIndex = Global.Settings.Purposes.Social + 11;

            choiceProbabilityCalculator.CreateUtilityComponent(tourComponentIndex);
            ChoiceProbabilityCalculator.Component tourComponent = choiceProbabilityCalculator.GetUtilityComponent(tourComponentIndex);
            tourComponent.AddUtilityTerm(1401, carsPerDriver);
            tourComponent.AddUtilityTerm(1402, person.WorksAtHome().ToFlag());
            tourComponent.AddUtilityTerm(1403, mixedDensity);
            tourComponent.AddUtilityTerm(1404, mixedDensity * person.IsChildAge5Through15.ToFlag());
            tourComponent.AddUtilityTerm(1405, compositeLogsum);
            tourComponent.AddUtilityTerm(1406, person.TransitPassOwnership);

            // stop utility
            int stopComponentIndex = Global.Settings.Purposes.Social + 12;

            choiceProbabilityCalculator.CreateUtilityComponent(stopComponentIndex);
            ChoiceProbabilityCalculator.Component stopComponent = choiceProbabilityCalculator.GetUtilityComponent(stopComponentIndex);
            stopComponent.AddUtilityTerm(1411, carsPerDriver);
            stopComponent.AddUtilityTerm(1412, person.WorksAtHome().ToFlag());
            stopComponent.AddUtilityTerm(1413, mixedDensity);
            stopComponent.AddUtilityTerm(1414, mixedDensity * person.IsChildAge5Through15.ToFlag());
            stopComponent.AddUtilityTerm(1415, compositeLogsum);
            stopComponent.AddUtilityTerm(1416, person.TransitPassOwnership);

            for (int alternativeIndex = 0; alternativeIndex < TOTAL_ALTERNATIVES; alternativeIndex++)
            {
                DayPattern dayPattern = _dayPatterns[alternativeIndex];
                bool       available  =
                    // work tours and stops only available for workers
                    (person.IsWorker || (dayPattern.WorkTours <= 0 && dayPattern.WorkStops <= 0)) &&
                    // school tours and stops only available for students with usual school parcel not at home
                    ((person.IsStudent && person.UsualSchoolParcel != null && person.UsualSchoolParcel != person.Household.ResidenceParcel) || (dayPattern.SchoolTours <= 0 && dayPattern.SchoolStops <= 0)) &&
                    // school stops not available if usual school parcel is same as usual work parcel
                    ((person.IsStudent && person.UsualSchoolParcel != null && person.UsualSchoolParcel != person.UsualWorkParcel) || (dayPattern.SchoolStops <= 0));

                ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(alternativeIndex, available, choice != null && choice.Equals(dayPattern));

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

                alternative.Choice = dayPattern;

                // components for the purposes
                for (int purpose = Global.Settings.Purposes.Work; purpose <= Global.Settings.Purposes.Social; purpose++)
                {
                    if (dayPattern.Tours[purpose] > 0 || dayPattern.Stops[purpose] > 0)
                    {
                        alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(purpose));

                        if (dayPattern.Tours[purpose] > 0)
                        {
                            alternative.AddUtilityTerm(100 * purpose, 1);                                  // tour purpose ASC
                            alternative.AddUtilityTerm(100 * purpose + 29, purposeLogsums[purpose]);       // tour purpose logsum
                            alternative.AddUtilityTerm(100 * purpose + 30, person.PaidParkingAtWorkplace); // only use for work purpose
                        }

                        if (dayPattern.Stops[purpose] > 0)
                        {
                            alternative.AddUtilityTerm(100 * purpose + 1, 1);                        // stop purpose ASC
                            alternative.AddUtilityTerm(100 * purpose + 31, purposeLogsums[purpose]); // stop purpose logsum
                        }
                        if (Global.Configuration.IsInEstimationMode)
                        {
                            alternative.AddUtilityTerm(100 * purpose + 32, 1 - person.PaperDiary);
                            alternative.AddUtilityTerm(100 * purpose + 33, person.ProxyResponse);
                        }
                    }
                }

                // multiple tour purposes component
                if (dayPattern.TotalTours > 1)
                {
                    alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(Global.Settings.Purposes.Social + (dayPattern.TotalTours - 1)));
                }

                // multiple stop purposes component
                if (dayPattern.TotalStops > 1)
                {
                    alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(Global.Settings.Purposes.Social + 5 + (dayPattern.TotalStops - 1)));
                }

                for (int tourPurpose = Global.Settings.Purposes.Work; tourPurpose <= Global.Settings.Purposes.Social; tourPurpose++)
                {
                    for (int stopPurpose = Global.Settings.Purposes.Work; stopPurpose <= Global.Settings.Purposes.Social - 1; stopPurpose++)
                    {
                        if (tourPurpose > Global.Settings.Purposes.School && stopPurpose <= Global.Settings.Purposes.School)
                        {
                            continue;
                        }

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

                for (int tourPurpose = Global.Settings.Purposes.Work; tourPurpose <= Global.Settings.Purposes.School; tourPurpose++)
                {
                    if (dayPattern.Tours[tourPurpose] == 1 && dayPattern.TotalStops >= 1)
                    {
                        alternative.AddUtilityTerm(1000 + 10 * tourPurpose, purposeLogsums[tourPurpose]);     // usual location logsum x presence of stops in work or school pattern
                        alternative.AddUtilityTerm(1000 + 10 * tourPurpose + 8, compositeLogsum);             // home aggregate logsum x  presence of stops in work or school pattern
                        alternative.AddUtilityTerm(1000 + 10 * tourPurpose + 9, atUsualLogsums[tourPurpose]); // at usual location aggregate logsum x  presence of stops in work or school pattern
                    }
                }

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

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

                if (dayPattern.TotalTours > 0 && dayPattern.TotalStops > 0)
                {
                    int totalStops = dayPattern.TotalStops;

                    if (totalStops > 3)
                    {
                        totalStops = 3;
                    }

                    alternative.AddUtilityTerm(1300 + 10 * dayPattern.TotalTours + totalStops, 1); // nttour-ntstop utility
                }
                if (dayPattern.TotalTours - dayPattern.Tours[Global.Settings.Purposes.Work] - dayPattern.Tours[Global.Settings.Purposes.School] > 0)
                {
                    // tour utility
                    alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(tourComponentIndex));
                }
                if (dayPattern.TotalStops - dayPattern.Stops[Global.Settings.Purposes.Work] - dayPattern.Stops[Global.Settings.Purposes.School] > 0)
                {
                    // stop utility
                    alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(stopComponentIndex));
                }
            }
        }
Exemplo n.º 3
0
            public void SetUtilities(ISampleItem sampleItem, int sampleFrequency)
            {
                if (sampleItem == null)
                {
                    throw new ArgumentNullException("sampleItem");
                }

                ChoiceProbabilityCalculator.Alternative alternative = sampleItem.Alternative;

                //remove nesting for estimation of conditional MNL
                if (!Global.Configuration.IsInEstimationMode || ESTIMATE_NESTED_MODEL)
                {
                    alternative.AddNestedAlternative(_sampleSize + 2, 0, THETA_PARAMETER);
                }
                if (!alternative.Available)
                {
                    return;
                }

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

                //                var destinationZoneTotals = ChoiceModelRunner.ZoneTotals[destinationParcel.ZoneId];

                alternative.Choice = destinationParcel;



                ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeModel>().RunNested(_person, _person.Household.ResidenceParcel, destinationParcel, _destinationArrivalTime, _destinationDepartureTime, _person.Household.HouseholdTotals.DrivingAgeMembers);
                double workTourLogsum  = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                int    votSegment      = _person.Household.GetVotALSegment();
                int    taSegment       = destinationParcel.TransitAccessSegment();
                double aggregateLogsum = Global.AggregateLogsums[destinationParcel.ZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.OneOrMoreCarsPerAdult][votSegment][taSegment];

                double distanceFromOrigin = _person.Household.ResidenceParcel.DistanceFromOrigin(destinationParcel, 1);
                double distance1          = Math.Min(distanceFromOrigin, .35);
                double distance2          = Math.Max(0, Math.Min(distanceFromOrigin - .35, 1 - .35));
                double distance3          = Math.Max(0, distanceFromOrigin - 1);
                double distance20         = Math.Max(0, distanceFromOrigin - 2);
                double distance30         = Math.Max(0, distanceFromOrigin - 3);
                double distance40         = Math.Max(0, distanceFromOrigin - 4);
                double distanceLog        = Math.Log(1 + distanceFromOrigin);
                double distanceFromSchool = _person.IsFullOrPartTimeWorker ? 0 : _person.UsualSchoolParcel.DistanceFromSchoolLog(destinationParcel, 1);

                // parcel buffers
                double educationBuffer  = Math.Log(destinationParcel.EmploymentEducationBuffer2 + 1);
                double governmentBuffer = Math.Log(destinationParcel.EmploymentGovernmentBuffer2 + 1);
                double officeBuffer     = Math.Log(destinationParcel.EmploymentOfficeBuffer2 + 1);
                double serviceBuffer    = Math.Log(destinationParcel.EmploymentServiceBuffer2 + 1);
                double householdsBuffer = Math.Log(destinationParcel.HouseholdsBuffer2 + 1);

                //                var retailBuffer = Math.Log(destinationParcel.EmploymentRetailBuffer2 + 1);
                double industrialAgricultureConstructionBuffer = Math.Log(destinationParcel.EmploymentIndustrialBuffer2 + destinationParcel.EmploymentAgricultureConstructionBuffer2 + 1);
                double foodBuffer               = Math.Log(destinationParcel.EmploymentFoodBuffer2 + 1);
                double medicalBuffer            = Math.Log(destinationParcel.EmploymentMedicalBuffer2 + 1);
                double employmentTotalBuffer    = Math.Log(destinationParcel.EmploymentTotalBuffer2 + 1);
                double studentsUniversityBuffer = Math.Log(destinationParcel.StudentsUniversityBuffer2 + 1);
                double studentsK12Buffer        = Math.Log(destinationParcel.StudentsK8Buffer2 + destinationParcel.StudentsHighSchoolBuffer2 + 1);

                //                var mixedUse4Index = destinationParcel.MixedUse4Index2();

                //size attributes (derived)
                double employmentIndustrialAgricultureConstruction = destinationParcel.EmploymentIndustrial + destinationParcel.EmploymentAgricultureConstruction;

                // parking attributes
                double parcelParkingDensity = destinationParcel.ParcelParkingPerTotalEmployment();

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


                alternative.AddUtilityTerm(1, sampleItem.AdjustmentFactor); //constrain coeff to 1
                alternative.AddUtilityTerm(2, _person.IsFulltimeWorker.ToFlag() * workTourLogsum);
                alternative.AddUtilityTerm(3, _person.IsPartTimeWorker.ToFlag() * workTourLogsum);
                alternative.AddUtilityTerm(4, _person.IsNotFullOrPartTimeWorker.ToFlag() * workTourLogsum);
                alternative.AddUtilityTerm(5, distanceLog); // for distance calibration
                alternative.AddUtilityTerm(6, _person.IsFulltimeWorker.ToFlag() * distance1);
                alternative.AddUtilityTerm(7, _person.IsFulltimeWorker.ToFlag() * distance2);
                alternative.AddUtilityTerm(8, _person.IsFulltimeWorker.ToFlag() * distance3);
                alternative.AddUtilityTerm(9, _person.IsPartTimeWorker.ToFlag() * distanceLog);
                alternative.AddUtilityTerm(10, _person.IsNotFullOrPartTimeWorker.ToFlag() * distanceLog);
                alternative.AddUtilityTerm(11, _person.Household.Has0To15KIncome.ToFlag() * distanceLog);
                alternative.AddUtilityTerm(12, _person.Household.Has50To75KIncome.ToFlag() * distanceLog);
                alternative.AddUtilityTerm(13, _person.Household.Has75To100KIncome.ToFlag() * distanceLog);
                alternative.AddUtilityTerm(14, _person.IsFemale.ToFlag() * distanceLog);
                alternative.AddUtilityTerm(15, _person.IsStudentAge.ToFlag() * distanceFromSchool);
                alternative.AddUtilityTerm(16, _person.IsFulltimeWorker.ToFlag() * aggregateLogsum);
                alternative.AddUtilityTerm(17, _person.IsPartTimeWorker.ToFlag() * aggregateLogsum);
                alternative.AddUtilityTerm(18, _person.IsNotFullOrPartTimeWorker.ToFlag() * aggregateLogsum);
                alternative.AddUtilityTerm(19, parcelParkingDensity);
                alternative.AddUtilityTerm(20, c34Ratio);
                //extra additive distance terms for calibrating longer distances
                alternative.AddUtilityTerm(46, distance20);
                alternative.AddUtilityTerm(47, distance30);
                alternative.AddUtilityTerm(48, distance40);

                //Neighborhood
                alternative.AddUtilityTerm(21, _person.Household.HasValidIncome.ToFlag() * serviceBuffer);
                alternative.AddUtilityTerm(22, _person.Household.HasValidIncome.ToFlag() * educationBuffer);
                alternative.AddUtilityTerm(23, _person.Household.HasValidIncome.ToFlag() * foodBuffer);
                alternative.AddUtilityTerm(24, _person.Household.HasValidIncome.ToFlag() * governmentBuffer);
                alternative.AddUtilityTerm(25, _person.Household.HasValidIncome.ToFlag() * officeBuffer);
                alternative.AddUtilityTerm(26, _person.Household.HasValidIncome.ToFlag() * medicalBuffer);
                alternative.AddUtilityTerm(27, _person.Household.HasValidIncome.ToFlag() * householdsBuffer);
                alternative.AddUtilityTerm(28, _person.Household.HasValidIncome.ToFlag() * studentsUniversityBuffer);

                alternative.AddUtilityTerm(29, _person.Household.HasValidIncome.ToFlag() * _person.IsFulltimeWorker.ToFlag() * studentsK12Buffer);
                alternative.AddUtilityTerm(30, _person.Household.HasValidIncome.ToFlag() * _person.IsFulltimeWorker.ToFlag() * studentsUniversityBuffer);
                alternative.AddUtilityTerm(31, _person.Household.HasValidIncome.ToFlag() * _person.IsPartTimeWorker.ToFlag() * industrialAgricultureConstructionBuffer);
                alternative.AddUtilityTerm(32, _person.Household.HasValidIncome.ToFlag() * _person.IsNotFullOrPartTimeWorker.ToFlag() * foodBuffer);
                alternative.AddUtilityTerm(33, _person.Household.HasValidIncome.ToFlag() * _person.IsNotFullOrPartTimeWorker.ToFlag() * medicalBuffer);

                alternative.AddUtilityTerm(34, _person.IsFulltimeWorker.ToFlag() * _person.Household.Has75KPlusIncome.ToFlag() * employmentTotalBuffer);
                alternative.AddUtilityTerm(35, _person.IsNotFullOrPartTimeWorker.ToFlag() * _person.Household.HasIncomeUnder50K.ToFlag() * governmentBuffer);
                alternative.AddUtilityTerm(36, _person.IsNotFullOrPartTimeWorker.ToFlag() * _person.Household.HasIncomeUnder50K.ToFlag() * employmentTotalBuffer);

                //Size
                alternative.AddUtilityTerm(51, _person.Household.HasValidIncome.ToFlag() * destinationParcel.EmploymentService);
                alternative.AddUtilityTerm(52, _person.Household.HasValidIncome.ToFlag() * destinationParcel.EmploymentEducation);
                alternative.AddUtilityTerm(53, _person.Household.HasValidIncome.ToFlag() * destinationParcel.EmploymentFood);
                alternative.AddUtilityTerm(54, _person.Household.HasValidIncome.ToFlag() * destinationParcel.EmploymentGovernment);
                alternative.AddUtilityTerm(55, _person.Household.HasValidIncome.ToFlag() * destinationParcel.EmploymentOffice);
                alternative.AddUtilityTerm(56, _person.Household.HasValidIncome.ToFlag() * destinationParcel.EmploymentRetail);
                alternative.AddUtilityTerm(57, _person.Household.HasValidIncome.ToFlag() * destinationParcel.EmploymentMedical);
                alternative.AddUtilityTerm(58, _person.Household.HasValidIncome.ToFlag() * employmentIndustrialAgricultureConstruction);
                alternative.AddUtilityTerm(59, _person.Household.HasValidIncome.ToFlag() * destinationParcel.StudentsUniversity);

                alternative.AddUtilityTerm(60, _person.Household.HasValidIncome.ToFlag() * _person.IsFulltimeWorker.ToFlag() * destinationParcel.EmploymentGovernment);
                alternative.AddUtilityTerm(61, _person.Household.HasValidIncome.ToFlag() * _person.IsFulltimeWorker.ToFlag() * employmentIndustrialAgricultureConstruction);
                alternative.AddUtilityTerm(62, _person.Household.HasValidIncome.ToFlag() * _person.IsPartTimeWorker.ToFlag() * employmentIndustrialAgricultureConstruction);
                alternative.AddUtilityTerm(63, _person.Household.HasValidIncome.ToFlag() * _person.IsNotFullOrPartTimeWorker.ToFlag() * destinationParcel.EmploymentEducation);
                alternative.AddUtilityTerm(64, _person.Household.HasValidIncome.ToFlag() * _person.IsNotFullOrPartTimeWorker.ToFlag() * destinationParcel.EmploymentFood);
                alternative.AddUtilityTerm(65, _person.Household.HasValidIncome.ToFlag() * _person.IsNotFullOrPartTimeWorker.ToFlag() * destinationParcel.EmploymentRetail);

                alternative.AddUtilityTerm(66, _person.Household.HasIncomeUnder50K.ToFlag() * destinationParcel.EmploymentRetail);
                alternative.AddUtilityTerm(67, _person.Household.HasIncomeUnder50K.ToFlag() * destinationParcel.EmploymentService);
                alternative.AddUtilityTerm(68, _person.Household.Has50To75KIncome.ToFlag() * destinationParcel.EmploymentMedical);
                alternative.AddUtilityTerm(69, _person.Household.Has50To75KIncome.ToFlag() * destinationParcel.EmploymentOffice);
                alternative.AddUtilityTerm(70, _person.Household.Has75KPlusIncome.ToFlag() * destinationParcel.EmploymentEducation);
                alternative.AddUtilityTerm(71, _person.Household.Has75KPlusIncome.ToFlag() * destinationParcel.EmploymentGovernment);
                alternative.AddUtilityTerm(72, _person.Household.Has75KPlusIncome.ToFlag() * destinationParcel.EmploymentMedical);
                alternative.AddUtilityTerm(73, _person.Household.Has75KPlusIncome.ToFlag() * destinationParcel.EmploymentOffice);

                alternative.AddUtilityTerm(74, _person.IsFulltimeWorker.ToFlag() * _person.Household.Has75KPlusIncome.ToFlag() * destinationParcel.EmploymentGovernment);
                alternative.AddUtilityTerm(75, _person.IsFulltimeWorker.ToFlag() * (!_person.Household.Has75KPlusIncome).ToFlag() * employmentIndustrialAgricultureConstruction);
                alternative.AddUtilityTerm(76, _person.IsPartTimeWorker.ToFlag() * (!_person.Household.HasIncomeUnder50K).ToFlag() * destinationParcel.EmploymentMedical);
                alternative.AddUtilityTerm(77, (!_person.IsFulltimeWorker).ToFlag() * _person.Household.Has75KPlusIncome.ToFlag() * destinationParcel.EmploymentOffice);
                alternative.AddUtilityTerm(78, _person.IsNotFullOrPartTimeWorker.ToFlag() * (!_person.Household.HasIncomeUnder50K).ToFlag() * destinationParcel.EmploymentRetail);

                alternative.AddUtilityTerm(79, _person.Household.HasMissingIncome.ToFlag() * destinationParcel.EmploymentTotal);
                alternative.AddUtilityTerm(80, _person.Household.HasMissingIncome.ToFlag() * destinationParcel.StudentsUniversity);

                //add any region-specific new terms in region-specific class, using coefficient numbers 91-100 or other unused variable #
                _parentClass.RegionSpecificCustomizations(alternative, _person, destinationParcel);


                // OD shadow pricing
                if (Global.Configuration.ShouldUseODShadowPricing)
                {
                    int res = _person.Household.ResidenceParcel.District;
                    int des = destinationParcel.District;
                    //var first = res <= des? res : des;
                    //var second = res <= des? des : res;
                    double shadowPriceConfigurationParameter = res == des ? Global.Configuration.WorkLocationOOShadowPriceCoefficient : Global.Configuration.WorkLocationODShadowPriceCoefficient;
                    int    odShadowPriceF12Value             = MAX_REGULAR_PARAMETER + Global.Configuration.NumberOfODShadowPricingDistricts * (res - 1) + des;
                    alternative.AddUtilityTerm(odShadowPriceF12Value, shadowPriceConfigurationParameter);
                }


                // set shadow price depending on persontype and add it to utility
                // we are using the sampling adjustment factor assuming that it is 1
                if (Global.Configuration.ShouldUseShadowPricing)
                {
                    alternative.AddUtilityTerm(1, destinationParcel.ShadowPriceForEmployment);
                }
            }
Exemplo n.º 4
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, IPersonWrapper person, int choice = Constants.DEFAULT_VALUE)
        {
            IParcelWrapper homeParcel   = person.Household.ResidenceParcel;
            IParcelWrapper workParcel   = person.IsUniversityStudent ? person.UsualSchoolParcel : person.UsualWorkParcel;
            IParcelWrapper schoolParcel = person.IsUniversityStudent ? null : person.UsualSchoolParcel;

            bool workParcelMissing   = workParcel == null;
            bool schoolParcelMissing = schoolParcel == null;

            const double maxTranDist = 1.5;

            double homeTranDist = 99.0;

            if (homeParcel.GetDistanceToTransit() >= 0.0001 && homeParcel.GetDistanceToTransit() <= maxTranDist)
            {
                homeTranDist = homeParcel.GetDistanceToTransit();
            }

            double workTranDist = 99.0;

            if (!workParcelMissing && workParcel.GetDistanceToTransit() >= 0.0001 && workParcel.GetDistanceToTransit() <= maxTranDist)
            {
                workTranDist = workParcel.GetDistanceToTransit();
            }

            double schoolTranDist = 99.0;

            if (!schoolParcelMissing && schoolParcel.GetDistanceToTransit() >= 0.0001 && schoolParcel.GetDistanceToTransit() <= maxTranDist)
            {
                schoolTranDist = schoolParcel.GetDistanceToTransit();
            }

            double workGenTimeNoPass   = -99.0;
            double workGenTimeWithPass = -99.0;

            if (!workParcelMissing && workTranDist < maxTranDist && homeTranDist < maxTranDist)
            {
                IEnumerable <IPathTypeModel> pathTypeModels = PathTypeModelFactory.Singleton.Run(
                    person.Household.RandomUtility,
                    homeParcel,
                    workParcel,
                    Global.Settings.Times.EightAM,
                    Global.Settings.Times.FivePM,
                    Global.Settings.Purposes.Work,
                    Global.Coefficients_BaseCostCoefficientPerMonetaryUnit,
                    Global.Configuration.Coefficients_MeanTimeCoefficient_Work,
                    /* isDrivingAge */ true,
                    /* householdCars */ 1,
                    /* transitPassOwnership */ 0,
                    /* carsAreAvs */ false,
                    0.0,
                    false,
                    Global.Settings.Modes.Transit);

                IPathTypeModel path = pathTypeModels.First();

                workGenTimeNoPass = path.GeneralizedTimeLogsum;

                pathTypeModels = PathTypeModelFactory.Singleton.Run(
                    person.Household.RandomUtility,
                    homeParcel,
                    workParcel,
                    Global.Settings.Times.EightAM,
                    Global.Settings.Times.FivePM,
                    Global.Settings.Purposes.Work,
                    Global.Coefficients_BaseCostCoefficientPerMonetaryUnit,
                    Global.Configuration.Coefficients_MeanTimeCoefficient_Work,
                    /* isDrivingAge */ true,
                    /* householdCars */ 1,
                    /* transitPassOwnership */ 0,
                    /* carsAreAvs */ false,
                    1.0,
                    false,
                    Global.Settings.Modes.Transit);

                path = pathTypeModels.First();

                workGenTimeWithPass = path.GeneralizedTimeLogsum;
            }

            //            double schoolGenTimeNoPass = -99.0;
            double schoolGenTimeWithPass = -99.0;

            if (!schoolParcelMissing && schoolTranDist < maxTranDist && homeTranDist < maxTranDist)
            {
                //                schoolGenTimeNoPass = path.GeneralizedTimeLogsum;
                IEnumerable <IPathTypeModel> pathTypeModels =
                    PathTypeModelFactory.Singleton.Run(
                        person.Household.RandomUtility,
                        homeParcel,
                        schoolParcel,
                        Global.Settings.Times.EightAM,
                        Global.Settings.Times.ThreePM,
                        Global.Settings.Purposes.School,
                        Global.Coefficients_BaseCostCoefficientPerMonetaryUnit,
                        Global.Configuration.Coefficients_MeanTimeCoefficient_Other,
                        /* isDrivingAge */ true,
                        /* householdCars */ 1,
                        /* transitPassOwnership */ 0,
                        /* carsAreAvs */ false,
                        1.0,
                        false,
                        Global.Settings.Modes.Transit);

                IPathTypeModel path = pathTypeModels.First();

                schoolGenTimeWithPass = path.GeneralizedTimeLogsum;
            }

            const double inflection = 0.50;

            double homeTranDist1 = Math.Pow(Math.Min(inflection, homeTranDist), 2.0);
            double homeTranDist2 = Math.Pow(Math.Max(homeTranDist - inflection, 0), 0.5);

            //            var workTranDist1 = Math.Pow(Math.Min(inflection, workTranDist),2.0);
            //            var workTranDist2 = Math.Pow(Math.Max(workTranDist - inflection, 0),0.5);

            const double minimumAggLogsum = -15.0;
            int          votSegment       = person.Household.GetVotALSegment();

            int    homeTaSegment            = homeParcel.TransitAccessSegment();
            double homeAggregateLogsumNoCar = Math.Max(minimumAggLogsum, Global.AggregateLogsums[homeParcel.ZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.NoCars][votSegment][homeTaSegment]);

            int    workTaSegment            = workParcelMissing ? 0 : workParcel.TransitAccessSegment();
            double workAggregateLogsumNoCar =
                workParcelMissing
                    ? 0
                    : Math.Max(minimumAggLogsum, Global.AggregateLogsums[workParcel.ZoneId][Global.Settings.Purposes.WorkBased][Global.Settings.CarOwnerships.NoCars][votSegment][workTaSegment]);

            int    schoolTaSegment            = schoolParcelMissing ? 0 : schoolParcel.TransitAccessSegment();
            double schoolAggregateLogsumNoCar =
                schoolParcelMissing
                    ? 0
                    : Math.Max(minimumAggLogsum, Global.AggregateLogsums[schoolParcel.ZoneId][Global.Settings.Purposes.WorkBased][Global.Settings.CarOwnerships.NoCars][votSegment][schoolTaSegment]);

            double transitPassCostChange = !Global.Configuration.IsInEstimationMode ? Global.Configuration.PathImpedance_TransitPassCostPercentChangeVersusBase : 0;

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

            alternative.AddUtilityTerm(1, 0.0);

            // 1 Transit pass
            alternative        = choiceProbabilityCalculator.GetAlternative(1, true, choice == 1);
            alternative.Choice = 1;

            alternative.AddUtilityTerm(1, 1.0);
            alternative.AddUtilityTerm(2, person.IsPartTimeWorker.ToFlag());
            alternative.AddUtilityTerm(3, (person.IsWorker && person.IsNotFullOrPartTimeWorker).ToFlag());
            alternative.AddUtilityTerm(4, person.IsUniversityStudent.ToFlag());
            alternative.AddUtilityTerm(5, person.IsRetiredAdult.ToFlag());
            alternative.AddUtilityTerm(6, person.IsNonworkingAdult.ToFlag());
            alternative.AddUtilityTerm(7, person.IsDrivingAgeStudent.ToFlag());
            alternative.AddUtilityTerm(8, person.IsChildUnder16.ToFlag());
            alternative.AddUtilityTerm(9, Math.Log(Math.Max(1, person.Household.Income)));
            alternative.AddUtilityTerm(10, person.Household.HasMissingIncome.ToFlag());
            alternative.AddUtilityTerm(11, workParcelMissing.ToFlag());
            alternative.AddUtilityTerm(12, schoolParcelMissing.ToFlag());
            alternative.AddUtilityTerm(13, (homeTranDist < 90.0) ? homeTranDist1 : 0);
            alternative.AddUtilityTerm(14, (homeTranDist < 90.0) ? homeTranDist2 : 0);
            alternative.AddUtilityTerm(15, (homeTranDist > 90.0) ? 1 : 0);
            //            alternative.AddUtility(16, (workTranDist < 90.0) ? workTranDist : 0);
            //            alternative.AddUtility(17, (workTranDist < 90.0) ? workTranDist2 : 0);
            //            alternative.AddUtility(18, (workTranDist > 90.0) ? 1 : 0);
            //            alternative.AddUtility(19, (schoolTranDist < 90.0) ? schoolTranDist : 0);
            //            alternative.AddUtility(20, (schoolTranDist > 90.0) ? 1 : 0);
            //            alternative.AddUtility(21, (!workParcelMissing && workGenTimeWithPass > -90 ) ? workGenTimeWithPass : 0);
            alternative.AddUtilityTerm(22, (!workParcelMissing && workGenTimeWithPass <= -90) ? 1 : 0);
            alternative.AddUtilityTerm(23, (!workParcelMissing && workGenTimeWithPass > -90 && workGenTimeNoPass > -90) ? workGenTimeNoPass - workGenTimeWithPass : 0);
            //            alternative.AddUtility(24, (!schoolParcelMissing && schoolGenTimeWithPass > -90 ) ? schoolGenTimeWithPass : 0);
            alternative.AddUtilityTerm(25, (!schoolParcelMissing && schoolGenTimeWithPass <= -90) ? 1 : 0);
            alternative.AddUtilityTerm(26, homeAggregateLogsumNoCar * (person.IsFullOrPartTimeWorker || person.IsUniversityStudent).ToFlag());
            alternative.AddUtilityTerm(27, homeAggregateLogsumNoCar * (person.IsDrivingAgeStudent || person.IsChildUnder16).ToFlag());
            alternative.AddUtilityTerm(28, homeAggregateLogsumNoCar * (person.IsNonworkingAdult).ToFlag());
            alternative.AddUtilityTerm(29, homeAggregateLogsumNoCar * (person.IsRetiredAdult).ToFlag());
            alternative.AddUtilityTerm(30, workParcelMissing ? 0 : workAggregateLogsumNoCar);
            alternative.AddUtilityTerm(31, schoolParcelMissing ? 0 : schoolAggregateLogsumNoCar);
            alternative.AddUtilityTerm(32, transitPassCostChange);
        }
Exemplo n.º 5
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, IPersonDayWrapper personDay, int purpose, int choice = Constants.DEFAULT_VALUE)
        {
            IHouseholdWrapper household       = personDay.Household;
            IParcelWrapper    residenceParcel = household.ResidenceParcel;
            IPersonWrapper    person          = personDay.Person;

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

            double purposeLogsum;

            if (purpose == Global.Settings.Purposes.Work)
            {
                if (person.UsualWorkParcel == null || person.UsualWorkParcelId == household.ResidenceParcelId)
                {
                    purposeLogsum = 0;
                }
                else
                {
                    int destinationArrivalTime   = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.WorkTourModeModel);
                    int destinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.WorkTourModeModel);
                    ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeModel>().RunNested(personDay, residenceParcel, person.UsualWorkParcel, destinationArrivalTime, destinationDepartureTime, household.VehiclesAvailable);

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

                    purposeLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                }
            }
            else
            {
                int carOwnership  = person.GetCarOwnershipSegment();
                int votSegment    = person.Household.GetVotALSegment();
                int transitAccess = residenceParcel.TransitAccessSegment();

                purposeLogsum = Global.AggregateLogsums[household.ResidenceZoneId][purpose][carOwnership][votSegment][transitAccess];
            }

            // 1 TOUR

            ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(0, true, choice == 1);

            alternative.Choice = 1;

            alternative.AddUtilityTerm(1, purpose);

            // 2 TOURS

            alternative = choiceProbabilityCalculator.GetAlternative(1, true, choice == 2);

            const int two = 2;

            alternative.Choice = two;

            alternative.AddUtilityTerm(100 * purpose + 1, person.IsFulltimeWorker.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 2, person.IsPartTimeWorker.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 3, person.IsRetiredAdult.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 4, person.IsNonworkingAdult.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 5, person.IsUniversityStudent.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 6, person.IsDrivingAgeStudent.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 7, person.IsChildAge5Through15.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 8, person.IsChildUnder5.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 9, household.Has0To25KIncome.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 10, household.Has25To45KIncome.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 11, household.Has75KPlusIncome.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 12, carsPerDriver);
            alternative.AddUtilityTerm(100 * purpose + 13, person.IsOnlyAdult().ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 14, person.IsOnlyFullOrPartTimeWorker().ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 15, 0);
            alternative.AddUtilityTerm(100 * purpose + 16, person.IsFemale.ToFlag() * person.IsAdult.ToFlag() * (!household.HasChildrenUnder16).ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 17, person.IsFemale.ToFlag() * person.IsAdult.ToFlag() * household.HasChildrenUnder5.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 18, person.IsFemale.ToFlag() * person.IsAdult.ToFlag() * household.HasChildrenAge5Through15.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 19, person.IsMale.ToFlag() * person.IsAdult.ToFlag() * household.HasChildrenUnder5.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 20, person.IsMale.ToFlag() * person.IsAdult.ToFlag() * household.HasChildrenAge5Through15.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 21, person.AgeIsBetween18And25.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 22, person.AgeIsBetween26And35.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 23, person.AgeIsBetween51And65.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 24, person.WorksAtHome().ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 25, mixedDensity);
            alternative.AddUtilityTerm(100 * purpose + 26, intersectionDensity);
            alternative.AddUtilityTerm(100 * purpose + 31, personDay.WorkTours);
            alternative.AddUtilityTerm(100 * purpose + 32, personDay.SchoolTours);
            alternative.AddUtilityTerm(100 * purpose + 33, personDay.EscortTours);
            alternative.AddUtilityTerm(100 * purpose + 34, personDay.PersonalBusinessTours);
            alternative.AddUtilityTerm(100 * purpose + 35, personDay.ShoppingTours);
            alternative.AddUtilityTerm(100 * purpose + 36, personDay.MealTours);
            alternative.AddUtilityTerm(100 * purpose + 37, personDay.SocialTours);
            alternative.AddUtilityTerm(100 * purpose + 41, personDay.WorkStops);

            if (purpose <= Global.Settings.Purposes.Escort)
            {
                alternative.AddUtilityTerm(100 * purpose + 42, personDay.SchoolStops);
            }

            alternative.AddUtilityTerm(100 * purpose + 43, personDay.EscortStops);
            alternative.AddUtilityTerm(100 * purpose + 44, personDay.PersonalBusinessStops);
            alternative.AddUtilityTerm(100 * purpose + 45, personDay.ShoppingStops);
            alternative.AddUtilityTerm(100 * purpose + 46, personDay.MealStops);
            alternative.AddUtilityTerm(100 * purpose + 47, personDay.SocialStops);
            alternative.AddUtilityTerm(100 * purpose + 50 + two, 1);                 // ASC
            alternative.AddUtilityTerm(100 * purpose + 23 + 2 * two, purposeLogsum); // accessibility effect has different coefficient for 2 and 3+

            // 3+ TOURS

            alternative = choiceProbabilityCalculator.GetAlternative(2, true, choice == 3);

            const int three = 3;

            alternative.Choice = three;

            alternative.AddUtilityTerm(100 * purpose + 1, person.IsFulltimeWorker.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 2, person.IsPartTimeWorker.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 3, person.IsRetiredAdult.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 4, person.IsNonworkingAdult.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 5, person.IsUniversityStudent.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 6, person.IsDrivingAgeStudent.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 7, person.IsChildAge5Through15.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 8, person.IsChildUnder5.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 9, household.Has0To25KIncome.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 10, household.Has25To45KIncome.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 11, household.Has75KPlusIncome.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 12, carsPerDriver);
            alternative.AddUtilityTerm(100 * purpose + 13, person.IsOnlyAdult().ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 14, person.IsOnlyFullOrPartTimeWorker().ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 15, 0);
            alternative.AddUtilityTerm(100 * purpose + 16, person.IsFemale.ToFlag() * person.IsAdult.ToFlag() * (!household.HasChildrenUnder16).ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 17, person.IsFemale.ToFlag() * person.IsAdult.ToFlag() * household.HasChildrenUnder5.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 18, person.IsFemale.ToFlag() * person.IsAdult.ToFlag() * household.HasChildrenAge5Through15.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 19, person.IsMale.ToFlag() * person.IsAdult.ToFlag() * household.HasChildrenUnder5.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 20, person.IsMale.ToFlag() * person.IsAdult.ToFlag() * household.HasChildrenAge5Through15.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 21, person.AgeIsBetween18And25.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 22, person.AgeIsBetween26And35.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 23, person.AgeIsBetween51And65.ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 24, person.WorksAtHome().ToFlag());
            alternative.AddUtilityTerm(100 * purpose + 25, mixedDensity);
            alternative.AddUtilityTerm(100 * purpose + 26, intersectionDensity);
            alternative.AddUtilityTerm(100 * purpose + 31, personDay.WorkTours);
            alternative.AddUtilityTerm(100 * purpose + 32, personDay.SchoolTours);
            alternative.AddUtilityTerm(100 * purpose + 33, personDay.EscortTours);
            alternative.AddUtilityTerm(100 * purpose + 34, personDay.PersonalBusinessTours);
            alternative.AddUtilityTerm(100 * purpose + 35, personDay.ShoppingTours);
            alternative.AddUtilityTerm(100 * purpose + 36, personDay.MealTours);
            alternative.AddUtilityTerm(100 * purpose + 37, personDay.SocialTours);
            alternative.AddUtilityTerm(100 * purpose + 41, personDay.WorkStops);

            if (purpose <= Global.Settings.Purposes.Escort)
            {
                alternative.AddUtilityTerm(100 * purpose + 42, personDay.SchoolStops);
            }

            alternative.AddUtilityTerm(100 * purpose + 43, personDay.EscortStops);
            alternative.AddUtilityTerm(100 * purpose + 44, personDay.PersonalBusinessStops);
            alternative.AddUtilityTerm(100 * purpose + 45, personDay.ShoppingStops);
            alternative.AddUtilityTerm(100 * purpose + 46, personDay.MealStops);
            alternative.AddUtilityTerm(100 * purpose + 47, personDay.SocialStops);
            alternative.AddUtilityTerm(100 * purpose + 50 + three, 1);                 // ASC
            alternative.AddUtilityTerm(100 * purpose + 23 + 2 * three, purposeLogsum); // accessibility effect has different coefficient for 2 and 3+
        }
Exemplo n.º 6
0
            public void SetUtilities(ISampleItem sampleItem, int sampleFrequency)
            {
                if (sampleItem == null)
                {
                    throw new ArgumentNullException("sampleItem");
                }

                ChoiceProbabilityCalculator.Alternative alternative = sampleItem.Alternative;

                if (!alternative.Available)
                {
                    return;
                }

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

                //                var destinationZoneTotals = ChoiceModelRunner.ZoneTotals[destinationParcel.ZoneId];

                alternative.Choice = destinationParcel;

                ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <SchoolTourModeModel>().RunNested(_person, _person.Household.ResidenceParcel, destinationParcel, _destinationArrivalTime, _destinationDepartureTime, _person.Household.HouseholdTotals.DrivingAgeMembers);
                double schoolTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                int    votSegment       = _person.Household.GetVotALSegment();
                int    taSegment        = destinationParcel.TransitAccessSegment();
                double aggregateLogsum  = Global.AggregateLogsums[destinationParcel.ZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.OneOrMoreCarsPerAdult][votSegment][taSegment];

                double distanceFromOrigin = _person.Household.ResidenceParcel.DistanceFromOrigin(destinationParcel, 1);
                double distance1          = Math.Min(distanceFromOrigin, .1);
                double distance2          = Math.Max(0, Math.Min(distanceFromOrigin - .1, .5 - .1));
                double distance3          = Math.Max(0, distanceFromOrigin - .5);
                double distanceLog        = Math.Log(1 + distanceFromOrigin);
                double distanceFromWork   = _person.IsFullOrPartTimeWorker ? _person.UsualWorkParcel.DistanceFromWorkLog(destinationParcel, 1) : 0;
                //                var millionsSquareFeet = destinationZoneTotals.MillionsSquareFeet();

                // zone densities
                //                var eduDensity = destinationZoneTotals.GetEmploymentEducationDensity(millionsSquareFeet);
                //                var govDensity = destinationZoneTotals.GetEmploymentGovernmentDensity(millionsSquareFeet);
                //                var offDensity = destinationZoneTotals.GetEmploymentOfficeDensity(millionsSquareFeet);
                //                var serDensity = destinationZoneTotals.GetEmploymentServiceDensity(millionsSquareFeet);
                //                var houDensity = destinationZoneTotals.GetHouseholdsDensity(millionsSquareFeet);

                // parcel buffers
                double educationBuffer1 = Math.Log(destinationParcel.EmploymentEducationBuffer1 + 1);
                //var governmentBuffer1 = Math.Log(destinationParcel.EmploymentGovernmentBuffer1 + 1);
                //var officeBuffer1 = Math.Log(destinationParcel.EmploymentOfficeBuffer1 + 1);
                //var serviceBuffer1 = Math.Log(destinationParcel.EmploymentServiceBuffer1 + 1);
                //var householdsBuffer1 = Math.Log(destinationParcel.HouseholdsBuffer1 + 1);
                //var retailBuffer1 = Math.Log(destinationParcel.EmploymentRetailBuffer1 + 1);
                //var industrialAgricultureConstructionBuffer1 = Math.Log(destinationParcel.EmploymentIndustrialBuffer1 + destinationParcel.EmploymentAgricultureConstructionBuffer1 + 1);
                //var foodBuffer1 = Math.Log(destinationParcel.EmploymentFoodBuffer1 + 1);
                //var medicalBuffer1 = Math.Log(destinationParcel.EmploymentMedicalBuffer1 + 1);
                //var employmentTotalBuffer1 = Math.Log(destinationParcel.EmploymentTotalBuffer1 + 1);
                double studentsUniversityBuffer1 = Math.Log(destinationParcel.StudentsUniversityBuffer1 + 1);
                double studentsK8Buffer1         = Math.Log(destinationParcel.StudentsK8Buffer1 + 1);
                double studentsHighSchoolBuffer1 = Math.Log(destinationParcel.StudentsHighSchoolBuffer1 + 1);

                //var educationBuffer2 = Math.Log(destinationParcel.EmploymentEducationBuffer2 + 1);
                //var governmentBuffer2 = Math.Log(destinationParcel.EmploymentGovernmentBuffer2 + 1);
                //var officeBuffer2 = Math.Log(destinationParcel.EmploymentOfficeBuffer2 + 1);
                //var serviceBuffer2 = Math.Log(destinationParcel.EmploymentServiceBuffer2 + 1);
                double householdsBuffer2 = Math.Log(destinationParcel.HouseholdsBuffer2 + 1);
                //var retailBuffer2 = Math.Log(destinationParcel.EmploymentRetailBuffer2 + 1);
                //var industrialAgricultureConstructionBuffer2 = Math.Log(destinationParcel.EmploymentIndustrialBuffer2 + destinationParcel.EmploymentAgricultureConstructionBuffer2 + 1);
                //var foodBuffer2 = Math.Log(destinationParcel.EmploymentFoodBuffer2 + 1);
                //var medicalBuffer2 = Math.Log(destinationParcel.EmploymentMedicalBuffer2 + 1);
                double employmentTotalBuffer2    = Math.Log(destinationParcel.EmploymentTotalBuffer2 + 1);
                double studentsUniversityBuffer2 = Math.Log(destinationParcel.StudentsUniversityBuffer2 + 1);

                //var studentsK8Buffer2 = Math.Log(destinationParcel.StudentsK8Buffer2 + 1);
                //var studentsHighSchoolBuffer2 = Math.Log(destinationParcel.StudentsHighSchoolBuffer2 + 1);

                //                var educationBuffer1 = Math.Log(Math.Max(0.0, destinationParcel.EmploymentEducationBuffer1 - destinationParcel.EmploymentEducation)  + 1);
                //                var governmentBuffer1 = Math.Log(Math.Max(0.0, destinationParcel.EmploymentGovernmentBuffer1 - destinationParcel.EmploymentGovernment)  + 1);
                //                var officeBuffer1 = Math.Log(Math.Max(0.0, destinationParcel.EmploymentOfficeBuffer1 - destinationParcel.EmploymentOffice)  + 1);
                //                var serviceBuffer1 = Math.Log(Math.Max(0.0, destinationParcel.EmploymentServiceBuffer1 - destinationParcel.EmploymentService)  + 1);
                //                var householdsBuffer1 = Math.Log(Math.Max(0.0, destinationParcel.HouseholdsBuffer1 - destinationParcel.Households)  + 1);
                //                var retailBuffer1 = Math.Log(Math.Max(0.0, destinationParcel.EmploymentRetailBuffer1 - destinationParcel.EmploymentRetail)  + 1);
                //                var industrialAgricultureConstructionBuffer1 = Math.Log(Math.Max(0.0, destinationParcel.EmploymentIndustrialBuffer1 + destinationParcel.EmploymentAgricultureConstructionBuffer1
                //                    - destinationParcel.EmploymentIndustrial - destinationParcel.EmploymentAgricultureConstruction)    + 1);
                //                var foodBuffer1 = Math.Log(Math.Max(0.0, destinationParcel.EmploymentFoodBuffer1 - destinationParcel.EmploymentFood)  + 1);
                //                var medicalBuffer1 = Math.Log(Math.Max(0.0, destinationParcel.EmploymentMedicalBuffer1 - destinationParcel.EmploymentMedical)  + 1);
                //                var employmentTotalBuffer1 = Math.Log(Math.Max(0.0, destinationParcel.EmploymentTotalBuffer1 - destinationParcel.EmploymentTotal)  + 1);
                //                var studentsUniversityBuffer1 = Math.Log(Math.Max(0.0, destinationParcel.StudentsUniversityBuffer1 - destinationParcel.StudentsUniversity)  + 1);
                //                var studentsK8Buffer1 = Math.Log(Math.Max(0.0, destinationParcel.StudentsK8Buffer1 - destinationParcel.StudentsK8)  + 1);
                //                var studentsHighSchoolBuffer1 = Math.Log(Math.Max(0.0, destinationParcel.StudentsHighSchoolBuffer1 - destinationParcel.StudentsHighSchool)  + 1);
                //
                //                var educationBuffer2 = Math.Log(Math.Max(0.0, destinationParcel.EmploymentEducationBuffer2 - destinationParcel.EmploymentEducation)  + 1);
                //                var governmentBuffer2 = Math.Log(Math.Max(0.0, destinationParcel.EmploymentGovernmentBuffer2 - destinationParcel.EmploymentGovernment)  + 1);
                //                var officeBuffer2 = Math.Log(Math.Max(0.0, destinationParcel.EmploymentOfficeBuffer2 - destinationParcel.EmploymentOffice)  + 1);
                //                var serviceBuffer2 = Math.Log(Math.Max(0.0, destinationParcel.EmploymentServiceBuffer2 - destinationParcel.EmploymentService)  + 1);
                //                var householdsBuffer2 = Math.Log(Math.Max(0.0, destinationParcel.HouseholdsBuffer2 - destinationParcel.Households)  + 1);
                //                var retailBuffer2 = Math.Log(Math.Max(0.0, destinationParcel.EmploymentRetailBuffer2 - destinationParcel.EmploymentRetail)  + 1);
                //                var industrialAgricultureConstructionBuffer2 = Math.Log(Math.Max(0.0, destinationParcel.EmploymentIndustrialBuffer2 + destinationParcel.EmploymentAgricultureConstructionBuffer2
                //                    - destinationParcel.EmploymentIndustrial - destinationParcel.EmploymentAgricultureConstruction)    + 1);
                //                var foodBuffer2 = Math.Log(Math.Max(0.0, destinationParcel.EmploymentFoodBuffer2 - destinationParcel.EmploymentFood)  + 1);
                //                var medicalBuffer2 = Math.Log(Math.Max(0.0, destinationParcel.EmploymentMedicalBuffer2 - destinationParcel.EmploymentMedical)  + 1);
                //                var employmentTotalBuffer2 = Math.Log(Math.Max(0.0, destinationParcel.EmploymentTotalBuffer2 - destinationParcel.EmploymentTotal)  + 1);
                //                var studentsUniversityBuffer2 = Math.Log(Math.Max(0.0, destinationParcel.StudentsUniversityBuffer2 - destinationParcel.StudentsUniversity)  + 1);
                //                var studentsK8Buffer2 = Math.Log(Math.Max(0.0, destinationParcel.StudentsK8Buffer2 - destinationParcel.StudentsK8)  + 1);
                //                var studentsHighSchoolBuffer2 = Math.Log(Math.Max(0.0, destinationParcel.StudentsHighSchoolBuffer2 - destinationParcel.StudentsHighSchool)  + 1);

                alternative.AddUtilityTerm(1, sampleItem.AdjustmentFactor);

                alternative.AddUtilityTerm(2, _person.IsChildUnder5.ToFlag() * schoolTourLogsum);
                alternative.AddUtilityTerm(3, _person.IsChildAge5Through15.ToFlag() * schoolTourLogsum);
                alternative.AddUtilityTerm(4, _person.IsDrivingAgeStudent.ToFlag() * schoolTourLogsum);
                alternative.AddUtilityTerm(5, _person.IsUniversityStudent.ToFlag() * schoolTourLogsum);
                alternative.AddUtilityTerm(6, (!_person.IsStudentAge).ToFlag() * schoolTourLogsum);

                alternative.AddUtilityTerm(7, _person.IsChildUnder5.ToFlag() * distance1);
                alternative.AddUtilityTerm(8, _person.IsChildUnder5.ToFlag() * distance2);
                alternative.AddUtilityTerm(9, _person.IsChildUnder5.ToFlag() * distance3);
                alternative.AddUtilityTerm(10, _person.IsChildAge5Through15.ToFlag() * distance1);
                alternative.AddUtilityTerm(11, _person.IsChildAge5Through15.ToFlag() * distance2);
                alternative.AddUtilityTerm(12, _person.IsChildAge5Through15.ToFlag() * distance3);
                alternative.AddUtilityTerm(13, _person.IsDrivingAgeStudent.ToFlag() * distanceLog);
                alternative.AddUtilityTerm(14, _person.IsUniversityStudent.ToFlag() * distanceLog);
                alternative.AddUtilityTerm(15, (!_person.IsStudentAge).ToFlag() * distanceLog);
                alternative.AddUtilityTerm(16, (!_person.IsStudentAge).ToFlag() * distanceFromWork);

                alternative.AddUtilityTerm(17, _person.IsChildUnder5.ToFlag() * aggregateLogsum);
                alternative.AddUtilityTerm(18, _person.IsChildAge5Through15.ToFlag() * aggregateLogsum);
                alternative.AddUtilityTerm(19, _person.IsDrivingAgeStudent.ToFlag() * aggregateLogsum);
                alternative.AddUtilityTerm(20, _person.IsUniversityStudent.ToFlag() * aggregateLogsum);
                alternative.AddUtilityTerm(21, (!_person.IsStudentAge).ToFlag() * aggregateLogsum);

                //Neighborhood
                alternative.AddUtilityTerm(30, _person.IsChildUnder5.ToFlag() * householdsBuffer2);
                alternative.AddUtilityTerm(31, _person.IsChildUnder5.ToFlag() * studentsHighSchoolBuffer1);
                alternative.AddUtilityTerm(32, _person.IsChildUnder5.ToFlag() * employmentTotalBuffer2);
                alternative.AddUtilityTerm(33, _person.IsChildAge5Through15.ToFlag() * studentsK8Buffer1);
                alternative.AddUtilityTerm(34, _person.IsDrivingAgeStudent.ToFlag() * studentsHighSchoolBuffer1);
                alternative.AddUtilityTerm(35, _person.IsUniversityStudent.ToFlag() * educationBuffer1);
                alternative.AddUtilityTerm(36, _person.IsAdult.ToFlag() * studentsUniversityBuffer1);
                alternative.AddUtilityTerm(37, _person.IsAdult.ToFlag() * studentsUniversityBuffer2);
                alternative.AddUtilityTerm(38, _person.IsAdult.ToFlag() * studentsK8Buffer1);

                //Size
                alternative.AddUtilityTerm(61, _person.IsChildUnder5.ToFlag() * destinationParcel.EmploymentEducation);
                alternative.AddUtilityTerm(62, _person.IsChildUnder5.ToFlag() * destinationParcel.EmploymentService);
                alternative.AddUtilityTerm(63, _person.IsChildUnder5.ToFlag() * destinationParcel.EmploymentOffice);
                alternative.AddUtilityTerm(64, _person.IsChildUnder5.ToFlag() * destinationParcel.EmploymentTotal);
                alternative.AddUtilityTerm(65, _person.IsChildUnder5.ToFlag() * 10.0 * destinationParcel.Households);
                alternative.AddUtilityTerm(66, _person.IsChildUnder5.ToFlag() * destinationParcel.StudentsK8);
                alternative.AddUtilityTerm(67, _person.IsChildAge5Through15.ToFlag() * destinationParcel.EmploymentEducation);
                alternative.AddUtilityTerm(68, _person.IsChildAge5Through15.ToFlag() * destinationParcel.EmploymentService);
                alternative.AddUtilityTerm(69, _person.IsChildAge5Through15.ToFlag() * destinationParcel.StudentsHighSchool);
                alternative.AddUtilityTerm(70, _person.IsChildAge5Through15.ToFlag() * destinationParcel.EmploymentTotal);
                alternative.AddUtilityTerm(71, _person.IsChildAge5Through15.ToFlag() * 10.0 * destinationParcel.Households);
                alternative.AddUtilityTerm(72, _person.IsChildAge5Through15.ToFlag() * destinationParcel.StudentsK8);
                alternative.AddUtilityTerm(73, _person.IsDrivingAgeStudent.ToFlag() * destinationParcel.EmploymentEducation);
                alternative.AddUtilityTerm(74, _person.IsDrivingAgeStudent.ToFlag() * destinationParcel.EmploymentService);
                alternative.AddUtilityTerm(75, _person.IsDrivingAgeStudent.ToFlag() * destinationParcel.EmploymentOffice);
                alternative.AddUtilityTerm(76, _person.IsDrivingAgeStudent.ToFlag() * destinationParcel.EmploymentTotal);
                alternative.AddUtilityTerm(77, _person.IsDrivingAgeStudent.ToFlag() * 10.0 * destinationParcel.Households);
                alternative.AddUtilityTerm(78, _person.IsDrivingAgeStudent.ToFlag() * destinationParcel.StudentsHighSchool);
                alternative.AddUtilityTerm(79, _person.IsAdult.ToFlag() * destinationParcel.EmploymentEducation);
                alternative.AddUtilityTerm(80, _person.IsAdult.ToFlag() * destinationParcel.EmploymentService);
                alternative.AddUtilityTerm(81, _person.IsAdult.ToFlag() * destinationParcel.EmploymentOffice);
                alternative.AddUtilityTerm(82, _person.IsAdult.ToFlag() * destinationParcel.EmploymentTotal);
                alternative.AddUtilityTerm(83, _person.IsAdult.ToFlag() * destinationParcel.StudentsUniversity);
                alternative.AddUtilityTerm(84, _person.IsAdult.ToFlag() * destinationParcel.StudentsHighSchool);

                // set shadow price depending on persontype and add it to utility
                // we are using the sampling adjustment factor assuming that it is 1

                if (Global.Configuration.ShouldUseShadowPricing)
                {
                    alternative.AddUtilityTerm(1, _person.IsAdult ? destinationParcel.ShadowPriceForStudentsUniversity : destinationParcel.ShadowPriceForStudentsK12);
                }

                //remove nesting for estimation of conditional MNL
                alternative.AddNestedAlternative(_sampleSize + 2, 0, 99);
            }
Exemplo n.º 7
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);

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

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

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

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

            ChoiceModelUtility.DrawRandomTourTimePeriodsActum(tour, tourCategory);

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

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


            DestinationSampler       destinationSampler       = new DestinationSampler(choiceProbabilityCalculator, segment, sampleSize, choice, tour.OriginParcel);
            TourDestinationUtilities 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
            Dictionary <DestinationSampler.TourSampleItem, int> sampleItems = destinationSampler.SampleAndReturnTourDestinations(tourDestinationUtilities);

            int index = 0;

            foreach (KeyValuePair <DestinationSampler.TourSampleItem, int> sampleItem in sampleItems)
            {
                bool           available         = sampleItem.Key.Available;
                bool           isChosen          = sampleItem.Key.IsChosen;
                double         adjustmentFactor  = sampleItem.Key.AdjustmentFactor;
                IParcelWrapper 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);
                }

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


                if (!available)
                {
                    continue;
                }

                double 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());
                        ChoiceProbabilityCalculator.Alternative 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());
                        ChoiceProbabilityCalculator.Alternative 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());
                    ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <TourModeTimeModel>().RunNested(tour, destinationParcel, tour.Household.VehiclesAvailable, tour.Person.GetTransitFareDiscountFraction());
                    tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                }

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

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


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

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

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

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

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

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


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


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

                int carCompetitionFlag   = FlagUtility.GetCarCompetitionFlag(carOwnership); // exludes no cars
                int noCarCompetitionFlag = FlagUtility.GetNoCarCompetitionFlag(carOwnership);
                int 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);
                }
            }
        }