Exemplo n.º 1
0
        //MBADD runnested
        public ChoiceProbabilityCalculator.Alternative RunNested(PersonWrapper person, IParcelWrapper originParcel, IParcelWrapper destinationParcel, int destinationArrivalTime, int destinationDepartureTime, int householdCars, double transitDiscountFraction, int purpose)
        {
            if (person == null)
            {
                throw new ArgumentNullException("person");
            }

            TourWrapper tour = (TourWrapper)_creator.CreateWrapper(person, null, originParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, purpose);

            return(RunNested(tour, destinationParcel, householdCars, transitDiscountFraction));
        }
Exemplo n.º 2
0
        protected override void RegionSpecificCustomizations(ChoiceProbabilityCalculator.Alternative alternative, IPersonWrapper _person, IParcelWrapper destinationParcel)
        {
            int homedist = _person.Household.ResidenceParcel.District;
            int zonedist = destinationParcel.District;

            //add any region-specific new terms in region-specific class, using coefficient numbers 91-97, 99,100 or other unused variable #
            //Global.PrintFile.WriteLine("Default PSRC_WorkLocationModel.RegionSpecificCustomizations called");
            int homeSKitWorkTRP   = homedist == 11 && (zonedist == 8 || zonedist == 10 || zonedist == 7) ? 1 : 0;
            int homeKitWorkTRP    = homedist == 9 && (zonedist == 8 || zonedist == 10 || zonedist == 7) ? 1 : 0;
            int homeEastWorkCBD   = homedist == 6 && zonedist == 4 ? 1 : 0;
            int homeKitWorkCBD    = (homedist == 9 || homedist == 11) && (zonedist == 4) ? 1 : 0;
            int homeTacWorkKit    = homedist == 8 && (zonedist == 9 || zonedist == 11) ? 1 : 0;
            int homeEvWorkEv      = homedist == 2 && zonedist == 2 ? 1 : 0;
            int homeWSWorkEast    = homedist == 5 && zonedist == 6 ? 1 : 0;
            int homeEastWorkEast  = homedist == 6 && zonedist == 6 ? 1 : 0;
            int homeKitWorkNotKit = (homedist == 9 || homedist == 11) && zonedist != 9 && zonedist != 11 ? 1 : 0;
            int homeSTacWorkCBD   = (homedist == 5 || homedist == 8) && zonedist == 9 ? 1 : 0;

            alternative.AddUtilityTerm(91, homeEastWorkEast);
            alternative.AddUtilityTerm(92, homeTacWorkKit);
            alternative.AddUtilityTerm(93, homeEvWorkEv);
            alternative.AddUtilityTerm(94, homeWSWorkEast);
            alternative.AddUtilityTerm(95, homeSKitWorkTRP);
            alternative.AddUtilityTerm(96, homeSTacWorkCBD);
            alternative.AddUtilityTerm(97, homeKitWorkTRP);
            alternative.AddUtilityTerm(49, homeKitWorkNotKit);
            alternative.AddUtilityTerm(99, homeEastWorkCBD);
            alternative.AddUtilityTerm(100, homeKitWorkCBD);
        }
Exemplo n.º 3
0
        protected override void RegionSpecificCustomizations(ChoiceProbabilityCalculator.Alternative alternative, ITourWrapper tour, int pathType, int mode, IParcelWrapper destinationParcel)
        {
            //Global.PrintFile.WriteLine("Default PSRC_WorkTourModeModel.RegionSpecificCustomizations called");

            if (mode == Global.Settings.Modes.Transit && pathType != Global.Settings.PathTypes.LightRail && pathType != Global.Settings.PathTypes.CommuterRail && pathType != Global.Settings.PathTypes.Ferry)
            {
                alternative.AddUtilityTerm(200 + tour.OriginParcel.District, 1); //district specific transit calibration constant
                alternative.AddUtilityTerm(300 + destinationParcel.District, 1); //district specific transit calibration constant
            }
        }
        protected override void RegionSpecificOtherTourDistrictCoefficients(ChoiceProbabilityCalculator.Alternative alternative, ITourWrapper _tour, IParcelWrapper destinationParcel)
        {
            //add any region-specific new terms in region-specific class, using coefficient numbers 114-120, or other unused variable #
            //Global.PrintFile.WriteLine("JAX_OtherTourDestinationModel.RegionSpecificOtherTourDistrictCoefficients called");
            var crossriver = ImpedanceRoster.GetValue("crossriver", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot,
                                                      1, _tour.OriginParcel, destinationParcel).Variable;
            var intracounty = ImpedanceRoster.GetValue("intracounty", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot,
                                                       1, _tour.OriginParcel, destinationParcel).Variable;


            if (_tour.DestinationPurpose == Global.Settings.Purposes.Escort)
            {
                alternative.AddUtilityTerm(114, crossriver);
            }
            else if (_tour.DestinationPurpose == Global.Settings.Purposes.PersonalBusiness || _tour.DestinationPurpose == Global.Settings.Purposes.Medical)
            {
                alternative.AddUtilityTerm(115, crossriver);
                alternative.AddUtilityTerm(119, intracounty);
            }
            else if (_tour.DestinationPurpose == Global.Settings.Purposes.Shopping)
            {
                alternative.AddUtilityTerm(116, crossriver);
                alternative.AddUtilityTerm(119, intracounty);
            }
            else if (_tour.DestinationPurpose == Global.Settings.Purposes.Meal)
            {
                alternative.AddUtilityTerm(117, crossriver);
                alternative.AddUtilityTerm(119, intracounty);
            }
            else if (_tour.DestinationPurpose == Global.Settings.Purposes.Social || _tour.DestinationPurpose == Global.Settings.Purposes.Recreation)
            {
                alternative.AddUtilityTerm(118, crossriver);
                alternative.AddUtilityTerm(119, intracounty);
            }
        }
        public ChoiceProbabilityCalculator.Alternative RunNested(IPersonDayWrapper personDay, IParcelWrapper originParcel, IParcelWrapper destinationParcel, int destinationArrivalTime, int destinationDepartureTime, int householdCars)
        {
            if (personDay == null)
            {
                throw new ArgumentNullException("personDay");
            }

            ITourWrapper tour = _creator.CreateWrapper(personDay.Person, personDay, originParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, Global.Settings.Purposes.Work);

            return(RunNested(tour, destinationParcel, householdCars, personDay.Person.GetTransitFareDiscountFraction()));
        }
Exemplo n.º 6
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITourWrapper subtour, IEnumerable <IPathTypeModel> pathTypeModels, IParcelWrapper destinationParcel, int parentTourMode, int choice = Constants.DEFAULT_VALUE)
        {
            IHouseholdWrapper household = subtour.Household;
            IPersonWrapper    person    = subtour.Person;
            IPersonDayWrapper personDay = subtour.PersonDay;

            // household inputs
            int income0To25KFlag  = household.Has0To25KIncome.ToFlag();
            int income25To50KFlag = household.Has25To50KIncome.ToFlag();
            int incomeOver100Flag = household.Has100KPlusIncome.ToFlag();

            // person inputs
            int maleFlag = person.IsMale.ToFlag();

            // tour inputs
            int sovTourFlag  = (parentTourMode == Global.Settings.Modes.Sov).ToFlag();
            int hov2TourFlag = (parentTourMode == Global.Settings.Modes.Hov2).ToFlag();
            int bikeTourFlag = (parentTourMode == Global.Settings.Modes.Bike).ToFlag();
            int walkTourFlag = (parentTourMode == Global.Settings.Modes.Walk).ToFlag();
            int tncTourFlag  = (parentTourMode == Global.Settings.Modes.PaidRideShare).ToFlag();

            // remaining inputs
            IParcelWrapper originParcel           = subtour.OriginParcel;
            int            parkingDuration        = ChoiceModelUtility.GetParkingDuration(person.IsFulltimeWorker);
            double         destinationParkingCost = destinationParcel.ParkingCostBuffer1(parkingDuration);

            ChoiceModelUtility.SetEscortPercentages(personDay, out double escortPercentage, out double nonEscortPercentage, true);


            foreach (IPathTypeModel pathTypeModel in pathTypeModels)
            {
                int  mode      = pathTypeModel.Mode;
                bool available = (pathTypeModel.Mode != Global.Settings.Modes.PaidRideShare || Global.Configuration.PaidRideShareModeIsAvailable) &&
                                 pathTypeModel.Available;
                double generalizedTimeLogsum = pathTypeModel.GeneralizedTimeLogsum;

                ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(mode, available, choice == mode);
                alternative.Choice = mode;

                alternative.AddNestedAlternative(_nestedAlternativeIds[pathTypeModel.Mode], _nestedAlternativeIndexes[pathTypeModel.Mode], THETA_PARAMETER);

                if (!available)
                {
                    continue;
                }

                double modeTimeCoefficient = (Global.Configuration.AV_IncludeAutoTypeChoice && household.OwnsAutomatedVehicles > 0 && mode >= Global.Settings.Modes.Sov && mode <= Global.Settings.Modes.Hov3) ?
                                             subtour.TimeCoefficient * (1.0 - Global.Configuration.AV_InVehicleTimeCoefficientDiscountFactor) :
                                             (mode == Global.Settings.Modes.PaidRideShare && Global.Configuration.AV_PaidRideShareModeUsesAVs) ?
                                             subtour.TimeCoefficient * (1.0 - Global.Configuration.AV_InVehicleTimeCoefficientDiscountFactor) : subtour.TimeCoefficient;
                alternative.AddUtilityTerm(2, generalizedTimeLogsum * modeTimeCoefficient);


                if (mode == Global.Settings.Modes.Transit)
                {
                    alternative.AddUtilityTerm(20, 1);
                    //                        alternative.AddUtility(129, destinationParcel.MixedUse2Index1());
                    //                        alternative.AddUtility(128, destinationParcel.TotalEmploymentDensity1());
                    //                        alternative.AddUtility(127, destinationParcel.NetIntersectionDensity1());
                    //                        alternative.AddUtility(126, originParcel.NetIntersectionDensity1());
                    //                        alternative.AddUtility(125, originParcel.TotalEmploymentDensity1());
                    //                        alternative.AddUtility(124, originParcel.MixedUse2Index1());
                    //                        alternative.AddUtility(123, Math.Log(destinationParcel.StopsTransitBuffer1+1));
                    //                        alternative.AddUtility(122, Math.Log(originParcel.StopsTransitBuffer1+1));
                }
                else if (mode == Global.Settings.Modes.Hov3)
                {
                    alternative.AddUtilityTerm(1, (destinationParkingCost * subtour.CostCoefficient / ChoiceModelUtility.CPFACT3));
                    alternative.AddUtilityTerm(30, 1);
                    alternative.AddUtilityTerm(88, sovTourFlag);
                    alternative.AddUtilityTerm(89, hov2TourFlag);
                }
                else if (mode == Global.Settings.Modes.Hov2)
                {
                    alternative.AddUtilityTerm(1, (destinationParkingCost * subtour.CostCoefficient / ChoiceModelUtility.CPFACT2));
                    alternative.AddUtilityTerm(40, 1);
                    alternative.AddUtilityTerm(88, sovTourFlag);
                    alternative.AddUtilityTerm(89, hov2TourFlag);
                }
                else if (mode == Global.Settings.Modes.Sov)
                {
                    alternative.AddUtilityTerm(1, (destinationParkingCost * subtour.CostCoefficient));
                    alternative.AddUtilityTerm(50, 1);
                    alternative.AddUtilityTerm(54, income0To25KFlag);
                    alternative.AddUtilityTerm(55, income25To50KFlag);
                    alternative.AddUtilityTerm(58, sovTourFlag);
                    alternative.AddUtilityTerm(59, hov2TourFlag);
                }
                else if (mode == Global.Settings.Modes.Bike)
                {
                    alternative.AddUtilityTerm(60, 1);
                    alternative.AddUtilityTerm(61, maleFlag);
                    alternative.AddUtilityTerm(69, bikeTourFlag);
                    alternative.AddUtilityTerm(169, destinationParcel.MixedUse4Index1());
                    alternative.AddUtilityTerm(168, destinationParcel.TotalEmploymentDensity1());
                    alternative.AddUtilityTerm(167, destinationParcel.NetIntersectionDensity1());
                    alternative.AddUtilityTerm(166, originParcel.NetIntersectionDensity1());
                    alternative.AddUtilityTerm(165, originParcel.TotalEmploymentDensity1());
                    alternative.AddUtilityTerm(164, originParcel.MixedUse4Index1());
                }
                else if (mode == Global.Settings.Modes.Walk)
                {
                    alternative.AddUtilityTerm(70, 1);
                    alternative.AddUtilityTerm(79, walkTourFlag);
                    alternative.AddUtilityTerm(179, destinationParcel.MixedUse4Index1());
                    alternative.AddUtilityTerm(178, destinationParcel.TotalEmploymentDensity1());
                    alternative.AddUtilityTerm(177, destinationParcel.NetIntersectionDensity1());
                    alternative.AddUtilityTerm(176, originParcel.NetIntersectionDensity1());
                    alternative.AddUtilityTerm(175, originParcel.TotalEmploymentDensity1());
                    alternative.AddUtilityTerm(174, originParcel.MixedUse4Index1());
                }
                else if (mode == Global.Settings.Modes.PaidRideShare)
                {
                    if (Global.Configuration.PaidRideshare_UseEstimatedInsteadOfAssertedCoefficients)
                    {
                        alternative.AddUtilityTerm(80, 1.0);
                        alternative.AddUtilityTerm(81, sovTourFlag);
                        alternative.AddUtilityTerm(82, walkTourFlag + bikeTourFlag);
                        alternative.AddUtilityTerm(83, subtour.Person.AgeIsBetween26And35.ToFlag());
                        alternative.AddUtilityTerm(83, subtour.Person.AgeIsBetween18And25.ToFlag());
                        alternative.AddUtilityTerm(84, tncTourFlag);
                        alternative.AddUtilityTerm(85, originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2);
                        alternative.AddUtilityTerm(86, income0To25KFlag);
                        alternative.AddUtilityTerm(87, incomeOver100Flag);
                    }
                    else
                    {
                        double modeConstant = Global.Configuration.AV_PaidRideShareModeUsesAVs
                        ? Global.Configuration.AV_PaidRideShare_ModeConstant
                                              + Global.Configuration.AV_PaidRideShare_DensityCoefficient * Math.Min(originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2,
                                                                                                                    (Global.Configuration.PaidRideShare_DensityMeasureCapValue > 0) ? Global.Configuration.PaidRideShare_DensityMeasureCapValue : 6000)
                                              + Global.Configuration.AV_PaidRideShare_AVOwnerCoefficient * (household.OwnsAutomatedVehicles > 0).ToFlag()
                        : Global.Configuration.PaidRideShare_ModeConstant
                                              + Global.Configuration.PaidRideShare_DensityCoefficient * Math.Min(originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2,
                                                                                                                 (Global.Configuration.PaidRideShare_DensityMeasureCapValue > 0) ? Global.Configuration.PaidRideShare_DensityMeasureCapValue : 6000);

                        alternative.AddUtilityTerm(90, modeConstant);
                        alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_Age26to35Coefficient * subtour.Person.AgeIsBetween26And35.ToFlag());
                        alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_Age18to25Coefficient * subtour.Person.AgeIsBetween18And25.ToFlag());
                        alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_AgeOver65Coefficient * (subtour.Person.Age >= 65).ToFlag());
                    }
                }
            }
        }
Exemplo n.º 7
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITourWrapper subtour, IEnumerable <IPathTypeModel> pathTypeModels, IParcelWrapper destinationParcel, int parentTourMode, int choice = Constants.DEFAULT_VALUE)
        {
            var household = subtour.Household;
            var person    = subtour.Person;
            var personDay = subtour.PersonDay;

            // household inputs
            var income0To25KFlag  = household.Has0To25KIncome.ToFlag();
            var income25To50KFlag = household.Has25To50KIncome.ToFlag();

            // person inputs
            var maleFlag = person.IsMale.ToFlag();

            // tour inputs
            var sovTourFlag  = (parentTourMode == Global.Settings.Modes.Sov).ToFlag();
            var hov2TourFlag = (parentTourMode == Global.Settings.Modes.Hov2).ToFlag();
            var bikeTourFlag = (parentTourMode == Global.Settings.Modes.Bike).ToFlag();
            var walkTourFlag = (parentTourMode == Global.Settings.Modes.Walk).ToFlag();

            // remaining inputs
            var originParcel           = subtour.OriginParcel;
            var parkingDuration        = ChoiceModelUtility.GetParkingDuration(person.IsFulltimeWorker);
            var destinationParkingCost = destinationParcel.ParkingCostBuffer1(parkingDuration);

            double escortPercentage;
            double nonEscortPercentage;

            ChoiceModelUtility.SetEscortPercentages(personDay, out escortPercentage, out nonEscortPercentage, true);

            // paidRideShare is a special case
            if (Global.Configuration.PaidRideShareModeIsAvailable)
            {
                var pathTypeExtra              = pathTypeModels.First(x => x.Mode == Global.Settings.Modes.PaidRideShare);
                var modeExtra                  = Global.Settings.Modes.PaidRideShare;
                var availableExtra             = pathTypeExtra.Available;
                var generalizedTimeLogsumExtra = pathTypeExtra.GeneralizedTimeLogsum;
                var distanceExtra              = pathTypeExtra.PathDistance;

                var alternative = choiceProbabilityCalculator.GetAlternative(modeExtra - 2, availableExtra, choice == modeExtra);
                alternative.Choice = modeExtra;

                alternative.AddNestedAlternative(_nestedAlternativeIds[modeExtra], _nestedAlternativeIndexes[modeExtra], THETA_PARAMETER);

                if (availableExtra)
                {
                    var extraCostPerMile = Global.Configuration.AV_PaidRideShareModeUsesAVs ?
                                           Global.Configuration.AV_PaidRideShare_ExtraCostPerDistanceUnit : Global.Configuration.PaidRideShare_ExtraCostPerDistanceUnit;
                    var fixedCostPerRide = Global.Configuration.AV_PaidRideShareModeUsesAVs ?
                                           Global.Configuration.AV_PaidRideShare_FixedCostPerRide : Global.Configuration.PaidRideShare_FixedCostPerRide;
                    var autoTimeCoefficient = Global.Configuration.AV_PaidRideShareModeUsesAVs ?
                                              subtour.TimeCoefficient * (1.0 - Global.Configuration.AV_InVehicleTimeCoefficientDiscountFactor) : subtour.TimeCoefficient;
                    alternative.AddUtilityTerm(2, generalizedTimeLogsumExtra * autoTimeCoefficient);
                    alternative.AddUtilityTerm(2, distanceExtra * extraCostPerMile * subtour.CostCoefficient);
                    alternative.AddUtilityTerm(2, fixedCostPerRide * subtour.CostCoefficient);

                    var modeConstant = Global.Configuration.AV_PaidRideShareModeUsesAVs
                      ? Global.Configuration.AV_PaidRideShare_ModeConstant
                                       + Global.Configuration.AV_PaidRideShare_DensityCoefficient * Math.Min(originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2, 6000)
                                       + Global.Configuration.AV_PaidRideShare_AVOwnerCoefficient * (household.OwnsAutomatedVehicles > 0).ToFlag()
                      : Global.Configuration.PaidRideShare_ModeConstant
                                       + Global.Configuration.PaidRideShare_DensityCoefficient * Math.Min(originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2, 6000);

                    alternative.AddUtilityTerm(90, modeConstant);
                    alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_Age26to35Coefficient * subtour.Person.AgeIsBetween26And35.ToFlag());
                    alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_Age18to25Coefficient * subtour.Person.AgeIsBetween18And25.ToFlag());
                    alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_AgeOver65Coefficient * (subtour.Person.Age >= 65).ToFlag());
                }
            }


            foreach (var pathTypeModel in pathTypeModels)
            {
                var mode                  = pathTypeModel.Mode;
                var available             = pathTypeModel.Mode != Global.Settings.Modes.ParkAndRide && pathTypeModel.Available;
                var generalizedTimeLogsum = pathTypeModel.GeneralizedTimeLogsum;

                var alternative = choiceProbabilityCalculator.GetAlternative(mode, available, choice == mode);
                alternative.Choice = mode;

                alternative.AddNestedAlternative(_nestedAlternativeIds[pathTypeModel.Mode], _nestedAlternativeIndexes[pathTypeModel.Mode], THETA_PARAMETER);

                if (!available)
                {
                    continue;
                }

                var modeTimeCoefficient = (Global.Configuration.AV_IncludeAutoTypeChoice && household.OwnsAutomatedVehicles > 0 && mode >= Global.Settings.Modes.Sov && mode <= Global.Settings.Modes.Hov3) ?
                                          subtour.TimeCoefficient * (1.0 - Global.Configuration.AV_InVehicleTimeCoefficientDiscountFactor) : subtour.TimeCoefficient;
                alternative.AddUtilityTerm(2, generalizedTimeLogsum * modeTimeCoefficient);


                if (mode == Global.Settings.Modes.Transit)
                {
                    alternative.AddUtilityTerm(20, 1);
                    //                        alternative.AddUtility(129, destinationParcel.MixedUse2Index1());
                    //                        alternative.AddUtility(128, destinationParcel.TotalEmploymentDensity1());
                    //                        alternative.AddUtility(127, destinationParcel.NetIntersectionDensity1());
                    //                        alternative.AddUtility(126, originParcel.NetIntersectionDensity1());
                    //                        alternative.AddUtility(125, originParcel.TotalEmploymentDensity1());
                    //                        alternative.AddUtility(124, originParcel.MixedUse2Index1());
                    //                        alternative.AddUtility(123, Math.Log(destinationParcel.StopsTransitBuffer1+1));
                    //                        alternative.AddUtility(122, Math.Log(originParcel.StopsTransitBuffer1+1));
                }
                else if (mode == Global.Settings.Modes.Hov3)
                {
                    alternative.AddUtilityTerm(1, (destinationParkingCost * subtour.CostCoefficient / ChoiceModelUtility.CPFACT3));
                    alternative.AddUtilityTerm(30, 1);
                    alternative.AddUtilityTerm(88, sovTourFlag);
                    alternative.AddUtilityTerm(89, hov2TourFlag);
                }
                else if (mode == Global.Settings.Modes.Hov2)
                {
                    alternative.AddUtilityTerm(1, (destinationParkingCost * subtour.CostCoefficient / ChoiceModelUtility.CPFACT2));
                    alternative.AddUtilityTerm(40, 1);
                    alternative.AddUtilityTerm(88, sovTourFlag);
                    alternative.AddUtilityTerm(89, hov2TourFlag);
                }
                else if (mode == Global.Settings.Modes.Sov)
                {
                    alternative.AddUtilityTerm(1, (destinationParkingCost * subtour.CostCoefficient));
                    alternative.AddUtilityTerm(50, 1);
                    alternative.AddUtilityTerm(54, income0To25KFlag);
                    alternative.AddUtilityTerm(55, income25To50KFlag);
                    alternative.AddUtilityTerm(58, sovTourFlag);
                    alternative.AddUtilityTerm(59, hov2TourFlag);
                }
                else if (mode == Global.Settings.Modes.Bike)
                {
                    alternative.AddUtilityTerm(60, 1);
                    alternative.AddUtilityTerm(61, maleFlag);
                    alternative.AddUtilityTerm(69, bikeTourFlag);
                    //                        alternative.AddUtility(169, destinationParcel.MixedUse4Index1());
                    //                        alternative.AddUtility(168, destinationParcel.TotalEmploymentDensity1());
                    //                        alternative.AddUtility(167, destinationParcel.NetIntersectionDensity1());
                    //                        alternative.AddUtility(166, originParcel.NetIntersectionDensity1());
                    //                        alternative.AddUtility(165, originParcel.TotalEmploymentDensity1());
                    //                        alternative.AddUtility(164, originParcel.MixedUse4Index1());
                }
                else if (mode == Global.Settings.Modes.Walk)
                {
                    alternative.AddUtilityTerm(70, 1);
                    alternative.AddUtilityTerm(79, walkTourFlag);
                    //                        alternative.AddUtility(179, destinationParcel.MixedUse4Index1());
                    //                        alternative.AddUtility(178, destinationParcel.TotalEmploymentDensity1());
                    //                        alternative.AddUtility(177, destinationParcel.NetIntersectionDensity1());
                    //                        alternative.AddUtility(176, originParcel.NetIntersectionDensity1());
                    //                        alternative.AddUtility(175, originParcel.TotalEmploymentDensity1());
                    //                        alternative.AddUtility(174, originParcel.MixedUse4Index1());
                }
            }
        }
