예제 #1
0
        public static void SignalShutdown()
        {
            if (ThreadQueue == null)
            {
                return;
            }

            ThreadQueue.Shutdown();

            HouseholdWrapper.Close();
            PersonWrapper.Close();
            HouseholdDayWrapper.Close();
            PersonDayWrapper.Close();
            TourWrapper.Close();
            TripWrapper.Close();
            if (!string.IsNullOrEmpty(Global.Configuration.OutputJointTourPath))
            {
                JointTourWrapper.Close();
            }
            if (!string.IsNullOrEmpty(Global.Configuration.OutputFullHalfTourPath))
            {
                FullHalfTourWrapper.Close();
            }
            if (!string.IsNullOrEmpty(Global.Configuration.OutputPartialHalfTourPath))
            {
                PartialHalfTourWrapper.Close();
            }
        }
예제 #2
0
파일: TripTest.cs 프로젝트: sfcta/DaySim
        public void TestTripWrapperByOriginDestination()
        {
            Global.Configuration = new Configuration {
                HouseholdSamplingRateOneInX = 256
            };
            Trip trip = new Trip {
                HalfTour = 1, OriginPurpose = Constants.Purpose.ESCORT, DestinationPurpose = Constants.Purpose.NONE_OR_HOME
            };
            TourWrapper tour = TestHelper.GetTourWrapper();

            TourWrapper.HalfTour halfTour = new TourWrapper.HalfTour(tour);
            TripWrapper          wrapper  = new TripWrapper(trip, tour, halfTour);

            Assert.Equal(true, wrapper.IsEscortPurposeByDestination);
            Assert.Equal(false, wrapper.IsNoneOrHomePurposeByDestination);
            Assert.Equal(false, wrapper.IsWorkPurposeByDestination);
            Assert.Equal(false, wrapper.IsEscortPurposeByOrigin);
            Assert.Equal(true, wrapper.IsNoneOrHomePurposeByOrigin);
            Assert.Equal(false, wrapper.IsWorkPurposeByOrigin);

            trip = new Trip {
                HalfTour = 1, OriginPurpose = Constants.Purpose.NONE_OR_HOME, DestinationPurpose = Constants.Purpose.WORK
            };
            wrapper = new TripWrapper(trip, tour, halfTour);
            Assert.Equal(false, wrapper.IsEscortPurposeByDestination);
            Assert.Equal(true, wrapper.IsNoneOrHomePurposeByDestination);
            Assert.Equal(false, wrapper.IsWorkPurposeByDestination);
            Assert.Equal(false, wrapper.IsEscortPurposeByOrigin);
            Assert.Equal(false, wrapper.IsNoneOrHomePurposeByOrigin);
            Assert.Equal(true, wrapper.IsWorkPurposeByOrigin);

            trip = new Trip {
                HalfTour = 1, OriginPurpose = Constants.Purpose.WORK, DestinationPurpose = Constants.Purpose.ESCORT
            };
            wrapper = new TripWrapper(trip, tour, halfTour);
            Assert.Equal(false, wrapper.IsEscortPurposeByDestination);
            Assert.Equal(false, wrapper.IsNoneOrHomePurposeByDestination);
            Assert.Equal(true, wrapper.IsWorkPurposeByDestination);
            Assert.Equal(true, wrapper.IsEscortPurposeByOrigin);
            Assert.Equal(false, wrapper.IsNoneOrHomePurposeByOrigin);
            Assert.Equal(false, wrapper.IsWorkPurposeByOrigin);

            trip = new Trip {
                HalfTour = 1, OriginPurpose = Constants.Purpose.BUSINESS, DestinationPurpose = Constants.Purpose.BUSINESS
            };
            wrapper = new TripWrapper(trip, tour, halfTour);
            Assert.Equal(false, wrapper.IsEscortPurposeByDestination);
            Assert.Equal(false, wrapper.IsNoneOrHomePurposeByDestination);
            Assert.Equal(false, wrapper.IsWorkPurposeByDestination);
            Assert.Equal(false, wrapper.IsEscortPurposeByOrigin);
            Assert.Equal(false, wrapper.IsNoneOrHomePurposeByOrigin);
            Assert.Equal(false, wrapper.IsWorkPurposeByOrigin);
        }
예제 #3
0
        public void Run(HouseholdDayWrapper householdDay, TripWrapper trip)
        {
            if (trip == null)
            {
                throw new ArgumentNullException("trip");
            }

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

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

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

            if (_helpers[ParallelUtility.threadLocalAssignedIndex.Value].ModelIsInEstimationMode)
            {
                if (trip.DestinationParcel == null || trip.OriginParcel == null || trip.Mode <= Global.Settings.Modes.None || trip.Mode == Global.Settings.Modes.Other)
                {
                    return;
                }

                RunModel(choiceProbabilityCalculator, householdDay, trip, new HTripTime(trip.DepartureTime));

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

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

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

                var choice = (HTripTime)chosenAlternative.Choice;

                trip.DepartureTime = choice.GetRandomFeasibleMinute(trip, choice);
            }
        }
        public int Run(TripWrapper trip, HouseholdDayWrapper householdDay, int choice)
        {
            if (trip == null)
            {
                throw new ArgumentNullException("trip");
            }

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

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

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

            if (_helpers[ParallelUtility.threadLocalAssignedIndex.Value].ModelIsInEstimationMode)
            {
                if (trip.OriginParcel == null)
                {
                    return(Constants.DEFAULT_VALUE);
                }
                RunModel(choiceProbabilityCalculator, trip, householdDay, choice);

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

                var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(trip.Household.RandomUtility);
                choice = (int)chosenAlternative.Choice;
            }

            return(choice);
        }
