private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, TourWrapper tour, HouseholdDayWrapper householdDay, int sampleSize, IParcelWrapper choice = null)
        {
            timesStartedRunModel++;
            HouseholdWrapper household = (HouseholdWrapper)tour.Household;
            PersonWrapper    person    = (PersonWrapper)tour.Person;
            PersonDayWrapper personDay = (PersonDayWrapper)tour.PersonDay;

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


            TimeWindow timeWindow = new TimeWindow();

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

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

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


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

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

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

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



            ChoiceModelUtility.DrawRandomTourTimePeriods(tour, tourCategory);

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

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


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

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

            int index = 0;

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

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

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


                if (!available)
                {
                    continue;
                }

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

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

                    continue;
                }

                alternative.Choice = destinationParcel;

                double tourLogsum;

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

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

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

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


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

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

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

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

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

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


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


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

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

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

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

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

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

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

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

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

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

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

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

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

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


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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    // Size terms
                    alternative.AddUtilityTerm(190, destinationParcel.EmploymentEducation);
                    alternative.AddUtilityTerm(191, destinationParcel.EmploymentGovernment);
                    alternative.AddUtilityTerm(192, destinationParcel.EmploymentIndustrial);
                    alternative.AddUtilityTerm(193, destinationParcel.EmploymentOffice);
                    alternative.AddUtilityTerm(194, destinationParcel.EmploymentRetail);
                    // GV 195 is fixed to zero
                    alternative.AddUtilityTerm(195, destinationParcel.EmploymentService);
                    alternative.AddUtilityTerm(196, destinationParcel.EmploymentAgricultureConstruction);
                    alternative.AddUtilityTerm(197, destinationParcel.EmploymentTotal);
                    alternative.AddUtilityTerm(198, destinationParcel.Households);
                }
            }
        }
Esempio n. 2
0
            public void SetUtilities(ISampleItem sampleItem, int sampleFrequency)
            {
                if (sampleItem == null)
                {
                    throw new ArgumentNullException("sampleItem");
                }

                var alternative = sampleItem.Alternative;

                if (!alternative.Available)
                {
                    return;
                }

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

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

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

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

                    return;
                }

                alternative.Choice = destinationParcel;

                double tourLogsum;

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

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

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

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

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

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

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

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

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

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

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

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

                alternative.AddUtilityTerm(19, noCarsFlag * c34Ratio);


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

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

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

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

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


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

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

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

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

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

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

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

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

                // OD shadow pricing
                if (Global.Configuration.ShouldUseODShadowPricing)
                {
                    var ori = _tour.OriginParcel.District;
                    var des = destinationParcel.District;
                    //var first = res <= des? res : des;
                    //var second = res <= des? des : res;
                    var shadowPriceConfigurationParameter = ori == des ? Global.Configuration.OtherTourDestinationOOShadowPriceCoefficient : Global.Configuration.OtherTourDestinationODShadowPriceCoefficient;
                    var odShadowPriceF12Value             = MAX_REGULAR_PARAMETER + Global.Configuration.NumberOfODShadowPricingDistricts * (ori - 1) + des;
                    alternative.AddUtilityTerm(odShadowPriceF12Value, shadowPriceConfigurationParameter);
                }
            }
Esempio n. 3
0
        private double[][][][] ComputeZone(IRandomUtility randomUtility, int id)
        {
            var purposes = new double[Global.Settings.Purposes.TotalPurposes][][][];

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

                purposes[purpose] = carOwnerships;

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

                    carOwnerships[carOwnership] = votALSegments;

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

                        votALSegments[votALSegment] = transitAccesses;

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

            IZone origin;

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

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

                //const double parkingCost = 0;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                                    if (setImpedance)
                                    {
                                        setImpedance = false;

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

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

                                        walkGenTime = walkPath.GeneralizedTimeLogsum;


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

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

                                        sovGenTime = sovPath.GeneralizedTimeLogsum;

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

                                        hov2GenTime = hov2Path.GeneralizedTimeLogsum;

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

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

                                        transitGenTime = transitPath.GeneralizedTimeLogsum;
                                    }

                                    var modeUtilitySum = 0D;

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

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

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

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

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

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

                                        break;

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

                                        break;

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

                                        break;
                                    }
                                }

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

            return(purposes);
        }