Exemplo n.º 8
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITourWrapper tour, IEnumerable <PathTypeModel> pathTypeModels, IParcelWrapper destinationParcel, int choice = Constants.DEFAULT_VALUE)
        {
            var household       = tour.Household;
            var householdTotals = household.HouseholdTotals;
            var person          = tour.Person;
            var personDay       = tour.PersonDay;

            // household inputs
            var income0To25KFlag        = household.Has0To25KIncome.ToFlag();
            var childrenUnder5          = householdTotals.ChildrenUnder5;
            var childrenAge5Through15   = householdTotals.ChildrenAge5Through15;
            var nonworkingAdults        = householdTotals.NonworkingAdults;
            var retiredAdults           = householdTotals.RetiredAdults;
            var onePersonHouseholdFlag  = household.IsOnePersonHousehold.ToFlag();
            var twoPersonHouseholdFlag  = household.IsTwoPersonHousehold.ToFlag();
            var noCarsInHouseholdFlag   = household.GetFlagForNoCarsInHousehold(household.VehiclesAvailable);
            var carsLessThanDriversFlag = household.GetFlagForCarsLessThanDrivers(household.VehiclesAvailable);
            var carsLessThanWorkersFlag = household.GetFlagForCarsLessThanWorkers(household.VehiclesAvailable);

            // person inputs
            var maleFlag = person.IsMale.ToFlag();
            var ageBetween51And98Flag = person.AgeIsBetween51And98.ToFlag();

            // tour inputs
            var shoppingTourFlag           = (tour.DestinationPurpose == Global.Settings.Purposes.Shopping).ToFlag();
            var mealTourFlag               = (tour.DestinationPurpose == Global.Settings.Purposes.Meal).ToFlag();
            var socialOrRecreationTourFlag = (tour.DestinationPurpose == Global.Settings.Purposes.Social).ToFlag();

            // remaining inputs
            var originParcel           = tour.OriginParcel;
            var parkingDuration        = ChoiceModelUtility.GetParkingDuration(person.IsFulltimeWorker);
            var destinationParkingCost = destinationParcel.ParkingCostBuffer1(parkingDuration);

            double escortPercentage;
            double nonEscortPercentage;

            ChoiceModelUtility.SetEscortPercentages(personDay, out escortPercentage, out nonEscortPercentage, true);

            foreach (var pathTypeModel in pathTypeModels)
            {
                var mode                  = pathTypeModel.Mode;
                var available             = pathTypeModel.Mode != Global.Settings.Modes.ParkAndRide && pathTypeModel.Available;
                var generalizedTimeLogsum = pathTypeModel.GeneralizedTimeLogsum;

                var alternative = choiceProbabilityCalculator.GetAlternative(mode, available, choice == mode);
                alternative.Choice = mode;

                alternative.AddNestedAlternative(_nestedAlternativeIds[pathTypeModel.Mode], _nestedAlternativeIndexes[pathTypeModel.Mode], THETA_PARAMETER);

                if (!available)
                {
                    continue;
                }

                alternative.AddUtilityTerm(2, generalizedTimeLogsum * tour.TimeCoefficient);

                if (mode == Global.Settings.Modes.Transit)
                {
                    alternative.AddUtilityTerm(20, 1);
                    alternative.AddUtilityTerm(21, noCarsInHouseholdFlag);
                    alternative.AddUtilityTerm(120, shoppingTourFlag);
                    //						alternative.AddUtility(121, mealTourFlag);
                    //						alternative.AddUtility(129, destinationParcel.MixedUse2Index1());
                    alternative.AddUtilityTerm(128, destinationParcel.TotalEmploymentDensity1());
                    //						alternative.AddUtility(127, destinationParcel.NetIntersectionDensity1());
                    //						alternative.AddUtility(126, originParcel.NetIntersectionDensity1());
                    //						alternative.AddUtility(125, originParcel.HouseholdDensity1());
                    alternative.AddUtilityTerm(124, originParcel.MixedUse2Index1());
                    //						alternative.AddUtility(123, Math.Log(destinationParcel.StopsTransitBuffer1+1));
                    //						alternative.AddUtility(122, Math.Log(originParcel.StopsTransitBuffer1+1));
                }
                else if (mode == Global.Settings.Modes.Hov3)
                {
                    alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / ChoiceModelUtility.CPFACT3));
                    alternative.AddUtilityTerm(30, 1);
                    alternative.AddUtilityTerm(31, childrenUnder5);
                    alternative.AddUtilityTerm(32, childrenAge5Through15);
                    alternative.AddUtilityTerm(34, nonworkingAdults + retiredAdults);
                    alternative.AddUtilityTerm(35, pathTypeModel.PathDistance.AlmostEquals(0) ? 0 : Math.Log(pathTypeModel.PathDistance));
                    alternative.AddUtilityTerm(38, onePersonHouseholdFlag);
                    alternative.AddUtilityTerm(39, twoPersonHouseholdFlag);
                    alternative.AddUtilityTerm(41, noCarsInHouseholdFlag);
                    alternative.AddUtilityTerm(43, carsLessThanWorkersFlag);
                    alternative.AddUtilityTerm(133, escortPercentage);
                    alternative.AddUtilityTerm(134, nonEscortPercentage);
                    alternative.AddUtilityTerm(136, shoppingTourFlag);
                    alternative.AddUtilityTerm(137, mealTourFlag);
                    alternative.AddUtilityTerm(138, socialOrRecreationTourFlag);
                }
                else if (mode == Global.Settings.Modes.Hov2)
                {
                    alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / ChoiceModelUtility.CPFACT2));
                    alternative.AddUtilityTerm(31, childrenUnder5);
                    alternative.AddUtilityTerm(32, childrenAge5Through15);
                    alternative.AddUtilityTerm(34, nonworkingAdults + retiredAdults);
                    alternative.AddUtilityTerm(35, pathTypeModel.PathDistance.AlmostEquals(0) ? 0 : Math.Log(pathTypeModel.PathDistance));
                    alternative.AddUtilityTerm(40, 1);
                    alternative.AddUtilityTerm(41, noCarsInHouseholdFlag);
                    alternative.AddUtilityTerm(43, carsLessThanWorkersFlag);
                    alternative.AddUtilityTerm(48, onePersonHouseholdFlag);
                    alternative.AddUtilityTerm(133, escortPercentage);
                    alternative.AddUtilityTerm(134, nonEscortPercentage);
                    alternative.AddUtilityTerm(136, shoppingTourFlag);
                    alternative.AddUtilityTerm(137, mealTourFlag);
                    alternative.AddUtilityTerm(138, socialOrRecreationTourFlag);
                }
                else if (mode == Global.Settings.Modes.Sov)
                {
                    alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient));
                    alternative.AddUtilityTerm(50, 1);
                    alternative.AddUtilityTerm(52, carsLessThanDriversFlag);
                    alternative.AddUtilityTerm(54, income0To25KFlag);
                    alternative.AddUtilityTerm(131, escortPercentage);
                    alternative.AddUtilityTerm(132, nonEscortPercentage);
                }
                else if (mode == Global.Settings.Modes.Bike)
                {
                    var class1Dist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ?
                                     ImpedanceRoster.GetValue("class1distance", mode, Global.Settings.PathTypes.FullNetwork,
                                                              Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0;
                    var class2Dist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ?
                                     ImpedanceRoster.GetValue("class2distance", mode, Global.Settings.PathTypes.FullNetwork,
                                                              Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0;
                    var worstDist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ?
                                    ImpedanceRoster.GetValue("worstdistance", mode, Global.Settings.PathTypes.FullNetwork,
                                                             Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable : 0;

                    alternative.AddUtilityTerm(60, 1);
                    alternative.AddUtilityTerm(61, maleFlag);
                    alternative.AddUtilityTerm(63, ageBetween51And98Flag);
                    alternative.AddUtilityTerm(160, socialOrRecreationTourFlag);
                    alternative.AddUtilityTerm(169, destinationParcel.MixedUse4Index1());
                    alternative.AddUtilityTerm(168, destinationParcel.TotalEmploymentDensity1());
                    //						alternative.AddUtility(167, destinationParcel.NetIntersectionDensity1());
                    //						alternative.AddUtility(166, originParcel.NetIntersectionDensity1());
                    alternative.AddUtilityTerm(165, originParcel.HouseholdDensity1());
                    alternative.AddUtilityTerm(164, originParcel.MixedUse4Index1());
                    alternative.AddUtilityTerm(161, (class1Dist > 0).ToFlag());
                    alternative.AddUtilityTerm(162, (class2Dist > 0).ToFlag());
                    alternative.AddUtilityTerm(163, (worstDist > 0).ToFlag());
                }
                else if (mode == Global.Settings.Modes.Walk)
                {
                    alternative.AddUtilityTerm(73, ageBetween51And98Flag);
                    alternative.AddUtilityTerm(171, mealTourFlag);
                    alternative.AddUtilityTerm(172, socialOrRecreationTourFlag);
                    //						alternative.AddUtility(179, destinationParcel.MixedUse4Index1());
                    alternative.AddUtilityTerm(178, destinationParcel.HouseholdDensity1());
                    //						alternative.AddUtility(177, destinationParcel.NetIntersectionDensity1());
                    //						alternative.AddUtility(176, originParcel.NetIntersectionDensity1());
                    alternative.AddUtilityTerm(175, originParcel.HouseholdDensity1());
                    //						alternative.AddUtility(174, originParcel.MixedUse4Index1());
                }
            }
        }
Exemplo n.º 9
0
        public ChoiceProbabilityCalculator.Alternative RunNested(IPersonWrapper person, IParcelWrapper originParcel, IParcelWrapper destinationParcel, int destinationArrivalTime, int destinationDepartureTime, int householdCars)
        {
            if (person == null)
            {
                throw new ArgumentNullException("person");
            }

            var tour = _creator.CreateWrapper(person, null, originParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, Global.Settings.Purposes.School);

            return(RunNested(tour, destinationParcel, householdCars, 0.0));
        }
Exemplo n.º 10
0
 protected virtual void RegionSpecificCustomizations(ChoiceProbabilityCalculator.Alternative alternative, IPersonWrapper _person, IParcelWrapper destinationParcel)
 {
     //PSRC customization dll for example
     //Global.PrintFile.WriteLine("Generic Default WorkLocationModel.RegionSpecificCustomizations being called so must not be overridden by CustomizationDll");
 }
Exemplo n.º 11
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.º 12
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, IPersonWrapper 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(this, person, sampleSize, destinationArrivalTime, destinationDepartureTime);

            destinationSampler.SampleTourDestinations(workLocationUtilites);

            //var alternative = choiceProbabilityCalculator.GetAlternative(countSampled, true);

            // JLB 20120329 added third call parameter to idenitfy whether this alt is chosen or not
            if (Global.Configuration.IsInEstimationMode && !ESTIMATE_NESTED_MODEL)
            {
                return;
            }
            ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(sampleSize, true, choseHome);

            alternative.Choice = person.Household.ResidenceParcel;

            alternative.AddUtilityTerm(41, 1);
            alternative.AddUtilityTerm(42, person.IsPartTimeWorker.ToFlag());
            alternative.AddUtilityTerm(43, person.IsStudentAge.ToFlag());
            alternative.AddUtilityTerm(44, person.IsFemale.ToFlag());
            alternative.AddUtilityTerm(89, 1);   //new dummy size variable for oddball alt
            alternative.AddUtilityTerm(90, 100); //old dummy size variable for oddball alt

            // OD shadow pricing - add for work at home
            if (Global.Configuration.ShouldUseODShadowPricing && Global.Configuration.UseODShadowPricingForWorkAtHomeAlternative)
            {
                int res = person.Household.ResidenceParcel.District;
                int des = person.Household.ResidenceParcel.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 && Global.Configuration.UseWorkShadowPricingForWorkAtHomeAlternative)
            {
                alternative.AddUtilityTerm(1, person.Household.ResidenceParcel.ShadowPriceForEmployment);
            }

            //make oddball alt unavailable and remove nesting for estimation of conditional MNL
            alternative.AddNestedAlternative(sampleSize + 3, 1, THETA_PARAMETER);
        }
Exemplo n.º 13
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, IPersonWrapper person, int sampleSize, IParcelWrapper choice = null, bool choseHome = false)
        {
            var segment                  = Global.Kernel.Get <SamplingWeightsSettingsFactory>().SamplingWeightsSettings.GetTourDestinationSegment(Global.Settings.Purposes.School, Global.Settings.TourPriorities.UsualLocation, Global.Settings.Modes.Sov, person.PersonType);
            var destinationSampler       = new DestinationSampler(choiceProbabilityCalculator, segment, sampleSize, person.Household.ResidenceParcel, choice);
            var destinationArrivalTime   = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.SchoolTourModeModel);
            var destinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.SchoolTourModeModel);
            var schoolLocationUtilities  = new SchoolLocationUtilities(person, sampleSize, destinationArrivalTime, destinationDepartureTime);

            destinationSampler.SampleTourDestinations(schoolLocationUtilities);

//			var alternative = choiceProbabilityCalculator.GetAlternative(countSampled, true);

            // JLB 20120403 added third call parameter to idenitfy whether this alt is chosen or not
            var alternative = choiceProbabilityCalculator.GetAlternative(sampleSize, true, choseHome);

            alternative.Choice = person.Household.ResidenceParcel;

            alternative.AddUtilityTerm(50, 1);
            alternative.AddUtilityTerm(51, (!person.IsStudentAge).ToFlag());
            alternative.AddUtilityTerm(52, person.Household.Size);
            alternative.AddUtilityTerm(97, 1);             //new dummy size variable for oddball alt
            alternative.AddUtilityTerm(98, 100);           //old dummy size variable for oddball alt

            //make oddball alt unavailable and remove nesting for estimation of conditional MNL
//			alternative.Available = false;
            alternative.AddNestedAlternative(sampleSize + 3, 1, 99);
        }