예제 #5
0
파일: TripTest.cs 프로젝트: sfcta/DaySim
        public void TestTripWrapperIsBeforeMandatoryDestination()
        {
            Global.Configuration = new Configuration {
                HouseholdSamplingRateOneInX = 256
            };
            Trip        trip = new Trip();
            TourWrapper tour = TestHelper.GetTourWrapper();

            TourWrapper.HalfTour halfTour = new TourWrapper.HalfTour(tour);
            TripWrapper          wrapper  = new TripWrapper(trip, tour, halfTour);

            Assert.Equal(false, wrapper.IsBeforeMandatoryDestination);

            trip = new Trip {
                HalfTour = 1
            };
            wrapper = new TripWrapper(trip, tour, halfTour);
            tour.DestinationPurpose = Constants.Purpose.MEDICAL;
            Assert.Equal(false, wrapper.IsBeforeMandatoryDestination);

            tour.DestinationPurpose = Constants.Purpose.WORK;
            Assert.Equal(true, wrapper.IsBeforeMandatoryDestination);

            tour.DestinationPurpose = Constants.Purpose.PERSONAL_BUSINESS;
            Assert.Equal(false, wrapper.IsBeforeMandatoryDestination);

            tour.DestinationPurpose = Constants.Purpose.SCHOOL;
            Assert.Equal(true, wrapper.IsBeforeMandatoryDestination);

            trip = new Trip {
                HalfTour = 0
            };
            wrapper = new TripWrapper(trip, tour, halfTour);
            Assert.Equal(false, wrapper.IsBeforeMandatoryDestination);

            tour.DestinationPurpose = Constants.Purpose.WORK;
            Assert.Equal(false, wrapper.IsBeforeMandatoryDestination);
        }
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, TripWrapper trip, HouseholdDayWrapper householdDay, int choice = Constants.DEFAULT_VALUE)
        {
            var household  = (HouseholdWrapper)trip.Household;
            var person     = (PersonWrapper)trip.Person;
            var personDay  = (PersonDayWrapper)trip.PersonDay;
            var tour       = (TourWrapper)trip.Tour;
            var halfTour   = (TourWrapper.HalfTour)trip.HalfTour;
            var personDays = householdDay.PersonDays;

            var isJointTour                  = tour.JointTourSequence > 0 ? 1 : 0;
            var isIndividualTour             = isJointTour == 1 ? 0 : 1;
            var destinationParcel            = tour.DestinationParcel;
            var jointHalfOfFullJointHalfTour = ((trip.Direction == Global.Settings.TourDirections.OriginToDestination && tour.FullHalfTour1Sequence > 0) ||
                                                (trip.Direction == Global.Settings.TourDirections.DestinationToOrigin && tour.FullHalfTour2Sequence > 0)).ToFlag();
            var individualHalfOfFullJointHalfTour =
                ((trip.Direction == Global.Settings.TourDirections.OriginToDestination &&
                  tour.FullHalfTour1Sequence == 0 &&
                  tour.FullHalfTour2Sequence > 0) ||
                 (trip.Direction == Global.Settings.TourDirections.DestinationToOrigin &&
                  tour.FullHalfTour2Sequence == 0 &&
                  tour.FullHalfTour1Sequence > 0)).ToFlag();
            var individualHalfTour = (isIndividualTour == 1 || individualHalfOfFullJointHalfTour == 1) ? 1 : 0;
            var jointHalfTour      = 1 - individualHalfTour;

            //destination parcel variables
            var foodBuffer2   = 0.0;
            var totEmpBuffer2 = 0.0;
            var retailBuffer2 = 0.0;

            if (destinationParcel != null)
            {
                foodBuffer2   = Math.Log(1 + destinationParcel.EmploymentFoodBuffer2);
                totEmpBuffer2 = Math.Log(1 + destinationParcel.EmploymentTotalBuffer2);
                retailBuffer2 = Math.Log(1 + destinationParcel.EmploymentRetailBuffer2);
            }

            var carOwnership = person.GetCarOwnershipSegment();

            // household inputs
            var onePersonHouseholdFlag = household.IsOnePersonHousehold.ToFlag();
            //var householdInc75KP = household.Has75KPlusIncome;

            var votALSegment         = tour.GetVotALSegment();
            var transitAccessSegment = household.ResidenceParcel.TransitAccessSegment();

            var totalAggregateLogsum = Global.AggregateLogsums[household.ResidenceParcel.ZoneId]
                                       [Global.Settings.Purposes.HomeBasedComposite][carOwnership][votALSegment][transitAccessSegment];

            var homeFoodBuffer2   = Math.Log(1 + household.ResidenceParcel.EmploymentFoodBuffer2);
            var homeTotEmpBuffer2 = Math.Log(1 + household.ResidenceParcel.EmploymentTotalBuffer2);
            var homeRetailBuffer2 = Math.Log(1 + household.ResidenceParcel.EmploymentRetailBuffer2);

            // person-day inputs
            var homeBasedTours                 = personDay.HomeBasedTours;
            var simulatedToursFlag             = personDay.SimulatedToursExist().ToFlag();
            var simulatedBusinessStops         = personDay.SimulatedBusinessStops;
            int simulatedBusinessStopsFlag     = simulatedBusinessStops > 0 ? 1 : 0;
            var simulatedSchoolStops           = personDay.SimulatedSchoolStops;
            var simulatedEscortStops           = personDay.SimulatedEscortStops;
            var simulatedPersonalBusinessStops = personDay.SimulatedPersonalBusinessStops;
            var simulatedShoppingStops         = personDay.SimulatedShoppingStops;
            var simulatedMealStops             = personDay.SimulatedMealStops;
            var simulatedSocialStops           = personDay.SimulatedSocialStops;
            var simulatedRecreationStops       = personDay.SimulatedRecreationStops;
            var simulatedMedicalStops          = personDay.SimulatedMedicalStops;
            var primaryFamilyTimeFlag          = householdDay.PrimaryPriorityTimeFlag;

            // tour inputs
            var hovDriverTourFlag          = tour.IsHovDriverMode().ToFlag();
            var hovPassengerTourFlag       = tour.IsHovPassengerMode().ToFlag();
            var transitTourFlag            = tour.IsTransitMode().ToFlag();
            var walkTourFlag               = tour.IsWalkMode().ToFlag();
            var bikeTourFlag               = tour.IsBikeMode().ToFlag();
            var autoTourFlag               = tour.IsAnAutoMode().ToFlag();
            var notHomeBasedTourFlag       = (!tour.IsHomeBasedTour).ToFlag();
            var workTourFlag               = tour.IsWorkPurpose().ToFlag();
            var businessTourFlag           = tour.IsBusinessPurpose().ToFlag();
            var personalBusinessTourFlag   = tour.IsPersonalBusinessPurpose().ToFlag();
            var socialTourFlag             = tour.IsSocialPurpose().ToFlag();
            var socialOrRecreationTourFlag = tour.IsSocialOrRecreationPurpose().ToFlag();
            var schoolTourFlag             = tour.IsSchoolPurpose().ToFlag();
            var escortTourFlag             = tour.IsEscortPurpose().ToFlag();
            var shoppingTourFlag           = tour.IsShoppingPurpose().ToFlag();

            // trip inputs
            var oneSimulatedTripFlag           = halfTour.OneSimulatedTripFlag;
            var twoSimulatedTripsFlag          = halfTour.TwoSimulatedTripsFlag;
            var threeSimulatedTripsFlag        = halfTour.ThreeSimulatedTripsFlag;
            var fourSimulatedTripsFlag         = halfTour.FourSimulatedTripsFlag;
            var fivePlusSimulatedTripsFlag     = halfTour.FivePlusSimulatedTripsFlag;
            var twoPlusSimulatedTripsFlag      = twoSimulatedTripsFlag + threeSimulatedTripsFlag + fourSimulatedTripsFlag + fivePlusSimulatedTripsFlag;
            var halfTourFromOriginFlag         = trip.IsHalfTourFromOrigin.ToFlag();
            var halfTourFromDestinationFlag    = (!trip.IsHalfTourFromOrigin).ToFlag();
            var beforeMandatoryDestinationFlag = trip.IsBeforeMandatoryDestination().ToFlag();

            // remaining inputs, including joint tour variables

            var remainingToursCount = personDay.HomeBasedTours - personDay.GetTotalSimulatedTours();

            var destinationDepartureTime =
                trip.IsHalfTourFromOrigin         // first trip in half tour, use tour destination time
                                ? trip.Sequence == 1
                                          ? tour.DestinationArrivalTime
                                          : trip.GetPreviousTrip().ArrivalTime
                                : trip.Sequence == 1
                                          ? tour.DestinationDepartureTime
                                          : trip.GetPreviousTrip().ArrivalTime;

            //var time = trip.IsHalfTourFromOrigin ? tour.DestinationArrivalTime : tour.DestinationDepartureTime;
            var time = destinationDepartureTime;

            bool timeIsAvailableForAnotherTrip = true;

            if ((trip.IsHalfTourFromOrigin && time < Global.Settings.Times.FourAM) ||
                (!trip.IsHalfTourFromOrigin && time > Global.Settings.Times.TwoAM))
            {
                timeIsAvailableForAnotherTrip = false;
            }

            bool stopsNeeded = false;

            //if ((halfTour.SimulatedTrips <= 5)
            //	&& (timeIsAvailableForAnotherTrip)
            //	&& (trip.Direction == 2)
            //	&&((trip.Tour.Sequence == trip.PersonDay.TotalCreatedTours)
            //	&& ((simulatedSchoolStops == 0 && personDay.SchoolStops > 0)
            //	||(simulatedBusinessStops == 0 && personDay.BusinessStops > 0)
            //	||(simulatedEscortStops == 0 && personDay.EscortStops > 0)
            //	||(simulatedPersonalBusinessStops == 0 && personDay.PersonalBusinessStops > 0)
            //	||(simulatedShoppingStops == 0 && personDay.ShoppingStops > 0)
            //	||(simulatedSocialStops == 0 && personDay.SocialStops > 0)))) {
            //		stopsNeeded = true;
            //}


            var from7AMto9AMFlag  = (time >= Global.Settings.Times.SevenAM && time < Global.Settings.Times.NineAM).ToFlag();
            var from9AMto3PMFlag  = (time >= Global.Settings.Times.NineAM && time < Global.Settings.Times.ThreePM).ToFlag();
            var from3PMto6PMFlag  = (time >= Global.Settings.Times.ThreePM && time < Global.Settings.Times.SixPM).ToFlag();
            var from6PMto10PMFlag = (time >= Global.Settings.Times.SixPM && time < Global.Settings.Times.TenPM).ToFlag();
            var from10PMto7AMFlag = (time >= Global.Settings.Times.TenPM).ToFlag();


            var from9AMto11AMFlag = (time >= Global.Settings.Times.NineAM && time < Global.Settings.Times.ElevenAM).ToFlag();
            var from11AMto1PMFlag = (time >= Global.Settings.Times.ElevenAM && time < Global.Settings.Times.OnePM).ToFlag();
            var from1PMto3PMFlag  = (time >= Global.Settings.Times.OnePM && time < Global.Settings.Times.ThreePM).ToFlag();
            var from3PMto5PMFlag  = (time >= Global.Settings.Times.ThreePM && time < Global.Settings.Times.FivePM).ToFlag();
            var from7PMto9PMFlag  = (time >= Global.Settings.Times.SevenPM && time < Global.Settings.Times.NinePM).ToFlag();
            var from9PMto11PMFlag = (time >= Global.Settings.Times.NinePM && time < Global.Settings.Times.ElevenPM).ToFlag();
            var from11PMto7AMFlag = (time >= Global.Settings.Times.ElevenPM).ToFlag();



            IEnumerable <PersonDayWrapper> orderedPersonDays = householdDay.PersonDays.OrderBy(p => p.GetJointTourParticipationPriority()).ToList().Cast <PersonDayWrapper>();
            int numChildrenOnJointTour = 0;
            int numAdultsOnJointTour   = 0;
            int totHHToursJT           = 0;
            //int totHHStopsJT=0;

            TimeWindow timeWindow = new TimeWindow();

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

                        if (pDay.Person.Age < 18)
                        {
                            numChildrenOnJointTour++;
                        }

                        if (pDay.Person.Age >= 18)
                        {
                            numAdultsOnJointTour++;
                        }
                    }
                }
            }
            else if (trip.Direction == Global.Settings.TourDirections.OriginToDestination && tour.FullHalfTour1Sequence > 0)
            {
                foreach (PersonDayWrapper pDay in householdDay.PersonDays)
                {
                    var tInJoint = (TourWrapper)pDay.Tours.Find(t => t.FullHalfTour1Sequence == tour.FullHalfTour1Sequence);
                    if (!(tInJoint == null))
                    {
                        // set jointTour time window
                        timeWindow.IncorporateAnotherTimeWindow(tInJoint.PersonDay.TimeWindow);

                        timeWindow.IncorporateAnotherTimeWindow(tInJoint.PersonDay.TimeWindow);
                        totHHToursJT = personDay.HomeBasedTours + totHHToursJT;

                        if (pDay.Person.Age < 18)
                        {
                            numChildrenOnJointTour++;
                        }

                        if (pDay.Person.Age >= 18)
                        {
                            numAdultsOnJointTour++;
                        }
                    }
                }
            }
            else if (trip.Direction == Global.Settings.TourDirections.DestinationToOrigin && tour.FullHalfTour2Sequence > 0)
            {
                foreach (PersonDayWrapper pDay in householdDay.PersonDays)
                {
                    var tInJoint = (TourWrapper)pDay.Tours.Find(t => t.FullHalfTour2Sequence == tour.FullHalfTour2Sequence);
                    if (!(tInJoint == null))
                    {
                        // set jointTour time window
                        timeWindow.IncorporateAnotherTimeWindow(tInJoint.PersonDay.TimeWindow);
                        timeWindow.IncorporateAnotherTimeWindow(tInJoint.PersonDay.TimeWindow);
                        totHHToursJT = personDay.HomeBasedTours + totHHToursJT;

                        if (pDay.Person.Age < 18)
                        {
                            numChildrenOnJointTour++;
                        }

                        if (pDay.Person.Age >= 18)
                        {
                            numAdultsOnJointTour++;
                        }
                    }
                }
            }
            else if (tour.ParentTour == null)
            {
                timeWindow.IncorporateAnotherTimeWindow(personDay.TimeWindow);
            }
            else
            {
                timeWindow.IncorporateAnotherTimeWindow(tour.ParentTour.TimeWindow);
            }

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

            // time window in minutes for yet unmodeled portion of halftour, only consider persons on this trip
            var availableWindow = timeWindow.AvailableWindow(destinationDepartureTime, Global.Settings.TimeDirections.Both);
            var timePressure    = 1000 * remainingToursCount / (Math.Max(1D, availableWindow));
            //alternative.AddUtilityTerm(98, 1000 * remainingToursCount / (Math.Max(1D, maxWindowRemaining)));


            //var duration = availableWindow / 60D;

            // connectivity attributes
            //var c34Ratio = trip.OriginParcel.C34RatioBuffer1();

            var adis    = 0.0;
            var logDist = 0.0;
            var minute  = DayPeriod.BigDayPeriods[DayPeriod.MIDDAY].Start;

            //distance from origin to destination
            if (tour.OriginParcel != null && tour.DestinationParcel != null)
            {
                if (trip.Direction == Global.Settings.TourDirections.OriginToDestination)
                {
                    adis = ImpedanceRoster.GetValue("distance", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, minute, tour.OriginParcel, destinationParcel).Variable;
                }
                else
                {
                    adis = ImpedanceRoster.GetValue("distance", Global.Settings.Modes.Sov, Global.Settings.PathTypes.FullNetwork, Global.Settings.ValueOfTimes.DefaultVot, minute, destinationParcel, tour.OriginParcel).Variable;
                }
                logDist = Math.Log(1 + adis);
            }

            // 0 - NO MORE STOPS

            var alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.NoneOrHome, !stopsNeeded, choice == Global.Settings.Purposes.NoneOrHome);

            alternative.Choice = Global.Settings.Purposes.NoneOrHome;
            //alternative.AddNestedAlternative(_nestedAlternativeIds[0], _nestedAlternativeIndexes[0], THETA_PARAMETER);

            alternative.AddUtilityTerm(1, oneSimulatedTripFlag);
            alternative.AddUtilityTerm(2, twoSimulatedTripsFlag);
            alternative.AddUtilityTerm(2, threeSimulatedTripsFlag);
            alternative.AddUtilityTerm(2, fourSimulatedTripsFlag);
            alternative.AddUtilityTerm(2, fivePlusSimulatedTripsFlag);
            alternative.AddUtilityTerm(6, transitTourFlag);
            alternative.AddUtilityTerm(7, bikeTourFlag);
            alternative.AddUtilityTerm(8, walkTourFlag);
            alternative.AddUtilityTerm(9, jointHalfTour);
            alternative.AddUtilityTerm(10, halfTourFromOriginFlag);
            alternative.AddUtilityTerm(11, totalAggregateLogsum);

            alternative.AddUtilityTerm(12, businessTourFlag);
            alternative.AddUtilityTerm(13, personalBusinessTourFlag);
            alternative.AddUtilityTerm(14, socialTourFlag);
            //alternative.AddUtilityTerm(15, schoolTourFlag);
            alternative.AddUtilityTerm(16, escortTourFlag);
            alternative.AddUtilityTerm(17, shoppingTourFlag);
            alternative.AddUtilityTerm(18, timePressure);
            //alternative.AddUtilityTerm(19, primaryFamilyTimeFlag);

            //alternative.AddUtilityTerm(15, from11PMto7AMFlag);

            //alternative.AddUtilityTerm(1, twoSimulatedTripsFlag * halfTourFromOriginFlag * isIndividualTour);
            //alternative.AddUtilityTerm(2, threeSimulatedTripsFlag * halfTourFromOriginFlag * isIndividualTour);
            //alternative.AddUtilityTerm(3, fourSimulatedTripsFlag * halfTourFromOriginFlag * isIndividualTour);
            //alternative.AddUtilityTerm(4, fivePlusSimulatedTripsFlag * halfTourFromOriginFlag * isIndividualTour);
            //alternative.AddUtilityTerm(5, twoSimulatedTripsFlag * halfTourFromDestinationFlag * isIndividualTour);
            //alternative.AddUtilityTerm(6, threeSimulatedTripsFlag * halfTourFromDestinationFlag * isIndividualTour);
            //alternative.AddUtilityTerm(7, fourSimulatedTripsFlag * halfTourFromDestinationFlag * isIndividualTour);
            //alternative.AddUtilityTerm(8, fivePlusSimulatedTripsFlag * halfTourFromDestinationFlag * isIndividualTour);
            //alternative.AddUtilityTerm(9, homeBasedTours * isIndividualTour);
            //alternative.AddUtilityTerm(10, homeBasedTours * isJointTour);
            //alternative.AddUtilityTerm(11, notHomeBasedTourFlag);
            //alternative.AddUtilityTerm(12, beforeMandatoryDestinationFlag*isJointTour);
            //alternative.AddUtilityTerm(13, beforeMandatoryDestinationFlag);
            //alternative.AddUtilityTerm(14, numAdultsOnJointTour);
            //alternative.AddUtilityTerm(15, numChildrenOnJointTour);
            //alternative.AddUtilityTerm(16, totHHToursJT);
            //	alternative.AddUtilityTerm(17, totHHStopsJT);
            //alternative.AddUtilityTerm(22, (threeSimulatedTripsFlag + fourSimulatedTripsFlag + fivePlusSimulatedTripsFlag) * halfTourFromOriginFlag * isJointTour);
            //alternative.AddUtilityTerm(26, threeSimulatedTripsFlag * halfTourFromDestinationFlag * isJointTour);
            //alternative.AddUtilityTerm(27, fourSimulatedTripsFlag * halfTourFromDestinationFlag * isJointTour);
            //alternative.AddUtilityTerm(28, fivePlusSimulatedTripsFlag * halfTourFromDestinationFlag * isJointTour);

            // 1 - BUSINESS STOP

            //if (personDay.BusinessStops > 0 && (tour.DestinationPurpose <= Global.Settings.Purposes.School || tour.DestinationPurpose == Global.Settings.Purposes.Business)) {
            // JLB 20130704 business stops are allowed on escort tours per data prep
            alternative = choiceProbabilityCalculator.GetAlternative(1,
                                                                     (personDay.BusinessStops > 0 &&
                                                                      (tour.DestinationPurpose <= Global.Settings.Purposes.Escort || tour.DestinationPurpose == Global.Settings.Purposes.Business) &&
                                                                      (halfTour.SimulatedTrips <= 5) &&
                                                                      timeIsAvailableForAnotherTrip),
                                                                     choice == Global.Settings.Purposes.Business);

            alternative.Choice = Global.Settings.Purposes.Business;
            //alternative.AddNestedAlternative(_nestedAlternativeIds[1], _nestedAlternativeIndexes[1], THETA_PARAMETER);

            //alternative.AddUtilityTerm(32, isIndividualTour);
            alternative.AddUtilityTerm(32, 1.0);
            alternative.AddUtilityTerm(33, businessTourFlag);
            //alternative.AddUtilityTerm(34, schoolTourFlag);
            //alternative.AddUtilityTerm(35, halfTourFromOriginFlag);
            //alternative.AddUtilityTerm(36, simulatedBusinessStops);
            //alternative.AddUtilityTerm(37, simulatedBusinessStopsFlag);
            //alternative.AddUtilityTerm(39, duration);

            //alternative.AddUtilityTerm(40, from9AMto11AMFlag + from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag);
            alternative.AddUtilityTerm(40, from9AMto3PMFlag + from3PMto6PMFlag);


            //alternative.AddUtilityTerm(42, logDist);
            //alternative.AddUtilityTerm(43, transitTourFlag);
            //alternative.AddUtilityTerm(44, (person.IsPartTimeWorker).ToFlag());

            //GV: 21. aug - I commented out as it is the only logsum in the model
            //alternative.AddUtilityTerm(46, totalAggregateLogsum);

            //alternative.AddUtilityTerm(47,totEmpBuffer2);
            //alternative.AddUtilityTerm(48, hovDriverTourFlag + hovPassengerTourFlag);


            // 2 - SCHOOL STOP

            alternative = choiceProbabilityCalculator.GetAlternative(2,
                                                                     (((personDay.SchoolStops > 0 && tour.DestinationPurpose <= Global.Settings.Purposes.School) || (isJointTour == 1)) &&
                                                                      halfTour.SimulatedTrips <= 5 &&
                                                                      timeIsAvailableForAnotherTrip),
                                                                     choice == Global.Settings.Purposes.School);

            alternative.Choice = Global.Settings.Purposes.School;
            //alternative.AddNestedAlternative(_nestedAlternativeIds[2], _nestedAlternativeIndexes[2], THETA_PARAMETER);

            //alternative.AddUtilityTerm(51, workTourFlag);
            alternative.AddUtilityTerm(51, 1.0);
            //alternative.AddUtilityTerm(52, schoolTourFlag);
            //alternative.AddUtilityTerm(53, halfTourFromOriginFlag);
            //alternative.AddUtilityTerm(54, simulatedSchoolStops);
            //alternative.AddUtilityTerm(55, remainingToursCount);
            //alternative.AddUtilityTerm(56, duration);

            //alternative.AddUtilityTerm(57, from7AMto9AMFlag + from7PMto9PMFlag + from9PMto11PMFlag + from11PMto7AMFlag);
            alternative.AddUtilityTerm(57, from7AMto9AMFlag + from9AMto3PMFlag + from10PMto7AMFlag);

            //alternative.AddUtilityTerm(58, oneSimulatedTripFlag);
            //alternative.AddUtilityTerm(59, logDist);
            alternative.AddUtilityTerm(61, jointHalfOfFullJointHalfTour * numChildrenOnJointTour);
            //alternative.AddUtilityTerm(65, (person.Age < 12).ToFlag());
            //alternative.AddUtilityTerm(66,  (person.IsUniversityStudent).ToFlag());



            // 3 - ESCORT STOP

            //if ((personDay.EscortStops > 0 && (tour.DestinationPurpose <= Global.Settings.Purposes.Escort || tour.DestinationPurpose == Global.Settings.Purposes.Business)) || (isJointTour==1)) {
            // JLB 20130704 no escort stops allowed on business tours per data prep
            alternative = choiceProbabilityCalculator.GetAlternative(3,
                                                                     (((personDay.EscortStops > 0 && tour.DestinationPurpose <= Global.Settings.Purposes.Escort) || (isJointTour == 1)) &&
                                                                      halfTour.SimulatedTrips <= 5 &&
                                                                      timeIsAvailableForAnotherTrip),
                                                                     choice == Global.Settings.Purposes.Escort);

            alternative.Choice = Global.Settings.Purposes.Escort;
            //alternative.AddNestedAlternative(_nestedAlternativeIds[3], _nestedAlternativeIndexes[3], THETA_PARAMETER);

            alternative.AddUtilityTerm(71, 1.0);
            //alternative.AddUtilityTerm(72, workTourFlag + schoolTourFlag);
            //alternative.AddUtilityTerm(72, isJointTour);
            //alternative.AddUtilityTerm(74, escortTourFlag);
            //alternative.AddUtilityTerm(75, socialOrRecreationTourFlag);
            //alternative.AddUtilityTerm(76, remainingToursCount);
            //alternative.AddUtilityTerm(77, duration);
            alternative.AddUtilityTerm(78, from7AMto9AMFlag);
            //alternative.AddUtilityTerm(79, from9AMto11AMFlag + from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag);
            //alternative.AddUtilityTerm(81, hovDriverTourFlag);
            //alternative.AddUtilityTerm(82, hovPassengerTourFlag);
            //alternative.AddUtilityTerm(83, simulatedEscortStops * isJointTour);
            //alternative.AddUtilityTerm(84, simulatedEscortStops * isIndividualTour);
            //alternative.AddUtilityTerm(85, totalAggregateLogsum);
            //alternative.AddUtilityTerm(86, jointHalfOfFullJointHalfTour);
            //alternative.AddUtilityTerm(88, enrollmentK8Buffer2);
            //alternative.AddUtilityTerm(89, numChildrenOnJointTour);
            //alternative.AddUtilityTerm(90, halfTourFromOriginFlag);



            // 4 - PERSONAL BUSINESS STOP


            alternative = choiceProbabilityCalculator.GetAlternative(4,
                                                                     ((personDay.PersonalBusinessStops > 0 || isJointTour == 1) &&
                                                                      halfTour.SimulatedTrips <= 5 &&
                                                                      timeIsAvailableForAnotherTrip),
                                                                     choice == Global.Settings.Purposes.PersonalBusiness);

            alternative.Choice = Global.Settings.Purposes.PersonalBusiness;
            //alternative.AddNestedAlternative(_nestedAlternativeIds[4], _nestedAlternativeIndexes[4], THETA_PARAMETER);

            alternative.AddUtilityTerm(91, 1.0);
            //alternative.AddUtilityTerm(92, (workTourFlag + schoolTourFlag + businessTourFlag));
            //alternative.AddUtilityTerm(92, isJointTour);
            //alternative.AddUtilityTerm(93, escortTourFlag);
            //alternative.AddUtilityTerm(94, personalBusinessOrMedicalTourFlag * isIndividualTour);
            //alternative.AddUtilityTerm(95, shoppingTourFlag);
            //alternative.AddUtilityTerm(96, mealTourFlag);
            //alternative.AddUtilityTerm(97, socialOrRecreationTourFlag);
            //alternative.AddUtilityTerm(98, halfTourFromOriginFlag);
            //alternative.AddUtilityTerm(99, simulatedPersonalBusinessStops * isIndividualTour);
            //alternative.AddUtilityTerm(100, simulatedPersonalBusinessStops * isJointTour);
            //alternative.AddUtilityTerm(101, duration);
            //alternative.AddUtilityTerm(102, (from7AMto9AMFlag + from7PMto9PMFlag + from9PMto11PMFlag + from11PMto7AMFlag));

            //alternative.AddUtilityTerm(103, from9AMto11AMFlag + from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag);
            alternative.AddUtilityTerm(103, from9AMto3PMFlag + from3PMto6PMFlag);

            //alternative.AddUtilityTerm(105, hovDriverTourFlag);
            //alternative.AddUtilityTerm(106, hovPassengerTourFlag);
            //alternative.AddUtilityTerm(109, jointHalfOfFullJointHalfTour);
            //alternative.AddUtilityTerm(110, totEmpBuffer2);
            //alternative.AddUtilityTerm(111, totalAggregateLogsum);
            //alternative.AddUtilityTerm(112, personalBusinessOrMedicalTourFlag * isJointTour);



            // 5 - SHOPPING STOP

            alternative = choiceProbabilityCalculator.GetAlternative(5,
                                                                     ((personDay.ShoppingStops > 0 || isJointTour == 1) &&
                                                                      halfTour.SimulatedTrips <= 5 &&
                                                                      timeIsAvailableForAnotherTrip),
                                                                     choice == Global.Settings.Purposes.Shopping);

            alternative.Choice = Global.Settings.Purposes.Shopping;
            //alternative.AddNestedAlternative(_nestedAlternativeIds[5], _nestedAlternativeIndexes[5], THETA_PARAMETER);

            alternative.AddUtilityTerm(121, 1.0);
            //alternative.AddUtilityTerm(122, workTourFlag + schoolTourFlag + businessTourFlag);
            //alternative.AddUtilityTerm(122, isJointTour);
            //alternative.AddUtilityTerm(123, escortTourFlag);
            //alternative.AddUtilityTerm(124, personalBusinessOrMedicalTourFlag);
            //alternative.AddUtilityTerm(125, shoppingTourFlag * isIndividualTour);
            //alternative.AddUtilityTerm(125, shoppingTourFlag);
            //alternative.AddUtilityTerm(126, mealTourFlag);
            //alternative.AddUtilityTerm(127, socialOrRecreationTourFlag);
            //alternative.AddUtilityTerm(128, halfTourFromOriginFlag);
            //alternative.AddUtilityTerm(129, simulatedShoppingStops * isIndividualTour);
            //alternative.AddUtilityTerm(130, simulatedShoppingStops * isJointTour);
            //alternative.AddUtilityTerm(131, duration);

            //alternative.AddUtilityTerm(132, from7AMto9AMFlag + from9PMto11PMFlag + from11PMto7AMFlag);
            //alternative.AddUtilityTerm(133, (from11AMto1PMFlag + from1PMto3PMFlag + from3PMto5PMFlag));

            //alternative.AddUtilityTerm(132, from7AMto9AMFlag + from6PMto10PMFlag);
            alternative.AddUtilityTerm(133, (from9AMto3PMFlag + from3PMto6PMFlag + from6PMto10PMFlag));

            //alternative.AddUtilityTerm(134, adultFemaleOnJointTour);
            //alternative.AddUtilityTerm(135, hovDriverTourFlag);
            //alternative.AddUtilityTerm(136, hovPassengerTourFlag);
            //alternative.AddUtilityTerm(137, Math.Log(1 + adis));
            //alternative.AddUtilityTerm(138, shoppingTourFlag * isJointTour);
            //alternative.AddUtilityTerm(140, shoppingAggregateLogsum);
            //alternative.AddUtilityTerm(141, retailBuffer2);
            //alternative.AddUtilityTerm(142, numChildrenOnJointTour);
            //alternative.AddUtilityTerm(143, (household.Has100KPlusIncome).ToFlag());
            alternative.AddUtilityTerm(134, primaryFamilyTimeFlag);



            // 6 - MEAL STOP

            //alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Meal, false, choice == Global.Settings.Purposes.Meal);
            //alternative.Choice = Global.Settings.Purposes.Meal;
            //alternative.AddNestedAlternative(12, 2, THETA_PARAMETER);


            // 6 - SOCIAL (OR RECREATION) STOP

            alternative = choiceProbabilityCalculator.GetAlternative(6,
                                                                     ((personDay.SocialStops > 0 || isJointTour == 1) &&
                                                                      halfTour.SimulatedTrips <= 5 &&
                                                                      timeIsAvailableForAnotherTrip),
                                                                     choice == Global.Settings.Purposes.Social);

            alternative.Choice = Global.Settings.Purposes.Social;
            //alternative.AddNestedAlternative(_nestedAlternativeIds[6], _nestedAlternativeIndexes[6], THETA_PARAMETER);

            alternative.AddUtilityTerm(181, 1.0);
            //alternative.AddUtilityTerm(182, workTourFlag + schoolTourFlag + businessTourFlag);
            //alternative.AddUtilityTerm(182, isJointTour);
            //alternative.AddUtilityTerm(183, escortTourFlag);
            //alternative.AddUtilityTerm(184, personalBusinessOrMedicalTourFlag);
            //alternative.AddUtilityTerm(185, shoppingTourFlag);
            //alternative.AddUtilityTerm(186, mealTourFlag);
            //alternative.AddUtilityTerm(187, socialOrRecreationTourFlag);
            //alternative.AddUtilityTerm(188, halfTourFromOriginFlag);
            //alternative.AddUtilityTerm(189, simulatedSocialStops * isIndividualTour);
            //alternative.AddUtilityTerm(197, simulatedSocialStops * isJointTour);
            //alternative.AddUtilityTerm(190, remainingToursCount);
            //alternative.AddUtilityTerm(191, duration);

            //alternative.AddUtilityTerm(192, from7AMto9AMFlag + from11PMto7AMFlag);
            //alternative.AddUtilityTerm(192, from7AMto9AMFlag);
            alternative.AddUtilityTerm(192, from9AMto3PMFlag + from3PMto6PMFlag + from6PMto10PMFlag);

            //alternative.AddUtilityTerm(194, hovDriverTourFlag);
            //alternative.AddUtilityTerm(195, hovPassengerTourFlag);
            //alternative.AddUtilityTerm(196, logDist);
            //alternative.AddUtilityTerm(200, numAdultsOnJointTour);


            // 8 - RECREATION STOP

            //alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Recreation, false, choice == Global.Settings.Purposes.Recreation);
            //alternative.Choice = Global.Settings.Purposes.Recreation;
            //alternative.AddNestedAlternative(12, 2, THETA_PARAMETER);

            // 9 - MEDICAL STOP

            //alternative = choiceProbabilityCalculator.GetAlternative(Global.Settings.Purposes.Medical, false, choice == Global.Settings.Purposes.Medical);
            //alternative.Choice = Global.Settings.Purposes.Medical;
            //alternative.AddNestedAlternative(12, 2, THETA_PARAMETER);
        }
 public int Run(TripWrapper trip, HouseholdDayWrapper householdDay)
 {
     return(Run(trip, householdDay, Global.Settings.Purposes.NoneOrHome));
 }
