예제 #1
0
        private ChoiceProbabilityCalculator.Alternative RunNested(ITourWrapper tour, IParcelWrapper destinationParcel, int householdCars, double transitDiscountFraction)
        {
            var choiceProbabilityCalculator = _helpers[ParallelUtility.GetBatchFromThreadId()].GetNestedChoiceProbabilityCalculator();

            var pathTypeModels =
                PathTypeModel.RunAll(
                    tour.Household.RandomUtility,
                    tour.OriginParcel,
                    destinationParcel,
                    tour.DestinationArrivalTime,
                    tour.DestinationDepartureTime,
                    tour.DestinationPurpose,
                    tour.CostCoefficient,
                    tour.TimeCoefficient,
                    tour.Person.IsDrivingAge,
                    householdCars,
                    transitDiscountFraction,
                    false);

            RunModel(choiceProbabilityCalculator, tour, pathTypeModels, destinationParcel, householdCars);

            return(choiceProbabilityCalculator.SimulateChoice(tour.Household.RandomUtility));
        }
예제 #2
0
        public void Run(TourWrapper tour)
        {
            if (tour == null)
            {
                throw new ArgumentNullException("tour");
            }

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

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

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

            if (_helpers[ParallelUtility.threadLocalAssignedIndex.Value].ModelIsInEstimationMode)
            {
                if (tour.DestinationParcel == null || (tour.Mode > Global.Settings.Modes.Hov3 || tour.Mode < Global.Settings.Modes.Walk))
                {
                    return;
                }

                var pathTypeModels =
                    PathTypeModel.Run(
                        tour.Household.RandomUtility,
                        tour.OriginParcel,
                        tour.DestinationParcel,
                        tour.DestinationArrivalTime,
                        tour.DestinationDepartureTime,
                        tour.DestinationPurpose,
                        tour.CostCoefficient,
                        tour.TimeCoefficient,
                        tour.Person.IsDrivingAge,
                        tour.Household.VehiclesAvailable,
                        tour.Person.GetTransitFareDiscountFraction(),
                        false,
                        Global.Settings.Modes.Walk, Global.Settings.Modes.Bike, Global.Settings.Modes.Sov, Global.Settings.Modes.Hov2, Global.Settings.Modes.Hov3);

                var pathTypeModel = pathTypeModels.First(x => x.Mode == tour.Mode);

                if (!pathTypeModel.Available)
                {
                    return;
                }

                RunModel(choiceProbabilityCalculator, tour, pathTypeModels, tour.DestinationParcel, tour.Mode);

                choiceProbabilityCalculator.WriteObservation();
            }
            else
            {
                var pathTypeModels =
                    PathTypeModel.Run(
                        tour.Household.RandomUtility,
                        tour.OriginParcel,
                        tour.DestinationParcel,
                        tour.DestinationArrivalTime,
                        tour.DestinationDepartureTime,
                        tour.DestinationPurpose,
                        tour.CostCoefficient,
                        tour.TimeCoefficient,
                        tour.Person.IsDrivingAge,
                        tour.Household.VehiclesAvailable,
                        tour.Person.GetTransitFareDiscountFraction(),
                        false,
                        Global.Settings.Modes.Walk, Global.Settings.Modes.Bike, Global.Settings.Modes.Sov, Global.Settings.Modes.Hov2, Global.Settings.Modes.Hov3);

                RunModel(choiceProbabilityCalculator, tour, pathTypeModels, tour.DestinationParcel);

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

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

                var choice = (int)chosenAlternative.Choice;

                tour.Mode = choice;
                var chosenPathType = pathTypeModels.First(x => x.Mode == choice);
                tour.PathType          = chosenPathType.PathType;
                tour.ParkAndRideNodeId = choice == Global.Settings.Modes.ParkAndRide ? chosenPathType.PathParkAndRideNodeId : 0;
            }
        }
예제 #3
0
        public void Run(ITourWrapper tour)
        {
            if (tour == null)
            {
                throw new ArgumentNullException("tour");
            }

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

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

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

            if (_helpers[ParallelUtility.GetBatchFromThreadId()].ModelIsInEstimationMode)
            {
                if (tour.DestinationParcel == null || tour.Mode <= Global.Settings.Modes.None || (tour.Mode > Global.Settings.Modes.Transit && tour.Mode != Global.Settings.Modes.SchoolBus))
                {
                    return;
                }

                var pathTypeModels =
                    PathTypeModel.RunAll(
                        tour.Household.RandomUtility,
                        tour.OriginParcel,
                        tour.DestinationParcel,
                        tour.DestinationArrivalTime,
                        tour.DestinationDepartureTime,
                        tour.DestinationPurpose,
                        tour.CostCoefficient,
                        tour.TimeCoefficient,
                        tour.Person.IsDrivingAge,
                        tour.Household.VehiclesAvailable,
                        tour.Person.GetTransitFareDiscountFraction(),
                        false);

                var mode          = (tour.Mode == Global.Settings.Modes.SchoolBus) ? Global.Settings.Modes.Hov3 : tour.Mode;        // use HOV3 for school bus impedance
                var pathTypeModel = pathTypeModels.First(x => x.Mode == mode);

                if (!pathTypeModel.Available)
                {
                    return;
                }

                RunModel(choiceProbabilityCalculator, tour, pathTypeModels, tour.DestinationParcel, tour.Household.VehiclesAvailable, tour.Mode);

                choiceProbabilityCalculator.WriteObservation();
            }
            else
            {
                var pathTypeModels =
                    PathTypeModel.RunAll(
                        tour.Household.RandomUtility,
                        tour.OriginParcel,
                        tour.DestinationParcel,
                        tour.DestinationArrivalTime,
                        tour.DestinationDepartureTime,
                        tour.DestinationPurpose,
                        tour.CostCoefficient,
                        tour.TimeCoefficient,
                        tour.Person.IsDrivingAge,
                        tour.Household.VehiclesAvailable,
                        tour.Person.GetTransitFareDiscountFraction(),
                        false);

                RunModel(choiceProbabilityCalculator, tour, pathTypeModels, tour.DestinationParcel, tour.Household.VehiclesAvailable);

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

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

                var choice = (int)chosenAlternative.Choice;

                tour.Mode = choice;
                if (choice == Global.Settings.Modes.SchoolBus)
                {
                    tour.PathType = 0;
                }
                else
                {
                    var chosenPathType = pathTypeModels.First(x => x.Mode == choice);
                    tour.PathType          = chosenPathType.PathType;
                    tour.ParkAndRideNodeId = choice == Global.Settings.Modes.ParkAndRide ? chosenPathType.PathParkAndRideNodeId : 0;
                }
            }
        }