Exemplo n.º 14
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, HouseholdDayWrapper householdDay, TourWrapper tour,
                              IParcelWrapper destinationParcel, int householdCars,
                              int constrainedMode, int constrainedArrivalTime, int constrainedDepartureTime, HTourModeTime choice = null)
        {
            //private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, HouseholdDayWrapper householdDay, TourWrapper tour,
            //			int constrainedMode, int constrainedArrivalTime, int constrainedDepartureTime, HTourModeTime choice = null) {

            IHouseholdWrapper household       = tour.Household;
            IPersonWrapper    person          = tour.Person;
            IPersonDayWrapper personDay       = tour.PersonDay;
            IHouseholdTotals  householdTotals = household.HouseholdTotals;

            // household inputs
            int childrenUnder5        = householdTotals.ChildrenUnder5;
            int childrenAge5Through15 = householdTotals.ChildrenAge5Through15;
            int nonworkingAdults      = householdTotals.NonworkingAdults;
            int retiredAdults         = householdTotals.RetiredAdults;

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

            //var householdCars = household.VehiclesAvailable;
            int noCarsInHouseholdFlag   = household.GetFlagForNoCarsInHousehold(householdCars);
            int carsLessThanDriversFlag = household.GetFlagForCarsLessThanDrivers(householdCars);
            int carsLessThanWorkersFlag = household.GetFlagForCarsLessThanWorkers(householdCars);

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

            int primaryFamilyTimeFlag = (householdDay == null) ? 0 : householdDay.PrimaryPriorityTimeFlag;

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

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

            int PTpass = person.TransitPassOwnership;

            // person-day inputs
            int homeBasedToursOnlyFlag          = 1;
            int firstSimulatedHomeBasedTourFlag = 1;
            int laterSimulatedHomeBasedTourFlag = 0;
            int totalStops              = 0;
            int totalSimulatedStops     = 0;
            int escortStops             = 0;
            int homeBasedTours          = 1;
            int simulatedHomeBasedTours = 0;

            if (!(personDay == null))
            {
                homeBasedToursOnlyFlag          = personDay.OnlyHomeBasedToursExist().ToFlag();
                firstSimulatedHomeBasedTourFlag = personDay.IsFirstSimulatedHomeBasedTour().ToFlag();
                laterSimulatedHomeBasedTourFlag = personDay.IsLaterSimulatedHomeBasedTour().ToFlag();
                totalStops              = personDay.GetTotalStops();
                totalSimulatedStops     = personDay.GetTotalSimulatedStops();
                escortStops             = personDay.EscortStops;
                homeBasedTours          = personDay.HomeBasedTours;
                simulatedHomeBasedTours = personDay.SimulatedHomeBasedTours;
            }

            // tour inputs
            int escortTourFlag           = tour.IsEscortPurpose().ToFlag();
            int shoppingTourFlag         = tour.IsShoppingPurpose().ToFlag();
            int socialTourFlag           = tour.IsSocialPurpose().ToFlag();
            int personalBusinessTourFlag = tour.IsPersonalBusinessPurpose().ToFlag();
            int workTourFlag             = tour.IsWorkPurpose().ToFlag();
            int educationTourFlag        = tour.IsSchoolPurpose().ToFlag();
            int businessTourFlag         = tour.IsBusinessPurpose().ToFlag();

            IParcelWrapper originParcel = tour.OriginParcel;
            //var destinationParcel = tour.DestinationParcel;
            int  jointTourFlag        = (tour.JointTourSequence > 0) ? 1 : 0;
            int  partialHalfTour1Flag = (tour.PartialHalfTour1Sequence > 0) ? 1 : 0;
            int  partialHalfTour2Flag = (tour.PartialHalfTour2Sequence > 0) ? 1 : 0;
            bool partialHalfTour      = (tour.PartialHalfTour1Sequence > 0 || tour.PartialHalfTour2Sequence > 0);
            int  fullHalfTour1Flag    = (tour.FullHalfTour1Sequence > 0) ? 1 : 0;
            int  fullHalfTour2Flag    = (tour.FullHalfTour2Sequence > 0) ? 1 : 0;


            // remaining inputs

            //Initialize a few variables in case personDay is null
            // Higher priority tour of 2+ tours for the same purpose
            int highPrioritySameFlag = 0;
            // Lower priority tour(s) of 2+ tours for the same purpose
            int lowPrioritySameFlag = 0;
            // Higher priority tour of 2+ tours for different purposes
            int highPriorityDifferentFlag = 0;
            // Lower priority tour of 2+ tours for different purposes
            int lowPriorityDifferentFlag = 0;

            if (!(personDay == null))
            {
                // Higher priority tour of 2+ tours for the same purpose
                highPrioritySameFlag = (tour.GetTotalToursByPurpose() > tour.GetTotalSimulatedToursByPurpose() && tour.GetTotalSimulatedToursByPurpose() == 1).ToFlag();
                // Lower priority tour(s) of 2+ tours for the same purpose
                lowPrioritySameFlag = (tour.GetTotalSimulatedToursByPurpose() > 1).ToFlag();
                // Higher priority tour of 2+ tours for different purposes
                highPriorityDifferentFlag = (personDay.IsFirstSimulatedHomeBasedTour() && personDay.HomeBasedToursExist()).ToFlag() * (1 - highPrioritySameFlag);
                // Lower priority tour of 2+ tours for different purposes
                lowPriorityDifferentFlag = (personDay.IsLaterSimulatedHomeBasedTour() && personDay.HomeBasedToursExist()).ToFlag() * (1 - lowPrioritySameFlag);
            }

            ITimeWindow timeWindow = (householdDay == null) ? new TimeWindow() : tour.GetRelevantTimeWindow(householdDay);
            int         totalMinutesAvailableInDay = timeWindow.TotalAvailableMinutes(1, 1440);

            if (totalMinutesAvailableInDay < 0)
            {
                if (!Global.Configuration.IsInEstimationMode)
                {
                    householdDay.IsValid = false;
                }
                totalMinutesAvailableInDay = 0;
            }

            int bigPeriodCount = DayPeriod.H_BIG_DAY_PERIOD_TOTAL_TOUR_TIMES;
            int nPeriodCombs   = bigPeriodCount * (bigPeriodCount + 1) / 2;

            bool useTimeComponents = Global.Configuration.IsInEstimationMode || constrainedArrivalTime == 0 || constrainedDepartureTime == 0;
            int  componentIndex    = 0;
            int  periodComb        = -1;

            //set components
            if (useTimeComponents)
            {
                for (int arrivalPeriodIndex = 0; arrivalPeriodIndex < bigPeriodCount; arrivalPeriodIndex++)
                {
                    MinuteSpan arrivalPeriod = DayPeriod.HBigDayPeriods[arrivalPeriodIndex];
                    int        arrivalPeriodAvailableMinutes = timeWindow.TotalAvailableMinutes(arrivalPeriod.Start, arrivalPeriod.End);

                    for (int departurePeriodIndex = arrivalPeriodIndex; departurePeriodIndex < bigPeriodCount; departurePeriodIndex++)
                    {
                        MinuteSpan departurePeriod = DayPeriod.HBigDayPeriods[departurePeriodIndex];
                        int        departurePeriodAvailableMinutes = timeWindow.TotalAvailableMinutes(departurePeriod.Start, departurePeriod.End);

                        if (arrivalPeriod == departurePeriod)
                        {
                            componentIndex = arrivalPeriodIndex;
                            choiceProbabilityCalculator.CreateUtilityComponent(componentIndex);
                            ChoiceProbabilityCalculator.Component arrivalComponent = choiceProbabilityCalculator.GetUtilityComponent(componentIndex);

                            if (arrivalPeriodAvailableMinutes > 0)
                            {
                                double hoursArrival = arrivalPeriod.Middle / 60.0;
                                int    firstCoef    = 300;
                                arrivalComponent.AddUtilityTerm(300, Math.Log(arrivalPeriodAvailableMinutes));
                                //arrival shift variables
                                arrivalComponent.AddUtilityTerm(firstCoef + 2, partTimeWorkerFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 3, nonworkingAdultFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 4, universityStudentFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 5, retiredAdultFlag * hoursArrival);

                                arrivalComponent.AddUtilityTerm(firstCoef + 6, childAge5Through15Flag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 7, childUnder5Flag * hoursArrival);

                                arrivalComponent.AddUtilityTerm(firstCoef + 8, educationTourFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 9, escortTourFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 10, shoppingTourFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 11, businessTourFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 12, personalBusinessTourFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 13, socialTourFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 14, workTourFlag * hoursArrival);

                                arrivalComponent.AddUtilityTerm(firstCoef + 15, primaryFamilyTimeFlag * hoursArrival);

                                arrivalComponent.AddUtilityTerm(firstCoef + 16, HHwithLowIncomeFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 17, HHwithMidleIncomeFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 18, HHwithHighIncomeFlag * hoursArrival);

                                arrivalComponent.AddUtilityTerm(firstCoef + 19, highPrioritySameFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 20, lowPrioritySameFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 21, highPriorityDifferentFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 22, lowPriorityDifferentFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 23, jointTourFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 24, partialHalfTour1Flag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 25, fullHalfTour1Flag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 26, partialHalfTour2Flag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 27, fullHalfTour2Flag * hoursArrival);
                            }

                            componentIndex = bigPeriodCount + departurePeriodIndex;
                            choiceProbabilityCalculator.CreateUtilityComponent(componentIndex);
                            ChoiceProbabilityCalculator.Component departureComponent = choiceProbabilityCalculator.GetUtilityComponent(componentIndex);


                            if (departurePeriodAvailableMinutes > 0)
                            {
                                departureComponent.AddUtilityTerm(300, Math.Log(departurePeriodAvailableMinutes));
                            }
                        }
                        // set period combination component
                        periodComb++;
                        componentIndex = 2 * bigPeriodCount + periodComb;
                        choiceProbabilityCalculator.CreateUtilityComponent(componentIndex);
                        ChoiceProbabilityCalculator.Component combinationComponent = choiceProbabilityCalculator.GetUtilityComponent(componentIndex);

                        if (arrivalPeriodAvailableMinutes > 0 && departurePeriodAvailableMinutes > 0)
                        {
                            double hoursDuration = (departurePeriod.Middle - arrivalPeriod.Middle) / 60.0;

                            int firstCoef = 700;
                            //combination constants
                            combinationComponent.AddUtilityTerm(firstCoef + periodComb, 1.0);
                            // duration shift variables
                            combinationComponent.AddUtilityTerm(firstCoef + 30, primaryFamilyTimeFlag * hoursDuration);

                            combinationComponent.AddUtilityTerm(firstCoef + 31, escortTourFlag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 32, shoppingTourFlag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 33, educationTourFlag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 34, socialTourFlag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 35, personalBusinessTourFlag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 36, businessTourFlag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 37, workTourFlag * hoursDuration);

                            combinationComponent.AddUtilityTerm(firstCoef + 38, highPrioritySameFlag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 39, lowPrioritySameFlag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 40, highPriorityDifferentFlag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 41, lowPriorityDifferentFlag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 42, partTimeWorkerFlag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 43, jointTourFlag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 44, partialHalfTour1Flag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 45, fullHalfTour1Flag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 46, partialHalfTour2Flag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 47, fullHalfTour2Flag * hoursDuration);

                            // peak-to-peak variables
                            if (arrivalPeriod.Index == DayPeriod.AM_PEAK && departurePeriod.Index == DayPeriod.PM_PEAK)
                            {
                                combinationComponent.AddUtilityTerm(firstCoef + 48, fullTimeWorkerFlag);
                                combinationComponent.AddUtilityTerm(firstCoef + 49, partTimeWorkerFlag);
                                combinationComponent.AddUtilityTerm(firstCoef + 50, maleFlag);
                            }
                        }
                    }
                }
            }
            //for (var mode = Global.Settings.Modes.Walk; mode <= Global.Settings.Modes.WalkRideBike; mode++) {  replaced 20171120 JLB
            for (int mode = Global.Settings.Modes.Walk; mode <= Global.Settings.Modes.PaidRideShare; mode++)
            {
                componentIndex = 2 * bigPeriodCount + nPeriodCombs + mode - 1;
                choiceProbabilityCalculator.CreateUtilityComponent(componentIndex);
                ChoiceProbabilityCalculator.Component modeComponent = choiceProbabilityCalculator.GetUtilityComponent(componentIndex);

                //if (mode == Global.Settings.Modes.SchoolBus) {
                //	modeComponent.AddUtilityTerm(10, 1);
                //}
                if (mode == Global.Settings.Modes.Transit)
                {
                    modeComponent.AddUtilityTerm(20, 1);
                    modeComponent.AddUtilityTerm(21, femaleFlag);
                    //modeComponent.AddUtilityTerm(22, retiredAdultFlag);

                    modeComponent.AddUtilityTerm(22, PTpass);

                    //GV: one person HH; 8. juni 2016
                    //modeComponent.AddUtilityTerm(23, onePersonHouseholdFlag);

                    //GV: income effect is not with a correct sign
                    //modeComponent.AddUtilityTerm(23, HHwithLowIncomeFlag);
                    //modeComponent.AddUtilityTerm(24, HHwithMidleIncomeFlag);
                    //modeComponent.AddUtilityTerm(25, HHwithHighIncomeFlag);

                    //GV: not significant
                    //modeComponent.AddUtilityTerm(26, childrenUnder5);
                    //modeComponent.AddUtilityTerm(27, childrenAge5Through15);

                    modeComponent.AddUtilityTerm(28, nonworkingAdults + retiredAdults);

                    //modeComponent.AddUtilityTerm(26, noCarsInHouseholdFlag);
                    modeComponent.AddUtilityTerm(29, carsLessThanDriversFlag);
                }
                else if (mode == Global.Settings.Modes.Hov3)
                {
                    modeComponent.AddUtilityTerm(30, 1);
                    modeComponent.AddUtilityTerm(31, childrenUnder5);
                    modeComponent.AddUtilityTerm(32, childrenAge5Through15);
                    modeComponent.AddUtilityTerm(33, nonworkingAdults + retiredAdults);
                    modeComponent.AddUtilityTerm(34, femaleFlag);

                    //modeComponent.AddUtilityTerm(38, onePersonHouseholdFlag);
                    modeComponent.AddUtilityTerm(36, twoPersonHouseholdFlag);

                    //GV: commented out 7. june 2016
                    //modeComponent.AddUtilityTerm(37, noCarsInHouseholdFlag);
                    modeComponent.AddUtilityTerm(38, carsLessThanDriversFlag);
                }
                else if (mode == Global.Settings.Modes.Hov2)
                {
                    modeComponent.AddUtilityTerm(40, 1);
                    modeComponent.AddUtilityTerm(41, maleFlag);
                    //modeComponent.AddUtilityTerm(41, onePersonHouseholdFlag);

                    //GV: Testing coeff. 42-44 again, 26. may 2016, coeff. numbering changed
                    modeComponent.AddUtilityTerm(42, childrenUnder5);
                    modeComponent.AddUtilityTerm(43, childrenAge5Through15);
                    modeComponent.AddUtilityTerm(44, nonworkingAdults + retiredAdults);

                    //GV: these are significant and plus; 8. juni 2016
                    //modeComponent.AddUtilityTerm(45, HHwithLowIncomeFlag);
                    //modeComponent.AddUtilityTerm(46, HHwithMidleIncomeFlag);
                    //modeComponent.AddUtilityTerm(47, HHwithHighIncomeFlag);

                    //GV coeff. numbering changed; 8. june 2016 - not significant
                    //modeComponent.AddUtilityTerm(48, noCarsInHouseholdFlag);
                    //modeComponent.AddUtilityTerm(49, carsLessThanDriversFlag);
                }
                else if (mode == Global.Settings.Modes.Sov)
                {
                    modeComponent.AddUtilityTerm(50, 1);
                    //not significant: modeComponent.AddUtilityTerm(51, maleFlag);
                    modeComponent.AddUtilityTerm(52, fullTimeWorkerFlag);
                    modeComponent.AddUtilityTerm(53, partTimeWorkerFlag);
                    modeComponent.AddUtilityTerm(54, onePersonHouseholdFlag);

                    //GV: these are NOT significant
                    //modeComponent.AddUtilityTerm(55, HHwithLowIncomeFlag);
                    //modeComponent.AddUtilityTerm(56, HHwithMidleIncomeFlag);
                    //modeComponent.AddUtilityTerm(57, HHwithHighIncomeFlag);

                    //GV: coeff. numbering changed, 26. may 2016
                    modeComponent.AddUtilityTerm(58, carsLessThanWorkersFlag);
                }
                else if (mode == Global.Settings.Modes.Bike)
                {
                    modeComponent.AddUtilityTerm(60, 1);
                    modeComponent.AddUtilityTerm(61, femaleFlag);
                    //modeComponent.AddUtilityTerm(62, childrenUnder5);
                    //GV: changed small kids to retired; 3. june 2016
                    modeComponent.AddUtilityTerm(62, retiredAdults);
                    modeComponent.AddUtilityTerm(63, childAge5Through15Flag);

                    //GV: 3. june 2016 - added "no cars in HH" for full/part_time workers
                    modeComponent.AddUtilityTerm(64, fullTimeWorkerFlag + noCarsInHouseholdFlag);
                    modeComponent.AddUtilityTerm(65, partTimeWorkerFlag + noCarsInHouseholdFlag);

                    //modeComponent.AddUtilityTerm(66, noCarsInHouseholdFlag);
                    modeComponent.AddUtilityTerm(67, carsLessThanDriversFlag);

                    //GV: university students; 3. june 2016 - not significant
                    //modeComponent.AddUtilityTerm(68, universityStudentFlag);

                    //GV: one person HH; 8. juni 2016
                    modeComponent.AddUtilityTerm(69, onePersonHouseholdFlag);
                }
                else if (mode == Global.Settings.Modes.Walk)
                {
                    modeComponent.AddUtilityTerm(70, 1.0);
                    //GV: Testing female variable again; 26. may 2016 - not sign.
                    //modeComponent.AddUtilityTerm(71, femaleFlag);
                    modeComponent.AddUtilityTerm(72, nonworkingAdults);
                    //not sign.: modeComponent.AddUtilityTerm(73, retiredAdults);

                    //GV: one person HH
                    modeComponent.AddUtilityTerm(74, onePersonHouseholdFlag);

                    //GV: not significant
                    //modeComponent.AddUtilityTerm(76, noCarsInHouseholdFlag);
                    //modeComponent.AddUtilityTerm(77, carsLessThanDriversFlag);
                }
                else if (mode == Global.Settings.Modes.ParkAndRide)
                {
                    modeComponent.AddUtilityTerm(80, 1.0);
                }
                else if (mode == Global.Settings.Modes.CarKissRideWalk)
                {
                    modeComponent.AddUtilityTerm(90, 1.0);
                }
                else if (mode == Global.Settings.Modes.BikeParkRideWalk)
                {
                    modeComponent.AddUtilityTerm(100, 1.0);
                }
                else if (mode == Global.Settings.Modes.BikeParkRideBike)
                {
                    modeComponent.AddUtilityTerm(110, 1.0);
                }
                else if (mode == Global.Settings.Modes.BikeOnTransit)
                {
                    modeComponent.AddUtilityTerm(120, 1.0);
                }
                else if (mode == Global.Settings.Modes.CarParkRideBike)
                {
                    modeComponent.AddUtilityTerm(130, 1.0);
                }
                else if (mode == Global.Settings.Modes.WalkRideBike)
                {
                    modeComponent.AddUtilityTerm(140, 1.0);
                }
                else if (mode == Global.Settings.Modes.PaidRideShare)
                {
                    //modeComponent.AddUtilityTerm(150, 1.0);

                    double modeConstant = Global.Configuration.AV_PaidRideShareModeUsesAVs
                     ? Global.Configuration.AV_PaidRideShare_ModeConstant
                                          + Global.Configuration.AV_PaidRideShare_DensityCoefficient * Math.Min(originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2, 6000)
                                          + Global.Configuration.AV_PaidRideShare_AVOwnerCoefficient * (household.OwnsAutomatedVehicles > 0).ToFlag()
                     : Global.Configuration.PaidRideShare_ModeConstant
                                          + Global.Configuration.PaidRideShare_DensityCoefficient * Math.Min(originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2, 6000);

                    modeComponent.AddUtilityTerm(150, modeConstant);
                    modeComponent.AddUtilityTerm(150, Global.Configuration.PaidRideShare_Age26to35Coefficient * tour.Person.AgeIsBetween26And35.ToFlag());
                    modeComponent.AddUtilityTerm(150, Global.Configuration.PaidRideShare_Age18to25Coefficient * tour.Person.AgeIsBetween18And25.ToFlag());
                    modeComponent.AddUtilityTerm(150, Global.Configuration.PaidRideShare_AgeOver65Coefficient * (tour.Person.Age >= 65).ToFlag());
                }


                //GV: Estimation of importance of "purpose" per mode - SOV is zero-alt and Work is zero-alt
                if (mode == Global.Settings.Modes.Walk || mode == Global.Settings.Modes.Bike || mode == Global.Settings.Modes.Hov2 ||
                    mode == Global.Settings.Modes.Hov3 || mode == Global.Settings.Modes.Transit)
                {
                    int firstCoef = 200 + 10 * mode;

                    modeComponent.AddUtilityTerm(firstCoef + 0, escortTourFlag);
                    modeComponent.AddUtilityTerm(firstCoef + 1, shoppingTourFlag);
                    modeComponent.AddUtilityTerm(firstCoef + 2, educationTourFlag);
                    modeComponent.AddUtilityTerm(firstCoef + 3, socialTourFlag);
                    modeComponent.AddUtilityTerm(firstCoef + 4, personalBusinessTourFlag);
                    modeComponent.AddUtilityTerm(firstCoef + 5, businessTourFlag);
                    //modeComponent.AddUtilityTerm(firstCoef + 6, workTourFlag); //GV: "work" is zero alternative

                    modeComponent.AddUtilityTerm(firstCoef + 7, jointTourFlag);
                    modeComponent.AddUtilityTerm(firstCoef + 8, Math.Min(partialHalfTour1Flag + partialHalfTour2Flag, 1.0));
                    modeComponent.AddUtilityTerm(firstCoef + 9, Math.Min(fullHalfTour1Flag + fullHalfTour2Flag, 1.0));
                }
            }



            //loop on all alternatives, using modeTimes objects
            {
                foreach (HTourModeTime modeTimes in HTourModeTime.ModeTimes[ParallelUtility.threadLocalAssignedIndex.Value])
                {
                    MinuteSpan arrivalPeriod = modeTimes.ArrivalPeriod;
                    int        arrivalPeriodAvailableMinutes = timeWindow.TotalAvailableMinutes(arrivalPeriod.Start, arrivalPeriod.End);

                    MinuteSpan departurePeriod = modeTimes.DeparturePeriod;
                    int        departurePeriodAvailableMinutes = timeWindow.TotalAvailableMinutes(departurePeriod.Start, departurePeriod.End);
                    periodComb = modeTimes.PeriodCombinationIndex;

                    int mode = modeTimes.Mode;

                    int altIndex = modeTimes.Index;



                    //limit availability based on mode and tour purpose
                    bool available = (mode == Global.Settings.Modes.BikeParkRideBike || mode == Global.Settings.Modes.CarParkRideBike || mode == Global.Settings.Modes.WalkRideBike) &&
                                     (!(tour.IsWorkPurpose() || tour.IsSchoolPurpose())) ? false : true;

                    //further limit availability on mode
                    if (mode == Global.Settings.Modes.PaidRideShare && !Global.Configuration.PaidRideShareModeIsAvailable)
                    {
                        available = false;
                    }

                    //further limit availability if tour includes joint travel
                    if ((tour.JointTourSequence > 0 ||
                         tour.FullHalfTour1Sequence > 0 || tour.FullHalfTour2Sequence > 0 ||
                         tour.PartialHalfTour1Sequence > 0 || tour.PartialHalfTour2Sequence > 0) &&
                        (mode > Global.Settings.Modes.Transit))
                    {
                        available = false;
                    }

                    //further limit availability:  kissAndRide and carParkRideBike are not supported
                    available = (available == true) && (mode != Global.Settings.Modes.CarKissRideWalk) && (mode != Global.Settings.Modes.CarParkRideBike);

                    //further limit availabillity based on time window variables and any constrained choices
                    available = (available == true) &&
                                (modeTimes.LongestFeasibleWindow != null) && (mode > 0)
                                //&& (mode <= Global.Settings.Modes.Transit)
                                && (person.Age >= 18 || (modeTimes.Mode != Global.Settings.Modes.Sov && modeTimes.Mode != Global.Settings.Modes.HovDriver)) &&
                                (constrainedMode > 0 || mode == Global.Settings.Modes.Walk || mode == Global.Settings.Modes.Bike || mode == Global.Settings.Modes.HovDriver || mode == Global.Settings.Modes.Transit || !partialHalfTour) &&
                                (constrainedMode <= 0 || constrainedMode == mode) &&
                                (constrainedArrivalTime <= 0 || (constrainedArrivalTime >= arrivalPeriod.Start && constrainedArrivalTime <= arrivalPeriod.End)) &&
                                (constrainedDepartureTime <= 0 || (constrainedDepartureTime >= departurePeriod.Start && constrainedDepartureTime <= departurePeriod.End));

                    ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(altIndex, available,
                                                                                                                     choice != null && choice.Index == altIndex);

                    alternative.Choice = modeTimes; // JLB added 20130420

                    //alternative.AddNestedAlternative(HTourModeTime.TOTAL_TOUR_MODE_TIMES + periodComb + 1, periodComb, THETA_PARAMETER);
                    alternative.AddNestedAlternative(HTourModeTime.TotalTourModeTimes + mode, mode - 1, THETA_PARAMETER);

                    //if (Global.Configuration.IsInEstimationMode && altIndex == choice.Index) {
                    //	Global.PrintFile.WriteLine("Aper Dper Mode {0} {1} {2} Travel Times {3} {4} Window {5} {6}",
                    //										arrivalPeriod.Index, departurePeriod.Index, mode,
                    //										modeTimes.ModeAvailableToDestination ? modeTimes.TravelTimeToDestination : -1,
                    //										modeTimes.ModeAvailableFromDestination ? modeTimes.TravelTimeFromDestination : -1,
                    //										modeTimes.LongestFeasibleWindow != null ? modeTimes.LongestFeasibleWindow.Start : -1,
                    //										modeTimes.LongestFeasibleWindow != null ? modeTimes.LongestFeasibleWindow.End : -1);

                    //}
                    //Following code was used to test handling of partially joint half tours (JLB 20140603)
                    //if (partialHalfTour) {
                    //	Global.PrintFile.WriteLine("HH pers {0} {1} avail {2} Aper Dper Mode {3} {4} {5} Travel Times {6} {7} Window {8} {9}",
                    //	   household.Id, person.Sequence,
                    //    available,
                    //		arrivalPeriod.Index, departurePeriod.Index, mode,
                    //	                           modeTimes.ModeAvailableToDestination ? modeTimes.TravelTimeToDestination : -1,
                    //	                           modeTimes.ModeAvailableFromDestination ? modeTimes.TravelTimeFromDestination : -1,
                    //	                           modeTimes.LongestFeasibleWindow != null ? modeTimes.LongestFeasibleWindow.Start : -1,
                    //	                           modeTimes.LongestFeasibleWindow != null ? modeTimes.LongestFeasibleWindow.End : -1);
                    //}

                    //if in application mode and combination is not available, can skip the rest
                    if (!Global.Configuration.IsInEstimationMode && !alternative.Available)
                    {
                        continue;
                    }
                    if (useTimeComponents)
                    {
                        // arrival period utility component
                        alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(arrivalPeriod.Index));

                        // departure period utility component
                        alternative.AddUtilityComponent(
                            choiceProbabilityCalculator.GetUtilityComponent(bigPeriodCount + departurePeriod.Index));

                        // period combination utility component
                        alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(2 * bigPeriodCount + periodComb));
                    }

                    // mode utility component
                    alternative.AddUtilityComponent(
                        choiceProbabilityCalculator.GetUtilityComponent(2 * bigPeriodCount + nPeriodCombs + mode - 1));

                    //even in estimation mode, do not need the rest of the code if not available
                    if (!alternative.Available)
                    {
                        continue;
                    }

                    //GV and JB: the parking cost are handled as part of genaralised time

                    double minimumTimeNeeded = modeTimes.TravelTimeToDestination + modeTimes.TravelTimeFromDestination + Global.Settings.Times.MinimumActivityDuration;

                    alternative.AddUtilityTerm(1, modeTimes.GeneralizedTimeToDestination + modeTimes.GeneralizedTimeFromDestination);

                    //alternative.AddUtilityTerm(3,
                    //                           Math.Log(modeTimes.LongestFeasibleWindow.End - modeTimes.LongestFeasibleWindow.Start -
                    //                                    minimumTimeNeeded + 1.0));

                    // JLB 20140204 replaced coeff 3 with a different time window formulation:  time pressure
                    //    instead of having positive utility for increasing time window, have negative utility for decreasing time window
                    alternative.AddUtilityTerm(3,
                                               Math.Log(Math.Max(Constants.EPSILON, 1 -
                                                                 Math.Pow(minimumTimeNeeded / (Math.Min(840, modeTimes.LongestFeasibleWindow.End - modeTimes.LongestFeasibleWindow.Start)), 0.8)
                                                                 )));



                    alternative.AddUtilityTerm(4, Math.Log((totalMinutesAvailableInDay + 1.0) / (minimumTimeNeeded + 1.0)));

                    alternative.AddUtilityTerm(5,
                                               (maleFlag == 0 && mode == Global.Settings.Modes.Walk &&
                                                arrivalPeriod.Index >= DayPeriod.EVENING)
                                                  ? 1
                                                  : 0);

                    if (altIndex == 0)
                    {
                        alternative.AddUtilityTerm(998, tour.DestinationPurpose);
                        alternative.AddUtilityTerm(999, (tour.ParentTour == null) ? 0 : 1);
                    }
                }
            }
        }