예제 #8
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, HouseholdDayWrapper householdDay, TripWrapper trip, HTripTime choice = null)
        {
            if (householdDay.Household.Id == 80066 && trip.Person.Sequence == 1 && trip.Tour.Sequence == 2 &&
                trip.Direction == 2 && trip.Sequence == 1)
            {
                bool testbreak = true;
            }

            var person    = (PersonWrapper)trip.Person;
            var personDay = (PersonDayWrapper)trip.PersonDay;
            var tour      = (TourWrapper)trip.Tour;

            // person inputs + househol_PFPT
            var partTimeWorkerFlag    = person.IsPartTimeWorker.ToFlag();
            var nonworkingAdultFlag   = person.IsNonworkingAdult.ToFlag();
            var universityStudentFlag = person.IsUniversityStudent.ToFlag();
            var retiredAdultFlag      = person.IsRetiredAdult.ToFlag();
            //var drivingAgeStudentFlag = person.IsDrivingAgeStudent.ToFlag(); // excluded by GV
            var childAge5Through15Flag = person.IsChildAge5Through15.ToFlag();
            var childUnder5Flag        = person.IsChildUnder5.ToFlag();
            var femaleFlag             = person.IsFemale.ToFlag();
            var fullTimeWorkerFlag     = person.IsFulltimeWorker.ToFlag();
            var primaryFamilyTimeFlag  = householdDay.PrimaryPriorityTimeFlag;

            // set tour inputs
            var workTourFlag             = tour.IsWorkPurpose().ToFlag();
            var schoolTourFlag           = tour.IsSchoolPurpose().ToFlag();
            var businessTourFlag         = tour.IsBusinessPurpose().ToFlag();
            var escortTourFlag           = tour.IsEscortPurpose().ToFlag();
            var personalBusinessTourFlag = tour.IsPersonalBusinessPurpose().ToFlag();
            var shoppingTourFlag         = tour.IsShoppingPurpose().ToFlag();
            var socialTourFlag           = tour.IsSocialPurpose().ToFlag();
            var notWorkSchoolTourFlag    = 1 - workTourFlag - schoolTourFlag;
            var notWorkTourFlag          = (!tour.IsWorkPurpose()).ToFlag();
            var notHomeBasedTourFlag     = (!tour.IsHomeBasedTour).ToFlag();
            var jointTourFlag            = (tour.JointTourSequence > 0) ? 1 : 0;
            var partialHalfTourFlag      = (trip.IsHalfTourFromOrigin ? tour.PartialHalfTour1Sequence > 0 : tour.PartialHalfTour2Sequence > 0) ? 1 : 0;
            var fullHalfTourFlag         = (trip.IsHalfTourFromOrigin ? tour.FullHalfTour1Sequence > 0 : tour.FullHalfTour2Sequence > 0) ? 1 : 0;

            // set trip inputs - travel purpose
            var originChangeMode           = trip.Sequence > 1 && trip.GetPreviousTrip().DestinationPurpose == Global.Settings.Purposes.ChangeMode;
            var originSchoolFlag           = trip.IsSchoolOriginPurpose().ToFlag();
            var originEscortFlag           = trip.IsEscortOriginPurpose().ToFlag();
            var originShoppingFlag         = trip.IsShoppingOriginPurpose().ToFlag();
            var originPersonalBusinessFlag = trip.IsPersonalBusinessOriginPurpose().ToFlag();
            var originMealFlag             = trip.IsMealOriginPurpose().ToFlag();
            var originSocialFlag           = trip.IsSocialOriginPurpose().ToFlag();
            var originBusinessFlag         = trip.IsBusinessOriginPurpose().ToFlag();

            // set trip inputs - travel modes
            var sovOrHovTripFlag      = trip.UsesSovOrHovModes().ToFlag();
            var bikeTripFlag          = trip.IsBikeMode().ToFlag();
            var walkTripFlag          = trip.IsWalkMode().ToFlag();
            var transitTripFlag       = trip.IsTransitMode().ToFlag();
            var carDriverAloneFlag    = trip.IsSovMode().ToFlag();
            var carDriverNotAloneFlag = trip.IsHov2Mode().ToFlag();
            var carPassengerFlag      = trip.IsHov3Mode().ToFlag();

            var halfTourFromOriginFlag      = trip.IsHalfTourFromOrigin.ToFlag();
            var halfTourFromDestinationFlag = (!trip.IsHalfTourFromOrigin).ToFlag();

            // set remaining inputs
            // set remaining inputs
            TimeWindow timeWindow = new TimeWindow();

            if (tour.JointTourSequence > 0)
            {
                foreach (PersonDayWrapper pDay in householdDay.PersonDays)
                {
                    var tInJoint = (TourWrapper)pDay.Tours.Find(t => t.JointTourSequence == tour.JointTourSequence);
                    if (!(tInJoint == null))
                    {
                        // set jointTour time window
                        timeWindow.IncorporateAnotherTimeWindow(tInJoint.PersonDay.TimeWindow);
                    }
                }
            }
            else if (trip.Direction == Global.Settings.TourDirections.OriginToDestination && tour.FullHalfTour1Sequence > 0)
            {
                foreach (PersonDayWrapper pDay in householdDay.PersonDays)
                {
                    var tInJoint = (TourWrapper)pDay.Tours.Find(t => t.FullHalfTour1Sequence == tour.FullHalfTour1Sequence);
                    if (!(tInJoint == null))
                    {
                        // set jointTour time window
                        timeWindow.IncorporateAnotherTimeWindow(tInJoint.PersonDay.TimeWindow);
                    }
                }
            }
            else if (trip.Direction == Global.Settings.TourDirections.DestinationToOrigin && tour.FullHalfTour2Sequence > 0)
            {
                foreach (PersonDayWrapper pDay in householdDay.PersonDays)
                {
                    var tInJoint = (TourWrapper)pDay.Tours.Find(t => t.FullHalfTour2Sequence == tour.FullHalfTour2Sequence);
                    if (!(tInJoint == null))
                    {
                        // set jointTour time window
                        timeWindow.IncorporateAnotherTimeWindow(tInJoint.PersonDay.TimeWindow);
                    }
                }
            }
            else if (tour.ParentTour == null)
            {
                timeWindow.IncorporateAnotherTimeWindow(personDay.TimeWindow);
            }
            else
            {
                timeWindow.IncorporateAnotherTimeWindow(tour.ParentTour.TimeWindow);
            }

            //set the availability and impedances for the periods
            HTripTime.SetTimeImpedances(trip);

            var remainingToursCount     = personDay.HomeBasedTours - personDay.GetTotalSimulatedTours();
            var tripRemainingInHalfTour = (trip.DestinationParcel != null && trip.DestinationParcel != tour.OriginParcel).ToFlag(); // we don't know exact #

            var previousArrivalTime = trip.IsHalfTourFromOrigin
                     ? (trip.Sequence == 1 ? tour.DestinationDepartureTime : trip.GetPreviousTrip().ArrivalTime)
                     : (trip.Sequence == 1 ? tour.DestinationArrivalTime : trip.GetPreviousTrip().ArrivalTime);

            var previousArrivalPeriod = new HTripTime(previousArrivalTime).DeparturePeriod;

            foreach (var time in HTripTime.Times[ParallelUtility.threadLocalAssignedIndex.Value])
            {
                var period = time.DeparturePeriod;

                var departurePeriodFraction = timeWindow.TotalAvailableMinutes(period.Start, period.End) / (period.End - period.Start + 1D);

                var departureShiftHours  = period.Middle / 60.0;
                var durationShiftMinutes = Math.Abs(period.Middle - previousArrivalPeriod.Middle);
                var durationShiftHours   = durationShiftMinutes / 60.0;



                var available = time.Available && departurePeriodFraction > 0;

                var alternative = choiceProbabilityCalculator.GetAlternative(time.Index, available, choice != null && choice.Equals(time));


                if (!alternative.Available)
                {
                    continue;
                }

                alternative.Choice = time;

                var indicatedTravelTime  = (int)time.ModeLOS.PathTime;
                var indicatedArrivalTime = trip.IsHalfTourFromOrigin
                     ? Math.Max(1, period.Middle - indicatedTravelTime)
                     : Math.Min(1440, period.Middle + indicatedTravelTime);

                var totalWindowRemaining = trip.IsHalfTourFromOrigin
                     ? timeWindow.TotalAvailableMinutesBefore(indicatedArrivalTime) + timeWindow.TotalAvailableMinutesAfter(previousArrivalTime)
                     : timeWindow.TotalAvailableMinutesAfter(indicatedArrivalTime) + timeWindow.TotalAvailableMinutesBefore(previousArrivalTime);

                var maxWindowRemaining = trip.IsHalfTourFromOrigin
                     ? timeWindow.MaxAvailableMinutesBefore(indicatedArrivalTime) + timeWindow.MaxAvailableMinutesAfter(previousArrivalTime)
                     : timeWindow.MaxAvailableMinutesAfter(indicatedArrivalTime) + timeWindow.MaxAvailableMinutesBefore(previousArrivalTime);

                if (trip.IsHalfTourFromOrigin)
                {
                    // outbound "departure" (arrival) period constants
                    alternative.AddUtilityTerm(11, time.DeparturePeriod.Middle.IsBetween(Global.Settings.Times.ThreeAM, Global.Settings.Times.SixAM).ToFlag());
                    alternative.AddUtilityTerm(12, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.SixAM, Global.Settings.Times.SevenAM).ToFlag());
                    alternative.AddUtilityTerm(13, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.SevenAM, Global.Settings.Times.EightAM).ToFlag());
                    alternative.AddUtilityTerm(14, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.EightAM, Global.Settings.Times.NineAM).ToFlag());
                    alternative.AddUtilityTerm(15, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.NineAM, Global.Settings.Times.TenAM).ToFlag());
                    alternative.AddUtilityTerm(16, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.TenAM, Global.Settings.Times.OnePM).ToFlag());

                    //alternative.AddUtilityTerm(17, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.OnePM, Global.Settings.Times.FourPM).ToFlag());
                    //alternative.AddUtilityTerm(18, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.FourPM, Global.Settings.Times.SevenPM).ToFlag());
                    //GV changed to 3pm
                    alternative.AddUtilityTerm(17, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.OnePM, Global.Settings.Times.ThreePM).ToFlag());
                    alternative.AddUtilityTerm(18, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.ThreePM, Global.Settings.Times.SixPM).ToFlag());
                    alternative.AddUtilityTerm(19, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.SixPM, Global.Settings.Times.TenPM).ToFlag());
                    alternative.AddUtilityTerm(20, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.TenPM, Global.Settings.Times.MinutesInADay).ToFlag());
                }
                else
                {
                    // return departure period constants
                    alternative.AddUtilityTerm(21, time.DeparturePeriod.Middle.IsBetween(Global.Settings.Times.ThreeAM, Global.Settings.Times.SevenAM).ToFlag());
                    alternative.AddUtilityTerm(22, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.SevenAM, Global.Settings.Times.TenAM).ToFlag());
                    alternative.AddUtilityTerm(23, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.TenAM, Global.Settings.Times.OnePM).ToFlag());
                    alternative.AddUtilityTerm(24, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.OnePM, Global.Settings.Times.ThreePM).ToFlag());
                    alternative.AddUtilityTerm(124, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.ThreePM, Global.Settings.Times.FourPM).ToFlag());
                    alternative.AddUtilityTerm(25, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.FourPM, Global.Settings.Times.FivePM).ToFlag());
                    alternative.AddUtilityTerm(26, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.FivePM, Global.Settings.Times.SixPM).ToFlag());
                    alternative.AddUtilityTerm(27, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.SixPM, Global.Settings.Times.SevenPM).ToFlag());
                    alternative.AddUtilityTerm(28, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.SevenPM, Global.Settings.Times.NinePM).ToFlag());
                    alternative.AddUtilityTerm(29, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.NinePM, Global.Settings.Times.Midnight).ToFlag());
                    alternative.AddUtilityTerm(30, time.DeparturePeriod.Middle.IsLeftExclusiveBetween(Global.Settings.Times.Midnight, Global.Settings.Times.MinutesInADay).ToFlag());
                }

                alternative.AddUtilityTerm(31, durationShiftMinutes.IsRightExclusiveBetween(Global.Settings.Times.ZeroHours, Global.Settings.Times.OneHour).ToFlag());           // 0 - 1
                alternative.AddUtilityTerm(32, durationShiftMinutes.IsRightExclusiveBetween(Global.Settings.Times.OneHour, Global.Settings.Times.TwoHours).ToFlag());            // 1 - 2
                alternative.AddUtilityTerm(33, durationShiftMinutes.IsRightExclusiveBetween(Global.Settings.Times.TwoHours, Global.Settings.Times.ThreeHours).ToFlag());         // 2 - 3
                alternative.AddUtilityTerm(34, durationShiftMinutes.IsRightExclusiveBetween(Global.Settings.Times.ThreeHours, Global.Settings.Times.FiveHours).ToFlag());        // 3 - 5
                alternative.AddUtilityTerm(35, durationShiftMinutes.IsRightExclusiveBetween(Global.Settings.Times.FiveHours, Global.Settings.Times.SevenHours).ToFlag());        // 5 - 7
                alternative.AddUtilityTerm(36, durationShiftMinutes.IsRightExclusiveBetween(Global.Settings.Times.SevenHours, Global.Settings.Times.NineHours).ToFlag());        // 7 - 9
                alternative.AddUtilityTerm(37, durationShiftMinutes.IsRightExclusiveBetween(Global.Settings.Times.NineHours, Global.Settings.Times.TwelveHours).ToFlag());       // 9 - 12
                alternative.AddUtilityTerm(38, durationShiftMinutes.IsRightExclusiveBetween(Global.Settings.Times.TwelveHours, Global.Settings.Times.FourteenHours).ToFlag());   // 12 - 14
                alternative.AddUtilityTerm(39, durationShiftMinutes.IsRightExclusiveBetween(Global.Settings.Times.FourteenHours, Global.Settings.Times.EighteenHours).ToFlag()); // 14 - 18
                alternative.AddUtilityTerm(40, (durationShiftMinutes >= Global.Settings.Times.EighteenHours).ToFlag());                                                          // 18 - 24

                alternative.AddUtilityTerm(41, partTimeWorkerFlag * departureShiftHours);
                alternative.AddUtilityTerm(43, nonworkingAdultFlag * departureShiftHours);
                alternative.AddUtilityTerm(45, universityStudentFlag * departureShiftHours);
                alternative.AddUtilityTerm(47, retiredAdultFlag * departureShiftHours);
                alternative.AddUtilityTerm(49, femaleFlag * departureShiftHours);
                alternative.AddUtilityTerm(51, childAge5Through15Flag * departureShiftHours);
                alternative.AddUtilityTerm(53, childUnder5Flag * departureShiftHours);
                alternative.AddUtilityTerm(61, jointTourFlag * departureShiftHours);
                //alternative.AddUtilityTerm(63, partialHalfTourFlag * departureShiftHours);
                //alternative.AddUtilityTerm(65, fullHalfTourFlag * departureShiftHours);
                alternative.AddUtilityTerm(67, primaryFamilyTimeFlag * departureShiftHours);

                //alternative.AddUtilityTerm(131, workTourFlag * halfTourFromOriginFlag * departureShiftHours);
                //alternative.AddUtilityTerm(133, workTourFlag * halfTourFromDestinationFlag * departureShiftHours);
                //alternative.AddUtilityTerm(135, notWorkTourFlag * halfTourFromDestinationFlag * departureShiftHours);
                //alternative.AddUtilityTerm(137, notHomeBasedTourFlag * departureShiftHours);
                alternative.AddUtilityTerm(145, originEscortFlag * departureShiftHours);
                alternative.AddUtilityTerm(147, originShoppingFlag * departureShiftHours);
                alternative.AddUtilityTerm(149, originBusinessFlag * departureShiftHours);
                alternative.AddUtilityTerm(151, originSocialFlag * departureShiftHours);
                alternative.AddUtilityTerm(153, originPersonalBusinessFlag * departureShiftHours);
                alternative.AddUtilityTerm(155, originSchoolFlag * departureShiftHours);

                alternative.AddUtilityTerm(42, partTimeWorkerFlag * durationShiftHours);
                alternative.AddUtilityTerm(44, nonworkingAdultFlag * durationShiftHours);
                alternative.AddUtilityTerm(46, universityStudentFlag * durationShiftHours);
                alternative.AddUtilityTerm(48, retiredAdultFlag * durationShiftHours);
                alternative.AddUtilityTerm(50, femaleFlag * durationShiftHours);
                alternative.AddUtilityTerm(52, childAge5Through15Flag * durationShiftHours);
                alternative.AddUtilityTerm(54, childUnder5Flag * durationShiftHours);
                //alternative.AddUtilityTerm(62, jointTourFlag * durationShiftHours);
                //alternative.AddUtilityTerm(64, partialHalfTourFlag * durationShiftHours);
                //alternative.AddUtilityTerm(66, fullHalfTourFlag * durationShiftHours);
                alternative.AddUtilityTerm(68, primaryFamilyTimeFlag * durationShiftHours);

                alternative.AddUtilityTerm(132, workTourFlag * halfTourFromOriginFlag * durationShiftHours);
                alternative.AddUtilityTerm(134, workTourFlag * halfTourFromDestinationFlag * durationShiftHours);
                alternative.AddUtilityTerm(136, notWorkTourFlag * halfTourFromDestinationFlag * durationShiftHours);
                alternative.AddUtilityTerm(138, notHomeBasedTourFlag * durationShiftHours);
                alternative.AddUtilityTerm(146, originEscortFlag * durationShiftHours);
                alternative.AddUtilityTerm(148, originShoppingFlag * durationShiftHours);
                alternative.AddUtilityTerm(150, originBusinessFlag * durationShiftHours);
                alternative.AddUtilityTerm(152, originSocialFlag * durationShiftHours);
                alternative.AddUtilityTerm(154, originPersonalBusinessFlag * durationShiftHours);
                alternative.AddUtilityTerm(156, originSchoolFlag * durationShiftHours);

                alternative.AddUtilityTerm(158, workTourFlag * halfTourFromOriginFlag * (trip.Sequence == 1).ToFlag() * durationShiftHours);
                alternative.AddUtilityTerm(159, workTourFlag * halfTourFromDestinationFlag * (trip.Sequence == 1).ToFlag() * durationShiftHours);
                alternative.AddUtilityTerm(160, schoolTourFlag * halfTourFromOriginFlag * (trip.Sequence == 1).ToFlag() * durationShiftHours);
                alternative.AddUtilityTerm(161, schoolTourFlag * halfTourFromDestinationFlag * (trip.Sequence == 1).ToFlag() * durationShiftHours);
                alternative.AddUtilityTerm(162, businessTourFlag * halfTourFromOriginFlag * (trip.Sequence == 1).ToFlag() * durationShiftHours);
                alternative.AddUtilityTerm(163, businessTourFlag * halfTourFromDestinationFlag * (trip.Sequence == 1).ToFlag() * durationShiftHours);
                alternative.AddUtilityTerm(164, escortTourFlag * halfTourFromOriginFlag * (trip.Sequence == 1).ToFlag() * durationShiftHours);
                alternative.AddUtilityTerm(165, escortTourFlag * halfTourFromDestinationFlag * (trip.Sequence == 1).ToFlag() * durationShiftHours);
                alternative.AddUtilityTerm(166, personalBusinessTourFlag * halfTourFromOriginFlag * (trip.Sequence == 1).ToFlag() * durationShiftHours);
                alternative.AddUtilityTerm(167, personalBusinessTourFlag * halfTourFromDestinationFlag * (trip.Sequence == 1).ToFlag() * durationShiftHours);
                alternative.AddUtilityTerm(168, shoppingTourFlag * halfTourFromOriginFlag * (trip.Sequence == 1).ToFlag() * durationShiftHours);
                alternative.AddUtilityTerm(169, shoppingTourFlag * halfTourFromDestinationFlag * (trip.Sequence == 1).ToFlag() * durationShiftHours);
                alternative.AddUtilityTerm(170, socialTourFlag * halfTourFromOriginFlag * (trip.Sequence == 1).ToFlag() * durationShiftHours);
                alternative.AddUtilityTerm(171, socialTourFlag * halfTourFromDestinationFlag * (trip.Sequence == 1).ToFlag() * durationShiftHours);

                //alternative.AddUtilityTerm(172, workTourFlag * halfTourFromOriginFlag * (trip.Sequence==1).ToFlag() * departureShiftHours);


                alternative.AddUtilityTerm(86, sovOrHovTripFlag * Math.Max(time.ModeLOS.GeneralizedTimeLogsum, 0) * tour.TimeCoefficient);
                //alternative.AddUtilityTerm(87, sovOrHovTripFlag * notWorkSchoolTourFlag * Math.Max(time.ModeLOS.GeneralizedTimeLogsum, 0) * tour.TimeCoefficient);
                //alternative.AddUtilityTerm(88, transitTripFlag * Math.Max(time.ModeLOS.GeneralizedTimeLogsum, 0) * tour.TimeCoefficient);
                //alternative.AddUtilityTerm(89, sovOrHovTripFlag * notWorkSchoolTourFlag * (trip.Sequence==1).ToFlag() * Math.Max(time.ModeLOS.GeneralizedTimeLogsum, 0) * tour.TimeCoefficient);

                alternative.AddUtilityTerm(92, Math.Log(departurePeriodFraction));
                //alternative.AddUtilityTerm(92, halfTourFromDestinationFlag * Math.Log(departurePeriodFraction));
                alternative.AddUtilityTerm(99, tripRemainingInHalfTour / (Math.Max(1D, Math.Abs(trip.ArrivalTimeLimit - period.Middle))));
                //alternative.AddUtilityTerm(97, remainingToursCount / (Math.Max(1D, totalWindowRemaining)));
                alternative.AddUtilityTerm(98, 1000 * remainingToursCount / (Math.Max(1D, maxWindowRemaining)));
            }
        }