Esempio n. 4
0
            public void SetUtilities(ISampleItem sampleItem, int sampleFrequency)
            {
                if (sampleItem == null)
                {
                    throw new ArgumentNullException("sampleItem");
                }

                var alternative = sampleItem.Alternative;

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

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

                var excludedParcel      = person.UsualWorkParcel == null || person.UsualWorkParcelId == household.ResidenceParcelId || _tour.DestinationPurpose != Global.Settings.Purposes.Work || _tour.GetTourCategory() == Global.Settings.TourCategories.WorkBased ? null : person.UsualWorkParcel;
                var usualWorkParcel     = (excludedParcel != null && excludedParcel.Id == destinationParcel.Id);             // only 1 for oddball alternative on tours with oddball alternative
                var usualWorkParcelFlag = usualWorkParcel.ToFlag();

                // Comment out these nesting calls when estimating the conditional flat model
                // model is NL with oddball alternative
                if (usualWorkParcelFlag == 0)
                {
                    // this alternative is in the non-oddball nest
                    alternative.AddNestedAlternative(_sampleSize + 2, 0, 60);                     // associates alternative with non-oddball nest
                }
                else
                {
                    // this is the oddball alternative
                    alternative.AddNestedAlternative(_sampleSize + 3, 1, 60);                     // associates alternative with oddball nest
                }


                if (!alternative.Available)
                {
                    return;
                }


                // use this block of code to eliminate the oddball alternative for estimation of the conditional model
                //if (usualWorkParcelFlag == 1) {
                //	alternative.Available = false;
                //
                //	return;
                //}

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

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

                    return;
                }

                alternative.Choice = destinationParcel;

                double tourLogsum;

                if (_tour.IsHomeBasedTour)
                {
                    var nestedAlternative = Global.ChoiceModelSession.Get <WorkTourModeModel>().RunNested(_tour, destinationParcel, household.VehiclesAvailable, person.GetTransitFareDiscountFraction());
                    tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                }
                else
                {
                    var nestedAlternative = Global.ChoiceModelSession.Get <WorkBasedSubtourModeModel>().RunNested(_tour, destinationParcel);
                    tourLogsum = nestedAlternative == null ? 0 : nestedAlternative.ComputeLogsum();
                }

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

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

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

                // log transforms of buffers for Neighborhood effects
                var empEduBuffer = Math.Log(destinationParcel.EmploymentEducationBuffer1 + 1.0);
//				var EMPFOO_B = Math.Log(destinationParcel.EmploymentFoodBuffer1 + 1.0);
//				var EMPGOV_B = Math.Log(destinationParcel.EmploymentGovernmentBuffer1 + 1.0);
                var empOfcBuffer = Math.Log(destinationParcel.EmploymentOfficeBuffer1 + 1.0);
//				var EMPRET_B = Math.Log(destinationParcel.EmploymentRetailBuffer1 + 1.0);
//				var EMPSVC_B = Math.Log(destinationParcel.EmploymentServiceBuffer1 + 1.0);
//				var EMPMED_B = Math.Log(destinationParcel.EmploymentMedicalBuffer1 + 1.0);
                var empIndBuffer = Math.Log(destinationParcel.EmploymentIndustrialBuffer1 + destinationParcel.EmploymentAgricultureConstructionBuffer1 + 1.0);
//				var EMPTOT_B = Math.Log(destinationParcel.EmploymentTotalBuffer1 + 1.0);
                var housesBuffer = Math.Log(destinationParcel.HouseholdsBuffer1 + 1.0);
//				var STUDK12B = Math.Log(destinationParcel.StudentsK8Buffer1 + destinationParcel.StudentsHighSchoolBuffer1 + 1.0);
//				var STUDUNIB = Math.Log(destinationParcel.StudentsUniversityBuffer1 + 1.0);
//				var EMPHOU_B = Math.Log(destinationParcel.EmploymentTotalBuffer1 + destinationParcel.HouseholdsBuffer1 + 1.0);

                // parking attributes