Exemplo n.º 15
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITourWrapper tour, IEnumerable <IPathTypeModel> pathTypeModels, IParcelWrapper destinationParcel, int householdCars, int choice = Constants.DEFAULT_VALUE)
        {
            IHouseholdWrapper household = tour.Household;

            Framework.DomainModels.Models.IHouseholdTotals householdTotals = household.HouseholdTotals;
            IPersonDayWrapper personDay = tour.PersonDay;
            IPersonWrapper    person    = tour.Person;

            // household inputs
            int childrenUnder5        = householdTotals.ChildrenUnder5;
            int childrenAge5Through15 = householdTotals.ChildrenAge5Through15;
            //            var nonworkingAdults = householdTotals.NonworkingAdults;
            //            var retiredAdults = householdTotals.RetiredAdults;
            int onePersonHouseholdFlag  = household.IsOnePersonHousehold.ToFlag();
            int twoPersonHouseholdFlag  = household.IsTwoPersonHousehold.ToFlag();
            int noCarsInHouseholdFlag   = household.GetFlagForNoCarsInHousehold(householdCars);
            int carsLessThanDriversFlag = household.GetFlagForCarsLessThanDrivers(householdCars);
            int carsLessThanWorkersFlag = household.GetFlagForCarsLessThanWorkers(householdCars);
            int income0To25KFlag        = household.Has0To25KIncome.ToFlag();
            int income75kPlusFlag       = household.Has75KPlusIncome.ToFlag();
            int incomeOver100Flag       = household.Has100KPlusIncome.ToFlag();

            // person inputs
            int maleFlag = person.IsMale.ToFlag();
            int ageBetween51And98Flag = person.AgeIsBetween51And98.ToFlag();
            int univStudentFlag       = person.IsUniversityStudent.ToFlag();

            IParcelWrapper originParcel    = tour.OriginParcel;
            int            parkingDuration = ChoiceModelUtility.GetParkingDuration(person.IsFulltimeWorker);
            // parking at work is free if no paid parking at work and tour goes to usual workplace
            double destinationParkingCost = (Global.Configuration.ShouldRunPayToParkAtWorkplaceModel && tour.Person.UsualWorkParcel != null &&
                                             destinationParcel == tour.Person.UsualWorkParcel && person.PaidParkingAtWorkplace == 0) ? 0.0 : destinationParcel.ParkingCostBuffer1(parkingDuration);

            ChoiceModelUtility.SetEscortPercentages(personDay, out double escortPercentage, out double nonEscortPercentage);

            foreach (IPathTypeModel pathTypeModel in pathTypeModels)
            {
                int    mode = pathTypeModel.Mode;
                double generalizedTimeLogsum = pathTypeModel.GeneralizedTimeLogsum;

                bool available = (pathTypeModel.Mode != Global.Settings.Modes.PaidRideShare || Global.Configuration.PaidRideShareModeIsAvailable) &&
                                 pathTypeModel.Available;

                ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(mode, available, choice == mode);
                alternative.Choice = mode;

                alternative.AddNestedAlternative(_nestedAlternativeIds[pathTypeModel.Mode], _nestedAlternativeIndexes[pathTypeModel.Mode], THETA_PARAMETER);

                if (!available)
                {
                    continue;
                }

                double modeTimeCoefficient = (Global.Configuration.AV_IncludeAutoTypeChoice && household.OwnsAutomatedVehicles > 0 && mode >= Global.Settings.Modes.Sov && mode <= Global.Settings.Modes.Hov3) ?
                                             tour.TimeCoefficient * (1.0 - Global.Configuration.AV_InVehicleTimeCoefficientDiscountFactor) :
                                             (mode == Global.Settings.Modes.PaidRideShare && Global.Configuration.AV_PaidRideShareModeUsesAVs) ?
                                             tour.TimeCoefficient * (1.0 - Global.Configuration.AV_InVehicleTimeCoefficientDiscountFactor) : tour.TimeCoefficient;
                alternative.AddUtilityTerm(2, generalizedTimeLogsum * modeTimeCoefficient);

                if (mode == Global.Settings.Modes.ParkAndRide)
                {
                    alternative.AddUtilityTerm(10, 1);
                    alternative.AddUtilityTerm(11, noCarsInHouseholdFlag);
                    alternative.AddUtilityTerm(13, carsLessThanWorkersFlag);
                    //                        alternative.AddUtility(129, destinationParcel.MixedUse2Index1());
                    alternative.AddUtilityTerm(130, Math.Log(destinationParcel.TotalEmploymentDensity1() + 1) * 2553.0 / Math.Log(2553.0));
                    alternative.AddUtilityTerm(128, destinationParcel.TotalEmploymentDensity1());
                    alternative.AddUtilityTerm(127, destinationParcel.NetIntersectionDensity1());
                    alternative.AddUtilityTerm(123, Math.Log(destinationParcel.StopsTransitBuffer1 + 1));
                    //alternative.AddUtilityTerm(120, Math.Log(destinationParcel.TotalEmploymentDensity1() + 1) * 2553.0 / Math.Log(2553.0));
                    alternative.AddUtilityTerm(118, destinationParcel.TotalEmploymentDensity1());
                    //alternative.AddUtilityTerm(117, destinationParcel.NetIntersectionDensity1());
                    alternative.AddUtilityTerm(113, Math.Log(destinationParcel.StopsTransitBuffer1 + 1));
                    alternative.AddUtilityTerm(112, Math.Log(originParcel.StopsTransitBuffer1 + 1));
                    alternative.AddUtilityTerm(115, Math.Log(pathTypeModel.PathParkAndRideNodeCapacity + 1));
                }
                else if (mode == Global.Settings.Modes.Transit)
                {
                    alternative.AddUtilityTerm(20, 1);
                    alternative.AddUtilityTerm(21, noCarsInHouseholdFlag);   //for calibration
                    alternative.AddUtilityTerm(22, carsLessThanDriversFlag); //for calibration
                                                                             //                        alternative.AddUtility(129, destinationParcel.MixedUse2Index1());
                    alternative.AddUtilityTerm(130, Math.Log(destinationParcel.TotalEmploymentDensity1() + 1) * 2553.0 / Math.Log(2553.0));
                    alternative.AddUtilityTerm(128, destinationParcel.TotalEmploymentDensity1());
                    alternative.AddUtilityTerm(127, destinationParcel.NetIntersectionDensity1());
                    alternative.AddUtilityTerm(126, originParcel.NetIntersectionDensity1());
                    //alternative.AddUtilityTerm(125, originParcel.HouseholdDensity1());
                    //alternative.AddUtilityTerm(124, originParcel.MixedUse2Index1());
                    alternative.AddUtilityTerm(123, Math.Log(destinationParcel.StopsTransitBuffer1 + 1));
                    alternative.AddUtilityTerm(122, Math.Log(originParcel.StopsTransitBuffer1 + 1));
                    alternative.AddUtilityTerm(180, univStudentFlag);
                    alternative.AddUtilityTerm(100, income75kPlusFlag);
                }
                else if (mode == Global.Settings.Modes.Hov3)
                {
                    alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / Global.Configuration.Coefficients_HOV3CostDivisor_Work));
                    alternative.AddUtilityTerm(30, 1);
                    alternative.AddUtilityTerm(31, childrenUnder5);
                    alternative.AddUtilityTerm(32, childrenAge5Through15);
                    //                       alternative.AddUtilityTerm(34, nonworkingAdults + retiredAdults);
                    alternative.AddUtilityTerm(35, pathTypeModel.PathDistance.AlmostEquals(0) ? 0 : Math.Log(pathTypeModel.PathDistance));
                    alternative.AddUtilityTerm(36, noCarsInHouseholdFlag);   // for calibration of hov3 vs hov2
                    alternative.AddUtilityTerm(37, carsLessThanDriversFlag); // for calibration of hov3 vs hov2
                    alternative.AddUtilityTerm(38, onePersonHouseholdFlag);
                    alternative.AddUtilityTerm(39, twoPersonHouseholdFlag);
                    alternative.AddUtilityTerm(41, noCarsInHouseholdFlag);
                    alternative.AddUtilityTerm(42, carsLessThanDriversFlag);
                    alternative.AddUtilityTerm(133, escortPercentage);
                    alternative.AddUtilityTerm(134, nonEscortPercentage);
                }
                else if (mode == Global.Settings.Modes.Hov2)
                {
                    alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / Global.Configuration.Coefficients_HOV2CostDivisor_Work));
                    alternative.AddUtilityTerm(31, childrenUnder5);
                    alternative.AddUtilityTerm(32, childrenAge5Through15);
                    //                        alternative.AddUtilityTerm(34, nonworkingAdults + retiredAdults);
                    alternative.AddUtilityTerm(35, pathTypeModel.PathDistance.AlmostEquals(0) ? 0 : Math.Log(pathTypeModel.PathDistance));
                    alternative.AddUtilityTerm(40, 1);
                    alternative.AddUtilityTerm(41, noCarsInHouseholdFlag);
                    alternative.AddUtilityTerm(42, carsLessThanDriversFlag);
                    alternative.AddUtilityTerm(48, onePersonHouseholdFlag);
                    alternative.AddUtilityTerm(133, escortPercentage);
                    alternative.AddUtilityTerm(134, nonEscortPercentage);
                }
                else if (mode == Global.Settings.Modes.Sov)
                {
                    alternative.AddUtilityTerm(1, (destinationParkingCost) * tour.CostCoefficient);
                    alternative.AddUtilityTerm(50, 1);
                    alternative.AddUtilityTerm(53, carsLessThanWorkersFlag);
                    alternative.AddUtilityTerm(54, income0To25KFlag);
                    alternative.AddUtilityTerm(131, escortPercentage);
                    alternative.AddUtilityTerm(132, nonEscortPercentage);
                }
                else if (mode == Global.Settings.Modes.Bike)
                {
                    double class1Dist
                        = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions
                  ? ImpedanceRoster.GetValue("class1distance", mode, Global.Settings.PathTypes.FullNetwork,
                                             Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable
                  : 0;

                    double class2Dist =
                        Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions
                  ? ImpedanceRoster.GetValue("class2distance", mode, Global.Settings.PathTypes.FullNetwork,
                                             Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable
                  : 0;

                    //                  double worstDist = Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions ?
                    //                         ImpedanceRoster.GetValue("worstdistance", mode, Global.Settings.PathTypes.FullNetwork,
                    //                            Global.Settings.VotGroups.Medium, tour.DestinationArrivalTime,originParcel, destinationParcel).Variable : 0;

                    alternative.AddUtilityTerm(60, 1);
                    alternative.AddUtilityTerm(61, maleFlag);
                    alternative.AddUtilityTerm(63, ageBetween51And98Flag);
                    alternative.AddUtilityTerm(67, noCarsInHouseholdFlag);   //for calibration
                    alternative.AddUtilityTerm(68, carsLessThanDriversFlag); //for calibration
                    alternative.AddUtilityTerm(169, destinationParcel.MixedUse4Index1());
                    alternative.AddUtilityTerm(168, destinationParcel.TotalEmploymentDensity1());
                    alternative.AddUtilityTerm(167, destinationParcel.NetIntersectionDensity1());
                    alternative.AddUtilityTerm(166, originParcel.NetIntersectionDensity1());
                    alternative.AddUtilityTerm(165, originParcel.HouseholdDensity1());
                    alternative.AddUtilityTerm(164, originParcel.MixedUse4Index1());
                    alternative.AddUtilityTerm(162, (class1Dist > 0).ToFlag());
                    alternative.AddUtilityTerm(162, (class2Dist > 0).ToFlag());
                    //                        alternative.AddUtility(163, (worstDist > 0).ToFlag());
                    alternative.AddUtilityTerm(170, 1.0 * destinationParcel.MixedUse4Index1()
                                               + 0.00002 * destinationParcel.TotalEmploymentDensity1()
                                               + 0.001 * destinationParcel.NetIntersectionDensity1()
                                               + 0.001 * originParcel.NetIntersectionDensity1()
                                               + 0.0002 * originParcel.HouseholdDensity1()
                                               + 1.0 * originParcel.MixedUse4Index1());

                    //alternative.AddUtilityTerm(261, originParcel.PCA_DensityTerm_Buffer1());
                    //alternative.AddUtilityTerm(262, originParcel.PCA_WalkabilityTerm_Buffer1());
                    //alternative.AddUtilityTerm(263, originParcel.PCA_MixedUseTerm_Buffer1());
                    //alternative.AddUtilityTerm(264, originParcel.PCA_TransitAccessTerm_Buffer1());
                    //alternative.AddUtilityTerm(261, destinationParcel.PCA_DensityTerm_Buffer1());
                    //alternative.AddUtilityTerm(262, destinationParcel.PCA_WalkabilityTerm_Buffer1());
                    //alternative.AddUtilityTerm(263, destinationParcel.PCA_MixedUseTerm_Buffer1());
                    //alternative.AddUtilityTerm(264, destinationParcel.PCA_TransitAccessTerm_Buffer1());
                    //alternative.AddUtilityTerm(265, destinationParcel.PCA_DensityTerm_Buffer1());
                    //alternative.AddUtilityTerm(266, destinationParcel.PCA_WalkabilityTerm_Buffer1());
                    //alternative.AddUtilityTerm(267, destinationParcel.PCA_MixedUseTerm_Buffer1());
                    //alternative.AddUtilityTerm(268, destinationParcel.PCA_TransitAccessTerm_Buffer1());
                }
                else if (mode == Global.Settings.Modes.Walk)
                {
                    alternative.AddUtilityTerm(70, 1); //for calibration
                    alternative.AddUtilityTerm(71, maleFlag);
                    alternative.AddUtilityTerm(73, ageBetween51And98Flag);
                    alternative.AddUtilityTerm(75, pathTypeModel.PathDistance * pathTypeModel.PathDistance);
                    alternative.AddUtilityTerm(77, noCarsInHouseholdFlag);   //for calibration
                    alternative.AddUtilityTerm(78, carsLessThanDriversFlag); //for calibration
                    alternative.AddUtilityTerm(179, destinationParcel.MixedUse4Index1());
                    alternative.AddUtilityTerm(178, destinationParcel.TotalEmploymentDensity1());
                    alternative.AddUtilityTerm(177, destinationParcel.NetIntersectionDensity1());
                    alternative.AddUtilityTerm(176, originParcel.NetIntersectionDensity1());
                    alternative.AddUtilityTerm(175, originParcel.HouseholdDensity1());
                    alternative.AddUtilityTerm(179, originParcel.MixedUse4Index1());
                    alternative.AddUtilityTerm(181, 1.0 * destinationParcel.MixedUse4Index1()
                                               + 0.00001 * destinationParcel.TotalEmploymentDensity1()
                                               + 0.001 * destinationParcel.NetIntersectionDensity1()
                                               + 0.001 * originParcel.NetIntersectionDensity1()
                                               + 0.0001 * originParcel.HouseholdDensity1()
                                               + 1.0 * originParcel.MixedUse4Index1());

                    //alternative.AddUtilityTerm(271, originParcel.PCA_DensityTerm_Buffer1());
                    //alternative.AddUtilityTerm(272, originParcel.PCA_WalkabilityTerm_Buffer1());
                    //alternative.AddUtilityTerm(273, originParcel.PCA_MixedUseTerm_Buffer1());
                    //alternative.AddUtilityTerm(274, originParcel.PCA_TransitAccessTerm_Buffer1());
                    //alternative.AddUtilityTerm(271, destinationParcel.PCA_DensityTerm_Buffer1());
                    //alternative.AddUtilityTerm(272, destinationParcel.PCA_WalkabilityTerm_Buffer1());
                    //alternative.AddUtilityTerm(273, destinationParcel.PCA_MixedUseTerm_Buffer1());
                    //alternative.AddUtilityTerm(274, destinationParcel.PCA_TransitAccessTerm_Buffer1());
                    //alternative.AddUtilityTerm(275, destinationParcel.PCA_DensityTerm_Buffer1());
                    //alternative.AddUtilityTerm(276, destinationParcel.PCA_WalkabilityTerm_Buffer1());
                    //alternative.AddUtilityTerm(277, destinationParcel.PCA_MixedUseTerm_Buffer1());
                    //alternative.AddUtilityTerm(278, destinationParcel.PCA_TransitAccessTerm_Buffer1());
                }
                else if (mode == Global.Settings.Modes.PaidRideShare)
                {
                    if (Global.Configuration.PaidRideshare_UseEstimatedInsteadOfAssertedCoefficients)
                    {
                        alternative.AddUtilityTerm(80, 1.0);
                        alternative.AddUtilityTerm(81, noCarsInHouseholdFlag);   //for calibration
                        alternative.AddUtilityTerm(82, carsLessThanDriversFlag); //for calibration
                        alternative.AddUtilityTerm(83, tour.Person.AgeIsBetween26And35.ToFlag());
                        alternative.AddUtilityTerm(83, tour.Person.AgeIsBetween18And25.ToFlag());
                        alternative.AddUtilityTerm(84, (tour.Person.Age >= 65).ToFlag());            //alternative.AddUtilityTerm(81, tour.Person.AgeIsBetween26And35.ToFlag());
                        alternative.AddUtilityTerm(85, originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2);
                        alternative.AddUtilityTerm(86, destinationParcel.HouseholdsBuffer2 + destinationParcel.StudentsUniversityBuffer2 + destinationParcel.EmploymentTotalBuffer2);
                        alternative.AddUtilityTerm(87, income0To25KFlag);
                        alternative.AddUtilityTerm(88, incomeOver100Flag);
                    }
                    else
                    {
                        double modeConstant = Global.Configuration.AV_PaidRideShareModeUsesAVs
                        ? Global.Configuration.AV_PaidRideShare_ModeConstant
                                              + Global.Configuration.AV_PaidRideShare_DensityCoefficient * Math.Min(originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2,
                                                                                                                    (Global.Configuration.PaidRideShare_DensityMeasureCapValue > 0) ? Global.Configuration.PaidRideShare_DensityMeasureCapValue : 6000)
                                              + Global.Configuration.AV_PaidRideShare_AVOwnerCoefficient * (household.OwnsAutomatedVehicles > 0).ToFlag()
                        : Global.Configuration.PaidRideShare_ModeConstant
                                              + Global.Configuration.PaidRideShare_DensityCoefficient * Math.Min(originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2,
                                                                                                                 (Global.Configuration.PaidRideShare_DensityMeasureCapValue > 0) ? Global.Configuration.PaidRideShare_DensityMeasureCapValue : 6000);

                        alternative.AddUtilityTerm(90, modeConstant);
                        alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_Age26to35Coefficient * tour.Person.AgeIsBetween26And35.ToFlag());
                        alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_Age18to25Coefficient * tour.Person.AgeIsBetween18And25.ToFlag());
                        alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_AgeOver65Coefficient * (tour.Person.Age >= 65).ToFlag());
                    }
                }



                RegionSpecificCustomizations(alternative, tour, pathTypeModel.PathType, mode, destinationParcel);
            }
        }
Exemplo n.º 16
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITourWrapper tour, List <PathTypeModel> pathTypeModels, IParcelWrapper destinationParcel, int householdCars, int choice = Constants.DEFAULT_VALUE)
        {
            var household = tour.Household;
            var person    = tour.Person;
            var personDay = tour.PersonDay;

            // household inputs
            var income0To25KFlag        = household.Has0To25KIncome.ToFlag();
            var income25To50KFlag       = household.Has25To50KIncome.ToFlag();
            var income75KPlusFlag       = household.Has75KPlusIncome.ToFlag();
            var onePersonHouseholdFlag  = household.IsOnePersonHousehold.ToFlag();
            var twoPersonHouseholdFlag  = household.IsTwoPersonHousehold.ToFlag();
            var noCarsInHouseholdFlag   = household.GetFlagForNoCarsInHousehold(householdCars);
            var carsLessThanDriversFlag = household.GetFlagForCarsLessThanDrivers(householdCars);

            // person inputs
            var childUnder5Flag       = person.IsChildUnder5.ToFlag();
            var adultFlag             = person.IsAdult.ToFlag();
            var drivingAgeStudentFlag = person.IsDrivingAgeStudent.ToFlag();
            var maleFlag = person.IsMale.ToFlag();

            // remaining inputs
            var originParcel           = tour.OriginParcel;
            var destinationParkingCost = destinationParcel.ParkingCostBuffer1(6);

            double escortPercentage;
            double nonEscortPercentage;

            ChoiceModelUtility.SetEscortPercentages(personDay, out escortPercentage, out nonEscortPercentage);

            // school bus is a special case - use HOV3 impedance
            var pathTypeExtra              = pathTypeModels.First(x => x.Mode == Global.Settings.Modes.Hov3);
            var modeExtra                  = Global.Settings.Modes.SchoolBus;
            var availableExtra             = pathTypeExtra.Available;
            var generalizedTimeLogsumExtra = pathTypeExtra.GeneralizedTimeLogsum;

            var alternative = choiceProbabilityCalculator.GetAlternative(modeExtra, availableExtra, choice == modeExtra);

            alternative.Choice = modeExtra;

            alternative.AddNestedAlternative(_nestedAlternativeIds[modeExtra], _nestedAlternativeIndexes[modeExtra], THETA_PARAMETER);

            if (availableExtra)
            {
                //	case Global.Settings.Modes.SchoolBus:
                alternative.AddUtilityTerm(2, generalizedTimeLogsumExtra * tour.TimeCoefficient);
                alternative.AddUtilityTerm(10, 1);
                alternative.AddUtilityTerm(17, childUnder5Flag);
                alternative.AddUtilityTerm(18, adultFlag);
            }

            foreach (var pathTypeModel in pathTypeModels)
            {
                var mode                  = pathTypeModel.Mode;
                var available             = pathTypeModel.Available;
                var generalizedTimeLogsum = pathTypeModel.GeneralizedTimeLogsum;

                alternative        = choiceProbabilityCalculator.GetAlternative(mode, available, choice == mode);
                alternative.Choice = mode;

                alternative.AddNestedAlternative(_nestedAlternativeIds[mode], _nestedAlternativeIndexes[mode], THETA_PARAMETER);

                if (!available)
                {
                    continue;
                }

                alternative.AddUtilityTerm(2, generalizedTimeLogsum * tour.TimeCoefficient);

                if (mode == Global.Settings.Modes.Transit)
                {
                    alternative.AddUtilityTerm(20, 1);
                    alternative.AddUtilityTerm(21, noCarsInHouseholdFlag);
                    alternative.AddUtilityTerm(22, carsLessThanDriversFlag);
                    alternative.AddUtilityTerm(27, childUnder5Flag);
                    alternative.AddUtilityTerm(28, adultFlag);
                    alternative.AddUtilityTerm(29, drivingAgeStudentFlag);
                    alternative.AddUtilityTerm(129, destinationParcel.MixedUse2Index1());
                    //						alternative.AddUtility(128, destinationParcel.TotalEmploymentDensity1());
                    //						alternative.AddUtility(127, destinationParcel.NetIntersectionDensity1());
                    //						alternative.AddUtility(126, originParcel.NetIntersectionDensity1());
                    //						alternative.AddUtility(125, originParcel.HouseholdDensity1());
                    //						alternative.AddUtility(124, originParcel.MixedUse2Index1());
                    //						alternative.AddUtility(123, Math.Log(destinationParcel.StopsTransitBuffer1+1));
                    alternative.AddUtilityTerm(122, Math.Log(originParcel.StopsTransitBuffer1 + 1));
                }
                else if (mode == Global.Settings.Modes.Hov3)
                {
                    alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / ChoiceModelUtility.CPFACT3));
                    alternative.AddUtilityTerm(30, 1);
                    alternative.AddUtilityTerm(37, twoPersonHouseholdFlag);
                    alternative.AddUtilityTerm(37, onePersonHouseholdFlag);
                    alternative.AddUtilityTerm(41, noCarsInHouseholdFlag);
                    alternative.AddUtilityTerm(44, income0To25KFlag);
                    alternative.AddUtilityTerm(45, income25To50KFlag);
                    alternative.AddUtilityTerm(47, childUnder5Flag);
                    alternative.AddUtilityTerm(133, escortPercentage);
                    alternative.AddUtilityTerm(134, nonEscortPercentage);
                }
                else if (mode == Global.Settings.Modes.Hov2)
                {
                    alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / ChoiceModelUtility.CPFACT2));
                    alternative.AddUtilityTerm(38, onePersonHouseholdFlag);
                    alternative.AddUtilityTerm(40, 1);
                    alternative.AddUtilityTerm(41, noCarsInHouseholdFlag);
                    alternative.AddUtilityTerm(44, income0To25KFlag);
                    alternative.AddUtilityTerm(45, income25To50KFlag);
                    alternative.AddUtilityTerm(47, childUnder5Flag);
                    alternative.AddUtilityTerm(133, escortPercentage);
                    alternative.AddUtilityTerm(134, nonEscortPercentage);
                }
                else if (mode == Global.Settings.Modes.Sov)
                {
                    alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient));
                    alternative.AddUtilityTerm(50, 1);
                    alternative.AddUtilityTerm(52, carsLessThanDriversFlag);
                    alternative.AddUtilityTerm(54, income0To25KFlag);
                    alternative.AddUtilityTerm(56, income75KPlusFlag);
                    alternative.AddUtilityTerm(59, drivingAgeStudentFlag);
                    alternative.AddUtilityTerm(131, escortPercentage);
                    alternative.AddUtilityTerm(132, nonEscortPercentage);
                }
                else if (mode == Global.Settings.Modes.Bike)
                {
                    var class1Dist =
                        Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions
                                                        ? ImpedanceRoster.GetValue("class1distance", mode, Global.Settings.PathTypes.FullNetwork,
                                                                                   Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable
                                                        : 0;

                    var class2Dist =
                        Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions
                                                        ? ImpedanceRoster.GetValue("class2distance", mode, Global.Settings.PathTypes.FullNetwork,
                                                                                   Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable
                                                        : 0;

                    var worstDist =
                        Global.Configuration.PathImpedance_BikeUseTypeSpecificDistanceFractions
                                                        ? ImpedanceRoster.GetValue("worstdistance", mode, Global.Settings.PathTypes.FullNetwork,
                                                                                   Global.Settings.ValueOfTimes.DefaultVot, tour.DestinationArrivalTime, originParcel, destinationParcel).Variable
                                                        : 0;

                    alternative.AddUtilityTerm(60, 1);
                    alternative.AddUtilityTerm(61, maleFlag);
                    alternative.AddUtilityTerm(69, adultFlag);
                    alternative.AddUtilityTerm(169, destinationParcel.MixedUse4Index1());
                    alternative.AddUtilityTerm(168, destinationParcel.TotalEmploymentDensity1());
                    //						alternative.AddUtility(167, destinationParcel.NetIntersectionDensity1());
                    //						alternative.AddUtility(166, originParcel.NetIntersectionDensity1());
                    //						alternative.AddUtility(165, originParcel.HouseholdDensity1());
                    alternative.AddUtilityTerm(164, originParcel.MixedUse4Index1());
                    alternative.AddUtilityTerm(161, (class1Dist > 0).ToFlag());
                    alternative.AddUtilityTerm(162, (class2Dist > 0).ToFlag());
                    alternative.AddUtilityTerm(163, (worstDist > 0).ToFlag());
                }
                else if (mode == Global.Settings.Modes.Walk)
                {
                    alternative.AddUtilityTerm(79, adultFlag);
                    alternative.AddUtilityTerm(179, destinationParcel.MixedUse4Index1());
                    //						alternative.AddUtility(178, destinationParcel.TotalEmploymentDensity1());
                    //						alternative.AddUtility(177, destinationParcel.NetIntersectionDensity1());
                    //						alternative.AddUtility(176, originParcel.NetIntersectionDensity1());
                    //						alternative.AddUtility(175, originParcel.HouseholdDensity1());
                    alternative.AddUtilityTerm(179, originParcel.MixedUse4Index1());
                }
            }
        }
