Exemple #1
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITourWrapper tour, IEnumerable <dynamic> 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) {
            foreach (dynamic pathTypeModel in pathTypeModels)
            {
                IPathTypeModel ipathTypeModel        = pathTypeModel;
                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, ((double)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, ((double)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)
                {
                    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.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());
                }
            }
        }
Exemple #2
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITourWrapper tour, IEnumerable <IPathTypeModel> pathTypeModels, IParcelWrapper destinationParcel, int householdCars, int choice = Constants.DEFAULT_VALUE)
        {
            var household       = tour.Household;
            var householdTotals = household.HouseholdTotals;
            var personDay       = tour.PersonDay;
            var person          = tour.Person;

            // household inputs
            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(householdCars);
            var carsLessThanDriversFlag = household.GetFlagForCarsLessThanDrivers(householdCars);
            var carsLessThanWorkersFlag = household.GetFlagForCarsLessThanWorkers(householdCars);
            var income0To25KFlag        = household.Has0To25KIncome.ToFlag();
            var income75kPlusFlag       = household.Has75KPlusIncome.ToFlag();

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

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

            double escortPercentage;
            double nonEscortPercentage;

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

            //            var timeWindow = (originParcel == tour.Household.ResidenceParcel) ? personDay.TimeWindow : tour.ParentTour.TimeWindow;
            //            var longestWindow = timeWindow.MaxAvailableMinutesAfter(1);
            //            var totalWindow = timeWindow.TotalAvailableMinutesAfter(1);
            //            var expectedDurationCurrentTour = person.IsFulltimeWorker ? Global.Settings.Times.EightHours : Global.Settings.Times.FourHours;
            //            var expectedDurationOtherTours = (personDay.TotalTours - personDay.TotalSimulatedTours) * Global.Settings.Times.TwoHours;
            //            var expectedDurationStops = (Math.Min(personDay.TotalStops,1) - Math.Min(personDay.TotalSimulatedStops,1)) * Global.Settings.Times.OneHour;
            //            var totalExpectedDuration = expectedDurationCurrentTour + expectedDurationOtherTours + expectedDurationStops;

            // 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 - 1, 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 generalizedTimeLogsum = pathTypeModel.GeneralizedTimeLogsum;
                //                var travelTime = pathTypeModel.PathTime;
                //                var travelCost = pathTypeModel.PathCost;

                var available = pathTypeModel.Available; //&& (travelTime < longestWindow);

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

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

                //                if (mode == Global.Settings.Modes.ParkAndRide) {
                //                    Console.WriteLine("Park and ride logsum = {0}", generalizedTimeLogsum);
                //                }

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

                //                alternative.AddUtility(3, Math.Log(1.0 - travelTime / longestWindow));
                //                alternative.AddUtility(4, travelTime < longestWindow - expectedDurationCurrentTour ? Math.Log(1.0 - travelTime / (longestWindow - expectedDurationCurrentTour)) : 0);
                //                alternative.AddUtility(5, travelTime < longestWindow - expectedDurationCurrentTour ? 0 : 1);
                //                alternative.AddUtility(6, travelTime < totalWindow - totalExpectedDuration ? Math.Log(1.0 - travelTime / (totalWindow - totalExpectedDuration)) : 0);
                //                alternative.AddUtility(7, travelTime < totalWindow - totalExpectedDuration ? 0 : 1);
                //                var vot = tour.TimeCoefficient / tour.CostCoefficient;

                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.AddUtility(123, Math.Log(destinationParcel.StopsTransitBuffer1+1));
                }
                else if (mode == Global.Settings.Modes.Transit)
                {
                    alternative.AddUtilityTerm(20, 1);
                    //                        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.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));
                    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.AddUtility(34, nonworkingAdults + retiredAdults);
                    alternative.AddUtilityTerm(35, ((double)pathTypeModel.PathDistance).AlmostEquals(0) ? 0 : Math.Log(pathTypeModel.PathDistance));
                    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.AddUtility(34, nonworkingAdults + retiredAdults);
                    alternative.AddUtilityTerm(35, ((double)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(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(162, (class1Dist > 0).ToFlag());
                    alternative.AddUtilityTerm(162, (class2Dist > 0).ToFlag());
                    //                        alternative.AddUtility(163, (worstDist > 0).ToFlag());
                }
                else if (mode == Global.Settings.Modes.Walk)
                {
                    alternative.AddUtilityTerm(70, 1);
                    alternative.AddUtilityTerm(71, maleFlag);
                    //                        alternative.AddUtility(73, ageBetween51And98Flag);
                    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());
                }

                RegionSpecificCustomizations(alternative, tour, pathTypeModel.PathType, mode, destinationParcel);
            }
        }
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITourWrapper tour, IEnumerable <IPathTypeModel> 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();
            var univStudentFlag       = person.IsUniversityStudent.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);

            // paidRideShare is another special case  - set in config file - use HOV2 impedance
            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 ?
                                              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) {
            foreach (IPathTypeModel pathTypeModel in pathTypeModels)
            {
                IPathTypeModel ipathTypeModel        = pathTypeModel;
                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) ?
                                          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(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));
                    alternative.AddUtilityTerm(180, univStudentFlag);
                }
                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, ((double)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, ((double)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)
                {
                    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.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(70, 1);
                    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());
                }

                RegionSpecificCustomizations(alternative, tour, pathTypeModel.PathType, mode, destinationParcel);
            }
        }
