public void Run(IPersonDayWrapper personDay)
        {
            if (personDay == null)
            {
                throw new ArgumentNullException("personDay");
            }

            personDay.ResetRandom(5);

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

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

            if (_helpers[ParallelUtility.threadLocalAssignedIndex.Value].ModelIsInEstimationMode)
            {
                RunModel(choiceProbabilityCalculator, personDay, new DayPattern(personDay));

                choiceProbabilityCalculator.WriteObservation();
            }
            else
            {
                if (personDay.Person.UsualWorkParcelId != Global.Settings.OutOfRegionParcelId && personDay.Person.UsualSchoolParcelId != Global.Settings.OutOfRegionParcelId)
                {
                    RunModel(choiceProbabilityCalculator, personDay);

                    ChoiceProbabilityCalculator.Alternative chosenAlternative = choiceProbabilityCalculator.SimulateChoice(personDay.Household.RandomUtility);
                    DayPattern choice = (DayPattern)chosenAlternative.Choice;

                    personDay.WorkTours             = choice.WorkTours;
                    personDay.SchoolTours           = choice.SchoolTours;
                    personDay.EscortTours           = choice.EscortTours;
                    personDay.PersonalBusinessTours = choice.PersonalBusinessTours;
                    personDay.ShoppingTours         = choice.ShoppingTours;
                    personDay.MealTours             = choice.MealTours;
                    personDay.SocialTours           = choice.SocialTours;

                    personDay.WorkStops             = choice.WorkStops;
                    personDay.SchoolStops           = choice.SchoolStops;
                    personDay.EscortStops           = choice.EscortStops;
                    personDay.PersonalBusinessStops = choice.PersonalBusinessStops;
                    personDay.ShoppingStops         = choice.ShoppingStops;
                    personDay.MealStops             = choice.MealStops;
                    personDay.SocialStops           = choice.SocialStops;
                }
            }
        }
Esempio n. 2
0
        public void Run(IPersonDayWrapper personDay, int purpose)
        {
            if (personDay == null)
            {
                throw new ArgumentNullException("personDay");
            }


            personDay.ResetRandom(890 + purpose);

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

            ChoiceProbabilityCalculator choiceProbabilityCalculator = _helpers[ParallelUtility.threadLocalAssignedIndex.Value].GetChoiceProbabilityCalculator((personDay.Id * 397) ^ purpose);

            if (_helpers[ParallelUtility.threadLocalAssignedIndex.Value].ModelIsInEstimationMode)
            {
                int tours;

                if (purpose == Global.Settings.Purposes.Work)
                {
                    tours = personDay.WorkTours;
                }
                else if (purpose == Global.Settings.Purposes.School)
                {
                    tours = personDay.SchoolTours;
                }
                else if (purpose == Global.Settings.Purposes.Escort)
                {
                    tours = personDay.EscortTours;
                }
                else if (purpose == Global.Settings.Purposes.PersonalBusiness)
                {
                    tours = personDay.PersonalBusinessTours;
                }
                else if (purpose == Global.Settings.Purposes.Shopping)
                {
                    tours = personDay.ShoppingTours;
                }
                else if (purpose == Global.Settings.Purposes.Meal)
                {
                    tours = personDay.MealTours;
                }
                else if (purpose == Global.Settings.Purposes.Social)
                {
                    tours = personDay.SocialTours;
                }
                else
                {
                    tours = Constants.DEFAULT_VALUE;
                }

                RunModel(choiceProbabilityCalculator, personDay, purpose, tours);

                choiceProbabilityCalculator.WriteObservation();
            }
            else
            {
                RunModel(choiceProbabilityCalculator, personDay, purpose);

                ChoiceProbabilityCalculator.Alternative chosenAlternative = choiceProbabilityCalculator.SimulateChoice(personDay.Household.RandomUtility);
                int choice = (int)chosenAlternative.Choice;

                personDay.HomeBasedTours += choice;

                if (purpose == Global.Settings.Purposes.Work)
                {
                    personDay.WorkTours = choice;
                }
                else if (purpose == Global.Settings.Purposes.School)
                {
                    personDay.SchoolTours = choice;
                }
                else if (purpose == Global.Settings.Purposes.Escort)
                {
                    personDay.EscortTours = choice;
                }
                else if (purpose == Global.Settings.Purposes.PersonalBusiness)
                {
                    personDay.PersonalBusinessTours = choice;
                }
                else if (purpose == Global.Settings.Purposes.Shopping)
                {
                    personDay.ShoppingTours = choice;
                }
                else if (purpose == Global.Settings.Purposes.Meal)
                {
                    personDay.MealTours = choice;
                }
                else if (purpose == Global.Settings.Purposes.Social)
                {
                    personDay.SocialTours = choice;
                }
            }
        }