public void SetUtilities(ISampleItem sampleItem, int sampleFrequency) { if (sampleItem == null) { throw new ArgumentNullException("sampleItem"); } ChoiceProbabilityCalculator.Alternative alternative = sampleItem.Alternative; if (!alternative.Available) { return; } IHouseholdWrapper household = _tour.Household; IPersonWrapper person = _tour.Person; //var personDay = _tour.PersonDay; bool householdHasChildren = household.HasChildren; bool householdHasNoChildren = householdHasChildren ? false : true; IParcelWrapper destinationParcel = ChoiceModelFactory.Parcels[sampleItem.ParcelId]; int jointTourFlag = (_tour.JointTourSequence > 0).ToFlag(); double fastestTravelTime = ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Hov3, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, _fastestAvailableTimeOfDay, _tour.OriginParcel, destinationParcel).Variable + ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Hov3, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, _fastestAvailableTimeOfDay, destinationParcel, _tour.OriginParcel).Variable; if (fastestTravelTime >= _maxAvailableMinutes) { alternative.Available = false; return; } alternative.Choice = destinationParcel; //double tourLogsum = 0; double jointTourLogsum = 0; double workTourLogsum = 0; double otherTourLogsum = 0; double subtourLogsum = 0; if (_tour.IsHomeBasedTour) { if (_tour.DestinationPurpose == Global.Settings.Purposes.Work) { //var destinationArrivalTime = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.WorkTourModeModel); //var destinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.WorkTourModeModel); ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().RunNested(_tour, destinationParcel, _tour.Household.VehiclesAvailable, _tour.Person.GetTransitFareDiscountFraction()); workTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } // else if (_tour.DestinationPurpose == Global.Settings.Purposes.Escort) { // var nestedAlternative = (Global.ChoiceModelDictionary.Get("HEscortTourModeModel") as HEscortTourModeModel).RunNested(_tour, destinationParcel); // tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); // } else { ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <OtherHomeBasedTourModeTimeModel>().RunNested(_tour, destinationParcel, _tour.Household.VehiclesAvailable, _tour.Person.GetTransitFareDiscountFraction()); if (_tour.JointTourSequence > 0) { jointTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } else { otherTourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } } } else { ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <WorkBasedSubtourModeTimeModel>().RunNested(_tour, destinationParcel, _tour.Household.VehiclesAvailable, _tour.Person.GetTransitFareDiscountFraction()); subtourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } //var purpose = _tour.TourPurposeSegment; //var carOwnership = person.CarOwnershipSegment; //var votSegment = _tour.VotALSegment; //var transitAccess = destinationParcel.TransitAccessSegment(); //var aggregateLogsum = Global.AggregateLogsums[destinationParcel.ZoneId][purpose][carOwnership][votSegment][transitAccess]; //var aggregateLogsumHomeBased = Global.AggregateLogsums[destinationParcel.ZoneId][Global.Settings.Purposes.HomeBasedComposite][carOwnership][votSegment][transitAccess]; //var aggregateLogsumWorkBased = Global.AggregateLogsums[destinationParcel.ZoneId][Global.Settings.Purposes.Work_BASED][carOwnership][votSegment][transitAccess]; double distanceFromOrigin = _tour.OriginParcel.DistanceFromOrigin(destinationParcel, _tour.DestinationArrivalTime); double piecewiseDistanceFrom5To10Miles = Math.Max(0, Math.Min(distanceFromOrigin - .5, 1 - .5)); double piecewiseDistanceFrom10MilesToInfinity = Math.Max(0, distanceFromOrigin - 1); double piecewiseDistanceFrom0To1Mile = Math.Min(distanceFromOrigin, .10); double piecewiseDistanceFrom1To5Miles = Math.Max(0, Math.Min(distanceFromOrigin - .1, .5 - .1)); double piecewiseDistanceFrom1To3AndAHalfMiles = Math.Max(0, Math.Min(distanceFromOrigin - .1, .35 - .1)); double piecewiseDistanceFrom3AndAHalfTo10Miles = Math.Max(0, Math.Min(distanceFromOrigin - .35, 1 - .35)); double distanceFromOriginLog = Math.Log(1 + distanceFromOrigin); //var distanceFromWorkLog = person.UsualWorkParcel.DistanceFromWorkLog(destinationParcel, 1); double distanceFromSchoolLog = person.UsualSchoolParcel.DistanceFromSchoolLog(destinationParcel, 1); double timePressure = Math.Log(1 - fastestTravelTime / _maxAvailableMinutes); // log transforms of buffers for Neighborhood effects double logOfOnePlusEmploymentEducationBuffer1 = Math.Log(destinationParcel.EmploymentEducationBuffer1 + 1.0); double logOfOnePlusEmploymentFoodBuffer1 = Math.Log(destinationParcel.EmploymentFoodBuffer1 + 1.0); double logOfOnePlusEmploymentGovernmentBuffer1 = Math.Log(destinationParcel.EmploymentGovernmentBuffer1 + 1.0); double logOfOnePlusEmploymentOfficeBuffer1 = Math.Log(destinationParcel.EmploymentOfficeBuffer1 + 1.0); double logOfOnePlusEmploymentRetailBuffer1 = Math.Log(destinationParcel.EmploymentRetailBuffer1 + 1.0); double logOfOnePlusEmploymentServiceBuffer1 = Math.Log(destinationParcel.EmploymentServiceBuffer1 + 1.0); double logOfOnePlusEmploymentMedicalBuffer1 = Math.Log(destinationParcel.EmploymentMedicalBuffer1 + 1.0); double logOfOnePlusEmploymentIndustrial_Ag_ConstructionBuffer1 = Math.Log(destinationParcel.EmploymentIndustrialBuffer1 + destinationParcel.EmploymentAgricultureConstructionBuffer1 + 1.0); double logOfOnePlusEmploymentTotalBuffer1 = Math.Log(destinationParcel.EmploymentTotalBuffer1 + 1.0); double logOfOnePlusHouseholdsBuffer1 = Math.Log(destinationParcel.HouseholdsBuffer1 + 1.0); double logOfOnePlusStudentsK12Buffer1 = Math.Log(destinationParcel.StudentsK8Buffer1 + destinationParcel.StudentsHighSchoolBuffer1 + 1.0); double logOfOnePlusStudentsUniversityBuffer1 = Math.Log(destinationParcel.StudentsUniversityBuffer1 + 1.0); // var EMPHOU_B = Math.Log(destinationParcel.EmploymentTotalBuffer1 + destinationParcel.HouseholdsBuffer1 + 1.0); //var logOfOnePlusParkingOffStreetDailySpacesBuffer1 = Math.Log(1 + destinationParcel.ParkingOffStreetPaidDailySpacesBuffer1); // connectivity attributes //var c34Ratio = destinationParcel.C34RatioBuffer1(); //var carCompetitionFlag = FlagUtility.GetCarCompetitionFlag(carOwnership); // exludes no cars //var noCarCompetitionFlag = FlagUtility.GetNoCarCompetitionFlag(carOwnership); //var noCarsFlag = FlagUtility.GetNoCarsFlag(carOwnership); alternative.AddUtilityTerm(2, sampleItem.AdjustmentFactor); alternative.AddUtilityTerm(3, workTourLogsum); alternative.AddUtilityTerm(4, otherTourLogsum); alternative.AddUtilityTerm(5, jointTourLogsum); alternative.AddUtilityTerm(6, subtourLogsum); //subpopulation-specific terms //alternative.AddUtilityTerm(260, _secondaryFlag * _workOrSchoolPatternFlag * piecewiseDistanceFrom0To1Mile); //alternative.AddUtilityTerm(261, _secondaryFlag * _workOrSchoolPatternFlag * piecewiseDistanceFrom1To5Miles); //alternative.AddUtilityTerm(262, _secondaryFlag * _workOrSchoolPatternFlag * piecewiseDistanceFrom5To10Miles); //alternative.AddUtilityTerm(263, _secondaryFlag * _workOrSchoolPatternFlag * piecewiseDistanceFrom10MilesToInfinity); alternative.AddUtilityTerm(260, _secondaryFlag * _workOrSchoolPatternFlag * distanceFromOriginLog); //alternative.AddUtilityTerm(264, _secondaryFlag * _otherPatternFlag * piecewiseDistanceFrom0To1Mile); //alternative.AddUtilityTerm(265, _secondaryFlag * _otherPatternFlag * piecewiseDistanceFrom1To5Miles); //alternative.AddUtilityTerm(266, _secondaryFlag * _otherPatternFlag * piecewiseDistanceFrom5To10Miles); //alternative.AddUtilityTerm(267, _secondaryFlag * _otherPatternFlag * piecewiseDistanceFrom10MilesToInfinity); alternative.AddUtilityTerm(264, _secondaryFlag * _otherPatternFlag * distanceFromOriginLog); alternative.AddUtilityTerm(268, (!_tour.IsHomeBasedTour).ToFlag() * distanceFromOriginLog); //alternative.AddUtilityTerm(269, household.Has0To15KIncome.ToFlag() * distanceFromOriginLog); //alternative.AddUtilityTerm(270, household.HasMissingIncome.ToFlag() * distanceFromOriginLog); //alternative.AddUtilityTerm(271, person.IsRetiredAdult.ToFlag() * distanceFromOriginLog); //alternative.AddUtilityTerm(272, person.IsUniversityStudent.ToFlag() * distanceFromOriginLog); alternative.AddUtilityTerm(273, person.IsChildAge5Through15.ToFlag() * distanceFromOriginLog); //alternative.AddUtilityTerm(274, person.IsChildUnder5.ToFlag() * distanceFromOriginLog); alternative.AddUtilityTerm(275, (_tour.IsHomeBasedTour).ToFlag() * timePressure); alternative.AddUtilityTerm(276, (_tour.IsHomeBasedTour).ToFlag() * distanceFromSchoolLog); //alternative.AddUtilityTerm(14, distanceFromWorkLog); //alternative.AddUtilityTerm(277, (carCompetitionFlag + noCarCompetitionFlag) * destinationParcel.ParkingHourlyEmploymentCommercialMixInParcel()); //alternative.AddUtilityTerm(278, noCarCompetitionFlag * destinationParcel.ParkingHourlyEmploymentCommercialMixInParcel()); //alternative.AddUtilityTerm(279, carCompetitionFlag * destinationParcel.ParkingHourlyEmploymentCommercialMixBuffer1()); //alternative.AddUtilityTerm(280, noCarCompetitionFlag * destinationParcel.ParkingHourlyEmploymentCommercialMixBuffer1()); //alternative.AddUtilityTerm(281, noCarsFlag * c34Ratio); //alternative.AddUtilityTerm(282, noCarCompetitionFlag * c34Ratio); //alternative.AddUtilityTerm(283, (carCompetitionFlag + noCarCompetitionFlag) * logOfOnePlusParkingOffStreetDailySpacesBuffer1); alternative.AddUtilityTerm(284, jointTourFlag * piecewiseDistanceFrom0To1Mile); alternative.AddUtilityTerm(285, jointTourFlag * piecewiseDistanceFrom1To5Miles); alternative.AddUtilityTerm(286, jointTourFlag * piecewiseDistanceFrom5To10Miles); alternative.AddUtilityTerm(287, jointTourFlag * piecewiseDistanceFrom10MilesToInfinity); if (_tour.DestinationPurpose == Global.Settings.Purposes.Work) { alternative.AddUtilityTerm(10, piecewiseDistanceFrom0To1Mile); alternative.AddUtilityTerm(11, piecewiseDistanceFrom1To3AndAHalfMiles); alternative.AddUtilityTerm(12, piecewiseDistanceFrom3AndAHalfTo10Miles); alternative.AddUtilityTerm(13, piecewiseDistanceFrom10MilesToInfinity); //alternative.AddUtilityTerm(14, aggregateLogsumWorkBased); // Neighborhood alternative.AddUtilityTerm(20, logOfOnePlusEmploymentEducationBuffer1); //alternative.AddUtilityTerm(21, logOfOnePlusEmploymentGovernmentBuffer1); alternative.AddUtilityTerm(22, logOfOnePlusEmploymentOfficeBuffer1); //alternative.AddUtilityTerm(23, logOfOnePlusEmploymentServiceBuffer1); alternative.AddUtilityTerm(24, logOfOnePlusEmploymentMedicalBuffer1); alternative.AddUtilityTerm(25, logOfOnePlusHouseholdsBuffer1); alternative.AddUtilityTerm(26, logOfOnePlusStudentsUniversityBuffer1); alternative.AddUtilityTerm(27, logOfOnePlusStudentsK12Buffer1); alternative.AddUtilityTerm(28, logOfOnePlusEmploymentIndustrial_Ag_ConstructionBuffer1); // Size terms alternative.AddUtilityTerm(30, destinationParcel.EmploymentEducation); alternative.AddUtilityTerm(31, destinationParcel.EmploymentFood); alternative.AddUtilityTerm(32, destinationParcel.EmploymentGovernment); alternative.AddUtilityTerm(33, destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(34, destinationParcel.EmploymentRetail); alternative.AddUtilityTerm(35, destinationParcel.EmploymentService); alternative.AddUtilityTerm(36, destinationParcel.EmploymentMedical); alternative.AddUtilityTerm(37, destinationParcel.EmploymentIndustrial + destinationParcel.EmploymentAgricultureConstruction); alternative.AddUtilityTerm(38, destinationParcel.Households); alternative.AddUtilityTerm(39, destinationParcel.GetStudentsK12()); //(for application) alternative.AddUtilityTerm(40, destinationParcel.StudentsUniversity); } else if (_tour.DestinationPurpose == Global.Settings.Purposes.Escort) { alternative.AddUtilityTerm(50, piecewiseDistanceFrom0To1Mile); alternative.AddUtilityTerm(51, piecewiseDistanceFrom1To3AndAHalfMiles); alternative.AddUtilityTerm(52, piecewiseDistanceFrom3AndAHalfTo10Miles); alternative.AddUtilityTerm(53, piecewiseDistanceFrom10MilesToInfinity); //alternative.AddUtilityTerm(54, aggregateLogsumHomeBased); // Neighborhood alternative.AddUtilityTerm(60, householdHasNoChildren.ToFlag() * logOfOnePlusEmploymentGovernmentBuffer1); alternative.AddUtilityTerm(61, householdHasNoChildren.ToFlag() * logOfOnePlusHouseholdsBuffer1); //alternative.AddUtilityTerm(62, householdHasChildren.ToFlag() * logOfOnePlusHouseholdsBuffer1); alternative.AddUtilityTerm(63, householdHasChildren.ToFlag() * logOfOnePlusStudentsK12Buffer1); alternative.AddUtilityTerm(64, logOfOnePlusEmploymentTotalBuffer1); // Size terms alternative.AddUtilityTerm(70, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentEducation); alternative.AddUtilityTerm(71, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentFood); alternative.AddUtilityTerm(72, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentGovernment); alternative.AddUtilityTerm(73, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(74, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentRetail); alternative.AddUtilityTerm(75, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentService); alternative.AddUtilityTerm(76, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentMedical); alternative.AddUtilityTerm(77, (!householdHasChildren).ToFlag() * (destinationParcel.EmploymentIndustrial + destinationParcel.EmploymentAgricultureConstruction)); alternative.AddUtilityTerm(78, (!householdHasChildren).ToFlag() * destinationParcel.Households); alternative.AddUtilityTerm(79, (!householdHasChildren).ToFlag() * destinationParcel.GetStudentsK12()); alternative.AddUtilityTerm(80, householdHasChildren.ToFlag() * destinationParcel.EmploymentEducation); alternative.AddUtilityTerm(81, householdHasChildren.ToFlag() * destinationParcel.EmploymentFood); alternative.AddUtilityTerm(82, householdHasChildren.ToFlag() * destinationParcel.EmploymentGovernment); alternative.AddUtilityTerm(83, householdHasChildren.ToFlag() * destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(84, householdHasChildren.ToFlag() * destinationParcel.EmploymentRetail); alternative.AddUtilityTerm(85, householdHasChildren.ToFlag() * destinationParcel.EmploymentService); alternative.AddUtilityTerm(86, householdHasChildren.ToFlag() * destinationParcel.EmploymentMedical); alternative.AddUtilityTerm(87, householdHasChildren.ToFlag() * (destinationParcel.EmploymentIndustrial + destinationParcel.EmploymentAgricultureConstruction)); alternative.AddUtilityTerm(88, householdHasChildren.ToFlag() * destinationParcel.Households); alternative.AddUtilityTerm(89, householdHasChildren.ToFlag() * destinationParcel.GetStudentsK12()); } else if (_tour.DestinationPurpose == Global.Settings.Purposes.PersonalBusiness) { alternative.AddUtilityTerm(90, piecewiseDistanceFrom0To1Mile); alternative.AddUtilityTerm(91, piecewiseDistanceFrom1To3AndAHalfMiles); alternative.AddUtilityTerm(92, piecewiseDistanceFrom3AndAHalfTo10Miles); alternative.AddUtilityTerm(93, piecewiseDistanceFrom10MilesToInfinity); //alternative.AddUtilityTerm(94, aggregateLogsumHomeBased); // Neighborhood alternative.AddUtilityTerm(100, logOfOnePlusEmploymentEducationBuffer1); alternative.AddUtilityTerm(101, logOfOnePlusEmploymentOfficeBuffer1); //alternative.AddUtilityTerm(102, logOfOnePlusEmploymentServiceBuffer1); //alternative.AddUtilityTerm(103, logOfOnePlusEmploymentMedicalBuffer1); alternative.AddUtilityTerm(104, logOfOnePlusHouseholdsBuffer1); //alternative.AddUtilityTerm(105, logOfOnePlusStudentsUniversityBuffer1); alternative.AddUtilityTerm(106, logOfOnePlusEmploymentGovernmentBuffer1); alternative.AddUtilityTerm(107, logOfOnePlusEmploymentRetailBuffer1); // Size terms alternative.AddUtilityTerm(110, destinationParcel.EmploymentEducation); alternative.AddUtilityTerm(111, destinationParcel.EmploymentFood); alternative.AddUtilityTerm(112, destinationParcel.EmploymentGovernment); alternative.AddUtilityTerm(113, destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(114, destinationParcel.EmploymentRetail); alternative.AddUtilityTerm(115, destinationParcel.EmploymentService); alternative.AddUtilityTerm(116, destinationParcel.EmploymentMedical); alternative.AddUtilityTerm(117, destinationParcel.EmploymentIndustrial + destinationParcel.EmploymentAgricultureConstruction); alternative.AddUtilityTerm(118, destinationParcel.Households); //(for application) alternative.AddUtilityTerm(119, destinationParcel.GetStudentsK12()); } else if (_tour.DestinationPurpose == Global.Settings.Purposes.Shopping) { alternative.AddUtilityTerm(120, piecewiseDistanceFrom0To1Mile); alternative.AddUtilityTerm(121, piecewiseDistanceFrom1To3AndAHalfMiles); alternative.AddUtilityTerm(122, piecewiseDistanceFrom3AndAHalfTo10Miles); alternative.AddUtilityTerm(123, piecewiseDistanceFrom10MilesToInfinity); //alternative.AddUtilityTerm(124, aggregateLogsumHomeBased); // Neighborhood alternative.AddUtilityTerm(130, logOfOnePlusEmploymentEducationBuffer1); alternative.AddUtilityTerm(131, logOfOnePlusEmploymentRetailBuffer1); // Size terms alternative.AddUtilityTerm(140, destinationParcel.EmploymentFood); alternative.AddUtilityTerm(141, destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(142, destinationParcel.EmploymentRetail); alternative.AddUtilityTerm(143, destinationParcel.EmploymentService); } else if (_tour.DestinationPurpose == Global.Settings.Purposes.Meal) { alternative.AddUtilityTerm(150, piecewiseDistanceFrom0To1Mile); alternative.AddUtilityTerm(151, piecewiseDistanceFrom1To3AndAHalfMiles); alternative.AddUtilityTerm(152, piecewiseDistanceFrom3AndAHalfTo10Miles); alternative.AddUtilityTerm(153, piecewiseDistanceFrom10MilesToInfinity); //alternative.AddUtilityTerm(154, aggregateLogsumHomeBased); // Neighborhood alternative.AddUtilityTerm(156, logOfOnePlusEmploymentFoodBuffer1); //alternative.AddUtilityTerm(157, logOfOnePlusEmploymentRetailBuffer1); alternative.AddUtilityTerm(158, logOfOnePlusEmploymentServiceBuffer1); // Size terms alternative.AddUtilityTerm(160, destinationParcel.EmploymentFood); //(for application) alternative.AddUtilityTerm(161, destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(162, destinationParcel.EmploymentTotal); alternative.AddUtilityTerm(163, destinationParcel.Households); } else if (_tour.DestinationPurpose == Global.Settings.Purposes.Social) { alternative.AddUtilityTerm(170, piecewiseDistanceFrom0To1Mile); alternative.AddUtilityTerm(171, piecewiseDistanceFrom1To3AndAHalfMiles); alternative.AddUtilityTerm(172, piecewiseDistanceFrom3AndAHalfTo10Miles); alternative.AddUtilityTerm(173, piecewiseDistanceFrom10MilesToInfinity); //alternative.AddUtilityTerm(174, aggregateLogsumHomeBased); // Neighborhood //alternative.AddUtilityTerm(180, logOfOnePlusEmploymentOfficeBuffer1); //alternative.AddUtilityTerm(181, logOfOnePlusEmploymentServiceBuffer1); //alternative.AddUtilityTerm(182, logOfOnePlusHouseholdsBuffer1); //alternative.AddUtilityTerm(183, logOfOnePlusStudentsK12Buffer1); //alternative.AddUtilityTerm(184, logOfOnePlusStudentsUniversityBuffer1); //alternative.AddUtilityTerm(185, logOfOnePlusEmploymentTotalBuffer1); // Size terms alternative.AddUtilityTerm(190, destinationParcel.EmploymentEducation); alternative.AddUtilityTerm(191, destinationParcel.EmploymentFood); alternative.AddUtilityTerm(192, destinationParcel.EmploymentGovernment); alternative.AddUtilityTerm(193, destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(194, destinationParcel.EmploymentRetail); alternative.AddUtilityTerm(195, destinationParcel.EmploymentService); alternative.AddUtilityTerm(196, destinationParcel.EmploymentMedical); alternative.AddUtilityTerm(197, destinationParcel.Households); alternative.AddUtilityTerm(198, destinationParcel.StudentsUniversity); //(for application) alternative.AddUtilityTerm(199, destinationParcel.GetStudentsK12()); } else if (_tour.DestinationPurpose == Global.Settings.Purposes.Recreation) { alternative.AddUtilityTerm(200, piecewiseDistanceFrom0To1Mile); alternative.AddUtilityTerm(201, piecewiseDistanceFrom1To3AndAHalfMiles); alternative.AddUtilityTerm(202, piecewiseDistanceFrom3AndAHalfTo10Miles); alternative.AddUtilityTerm(203, piecewiseDistanceFrom10MilesToInfinity); //alternative.AddUtilityTerm(204, aggregateLogsumHomeBased); // Neighborhood alternative.AddUtilityTerm(210, logOfOnePlusEmploymentOfficeBuffer1); alternative.AddUtilityTerm(211, logOfOnePlusEmploymentServiceBuffer1); alternative.AddUtilityTerm(212, logOfOnePlusHouseholdsBuffer1); //alternative.AddUtilityTerm(213, logOfOnePlusStudentsK12Buffer1); alternative.AddUtilityTerm(214, logOfOnePlusStudentsUniversityBuffer1); //alternative.AddUtilityTerm(215, logOfOnePlusEmploymentTotalBuffer1); // Size terms alternative.AddUtilityTerm(220, destinationParcel.EmploymentEducation); alternative.AddUtilityTerm(221, destinationParcel.EmploymentFood); alternative.AddUtilityTerm(222, destinationParcel.EmploymentGovernment); alternative.AddUtilityTerm(223, destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(224, destinationParcel.EmploymentRetail); alternative.AddUtilityTerm(225, destinationParcel.EmploymentService); alternative.AddUtilityTerm(226, destinationParcel.EmploymentMedical); alternative.AddUtilityTerm(227, destinationParcel.Households); alternative.AddUtilityTerm(228, destinationParcel.StudentsUniversity); alternative.AddUtilityTerm(229, destinationParcel.GetStudentsK12()); } else if (_tour.DestinationPurpose == Global.Settings.Purposes.Medical) { alternative.AddUtilityTerm(230, piecewiseDistanceFrom0To1Mile); alternative.AddUtilityTerm(231, piecewiseDistanceFrom1To3AndAHalfMiles); alternative.AddUtilityTerm(232, piecewiseDistanceFrom3AndAHalfTo10Miles); alternative.AddUtilityTerm(233, piecewiseDistanceFrom10MilesToInfinity); //alternative.AddUtilityTerm(234, aggregateLogsumHomeBased); // Neighborhood //alternative.AddUtilityTerm(240, logOfOnePlusEmploymentEducationBuffer1); //alternative.AddUtilityTerm(241, logOfOnePlusEmploymentOfficeBuffer1); //alternative.AddUtilityTerm(242, logOfOnePlusEmploymentServiceBuffer1); //alternative.AddUtilityTerm(243, logOfOnePlusEmploymentMedicalBuffer1); alternative.AddUtilityTerm(244, logOfOnePlusHouseholdsBuffer1); //alternative.AddUtilityTerm(245, logOfOnePlusStudentsUniversityBuffer1); //alternative.AddUtilityTerm(246, logOfOnePlusEmploymentGovernmentBuffer1); alternative.AddUtilityTerm(247, logOfOnePlusEmploymentRetailBuffer1); // Size terms //(for application) alternative.AddUtilityTerm(250, destinationParcel.EmploymentEducation); //(for application) alternative.AddUtilityTerm(251, destinationParcel.EmploymentFood); //(for application) alternative.AddUtilityTerm(252, destinationParcel.EmploymentGovernment); //(for application) alternative.AddUtilityTerm(253, destinationParcel.EmploymentOffice); //(for application) alternative.AddUtilityTerm(254, destinationParcel.EmploymentRetail); //(for application) alternative.AddUtilityTerm(255, destinationParcel.EmploymentService); alternative.AddUtilityTerm(256, destinationParcel.EmploymentMedical); //(for application) alternative.AddUtilityTerm(257, destinationParcel.EmploymentIndustrial + destinationParcel.EmploymentAgricultureConstruction); //(for application) alternative.AddUtilityTerm(258, destinationParcel.Households); //(for application) alternative.AddUtilityTerm(259, destinationParcel.GetStudentsK12()); } }
public void SetUtilities(ISampleItem sampleItem, int sampleFrequency) { if (sampleItem == null) { throw new ArgumentNullException("sampleItem"); } ChoiceProbabilityCalculator.Alternative alternative = sampleItem.Alternative; if (!alternative.Available) { return; } IHouseholdWrapper household = _tour.Household; IPersonWrapper person = _tour.Person; // var personDay = _tour.PersonDay; bool householdHasChildren = household.HasChildren; IParcelWrapper destinationParcel = ChoiceModelFactory.Parcels[sampleItem.ParcelId]; double fastestTravelTime = ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Hov3, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, _fastestAvailableTimeOfDay, _tour.OriginParcel, destinationParcel).Variable + ImpedanceRoster.GetValue("ivtime", Global.Settings.Modes.Hov3, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, _fastestAvailableTimeOfDay, destinationParcel, _tour.OriginParcel).Variable; if (fastestTravelTime >= _maxAvailableMinutes) { alternative.Available = false; return; } alternative.Choice = destinationParcel; double tourLogsum; if (_tour.IsHomeBasedTour) { if (_tour.DestinationPurpose == Global.Settings.Purposes.Escort) { ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <EscortTourModeModel>().RunNested(_tour, destinationParcel); tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } else { ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <OtherHomeBasedTourModeModel>().RunNested(_tour, destinationParcel); tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } } else { ChoiceProbabilityCalculator.Alternative nestedAlternative = Global.ChoiceModelSession.Get <WorkBasedSubtourModeModel>().RunNested(_tour, destinationParcel); tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum(); } //var purpose = _tour.TourPurposeSegment; int carOwnership = person.GetCarOwnershipSegment(); //var votSegment = _tour.VotALSegment; //var transitAccess = destinationParcel.TransitAccessSegment(); //var aggregateLogsum = Global.AggregateLogsums[destinationParcel.ZoneId][purpose][carOwnership][votSegment][transitAccess]; //var aggregateLogsumHomeBased = Global.AggregateLogsums[destinationParcel.ZoneId][Global.Settings.Purposes.HomeBasedComposite][carOwnership][votSegment][transitAccess]; //var aggregateLogsumWorkBased = Global.AggregateLogsums[destinationParcel.ZoneId][Global.Settings.Purposes.Work_BASED][carOwnership][votSegment][transitAccess]; //distanceFromOrigin is in units of 10 miles, so 1=10 miles double distanceFromOrigin = _tour.OriginParcel.DistanceFromOrigin(destinationParcel, _tour.DestinationArrivalTime); double distanceFromOrigin0 = Math.Max(0, Math.Min(distanceFromOrigin - .5, 1 - .5)); double distanceFromOrigin3 = Math.Max(0, distanceFromOrigin - 1); //distance over 10 miles double distanceFromOrigin4 = Math.Min(distanceFromOrigin, .10); //distance up to 1 mile double distanceFromOrigin5 = Math.Max(0, Math.Min(distanceFromOrigin - .1, .5 - .1)); //distance between 1 and 5 miles double distanceFromOrigin8 = Math.Max(0, Math.Min(distanceFromOrigin - .1, .35 - .1)); double distanceFromOrigin9 = Math.Max(0, Math.Min(distanceFromOrigin - .35, 1 - .35)); double distanceFromOriginLog = Math.Log(1 + distanceFromOrigin); double distanceFromWorkLog = person.UsualWorkParcel.DistanceFromWorkLog(destinationParcel, 1); double distanceFromSchoolLog = person.UsualSchoolParcel.DistanceFromSchoolLog(destinationParcel, 1); double timePressure = Math.Log(1 - fastestTravelTime / _maxAvailableMinutes); // log transforms of buffers for Neighborhood effects double empEduBuffer = Math.Log(destinationParcel.EmploymentEducationBuffer1 + 1.0); double empFooBuffer = Math.Log(destinationParcel.EmploymentFoodBuffer1 + 1.0); // var EMPGOV_B = Math.Log(destinationParcel.EmploymentGovernmentBuffer1 + 1.0); double empOfcBuffer = Math.Log(destinationParcel.EmploymentOfficeBuffer1 + 1.0); double empRetBuffer = Math.Log(destinationParcel.EmploymentRetailBuffer1 + 1.0); double empSvcBuffer = Math.Log(destinationParcel.EmploymentServiceBuffer1 + 1.0); double empMedBuffer = Math.Log(destinationParcel.EmploymentMedicalBuffer1 + 1.0); // var EMPIND_B = Math.Log(destinationParcel.EmploymentIndustrialBuffer1 + destinationParcel.EmploymentAgricultureConstructionBuffer1 + 1.0); double empTotBuffer = Math.Log(destinationParcel.EmploymentTotalBuffer1 + 1.0); double housesBuffer = Math.Log(destinationParcel.HouseholdsBuffer1 + 1.0); double studK12Buffer = Math.Log(destinationParcel.StudentsK8Buffer1 + destinationParcel.StudentsHighSchoolBuffer1 + 1.0); double studUniBuffer = Math.Log(destinationParcel.StudentsUniversityBuffer1 + 1.0); // var EMPHOU_B = Math.Log(destinationParcel.EmploymentTotalBuffer1 + destinationParcel.HouseholdsBuffer1 + 1.0); // connectivity attributes double c34Ratio = destinationParcel.C34RatioBuffer1(); int carCompetitionFlag = FlagUtility.GetCarCompetitionFlag(carOwnership); // exludes no cars int noCarCompetitionFlag = FlagUtility.GetNoCarCompetitionFlag(carOwnership); int noCarsFlag = FlagUtility.GetNoCarsFlag(carOwnership); alternative.AddUtilityTerm(1, sampleItem.AdjustmentFactor); alternative.AddUtilityTerm(2, (_tour.IsHomeBasedTour).ToFlag() * timePressure); alternative.AddUtilityTerm(3, _secondaryFlag * _workOrSchoolPatternFlag * distanceFromOrigin0); alternative.AddUtilityTerm(4, _secondaryFlag * _otherPatternFlag * distanceFromOrigin5); alternative.AddUtilityTerm(5, _secondaryFlag * _otherPatternFlag * distanceFromOrigin0); alternative.AddUtilityTerm(6, _secondaryFlag * _otherPatternFlag * distanceFromOrigin3); alternative.AddUtilityTerm(7, (!_tour.IsHomeBasedTour).ToFlag() * distanceFromOriginLog); //new calibration constants work-based tours alternative.AddUtilityTerm(58, (!_tour.IsHomeBasedTour).ToFlag() * distanceFromOrigin4); alternative.AddUtilityTerm(59, (!_tour.IsHomeBasedTour).ToFlag() * distanceFromOrigin3); alternative.AddUtilityTerm(60, (!_tour.IsHomeBasedTour).ToFlag() * distanceFromOrigin5); alternative.AddUtilityTerm(8, household.Has0To15KIncome.ToFlag() * distanceFromOriginLog); alternative.AddUtilityTerm(9, household.HasMissingIncome.ToFlag() * distanceFromOriginLog); alternative.AddUtilityTerm(10, person.IsRetiredAdult.ToFlag() * distanceFromOriginLog); alternative.AddUtilityTerm(11, person.IsChildAge5Through15.ToFlag() * distanceFromOriginLog); alternative.AddUtilityTerm(12, person.IsChildUnder5.ToFlag() * distanceFromOriginLog); alternative.AddUtilityTerm(13, (_tour.IsHomeBasedTour).ToFlag() * distanceFromSchoolLog); alternative.AddUtilityTerm(14, distanceFromWorkLog); alternative.AddUtilityTerm(15, carCompetitionFlag * destinationParcel.ParkingHourlyEmploymentCommercialMixInParcel()); alternative.AddUtilityTerm(16, noCarCompetitionFlag * destinationParcel.ParkingHourlyEmploymentCommercialMixInParcel()); alternative.AddUtilityTerm(17, carCompetitionFlag * destinationParcel.ParkingHourlyEmploymentCommercialMixBuffer1()); alternative.AddUtilityTerm(18, noCarCompetitionFlag * destinationParcel.ParkingHourlyEmploymentCommercialMixBuffer1()); alternative.AddUtilityTerm(19, noCarsFlag * c34Ratio); if (_tour.DestinationPurpose == Global.Settings.Purposes.Escort) { alternative.AddUtilityTerm(20, tourLogsum); alternative.AddUtilityTerm(21, distanceFromOrigin4); alternative.AddUtilityTerm(22, distanceFromOrigin8); alternative.AddUtilityTerm(23, distanceFromOrigin9); // Neighborhood alternative.AddUtilityTerm(24, householdHasChildren.ToFlag() * studK12Buffer); alternative.AddUtilityTerm(25, empTotBuffer); // Size terms alternative.AddUtilityTerm(71, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentEducation); alternative.AddUtilityTerm(72, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentFood); alternative.AddUtilityTerm(73, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentGovernment); alternative.AddUtilityTerm(74, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(75, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentRetail); alternative.AddUtilityTerm(76, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentService); alternative.AddUtilityTerm(77, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentMedical); alternative.AddUtilityTerm(78, (!householdHasChildren).ToFlag() * destinationParcel.EmploymentIndustrial + destinationParcel.EmploymentAgricultureConstruction); alternative.AddUtilityTerm(79, (!householdHasChildren).ToFlag() * destinationParcel.Households); alternative.AddUtilityTerm(80, householdHasChildren.ToFlag() * destinationParcel.EmploymentEducation); alternative.AddUtilityTerm(81, householdHasChildren.ToFlag() * destinationParcel.EmploymentGovernment); alternative.AddUtilityTerm(82, householdHasChildren.ToFlag() * destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(83, householdHasChildren.ToFlag() * destinationParcel.EmploymentRetail); alternative.AddUtilityTerm(84, householdHasChildren.ToFlag() * destinationParcel.EmploymentService); alternative.AddUtilityTerm(85, householdHasChildren.ToFlag() * destinationParcel.EmploymentMedical); alternative.AddUtilityTerm(86, householdHasChildren.ToFlag() * destinationParcel.EmploymentIndustrial + destinationParcel.EmploymentAgricultureConstruction); alternative.AddUtilityTerm(87, householdHasChildren.ToFlag() * destinationParcel.Households); alternative.AddUtilityTerm(88, householdHasChildren.ToFlag() * destinationParcel.GetStudentsK12()); } else if (_tour.DestinationPurpose == Global.Settings.Purposes.PersonalBusiness || _tour.DestinationPurpose == Global.Settings.Purposes.Medical) { alternative.AddUtilityTerm(26, tourLogsum); alternative.AddUtilityTerm(27, distanceFromOrigin4); alternative.AddUtilityTerm(28, distanceFromOrigin8); alternative.AddUtilityTerm(29, distanceFromOrigin9); alternative.AddUtilityTerm(30, distanceFromOrigin3); // Neighborhood alternative.AddUtilityTerm(31, empEduBuffer); alternative.AddUtilityTerm(32, empSvcBuffer); alternative.AddUtilityTerm(33, empMedBuffer); alternative.AddUtilityTerm(34, housesBuffer); // also psrc alternative.AddUtilityTerm(35, studUniBuffer); // Size terms alternative.AddUtilityTerm(89, destinationParcel.EmploymentEducation); alternative.AddUtilityTerm(90, destinationParcel.EmploymentFood); alternative.AddUtilityTerm(91, destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(92, destinationParcel.EmploymentRetail); alternative.AddUtilityTerm(93, destinationParcel.EmploymentService); alternative.AddUtilityTerm(94, destinationParcel.EmploymentMedical); alternative.AddUtilityTerm(95, destinationParcel.EmploymentIndustrial + destinationParcel.EmploymentAgricultureConstruction); alternative.AddUtilityTerm(96, destinationParcel.Households); alternative.AddUtilityTerm(97, destinationParcel.GetStudentsK12()); } else if (_tour.DestinationPurpose == Global.Settings.Purposes.Shopping) { alternative.AddUtilityTerm(36, tourLogsum); alternative.AddUtilityTerm(37, distanceFromOrigin4); alternative.AddUtilityTerm(38, distanceFromOrigin8); alternative.AddUtilityTerm(39, distanceFromOrigin9); alternative.AddUtilityTerm(40, distanceFromOrigin3); // Neighborhood alternative.AddUtilityTerm(41, empEduBuffer); // also psrc alternative.AddUtilityTerm(42, empRetBuffer); // also psrc // Size terms alternative.AddUtilityTerm(98, destinationParcel.EmploymentFood); alternative.AddUtilityTerm(99, destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(100, destinationParcel.EmploymentRetail); alternative.AddUtilityTerm(101, destinationParcel.EmploymentService); } else if (_tour.DestinationPurpose == Global.Settings.Purposes.Meal) { alternative.AddUtilityTerm(43, tourLogsum); alternative.AddUtilityTerm(44, distanceFromOrigin4); alternative.AddUtilityTerm(45, distanceFromOrigin8); alternative.AddUtilityTerm(46, distanceFromOrigin9); alternative.AddUtilityTerm(47, distanceFromOrigin3); // Neighborhood alternative.AddUtilityTerm(48, empFooBuffer); // psrc // Size terms alternative.AddUtilityTerm(102, destinationParcel.EmploymentFood); alternative.AddUtilityTerm(103, destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(104, destinationParcel.EmploymentTotal); alternative.AddUtilityTerm(105, destinationParcel.Households); } else if (_tour.DestinationPurpose == Global.Settings.Purposes.Social || _tour.DestinationPurpose == Global.Settings.Purposes.Recreation) { alternative.AddUtilityTerm(49, tourLogsum); alternative.AddUtilityTerm(50, distanceFromOrigin4); alternative.AddUtilityTerm(51, distanceFromOrigin8); alternative.AddUtilityTerm(52, distanceFromOrigin9); alternative.AddUtilityTerm(53, distanceFromOrigin3); // Neighborhood alternative.AddUtilityTerm(54, empOfcBuffer); // also psrc alternative.AddUtilityTerm(55, empSvcBuffer); // also psrc alternative.AddUtilityTerm(56, housesBuffer); // also psrc alternative.AddUtilityTerm(57, studUniBuffer); // psrc // Size terms alternative.AddUtilityTerm(106, destinationParcel.EmploymentFood); alternative.AddUtilityTerm(107, destinationParcel.EmploymentGovernment); alternative.AddUtilityTerm(108, destinationParcel.EmploymentOffice); alternative.AddUtilityTerm(109, destinationParcel.EmploymentRetail); alternative.AddUtilityTerm(110, destinationParcel.EmploymentService); alternative.AddUtilityTerm(111, destinationParcel.Households); alternative.AddUtilityTerm(112, destinationParcel.StudentsUniversity); alternative.AddUtilityTerm(113, destinationParcel.GetStudentsK12()); //new size variable for log(sq ft open space) if (destinationParcel.LandUseCode > 0) { alternative.AddUtilityTerm(120, (Global.Configuration.UseParcelLandUseCodeAsSquareFeetOpenSpace) ? Math.Log(destinationParcel.LandUseCode + 1.0) : 0.0); } } //add any region-specific new terms in region-specific class, using coefficient numbers 114-120, or other unused variable # _parentClass.RegionSpecificOtherTourDistrictCoefficients(alternative, _tour, destinationParcel); // OD shadow pricing if (Global.Configuration.ShouldUseODShadowPricing) { int ori = _tour.OriginParcel.District; int des = destinationParcel.District; //var first = res <= des? res : des; //var second = res <= des? des : res; double shadowPriceConfigurationParameter = ori == des ? Global.Configuration.OtherTourDestinationOOShadowPriceCoefficient : Global.Configuration.OtherTourDestinationODShadowPriceCoefficient; int odShadowPriceF12Value = MAX_REGULAR_PARAMETER + Global.Configuration.NumberOfODShadowPricingDistricts * (ori - 1) + des; alternative.AddUtilityTerm(odShadowPriceF12Value, shadowPriceConfigurationParameter); } }