예제 #9
0
파일: TripTest.cs 프로젝트: sfcta/DaySim
        public void TestTripWrapperIsOther()
        {
            Global.Configuration = new Configuration {
                HouseholdSamplingRateOneInX = 256
            };
            Trip trip = new Trip {
                Mode = Constants.Mode.BIKE
            };
            TourWrapper tour = TestHelper.GetTourWrapper();

            TourWrapper.HalfTour halfTour = new TourWrapper.HalfTour(tour);
            TripWrapper          wrapper  = new TripWrapper(trip, tour, halfTour);

            Assert.Equal(false, wrapper.IsTransitMode);
            Assert.Equal(false, wrapper.UsesSovOrHovModes);

            trip = new Trip {
                Mode = Constants.Mode.HOV2
            };
            wrapper = new TripWrapper(trip, tour, halfTour);
            Assert.Equal(false, wrapper.IsTransitMode);
            Assert.Equal(true, wrapper.UsesSovOrHovModes);

            trip = new Trip {
                Mode = Constants.Mode.HOV3
            };
            wrapper = new TripWrapper(trip, tour, halfTour);
            Assert.Equal(false, wrapper.IsTransitMode);
            Assert.Equal(true, wrapper.UsesSovOrHovModes);

            trip = new Trip {
                Mode = Constants.Mode.HOVDRIVER
            };
            wrapper = new TripWrapper(trip, tour, halfTour);
            Assert.Equal(false, wrapper.IsTransitMode);
            Assert.Equal(true, wrapper.UsesSovOrHovModes);

            trip = new Trip {
                Mode = Constants.Mode.HOVPASSENGER
            };
            wrapper = new TripWrapper(trip, tour, halfTour);
            Assert.Equal(false, wrapper.IsTransitMode);
            Assert.Equal(true, wrapper.UsesSovOrHovModes);

            trip = new Trip {
                Mode = Constants.Mode.NONE
            };
            wrapper = new TripWrapper(trip, tour, halfTour);
            Assert.Equal(false, wrapper.IsTransitMode);
            Assert.Equal(false, wrapper.UsesSovOrHovModes);

            trip = new Trip {
                Mode = Constants.Mode.OTHER
            };
            wrapper = new TripWrapper(trip, tour, halfTour);
            Assert.Equal(false, wrapper.IsTransitMode);
            Assert.Equal(false, wrapper.UsesSovOrHovModes);

            trip = new Trip {
                Mode = Constants.Mode.PARK_AND_RIDE
            };
            wrapper = new TripWrapper(trip, tour, halfTour);
            Assert.Equal(false, wrapper.IsTransitMode);
            Assert.Equal(false, wrapper.UsesSovOrHovModes);

            trip = new Trip {
                Mode = Constants.Mode.SCHOOL_BUS
            };
            wrapper = new TripWrapper(trip, tour, halfTour);
            Assert.Equal(false, wrapper.IsTransitMode);
            Assert.Equal(false, wrapper.UsesSovOrHovModes);

            trip = new Trip {
                Mode = Constants.Mode.SOV
            };
            wrapper = new TripWrapper(trip, tour, halfTour);
            Assert.Equal(false, wrapper.IsTransitMode);
            Assert.Equal(true, wrapper.UsesSovOrHovModes);

            trip = new Trip {
                Mode = Constants.Mode.TRANSIT
            };
            wrapper = new TripWrapper(trip, tour, halfTour);
            Assert.Equal(true, wrapper.IsTransitMode);
            Assert.Equal(false, wrapper.UsesSovOrHovModes);

            trip = new Trip {
                Mode = Constants.Mode.WALK
            };
            wrapper = new TripWrapper(trip, tour, halfTour);
            Assert.Equal(false, wrapper.IsTransitMode);
            Assert.Equal(false, wrapper.UsesSovOrHovModes);
        }