Exemple #4
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, IPersonWrapper person)
        {
            IHouseholdWrapper household = person.Household;

            Framework.DomainModels.Models.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();
            int income0To25KFlag       = household.Has0To25KIncome.ToFlag();

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

            IParcelWrapper originParcel      = household.ResidenceParcel;
            IParcelWrapper destinationParcel = person.UsualWorkParcel;
            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 && person.PaidParkingAtWorkplace == 0) ? 0.0 : destinationParcel.ParkingCostBuffer1(parkingDuration);

            double income         = household.Income < 0 ? Global.Configuration.Coefficients_BaseCostCoefficientIncomeLevel : 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);

            /*
             *          var pathTypeModels =
             *              PathTypeModelFactory.Singleton.RunAll(
             *                  household.RandomUtility,
             *                  originParcel,
             *                  destinationParcel,
             *                  240,
             *                  720,
             *                  Global.Settings.Purposes.Work,
             *                  costCoefficient,
             *                  Global.Configuration.Coefficients_MeanTimeCoefficient_Work,
             *                  person.IsDrivingAge,
             *                  householdTotals.Adults, //assumes householdCars = adults
             *                  0.0, // assumes transitDiscountFraction = 0,
             *                  false);
             *
             *          foreach (var pathTypeModel in pathTypeModels) {
             *              var mode = pathTypeModel.Mode;
             *              var generalizedTime = pathTypeModel.GeneralizedTimeLogsum;
             * //                var travelTime = pathTypeModel.PathTime;
             * //                var travelCost = pathTypeModel.PathCost;
             *
             *              var available = pathTypeModel.Available; //&& (travelTime < longestWindow);
             *
             *              var alternative = choiceProbabilityCalculator.GetAlternative(mode, available, choice == mode);
             *              alternative.Choice = mode;
             *
             *              alternative.AddNestedAlternative(_nestedAlternativeIds[pathTypeModel.Mode], _nestedAlternativeIndexes[pathTypeModel.Mode], THETA_PARAMETER);
             *
             * //                if (mode == Global.Settings.Modes.ParkAndRide) {
             * //                    Console.WriteLine("Park and ride logsum = {0}", generalizedTimeLogsum);
             * //                }
             *
             *              if (!available) {
             *                  continue;
             *              }
             *
             *              alternative.AddUtilityTerm(2, generalizedTime * tour.TimeCoefficient);
             * //                alternative.AddUtility(3, Math.Log(1.0 - travelTime / longestWindow));
             * //                alternative.AddUtility(4, travelTime < longestWindow - expectedDurationCurrentTour ? Math.Log(1.0 - travelTime / (longestWindow - expectedDurationCurrentTour)) : 0);
             * //                alternative.AddUtility(5, travelTime < longestWindow - expectedDurationCurrentTour ? 0 : 1);
             * //                alternative.AddUtility(6, travelTime < totalWindow - totalExpectedDuration ? Math.Log(1.0 - travelTime / (totalWindow - totalExpectedDuration)) : 0);
             * //                alternative.AddUtility(7, travelTime < totalWindow - totalExpectedDuration ? 0 : 1);
             * //                var vot = tour.TimeCoefficient / tour.CostCoefficient;
             *
             *              switch (mode) {
             *                  case Global.Settings.Modes.ParkAndRide:
             *                      alternative.AddUtilityTerm(10, 1);
             *                      alternative.AddUtilityTerm(11, noCarsInHouseholdFlag);
             *                      alternative.AddUtilityTerm(13, carsLessThanWorkersFlag);
             * //                        alternative.AddUtility(129, destinationParcel.MixedUse2Index1());
             *                      alternative.AddUtilityTerm(128, destinationParcel.TotalEmploymentDensity1());
             *                      alternative.AddUtilityTerm(127, destinationParcel.NetIntersectionDensity1());
             * //                        alternative.AddUtility(123, Math.Log(destinationParcel.StopsTransitBuffer1+1));
             *
             *                      break;
             *                  case Global.Settings.Modes.Transit:
             *                      alternative.AddUtilityTerm(20, 1);
             * //                        alternative.AddUtility(129, destinationParcel.MixedUse2Index1());
             *                      alternative.AddUtilityTerm(128, destinationParcel.TotalEmploymentDensity1());
             *                      alternative.AddUtilityTerm(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));
             *
             *                      break;
             *                  case 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.AddUtility(34, nonworkingAdults + retiredAdults);
             *                      alternative.AddUtilityTerm(35, ((double)pathTypeModel.PathDistance).AlmostEquals(0) ? 0 : Math.Log(pathTypeModel.PathDistance));
             *                      alternative.AddUtilityTerm(38, onePersonHouseholdFlag);
             *                      alternative.AddUtilityTerm(39, twoPersonHouseholdFlag);
             *                      alternative.AddUtilityTerm(41, noCarsInHouseholdFlag);
             *                      alternative.AddUtilityTerm(42, carsLessThanDriversFlag);
             *                      alternative.AddUtilityTerm(133, escortPercentage);
             *                      alternative.AddUtilityTerm(134, nonEscortPercentage);
             *
             *                      break;
             *                  case Global.Settings.Modes.Hov2:
             *                      alternative.AddUtilityTerm(1, (destinationParkingCost * tour.CostCoefficient / Global.Configuration.Coefficients_HOV2CostDivisor_Work));
             *                      alternative.AddUtilityTerm(31, childrenUnder5);
             *                      alternative.AddUtilityTerm(32, childrenAge5Through15);
             * //                        alternative.AddUtility(34, nonworkingAdults + retiredAdults);
             *                      alternative.AddUtilityTerm(35, ((double)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);
             *
             *                      break;
             *                  case 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);
             *
             *                      break;
             *                  case 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(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(162, (class1Dist > 0).ToFlag());
             *                      alternative.AddUtilityTerm(162, (class2Dist > 0).ToFlag());
             * //                        alternative.AddUtility(163, (worstDist > 0).ToFlag());
             *
             *                      break;
             *                  case Global.Settings.Modes.Walk:
             *                      alternative.AddUtilityTerm(71, maleFlag);
             * //                        alternative.AddUtility(73, ageBetween51And98Flag);
             *                      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());
             *
             *                      break;
             *              }
             *          }
             */
        }
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITourWrapper tour, IEnumerable <IPathTypeModel> pathTypeModels, IParcelWrapper destinationParcel, int choice = Constants.DEFAULT_VALUE)
        {
            IHouseholdWrapper household = tour.Household;

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

            // household inputs
            int income0To25KFlag        = household.Has0To25KIncome.ToFlag();
            int incomeOver100Flag       = household.Has100KPlusIncome.ToFlag();
            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();
            int noCarsInHouseholdFlag   = household.GetFlagForNoCarsInHousehold(household.VehiclesAvailable);
            int carsLessThanDriversFlag = household.GetFlagForCarsLessThanDrivers(household.VehiclesAvailable);
            int carsLessThanWorkersFlag = household.GetFlagForCarsLessThanWorkers(household.VehiclesAvailable);

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

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

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

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


            //foreach (var pathTypeModel in pathTypeModels) {
            foreach (IPathTypeModel pathTypeModel in pathTypeModels)
            {
                IPathTypeModel ipathTypeModel = pathTypeModel;
                int            mode           = pathTypeModel.Mode;
                bool           available      = (pathTypeModel.Mode != Global.Settings.Modes.ParkAndRide || Global.Configuration.IncludeParkAndRideInOtherHomeBasedTourModeModel) &&
                                                (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) ?
                                             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(5, 1);
                    alternative.AddUtilityTerm(6, noCarsInHouseholdFlag);
                    alternative.AddUtilityTerm(7, carsLessThanWorkersFlag);
                    alternative.AddUtilityTerm(128, destinationParcel.TotalEmploymentDensity1());
                }
                else if (mode == Global.Settings.Modes.Transit)
                {
                    alternative.AddUtilityTerm(20, 1);
                    alternative.AddUtilityTerm(21, noCarsInHouseholdFlag);
                    alternative.AddUtilityTerm(22, carsLessThanDriversFlag); //for calibration
                    alternative.AddUtilityTerm(120, shoppingTourFlag);
                    alternative.AddUtilityTerm(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));
                    alternative.AddUtilityTerm(180, univStudentFlag);
                }
                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(36, noCarsInHouseholdFlag);   // for calibration of hov3 vs hov2
                    alternative.AddUtilityTerm(37, carsLessThanWorkersFlag); // for calibration of hov3 vs hov2
                    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)
                {
                    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.ValueOfTimes.DefaultVot, 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(160, socialOrRecreationTourFlag);
                    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(161, (class1Dist > 0).ToFlag());
                    alternative.AddUtilityTerm(162, (class2Dist > 0).ToFlag());
                    alternative.AddUtilityTerm(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());
                }
                else if (mode == Global.Settings.Modes.Walk)
                {
                    alternative.AddUtilityTerm(70, 1);
                    alternative.AddUtilityTerm(73, ageBetween51And98Flag);
                    alternative.AddUtilityTerm(77, noCarsInHouseholdFlag);   //for calibration
                    alternative.AddUtilityTerm(78, carsLessThanDriversFlag); //for calibration
                    alternative.AddUtilityTerm(171, mealTourFlag);
                    alternative.AddUtilityTerm(172, socialOrRecreationTourFlag);
                    alternative.AddUtilityTerm(179, destinationParcel.MixedUse4Index1());
                    alternative.AddUtilityTerm(178, destinationParcel.HouseholdDensity1());
                    alternative.AddUtilityTerm(177, destinationParcel.NetIntersectionDensity1());
                    alternative.AddUtilityTerm(176, originParcel.NetIntersectionDensity1());
                    alternative.AddUtilityTerm(175, originParcel.HouseholdDensity1());
                    alternative.AddUtilityTerm(174, 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());
                }
                else if (mode == Global.Settings.Modes.PaidRideShare)
                {
                    if (Global.Configuration.PaidRideshare_UseEstimatedInsteadOfAssertedCoefficients)
                    {
                        alternative.AddUtilityTerm(80, 1.0);
                        //alternative.AddUtilityTerm(81, tour.Person.AgeIsBetween26And35.ToFlag());
                        //alternative.AddUtilityTerm(82, tour.Person.AgeIsBetween18And25.ToFlag());
                        alternative.AddUtilityTerm(81, noCarsInHouseholdFlag);   //for calibration
                        alternative.AddUtilityTerm(82, carsLessThanDriversFlag); //for calibration
                        alternative.AddUtilityTerm(83, (tour.Person.Age >= 65).ToFlag());
                        alternative.AddUtilityTerm(84, originParcel.HouseholdsBuffer2 + originParcel.StudentsUniversityBuffer2 + originParcel.EmploymentTotalBuffer2);
                        alternative.AddUtilityTerm(85, destinationParcel.HouseholdsBuffer2 + destinationParcel.StudentsUniversityBuffer2 + destinationParcel.EmploymentTotalBuffer2);
                        alternative.AddUtilityTerm(86, income0To25KFlag);
                        alternative.AddUtilityTerm(87, incomeOver100Flag);
                        alternative.AddUtilityTerm(88, mealTourFlag);
                        alternative.AddUtilityTerm(89, shoppingTourFlag);
                    }
                    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);
            }
        }