Exemplo n.º 17
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.º 18
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, HouseholdDayWrapper householdDay, int nCallsForTour, int[] purpose, int[][] altParticipants, int choice = Constants.DEFAULT_VALUE)
        {
            IEnumerable <PersonDayWrapper> orderedPersonDays = householdDay.PersonDays.OrderBy(p => p.GetJointTourParticipationPriority()).ToList().Cast <PersonDayWrapper>();
            // set household characteristics here that don't depend on person characteristics

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

            int tourPurpose = purpose[nCallsForTour];

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

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

            PersonDayWrapper pPersonDay = null;

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


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

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

            int[] pTransit = new int[6];

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

            int count = 0;

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

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

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

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                alternative.Choice = alt;

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

                for (int p = 1; p <= 5; p++)
                {
                    if (altParticipants[alt][p] == 1)
                    {
                        alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]));
                    }
                }
                for (int t2 = 1; t2 <= 5; t2++)
                {
                    for (int t1 = 1; t1 < t2; t1++)
                    {
                        if (altParticipants[alt][t1] == 1 && altParticipants[alt][t2] == 1)
                        {
                            alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]));
                        }
                    }
                }
                for (int t2 = 1; t2 <= 5; t2++)
                {
                    for (int t1 = 1; t1 <= 5; t1++)
                    {
                        if (!(t1 == t2))
                        {
                            if (altParticipants[alt][t1] == 1 && altParticipants[alt][t2] == 1)
                            {
                                alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]));
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 19
0
        public ChoiceProbabilityCalculator.Alternative RunNested(ITourWrapper subtour, IParcelWrapper destinationParcel)
        {
            if (subtour == null)
            {
                throw new ArgumentNullException("subtour");
            }

            var choiceProbabilityCalculator = _helpers[ParallelUtility.threadLocalAssignedIndex.Value].GetNestedChoiceProbabilityCalculator();

            IEnumerable <IPathTypeModel> pathTypeModels =
                PathTypeModelFactory.Singleton.RunAll(
                    subtour.Household.RandomUtility,
                    subtour.OriginParcel,
                    destinationParcel,
                    subtour.DestinationArrivalTime,
                    subtour.DestinationDepartureTime,
                    subtour.DestinationPurpose,
                    subtour.CostCoefficient,
                    subtour.TimeCoefficient,
                    subtour.Person.IsDrivingAge,
                    subtour.Household.VehiclesAvailable,
                    subtour.Household.OwnsAutomatedVehicles > 0,
                    subtour.Person.GetTransitFareDiscountFraction(),
                    false);

            RunModel(choiceProbabilityCalculator, subtour, pathTypeModels, destinationParcel, subtour.ParentTour.Mode);

            return(choiceProbabilityCalculator.SimulateChoice(subtour.Household.RandomUtility));
        }
Exemplo n.º 20
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITripWrapper trip, IEnumerable <IPathTypeModel> pathTypeModels, IParcelWrapper originParcel, IParcelWrapper destinationParcel, int departureTime, int choice = Constants.DEFAULT_VALUE)
        {
            var household       = trip.Household;
            var householdTotals = household.HouseholdTotals;
            var person          = trip.Person;
            var tour            = trip.Tour;
            var halfTour        = trip.HalfTour;

            // household inputs
            var onePersonHouseholdFlag  = household.IsOnePersonHousehold.ToFlag();
            var twoPersonHouseholdFlag  = household.IsTwoPersonHousehold.ToFlag();
            var income0To25KFlag        = household.Has0To25KIncome.ToFlag();
            var income25To45KFlag       = household.Has25To45KIncome.ToFlag();
            var childrenAge5Through15   = householdTotals.ChildrenAge5Through15;
            var nonworkingAdults        = householdTotals.NonworkingAdults;
            var retiredAdults           = householdTotals.RetiredAdults;
            var noCarsInHouseholdFlag   = household.GetFlagForNoCarsInHousehold(household.VehiclesAvailable);
            var carsLessThanDriversFlag = household.GetFlagForCarsLessThanDrivers(household.VehiclesAvailable);

            // person inputs
            var drivingAgeStudentFlag = person.IsDrivingAgeStudent.ToFlag();
            var maleFlag          = person.IsMale.ToFlag();
            var ageLessThan35Flag = person.AgeIsLessThan35.ToFlag();

            // tour inputs
            var parkAndRideTourFlag       = tour.IsParkAndRideMode().ToFlag();
            var transitTourFlag           = tour.IsTransitMode().ToFlag();
            var schoolBusTourFlag         = tour.IsSchoolBusMode().ToFlag();
            var hov3TourFlag              = tour.IsHov3Mode().ToFlag();
            var hov2TourFlag              = tour.IsHov2Mode().ToFlag();
            var sovTourFlag               = tour.IsSovMode().ToFlag();
            var bikeTourFlag              = tour.IsBikeMode().ToFlag();
            var walkTourFlag              = tour.IsWalkMode().ToFlag();
            var homeBasedWorkTourFlag     = (tour.IsHomeBasedTour && tour.IsWorkPurpose()).ToFlag();
            var homeBasedSchoolTourFlag   = (tour.IsHomeBasedTour && tour.IsSchoolPurpose()).ToFlag();
            var homeBasedEscortTourFlag   = (tour.IsHomeBasedTour && tour.IsEscortPurpose()).ToFlag();
            var homeBasedShoppingTourFlag = (tour.IsHomeBasedTour && tour.IsShoppingPurpose()).ToFlag();
            var homeBasedMealTourFlag     = (tour.IsHomeBasedTour && tour.IsMealPurpose()).ToFlag();
            var homeBasedSocialTourFlag   = (tour.IsHomeBasedTour && tour.IsSocialPurpose()).ToFlag();
            var notHomeBasedTourFlag      = (!tour.IsHomeBasedTour).ToFlag();
            //            var homeBasedNotWorkSchoolEscortTourFlag = (tour.IsHomeBasedTour && tour.DestinationPurpose > Global.Settings.Purposes.Escort).ToFlag();
            //            var costco = -0.1432 * homeBasedWorkTourFlag - 0.2000 * homeBasedSchoolTourFlag - 0.3000 * homeBasedEscortTourFlag - 0.2000 * homeBasedNotWorkSchoolEscortTourFlag - 0.2000 * notHomeBasedTourFlag;

            // trip inputs
            var originHomeEscortFlag = (trip.IsNoneOrHomePurposeByOrigin() && trip.IsEscortPurposeByDestination()).ToFlag();
            var originWorkEscortFlag = (trip.IsWorkPurposeByOrigin() && trip.IsEscortPurposeByDestination()).ToFlag();

            var destinationHomeEscortFlag = (trip.IsNoneOrHomePurposeByDestination() && trip.IsEscortPurposeByOrigin()).ToFlag();
            var destinationWorkEscortFlag = (trip.IsWorkPurposeByDestination() && trip.IsEscortPurposeByOrigin()).ToFlag();

            // only trip on first half-tour
            var onlyTripOnFirstHalfFlag = (trip.IsHalfTourFromOrigin && halfTour.SimulatedTrips == 1 && trip.IsToTourOrigin).ToFlag();

            // first trip on first half-tour, not only one
            var firstTripOnFirstHalfFlag = (trip.IsHalfTourFromOrigin && halfTour.SimulatedTrips == 1 && !trip.IsToTourOrigin).ToFlag();

            // last trip first half-tour, not only one
            var lastTripOnFirstHalfFlag = (trip.IsHalfTourFromOrigin && halfTour.SimulatedTrips > 1 && trip.IsToTourOrigin).ToFlag();

            // only trip on second half-tour
            var onlyTripOnSecondHalfFlag = (!trip.IsHalfTourFromOrigin && halfTour.SimulatedTrips == 1 && trip.IsToTourOrigin).ToFlag();

            // first trip on second half-tour, not only one
            var firstTripOnSecondHalfFlag = (!trip.IsHalfTourFromOrigin && halfTour.SimulatedTrips == 1 && !trip.IsToTourOrigin).ToFlag();

            // last trip second half-tour, not only one
            var lastTripOnSecondHalfFlag = (!trip.IsHalfTourFromOrigin && halfTour.SimulatedTrips > 1 && trip.IsToTourOrigin).ToFlag();

            // remaining inputs
            var originMixedDensity        = originParcel.MixedUse4Index1();
            var originIntersectionDensity = originParcel.NetIntersectionDensity1();
            var destinationParkingCost    = destinationParcel.ParkingCostBuffer1(2);
            var amPeriodFlag      = departureTime.IsLeftExclusiveBetween(Global.Settings.Times.SixAM, Global.Settings.Times.TenAM).ToFlag();
            var middayPeriodFlag  = departureTime.IsLeftExclusiveBetween(Global.Settings.Times.TenAM, Global.Settings.Times.ThreePM).ToFlag();
            var pmPeriodFlag      = departureTime.IsLeftExclusiveBetween(Global.Settings.Times.ThreePM, Global.Settings.Times.SevenPM).ToFlag();
            var eveningPeriodFlag = (departureTime > Global.Settings.Times.SevenPM).ToFlag();

            // availability
            var tripModeAvailable = new bool[Global.Settings.Modes.TotalModes];

            var isLastTripInTour = (!trip.IsHalfTourFromOrigin && halfTour.SimulatedTrips == 1 && trip.IsToTourOrigin) || (!trip.IsHalfTourFromOrigin && halfTour.SimulatedTrips > 1 && trip.IsToTourOrigin);
            var frequencyPreviousTripModeIsTourMode =
                trip.IsHalfTourFromOrigin
                    ? tour.HalfTourFromOrigin.Trips.Where(x => x.Sequence < trip.Sequence).Count(x => tour.Mode == x.Mode)
                    : tour.HalfTourFromOrigin.Trips.Union(tour.HalfTourFromDestination.Trips.Where(x => x.Sequence < trip.Sequence)).Count(x => tour.Mode == x.Mode);

            // if a park and ride tour, only car is available
            var maxAvail = tour.Mode == Global.Settings.Modes.PaidRideShare ? Global.Settings.Modes.Transit : tour.Mode;

            if (tour.Mode == Global.Settings.Modes.ParkAndRide)
            {
                tripModeAvailable[Global.Settings.Modes.Sov]  = tour.Household.VehiclesAvailable > 0 && tour.Person.IsDrivingAge;
                tripModeAvailable[Global.Settings.Modes.Hov2] = !tripModeAvailable[Global.Settings.Modes.Sov];
            }
            // if the last trip of the tour and tour mode not yet used, only the tour mode is available
            else if (isLastTripInTour && frequencyPreviousTripModeIsTourMode == 0 && tour.Mode <= maxAvail)
            {
                tripModeAvailable[tour.Mode] = true;
            }
            else
            {
                // set availability based on tour mode
                for (var mode = Global.Settings.Modes.Walk; mode <= maxAvail; mode++)
                {
                    tripModeAvailable[mode] = true;
                }
            }

            {
                // school bus is a special case - use HOV3 impedance and only available for school bus tours
                var pathTypeExtra              = pathTypeModels.First(x => x.Mode == Global.Settings.Modes.Hov3);
                var modeExtra                  = Global.Settings.Modes.SchoolBus;
                var availableExtra             = pathTypeExtra.Available && tour.IsSchoolBusMode() && tripModeAvailable[modeExtra];
                var generalizedTimeLogsumExtra = pathTypeExtra.GeneralizedTimeLogsum;

                var alternative = choiceProbabilityCalculator.GetAlternative(modeExtra, availableExtra, choice == modeExtra);
                alternative.Choice = modeExtra;

                alternative.AddNestedAlternative(_nestedAlternativeIds[modeExtra], _nestedAlternativeIndexes[modeExtra], THETA_PARAMETER);

                if (availableExtra)
                {
                    //    case Global.Settings.Modes.SchoolBus:
                    alternative.AddUtilityTerm(2, generalizedTimeLogsumExtra * tour.TimeCoefficient);
                    alternative.AddUtilityTerm(18, 1);
                    alternative.AddUtilityTerm(100, schoolBusTourFlag);
                    alternative.AddUtilityTerm(102, (schoolBusTourFlag * onlyTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(103, (schoolBusTourFlag * onlyTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(104, (schoolBusTourFlag * firstTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(105, (schoolBusTourFlag * firstTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(106, (schoolBusTourFlag * lastTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(107, (schoolBusTourFlag * lastTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(112, parkAndRideTourFlag);
                    alternative.AddUtilityTerm(113, transitTourFlag);
                }
            }
            // paidRideShare is a special case
            if (Global.Configuration.PaidRideShareModeIsAvailable && tour.Mode == Global.Settings.Modes.PaidRideShare)
            {
                var pathTypeExtra              = pathTypeModels.First(x => x.Mode == Global.Settings.Modes.PaidRideShare);
                var modeExtra                  = Global.Settings.Modes.PaidRideShare;
                var availableExtra             = pathTypeExtra.Available;
                var generalizedTimeLogsumExtra = pathTypeExtra.GeneralizedTimeLogsum;
                var distanceExtra              = pathTypeExtra.PathDistance;

                var alternative = choiceProbabilityCalculator.GetAlternative(modeExtra - 2, availableExtra, choice == modeExtra);
                alternative.Choice = modeExtra;

                alternative.AddNestedAlternative(_nestedAlternativeIds[modeExtra], _nestedAlternativeIndexes[modeExtra], THETA_PARAMETER);

                if (availableExtra)
                {
                    var extraCostPerMile = Global.Configuration.AV_PaidRideShareModeUsesAVs ?
                                           Global.Configuration.AV_PaidRideShare_ExtraCostPerDistanceUnit : Global.Configuration.PaidRideShare_ExtraCostPerDistanceUnit;
                    var fixedCostPerRide = Global.Configuration.AV_PaidRideShareModeUsesAVs ?
                                           Global.Configuration.AV_PaidRideShare_FixedCostPerRide : Global.Configuration.PaidRideShare_FixedCostPerRide;
                    var autoTimeCoefficient = Global.Configuration.AV_PaidRideShareModeUsesAVs ?
                                              tour.TimeCoefficient * (1.0 - Global.Configuration.AV_InVehicleTimeCoefficientDiscountFactor) : tour.TimeCoefficient;
                    alternative.AddUtilityTerm(2, generalizedTimeLogsumExtra * autoTimeCoefficient);
                    alternative.AddUtilityTerm(2, distanceExtra * extraCostPerMile * tour.CostCoefficient);
                    alternative.AddUtilityTerm(2, fixedCostPerRide * tour.CostCoefficient);

                    var modeConstant = Global.Configuration.AV_PaidRideShareModeUsesAVs
                     ? Global.Configuration.AV_PaidRideShare_ModeConstant
                                       + Global.Configuration.AV_PaidRideShare_DensityCoefficient * Math.Min(originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2, 6000)
                                       + Global.Configuration.AV_PaidRideShare_AVOwnerCoefficient * (household.OwnsAutomatedVehicles > 0).ToFlag()
                     : Global.Configuration.PaidRideShare_ModeConstant
                                       + Global.Configuration.PaidRideShare_DensityCoefficient * Math.Min(originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2, 6000);

                    alternative.AddUtilityTerm(90, modeConstant);
                    alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_Age26to35Coefficient * tour.Person.AgeIsBetween26And35.ToFlag());
                    alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_Age18to25Coefficient * tour.Person.AgeIsBetween18And25.ToFlag());
                    alternative.AddUtilityTerm(90, Global.Configuration.PaidRideShare_AgeOver65Coefficient * (tour.Person.Age >= 65).ToFlag());
                }
            }


            foreach (var pathTypeModel in pathTypeModels)
            {
                var mode                  = pathTypeModel.Mode;
                var available             = pathTypeModel.Available && tripModeAvailable[mode];
                var generalizedTimeLogsum = pathTypeModel.GeneralizedTimeLogsum;

                var alternative = choiceProbabilityCalculator.GetAlternative(mode, available, choice == mode);
                alternative.Choice = mode;

                alternative.AddNestedAlternative(_nestedAlternativeIds[mode], _nestedAlternativeIndexes[mode], THETA_PARAMETER);

                if (!available)
                {
                    continue;
                }

                var modeTimeCoefficient = (Global.Configuration.AV_IncludeAutoTypeChoice && household.OwnsAutomatedVehicles > 0 && mode >= Global.Settings.Modes.Sov && mode <= Global.Settings.Modes.Hov3) ?
                                          tour.TimeCoefficient * (1.0 - Global.Configuration.AV_InVehicleTimeCoefficientDiscountFactor) : tour.TimeCoefficient;
                alternative.AddUtilityTerm(2, generalizedTimeLogsum * modeTimeCoefficient);


                if (mode == Global.Settings.Modes.Transit)
                {
                    alternative.AddUtilityTerm(20, 1);
                    alternative.AddUtilityTerm(22, carsLessThanDriversFlag);
                    alternative.AddUtilityTerm(100, transitTourFlag);
                    alternative.AddUtilityTerm(102, (transitTourFlag * onlyTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(103, (transitTourFlag * onlyTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(104, (transitTourFlag * firstTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(105, (transitTourFlag * firstTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(106, (transitTourFlag * lastTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(107, (transitTourFlag * lastTripOnSecondHalfFlag));
                }
                else if (mode == Global.Settings.Modes.Hov3)
                {
                    alternative.AddUtilityTerm(30, 1);
                    alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / ChoiceModelUtility.CPFACT3));
                    alternative.AddUtilityTerm(32, childrenAge5Through15);
                    alternative.AddUtilityTerm(34, (nonworkingAdults + retiredAdults));
                    alternative.AddUtilityTerm(36, onePersonHouseholdFlag);
                    alternative.AddUtilityTerm(37, twoPersonHouseholdFlag);
                    alternative.AddUtilityTerm(41, noCarsInHouseholdFlag);
                    alternative.AddUtilityTerm(100, hov3TourFlag);
                    alternative.AddUtilityTerm(102, (hov3TourFlag * onlyTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(103, (hov3TourFlag * onlyTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(104, (hov3TourFlag * firstTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(105, (hov3TourFlag * firstTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(106, (hov3TourFlag * lastTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(107, (hov3TourFlag * lastTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(114, parkAndRideTourFlag);
                    alternative.AddUtilityTerm(115, transitTourFlag);
                    alternative.AddUtilityTerm(116, schoolBusTourFlag);
                    alternative.AddUtilityTerm(149, homeBasedWorkTourFlag);
                    alternative.AddUtilityTerm(150, homeBasedSchoolTourFlag);
                    alternative.AddUtilityTerm(152, homeBasedEscortTourFlag);
                    alternative.AddUtilityTerm(153, homeBasedShoppingTourFlag);
                    alternative.AddUtilityTerm(154, homeBasedMealTourFlag);
                    alternative.AddUtilityTerm(155, homeBasedSocialTourFlag);
                    alternative.AddUtilityTerm(161, (destinationWorkEscortFlag * amPeriodFlag));
                    alternative.AddUtilityTerm(162, (originWorkEscortFlag * pmPeriodFlag));
                    alternative.AddUtilityTerm(163, (originHomeEscortFlag * amPeriodFlag));
                    alternative.AddUtilityTerm(164, (originHomeEscortFlag * middayPeriodFlag));
                    alternative.AddUtilityTerm(165, (originHomeEscortFlag * pmPeriodFlag));
                    alternative.AddUtilityTerm(166, (originHomeEscortFlag * eveningPeriodFlag));
                    alternative.AddUtilityTerm(167, (destinationHomeEscortFlag * amPeriodFlag));
                    alternative.AddUtilityTerm(168, (destinationHomeEscortFlag * middayPeriodFlag));
                    alternative.AddUtilityTerm(169, (destinationHomeEscortFlag * pmPeriodFlag));
                    alternative.AddUtilityTerm(170, (destinationHomeEscortFlag * eveningPeriodFlag));
                }
                else if (mode == Global.Settings.Modes.Hov2)
                {
                    alternative.AddUtilityTerm(40, 1);
                    alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / ChoiceModelUtility.CPFACT2));
                    alternative.AddUtilityTerm(32, (childrenAge5Through15 * (1 - homeBasedEscortTourFlag)));
                    alternative.AddUtilityTerm(34, ((nonworkingAdults + retiredAdults) * (1 - homeBasedEscortTourFlag)));
                    alternative.AddUtilityTerm(38, onePersonHouseholdFlag);
                    alternative.AddUtilityTerm(41, noCarsInHouseholdFlag);
                    alternative.AddUtilityTerm(100, hov2TourFlag);
                    alternative.AddUtilityTerm(102, (hov2TourFlag * onlyTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(103, (hov2TourFlag * onlyTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(104, (hov2TourFlag * firstTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(105, (hov2TourFlag * firstTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(106, (hov2TourFlag * lastTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(107, (hov2TourFlag * lastTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(118, transitTourFlag);
                    alternative.AddUtilityTerm(119, schoolBusTourFlag);
                    alternative.AddUtilityTerm(120, hov3TourFlag);
                    alternative.AddUtilityTerm(149, homeBasedWorkTourFlag);
                    alternative.AddUtilityTerm(150, homeBasedSchoolTourFlag);
                    alternative.AddUtilityTerm(152, homeBasedEscortTourFlag);
                    alternative.AddUtilityTerm(153, homeBasedShoppingTourFlag);
                    alternative.AddUtilityTerm(154, homeBasedMealTourFlag);
                    alternative.AddUtilityTerm(155, homeBasedSocialTourFlag);
                    alternative.AddUtilityTerm(161, (destinationWorkEscortFlag * amPeriodFlag));
                    alternative.AddUtilityTerm(162, (originWorkEscortFlag * pmPeriodFlag));
                    alternative.AddUtilityTerm(163, (originHomeEscortFlag * amPeriodFlag));
                    alternative.AddUtilityTerm(164, (originHomeEscortFlag * middayPeriodFlag));
                    alternative.AddUtilityTerm(165, (originHomeEscortFlag * pmPeriodFlag));
                    alternative.AddUtilityTerm(166, (originHomeEscortFlag * eveningPeriodFlag));
                    alternative.AddUtilityTerm(167, (destinationHomeEscortFlag * amPeriodFlag));
                    alternative.AddUtilityTerm(168, (destinationHomeEscortFlag * middayPeriodFlag));
                    alternative.AddUtilityTerm(169, (destinationHomeEscortFlag * pmPeriodFlag));
                    alternative.AddUtilityTerm(170, (destinationHomeEscortFlag * eveningPeriodFlag));
                }
                else if (mode == Global.Settings.Modes.Sov)
                {
                    alternative.AddUtilityTerm(50, 1);
                    alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient));
                    alternative.AddUtilityTerm(52, carsLessThanDriversFlag);
                    alternative.AddUtilityTerm(54, income0To25KFlag);
                    alternative.AddUtilityTerm(55, income25To45KFlag);
                    alternative.AddUtilityTerm(59, drivingAgeStudentFlag);
                    alternative.AddUtilityTerm(100, sovTourFlag);
                    alternative.AddUtilityTerm(102, (sovTourFlag * onlyTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(103, (sovTourFlag * onlyTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(104, (sovTourFlag * firstTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(105, (sovTourFlag * firstTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(106, (sovTourFlag * lastTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(107, (sovTourFlag * lastTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(121, parkAndRideTourFlag);
                    alternative.AddUtilityTerm(122, transitTourFlag);
                    alternative.AddUtilityTerm(124, hov3TourFlag);
                    alternative.AddUtilityTerm(125, hov2TourFlag);
                }
                else if (mode == Global.Settings.Modes.Bike)
                {
                    alternative.AddUtilityTerm(60, 1);
                    alternative.AddUtilityTerm(61, maleFlag);
                    alternative.AddUtilityTerm(62, ageLessThan35Flag);
                    alternative.AddUtilityTerm(65, originIntersectionDensity);
                    alternative.AddUtilityTerm(100, bikeTourFlag);
                    alternative.AddUtilityTerm(102, (bikeTourFlag * onlyTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(103, (bikeTourFlag * onlyTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(104, (bikeTourFlag * firstTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(105, (bikeTourFlag * firstTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(106, (bikeTourFlag * lastTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(107, (bikeTourFlag * lastTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(127, transitTourFlag);
                    alternative.AddUtilityTerm(128, schoolBusTourFlag);
                    alternative.AddUtilityTerm(130, hov2TourFlag);
                    alternative.AddUtilityTerm(131, sovTourFlag);
                    alternative.AddUtilityTerm(147, notHomeBasedTourFlag);
                }
                else if (mode == Global.Settings.Modes.Walk)
                {
                    alternative.AddUtilityTerm(72, ageLessThan35Flag);
                    alternative.AddUtilityTerm(75, originIntersectionDensity);
                    alternative.AddUtilityTerm(78, originMixedDensity); // origin and destination mixed use measures - geometric avg. - half mile from cell, in 1000s
                    alternative.AddUtilityTerm(100, walkTourFlag);
                    alternative.AddUtilityTerm(102, (walkTourFlag * onlyTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(103, (walkTourFlag * onlyTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(104, (walkTourFlag * firstTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(105, (walkTourFlag * firstTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(106, (walkTourFlag * lastTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(107, (walkTourFlag * lastTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(141, homeBasedWorkTourFlag);
                    alternative.AddUtilityTerm(142, homeBasedSchoolTourFlag);
                }
            }
        }
Exemplo n.º 21
0
        //MBADD runnested
        public ChoiceProbabilityCalculator.Alternative RunNested(IPersonWrapper person, IParcelWrapper originParcel, IParcelWrapper destinationParcel, int destinationArrivalTime, int destinationDepartureTime, int householdCars, double constrainedTransitDiscountFraction)
        {
            if (person == null)
            {
                throw new ArgumentNullException("person");
            }

            ITourWrapper tour = _creator.CreateWrapper(person, null, originParcel, destinationParcel, destinationArrivalTime, destinationDepartureTime, Global.Settings.Purposes.Work);

            return(RunNested(tour, destinationParcel, householdCars, constrainedTransitDiscountFraction));
        }
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, HouseholdDayWrapper householdDay, int jHTSimulated, int genChoice, bool[,] jHTAvailable, bool[] pHTAvailable, int[][] altParticipants, int choice = Constants.DEFAULT_VALUE)
        {
            IEnumerable <PersonDayWrapper> orderedPersonDays = householdDay.PersonDays.OrderBy(p => p.GetJointHalfTourParticipationPriority()).ToList().Cast <PersonDayWrapper>();
            int threadAssignedIndex = ParallelUtility.threadLocalAssignedIndex.Value;
            int pairedHalfTour      = genChoice == 1 ? 1 : 0;
            int firstHalfTour       = genChoice == 2 ? 1 : 0;
            int secondHalfTour      = genChoice == 3 ? 1 : 0;

            double income          = householdDay.Household.Income < 0 ? Global.Configuration.Coefficients_BaseCostCoefficientIncomeLevel : householdDay.Household.Income; // missing converted to 30K
            double incomeMultiple  = Math.Min(Math.Max(income / Global.Configuration.Coefficients_BaseCostCoefficientIncomeLevel, .1), 10);                                // ranges for extreme values
            double incomePower     = Global.Configuration.Coefficients_CostCoefficientIncomePower_Work;
            double costCoefficient = Global.Coefficients_BaseCostCoefficientPerMonetaryUnit / Math.Pow(incomeMultiple, incomePower);
            double votValue        = (60.0 * Global.Configuration.Coefficients_MeanTimeCoefficient_Work) / costCoefficient; // in $/hour

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

            int hhsize = householdDay.Household.Size;

            int[]            pUsualLocationParcelId = new int[6];
            int[]            pUsualLocationZoneId   = new int[6];
            IParcelWrapper[] pUsualLocationParcel   = new IParcelWrapper[6];
            int[]            pPatternType           = new int[6];
            int[]            pConstant = new int[6];
            int[]            pType8    = new int[6];
            int[]            pType7    = new int[6];
            int[]            pType6    = new int[6];
            int[]            pType5    = new int[6];
            int[]            pType4    = new int[6];
            int[]            pType3    = new int[6];
            int[]            pType2    = new int[6];
            int[]            pType1    = new int[6];
            int[]            pAdult    = new int[6];
            int[]            pAdultWithChildrenUnder16 = new int[6];
            int[]            pAdultFemale     = new int[6];
            int[]            pType7AgeUnder12 = new int[6];
            int[]            pType7Age12Plus  = new int[6];
            int[]            pAgeUnder12      = new int[6];
            int[]            pAge5To8         = new int[6];
            int[]            pAge9To12        = new int[6];
            int[]            pAge13To15       = new int[6];
            int[]            pAge             = new int[6];
            int[]            pDrivingAge      = new int[6];

            int count = 0;

            foreach (PersonDayWrapper personDay in orderedPersonDays)
            {
                count++;
                if (count <= 5)
                {
                    // set characteristics here that depend on person characteristics
                    if (personDay.Person.IsFullOrPartTimeWorker && personDay.Person.UsualWorkParcel != null)
                    {
                        pUsualLocationParcelId[count] = personDay.Person.UsualWorkParcelId;
                        pUsualLocationParcel[count]   = personDay.Person.UsualWorkParcel;
                        pUsualLocationZoneId[count]   = personDay.Person.UsualWorkParcel.ZoneId;
                    }
                    else if (personDay.Person.IsStudent && personDay.Person.UsualSchoolParcel != null)
                    {
                        pUsualLocationParcelId[count] = personDay.Person.UsualSchoolParcelId;
                        pUsualLocationParcel[count]   = personDay.Person.UsualSchoolParcel;
                        pUsualLocationZoneId[count]   = personDay.Person.UsualSchoolParcel.ZoneId;
                    }
                    else if (personDay.Person.IsWorker && personDay.Person.IsNotFullOrPartTimeWorker && personDay.Person.UsualWorkParcel != null)
                    {
                        pUsualLocationParcelId[count] = personDay.Person.UsualWorkParcelId;
                        pUsualLocationParcel[count]   = personDay.Person.UsualWorkParcel;
                        pUsualLocationZoneId[count]   = personDay.Person.UsualWorkParcel.ZoneId;
                    }
                    else
                    {
                        pUsualLocationParcelId[count] = personDay.Household.ResidenceParcelId;
                        pUsualLocationParcel[count]   = personDay.Household.ResidenceParcel;
                        pUsualLocationZoneId[count]   = personDay.Household.ResidenceZoneId;
                    }

                    pPatternType[count] = personDay.PatternType;
                    pConstant[count]    = 1;
                    pType8[count]       = personDay.Person.IsChildUnder5.ToFlag();
                    pType7[count]       = personDay.Person.IsChildAge5Through15.ToFlag();
                    pType6[count]       = personDay.Person.IsDrivingAgeStudent.ToFlag();
                    pType5[count]       = personDay.Person.IsUniversityStudent.ToFlag();
                    pType4[count]       = personDay.Person.IsNonworkingAdult.ToFlag();
                    pType3[count]       = personDay.Person.IsRetiredAdult.ToFlag();
                    pType2[count]       = personDay.Person.IsPartTimeWorker.ToFlag();
                    pType1[count]       = personDay.Person.IsFulltimeWorker.ToFlag();
                    pAdult[count]       = personDay.Person.IsAdult.ToFlag();
                    pAdultWithChildrenUnder16[count] = (personDay.Person.IsAdult && personDay.Household.HasChildrenUnder16).ToFlag();
                    pAdultFemale[count]     = personDay.Person.IsAdultFemale.ToFlag();
                    pType7AgeUnder12[count] = (personDay.Person.IsChildAge5Through15 && personDay.Person.Age < 12).ToFlag();
                    pType7Age12Plus[count]  = (personDay.Person.IsChildAge5Through15 && personDay.Person.Age >= 12).ToFlag();
                    pAgeUnder12[count]      = (personDay.Person.Age < 12).ToFlag();
                    pAge5To8[count]         = (personDay.Person.Age >= 5 && personDay.Person.Age <= 8).ToFlag();
                    pAge9To12[count]        = (personDay.Person.Age >= 9 && personDay.Person.Age <= 12).ToFlag();
                    pAge13To15[count]       = (personDay.Person.Age >= 13 && personDay.Person.Age <= 15).ToFlag();
                    pAge[count]             = personDay.Person.Age;
                    pDrivingAge[count]      = personDay.Person.IsDrivingAge.ToFlag();
                }
            }

            // set household characteristics here that do depend on person characteristics
            //bool partTimeWorkerIsAvailable = false;
            //for (int i = 1; i <= 5; i++) {
            //    if (pType2[i] == 1 && pPatternType[i] == Constants.PatternType.MANDATORY && pHTAvailable[i] == true)
            //        partTimeWorkerIsAvailable = true;
            //
            //}

            // set person characteristics here that depend on household characteristics
            //int[] pFullTimeWorkerButPartTimeWorkerIsAvailable = new int[6];
            //for (int i = 1; i <= 5; i++) {
            //    if (pType1[i] == 1 && partTimeWorkerIsAvailable) {
            //        pFullTimeWorkerButPartTimeWorkerIsAvailable[i] = 1;
            //    }
            //}

            int componentIndex = 0;

            //Create person utility components
            int[] componentPerson = new int[6];
            for (int p = 1; p <= 5; p++)
            {
                // create component for basic person-purposes
                componentIndex++;
                componentPerson[p] = componentIndex;
                choiceProbabilityCalculator.CreateUtilityComponent(componentPerson[p]);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(01, pType1[p]);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(02, pType2[p]);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(03, pType3[p]);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(04, pType4[p]);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(05, pType5[p]);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(06, pType6[p]);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(07, pType7[p]);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(08, pType8[p]);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(09, pAge5To8[p]);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(10, pAge9To12[p]);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(11, pAdultFemale[p]);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(12, pType1[p] * firstHalfTour);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(13, pType1[p] * secondHalfTour);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(14, pType2[p] * firstHalfTour);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(15, pType2[p] * secondHalfTour);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(16, (1 - pAdult[p]) * firstHalfTour);
                choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(17, (1 - pAdult[p]) * secondHalfTour);
                //choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]).AddUtilityTerm(18, pFullTimeWorkerButPartTimeWorkerIsAvailable[p]);
            }

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

            double distanceInMiles          = 0;
            double inverseOfDistanceInMiles = 0;
            double logAgeDiffAdult          = 0;
            double logAgeDiffChild          = 0;

            for (int t2 = 1; t2 <= 5; t2++)
            {
                for (int t1 = 1; t1 < t2; t1++)
                {
                    //populate match variables
                    iMatchAgeUnder12 = pAgeUnder12[t1] * pAgeUnder12[t2];
                    iMatchAdult      = pAdult[t1] * pAdult[t2];
                    iMatchAdultWithChildrenUnder16 = pAdultWithChildrenUnder16[t1] * pAdultWithChildrenUnder16[t2];

                    logAgeDiffChild = Math.Log(1 + Math.Abs(pAge[t1] - pAge[t2])) * (pAge[t1] <= 18).ToFlag() * (pAge[t2] <= 18).ToFlag();
                    logAgeDiffAdult = Math.Log(1 + Math.Abs(pAge[t1] - pAge[t2])) * (pAge[t1] >= 18).ToFlag() * (pAge[t2] >= 18).ToFlag();

                    distanceInMiles          = 0;
                    inverseOfDistanceInMiles = 0;
                    if (pPatternType[t1] > 0 && pPatternType[t2] > 0)
                    {
                        double zzDist           = ImpedanceRoster.GetValue("distance", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, votValue, Global.Settings.Times.EightAM, pUsualLocationZoneId[t1], pUsualLocationZoneId[t2]).Variable;
                        double circuityDistance =
                            (zzDist > Global.Configuration.MaximumBlendingDistance || Global.Configuration.DestinationScale != Global.Settings.DestinationScales.Parcel)
                                ? pUsualLocationParcel[t1].CalculateShortDistance(pUsualLocationParcel[t2], /* doNewCorrections */ false)
                                : Constants.DEFAULT_VALUE;
                        SkimValue skimValue =
                            Global.Configuration.DestinationScale != Global.Settings.DestinationScales.Parcel
                                ? ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, votValue, Global.Settings.Times.EightAM, pUsualLocationZoneId[t1], pUsualLocationZoneId[t2])
                                : ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, votValue, Global.Settings.Times.EightAM, pUsualLocationParcel[t1], pUsualLocationParcel[t2], circuityDistance);
                        distanceInMiles          = skimValue.BlendVariable;
                        inverseOfDistanceInMiles = 1 / (Math.Max(0.1, distanceInMiles));
                    }

                    //create and populate components
                    componentIndex++;
                    componentMatch[t1, t2] = componentIndex;
                    choiceProbabilityCalculator.CreateUtilityComponent(componentMatch[t1, t2]);
                    choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(21, iMatchAdultWithChildrenUnder16);
                    choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(22, inverseOfDistanceInMiles);
                    choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(23, logAgeDiffChild);
                    choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]).AddUtilityTerm(24, logAgeDiffAdult);
                }
            }

            //create two-way cross interaction utility components
            int[,] componentCross = new int[6, 6];
            int iCrossAgeUnderTwelveAndAdult = 0;

            //int iCrossAge13To15AndAdultFemale = 0;
            //int iCrossAge9To12AndAdultFemale = 0;
            //int iCrossAge5To8AndAdultFemale = 0;
            //int iCrossAgeUnder5AndAdultFemale = 0;
            //int iCrossAgeUnder5AndFTWorker = 0;
            for (int t2 = 1; t2 <= 5; t2++)
            {
                for (int t1 = 1; t1 <= 5; t1++)
                {
                    if (!(t1 == t2))
                    {
                        //populate cross variables
                        iCrossAgeUnderTwelveAndAdult = pAgeUnder12[t1] * pAdult[t2];
                        //iCrossAge13To15AndAdultFemale = pAge13To15[t1] * pAdultFemale[t2];
                        //iCrossAge9To12AndAdultFemale = pAge9To12[t1] * pAdultFemale[t2];
                        //iCrossAge5To8AndAdultFemale = pAge5To8[t1] * pAdultFemale[t2];
                        //iCrossAgeUnder5AndAdultFemale = pType8[t1] * pAdultFemale[t2];
                        //iCrossAgeUnder5AndFTWorker = pType8[t1] * pType1[t2];

                        //create and populate cross components
                        componentIndex++;
                        componentCross[t1, t2] = componentIndex;
                        choiceProbabilityCalculator.CreateUtilityComponent(componentCross[t1, t2]);
                        choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(41, iCrossAgeUnderTwelveAndAdult);
                        //choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(42, iCrossAge13To15AndAdultFemale);
                        //choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(43, iCrossAge9To12AndAdultFemale);
                        //choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(44, iCrossAge5To8AndAdultFemale);
                        //choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(45, iCrossAgeUnder5AndAdultFemale);
                        //choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]).AddUtilityTerm(46, iCrossAgeUnder5AndFTWorker);
                    }
                }
            }

            //Generate utility funtions for the alternatives
            bool[] available = new bool[32];
            bool[] chosen    = new bool[32];
            for (int alt = 0; alt < 32; alt++)
            {
                available[alt] = false;
                chosen[alt]    = false;
                // set availability based on household size
                if (hhsize >= altParticipants[alt][6])
                {
                    available[alt] = true;
                }
                // restrict availability based on person unavailability
                for (int i = 1; i <= 5; i++)
                {
                    if (altParticipants[alt][i] == 1 && (jHTAvailable[genChoice - 1, i] == false || pHTAvailable[i] == false))
                    {
                        available[alt] = false;
                    }
                }
                // restrict availability if nobody is an driving age
                bool altHasDrivingAge = false;
                for (int i = 1; i <= 5; i++)
                {
                    if (altParticipants[alt][i] == 1 && pDrivingAge[i] > 0)
                    {
                        altHasDrivingAge = true;
                    }
                }
                if (!altHasDrivingAge)
                {
                    available[alt] = false;
                }
                // restrict availability if anybody has nonMandatory pattern type
                bool altHasNonMandatoryPatternType = false;
                for (int i = 1; i <= 5; i++)
                {
                    if (altParticipants[alt][i] == 1 && !(pPatternType[i] == Global.Settings.PatternTypes.Mandatory))
                    {
                        altHasNonMandatoryPatternType = true;
                    }
                }
                if (altHasNonMandatoryPatternType)
                {
                    available[alt] = false;
                }
                // restrict availability of alts that include less than 2 participants
                if (altParticipants[alt][7] < 2)
                {
                    available[alt] = false;
                }

                //Generate alt-specific variables
                int numberOfParticipatingAdults   = 0;
                int numberOfParticipatingChildren = 0;
                //bool includesAllMandatoryPatternPersons = true;
                if (available[alt] == true)
                {
                    for (int i = 1; i <= 5; i++)
                    {
                        if (altParticipants[alt][i] == 1)
                        {
                            //                                totalParticipants++;
                            if (pAdult[i] == 1)
                            {
                                numberOfParticipatingAdults++;
                            }
                            if (pAdult[i] == 0)
                            {
                                numberOfParticipatingChildren++;
                            }
                        }
                        //else if (pPatternType[i] == Constants.PatternType.MANDATORY && pHTAvailable[i] == true) { includesAllMandatoryPatternPersons = false; }
                    }
                }


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

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

                alternative.Choice = alt;

                //Add alt-specific utility terms
                alternative.AddUtilityTerm(61, (numberOfParticipatingAdults > 1 && numberOfParticipatingChildren > 0) ? 1 : 0);
                //alternative.AddUtilityTerm(62, includesAllMandatoryPatternPersons.ToFlag());

                //Add utility components

                for (int p = 1; p <= 5; p++)
                {
                    if (altParticipants[alt][p] == 1)
                    {
                        alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(componentPerson[p]));
                    }
                }
                for (int t2 = 1; t2 <= 5; t2++)
                {
                    for (int t1 = 1; t1 < t2; t1++)
                    {
                        if (altParticipants[alt][t1] == 1 && altParticipants[alt][t2] == 1)
                        {
                            alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(componentMatch[t1, t2]));
                        }
                    }
                }
                for (int t2 = 1; t2 <= 5; t2++)
                {
                    for (int t1 = 1; t1 <= 5; t1++)
                    {
                        if (!(t1 == t2))
                        {
                            if (altParticipants[alt][t1] == 1 && altParticipants[alt][t2] == 1)
                            {
                                alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(componentCross[t1, t2]));
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 23
0
 public HTourDestinationModeTime(IParcelWrapper destination, HTourModeTime modeTimes)
 {
     Destination = destination;
     ModeTimes   = modeTimes;
 }
Exemplo n.º 24
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, TripWrapper trip,
                              IEnumerable <IPathTypeModel> pathTypeModels, IParcelWrapper originParcel,
                              IParcelWrapper destinationParcel,
                              int choice = Constants.DEFAULT_VALUE)
        {
            IHouseholdWrapper household = trip.Household;

            Framework.DomainModels.Models.IHouseholdTotals householdTotals = household.HouseholdTotals;
            IPersonWrapper person = trip.Person;
            ITourWrapper   tour   = trip.Tour;

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

            // household inputs
            int onePersonHouseholdFlag  = household.IsOnePersonHousehold.ToFlag();
            int HHwithChildrenFlag      = household.HasChildren.ToFlag();
            int HHwithSmallChildrenFlag = household.HasChildrenUnder5.ToFlag();
            int childrenAge5Through15   = householdTotals.ChildrenAge5Through15;
            int HHwithLowIncomeFlag     = (household.Income >= 300000 && household.Income < 600000).ToFlag();
            int HHwithMidleIncomeFlag   = (household.Income >= 600000 && household.Income < 900000).ToFlag();
            int HHwithHighIncomeFlag    = (household.Income >= 900000).ToFlag();
            int nonworkingAdults        = householdTotals.NonworkingAdults;
            int retiredAdults           = householdTotals.RetiredAdults;
            int twoPersonHouseholdFlag  = household.IsTwoPersonHousehold.ToFlag();
            int noCarsInHouseholdFlag   = household.GetFlagForNoCarsInHousehold(household.VehiclesAvailable);
            int carsLessThanDriversFlag = household.GetFlagForCarsLessThanDrivers(household.VehiclesAvailable);

            // person inputs
            //var drivingAgeStudentFlag = person.IsDrivingAgeStudent.ToFlag();
            int maleFlag   = person.IsMale.ToFlag();
            int femaleFlag = person.IsFemale.ToFlag();

            int PTpass = person.TransitPassOwnership;

            //var ageLessThan35Flag = person.AgeIsLessThan35.ToFlag();

            // tour inputs
            int bikeTourFlag          = tour.IsBikeMode().ToFlag();
            int walkTourFlag          = tour.IsWalkMode().ToFlag();
            int CarDrivAloneFlag      = tour.IsSovMode().ToFlag();
            int CarDrivNotAloneFlag   = tour.IsHov2Mode().ToFlag();
            int CarPassengerFlag      = tour.IsHov3Mode().ToFlag();
            int transitTourFlag       = tour.IsTransitMode().ToFlag();
            int paidRideShareTourFlag = ((IActumTourWrapper)tour).IsPaidRideShareMode().ToFlag();

            int homeBasedWorkTourFlag                = (tour.IsHomeBasedTour && tour.IsWorkPurpose()).ToFlag();
            int homeBasedSchoolTourFlag              = (tour.IsHomeBasedTour && tour.IsSchoolPurpose()).ToFlag();
            int homeBasedEscortTourFlag              = (tour.IsHomeBasedTour && tour.IsEscortPurpose()).ToFlag();
            int homeBasedShoppingTourFlag            = (tour.IsHomeBasedTour && tour.IsShoppingPurpose()).ToFlag();
            int homeBasedSocialTourFlag              = (tour.IsHomeBasedTour && tour.IsSocialPurpose()).ToFlag();
            int notHomeBasedTourFlag                 = (!tour.IsHomeBasedTour).ToFlag();
            int homeBasedNotWorkSchoolEscortTourFlag =
                (tour.IsHomeBasedTour && tour.DestinationPurpose > Global.Settings.Purposes.Escort).ToFlag();

            int jointTourFlag       = (tour.JointTourSequence > 0) ? 1 : 0;
            int partialHalfTourFlag = (trip.IsHalfTourFromOrigin
                                                    ? tour.PartialHalfTour1Sequence > 0
                                                    : tour.PartialHalfTour2Sequence > 0)
                                                  ? 1
                                                  : 0;
            int fullHalfTourFlag = (trip.IsHalfTourFromOrigin ? tour.FullHalfTour1Sequence > 0 : tour.FullHalfTour2Sequence > 0)
                                              ? 1
                                              : 0;


            // trip inputs
            int originHomeEscortFlag = (trip.IsNoneOrHomePurposeByOrigin() && trip.IsEscortPurposeByDestination()).ToFlag();
            int originWorkEscortFlag = (trip.IsWorkPurposeByOrigin() && trip.IsEscortPurposeByDestination()).ToFlag();

            int destinationHomeEscortFlag = (trip.IsNoneOrHomePurposeByDestination() && trip.IsEscortPurposeByOrigin()).ToFlag();
            int destinationWorkEscortFlag = (trip.IsWorkPurposeByDestination() && trip.IsEscortPurposeByOrigin()).ToFlag();

            // only trip on first half-tour
            int onlyTripOnFirstHalfFlag =
                (trip.IsHalfTourFromOrigin && halfTour.SimulatedTrips == 1 && trip.IsToTourOrigin).ToFlag();

            // first trip on first half-tour, not only one
            int firstTripOnFirstHalfFlag =
                (trip.IsHalfTourFromOrigin && halfTour.SimulatedTrips == 1 && !trip.IsToTourOrigin).ToFlag();

            // last trip first half-tour, not only one
            int lastTripOnFirstHalfFlag =
                (trip.IsHalfTourFromOrigin && halfTour.SimulatedTrips > 1 && trip.IsToTourOrigin).ToFlag();

            // only trip on second half-tour
            int onlyTripOnSecondHalfFlag =
                (!trip.IsHalfTourFromOrigin && halfTour.SimulatedTrips == 1 && trip.IsToTourOrigin).ToFlag();

            // first trip on second half-tour, not only one
            int firstTripOnSecondHalfFlag =
                (!trip.IsHalfTourFromOrigin && halfTour.SimulatedTrips == 1 && !trip.IsToTourOrigin).ToFlag();

            // last trip second half-tour, not only one
            int lastTripOnSecondHalfFlag =
                (!trip.IsHalfTourFromOrigin && halfTour.SimulatedTrips > 1 && trip.IsToTourOrigin).ToFlag();

            // remaining inputs
            int departureTime = trip.IsHalfTourFromOrigin ? trip.LatestDepartureTime : trip.EarliestDepartureTime;

            double originMixedDensity        = originParcel.MixedUse4Index1();
            double originIntersectionDensity = originParcel.NetIntersectionDensity1();
            double destinationParkingCost    = destinationParcel.ParkingCostBuffer1(2);
            int    amPeriodFlag = departureTime.IsLeftExclusiveBetween(Global.Settings.Times.SixAM, Global.Settings.Times.NineAM).ToFlag();
            //GV changed to 6-9 am
            int middayPeriodFlag = departureTime.IsLeftExclusiveBetween(Global.Settings.Times.NineAM, Global.Settings.Times.ThreePM).ToFlag();
            int pmPeriodFlag     = departureTime.IsLeftExclusiveBetween(Global.Settings.Times.ThreePM, Global.Settings.Times.SixPM).ToFlag();
            //GV changed to 3-6 pm
            int eveningPeriodFlag = (departureTime > Global.Settings.Times.SixPM).ToFlag(); //GV changed to 6 pm

            // availability
            bool[] tripModeAvailable = new bool[Global.Settings.Modes.TotalModes];

            bool isLastTripInTour = (!trip.IsHalfTourFromOrigin && halfTour.SimulatedTrips >= 1 && trip.IsToTourOrigin);
            int  frequencyPreviousTripModeIsTourMode = 0;

            if (trip.IsHalfTourFromOrigin)
            {
                frequencyPreviousTripModeIsTourMode +=
                    tour.HalfTourFromOrigin.Trips.Where(x => x.Sequence < trip.Sequence).Count(x => tour.Mode == x.Mode);
            }
            else
            {
                if (tour.HalfTourFromOrigin != null)
                {
                    frequencyPreviousTripModeIsTourMode +=
                        tour.HalfTourFromOrigin.Trips.Where(x => x.Sequence > 0).Count(x => tour.Mode == x.Mode);
                }
                frequencyPreviousTripModeIsTourMode +=
                    tour.HalfTourFromDestination.Trips.Where(x => x.Sequence < trip.Sequence).Count(x => tour.Mode == x.Mode);
            }

            // GV commented out park and ride for COMPAS1; JOHN restored it for COMPAS2
            //// if a park and ride tour, only car is available
            if (tour.Mode == Global.Settings.Modes.ParkAndRide)
            {
                tripModeAvailable[Global.Settings.Modes.Sov]          = tour.Household.VehiclesAvailable > 0 && person.Age >= 18;
                tripModeAvailable[Global.Settings.Modes.HovDriver]    = tour.Household.VehiclesAvailable > 0 && person.Age >= 18;
                tripModeAvailable[Global.Settings.Modes.HovPassenger] = !tripModeAvailable[Global.Settings.Modes.Sov];
            }
            //// if the last trip of the tour and tour mode not yet used, only the tour mode is available
            else if (isLastTripInTour && frequencyPreviousTripModeIsTourMode == 0)
            {
                tripModeAvailable[tour.Mode] = true;
            }
            else
            {
                // set availability based on tour mode
                for (int mode = Global.Settings.Modes.Walk; mode <= tour.Mode; mode++)
                {
                    tripModeAvailable[mode] = true;
                }
            }
            if (person.Age < 18)
            {
                tripModeAvailable[Global.Settings.Modes.Sov]       = false;
                tripModeAvailable[Global.Settings.Modes.HovDriver] = false;
            }

            // GV commented out School Bus
            // school bus is a special case - use HOV3 impedance and only available for school bus tours
            //var pathTypeExtra = pathTypeModels.First(x => x.Mode == Global.Settings.Modes.Hov3);
            //const int modeExtra = Global.Settings.Modes.SchoolBus;
            //var availableExtra = pathTypeExtra.Available && tour.IsSchoolBusMode && tripModeAvailable[modeExtra]
            //	 && (trip.IsHalfTourFromOrigin
            //		  ? trip.LatestDepartureTime - pathTypeExtra.PathTime >= trip.ArrivalTimeLimit
            //		  : trip.EarliestDepartureTime + pathTypeExtra.PathTime <= trip.ArrivalTimeLimit);
            //var generalizedTimeLogsumExtra = pathTypeExtra.GeneralizedTimeLogsum;

            //var alternative = choiceProbabilityCalculator.GetAlternative(modeExtra, availableExtra, choice == modeExtra);
            //alternative.Choice = modeExtra;

            //alternative.AddNestedAlternative(_nestedAlternativeIds[modeExtra], _nestedAlternativeIndexes[modeExtra], THETA_PARAMETER);
            //
            //if (availableExtra) {
            //	//	case Global.Settings.Modes.SchoolBus:
            //	alternative.AddUtilityTerm(2, generalizedTimeLogsumExtra * tour.TimeCoefficient);
            //	alternative.AddUtilityTerm(18, 1);
            //	alternative.AddUtilityTerm(100, schoolBusTourFlag);
            //	alternative.AddUtilityTerm(102, (schoolBusTourFlag * onlyTripOnFirstHalfFlag));
            //	alternative.AddUtilityTerm(103, (schoolBusTourFlag * onlyTripOnSecondHalfFlag));
            //	alternative.AddUtilityTerm(104, (schoolBusTourFlag * firstTripOnFirstHalfFlag));
            //	alternative.AddUtilityTerm(105, (schoolBusTourFlag * firstTripOnSecondHalfFlag));
            //	alternative.AddUtilityTerm(106, (schoolBusTourFlag * lastTripOnFirstHalfFlag));
            //	alternative.AddUtilityTerm(107, (schoolBusTourFlag * lastTripOnSecondHalfFlag));
            //	alternative.AddUtilityTerm(112, parkAndRideTourFlag);
            //	alternative.AddUtilityTerm(113, transitTourFlag);
            //}

            ChoiceProbabilityCalculator.Alternative alternative;

            foreach (IPathTypeModel pathTypeModel in pathTypeModels)
            {
                int  mode      = pathTypeModel.Mode;
                bool available = pathTypeModel.Available && tripModeAvailable[mode] &&
                                 (trip.IsHalfTourFromOrigin
                                      ? trip.LatestDepartureTime - pathTypeModel.PathTime >= trip.ArrivalTimeLimit
                                      : trip.EarliestDepartureTime + pathTypeModel.PathTime <= trip.ArrivalTimeLimit);
                double generalizedTimeLogsum = pathTypeModel.GeneralizedTimeLogsum;

                alternative        = choiceProbabilityCalculator.GetAlternative(mode - 1, available, choice == mode);
                alternative.Choice = mode;

                // GV for tree Logit uncomment this
                alternative.AddNestedAlternative(_nestedAlternativeIds[mode], _nestedAlternativeIndexes[mode], THETA_PARAMETER);

                if (!available)
                {
                    continue;
                }

                alternative.AddUtilityTerm(2, generalizedTimeLogsum * tour.TimeCoefficient);

                if (mode == Global.Settings.Modes.Transit)
                {
                    alternative.AddUtilityTerm(20, 1);
                    alternative.AddUtilityTerm(22, carsLessThanDriversFlag);

                    //GV: income is not sign. 22. june 2016
                    //alternative.AddUtilityTerm(54, HHwithLowIncomeFlag);
                    //alternative.AddUtilityTerm(55, HHwithMidleIncomeFlag);
                    //alternative.AddUtilityTerm(56, HHwithHighIncomeFlag);

                    alternative.AddUtilityTerm(57, PTpass);

                    alternative.AddUtilityTerm(100, transitTourFlag);
                    alternative.AddUtilityTerm(102, (transitTourFlag * onlyTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(103, (transitTourFlag * onlyTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(104, (transitTourFlag * firstTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(105, (transitTourFlag * firstTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(106, (transitTourFlag * lastTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(107, (transitTourFlag * lastTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(181, jointTourFlag);
                    alternative.AddUtilityTerm(182, fullHalfTourFlag + partialHalfTourFlag);
                }
                else if (mode == Global.Settings.Modes.HovPassenger)
                {
                    alternative.AddUtilityTerm(30, 1);
                    alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / ChoiceModelUtility.CPFACT3));
                    alternative.AddUtilityTerm(32, childrenAge5Through15);
                    alternative.AddUtilityTerm(33, femaleFlag);
                    alternative.AddUtilityTerm(34, (nonworkingAdults + retiredAdults));
                    alternative.AddUtilityTerm(36, onePersonHouseholdFlag);
                    alternative.AddUtilityTerm(37, twoPersonHouseholdFlag);
                    alternative.AddUtilityTerm(41, noCarsInHouseholdFlag);
                    alternative.AddUtilityTerm(100, CarPassengerFlag);
                    alternative.AddUtilityTerm(102, (CarPassengerFlag * onlyTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(103, (CarPassengerFlag * onlyTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(104, (CarPassengerFlag * firstTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(105, (CarPassengerFlag * firstTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(106, (CarPassengerFlag * lastTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(107, (CarPassengerFlag * lastTripOnSecondHalfFlag));

                    alternative.AddUtilityTerm(115, transitTourFlag);

                    alternative.AddUtilityTerm(149, homeBasedWorkTourFlag);
                    alternative.AddUtilityTerm(150, homeBasedSchoolTourFlag);
                    alternative.AddUtilityTerm(152, homeBasedEscortTourFlag);
                    alternative.AddUtilityTerm(153, homeBasedShoppingTourFlag);
                    alternative.AddUtilityTerm(155, homeBasedSocialTourFlag);

                    alternative.AddUtilityTerm(161, (destinationWorkEscortFlag * amPeriodFlag));
                    alternative.AddUtilityTerm(162, (originWorkEscortFlag * pmPeriodFlag));
                    alternative.AddUtilityTerm(163, (originHomeEscortFlag * amPeriodFlag));
                    alternative.AddUtilityTerm(164, (originHomeEscortFlag * middayPeriodFlag));
                    alternative.AddUtilityTerm(165, (originHomeEscortFlag * pmPeriodFlag));
                    alternative.AddUtilityTerm(166, (originHomeEscortFlag * eveningPeriodFlag));
                    alternative.AddUtilityTerm(167, (destinationHomeEscortFlag * amPeriodFlag));
                    alternative.AddUtilityTerm(168, (destinationHomeEscortFlag * middayPeriodFlag));
                    alternative.AddUtilityTerm(169, (destinationHomeEscortFlag * pmPeriodFlag));
                    alternative.AddUtilityTerm(170, (destinationHomeEscortFlag * eveningPeriodFlag));
                    alternative.AddUtilityTerm(183, jointTourFlag);
                    alternative.AddUtilityTerm(184, fullHalfTourFlag + partialHalfTourFlag);
                }
                else if (mode == Global.Settings.Modes.HovDriver)
                {
                    alternative.AddUtilityTerm(40, 1);
                    alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / ChoiceModelUtility.CPFACT2));
                    alternative.AddUtilityTerm(42, (childrenAge5Through15 * (1 - homeBasedEscortTourFlag)));
                    alternative.AddUtilityTerm(43, (femaleFlag * (1 - homeBasedEscortTourFlag)));
                    alternative.AddUtilityTerm(44, ((nonworkingAdults + retiredAdults) * (1 - homeBasedEscortTourFlag)));
                    alternative.AddUtilityTerm(38, onePersonHouseholdFlag);
                    alternative.AddUtilityTerm(41, noCarsInHouseholdFlag);
                    alternative.AddUtilityTerm(100, CarDrivNotAloneFlag);
                    alternative.AddUtilityTerm(102, (CarDrivNotAloneFlag * onlyTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(103, (CarDrivNotAloneFlag * onlyTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(104, (CarDrivNotAloneFlag * firstTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(105, (CarDrivNotAloneFlag * firstTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(106, (CarDrivNotAloneFlag * lastTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(107, (CarDrivNotAloneFlag * lastTripOnSecondHalfFlag));

                    alternative.AddUtilityTerm(118, transitTourFlag);
                    alternative.AddUtilityTerm(120, CarPassengerFlag);

                    alternative.AddUtilityTerm(149, homeBasedWorkTourFlag);
                    alternative.AddUtilityTerm(150, homeBasedSchoolTourFlag);
                    alternative.AddUtilityTerm(152, homeBasedEscortTourFlag);
                    alternative.AddUtilityTerm(153, homeBasedShoppingTourFlag);
                    alternative.AddUtilityTerm(155, homeBasedSocialTourFlag);

                    alternative.AddUtilityTerm(161, (destinationWorkEscortFlag * amPeriodFlag));
                    alternative.AddUtilityTerm(162, (originWorkEscortFlag * pmPeriodFlag));
                    alternative.AddUtilityTerm(163, (originHomeEscortFlag * amPeriodFlag));
                    alternative.AddUtilityTerm(164, (originHomeEscortFlag * middayPeriodFlag));
                    alternative.AddUtilityTerm(165, (originHomeEscortFlag * pmPeriodFlag));
                    alternative.AddUtilityTerm(166, (originHomeEscortFlag * eveningPeriodFlag));
                    alternative.AddUtilityTerm(167, (destinationHomeEscortFlag * amPeriodFlag));
                    alternative.AddUtilityTerm(168, (destinationHomeEscortFlag * middayPeriodFlag));
                    alternative.AddUtilityTerm(169, (destinationHomeEscortFlag * pmPeriodFlag));
                    alternative.AddUtilityTerm(170, (destinationHomeEscortFlag * eveningPeriodFlag));
                }
                else if (mode == Global.Settings.Modes.Sov)
                {
                    alternative.AddUtilityTerm(50, 1);
                    alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient));
                    alternative.AddUtilityTerm(52, carsLessThanDriversFlag);

                    alternative.AddUtilityTerm(100, CarDrivAloneFlag);
                    alternative.AddUtilityTerm(102, (CarDrivAloneFlag * onlyTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(103, (CarDrivAloneFlag * onlyTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(104, (CarDrivAloneFlag * firstTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(105, (CarDrivAloneFlag * firstTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(106, (CarDrivAloneFlag * lastTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(107, (CarDrivAloneFlag * lastTripOnSecondHalfFlag));

                    alternative.AddUtilityTerm(122, transitTourFlag);
                    alternative.AddUtilityTerm(124, CarPassengerFlag);
                    alternative.AddUtilityTerm(125, CarDrivNotAloneFlag);

                    alternative.AddUtilityTerm(126, maleFlag);

                    alternative.AddUtilityTerm(185, jointTourFlag);
                    alternative.AddUtilityTerm(186, fullHalfTourFlag + partialHalfTourFlag);
                }
                else if (mode == Global.Settings.Modes.Bike)
                {
                    alternative.AddUtilityTerm(60, 1);
                    //alternative.AddUtilityTerm(65, originIntersectionDensity);

                    alternative.AddUtilityTerm(100, bikeTourFlag);
                    alternative.AddUtilityTerm(102, (bikeTourFlag * onlyTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(103, (bikeTourFlag * onlyTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(104, (bikeTourFlag * firstTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(105, (bikeTourFlag * firstTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(106, (bikeTourFlag * lastTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(107, (bikeTourFlag * lastTripOnSecondHalfFlag));

                    alternative.AddUtilityTerm(127, transitTourFlag);
                    alternative.AddUtilityTerm(130, CarDrivNotAloneFlag);
                    alternative.AddUtilityTerm(131, CarDrivAloneFlag);

                    alternative.AddUtilityTerm(132, maleFlag);

                    alternative.AddUtilityTerm(147, notHomeBasedTourFlag);
                    alternative.AddUtilityTerm(187, jointTourFlag);
                    alternative.AddUtilityTerm(188, fullHalfTourFlag + partialHalfTourFlag);
                }
                else if (mode == Global.Settings.Modes.Walk)
                {
                    alternative.AddUtilityTerm(70, 1);

                    //alternative.AddUtilityTerm(75, originIntersectionDensity);
                    alternative.AddUtilityTerm(78, originMixedDensity);
                    // origin and destination mixed use measures - geometric avg. - half mile from cell, in 1000s

                    alternative.AddUtilityTerm(100, walkTourFlag);
                    alternative.AddUtilityTerm(102, (walkTourFlag * onlyTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(103, (walkTourFlag * onlyTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(104, (walkTourFlag * firstTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(105, (walkTourFlag * firstTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(106, (walkTourFlag * lastTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(107, (walkTourFlag * lastTripOnSecondHalfFlag));

                    alternative.AddUtilityTerm(141, homeBasedWorkTourFlag);
                    alternative.AddUtilityTerm(142, homeBasedSchoolTourFlag);

                    alternative.AddUtilityTerm(187, jointTourFlag);
                    alternative.AddUtilityTerm(188, fullHalfTourFlag + partialHalfTourFlag);
                }
                else if (mode == Global.Settings.Modes.PaidRideShare)
                {
                    double modeConstant = Global.Configuration.AV_PaidRideShareModeUsesAVs
                     ? Global.Configuration.AV_PaidRideShare_ModeConstant
                                          + Global.Configuration.AV_PaidRideShare_DensityCoefficient * Math.Min(originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2, 6000)
                                          + Global.Configuration.AV_PaidRideShare_AVOwnerCoefficient * (household.OwnsAutomatedVehicles > 0).ToFlag()
                     : Global.Configuration.PaidRideShare_ModeConstant
                                          + Global.Configuration.PaidRideShare_DensityCoefficient * Math.Min(originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2, 6000);

                    alternative.AddUtilityTerm(80, modeConstant);
                    alternative.AddUtilityTerm(80, Global.Configuration.PaidRideShare_Age26to35Coefficient * tour.Person.AgeIsBetween26And35.ToFlag());
                    alternative.AddUtilityTerm(80, Global.Configuration.PaidRideShare_Age18to25Coefficient * tour.Person.AgeIsBetween18And25.ToFlag());
                    alternative.AddUtilityTerm(80, Global.Configuration.PaidRideShare_AgeOver65Coefficient * (tour.Person.Age >= 65).ToFlag());

                    alternative.AddUtilityTerm(100, paidRideShareTourFlag);
                    alternative.AddUtilityTerm(102, (paidRideShareTourFlag * onlyTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(103, (paidRideShareTourFlag * onlyTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(104, (paidRideShareTourFlag * firstTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(105, (paidRideShareTourFlag * firstTripOnSecondHalfFlag));
                    alternative.AddUtilityTerm(106, (paidRideShareTourFlag * lastTripOnFirstHalfFlag));
                    alternative.AddUtilityTerm(107, (paidRideShareTourFlag * lastTripOnSecondHalfFlag));
                }
            }
        }
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, IHouseholdDayWrapper householdDay, ITourWrapper tour,
                              IParcelWrapper destinationParcel, int householdCars,
                              int constrainedMode, int constrainedArrivalTime, int constrainedDepartureTime, HTourModeTime choice = null)
        {
            IHouseholdWrapper household       = tour.Household;
            IPersonWrapper    person          = tour.Person;
            IPersonDayWrapper personDay       = tour.PersonDay;
            IHouseholdTotals  householdTotals = household.HouseholdTotals;

            // household inputs
            int childrenUnder5         = householdTotals.ChildrenUnder5;
            int childrenAge5Through15  = householdTotals.ChildrenAge5Through15;
            int nonworkingAdults       = householdTotals.NonworkingAdults;
            int retiredAdults          = householdTotals.RetiredAdults;
            int onePersonHouseholdFlag = household.IsOnePersonHousehold.ToFlag();
            int twoPersonHouseholdFlag = household.IsTwoPersonHousehold.ToFlag();
            //var householdCars = household.VehiclesAvailable; MABADD now an input parameter
            int noCarsInHouseholdFlag   = household.GetFlagForNoCarsInHousehold(householdCars);
            int carsLessThanDriversFlag = household.GetFlagForCarsLessThanDrivers(householdCars);
            int carsLessThanWorkersFlag = household.GetFlagForCarsLessThanWorkers(householdCars);
            int income0To25KFlag        = household.Has0To25KIncome.ToFlag();
            int income100KPlusFlag      = household.Has100KPlusIncome.ToFlag();

            // person inputs
            int partTimeWorkerFlag     = person.IsPartTimeWorker.ToFlag();
            int nonworkingAdultFlag    = person.IsNonworkingAdult.ToFlag();
            int universityStudentFlag  = person.IsUniversityStudent.ToFlag();
            int retiredAdultFlag       = person.IsRetiredAdult.ToFlag();
            int drivingAgeStudentFlag  = person.IsDrivingAgeStudent.ToFlag();
            int fulltimeWorkerFlag     = person.IsFulltimeWorker.ToFlag();
            int childAge5Through15Flag = person.IsChildAge5Through15.ToFlag();
            int childUnder5Flag        = person.IsChildUnder5.ToFlag();
            int maleFlag              = person.IsMale.ToFlag();
            int ageUnder30Flag        = person.AgeIsLessThan30.ToFlag();
            int ageBetween51And98Flag = person.AgeIsBetween51And98.ToFlag();
            int adultFlag             = person.IsAdult.ToFlag();

            // person-day inputs
            int homeBasedToursOnlyFlag          = (personDay == null) ? 1 : personDay.OnlyHomeBasedToursExist().ToFlag();
            int firstSimulatedHomeBasedTourFlag = (personDay == null) ? 1 : personDay.IsFirstSimulatedHomeBasedTour().ToFlag();
            int laterSimulatedHomeBasedTourFlag = (personDay == null) ? 0 : personDay.IsLaterSimulatedHomeBasedTour().ToFlag();
            int totalStops              = (personDay == null) ? 0 : personDay.GetTotalStops();
            int totalSimulatedStops     = (personDay == null) ? 0 : personDay.GetTotalSimulatedStops();
            int escortStops             = (personDay == null) ? 0 : personDay.EscortStops;
            int homeBasedTours          = (personDay == null) ? 1 : personDay.HomeBasedTours;
            int simulatedHomeBasedTours = (personDay == null) ? 0 : personDay.SimulatedHomeBasedTours;

            // tour inputs
            int            escortTourFlag           = tour.IsEscortPurpose().ToFlag();
            int            shoppingTourFlag         = tour.IsShoppingPurpose().ToFlag();
            int            mealTourFlag             = tour.IsMealPurpose().ToFlag();
            int            socialTourFlag           = tour.IsSocialPurpose().ToFlag();
            int            personalBusinessTourFlag = tour.IsPersonalBusinessPurpose().ToFlag();
            int            recreationTourFlag       = tour.IsRecreationPurpose().ToFlag();
            int            medicalTourFlag          = tour.IsMedicalPurpose().ToFlag();
            IParcelWrapper originParcel             = tour.OriginParcel;
            //var destinationParcel = tour.DestinationParcel; MABADD now an input parameter
            int  jointTourFlag        = (tour.JointTourSequence > 0) ? 1 : 0;
            int  partialHalfTour1Flag = (tour.PartialHalfTour1Sequence > 0) ? 1 : 0;
            int  partialHalfTour2Flag = (tour.PartialHalfTour2Sequence > 0) ? 1 : 0;
            bool partialHalfTour      = (tour.PartialHalfTour1Sequence > 0 || tour.PartialHalfTour2Sequence > 0);
            int  fullHalfTour1Flag    = (tour.FullHalfTour1Sequence > 0) ? 1 : 0;
            int  fullHalfTour2Flag    = (tour.FullHalfTour2Sequence > 0) ? 1 : 0;
            int  parentTourMode       = tour.ParentTour == null ? 0 : tour.ParentTour.Mode;


            // remaining inputs
            // Higher priority tour of 2+ tours for the same purpose
            int highPrioritySameFlag = (personDay == null) ? 1 : (tour.GetTotalToursByPurpose() > tour.GetTotalSimulatedToursByPurpose() && tour.GetTotalSimulatedToursByPurpose() == 1).ToFlag();

            // Lower priority tour(s) of 2+ tours for the same purpose
            int lowPrioritySameFlag = (personDay == null) ? 0 : (tour.GetTotalSimulatedToursByPurpose() > 1).ToFlag();

            // Higher priority tour of 2+ tours for different purposes
            int highPriorityDifferentFlag = (personDay == null) ? 0 : (personDay.IsFirstSimulatedHomeBasedTour() && personDay.HomeBasedToursExist()).ToFlag() * (1 - highPrioritySameFlag);

            // Lower priority tour of 2+ tours for different purposes
            int lowPriorityDifferentFlag = (personDay == null) ? 0 : (personDay.IsLaterSimulatedHomeBasedTour() && personDay.HomeBasedToursExist()).ToFlag() * (1 - lowPrioritySameFlag);


            ITimeWindow timeWindow = (householdDay == null) ? new TimeWindow() : tour.GetRelevantTimeWindow(householdDay);
            int         totalMinutesAvailableInDay = timeWindow.TotalAvailableMinutes(1, 1440);


            int bigPeriodCount = DayPeriod.H_BIG_DAY_PERIOD_TOTAL_TOUR_TIMES;
            int nPeriodCombs   = bigPeriodCount * (bigPeriodCount + 1) / 2;


            bool useTimeComponents = Global.Configuration.IsInEstimationMode || constrainedArrivalTime == 0 || constrainedDepartureTime == 0;
            int  componentIndex    = 0;
            int  periodComb        = -1;

            //set components
            if (useTimeComponents)
            {
                for (int arrivalPeriodIndex = 0; arrivalPeriodIndex < bigPeriodCount; arrivalPeriodIndex++)
                {
                    MinuteSpan arrivalPeriod = DayPeriod.HBigDayPeriods[arrivalPeriodIndex];
                    int        arrivalPeriodAvailableMinutes = timeWindow.TotalAvailableMinutes(arrivalPeriod.Start, arrivalPeriod.End);

                    for (int departurePeriodIndex = arrivalPeriodIndex; departurePeriodIndex < bigPeriodCount; departurePeriodIndex++)
                    {
                        MinuteSpan departurePeriod = DayPeriod.HBigDayPeriods[departurePeriodIndex];
                        int        departurePeriodAvailableMinutes = timeWindow.TotalAvailableMinutes(departurePeriod.Start, departurePeriod.End);

                        if (arrivalPeriod == departurePeriod)
                        {
                            componentIndex = arrivalPeriodIndex;
                            choiceProbabilityCalculator.CreateUtilityComponent(componentIndex);
                            ChoiceProbabilityCalculator.Component arrivalComponent = choiceProbabilityCalculator.GetUtilityComponent(componentIndex);

                            if (arrivalPeriodAvailableMinutes > 0)
                            {
                                double hoursArrival = arrivalPeriod.Middle / 60.0;
                                int    firstCoef    = 300;
                                arrivalComponent.AddUtilityTerm(300, Math.Log(arrivalPeriodAvailableMinutes));
                                //arrival shift variables
                                //arrivalComponent.AddUtilityTerm(firstCoef + 2, partTimeWorkerFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 3, nonworkingAdultFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 4, universityStudentFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 5, retiredAdultFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 6, drivingAgeStudentFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 7, childAge5Through15Flag * hoursArrival);
                                //arrivalComponent.AddUtilityTerm(firstCoef + 8, childUnder5Flag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 9, escortTourFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 10, shoppingTourFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 11, mealTourFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 12, socialTourFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 13, personalBusinessTourFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 14, recreationTourFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 15, medicalTourFlag * hoursArrival);
                                //arrivalComponent.AddUtilityTerm(firstCoef + 16, income0To25KFlag * hoursArrival);
                                //arrivalComponent.AddUtilityTerm(firstCoef + 17, income100KPlusFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 18, highPrioritySameFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 19, lowPrioritySameFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 20, highPriorityDifferentFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 21, lowPriorityDifferentFlag * hoursArrival);
                                arrivalComponent.AddUtilityTerm(firstCoef + 22, jointTourFlag * hoursArrival);
                                //arrivalComponent.AddUtilityTerm(firstCoef + 23, partialHalfTour1Flag * hoursArrival);
                                //arrivalComponent.AddUtilityTerm(firstCoef + 24, fullHalfTour1Flag * hoursArrival);
                                //arrivalComponent.AddUtilityTerm(firstCoef + 25, partialHalfTour2Flag * hoursArrival);
                                //arrivalComponent.AddUtilityTerm(firstCoef + 26, fullHalfTour2Flag * hoursArrival);
                            }

                            componentIndex = bigPeriodCount + departurePeriodIndex;
                            choiceProbabilityCalculator.CreateUtilityComponent(componentIndex);
                            ChoiceProbabilityCalculator.Component departureComponent = choiceProbabilityCalculator.GetUtilityComponent(componentIndex);


                            if (departurePeriodAvailableMinutes > 0)
                            {
                                departureComponent.AddUtilityTerm(300, Math.Log(departurePeriodAvailableMinutes));
                            }
                        }
                        // set period combination component
                        periodComb++;
                        componentIndex = 2 * bigPeriodCount + periodComb;
                        choiceProbabilityCalculator.CreateUtilityComponent(componentIndex);
                        ChoiceProbabilityCalculator.Component combinationComponent = choiceProbabilityCalculator.GetUtilityComponent(componentIndex);

                        if (arrivalPeriodAvailableMinutes > 0 && departurePeriodAvailableMinutes > 0)
                        {
                            double hoursDuration = (departurePeriod.Middle - arrivalPeriod.Middle) / 60.0;

                            int firstCoef = 700;
                            //combination constants
                            combinationComponent.AddUtilityTerm(firstCoef + periodComb, 1.0);
                            // duration shift variables
                            combinationComponent.AddUtilityTerm(firstCoef + 31, escortTourFlag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 32, shoppingTourFlag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 33, mealTourFlag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 34, socialTourFlag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 35, personalBusinessTourFlag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 36, recreationTourFlag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 37, medicalTourFlag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 38, highPrioritySameFlag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 39, lowPrioritySameFlag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 40, highPriorityDifferentFlag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 41, lowPriorityDifferentFlag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 42, partTimeWorkerFlag * hoursDuration);
                            combinationComponent.AddUtilityTerm(firstCoef + 43, jointTourFlag * hoursDuration);
                            //combinationComponent.AddUtilityTerm(firstCoef + 44, partialHalfTour1Flag * hoursDuration);
                            //combinationComponent.AddUtilityTerm(firstCoef + 45, fullHalfTour1Flag * hoursDuration);
                            //combinationComponent.AddUtilityTerm(firstCoef + 46, partialHalfTour2Flag * hoursDuration);
                            //combinationComponent.AddUtilityTerm(firstCoef + 47, fullHalfTour2Flag * hoursDuration);
                            // peak-to-peak variables
                            if (arrivalPeriod.Index == DayPeriod.AM_PEAK && departurePeriod.Index == DayPeriod.PM_PEAK)
                            {
                                //combinationComponent.AddUtilityTerm(firstCoef + 48, fulltimeWorkerFlag);
                                //combinationComponent.AddUtilityTerm(firstCoef + 49, income0To25KFlag);
                                //combinationComponent.AddUtilityTerm(firstCoef + 50, income100KPlusFlag);
                            }
                        }
                    }
                }
            }

            for (int mode = Global.Settings.Modes.Walk; mode <= Global.Settings.Modes.SchoolBus; mode++)
            {
                componentIndex = 2 * bigPeriodCount + nPeriodCombs + mode - 1;
                choiceProbabilityCalculator.CreateUtilityComponent(componentIndex);
                ChoiceProbabilityCalculator.Component modeComponent = choiceProbabilityCalculator.GetUtilityComponent(componentIndex);

                if (mode == Global.Settings.Modes.SchoolBus)
                {
                    //modeComponent.AddUtilityTerm(10, 1);
                    //modeComponent.AddUtilityTerm(11, childUnder5Flag);
                    //modeComponent.AddUtilityTerm(12, adultFlag);
                }
                else if (mode == Global.Settings.Modes.ParkAndRide)
                {
                    modeComponent.AddUtilityTerm(10, 1);
                    //modeComponent.AddUtilityTerm(16, noCarsInHouseholdFlag);
                    //modeComponent.AddUtilityTerm(17, carsLessThanWorkersFlag);
                    //modeComponent.AddUtilityTerm(129, destinationParcel.MixedUse2Index1());
                    //modeComponent.AddUtilityTerm(129, destinationParcel.TotalEmploymentDensity1()/5000.0);
                    //modeComponent.AddUtilityTerm(129, destinationParcel.NetIntersectionDensity1()/50.0);
                    //modeComponent.AddUtilityTerm(123, Math.Log(destinationParcel.StopsTransitBuffer1 + 1));
                }
                else if (mode == Global.Settings.Modes.Transit)
                {
                    modeComponent.AddUtilityTerm(20, 1);
                    modeComponent.AddUtilityTerm(21, maleFlag);
                    //modeComponent.AddUtilityTerm(22, ageUnder30Flag);
                    //modeComponent.AddUtilityTerm(23, ageBetween51And98Flag);
                    modeComponent.AddUtilityTerm(24, income0To25KFlag);
                    modeComponent.AddUtilityTerm(25, income100KPlusFlag);
                    modeComponent.AddUtilityTerm(26, noCarsInHouseholdFlag);
                    modeComponent.AddUtilityTerm(27, carsLessThanDriversFlag);
                    modeComponent.AddUtilityTerm(129, destinationParcel.MixedUse2Index1());
                    modeComponent.AddUtilityTerm(129, destinationParcel.TotalEmploymentDensity1() / 5000.0);
                    modeComponent.AddUtilityTerm(129, destinationParcel.NetIntersectionDensity1() / 50.0);
                    modeComponent.AddUtilityTerm(124, originParcel.NetIntersectionDensity1() / 50.0);
                    modeComponent.AddUtilityTerm(124, originParcel.HouseholdDensity1() / 1000.0);
                    modeComponent.AddUtilityTerm(124, originParcel.MixedUse2Index1());
                    //modeComponent.AddUtilityTerm(123, Math.Log(destinationParcel.StopsTransitBuffer1 + 1));
                    modeComponent.AddUtilityTerm(122, Math.Log(originParcel.StopsTransitBuffer1 + 1));
                }
                else if (mode == Global.Settings.Modes.Hov3)
                {
                    modeComponent.AddUtilityTerm(30, 1);
                    modeComponent.AddUtilityTerm(31, childrenUnder5);
                    modeComponent.AddUtilityTerm(32, childrenAge5Through15);
                    modeComponent.AddUtilityTerm(34, nonworkingAdults + retiredAdults);
                    modeComponent.AddUtilityTerm(38, onePersonHouseholdFlag);
                    modeComponent.AddUtilityTerm(39, twoPersonHouseholdFlag);
                    modeComponent.AddUtilityTerm(36, noCarsInHouseholdFlag);
                    modeComponent.AddUtilityTerm(37, carsLessThanDriversFlag);
                }
                else if (mode == Global.Settings.Modes.Hov2)
                {
                    modeComponent.AddUtilityTerm(31, childrenUnder5);
                    modeComponent.AddUtilityTerm(32, childrenAge5Through15);
                    modeComponent.AddUtilityTerm(34, nonworkingAdults + retiredAdults);
                    modeComponent.AddUtilityTerm(36, noCarsInHouseholdFlag);
                    modeComponent.AddUtilityTerm(37, carsLessThanDriversFlag);
                    modeComponent.AddUtilityTerm(40, 1);
                    modeComponent.AddUtilityTerm(41, onePersonHouseholdFlag);
                }
                else if (mode == Global.Settings.Modes.Sov)
                {
                    //	modeComponent.AddUtilityTerm(50, 1);
                    modeComponent.AddUtilityTerm(54, income0To25KFlag);
                    //modeComponent.AddUtilityTerm(55, income100KPlusFlag);
                    //modeComponent.AddUtilityTerm(57, carsLessThanWorkersFlag);
                }
                else if (mode == Global.Settings.Modes.Bike)
                {
                    modeComponent.AddUtilityTerm(60, 1);
                    modeComponent.AddUtilityTerm(61, maleFlag);
                    modeComponent.AddUtilityTerm(62, ageUnder30Flag);
                    modeComponent.AddUtilityTerm(63, ageBetween51And98Flag);
                    modeComponent.AddUtilityTerm(64, income0To25KFlag);
                    //modeComponent.AddUtilityTerm(65, income100KPlusFlag);
                    //modeComponent.AddUtilityTerm(66, noCarsInHouseholdFlag);
                    //modeComponent.AddUtilityTerm(67, carsLessThanDriversFlag);
                    modeComponent.AddUtilityTerm(169, destinationParcel.MixedUse4Index2());
                    modeComponent.AddUtilityTerm(169, destinationParcel.TotalEmploymentDensity2() / 20000.0);
                    modeComponent.AddUtilityTerm(169, destinationParcel.NetIntersectionDensity2() / 200.0);
                    modeComponent.AddUtilityTerm(164, originParcel.NetIntersectionDensity2() / 200.0);
                    modeComponent.AddUtilityTerm(164, originParcel.HouseholdDensity2() / 4000.0);
                    modeComponent.AddUtilityTerm(164, originParcel.MixedUse4Index2());
                }
                else if (mode == Global.Settings.Modes.Walk)
                {
                    modeComponent.AddUtilityTerm(70, 1.0);
                    //modeComponent.AddUtilityTerm(71, maleFlag);
                    modeComponent.AddUtilityTerm(72, ageUnder30Flag);
                    modeComponent.AddUtilityTerm(73, ageBetween51And98Flag);
                    modeComponent.AddUtilityTerm(74, income0To25KFlag);
                    //modeComponent.AddUtilityTerm(75, income100KPlusFlag);
                    modeComponent.AddUtilityTerm(76, noCarsInHouseholdFlag);
                    modeComponent.AddUtilityTerm(77, carsLessThanDriversFlag);
                    modeComponent.AddUtilityTerm(179, destinationParcel.MixedUse4Index1());
                    modeComponent.AddUtilityTerm(179, destinationParcel.TotalEmploymentDensity1() / 5000.0);
                    modeComponent.AddUtilityTerm(179, destinationParcel.NetIntersectionDensity1() / 50.0);
                    modeComponent.AddUtilityTerm(179, originParcel.NetIntersectionDensity1() / 50.0);
                    modeComponent.AddUtilityTerm(179, originParcel.HouseholdDensity1() / 1000.0);
                    modeComponent.AddUtilityTerm(179, originParcel.MixedUse4Index1());
                }

                if (mode == Global.Settings.Modes.Walk || mode == Global.Settings.Modes.Bike || mode == Global.Settings.Modes.Hov2 ||
                    mode == Global.Settings.Modes.Hov3 || mode == Global.Settings.Modes.Transit)
                {
                    int firstCoef = 200 + 10 * mode;
                    modeComponent.AddUtilityTerm(firstCoef + 0, escortTourFlag);
                    modeComponent.AddUtilityTerm(firstCoef + 1, shoppingTourFlag);
                    modeComponent.AddUtilityTerm(firstCoef + 2, mealTourFlag);
                    modeComponent.AddUtilityTerm(firstCoef + 3, socialTourFlag);
                    modeComponent.AddUtilityTerm(firstCoef + 4, personalBusinessTourFlag);
                    modeComponent.AddUtilityTerm(firstCoef + 5, recreationTourFlag);
                    modeComponent.AddUtilityTerm(firstCoef + 6, medicalTourFlag);
                    modeComponent.AddUtilityTerm(firstCoef + 7, jointTourFlag);
                    modeComponent.AddUtilityTerm(firstCoef + 8, Math.Min(partialHalfTour1Flag + partialHalfTour2Flag, 1.0));
                    modeComponent.AddUtilityTerm(firstCoef + 9, Math.Min(fullHalfTour1Flag + fullHalfTour2Flag, 1.0));

                    modeComponent.AddUtilityTerm(290 + mode, mode == parentTourMode ? 1 : 0);
                }
                modeComponent.AddUtilityTerm(298, mode >= Global.Settings.Modes.Sov && mode <= Global.Settings.Modes.Hov3 && parentTourMode == Global.Settings.Modes.Sov ? 1 : 0);
                modeComponent.AddUtilityTerm(299, mode >= Global.Settings.Modes.Sov && mode <= Global.Settings.Modes.Hov3 && parentTourMode >= Global.Settings.Modes.Hov2 && parentTourMode <= Global.Settings.Modes.Hov3 ? 1 : 0);
            }



            //loop on all alternatives, using modeTimes objects
            {
                foreach (HTourModeTime modeTimes in HTourModeTime.ModeTimes[ParallelUtility.threadLocalAssignedIndex.Value])
                {
                    MinuteSpan arrivalPeriod = modeTimes.ArrivalPeriod;
                    int        arrivalPeriodAvailableMinutes = timeWindow.TotalAvailableMinutes(arrivalPeriod.Start, arrivalPeriod.End);

                    MinuteSpan departurePeriod = modeTimes.DeparturePeriod;
                    int        departurePeriodAvailableMinutes = timeWindow.TotalAvailableMinutes(departurePeriod.Start, departurePeriod.End);
                    periodComb = modeTimes.PeriodCombinationIndex;

                    int mode = modeTimes.Mode;

                    int altIndex = modeTimes.Index;

                    //set availabillity based on time window variables and any constrained choices
                    bool available = (modeTimes.LongestFeasibleWindow != null) && (mode > 0) &&
                                     (mode <= Global.Settings.Modes.Transit) &&
                                     (person.Age >= 18 || (modeTimes.Mode != Global.Settings.Modes.Sov && modeTimes.Mode != Global.Settings.Modes.HovDriver)) &&
                                     (constrainedMode > 0 || mode == Global.Settings.Modes.Walk || mode == Global.Settings.Modes.Bike || mode == Global.Settings.Modes.HovDriver || mode == Global.Settings.Modes.Transit || !partialHalfTour) &&
                                     (constrainedMode <= 0 || constrainedMode == mode) &&
                                     (constrainedArrivalTime <= 0 || (constrainedArrivalTime >= arrivalPeriod.Start && constrainedArrivalTime <= arrivalPeriod.End)) &&
                                     (constrainedDepartureTime <= 0 || (constrainedDepartureTime >= departurePeriod.Start && constrainedDepartureTime <= departurePeriod.End));


                    ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(altIndex, available,
                                                                                                                     choice != null && choice.Index == altIndex);

                    alternative.Choice = modeTimes; // JLB added 20130420

                    //alternative.AddNestedAlternative(HTourModeTime.TOTAL_TOUR_MODE_TIMES + mode + 1, mode, THETA_PARAMETER);

                    if (Global.Configuration.IsInEstimationMode && choice != null && altIndex == choice.Index)
                    {
                        Global.PrintFile.WriteLine("Aper Dper Mode {0} {1} {2} Travel Times {3} {4} Window {5} {6}",
                                                   arrivalPeriod.Index, departurePeriod.Index, mode,
                                                   modeTimes.ModeAvailableToDestination ? modeTimes.TravelTimeToDestination : -1,
                                                   modeTimes.ModeAvailableFromDestination ? modeTimes.TravelTimeFromDestination : -1,
                                                   modeTimes.LongestFeasibleWindow != null ? modeTimes.LongestFeasibleWindow.Start : -1,
                                                   modeTimes.LongestFeasibleWindow != null ? modeTimes.LongestFeasibleWindow.End : -1);
                    }

                    /*				if (altIndex == 0)
                     *                  {
                     *                      alternative.AddUtilityTerm(991, tour.Household.Id);
                     *                      alternative.AddUtilityTerm(992, tour.Person.Id);
                     *                      alternative.AddUtilityTerm(993, tour.PersonDay.Day);
                     *                      alternative.AddUtilityTerm(994, tour.Sequence);
                     *                      alternative.AddUtilityTerm(995, constrainedMode);
                     *                      alternative.AddUtilityTerm(996, constrainedArrivalTime);
                     *                      alternative.AddUtilityTerm(997, constrainedDepartureTime);
                     *                      alternative.AddUtilityTerm(998, tour.DestinationPurpose);
                     *                      alternative.AddUtilityTerm(999, (tour.ParentTour == null) ? 0 : 1);
                     *                  }
                     */
                    //if in application mode and combination is not available, can skip the rest
                    if (!Global.Configuration.IsInEstimationMode && !alternative.Available)
                    {
                        continue;
                    }
                    if (useTimeComponents)
                    {
                        // arrival period utility component
                        alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(arrivalPeriod.Index));

                        // departure period utility component
                        alternative.AddUtilityComponent(
                            choiceProbabilityCalculator.GetUtilityComponent(bigPeriodCount + departurePeriod.Index));

                        // period combination utility component
                        alternative.AddUtilityComponent(choiceProbabilityCalculator.GetUtilityComponent(2 * bigPeriodCount + periodComb));
                    }
                    // mode utility component
                    alternative.AddUtilityComponent(
                        choiceProbabilityCalculator.GetUtilityComponent(2 * bigPeriodCount + nPeriodCombs + mode - 1));

                    //even in estimation mode, do not need the rest of the code if not available
                    if (!alternative.Available)
                    {
                        continue;
                    }

                    // set parking cost for period combination
                    double parkingDuration = (departurePeriod == arrivalPeriod
                                               ? (arrivalPeriod.End - arrivalPeriod.Start) / 2.0
                                               : departurePeriod.Middle - arrivalPeriod.Middle) / 60.0;

                    // parking at work is free if no paid parking at work and tour goes to usual workplace
                    double destinationParkingCost = (!Global.Configuration.IsInEstimationMode &&
                                                     Global.Configuration.ShouldRunPayToParkAtWorkplaceModel &&
                                                     tour.Person.UsualWorkParcel != null &&
                                                     destinationParcel == tour.Person.UsualWorkParcel &&
                                                     person.PaidParkingAtWorkplace == 0)
                                                     ? 0.0
                                                     : destinationParcel.ParkingCostBuffer1(parkingDuration);
                    double parkingCostFraction = (mode == Global.Settings.Modes.Sov)
                                                  ? 1.0
                                                  : (mode == Global.Settings.Modes.Hov2)
                                                        ? 1.0 / Global.Configuration.Coefficients_HOV2CostDivisor_Work
                                                        : (mode == Global.Settings.Modes.Hov3)
                                                              ? 1.0 / Global.Configuration.Coefficients_HOV3CostDivisor_Work
                                                              : 0.0;


                    double minimumTimeNeeded = modeTimes.TravelTimeToDestination + modeTimes.TravelTimeFromDestination +
                                               Global.Settings.Times.MinimumActivityDuration;

                    alternative.AddUtilityTerm(1, modeTimes.GeneralizedTimeToDestination + modeTimes.GeneralizedTimeFromDestination);
                    alternative.AddUtilityTerm(2, destinationParkingCost * parkingCostFraction);
                    //alternative.AddUtilityTerm(3,
                    //                          Math.Log(Math.Min(840, modeTimes.LongestFeasibleWindow.End - modeTimes.LongestFeasibleWindow.Start -
                    //													 minimumTimeNeeded + 1.0)));
                    // JLB 20140204 replaced coeff 3 with a different time window formulation:  time pressure
                    //    instead of having positive utility for increasing time window, have negative utility for decreasing time window
                    alternative.AddUtilityTerm(3,
                                               Math.Log(Math.Max(Constants.EPSILON, 1 -
                                                                 Math.Pow(minimumTimeNeeded / (Math.Min(840, modeTimes.LongestFeasibleWindow.End - modeTimes.LongestFeasibleWindow.Start)), 0.8)
                                                                 )));

                    //alternative.AddUtilityTerm(4, Math.Log((totalMinutesAvailableInDay + 1.0)/(minimumTimeNeeded + 1.0)));
                    //alternative.AddUtilityTerm(4,
                    //					Math.Log(Math.Max(Constants.EPSILON, 1 - minimumTimeNeeded/(Math.Min(1140, totalMinutesAvailableInDay)))));
                    alternative.AddUtilityTerm(5,
                                               (maleFlag == 0 && mode == Global.Settings.Modes.Walk &&
                                                arrivalPeriod.Index >= DayPeriod.EVENING)
                                         ? 1
                                         : 0);
                    alternative.AddUtilityTerm(5,
                                               (maleFlag == 0 && mode == Global.Settings.Modes.Walk &&
                                                departurePeriod.Index >= DayPeriod.EVENING)
                                         ? 1
                                         : 0);
                }
            }
        }
Exemplo n.º 26
0
        public void Run(HouseholdDayWrapper householdDay, TripWrapper trip)
        {
            if (trip == null)
            {
                throw new ArgumentNullException("trip");
            }

            if (householdDay.Household.Id == 80073 && trip.Day == 1 && trip.Person.Sequence == 1 &&
                trip.Tour.Sequence == 2 && trip.Direction == 1 && trip.Sequence == 1)
            {
            }

            trip.PersonDay.ResetRandom(40 * (2 * trip.Tour.Sequence - 1 + trip.Direction - 1) + 40 + trip.Sequence - 1);

            if (Global.Configuration.IsInEstimationMode)
            {
                if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME)
                {
                    return;
                }
            }

            ChoiceProbabilityCalculator choiceProbabilityCalculator =
                _helpers[ParallelUtility.threadLocalAssignedIndex.Value].GetChoiceProbabilityCalculator(trip.Id);

            IParcelWrapper originParcel =
                trip.IsHalfTourFromOrigin
                    ? trip.DestinationParcel
                    : trip.OriginParcel;

            // for skims - use actual travel direction, not simulation direction
            IParcelWrapper destinationParcel =
                trip.IsHalfTourFromOrigin
                    ? trip.OriginParcel
                    : trip.DestinationParcel;


            int departureTime = trip.IsHalfTourFromOrigin ? trip.LatestDepartureTime : trip.EarliestDepartureTime;

            if (departureTime < 1)
            {
                Global.PrintFile.WriteLine("From origin / latest / earliest  {0} {1} {2}", trip.IsHalfTourFromOrigin,
                                           trip.LatestDepartureTime, trip.EarliestDepartureTime);
                if (!Global.Configuration.IsInEstimationMode)
                {
                    trip.PersonDay.IsValid = false;
                    householdDay.IsValid   = false;
                }
                return;
            }

            if (_helpers[ParallelUtility.threadLocalAssignedIndex.Value].ModelIsInEstimationMode)
            {
                if (destinationParcel == null || originParcel == null || trip.Mode <= Global.Settings.Modes.None ||
                    trip.Mode > Global.Settings.Modes.Transit)
                {
                    return;
                }

                IEnumerable <IPathTypeModel> pathTypeModels =
                    PathTypeModelFactory.Singleton.RunAll(
                        trip.Household.RandomUtility,
                        originParcel,
                        destinationParcel,
                        departureTime,
                        0,
                        trip.Tour.DestinationPurpose,
                        trip.Tour.CostCoefficient,
                        trip.Tour.TimeCoefficient,
                        trip.Person.IsDrivingAge,
                        trip.Household.VehiclesAvailable,
                        trip.Person.TransitPassOwnership,
                        trip.Household.OwnsAutomatedVehicles > 0,
                        trip.Person.GetTransitFareDiscountFraction(),
                        false);

                // GV, July 9th: COMPAS modes are: Bike, Walk, PT, SOV (car driver alone), HOV2 (car driver in a car with a passenger) and HOV3 (car passenger)
                // GV, July 9th: COMPAS has no follwing modes: School bus

                //// there is no path type model for school bus, use HOV3
                //var mode = trip.Mode == Global.Settings.Modes.SchoolBus ? Global.Settings.Modes.Hov3 : trip.Mode;
                //var pathTypeModel = pathTypeModels.First(x => x.Mode == mode);
                //
                //if (!pathTypeModel.Available) {
                //	return;
                //}

                RunModel(choiceProbabilityCalculator, trip, pathTypeModels, originParcel, destinationParcel, trip.Mode);

                choiceProbabilityCalculator.WriteObservation();
            }
            else
            {
                IEnumerable <IPathTypeModel> pathTypeModels =
                    PathTypeModelFactory.Singleton.RunAll(
                        trip.Household.RandomUtility,
                        originParcel,
                        destinationParcel,
                        departureTime,
                        0,
                        trip.Tour.DestinationPurpose,
                        trip.Tour.CostCoefficient,
                        trip.Tour.TimeCoefficient,
                        trip.Person.IsDrivingAge,
                        trip.Household.VehiclesAvailable,
                        trip.Person.TransitPassOwnership,
                        trip.Household.OwnsAutomatedVehicles > 0,
                        trip.Person.GetTransitFareDiscountFraction(),
                        false);

                RunModel(choiceProbabilityCalculator, trip, pathTypeModels, originParcel, destinationParcel);

                ChoiceProbabilityCalculator.Alternative chosenAlternative = choiceProbabilityCalculator.SimulateChoice(trip.Household.RandomUtility);

                if (chosenAlternative == null)
                {
                    Global.PrintFile.WriteNoAlternativesAvailableWarning(CHOICE_MODEL_NAME, "Run", 100 * trip.Tour.DestinationPurpose + trip.Tour.Mode);
                    trip.Mode = Global.Settings.Modes.Hov3;
                    if (!Global.Configuration.IsInEstimationMode)
                    {
                        trip.PersonDay.IsValid = false;
                    }
                    return;
                }

                int choice = (int)chosenAlternative.Choice;

                trip.Mode = choice;
                if (choice == Global.Settings.Modes.SchoolBus || choice == Global.Settings.Modes.PaidRideShare)
                {
                    trip.PathType = 0;
                }

                //else if (Global.Configuration.TestEstimationModelInApplicationMode)
                //{
                //    Global.Configuration.IsInEstimationMode = false;
                //
                //    RunModel(choiceProbabilityCalculator, trip, pathTypeModels, originParcel, destinationParcel);
                //
                //    var simulatedChoice = choiceProbabilityCalculator.SimulateChoice(householdDay.Household.RandomUtility, householdDay.Household.Id, householdDay.PrimaryPriorityTimeFlag);
                //
                //    Global.Configuration.IsInEstimationMode = true;
                //}

                else
                {
                    IPathTypeModel chosenPathType = pathTypeModels.First(x => x.Mode == choice);
                    trip.PathType = chosenPathType.PathType;
                }
            }
        }
        protected override void RegionSpecificCustomizations(ChoiceProbabilityCalculator.Alternative alternative, ITourWrapper tour, int pathType, int mode, IParcelWrapper destinationParcel)
        {
            //Global.PrintFile.WriteLine("Default PSRC_OtherHomeBasedTourModeModel.RegionSpecificCustomizations2 called");

            if (mode == Global.Settings.Modes.Transit && pathType != Global.Settings.PathTypes.LightRail && pathType != Global.Settings.PathTypes.CommuterRail && pathType != Global.Settings.PathTypes.Ferry)
            {
                alternative.AddUtilityTerm(200 + tour.OriginParcel.District, 1); //district specific transit calibration constant
                alternative.AddUtilityTerm(300 + destinationParcel.District, 1); //district specific transit calibration constant
            }

            if (mode == Global.Settings.Modes.ParkAndRide)
            {
                alternative.AddUtilityTerm(250, pathType == 3 ? 1 : 0);
                alternative.AddUtilityTerm(251, pathType == 4 ? 1 : 0);
                alternative.AddUtilityTerm(252, pathType == 5 ? 1 : 0);
                alternative.AddUtilityTerm(253, pathType == 6 ? 1 : 0);
                alternative.AddUtilityTerm(254, pathType == 7 ? 1 : 0);
            }
            else if (mode == Global.Settings.Modes.Transit)
            {
                alternative.AddUtilityTerm(255, pathType == 3 ? 1 : 0);
                alternative.AddUtilityTerm(256, pathType == 4 ? 1 : 0);
                alternative.AddUtilityTerm(257, pathType == 5 ? 1 : 0);
                alternative.AddUtilityTerm(258, pathType == 6 ? 1 : 0);
                alternative.AddUtilityTerm(259, pathType == 7 ? 1 : 0);
            }
        }
Exemplo n.º 28
0
 protected virtual void RegionSpecificCustomizations(ChoiceProbabilityCalculator.Alternative alternative, ITourWrapper tour, int pathType, int mode, IParcelWrapper destinationParcel)
 {
     //see PSRC customization dll for example
     //Global.PrintFile.WriteLine("Generic Default WorkTourModeModel.RegionSpecificCustomizations being called so must not be overridden by CustomizationDll");
 }
Exemplo n.º 29
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, IPersonWrapper person, int sampleSize, IParcelWrapper choice = null, bool choseHome = false)
        {
            var segment                  = Global.Kernel.Get <SamplingWeightsSettingsFactory>().SamplingWeightsSettings.GetTourDestinationSegment(Global.Settings.Purposes.Work, Global.Settings.TourPriorities.HomeBasedTour, Global.Settings.Modes.Sov, person.PersonType);
            var destinationSampler       = new DestinationSampler(choiceProbabilityCalculator, segment, sampleSize, person.Household.ResidenceParcel, choice);
            var destinationArrivalTime   = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.WorkTourModeModel);
            var destinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.WorkTourModeModel);
            var workLocationUtilites     = new WorkLocationUtilities(person, sampleSize, destinationArrivalTime, destinationDepartureTime);

            destinationSampler.SampleTourDestinations(workLocationUtilites);

            //var alternative = choiceProbabilityCalculator.GetAlternative(countSampled, true);

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

            alternative.Choice = person.Household.ResidenceParcel;

            alternative.AddUtilityTerm(41, 1);
            alternative.AddUtilityTerm(42, person.IsPartTimeWorker.ToFlag());
            alternative.AddUtilityTerm(43, person.IsStudentAge.ToFlag());
            alternative.AddUtilityTerm(44, person.IsFemale.ToFlag());
            alternative.AddUtilityTerm(90, 100);

            //make oddball alt unavailable and remove nesting for estimation of conditional MNL
//			alternative.Available = false;
            alternative.AddNestedAlternative(sampleSize + 3, 1, 98);
        }
Exemplo n.º 30
0
        public void Run(TourWrapper tour, HouseholdDayWrapper householdDay, int sampleSize, IParcelWrapper constrainedParcel = null)
        {
            if (tour == null)
            {
                throw new ArgumentNullException("tour");
            }

            tour.PersonDay.ResetRandom(20 + tour.Sequence - 1);

            if (Global.Configuration.IsInEstimationMode)
            {
                if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME)
                {
                    return;
                }
                if (!TourDestinationUtilities.ShouldRunInEstimationModeForModel(tour))
                {
                    return;
                }
                // JLB 20140421 add the following to keep from estimatign twice for the same tour
                if (tour.DestinationModeAndTimeHaveBeenSimulated)
                {
                    return;
                }
            }

            if (tour.DestinationPurpose == Global.Settings.Purposes.School)
            {
                // the following lines were redundant.  Usual destination properties are set in GetMandatoryTourSimulatedData()
                // sets the destination for the school tour
                //tour.DestinationParcelId = tour.Person.UsualSchoolParcelId;
                //tour.DestinationParcel = tour.Person.UsualSchoolParcel;
                //tour.DestinationZoneKey = tour.Person.UsualSchoolZoneKey;
                //tour.DestinationAddressType = Global.Settings.AddressTypes.UsualSchool;
                return;
            }
            else if (tour.DestinationPurpose == Global.Settings.Purposes.Work)
            {
                return;
            }
            else if (constrainedParcel != null)
            {
                tour.DestinationParcel   = constrainedParcel;
                tour.DestinationParcelId = constrainedParcel.Id;
                tour.DestinationZoneKey  = constrainedParcel.ZoneId;
                return;
            }

            var choiceProbabilityCalculator = _helpers[ParallelUtility.threadLocalAssignedIndex.Value].GetChoiceProbabilityCalculator(tour.Id);

            if (_helpers[ParallelUtility.threadLocalAssignedIndex.Value].ModelIsInEstimationMode)
            {
                if (constrainedParcel == null)
                {
                    RunModel(choiceProbabilityCalculator, tour, householdDay, sampleSize, tour.DestinationParcel);

                    choiceProbabilityCalculator.WriteObservation();
                }
            }
            else
            {
                RunModel(choiceProbabilityCalculator, tour, householdDay, sampleSize);

                var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(tour.Household.RandomUtility);

                if (chosenAlternative == null)
                {
                    Global.PrintFile.WriteNoAlternativesAvailableWarning(CHOICE_MODEL_NAME, "Run", tour.PersonDay.Id);
                    if (!Global.Configuration.IsInEstimationMode)
                    {
                        tour.PersonDay.IsValid = false;
                        tour.PersonDay.HouseholdDay.IsValid = false;
                    }

                    return;
                }

                var choice = (IParcelWrapper)chosenAlternative.Choice;

                tour.DestinationParcelId    = choice.Id;
                tour.DestinationParcel      = choice;
                tour.DestinationZoneKey     = ChoiceModelFactory.ZoneKeys[choice.ZoneId];
                tour.DestinationAddressType = Global.Settings.AddressTypes.Other;
            }
        }