예제 #10
0
파일: TripTest.cs 프로젝트: sfcta/DaySim
        public void TestTripWrapperIsDestination()
        {
            Global.Configuration = new Configuration {
                HouseholdSamplingRateOneInX = 256
            };
            Trip        trip = new Trip();
            TourWrapper tour = TestHelper.GetTourWrapper();

            TourWrapper.HalfTour halfTour = new TourWrapper.HalfTour(tour);
            TripWrapper          wrapper  = new TripWrapper(trip, tour, halfTour);

            Assert.Equal(false, wrapper.IsEscortDestinationPurpose);
            Assert.Equal(false, wrapper.IsEscortPurposeByDestination);
            Assert.Equal(false, wrapper.IsMealDestinationPurpose);
            Assert.Equal(false, wrapper.IsMedicalDestinationPurpose);
            Assert.Equal(true, wrapper.IsNoneOrHomePurposeByDestination);
            Assert.Equal(false, wrapper.IsPersonalBusinessDestinationPurpose);
            Assert.Equal(false, wrapper.IsPersonalBusinessOrMedicalDestinationPurpose);
            Assert.Equal(false, wrapper.IsPersonalReasonsDestinationPurpose);
            Assert.Equal(false, wrapper.IsRecreationDestinationPurpose);
            Assert.Equal(false, wrapper.IsSchoolDestinationPurpose);
            Assert.Equal(false, wrapper.IsShoppingDestinationPurpose);
            Assert.Equal(false, wrapper.IsSocialDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkOrSchoolDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkPurposeByDestination);

            trip = new Trip {
                DestinationPurpose = Constants.Purpose.BUSINESS
            };
            wrapper = new TripWrapper(trip, tour, halfTour);

            Assert.Equal(false, wrapper.IsEscortDestinationPurpose);
            Assert.Equal(false, wrapper.IsEscortPurposeByDestination);
            Assert.Equal(false, wrapper.IsMealDestinationPurpose);
            Assert.Equal(false, wrapper.IsMedicalDestinationPurpose);
            Assert.Equal(false, wrapper.IsNoneOrHomePurposeByDestination);
            Assert.Equal(false, wrapper.IsPersonalBusinessDestinationPurpose);
            Assert.Equal(false, wrapper.IsPersonalBusinessOrMedicalDestinationPurpose);
            Assert.Equal(false, wrapper.IsPersonalReasonsDestinationPurpose);
            Assert.Equal(false, wrapper.IsRecreationDestinationPurpose);
            Assert.Equal(false, wrapper.IsSchoolDestinationPurpose);
            Assert.Equal(false, wrapper.IsShoppingDestinationPurpose);
            Assert.Equal(false, wrapper.IsSocialDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkOrSchoolDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkPurposeByDestination);

            trip = new Trip {
                DestinationPurpose = Constants.Purpose.ESCORT
            };
            wrapper = new TripWrapper(trip, tour, halfTour);

            Assert.Equal(true, wrapper.IsEscortDestinationPurpose);
            Assert.Equal(true, wrapper.IsEscortPurposeByDestination);
            Assert.Equal(false, wrapper.IsMealDestinationPurpose);
            Assert.Equal(false, wrapper.IsMedicalDestinationPurpose);
            Assert.Equal(false, wrapper.IsNoneOrHomePurposeByDestination);
            Assert.Equal(false, wrapper.IsPersonalBusinessDestinationPurpose);
            Assert.Equal(false, wrapper.IsPersonalBusinessOrMedicalDestinationPurpose);
            Assert.Equal(false, wrapper.IsPersonalReasonsDestinationPurpose);
            Assert.Equal(false, wrapper.IsRecreationDestinationPurpose);
            Assert.Equal(false, wrapper.IsSchoolDestinationPurpose);
            Assert.Equal(false, wrapper.IsShoppingDestinationPurpose);
            Assert.Equal(false, wrapper.IsSocialDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkOrSchoolDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkPurposeByDestination);

            trip = new Trip {
                DestinationPurpose = Constants.Purpose.MEAL
            };
            wrapper = new TripWrapper(trip, tour, halfTour);

            Assert.Equal(false, wrapper.IsEscortDestinationPurpose);
            Assert.Equal(false, wrapper.IsEscortPurposeByDestination);
            Assert.Equal(true, wrapper.IsMealDestinationPurpose);
            Assert.Equal(false, wrapper.IsMedicalDestinationPurpose);
            Assert.Equal(false, wrapper.IsNoneOrHomePurposeByDestination);
            Assert.Equal(false, wrapper.IsPersonalBusinessDestinationPurpose);
            Assert.Equal(false, wrapper.IsPersonalBusinessOrMedicalDestinationPurpose);
            Assert.Equal(true, wrapper.IsPersonalReasonsDestinationPurpose);
            Assert.Equal(false, wrapper.IsRecreationDestinationPurpose);
            Assert.Equal(false, wrapper.IsSchoolDestinationPurpose);
            Assert.Equal(false, wrapper.IsShoppingDestinationPurpose);
            Assert.Equal(false, wrapper.IsSocialDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkOrSchoolDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkPurposeByDestination);

            trip = new Trip {
                DestinationPurpose = Constants.Purpose.MEDICAL
            };
            wrapper = new TripWrapper(trip, tour, halfTour);

            Assert.Equal(false, wrapper.IsEscortDestinationPurpose);
            Assert.Equal(false, wrapper.IsEscortPurposeByDestination);
            Assert.Equal(false, wrapper.IsMealDestinationPurpose);
            Assert.Equal(true, wrapper.IsMedicalDestinationPurpose);
            Assert.Equal(false, wrapper.IsNoneOrHomePurposeByDestination);
            Assert.Equal(false, wrapper.IsPersonalBusinessDestinationPurpose);
            Assert.Equal(true, wrapper.IsPersonalBusinessOrMedicalDestinationPurpose);
            Assert.Equal(false, wrapper.IsPersonalReasonsDestinationPurpose);
            Assert.Equal(false, wrapper.IsRecreationDestinationPurpose);
            Assert.Equal(false, wrapper.IsSchoolDestinationPurpose);
            Assert.Equal(false, wrapper.IsShoppingDestinationPurpose);
            Assert.Equal(false, wrapper.IsSocialDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkOrSchoolDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkPurposeByDestination);

            trip = new Trip {
                DestinationPurpose = Constants.Purpose.PERSONAL_BUSINESS
            };
            wrapper = new TripWrapper(trip, tour, halfTour);

            Assert.Equal(false, wrapper.IsEscortDestinationPurpose);
            Assert.Equal(false, wrapper.IsEscortPurposeByDestination);
            Assert.Equal(false, wrapper.IsMealDestinationPurpose);
            Assert.Equal(false, wrapper.IsMedicalDestinationPurpose);
            Assert.Equal(false, wrapper.IsNoneOrHomePurposeByDestination);
            Assert.Equal(true, wrapper.IsPersonalBusinessDestinationPurpose);
            Assert.Equal(true, wrapper.IsPersonalBusinessOrMedicalDestinationPurpose);
            Assert.Equal(true, wrapper.IsPersonalReasonsDestinationPurpose);
            Assert.Equal(false, wrapper.IsRecreationDestinationPurpose);
            Assert.Equal(false, wrapper.IsSchoolDestinationPurpose);
            Assert.Equal(false, wrapper.IsShoppingDestinationPurpose);
            Assert.Equal(false, wrapper.IsSocialDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkOrSchoolDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkPurposeByDestination);

            trip = new Trip {
                DestinationPurpose = Constants.Purpose.RECREATION
            };
            wrapper = new TripWrapper(trip, tour, halfTour);

            Assert.Equal(false, wrapper.IsEscortDestinationPurpose);
            Assert.Equal(false, wrapper.IsEscortPurposeByDestination);
            Assert.Equal(false, wrapper.IsMealDestinationPurpose);
            Assert.Equal(false, wrapper.IsMedicalDestinationPurpose);
            Assert.Equal(false, wrapper.IsNoneOrHomePurposeByDestination);
            Assert.Equal(false, wrapper.IsPersonalBusinessDestinationPurpose);
            Assert.Equal(false, wrapper.IsPersonalBusinessOrMedicalDestinationPurpose);
            Assert.Equal(false, wrapper.IsPersonalReasonsDestinationPurpose);
            Assert.Equal(true, wrapper.IsRecreationDestinationPurpose);
            Assert.Equal(false, wrapper.IsSchoolDestinationPurpose);
            Assert.Equal(false, wrapper.IsShoppingDestinationPurpose);
            Assert.Equal(false, wrapper.IsSocialDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkOrSchoolDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkPurposeByDestination);

            trip = new Trip {
                DestinationPurpose = Constants.Purpose.SCHOOL
            };
            wrapper = new TripWrapper(trip, tour, halfTour);

            Assert.Equal(false, wrapper.IsEscortDestinationPurpose);
            Assert.Equal(false, wrapper.IsEscortPurposeByDestination);
            Assert.Equal(false, wrapper.IsMealDestinationPurpose);
            Assert.Equal(false, wrapper.IsMedicalDestinationPurpose);
            Assert.Equal(false, wrapper.IsNoneOrHomePurposeByDestination);
            Assert.Equal(false, wrapper.IsPersonalBusinessDestinationPurpose);
            Assert.Equal(false, wrapper.IsPersonalBusinessOrMedicalDestinationPurpose);
            Assert.Equal(false, wrapper.IsPersonalReasonsDestinationPurpose);
            Assert.Equal(false, wrapper.IsRecreationDestinationPurpose);
            Assert.Equal(true, wrapper.IsSchoolDestinationPurpose);
            Assert.Equal(false, wrapper.IsShoppingDestinationPurpose);
            Assert.Equal(false, wrapper.IsSocialDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkDestinationPurpose);
            Assert.Equal(true, wrapper.IsWorkOrSchoolDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkPurposeByDestination);

            trip = new Trip {
                DestinationPurpose = Constants.Purpose.SHOPPING
            };
            wrapper = new TripWrapper(trip, tour, halfTour);

            Assert.Equal(false, wrapper.IsEscortDestinationPurpose);
            Assert.Equal(false, wrapper.IsEscortPurposeByDestination);
            Assert.Equal(false, wrapper.IsMealDestinationPurpose);
            Assert.Equal(false, wrapper.IsMedicalDestinationPurpose);
            Assert.Equal(false, wrapper.IsNoneOrHomePurposeByDestination);
            Assert.Equal(false, wrapper.IsPersonalBusinessDestinationPurpose);
            Assert.Equal(false, wrapper.IsPersonalBusinessOrMedicalDestinationPurpose);
            Assert.Equal(true, wrapper.IsPersonalReasonsDestinationPurpose);
            Assert.Equal(false, wrapper.IsRecreationDestinationPurpose);
            Assert.Equal(false, wrapper.IsSchoolDestinationPurpose);
            Assert.Equal(true, wrapper.IsShoppingDestinationPurpose);
            Assert.Equal(false, wrapper.IsSocialDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkOrSchoolDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkPurposeByDestination);

            trip = new Trip {
                DestinationPurpose = Constants.Purpose.SOCIAL
            };
            wrapper = new TripWrapper(trip, tour, halfTour);

            Assert.Equal(false, wrapper.IsEscortDestinationPurpose);
            Assert.Equal(false, wrapper.IsEscortPurposeByDestination);
            Assert.Equal(false, wrapper.IsMealDestinationPurpose);
            Assert.Equal(false, wrapper.IsMedicalDestinationPurpose);
            Assert.Equal(false, wrapper.IsNoneOrHomePurposeByDestination);
            Assert.Equal(false, wrapper.IsPersonalBusinessDestinationPurpose);
            Assert.Equal(false, wrapper.IsPersonalBusinessOrMedicalDestinationPurpose);
            Assert.Equal(true, wrapper.IsPersonalReasonsDestinationPurpose);
            Assert.Equal(false, wrapper.IsRecreationDestinationPurpose);
            Assert.Equal(false, wrapper.IsSchoolDestinationPurpose);
            Assert.Equal(false, wrapper.IsShoppingDestinationPurpose);
            Assert.Equal(true, wrapper.IsSocialDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkOrSchoolDestinationPurpose);
            Assert.Equal(false, wrapper.IsWorkPurposeByDestination);

            trip = new Trip {
                DestinationPurpose = Constants.Purpose.WORK
            };
            wrapper = new TripWrapper(trip, tour, halfTour);

            Assert.Equal(false, wrapper.IsEscortDestinationPurpose);
            Assert.Equal(false, wrapper.IsEscortPurposeByDestination);
            Assert.Equal(false, wrapper.IsMealDestinationPurpose);
            Assert.Equal(false, wrapper.IsMedicalDestinationPurpose);
            Assert.Equal(false, wrapper.IsNoneOrHomePurposeByDestination);
            Assert.Equal(false, wrapper.IsPersonalBusinessDestinationPurpose);
            Assert.Equal(false, wrapper.IsPersonalBusinessOrMedicalDestinationPurpose);
            Assert.Equal(false, wrapper.IsPersonalReasonsDestinationPurpose);
            Assert.Equal(false, wrapper.IsRecreationDestinationPurpose);
            Assert.Equal(false, wrapper.IsSchoolDestinationPurpose);
            Assert.Equal(false, wrapper.IsShoppingDestinationPurpose);
            Assert.Equal(false, wrapper.IsSocialDestinationPurpose);
            Assert.Equal(true, wrapper.IsWorkDestinationPurpose);
            Assert.Equal(true, wrapper.IsWorkOrSchoolDestinationPurpose);
            Assert.Equal(true, wrapper.IsWorkPurposeByDestination);
        }