//				var parcelParkingDensity = destinationParcel.ParcelParkingPerTotalEmployment();
//				var zoneParkingDensity = destinationParcel.ZoneParkingPerTotalEmploymentAndK12UniversityStudents(destinationZoneTotals, millionsSquareFeet);
//				var ParkingPaidDailyLogBuffer1 = Math.Log(1 + destinationParcel.ParkingOffStreetPaidDailySpacesBuffer1);

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

                //				var carDeficitFlag = FlagUtility.GetCarDeficitFlag(carOwnership);  // includes no cars
                //				var carCompetitionFlag = FlagUtility.GetCarCompetitionFlag(carOwnership); // exludes no cars
                var noCarCompetitionFlag = FlagUtility.GetNoCarCompetitionFlag(carOwnership);

                //				var noCarsFlag = FlagUtility.GetNoCarsFlag(carOwnership);

                // Usual location attributes
                alternative.AddUtilityTerm(1, usualWorkParcelFlag);
                alternative.AddUtilityTerm(2, person.IsPartTimeWorker.ToFlag() * usualWorkParcelFlag);
                alternative.AddUtilityTerm(3, person.IsStudentAge.ToFlag() * usualWorkParcelFlag);
                alternative.AddUtilityTerm(4, _primaryFlag * personDay.TwoOrMoreWorkToursExist().ToFlag() * usualWorkParcelFlag);
                alternative.AddUtilityTerm(5, personDay.WorkStopsExist().ToFlag() * usualWorkParcelFlag);
                alternative.AddUtilityTerm(6, _secondaryFlag * usualWorkParcelFlag);

                // non-usual location attributes
                alternative.AddUtilityTerm(11, (!usualWorkParcel).ToFlag() * sampleItem.AdjustmentFactor);
                alternative.AddUtilityTerm(12, _tour.IsHomeBasedTour.ToFlag() * (!usualWorkParcel).ToFlag() * timePressure);

                alternative.AddUtilityTerm(13, (!usualWorkParcel).ToFlag() * person.IsFulltimeWorker.ToFlag() * tourLogsum);
                alternative.AddUtilityTerm(14, (!usualWorkParcel).ToFlag() * person.IsPartTimeWorker.ToFlag() * tourLogsum);
                alternative.AddUtilityTerm(15, (!usualWorkParcel).ToFlag() * person.IsNotFullOrPartTimeWorker.ToFlag() * tourLogsum);
                alternative.AddUtilityTerm(16, (!usualWorkParcel).ToFlag() * person.IsRetiredAdult.ToFlag() * distanceFromOriginLog);

                alternative.AddUtilityTerm(17, (!usualWorkParcel).ToFlag() * distanceFromWorkLog);
                alternative.AddUtilityTerm(18, (!usualWorkParcel).ToFlag() * person.IsStudentAge.ToFlag() * distanceFromSchoolLog);

                alternative.AddUtilityTerm(19, (!usualWorkParcel).ToFlag() * noCarCompetitionFlag * destinationParcel.ParkingHourlyEmploymentCommercialMixBuffer1());

                // non-usual location Neighborhood attributes
                alternative.AddUtilityTerm(31, (!usualWorkParcel).ToFlag() * empEduBuffer);
                alternative.AddUtilityTerm(32, (!usualWorkParcel).ToFlag() * empOfcBuffer);
                alternative.AddUtilityTerm(33, (!usualWorkParcel).ToFlag() * housesBuffer);
                alternative.AddUtilityTerm(34, (!usualWorkParcel).ToFlag() * empIndBuffer);

                // non-usual location Size terms (consider conditioning these by fulltime, parttime, notFTPT, an income (see original sacog spec)
                alternative.AddUtilityTerm(40, (!usualWorkParcel).ToFlag() * destinationParcel.EmploymentEducation);
                alternative.AddUtilityTerm(41, (!usualWorkParcel).ToFlag() * destinationParcel.EmploymentFood);
                alternative.AddUtilityTerm(42, (!usualWorkParcel).ToFlag() * destinationParcel.EmploymentGovernment);
                alternative.AddUtilityTerm(43, (!usualWorkParcel).ToFlag() * destinationParcel.EmploymentOffice);
                alternative.AddUtilityTerm(44, (!usualWorkParcel).ToFlag() * destinationParcel.EmploymentRetail);
                alternative.AddUtilityTerm(45, (!usualWorkParcel).ToFlag() * destinationParcel.EmploymentService);
                alternative.AddUtilityTerm(46, (!usualWorkParcel).ToFlag() * destinationParcel.EmploymentMedical);
                alternative.AddUtilityTerm(47, (!usualWorkParcel).ToFlag() * destinationParcel.EmploymentIndustrial + destinationParcel.EmploymentAgricultureConstruction);
                alternative.AddUtilityTerm(48, (!usualWorkParcel).ToFlag() * destinationParcel.Households);
                alternative.AddUtilityTerm(49, (!usualWorkParcel).ToFlag() * destinationParcel.StudentsUniversity);

                //		// usual location size term
                //		alternative.AddUtilityTerm(50, usualWorkParcelFlag * 1);

                //		// Comment out these nesting calls when estimating the conditional flat model
                //		// model is NL with oddball alternative
                //		if (usualWorkParcelFlag == 0) {
                //			// this alternative is in the non-oddball nest
                //			alternative.AddNestedAlternative(_sampleSize + 2, 0, 60); // associates alternative with non-oddball nest
                //		}
                //		else {
                //			// this is the oddball alternative
                //			alternative.AddNestedAlternative(_sampleSize + 3, 1, 60); // associates alternative with oddball nest
                //		}
            }