Exemple #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());
                    }
                }
            }
        }
Exemple #7
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITourWrapper tour, IEnumerable <PathTypeModel> pathTypeModels, IParcelWrapper destinationParcel, int householdCars, int choice = Constants.DEFAULT_VALUE)
        {
            var household       = tour.Household;
            var householdTotals = household.HouseholdTotals;
            var personDay       = tour.PersonDay;
            var person          = tour.Person;

            // household inputs
            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(householdCars);
            var carsLessThanDriversFlag = household.GetFlagForCarsLessThanDrivers(householdCars);
            var carsLessThanWorkersFlag = household.GetFlagForCarsLessThanWorkers(householdCars);
            var income0To25KFlag        = household.Has0To25KIncome.ToFlag();

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

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

            double escortPercentage;
            double nonEscortPercentage;

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

            //			var timeWindow = (originParcel == tour.Household.ResidenceParcel) ? personDay.TimeWindow : tour.ParentTour.TimeWindow;
            //			var longestWindow = timeWindow.MaxAvailableMinutesAfter(1);
            //			var totalWindow = timeWindow.TotalAvailableMinutesAfter(1);
            //			var expectedDurationCurrentTour = person.IsFulltimeWorker ? Global.Settings.Times.EightHours : Global.Settings.Times.FourHours;
            //			var expectedDurationOtherTours = (personDay.TotalTours - personDay.TotalSimulatedTours) * Global.Settings.Times.TwoHours;
            //			var expectedDurationStops = (Math.Min(personDay.TotalStops,1) - Math.Min(personDay.TotalSimulatedStops,1)) * Global.Settings.Times.OneHour;
            //			var totalExpectedDuration = expectedDurationCurrentTour + expectedDurationOtherTours + expectedDurationStops;

            foreach (var pathTypeModel in pathTypeModels)
            {
                var mode            = pathTypeModel.Mode;
                var generalizedTime = pathTypeModel.GeneralizedTimeLogsum;
                //				var travelTime = pathTypeModel.PathTime;
                //				var travelCost = pathTypeModel.PathCost;

                var available = pathTypeModel.Available;                 //&& (travelTime < longestWindow);

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

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

                //				if (mode == Global.Settings.Modes.ParkAndRide) {
                //					Console.WriteLine("Park and ride logsum = {0}", generalizedTimeLogsum);
                //				}

                if (!available)
                {
                    continue;
                }

                alternative.AddUtilityTerm(2, generalizedTime * tour.TimeCoefficient);
                //				alternative.AddUtility(3, Math.Log(1.0 - travelTime / longestWindow));
                //				alternative.AddUtility(4, travelTime < longestWindow - expectedDurationCurrentTour ? Math.Log(1.0 - travelTime / (longestWindow - expectedDurationCurrentTour)) : 0);
                //				alternative.AddUtility(5, travelTime < longestWindow - expectedDurationCurrentTour ? 0 : 1);
                //				alternative.AddUtility(6, travelTime < totalWindow - totalExpectedDuration ? Math.Log(1.0 - travelTime / (totalWindow - totalExpectedDuration)) : 0);
                //				alternative.AddUtility(7, travelTime < totalWindow - totalExpectedDuration ? 0 : 1);
                //				var vot = tour.TimeCoefficient / tour.CostCoefficient;

                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(128, destinationParcel.TotalEmploymentDensity1());
                    alternative.AddUtilityTerm(127, destinationParcel.NetIntersectionDensity1());
                    //						alternative.AddUtility(123, Math.Log(destinationParcel.StopsTransitBuffer1+1));
                }
                else if (mode == Global.Settings.Modes.Transit)
                {
                    alternative.AddUtilityTerm(20, 1);
                    //						alternative.AddUtility(129, destinationParcel.MixedUse2Index1());
                    alternative.AddUtilityTerm(128, destinationParcel.TotalEmploymentDensity1());
                    alternative.AddUtilityTerm(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 / Global.Configuration.Coefficients_HOV3CostDivisor_Work));
                    alternative.AddUtilityTerm(30, 1);
                    alternative.AddUtilityTerm(31, childrenUnder5);
                    alternative.AddUtilityTerm(32, childrenAge5Through15);
                    //						alternative.AddUtility(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(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.AddUtility(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)
                {
                    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.VotGroups.Medium, tour.DestinationArrivalTime,originParcel, destinationParcel).Variable : 0;

                    alternative.AddUtilityTerm(60, 1);
                    alternative.AddUtilityTerm(61, maleFlag);
                    alternative.AddUtilityTerm(63, ageBetween51And98Flag);
                    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(162, (class1Dist > 0).ToFlag());
                    alternative.AddUtilityTerm(162, (class2Dist > 0).ToFlag());
                    //						alternative.AddUtility(163, (worstDist > 0).ToFlag());
                }
                else if (mode == Global.Settings.Modes.Walk)
                {
                    alternative.AddUtilityTerm(71, maleFlag);
                    //						alternative.AddUtility(73, ageBetween51And98Flag);
                    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());
                }
            }
        }
Exemple #8
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());
                }
            }
        }
Exemple #9
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);
            }
        }
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, ITourWrapper subtour, IEnumerable <PathTypeModel> 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);

            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 * subtour.TimeCoefficient);

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