예제 #11
0
파일: TripTest.cs 프로젝트: sfcta/DaySim
        public void TestTripWrapper()
        {
            Global.Configuration = new Configuration();
            Global.Configuration.HouseholdSamplingRateOneInX = 256;

            int    id                     = 1;
            int    tourId                 = 2;
            int    householdId            = 3;
            int    personSequence         = 4;
            int    day                    = 5;
            int    tourSequence           = 6;
            int    halfTourId             = 7;
            int    sequence               = 8;
            int    surveyTripSequence     = 9;
            int    originPurpose          = 10;
            int    destinationPurpose     = 11;
            int    originAddressType      = 12;
            int    destinationAddressType = 13;
            int    originParcelId         = 14;
            int    originZoneKey          = 15;
            int    destinationParcelId    = 16;
            int    destinationZoneKey     = 17;
            int    mode                   = 18;
            int    pathType               = 19;
            int    driverType             = 20;
            int    departureTime          = 21;
            int    arrivalTime            = 22;
            int    activityEndTime        = 23;
            double travelTime             = 24.01;
            double travelCost             = 25.01;
            double travelDistance         = 26.01;
            double valueOfTime            = 27.01;
            double expansionFactor        = 28.01;

            Trip trip = new Trip
            {
                ActivityEndTime        = activityEndTime,
                ArrivalTime            = arrivalTime,
                Day                    = day,
                DepartureTime          = departureTime,
                DestinationAddressType = destinationAddressType,
                DestinationParcelId    = destinationParcelId,
                DestinationPurpose     = destinationPurpose,
                DestinationZoneKey     = destinationZoneKey,
                DriverType             = driverType,
                ExpansionFactor        = expansionFactor,
                HalfTour               = halfTourId,
                HouseholdId            = householdId,
                Id   = id,
                Mode = mode,
                OriginAddressType  = originAddressType,
                OriginParcelId     = originParcelId,
                OriginPurpose      = originPurpose,
                OriginZoneKey      = originZoneKey,
                PathType           = pathType,
                PersonSequence     = personSequence,
                Sequence           = sequence,
                SurveyTripSequence = surveyTripSequence,
                TourId             = tourId,
                TourSequence       = tourSequence,
                TravelCost         = travelCost,
                TravelDistance     = travelDistance,
                TravelTime         = travelTime,
                ValueOfTime        = valueOfTime,
            };

            TourWrapper tour = TestHelper.GetTourWrapper();

            TourWrapper.HalfTour halfTour = new TourWrapper.HalfTour(tour);
            TripWrapper          wrapper  = new TripWrapper(trip, tour, halfTour);

            Assert.Equal(id, wrapper.Id);
            Assert.Equal(tour, wrapper.Tour);
            Assert.Equal(tour.Household, wrapper.Household);
            Assert.Equal(tour.Person, wrapper.Person);
            Assert.Equal(day, wrapper.Day);
            Assert.Equal(halfTour, wrapper.HalfTour);
            Assert.Equal(sequence, wrapper.Sequence);
            Assert.Equal(originPurpose, wrapper.OriginPurpose);
            Assert.Equal(destinationPurpose, wrapper.DestinationPurpose);
            Assert.Equal(destinationAddressType, wrapper.DestinationAddressType);
            Assert.Equal(originParcelId, wrapper.OriginParcelId);
            Assert.Equal(originZoneKey, wrapper.OriginZoneKey);
            Assert.Equal(destinationParcelId, wrapper.DestinationParcelId);
            Assert.Equal(destinationZoneKey, wrapper.DestinationZoneKey);
            Assert.Equal(mode, wrapper.Mode);
            Assert.Equal(pathType, wrapper.PathType);
            Assert.Equal(driverType, wrapper.DriverType);
            Assert.Equal(departureTime.ToMinutesAfter3AM(), wrapper.DepartureTime);
            Assert.Equal(arrivalTime.ToMinutesAfter3AM(), wrapper.ArrivalTime);
            Assert.Equal(activityEndTime.ToMinutesAfter3AM(), wrapper.ActivityEndTime);
            Assert.Equal(valueOfTime, wrapper.ValueOfTime);

            int newDepartureTime = 100;

            wrapper.DepartureTime = newDepartureTime;
            Assert.Equal(newDepartureTime.ToMinutesAfterMidnight().ToMinutesAfter3AM(), wrapper.DepartureTime);

            Assert.Equal(0, wrapper.ArrivalTimeLimit);

            wrapper.ArrivalTimeLimit = 2;
            Assert.Equal(2, wrapper.ArrivalTimeLimit);

            Assert.Equal(0, wrapper.EarliestDepartureTime);
            wrapper.EarliestDepartureTime = 2;
            Assert.Equal(2, wrapper.EarliestDepartureTime);

            Assert.Equal(0, wrapper.LatestDepartureTime);
            wrapper.LatestDepartureTime = 2;
            Assert.Equal(2, wrapper.LatestDepartureTime);


            Assert.Equal(null, wrapper.DestinationParcel);
            CondensedParcel destinationParcel = new CondensedParcel();

            wrapper.DestinationParcel = destinationParcel;
            Assert.Equal(destinationParcel, wrapper.DestinationParcel);


            Assert.Equal(false, wrapper.IsMissingData);
            wrapper.IsMissingData = true;
            Assert.Equal(true, wrapper.IsMissingData);

            /*TripModeImpedance[] impedances = wrapper.GetTripModeImpedances();
             * wrapper.HUpdateTripValues();
             * wrapper.SetActivityEndTime();
             * wrapper.SetDriverOrPassenger();
             * wrapper.SetOriginAddressType();
             * wrapper.SetTourSequence();
             * wrapper.SetTripValueOfTime();
             * wrapper.Invert();
             */
        }
예제 #12
0
        public void Run(HouseholdDayWrapper householdDay, TripWrapper trip)
        {
            if (trip == null)
            {
                throw new ArgumentNullException("trip");
            }

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

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

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

                int choice = (int)chosenAlternative.Choice;

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

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

                else
                {
                    IPathTypeModel chosenPathType = pathTypeModels.First(x => x.Mode == choice);
                    trip.PathType = chosenPathType.PathType;
                }
            }
        }
예제 #13
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, TripWrapper trip,
                              IEnumerable <IPathTypeModel> pathTypeModels, IParcelWrapper originParcel,
                              IParcelWrapper destinationParcel,
                              int choice = Constants.DEFAULT_VALUE)
        {
            IHouseholdWrapper household = trip.Household;

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

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

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

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

            int PTpass = person.TransitPassOwnership;

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

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

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

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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            ChoiceProbabilityCalculator.Alternative alternative;

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

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

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

                if (!available)
                {
                    continue;
                }

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

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

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

                    alternative.AddUtilityTerm(57, PTpass);

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

                    alternative.AddUtilityTerm(115, transitTourFlag);

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

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

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

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

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

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

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

                    alternative.AddUtilityTerm(126, maleFlag);

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

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

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

                    alternative.AddUtilityTerm(132, maleFlag);

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

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

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

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

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

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

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