Ejemplo n.º 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();
            }
        }
Ejemplo n.º 2
0
        public void TestPersonWrapperTransitFareDiscountFraction()
        {
            Global.Configuration = new Configuration {
                HouseholdSamplingRateOneInX = 1
            };
            Global.Configuration.PathImpedance_TransitUseFareDiscountFractions = false;
            List <IPerson> persons = new List <IPerson>()
            {
                new Person()
                {
                    Age = 4,
                    TransitPassOwnership = 1,
                    PersonType           = Constants.PersonType.CHILD_UNDER_5,
                }
            };
            HouseholdWrapper household = TestHelper.GetHouseholdWrapper(persons);

            household.Init();
            PersonWrapper wrapper = new PersonWrapper(persons[0], household)
            {
            };

            Assert.Equal(0, wrapper.TransitFareDiscountFraction);
            Global.Configuration.PathImpedance_TransitUseFareDiscountFractions = true;
            Global.Configuration.IncludeTransitPassOwnershipModel = true;
            Assert.Equal(1, wrapper.TransitFareDiscountFraction);

            Global.Configuration.IncludeTransitPassOwnershipModel            = false;
            Global.Configuration.Policy_UniversalTransitFareDiscountFraction = .1;
            Assert.Equal(.1, wrapper.TransitFareDiscountFraction);

            Global.Configuration.PathImpedance_TransitFareDiscountFractionChildUnder5 = .2;
            Global.Configuration.Policy_UniversalTransitFareDiscountFraction          = 0;
            Assert.Equal(.2, wrapper.TransitFareDiscountFraction);

            wrapper = TestHelper.GetPersonWrapper(personType: Constants.PersonType.CHILD_AGE_5_THROUGH_15);
            Global.Configuration.PathImpedance_TransitFareDiscountFractionChild5To15 = .3;
            Assert.Equal(.3, wrapper.TransitFareDiscountFraction);

            wrapper = TestHelper.GetPersonWrapper(personType: Constants.PersonType.DRIVING_AGE_STUDENT);
            Global.Configuration.PathImpedance_TransitFareDiscountFractionHighSchoolStudent = .4;
            Assert.Equal(.4, wrapper.TransitFareDiscountFraction);

            wrapper = TestHelper.GetPersonWrapper(personType: Constants.PersonType.UNIVERSITY_STUDENT);
            Global.Configuration.PathImpedance_TransitFareDiscountFractionUniverityStudent = .5;
            Assert.Equal(.5, wrapper.TransitFareDiscountFraction);

            wrapper = TestHelper.GetPersonWrapper(age: 65);
            Global.Configuration.PathImpedance_TransitFareDiscountFractionAge65Up = .6;
            Assert.Equal(.6, wrapper.TransitFareDiscountFraction);

            wrapper = TestHelper.GetPersonWrapper(age: 64);
            Assert.Equal(0, wrapper.TransitFareDiscountFraction);
        }
Ejemplo n.º 3
0
        public void Run(HouseholdWrapper household)
        {
            if (household == null)
            {
                throw new ArgumentNullException("household");
            }

            household.ResetRandom(4);

            if (Global.Configuration.IsInEstimationMode)
            {
                if (Global.Configuration.EstimationModel != CHOICE_MODEL_NAME)
                {
                    return;
                }
            }
            else if (Global.Configuration.AV_IncludeAutoTypeChoice)
            {
                ChoiceProbabilityCalculator AVchoiceProbabilityCalculator = _helpers[ParallelUtility.threadLocalAssignedIndex.Value].GetChoiceProbabilityCalculator(household.Id);
                RunAVModel(AVchoiceProbabilityCalculator, household);
                ChoiceProbabilityCalculator.Alternative chosenAlternative = AVchoiceProbabilityCalculator.SimulateChoice(household.RandomUtility);
                int choice = (int)chosenAlternative.Choice;

                household.OwnsAutomatedVehicles = choice;
            }

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

            int vehicles = household.VehiclesAvailable;

            if (household.VehiclesAvailable > 2)
            {
                vehicles = 2;
            }

            if (_helpers[ParallelUtility.threadLocalAssignedIndex.Value].ModelIsInEstimationMode)
            {
                RunModel(choiceProbabilityCalculator, household, vehicles);

                choiceProbabilityCalculator.WriteObservation();
            }
            else
            {
                RunModel(choiceProbabilityCalculator, household);

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

                household.VehiclesAvailable = choice;
            }
        }
Ejemplo n.º 4
0
        public void TestHouseholdWrapperFractionWorkersWithJobsOutsideRegion()
        {
            Global.Configuration = new Configuration();
            Global.Configuration.HouseholdSamplingRateOneInX = 1;
            List <IPerson> persons = new List <IPerson> {
                new Person {
                    Age = 37, PersonType = Constants.PersonType.FULL_TIME_WORKER, WorkerType = 1
                }
            };
            HouseholdWrapper wrapper = TestHelper.GetHouseholdWrapper(persons, fractionWorkersWithJobsOutsideRegion: .24);

            wrapper.Init();
            Assert.Equal(.24, wrapper.FractionWorkersWithJobsOutsideRegion);
        }
Ejemplo n.º 5
0
        public static PersonDayWrapper GetPersonDayWrapper(PersonWrapper personWrapper = null, int income = 0)
        {
            List <IPerson> persons = new List <IPerson> {
                new Person()
            };
            HouseholdWrapper    householdWrapper = TestHelper.GetHouseholdWrapper(persons, income: income);
            HouseholdDayWrapper householdDay     = TestHelper.GetHouseholdDayWrapper(householdWrapper: householdWrapper);

            if (personWrapper == null)
            {
                personWrapper = GetPersonWrapper(household: householdWrapper);
            }
            return(new PersonDayWrapper(new PersonDay(), personWrapper, householdDay));
        }
Ejemplo n.º 6
0
        public void Run(HouseholdWrapper household)
        {
            if (household == null)
            {
                throw new ArgumentNullException("household");
            }

            household.ResetRandom(4);

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

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

            if (household.VehiclesAvailable > 4)
            {
                household.VehiclesAvailable = 4;
            }

            if (_helpers[ParallelUtility.threadLocalAssignedIndex.Value].ModelIsInEstimationMode)
            {
                RunModel(choiceProbabilityCalculator, household, household.VehiclesAvailable);

                choiceProbabilityCalculator.WriteObservation();
            }
            else if (Global.Configuration.TestEstimationModelInApplicationMode)
            {
                Global.Configuration.IsInEstimationMode = false;
                RunModel(choiceProbabilityCalculator, household);
                ChoiceProbabilityCalculator.Alternative chosenAlternative = choiceProbabilityCalculator.SimulateChoice(household.RandomUtility, household.Id, household.VehiclesAvailable);
                Global.Configuration.IsInEstimationMode = true;
            }
            else
            {
                RunModel(choiceProbabilityCalculator, household);

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

                household.VehiclesAvailable = choice;
            }
        }
Ejemplo n.º 7
0
        public void TestHouseholdDayWrapperJointHalfTour()
        {
            List <IPerson> persons = new List <IPerson> {
                new Person()
            };

            Global.Configuration = new Configuration {
                HouseholdSamplingRateOneInX = 1
            };
            ChoiceModelFactory.Parcels = new Dictionary <int, CondensedParcel>();
            const int residenceParcelId = 99;

            ChoiceModelFactory.Parcels.Add(residenceParcelId, new CondensedParcel());

            HouseholdWrapper    household = TestHelper.GetHouseholdWrapper(persons);
            HouseholdDayWrapper wrapper   = TestHelper.GetHouseholdDayWrapper(householdWrapper: household);
        }
Ejemplo n.º 8
0
        public void TestHouseholdWrapper()
        {
            Global.Configuration = new Configuration();
            Global.Configuration.HouseholdSamplingRateOneInX = 256;

            const int id = 3;

            List <IPerson> persons = new List <IPerson> {
                new Person {
                    HouseholdId = id, Age = 20, PersonType = Constants.PersonType.FULL_TIME_WORKER
                },
                new Person {
                    HouseholdId = id, Age = 35, PersonType = Constants.PersonType.FULL_TIME_WORKER
                },
                new Person {
                    HouseholdId = id, Age = 37, PersonType = Constants.PersonType.FULL_TIME_WORKER
                },
                new Person {
                    HouseholdId = id, Age = 20, PersonType = Constants.PersonType.PART_TIME_WORKER
                },
                new Person {
                    HouseholdId = id, Age = 35, PersonType = Constants.PersonType.PART_TIME_WORKER
                },
                new Person {
                    HouseholdId = id, Age = 37, PersonType = Constants.PersonType.FULL_TIME_WORKER
                },
                new Person {
                    HouseholdId = id, Age = 10, PersonType = Constants.PersonType.CHILD_AGE_5_THROUGH_15
                },
            };

            HouseholdWrapper wrapper = TestHelper.GetHouseholdWrapper(persons);

            wrapper.Init();

            Assert.Equal(1, wrapper.HouseholdDays.Count);
            Assert.Equal(0, wrapper.HouseholdDays[0].AttemptedSimulations);
            Assert.Equal(0, wrapper.HouseholdDays[0].FullHalfTours);
            Assert.Equal(id, wrapper.HouseholdDays[0].Household.Id);
            Assert.Equal(false, wrapper.HouseholdDays[0].IsMissingData);
            Assert.Equal(0, wrapper.HouseholdDays[0].JointTours);
            Assert.Equal(0, wrapper.HouseholdDays[0].PartialHalfTours);
            Assert.Equal(7, wrapper.HouseholdDays[0].PersonDays.Count);
        }
Ejemplo n.º 9
0
        public void Run(HouseholdWrapper household)
        {
            if (household == null)
            {
                throw new ArgumentNullException("household");
            }

            household.ResetRandom(4);

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

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

            var vehicles = household.VehiclesAvailable;

            if (household.VehiclesAvailable > 2)
            {
                vehicles = 2;
            }

            if (_helpers[ParallelUtility.GetBatchFromThreadId()].ModelIsInEstimationMode)
            {
                RunModel(choiceProbabilityCalculator, household, vehicles);

                choiceProbabilityCalculator.WriteObservation();
            }
            else
            {
                RunModel(choiceProbabilityCalculator, household);

                var chosenAlternative = choiceProbabilityCalculator.SimulateChoice(household.RandomUtility);
                var choice            = (int)chosenAlternative.Choice;

                household.VehiclesAvailable = choice;
            }
        }
Ejemplo n.º 10
0
        public void TestAutoOwnershipModel()
        {
            Global.Configuration = new Configuration {
                NProcessors = 1
            };
            ParallelUtility.Init();
            Global.Configuration.AutoOwnershipModelCoefficients = "c:\\a.txt";
            ParallelUtility.Register(Thread.CurrentThread.ManagedThreadId, 0);
            List <IPerson> persons = new List <IPerson> {
                new Person()
            };
            CondensedParcel  residenceParcel = new CondensedParcel();
            HouseholdWrapper household       = TestHelper.GetHouseholdWrapper(persons, residenceParcel: residenceParcel);

            household.Init();
            AutoOwnershipModel model = new AutoOwnershipModel();

            model.RunInitialize(new TestCoefficientsReader());
            model.Run(household);
        }
Ejemplo n.º 11
0
        public static HouseholdDayWrapper GetHouseholdDayWrapper(HouseholdWrapper householdWrapper = null, Household household = null, int id = 3)
        {
            List <IPerson> persons = new List <IPerson> {
                new Person()
            };

            if (householdWrapper == null)
            {
                householdWrapper = GetHouseholdWrapper(persons, household: household);
            }
            householdWrapper.Init();
            Global.Configuration.DataType = "Default";
            PersonDayWrapperFactory factory = new PersonDayWrapperFactory();

            factory.Register("Default", new PersonDayWrapperCreator());
            factory.Initialize();
            return(new HouseholdDayWrapper(new HouseholdDay()
            {
                Id = id
            }, householdWrapper, factory));
        }
Ejemplo n.º 12
0
        public void TestAutoOwnershipModelNullHouseholdException()
        {
            Global.Configuration = new Configuration {
                NProcessors = 1
            };
            ParallelUtility.Init();
            Global.Configuration.AutoOwnershipModelCoefficients = "c:\\a.txt";
            ParallelUtility.Register(Thread.CurrentThread.ManagedThreadId, 0);
            List <IPerson> persons = new List <IPerson> {
                new Person()
            };
            CondensedParcel  residenceParcel = new CondensedParcel();
            HouseholdWrapper household       = TestHelper.GetHouseholdWrapper(persons, residenceParcel: residenceParcel);

            household.Init();
            AutoOwnershipModel model = new AutoOwnershipModel();

            model.RunInitialize(new TestCoefficientsReader());
            ArgumentNullException ex = Assert.Throws <ArgumentNullException>(() => model.Run(null));

            Assert.Equal("Value cannot be null.\r\nParameter name: household", ex.Message);
        }
Ejemplo n.º 13
0
        public void TestHouseholdDayWrapperFullHalfTour()
        {
            List <IPerson> persons = new List <IPerson> {
                new Person()
            };

            Global.Configuration = new Configuration {
                HouseholdSamplingRateOneInX = 1
            };
            ChoiceModelFactory.Parcels = new Dictionary <int, CondensedParcel>();
            const int residenceParcelId = 99;

            ChoiceModelFactory.Parcels.Add(residenceParcelId, new CondensedParcel());
            Global.Configuration.IsInEstimationMode = false;
            Global.Configuration.UseJointTours      = true;
            FullHalfTourWrapper.SetPersister(new PersisterWithHDF5 <FullHalfTour>(new TestFullHalfTourExporter()));

            HouseholdWrapper household = TestHelper.GetHouseholdWrapper(persons, id: 9);

            HouseholdDayWrapper wrapper = TestHelper.GetHouseholdDayWrapper(householdWrapper: household, id: 8);

            Assert.Equal(0, wrapper.FullHalfTours);
            Assert.Equal(0, wrapper.FullHalfToursList.Count);
            IEnumerable <PersonDayWrapper> orderedPersonDays = wrapper.PersonDays.OrderBy(p => p.JointHalfTourParticipationPriority).ToList().Cast <PersonDayWrapper>();

            int[]                participants = new [] { 0, 0, 0, 0, 0, 0, 0, 0 };
            const int            direction    = 1;
            IFullHalfTourWrapper tourWrapper  = wrapper.CreateFullHalfTour(wrapper, orderedPersonDays, participants, direction);

            Assert.Equal(1, tourWrapper.Direction);
            Assert.Equal(household, tourWrapper.Household);
            Assert.Equal(wrapper, tourWrapper.HouseholdDay);
            Assert.Equal(81, tourWrapper.Id);
            Assert.Equal(false, tourWrapper.Paired);
            tourWrapper.Paired = true;
            Assert.Equal(true, tourWrapper.Paired);
            Assert.Equal(0, tourWrapper.Participants);
        }
Ejemplo n.º 14
0
        public void TestHouseholdDayWrapper()
        {
            List <IPerson> persons = new List <IPerson> {
                new Person {
                    Id = 58
                }
            };

            Global.Configuration = new Configuration {
                HouseholdSamplingRateOneInX = 1
            };
            ChoiceModelFactory.Parcels = new Dictionary <int, CondensedParcel>();
            const int residenceParcelId = 99;

            ChoiceModelFactory.Parcels.Add(residenceParcelId, new CondensedParcel());

            HouseholdWrapper    household = TestHelper.GetHouseholdWrapper(persons);
            HouseholdDayWrapper wrapper   = TestHelper.GetHouseholdDayWrapper(householdWrapper: household);

            Assert.Equal(0, wrapper.AttemptedSimulations);
            wrapper.AttemptedSimulations++;
            Assert.Equal(1, wrapper.AttemptedSimulations);

            Assert.Equal(household, wrapper.Household);

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

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

            Assert.Equal(1, wrapper.PersonDays.Count);
            Assert.Equal(persons[0].Id, wrapper.PersonDays[0].Person.Id);
        }
Ejemplo n.º 15
0
        public void TestHouseholdWrapperExpansionFactor()
        {
            Global.Configuration = new Configuration();
            Global.Configuration.HouseholdSamplingRateOneInX = 1;
            List <IPerson> persons = new List <IPerson> {
                new Person {
                    Age = 37, PersonType = Constants.PersonType.FULL_TIME_WORKER, WorkerType = 1
                }
            };
            HouseholdWrapper wrapper = TestHelper.GetHouseholdWrapper(persons, expansionFactor: .25);

            wrapper.Init();
            Assert.Equal(.25, wrapper.ExpansionFactor);

            Global.Configuration.HouseholdSamplingRateOneInX = 4;
            wrapper = TestHelper.GetHouseholdWrapper(persons, expansionFactor: .25);
            wrapper.Init();
            Assert.Equal(1, wrapper.ExpansionFactor);

            Global.Configuration.HouseholdSamplingRateOneInX = 256;
            wrapper = TestHelper.GetHouseholdWrapper(persons, expansionFactor: .25);
            wrapper.Init();
            Assert.Equal(64, wrapper.ExpansionFactor);
        }
Ejemplo n.º 16
0
        public void TestFullHalfTourWrapper()
        {
            Global.Configuration = new Configuration();
            Global.Configuration.HouseholdSamplingRateOneInX = 256;


            const int id              = 1;
            const int householdDayId  = 2;
            const int householdId     = 3;
            const int day             = 4;
            const int sequence        = 5;
            const int direction       = 6;
            const int participants    = 7;
            const int personSequence1 = 8;
            const int tourSequence1   = 9;
            const int personSequence2 = 10;
            const int tourSequence2   = 11;
            const int personSequence3 = 12;
            const int tourSequence3   = 13;
            const int personSequence4 = 14;
            const int tourSequence4   = 15;
            const int personSequence5 = 16;
            const int tourSequence5   = 17;
            const int personSequence6 = 18;
            const int tourSequence6   = 19;
            const int personSequence7 = 20;
            const int tourSequence7   = 21;
            const int personSequence8 = 22;
            const int tourSequence8   = 23;

            FullHalfTour tour = new FullHalfTour
            {
                Day             = day,
                HouseholdDayId  = householdDayId,
                HouseholdId     = householdId,
                Id              = id,
                Direction       = direction,
                Participants    = participants,
                PersonSequence1 = personSequence1,
                TourSequence1   = tourSequence1,
                PersonSequence2 = personSequence2,
                TourSequence2   = tourSequence2,
                PersonSequence3 = personSequence3,
                TourSequence3   = tourSequence3,
                PersonSequence4 = personSequence4,
                TourSequence4   = tourSequence4,
                PersonSequence5 = personSequence5,
                TourSequence5   = tourSequence5,
                PersonSequence6 = personSequence6,
                TourSequence6   = tourSequence6,
                PersonSequence7 = personSequence7,
                TourSequence7   = tourSequence7,
                PersonSequence8 = personSequence8,
                TourSequence8   = tourSequence8,
                Sequence        = sequence
            };

            List <IPerson> persons = new List <IPerson> {
                new Person()
            };

            HouseholdWrapper householdWrapper = TestHelper.GetHouseholdWrapper(persons);

            householdWrapper.Init();
            //HouseholdDayWrapper householdDayWrapper = new HouseholdDayWrapper(new HouseholdDay(), householdWrapper, new PersonDayWrapperFactory());

            HouseholdDayWrapper householdDayWrapper = TestHelper.GetHouseholdDayWrapper(householdWrapper);

            FullHalfTourWrapper.SetPersister(new PersisterWithHDF5 <FullHalfTour>(new TestFullHalfTourExporter()));
            FullHalfTourWrapper wrapper = new FullHalfTourWrapper(tour, householdDayWrapper);

            Assert.Equal(direction, wrapper.Direction);
            Assert.Equal(id, wrapper.Id);
            Assert.Equal(participants, wrapper.Participants);
            Assert.Equal(personSequence1, wrapper.PersonSequence1);
            Assert.Equal(tourSequence1, wrapper.TourSequence1);
            Assert.Equal(personSequence2, wrapper.PersonSequence2);
            Assert.Equal(tourSequence2, wrapper.TourSequence2);
            Assert.Equal(personSequence3, wrapper.PersonSequence3);
            Assert.Equal(tourSequence3, wrapper.TourSequence3);
            Assert.Equal(personSequence4, wrapper.PersonSequence4);
            Assert.Equal(tourSequence4, wrapper.TourSequence4);
            Assert.Equal(personSequence5, wrapper.PersonSequence5);
            Assert.Equal(tourSequence5, wrapper.TourSequence5);
            Assert.Equal(personSequence6, wrapper.PersonSequence6);
            Assert.Equal(tourSequence6, wrapper.TourSequence6);
            Assert.Equal(personSequence7, wrapper.PersonSequence7);
            Assert.Equal(tourSequence7, wrapper.TourSequence7);
            Assert.Equal(personSequence8, wrapper.PersonSequence8);
            Assert.Equal(tourSequence8, wrapper.TourSequence8);
            Assert.Equal(sequence, wrapper.Sequence);


            Assert.Equal(householdWrapper, wrapper.Household);
            Assert.Equal(householdDayWrapper, wrapper.HouseholdDay);


            Global.Configuration = new Configuration {
                HouseholdSamplingRateOneInX = 1
            };
        }
Ejemplo n.º 17
0
        public void TestFullHalfTourSetParticipantTourSequence()
        {
            Global.Configuration = new Configuration();
            Global.Configuration.HouseholdSamplingRateOneInX = 256;


            const int id              = 1;
            const int householdDayId  = 2;
            const int householdId     = 3;
            const int day             = 4;
            const int sequence        = 5;
            const int direction       = 6;
            const int participants    = 7;
            const int personSequence1 = 8;
            const int tourSequence1   = 9;
            const int personSequence2 = 10;
            const int tourSequence2   = 11;
            const int personSequence3 = 12;
            const int tourSequence3   = 13;
            const int personSequence4 = 14;
            const int tourSequence4   = 15;
            const int personSequence5 = 16;
            const int tourSequence5   = 17;
            const int personSequence6 = 18;
            const int tourSequence6   = 19;
            const int personSequence7 = 20;
            const int tourSequence7   = 21;
            const int personSequence8 = 22;
            const int tourSequence8   = 23;

            FullHalfTour tour = new FullHalfTour
            {
                Day             = day,
                Direction       = direction,
                HouseholdDayId  = householdDayId,
                HouseholdId     = householdId,
                Id              = id,
                Participants    = participants,
                PersonSequence1 = personSequence1,
                TourSequence1   = tourSequence1,
                PersonSequence2 = personSequence2,
                TourSequence2   = tourSequence2,
                PersonSequence3 = personSequence3,
                TourSequence3   = tourSequence3,
                PersonSequence4 = personSequence4,
                TourSequence4   = tourSequence4,
                PersonSequence5 = personSequence5,
                TourSequence5   = tourSequence5,
                PersonSequence6 = personSequence6,
                TourSequence6   = tourSequence6,
                PersonSequence7 = personSequence7,
                TourSequence7   = tourSequence7,
                PersonSequence8 = personSequence8,
                TourSequence8   = tourSequence8,
                Sequence        = sequence
            };

            List <IPerson> persons = new List <IPerson> {
                new Person()
            };

            HouseholdWrapper householdWrapper = TestHelper.GetHouseholdWrapper(persons);

            householdWrapper.Init();
            //HouseholdDayWrapper householdDayWrapper = new HouseholdDayWrapper(new HouseholdDay(), householdWrapper, new PersonDayWrapperFactory());

            HouseholdDayWrapper householdDayWrapper = TestHelper.GetHouseholdDayWrapper(householdWrapper);

            FullHalfTourWrapper.SetPersister(new PersisterWithHDF5 <FullHalfTour>(new TestFullHalfTourExporter()));
            FullHalfTourWrapper wrapper = new FullHalfTourWrapper(tour, householdDayWrapper);

            int[] sequences  = new[] { 1, 2, 3, 4, 5, 6, 7, 8 };
            int[] pSequences = new[] { personSequence1, personSequence2, personSequence3, personSequence4, personSequence5, personSequence6, personSequence7, personSequence8 };

            for (int x = 0; x < 8; x++)
            {
                PersonWrapper    person             = TestHelper.GetPersonWrapper(sequence: pSequences[x]);
                PersonDayWrapper personDay          = TestHelper.GetPersonDayWrapper(personWrapper: person, income: -1);
                const int        destinationPurpose = Constants.Purpose.BUSINESS;

                Global.Configuration.Coefficients_BaseCostCoefficientIncomeLevel     = 25000;
                Global.Configuration.Coefficients_StdDeviationTimeCoefficient_Other  = .75;
                Global.Configuration.Coefficients_MeanTimeCoefficient_Other          = .45;
                Global.Configuration.Coefficients_BaseCostCoefficientPerMonetaryUnit = 5;
                Tour        ptour       = new Tour();
                TourWrapper tourWrapper = new TourWrapper(ptour, personDay, destinationPurpose, false)
                {
                    Sequence = sequences[x]
                };
                wrapper.SetParticipantTourSequence(tourWrapper);

                Assert.Equal(sequences[x], GetWrapperTourSequence(wrapper, x));
            }
        }
Ejemplo n.º 18
0
		private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, HouseholdWrapper household, int choice = Constants.DEFAULT_VALUE) {
			//			//			var distanceToTransitCappedUnderQtrMile = household.ResidenceParcel.DistanceToTransitCappedUnderQtrMile();
			//			//			var distanceToTransitQtrToHalfMile = household.ResidenceParcel.DistanceToTransitQtrToHalfMile();
			//var foodRetailServiceMedicalLogBuffer1 = household.ResidenceParcel.FoodRetailServiceMedicalLogBuffer1();

			var workTourLogsumDifference = 0D; // (full or part-time workers) full car ownership vs. no car ownership
			var schoolTourLogsumDifference = 0D; // (school) full car ownership vs. no car ownership
															 //															 //			const double workTourOtherLogsumDifference = 0D; // (other workers) full car ownership vs. no car ownership
															 //
															 // Stefan
			var netIncome = (household.Income / 1000.0) / 2.0; // in 1000s of DKK
			var userCost = 2.441 * 15.0;  //annual cost to use 1 car in 1000s of DKK
			bool isInCopenhagenMunicipality = household.MunicipalCode == 101;  

			bool municipality101 = household.MunicipalCode == 101;
			bool municipality147 = household.MunicipalCode == 147;
			bool municipality151 = household.MunicipalCode == 151;
			bool municipality153 = household.MunicipalCode == 153;
			bool municipality155 = household.MunicipalCode == 155;
			bool municipality157 = household.MunicipalCode == 157;
			bool municipality159 = household.MunicipalCode == 159;
			bool municipality161 = household.MunicipalCode == 161;
			bool municipality163 = household.MunicipalCode == 163;
			bool municipality165 = household.MunicipalCode == 165;
			bool municipality167 = household.MunicipalCode == 167;
			bool municipality169 = household.MunicipalCode == 169;
			bool municipality173 = household.MunicipalCode == 173;
			bool municipality175 = household.MunicipalCode == 175;
			bool municipality183 = household.MunicipalCode == 183;
			bool municipality185 = household.MunicipalCode == 185;
			bool municipality187 = household.MunicipalCode == 187;
			bool municipality190 = household.MunicipalCode == 190;
			bool municipality201 = household.MunicipalCode == 201;
			bool municipality210 = household.MunicipalCode == 210;
			bool municipality217 = household.MunicipalCode == 217;
			bool municipality219 = household.MunicipalCode == 219;
			bool municipality223 = household.MunicipalCode == 223;
			bool municipality230 = household.MunicipalCode == 230;
			bool municipality240 = household.MunicipalCode == 240;
			bool municipality250 = household.MunicipalCode == 250;
			bool municipality253 = household.MunicipalCode == 253;
			bool municipality259 = household.MunicipalCode == 259;
			bool municipality260 = household.MunicipalCode == 260;
			bool municipality265 = household.MunicipalCode == 265;
			bool municipality269 = household.MunicipalCode == 269;
			bool municipality270 = household.MunicipalCode == 270;
			bool municipality336 = household.MunicipalCode == 336;
			bool municipality350 = household.MunicipalCode == 350;

			int numberAdults = 0;
			int numberChildren = 0;
			int numberWorkers = 0;
			int sumAdultAges = 0;
			double averageAdultAge = 0.0;
			bool isMale = false;

			foreach (PersonWrapper person in household.Persons) {
				if (person.IsWorker && person.UsualWorkParcel != null && person.UsualWorkParcelId != household.ResidenceParcelId) {
					var destinationArrivalTime = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.WorkTourModeModel);
					var destinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.WorkTourModeModel);
					//JLB 201602
					//var nestedAlternative1 = Global.ChoiceModelSession.Get<WorkTourModeTimeModel>().RunNested(person, household.ResidenceParcel, person.UsualWorkParcel, destinationArrivalTime, destinationDepartureTime, household.HouseholdTotals.DrivingAgeMembers, 0.0);
					//var nestedAlternative2 = Global.ChoiceModelSession.Get<WorkTourModeTimeModel>().RunNested(person, household.ResidenceParcel, person.UsualWorkParcel, destinationArrivalTime, destinationDepartureTime, 0, 0.0);
					var nestedAlternative1 = Global.ChoiceModelSession.Get<TourModeTimeModel>().RunNested(person, household.ResidenceParcel, person.UsualWorkParcel, destinationArrivalTime, destinationDepartureTime, household.HouseholdTotals.DrivingAgeMembers, 0.0, Global.Settings.Purposes.Work);
					var nestedAlternative2 = Global.ChoiceModelSession.Get<TourModeTimeModel>().RunNested(person, household.ResidenceParcel, person.UsualWorkParcel, destinationArrivalTime, destinationDepartureTime, 0, 0.0, Global.Settings.Purposes.Work);

					workTourLogsumDifference += nestedAlternative1 == null ? 0 : nestedAlternative1.ComputeLogsum();
					workTourLogsumDifference -= nestedAlternative2 == null ? 0 : nestedAlternative2.ComputeLogsum();
				}

				if (person.IsDrivingAgeStudent && person.UsualSchoolParcel != null && person.UsualSchoolParcelId != household.ResidenceParcelId) {
					var destinationArrivalTime = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.SchoolTourModeModel);
					var destinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.SchoolTourModeModel);

					//TODO: change the following school logsum retrievals when estimating this model after schoolTourModeTimeModel is enhanced for COMPAS2 
					var nestedAlternative1 = Global.ChoiceModelSession.Get<TourModeTimeModel>().RunNested(person, household.ResidenceParcel, person.UsualSchoolParcel, destinationArrivalTime, destinationDepartureTime, household.HouseholdTotals.DrivingAgeMembers, 0.0, Global.Settings.Purposes.School);
					var nestedAlternative2 = Global.ChoiceModelSession.Get<TourModeTimeModel>().RunNested(person, household.ResidenceParcel, person.UsualSchoolParcel, destinationArrivalTime, destinationDepartureTime, 0, 0.0, Global.Settings.Purposes.School);

					schoolTourLogsumDifference += nestedAlternative1 == null ? 0 : nestedAlternative1.ComputeLogsum();
					schoolTourLogsumDifference -= nestedAlternative2 == null ? 0 : nestedAlternative2.ComputeLogsum();
				}
				if (person.Age >= 18) {
					numberAdults++;
					sumAdultAges = sumAdultAges + person.Age;
					isMale = person.IsMale;
					if (person.PersonType == Global.Settings.PersonTypes.FullTimeWorker
						//|| person.PersonType == Constants.PersonType.PART_TIME_WORKER
						) {
						numberWorkers++;
					}
				}
				else {
					numberChildren++;
				}

			}
			averageAdultAge = sumAdultAges / Math.Max(numberAdults, 1);


			// var votSegment = household.VotALSegment;
			//var taSegment = household.ResidenceParcel.TransitAccessSegment();

			//var aggregateLogsumDifference = // full car ownership vs. no car ownership
			//	Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.OneOrMoreCarsPerAdult][votSegment][taSegment] -
			//	Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.NoCars][votSegment][taSegment];

			//var distanceToStop
			//	 = household.ResidenceParcel.GetDistanceToTransit() > 0
			//			 ? Math.Min(household.ResidenceParcel.GetDistanceToTransit(), 2 * Global.Settings.DistanceUnitsPerMile)  // JLBscale
			//			 : 2 * Global.Settings.DistanceUnitsPerMile;

			//var ruralFlag = household.ResidenceParcel.RuralFlag();

			var zeroVehAVEffect = (Global.Configuration.AV_IncludeAutoTypeChoice && household.OwnsAutomatedVehicles > 0) ? Global.Configuration.AV_Own0VehiclesCoefficientForAVHouseholds : 0;
			var oneVehAVEffect = (Global.Configuration.AV_IncludeAutoTypeChoice && household.OwnsAutomatedVehicles > 0) ? Global.Configuration.AV_Own1VehicleCoefficientForAVHouseholds : 0;

			var zeroVehSEEffect = (Global.Configuration.PaidRideShareModeIsAvailable && Global.Configuration.AV_PaidRideShareModeUsesAVs) ? Global.Configuration.AV_SharingEconomy_DensityCoefficientForOwning0Vehicles * Math.Min(household.ResidenceBuffer2Density, 6000) : 0;
			var oneVehSEEffect = (Global.Configuration.PaidRideShareModeIsAvailable && Global.Configuration.AV_PaidRideShareModeUsesAVs) ? Global.Configuration.AV_SharingEconomy_ConstantForOwning1Vehicle : 0;
			var twoVehSEEffect = (Global.Configuration.PaidRideShareModeIsAvailable && Global.Configuration.AV_PaidRideShareModeUsesAVs) ? Global.Configuration.AV_SharingEconomy_ConstantForOwning2Vehicles : 0;
			//var threeVehSEEffect = (Global.Configuration.PaidRideShareModeIsAvailable && Global.Configuration.AV_PaidRideShareModeUsesAVs) ? Global.Configuration.AV_SharingEconomy_ConstantForOwning3Vehicles : 0;
			//var fourVehSEEffect = (Global.Configuration.PaidRideShareModeIsAvailable && Global.Configuration.AV_PaidRideShareModeUsesAVs) ? Global.Configuration.AV_SharingEconomy_ConstantForOwning4Vehicles : 0;

			// 0 AUTOS

			var alternative = choiceProbabilityCalculator.GetAlternative(0, true, choice == 0);
			alternative.Choice = 0;
			alternative.AddUtilityTerm(14, Math.Log(Math.Max(netIncome, 1)));
			alternative.AddUtilityTerm(15, workTourLogsumDifference);  // instead of all Stefan's work-related and logsum variables
			alternative.AddUtilityTerm(90, 1); //calibration constant
			alternative.AddUtilityTerm(100, zeroVehAVEffect);
			alternative.AddUtilityTerm(100, zeroVehSEEffect);
			alternative.AddUtilityTerm(101, municipality101.ToFlag());
			alternative.AddUtilityTerm(102, municipality147.ToFlag());
			alternative.AddUtilityTerm(103, municipality151.ToFlag());
			alternative.AddUtilityTerm(104, municipality153.ToFlag());
			alternative.AddUtilityTerm(105, municipality155.ToFlag());
			alternative.AddUtilityTerm(106, municipality157.ToFlag());
			alternative.AddUtilityTerm(107, municipality159.ToFlag());
			alternative.AddUtilityTerm(108, municipality161.ToFlag());
			alternative.AddUtilityTerm(109, municipality163.ToFlag());
			alternative.AddUtilityTerm(110, municipality165.ToFlag());
			alternative.AddUtilityTerm(111, municipality167.ToFlag());
			alternative.AddUtilityTerm(112, municipality169.ToFlag());
			alternative.AddUtilityTerm(113, municipality173.ToFlag());
			alternative.AddUtilityTerm(114, municipality175.ToFlag());
			alternative.AddUtilityTerm(115, municipality183.ToFlag());
			alternative.AddUtilityTerm(116, municipality185.ToFlag());
			alternative.AddUtilityTerm(117, municipality187.ToFlag());
			alternative.AddUtilityTerm(118, municipality190.ToFlag());
			alternative.AddUtilityTerm(119, municipality201.ToFlag());
			alternative.AddUtilityTerm(120, municipality210.ToFlag());
			alternative.AddUtilityTerm(121, municipality217.ToFlag());
			alternative.AddUtilityTerm(122, municipality219.ToFlag());
			alternative.AddUtilityTerm(123, municipality223.ToFlag());
			alternative.AddUtilityTerm(124, municipality230.ToFlag());
			alternative.AddUtilityTerm(125, municipality240.ToFlag());
			alternative.AddUtilityTerm(126, municipality250.ToFlag());
			alternative.AddUtilityTerm(127, municipality253.ToFlag());
			alternative.AddUtilityTerm(128, municipality259.ToFlag());
			alternative.AddUtilityTerm(129, municipality260.ToFlag());
			alternative.AddUtilityTerm(130, municipality265.ToFlag());
			alternative.AddUtilityTerm(131, municipality269.ToFlag());
			alternative.AddUtilityTerm(132, municipality270.ToFlag());
			alternative.AddUtilityTerm(133, municipality336.ToFlag());
			alternative.AddUtilityTerm(134, municipality350.ToFlag());


			// 1 AUTO

			var beta010 = -6.59;
			var beta011 = 4.25;
			var beta012 = 5.53;
			var beta013 = 6.54;
			var beta014 = 1.17;
			var beta015 = 0.54;
			var beta016 = 0.81;
			var beta017 = 1.20;
			var beta018 = -0.54;
			var beta019 = 0.0;
			var beta020 = 0.45;
			var beta021 = 0.0;
			var beta022 = -0.04;
			var beta023 = 0.57;
			var beta024 = 0.18;
			var beta025 = -0.82;

			var stefanOneCarUtility =
				beta010 * 1.0 +
				beta011 * household.Has1Driver.ToFlag() +
				beta012 * household.Has2Drivers.ToFlag() +
				beta013 * (household.Has3Drivers || household.Has4OrMoreDrivers).ToFlag() +
				beta014 * Math.Log(Math.Max(netIncome - userCost, 1)) +
				beta015 * (numberChildren == 1).ToFlag() +
				beta016 * (numberChildren == 2).ToFlag() +
				beta017 * (numberChildren > 2).ToFlag() +
				beta018 * (numberAdults == 1 && !isMale).ToFlag() +
				beta019 * (numberAdults == 1 && isMale).ToFlag() +
				beta020 * averageAdultAge / 10.0 +
				beta021 * Math.Pow(averageAdultAge / 10.0, 2.0) +
				beta022 * 0 + //household.ResidenceParcel.PSearchTime16_17 +  // Add this when new parcel variables with seach time are available
				beta023 * household.ResidenceParcel.DistanceToLocalBus +
				beta024 * household.ResidenceParcel.DistanceToExpressBus +
				beta025 * isInCopenhagenMunicipality.ToFlag() +
				0;

			alternative = choiceProbabilityCalculator.GetAlternative(1, true, choice == 1);
			alternative.Choice = 1;
			//Stefan
			//alternative.AddUtilityTerm(10, 1.0);
			//alternative.AddUtilityTerm(11, household.Has1Driver.ToFlag());
			//alternative.AddUtilityTerm(12, household.Has2Drivers.ToFlag());
			//alternative.AddUtilityTerm(13, (household.Has3Drivers || household.Has4OrMoreDrivers).ToFlag());
			//alternative.AddUtilityTerm(14, Math.Log(Math.Max(netIncome - userCost, 1)));
			//alternative.AddUtilityTerm(15, (numberChildren == 1).ToFlag());
			//alternative.AddUtilityTerm(16, (numberChildren == 2).ToFlag());
			//alternative.AddUtilityTerm(17, (numberChildren > 2).ToFlag());
			//alternative.AddUtilityTerm(18, (numberAdults == 1 && !isMale).ToFlag());
			//alternative.AddUtilityTerm(19, (numberAdults == 1 && isMale).ToFlag());
			//alternative.AddUtilityTerm(20, averageAdultAge / 10.0);
			//alternative.AddUtilityTerm(21, Math.Pow(averageAdultAge / 10.0, 2.0));
			////alternative.AddUtilityTerm(22, household.ResidenceParcel.PSearchTime16_17);  // Add this when new parcel variables with seach time are available
			//alternative.AddUtilityTerm(23, household.ResidenceParcel.DistanceToLocalBus);
			//alternative.AddUtilityTerm(24, household.ResidenceParcel.DistanceToExpressBus);
			//alternative.AddUtilityTerm(25, isInCopenhagenMunicipality.ToFlag());
			alternative.AddUtilityTerm(26, stefanOneCarUtility);  //this composite replaces above separate terms 10-25

			alternative.AddUtilityTerm(27, workTourLogsumDifference * household.HasMoreDriversThan1.ToFlag());  // instead of all Stefan's work-related and logsum variables
			alternative.AddUtilityTerm(91, 1); //calibration constant
			alternative.AddUtilityTerm(100, oneVehAVEffect);
			alternative.AddUtilityTerm(100, oneVehSEEffect);

			//alternative.AddUtilityTerm(24, household.HouseholdTotals.RetiredAdultsPerDrivingAgeMembers);
			//alternative.AddUtilityTerm(25, household.HouseholdTotals.UniversityStudentsPerDrivingAgeMembers);
			//alternative.AddUtilityTerm(26, household.HouseholdTotals.DrivingAgeStudentsPerDrivingAgeMembers);
			//alternative.AddUtilityTerm(27, household.HouseholdTotals.HomeBasedPersonsPerDrivingAgeMembers);

			// 2+ AUTOS

			var beta040 = -9.540;
			var beta041 = 2.79;
			var beta042 = 6.09;
			var beta043 = 7.77;
			var beta044 = 0;
			var beta045 = 0.35;
			var beta046 = 0.81;
			var beta047 = 1.33;
			var beta048 = -1.13;
			var beta049 = 0.60;
			var beta050 = 0.92;
			var beta051 = -0.05;
			var beta052 = -0.09;
			var beta053 = 0.94;
			var beta054 = 0.31;
			var beta055 = -1.54;

			var stefanTwoCarUtility =
				beta040 * 1.0 +
				beta041 * household.Has1Driver.ToFlag() +
				beta042 * household.Has2Drivers.ToFlag() +
				beta043 * (household.Has3Drivers || household.Has4OrMoreDrivers).ToFlag() +
				beta014 * Math.Log(Math.Max(netIncome - userCost * 2.0, 1)) +
				beta045 * (numberChildren == 1).ToFlag() +
				beta046 * (numberChildren == 2).ToFlag() +
				beta047 * (numberChildren > 2).ToFlag() +
				beta048 * (numberAdults == 1 && !isMale).ToFlag() +
				beta049 * (numberAdults == 1 && isMale).ToFlag() +
				beta050 * averageAdultAge / 10.0 +
				beta051 * Math.Pow(averageAdultAge / 10.0, 2.0) +
				beta052 * 0 + //household.ResidenceParcel.PSearchTime16_17 +  // Add this when new parcel variables with seach time are available
				beta053 * household.ResidenceParcel.DistanceToLocalBus +
				beta054 * household.ResidenceParcel.DistanceToExpressBus +
				beta055 * isInCopenhagenMunicipality.ToFlag() +
				0;

			alternative = choiceProbabilityCalculator.GetAlternative(2, true, choice == 2);
			alternative.Choice = 2;
			//Stefan
			//alternative.AddUtilityTerm(40, 1.0);
			//alternative.AddUtilityTerm(41, household.Has1Driver.ToFlag());
			//alternative.AddUtilityTerm(42, household.Has2Drivers.ToFlag());
			//alternative.AddUtilityTerm(43, (household.Has3Drivers || household.Has4OrMoreDrivers).ToFlag());
			//alternative.AddUtilityTerm(14, Math.Log(Math.Max(netIncome - userCost * 2.0, 1)));
			//alternative.AddUtilityTerm(45, (numberChildren == 1).ToFlag());
			//alternative.AddUtilityTerm(46, (numberChildren == 2).ToFlag());
			//alternative.AddUtilityTerm(47, (numberChildren > 2).ToFlag());
			//alternative.AddUtilityTerm(48, (numberAdults == 1 && !isMale).ToFlag());
			//alternative.AddUtilityTerm(49, (numberAdults == 1 && isMale).ToFlag());
			//alternative.AddUtilityTerm(50, averageAdultAge / 10.0);
			//alternative.AddUtilityTerm(51, Math.Pow(averageAdultAge / 10.0, 2.0));
			////alternative.AddUtilityTerm(52, household.ResidenceParcel.PSearchTime16_17);  // Add this when new parcel variables with seach time are available
			//alternative.AddUtilityTerm(53, household.ResidenceParcel.DistanceToLocalBus);
			//alternative.AddUtilityTerm(54, household.ResidenceParcel.DistanceToExpressBus);
			//alternative.AddUtilityTerm(55, isInCopenhagenMunicipality.ToFlag());
			alternative.AddUtilityTerm(56, stefanTwoCarUtility);  //this composite replaces above separate terms 40-55

			//alternative.AddUtilityTerm(57, workTourLogsumDifference);
			alternative.AddUtilityTerm(92, 1); //new calibration constant - must be constrained to 0 in estimation
			alternative.AddUtilityTerm(100, twoVehSEEffect);
			alternative.AddUtilityTerm(201, municipality101.ToFlag());
			alternative.AddUtilityTerm(202, municipality147.ToFlag());
			alternative.AddUtilityTerm(203, municipality151.ToFlag());
			alternative.AddUtilityTerm(204, municipality153.ToFlag());
			alternative.AddUtilityTerm(205, municipality155.ToFlag());
			alternative.AddUtilityTerm(206, municipality157.ToFlag());
			alternative.AddUtilityTerm(207, municipality159.ToFlag());
			alternative.AddUtilityTerm(208, municipality161.ToFlag());
			alternative.AddUtilityTerm(209, municipality163.ToFlag());
			alternative.AddUtilityTerm(210, municipality165.ToFlag());
			alternative.AddUtilityTerm(211, municipality167.ToFlag());
			alternative.AddUtilityTerm(212, municipality169.ToFlag());
			alternative.AddUtilityTerm(213, municipality173.ToFlag());
			alternative.AddUtilityTerm(214, municipality175.ToFlag());
			alternative.AddUtilityTerm(215, municipality183.ToFlag());
			alternative.AddUtilityTerm(216, municipality185.ToFlag());
			alternative.AddUtilityTerm(217, municipality187.ToFlag());
			alternative.AddUtilityTerm(218, municipality190.ToFlag());
			alternative.AddUtilityTerm(219, municipality201.ToFlag());
			alternative.AddUtilityTerm(220, municipality210.ToFlag());
			alternative.AddUtilityTerm(221, municipality217.ToFlag());
			alternative.AddUtilityTerm(222, municipality219.ToFlag());
			alternative.AddUtilityTerm(223, municipality223.ToFlag());
			alternative.AddUtilityTerm(224, municipality230.ToFlag());
			alternative.AddUtilityTerm(225, municipality240.ToFlag());
			alternative.AddUtilityTerm(226, municipality250.ToFlag());
			alternative.AddUtilityTerm(227, municipality253.ToFlag());
			alternative.AddUtilityTerm(228, municipality259.ToFlag());
			alternative.AddUtilityTerm(229, municipality260.ToFlag());
			alternative.AddUtilityTerm(230, municipality265.ToFlag());
			alternative.AddUtilityTerm(231, municipality269.ToFlag());
			alternative.AddUtilityTerm(232, municipality270.ToFlag());
			alternative.AddUtilityTerm(233, municipality336.ToFlag());
			alternative.AddUtilityTerm(234, municipality350.ToFlag());

			//alternative.AddUtilityTerm(44, household.HouseholdTotals.RetiredAdultsPerDrivingAgeMembers);
			//alternative.AddUtilityTerm(45, household.HouseholdTotals.UniversityStudentsPerDrivingAgeMembers);
			//alternative.AddUtilityTerm(46, household.HouseholdTotals.DrivingAgeStudentsPerDrivingAgeMembers);
			//alternative.AddUtilityTerm(47, household.HouseholdTotals.HomeBasedPersonsPerDrivingAgeMembers);

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

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


            TimeWindow timeWindow = new TimeWindow();

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

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

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


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

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

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

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

            ChoiceModelUtility.DrawRandomTourTimePeriodsActum(tour, tourCategory);

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

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


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

            // get destination sample and perform code that used to be in SetUtilities below
            Dictionary <DestinationSampler.TourSampleItem, int> sampleItems = destinationSampler.SampleAndReturnTourDestinations(tourDestinationUtilities);

            int index = 0;

            foreach (KeyValuePair <DestinationSampler.TourSampleItem, int> sampleItem in sampleItems)
            {
                bool           available         = sampleItem.Key.Available;
                bool           isChosen          = sampleItem.Key.IsChosen;
                double         adjustmentFactor  = sampleItem.Key.AdjustmentFactor;
                IParcelWrapper destinationParcel = ChoiceModelFactory.Parcels[sampleItem.Key.ParcelId];

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

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


                if (!available)
                {
                    continue;
                }

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

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

                    continue;
                }

                alternative.Choice = destinationParcel;

                double tourLogsum;

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

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

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

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


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

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

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

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

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

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


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


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

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

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

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

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

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

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

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

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

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

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

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

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

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


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


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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                    // Size terms
                    alternative.AddUtilityTerm(190, destinationParcel.EmploymentEducation);
                    alternative.AddUtilityTerm(191, destinationParcel.EmploymentGovernment);
                    alternative.AddUtilityTerm(192, destinationParcel.EmploymentIndustrial);
                    alternative.AddUtilityTerm(193, destinationParcel.EmploymentOffice);
                    alternative.AddUtilityTerm(194, destinationParcel.EmploymentRetail);
                    // GV 195 is fixed to zero
                    alternative.AddUtilityTerm(195, destinationParcel.EmploymentService);
                    alternative.AddUtilityTerm(196, destinationParcel.EmploymentAgricultureConstruction);
                    alternative.AddUtilityTerm(197, destinationParcel.EmploymentTotal);
                    alternative.AddUtilityTerm(198, destinationParcel.Households);
                }
            }
        }
Ejemplo n.º 20
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, TripWrapper trip, HouseholdDayWrapper householdDay, int choice = Constants.DEFAULT_VALUE)
        {
            HouseholdWrapper household = (HouseholdWrapper)trip.Household;
            PersonWrapper    person    = (PersonWrapper)trip.Person;
            PersonDayWrapper personDay = (PersonDayWrapper)trip.PersonDay;
            TourWrapper      tour      = (TourWrapper)trip.Tour;

            TourWrapper.HalfTour halfTour = (TourWrapper.HalfTour)trip.HalfTour;
            List <Framework.DomainModels.Wrappers.IPersonDayWrapper> personDays = householdDay.PersonDays;

            int isJointTour      = tour.JointTourSequence > 0 ? 1 : 0;
            int isIndividualTour = isJointTour == 1 ? 0 : 1;

            Framework.DomainModels.Wrappers.IParcelWrapper destinationParcel = tour.DestinationParcel;
            int jointHalfOfFullJointHalfTour = ((trip.Direction == Global.Settings.TourDirections.OriginToDestination && tour.FullHalfTour1Sequence > 0) ||
                                                (trip.Direction == Global.Settings.TourDirections.DestinationToOrigin && tour.FullHalfTour2Sequence > 0)).ToFlag();
            int 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();
            int individualHalfTour = (isIndividualTour == 1 || individualHalfOfFullJointHalfTour == 1) ? 1 : 0;
            int jointHalfTour      = 1 - individualHalfTour;

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

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

            int carOwnership = person.GetCarOwnershipSegment();

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

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

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

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

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

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

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

            // remaining inputs, including joint tour variables

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

            int 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;
            int 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;
            //}


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


            int from9AMto11AMFlag = (time >= Global.Settings.Times.NineAM && time < Global.Settings.Times.ElevenAM).ToFlag();
            int from11AMto1PMFlag = (time >= Global.Settings.Times.ElevenAM && time < Global.Settings.Times.OnePM).ToFlag();
            int from1PMto3PMFlag  = (time >= Global.Settings.Times.OnePM && time < Global.Settings.Times.ThreePM).ToFlag();
            int from3PMto5PMFlag  = (time >= Global.Settings.Times.ThreePM && time < Global.Settings.Times.FivePM).ToFlag();
            int from7PMto9PMFlag  = (time >= Global.Settings.Times.SevenPM && time < Global.Settings.Times.NinePM).ToFlag();
            int from9PMto11PMFlag = (time >= Global.Settings.Times.NinePM && time < Global.Settings.Times.ElevenPM).ToFlag();
            int 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)
                {
                    TourWrapper 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)
                {
                    TourWrapper 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)
                {
                    TourWrapper 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
            int    availableWindow = timeWindow.AvailableWindow(destinationDepartureTime, Global.Settings.TimeDirections.Both);
            double 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();

            double adis    = 0.0;
            double logDist = 0.0;
            int    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

            ChoiceProbabilityCalculator.Alternative 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);

            //GV: 21. june 2016, not sign.
            //alternative.AddUtilityTerm(6, transitTourFlag);

            alternative.AddUtilityTerm(7, bikeTourFlag);
            alternative.AddUtilityTerm(8, walkTourFlag);
            alternative.AddUtilityTerm(9, jointHalfTour);
            alternative.AddUtilityTerm(10, halfTourFromOriginFlag);

            //GV: june 2016 - not sign
            //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);

            //GV: 21. june 2016, try to estimate again
            alternative.AddUtilityTerm(19, primaryFamilyTimeFlag);

            alternative.AddUtilityTerm(20, person.IsChildUnder5.ToFlag());

            //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);

            //GV: june 2016 - not sign
            //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());

            //GV: 21. june 2016, not sign.
            //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);
        }
Ejemplo n.º 21
0
        public void TestFullHalfTourExport()
        {
            Global.Configuration = new Configuration();
            Global.Configuration.HouseholdSamplingRateOneInX = 256;


            const int id              = 1;
            const int householdDayId  = 2;
            const int householdId     = 3;
            const int day             = 4;
            const int sequence        = 5;
            const int participants    = 7;
            const int personSequence1 = 8;
            const int tourSequence1   = 9;
            const int personSequence2 = 10;
            const int tourSequence2   = 11;
            const int personSequence3 = 12;
            const int tourSequence3   = 13;
            const int personSequence4 = 14;
            const int tourSequence4   = 15;
            const int personSequence5 = 16;
            const int tourSequence5   = 17;
            const int personSequence6 = 18;
            const int tourSequence6   = 19;
            const int personSequence7 = 20;
            const int tourSequence7   = 21;
            const int personSequence8 = 22;
            const int tourSequence8   = 23;
            const int mainPurpose     = 24;

            JointTour tour = new JointTour()
            {
                Day             = day,
                MainPurpose     = mainPurpose,
                HouseholdDayId  = householdDayId,
                HouseholdId     = householdId,
                Id              = id,
                Participants    = participants,
                PersonSequence1 = personSequence1,
                TourSequence1   = tourSequence1,
                PersonSequence2 = personSequence2,
                TourSequence2   = tourSequence2,
                PersonSequence3 = personSequence3,
                TourSequence3   = tourSequence3,
                PersonSequence4 = personSequence4,
                TourSequence4   = tourSequence4,
                PersonSequence5 = personSequence5,
                TourSequence5   = tourSequence5,
                PersonSequence6 = personSequence6,
                TourSequence6   = tourSequence6,
                PersonSequence7 = personSequence7,
                TourSequence7   = tourSequence7,
                PersonSequence8 = personSequence8,
                TourSequence8   = tourSequence8,
                Sequence        = sequence
            };

            List <IPerson> persons = new List <IPerson> {
                new Person()
            };

            HouseholdWrapper householdWrapper = TestHelper.GetHouseholdWrapper(persons);

            householdWrapper.Init();

            HouseholdDayWrapper householdDayWrapper = TestHelper.GetHouseholdDayWrapper(householdWrapper);
            var exporter = new TestJointTourExporter();

            JointTourWrapper.SetPersister(new PersisterWithHDF5 <JointTour>(exporter));
            JointTourWrapper wrapper = new JointTourWrapper(tour, householdDayWrapper);

            Assert.Equal(false, exporter.HasWritten);
            Assert.Equal(0, ChoiceModelFactory.JointTourFileRecordsWritten);
            wrapper.Export();
            Assert.Equal(true, exporter.HasWritten);
            Assert.Equal(1, ChoiceModelFactory.JointTourFileRecordsWritten);
        }
Ejemplo n.º 22
0
        public void TestHouseholdWrapperHouseholdType()
        {
            Global.Configuration = new Configuration();
            Global.Configuration.HouseholdSamplingRateOneInX = 1;
            List <IPerson> persons = new List <IPerson>
            {
                new Person {
                    Age = 37, PersonType = Constants.PersonType.UNIVERSITY_STUDENT, WorkerType = 1, StudentType = 1
                }
            };
            HouseholdWrapper wrapper = TestHelper.GetHouseholdWrapper(persons, size: 1);

            wrapper.Init();
            Assert.Equal(Constants.HouseholdType.INDIVIDUAL_WORKER_STUDENT, wrapper.HouseholdType);

            persons = new List <IPerson>
            {
                new Person {
                    Age = 37, PersonType = Constants.PersonType.NON_WORKING_ADULT, WorkerType = 0, StudentType = 0
                }
            };
            wrapper = TestHelper.GetHouseholdWrapper(persons, size: 1);
            wrapper.Init();
            Assert.Equal(Constants.HouseholdType.INDIVIDUAL_NONWORKER_NONSTUDENT, wrapper.HouseholdType);

            persons = new List <IPerson>
            {
                new Person {
                    Age = 37, PersonType = Constants.PersonType.NON_WORKING_ADULT, WorkerType = 0, StudentType = 0
                },
                new Person {
                    Age = 6, PersonType = Constants.PersonType.CHILD_AGE_5_THROUGH_15, WorkerType = 0, StudentType = 1
                },
            };
            wrapper = TestHelper.GetHouseholdWrapper(persons, size: 2);
            wrapper.Init();
            Assert.Equal(Constants.HouseholdType.ONE_ADULT_WITH_CHILDREN, wrapper.HouseholdType);

            persons = new List <IPerson>
            {
                new Person {
                    Age = 37, PersonType = Constants.PersonType.FULL_TIME_WORKER, WorkerType = 1, StudentType = 0
                },
                new Person {
                    Age = 37, PersonType = Constants.PersonType.PART_TIME_WORKER, WorkerType = 1, StudentType = 0
                },
                new Person {
                    Age = 6, PersonType = Constants.PersonType.CHILD_AGE_5_THROUGH_15, WorkerType = 0, StudentType = 1
                },
            };
            wrapper = TestHelper.GetHouseholdWrapper(persons, size: 3);
            wrapper.Init();
            Assert.Equal(Constants.HouseholdType.TWO_PLUS_WORKER_STUDENT_ADULTS_WITH_CHILDREN, wrapper.HouseholdType);

            persons = new List <IPerson>
            {
                new Person {
                    Age = 37, PersonType = Constants.PersonType.FULL_TIME_WORKER, WorkerType = 1, StudentType = 0
                },
                new Person {
                    Age = 37, PersonType = Constants.PersonType.NON_WORKING_ADULT, WorkerType = 0, StudentType = 0
                },
                new Person {
                    Age = 6, PersonType = Constants.PersonType.CHILD_AGE_5_THROUGH_15, WorkerType = 0, StudentType = 1
                },
            };
            wrapper = TestHelper.GetHouseholdWrapper(persons, size: 3);
            wrapper.Init();
            Assert.Equal(Constants.HouseholdType.TWO_PLUS_ADULTS_ONE_PLUS_WORKERS_STUDENTS_WITH_CHILDREN, wrapper.HouseholdType);

            persons = new List <IPerson>
            {
                new Person {
                    Age = 37, PersonType = Constants.PersonType.FULL_TIME_WORKER, WorkerType = 1, StudentType = 0
                },
                new Person {
                    Age = 37, PersonType = Constants.PersonType.FULL_TIME_WORKER, WorkerType = 1, StudentType = 0
                },
            };
            wrapper = TestHelper.GetHouseholdWrapper(persons, size: 2);
            wrapper.Init();
            Assert.Equal(Constants.HouseholdType.TWO_PLUS_WORKER_STUDENT_ADULTS_WITHOUT_CHILDREN, wrapper.HouseholdType);

            persons = new List <IPerson>
            {
                new Person {
                    Age = 37, PersonType = Constants.PersonType.FULL_TIME_WORKER, WorkerType = 1, StudentType = 0
                },
                new Person {
                    Age = 37, PersonType = Constants.PersonType.NON_WORKING_ADULT, WorkerType = 0, StudentType = 0
                },
            };
            wrapper = TestHelper.GetHouseholdWrapper(persons, size: 2);
            wrapper.Init();
            Assert.Equal(Constants.HouseholdType.ONE_PLUS_WORKER_STUDENT_ADULTS_AND_ONE_PLUS_NONWORKER_NONSTUDENT_ADULTS_WITHOUT_CHILDREN, wrapper.HouseholdType);

            persons = new List <IPerson>
            {
                new Person {
                    Age = 37, PersonType = Constants.PersonType.NON_WORKING_ADULT, WorkerType = 0, StudentType = 0
                },
                new Person {
                    Age = 37, PersonType = Constants.PersonType.NON_WORKING_ADULT, WorkerType = 0, StudentType = 0
                },
            };
            wrapper = TestHelper.GetHouseholdWrapper(persons, size: 2);
            wrapper.Init();
            Assert.Equal(Constants.HouseholdType.TWO_PLUS_NONWORKER_NONSTUDENT_ADULTS_WITHOUT_CHILDREN, wrapper.HouseholdType);
        }
Ejemplo n.º 23
0
        public void TestPersonWrapperCarOwnershipSegment()
        {
            Global.Configuration = new Configuration {
                HouseholdSamplingRateOneInX = 1
            };

            List <IPerson> persons = new List <IPerson>()
            {
                new Person()
                {
                    Age = 15
                }
            };
            HouseholdWrapper household = TestHelper.GetHouseholdWrapper(persons);

            household.Init();
            PersonWrapper wrapper = new PersonWrapper(persons[0], household)
            {
            };

            Assert.Equal(Constants.CarOwnership.CHILD, wrapper.CarOwnershipSegment);


            persons = new List <IPerson>()
            {
                new Person()
                {
                    Age = 25
                }
            };
            household = TestHelper.GetHouseholdWrapper(persons, vehiclesAvailable: 0);
            household.Init();
            wrapper = new PersonWrapper(persons[0], household)
            {
            };

            Assert.Equal(Constants.CarOwnership.NO_CARS, wrapper.CarOwnershipSegment);

            persons = new List <IPerson>()
            {
                new Person()
                {
                    Age = 25, PersonType = Constants.PersonType.FULL_TIME_WORKER
                },
                new Person()
                {
                    Age = 25, PersonType = Constants.PersonType.FULL_TIME_WORKER
                }
            };
            household = TestHelper.GetHouseholdWrapper(persons, vehiclesAvailable: 1);
            household.Init();
            wrapper = new PersonWrapper(persons[0], household)
            {
            };

            Assert.Equal(Constants.CarOwnership.LT_ONE_CAR_PER_ADULT, wrapper.CarOwnershipSegment);

            persons = new List <IPerson>()
            {
                new Person()
                {
                    Age = 25, PersonType = Constants.PersonType.FULL_TIME_WORKER
                },
                new Person()
                {
                    Age = 25, PersonType = Constants.PersonType.FULL_TIME_WORKER
                }
            };
            household = TestHelper.GetHouseholdWrapper(persons, vehiclesAvailable: 2);
            household.Init();
            wrapper = new PersonWrapper(persons[0], household)
            {
            };

            Assert.Equal(Constants.CarOwnership.ONE_OR_MORE_CARS_PER_ADULT, wrapper.CarOwnershipSegment);
        }
Ejemplo n.º 24
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, HouseholdWrapper household, int choice = Constants.DEFAULT_VALUE)
        {
            //			var distanceToTransitCappedUnderQtrMile = household.ResidenceParcel.DistanceToTransitCappedUnderQtrMile();
            //			var distanceToTransitQtrToHalfMile = household.ResidenceParcel.DistanceToTransitQtrToHalfMile();
            var foodRetailServiceMedicalLogBuffer1 = household.ResidenceParcel.FoodRetailServiceMedicalLogBuffer1();

            var workTourLogsumDifference   = 0D;           // (full or part-time workers) full car ownership vs. no car ownership
            var schoolTourLogsumDifference = 0D;           // (school) full car ownership vs. no car ownership
            //			const double workTourOtherLogsumDifference = 0D; // (other workers) full car ownership vs. no car ownership

            // Stefan
            var  netIncome = (household.Income / 1000.0) / 2.0; // in 1000s of DKK
            var  userCost  = 2.441 * 15.0;                      //annual cost to use 1 car in 1000s of DKK
            bool isInCopenhagenMunicipality = true;             //household.ResidenceParcel.Municipality == 101;  Need to change this after Municipality property is added to LD parcel file

            int    numberAdults    = 0;
            int    numberChildren  = 0;
            int    numberWorkers   = 0;
            int    sumAdultAges    = 0;
            double averageAdultAge = 0.0;
            bool   isMale          = false;

            foreach (PersonWrapper person in household.Persons)
            {
                if (person.IsWorker && person.UsualWorkParcel != null && person.UsualWorkParcelId != household.ResidenceParcelId)
                {
                    var destinationArrivalTime   = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.WorkTourModeModel);
                    var destinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.WorkTourModeModel);

                    var nestedAlternative1 = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().RunNested(person, household.ResidenceParcel, person.UsualWorkParcel, destinationArrivalTime, destinationDepartureTime, household.HouseholdTotals.DrivingAgeMembers, 0.0);
                    var nestedAlternative2 = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().RunNested(person, household.ResidenceParcel, person.UsualWorkParcel, destinationArrivalTime, destinationDepartureTime, 0, 0.0);

                    workTourLogsumDifference += nestedAlternative1 == null ? 0 : nestedAlternative1.ComputeLogsum();
                    workTourLogsumDifference -= nestedAlternative2 == null ? 0 : nestedAlternative2.ComputeLogsum();
                }

                if (person.IsDrivingAgeStudent && person.UsualSchoolParcel != null && person.UsualSchoolParcelId != household.ResidenceParcelId)
                {
                    var destinationArrivalTime   = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.SchoolTourModeModel);
                    var destinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.SchoolTourModeModel);

                    var nestedAlternative1 = Global.ChoiceModelSession.Get <SchoolTourModeTimeModel>().RunNested(person, household.ResidenceParcel, person.UsualSchoolParcel, destinationArrivalTime, destinationDepartureTime, household.HouseholdTotals.DrivingAgeMembers, 0.0);
                    var nestedAlternative2 = Global.ChoiceModelSession.Get <SchoolTourModeTimeModel>().RunNested(person, household.ResidenceParcel, person.UsualSchoolParcel, destinationArrivalTime, destinationDepartureTime, 0, 0.0);

                    schoolTourLogsumDifference += nestedAlternative1 == null ? 0 : nestedAlternative1.ComputeLogsum();
                    schoolTourLogsumDifference -= nestedAlternative2 == null ? 0 : nestedAlternative2.ComputeLogsum();
                }
                if (person.Age >= 18)
                {
                    numberAdults++;
                    sumAdultAges = sumAdultAges + person.Age;
                    isMale       = person.IsMale;
                    if (person.PersonType == Global.Settings.PersonTypes.FullTimeWorker
                        //|| person.PersonType == Constants.PersonType.PART_TIME_WORKER
                        )
                    {
                        numberWorkers++;
                    }
                }
                else
                {
                    numberChildren++;
                }
            }
            averageAdultAge = sumAdultAges / Math.Max(numberAdults, 1);


            // var votSegment = household.VotALSegment;
            //var taSegment = household.ResidenceParcel.TransitAccessSegment();

            //var aggregateLogsumDifference = // full car ownership vs. no car ownership
            //	Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.OneOrMoreCarsPerAdult][votSegment][taSegment] -
            //	Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.NoCars][votSegment][taSegment];

            // 0 AUTOS

            var alternative = choiceProbabilityCalculator.GetAlternative(0, true, choice == 0);

            alternative.Choice = 0;
            alternative.AddUtilityTerm(14, Math.Log(Math.Max(netIncome, 1)));


            // 1 AUTO

            var beta010 = -6.59;
            var beta011 = 4.25;
            var beta012 = 5.53;
            var beta013 = 6.54;
            var beta014 = 1.17;
            var beta015 = 0.54;
            var beta016 = 0.81;
            var beta017 = 1.20;
            var beta018 = -0.54;
            var beta019 = 0.0;
            var beta020 = 0.45;
            var beta021 = 0.0;
            var beta022 = -0.04;
            var beta023 = 0.57;
            var beta024 = 0.18;
            var beta025 = -0.82;

            var stefanOneCarUtility =
                beta010 * 1.0 +
                beta011 * household.Has1Driver.ToFlag() +
                beta012 * household.Has2Drivers.ToFlag() +
                beta013 * (household.Has3Drivers || household.Has4OrMoreDrivers).ToFlag() +
                beta014 * Math.Log(Math.Max(netIncome - userCost, 1)) +
                beta015 * (numberChildren == 1).ToFlag() +
                beta016 * (numberChildren == 2).ToFlag() +
                beta017 * (numberChildren > 2).ToFlag() +
                beta018 * (numberAdults == 1 && !isMale).ToFlag() +
                beta019 * (numberAdults == 1 && isMale).ToFlag() +
                beta020 * averageAdultAge / 10.0 +
                beta021 * Math.Pow(averageAdultAge / 10.0, 2.0) +
                beta022 * 0 +                 //household.ResidenceParcel.PSearchTime16_17 +  // Add this when new parcel variables with seach time are available
                beta023 * household.ResidenceParcel.DistanceToLocalBus +
                beta024 * household.ResidenceParcel.DistanceToExpressBus +
                beta025 * isInCopenhagenMunicipality.ToFlag() +
                0;

            alternative        = choiceProbabilityCalculator.GetAlternative(1, true, choice == 1);
            alternative.Choice = 1;
            //Stefan
            //alternative.AddUtilityTerm(10, 1.0);
            //alternative.AddUtilityTerm(11, household.Has1Driver.ToFlag());
            //alternative.AddUtilityTerm(12, household.Has2Drivers.ToFlag());
            //alternative.AddUtilityTerm(13, (household.Has3Drivers || household.Has4OrMoreDrivers).ToFlag());
            //alternative.AddUtilityTerm(14, Math.Log(Math.Max(netIncome - userCost, 1)));
            //alternative.AddUtilityTerm(15, (numberChildren == 1).ToFlag());
            //alternative.AddUtilityTerm(16, (numberChildren == 2).ToFlag());
            //alternative.AddUtilityTerm(17, (numberChildren > 2).ToFlag());
            //alternative.AddUtilityTerm(18, (numberAdults == 1 && !isMale).ToFlag());
            //alternative.AddUtilityTerm(19, (numberAdults == 1 && isMale).ToFlag());
            //alternative.AddUtilityTerm(20, averageAdultAge / 10.0);
            //alternative.AddUtilityTerm(21, Math.Pow(averageAdultAge / 10.0, 2.0));
            ////alternative.AddUtilityTerm(22, household.ResidenceParcel.PSearchTime16_17);  // Add this when new parcel variables with seach time are available
            //alternative.AddUtilityTerm(23, household.ResidenceParcel.DistanceToLocalBus);
            //alternative.AddUtilityTerm(24, household.ResidenceParcel.DistanceToExpressBus);
            //alternative.AddUtilityTerm(25, isInCopenhagenMunicipality.ToFlag());
            alternative.AddUtilityTerm(26, stefanOneCarUtility);              //this composite replaces above separate terms 10-25

            alternative.AddUtilityTerm(27, workTourLogsumDifference);         // instead of all Stefan's work-related and logsum variables

            //alternative.AddUtilityTerm(24, household.HouseholdTotals.RetiredAdultsPerDrivingAgeMembers);
            //alternative.AddUtilityTerm(25, household.HouseholdTotals.UniversityStudentsPerDrivingAgeMembers);
            //alternative.AddUtilityTerm(26, household.HouseholdTotals.DrivingAgeStudentsPerDrivingAgeMembers);
            //alternative.AddUtilityTerm(27, household.HouseholdTotals.HomeBasedPersonsPerDrivingAgeMembers);

            // 2+ AUTOS

            var beta040 = -9.540;
            var beta041 = 2.79;
            var beta042 = 6.09;
            var beta043 = 7.77;
            var beta044 = 0;
            var beta045 = 0.35;
            var beta046 = 0.81;
            var beta047 = 1.33;
            var beta048 = -1.13;
            var beta049 = 0.60;
            var beta050 = 0.92;
            var beta051 = -0.05;
            var beta052 = -0.09;
            var beta053 = 0.94;
            var beta054 = 0.31;
            var beta055 = -1.54;

            var stefanTwoCarUtility =
                beta040 * 1.0 +
                beta041 * household.Has1Driver.ToFlag() +
                beta042 * household.Has2Drivers.ToFlag() +
                beta043 * (household.Has3Drivers || household.Has4OrMoreDrivers).ToFlag() +
                beta014 * Math.Log(Math.Max(netIncome - userCost * 2.0, 1)) +
                beta045 * (numberChildren == 1).ToFlag() +
                beta046 * (numberChildren == 2).ToFlag() +
                beta047 * (numberChildren > 2).ToFlag() +
                beta048 * (numberAdults == 1 && !isMale).ToFlag() +
                beta049 * (numberAdults == 1 && isMale).ToFlag() +
                beta050 * averageAdultAge / 10.0 +
                beta051 * Math.Pow(averageAdultAge / 10.0, 2.0) +
                beta052 * 0 +                 //household.ResidenceParcel.PSearchTime16_17 +  // Add this when new parcel variables with seach time are available
                beta053 * household.ResidenceParcel.DistanceToLocalBus +
                beta054 * household.ResidenceParcel.DistanceToExpressBus +
                beta055 * isInCopenhagenMunicipality.ToFlag() +
                0;

            alternative        = choiceProbabilityCalculator.GetAlternative(2, true, choice == 2);
            alternative.Choice = 2;
            //Stefan
            //alternative.AddUtilityTerm(40, 1.0);
            //alternative.AddUtilityTerm(41, household.Has1Driver.ToFlag());
            //alternative.AddUtilityTerm(42, household.Has2Drivers.ToFlag());
            //alternative.AddUtilityTerm(43, (household.Has3Drivers || household.Has4OrMoreDrivers).ToFlag());
            //alternative.AddUtilityTerm(14, Math.Log(Math.Max(netIncome - userCost * 2.0, 1)));
            //alternative.AddUtilityTerm(45, (numberChildren == 1).ToFlag());
            //alternative.AddUtilityTerm(46, (numberChildren == 2).ToFlag());
            //alternative.AddUtilityTerm(47, (numberChildren > 2).ToFlag());
            //alternative.AddUtilityTerm(48, (numberAdults == 1 && !isMale).ToFlag());
            //alternative.AddUtilityTerm(49, (numberAdults == 1 && isMale).ToFlag());
            //alternative.AddUtilityTerm(50, averageAdultAge / 10.0);
            //alternative.AddUtilityTerm(51, Math.Pow(averageAdultAge / 10.0, 2.0));
            ////alternative.AddUtilityTerm(52, household.ResidenceParcel.PSearchTime16_17);  // Add this when new parcel variables with seach time are available
            //alternative.AddUtilityTerm(53, household.ResidenceParcel.DistanceToLocalBus);
            //alternative.AddUtilityTerm(54, household.ResidenceParcel.DistanceToExpressBus);
            //alternative.AddUtilityTerm(55, isInCopenhagenMunicipality.ToFlag());
            alternative.AddUtilityTerm(56, stefanTwoCarUtility);              //this composite replaces above separate terms 40-55

            alternative.AddUtilityTerm(57, workTourLogsumDifference);

            //alternative.AddUtilityTerm(44, household.HouseholdTotals.RetiredAdultsPerDrivingAgeMembers);
            //alternative.AddUtilityTerm(45, household.HouseholdTotals.UniversityStudentsPerDrivingAgeMembers);
            //alternative.AddUtilityTerm(46, household.HouseholdTotals.DrivingAgeStudentsPerDrivingAgeMembers);
            //alternative.AddUtilityTerm(47, household.HouseholdTotals.HomeBasedPersonsPerDrivingAgeMembers);
        }
Ejemplo n.º 25
0
        public static HouseholdWrapper GetHouseholdWrapper(List <IPerson> persons, int size            = 16, int vehiclesAvailable = 12,
                                                           double expansionFactor                      = .67,
                                                           double fractionWorkersWithJobsOutsideRegion = .25,
                                                           int income                      = 25000,
                                                           int id                          = 3,
                                                           Household household             = null,
                                                           CondensedParcel residenceParcel = null)
        {
            ChoiceModelFactory.Parcels = new Dictionary <int, CondensedParcel>();
            int residenceParcelId = 99;

            ChoiceModelFactory.Parcels.Add(residenceParcelId, residenceParcel == null ? new CondensedParcel() : residenceParcel);


            int workers            = 6;
            int fulltimeWorkers    = 4;
            int partTimeWorkers    = 2;
            int retiredAdults      = 3;
            int otherAdults        = 1;
            int collegeStudents    = 0;
            int highSchoolStudents = 1;
            int kidsBetween5And15  = 1;
            int kidsBetween0And4   = 1;
            int ownOrRent          = 1;
            int residenceType      = 2;
            int residenceZoneId    = 4;
            int residenceZoneKey   = 5;
            int sampleType         = 7;

            if (household == null)
            {
                household = new Household
                {
                    CollegeStudents = collegeStudents,
                    ExpansionFactor = expansionFactor,
                    FractionWorkersWithJobsOutsideRegion =
                        fractionWorkersWithJobsOutsideRegion,
                    FulltimeWorkers    = fulltimeWorkers,
                    HighSchoolStudents = highSchoolStudents,
                    Income             = income,
                    Id = id,
                    KidsBetween0And4  = kidsBetween0And4,
                    KidsBetween5And15 = kidsBetween5And15,
                    OtherAdults       = otherAdults,
                    OwnOrRent         = ownOrRent,
                    PartTimeWorkers   = partTimeWorkers,
                    ResidenceParcelId = residenceParcelId,
                    ResidenceType     = residenceType,
                    ResidenceZoneId   = residenceZoneId,
                    ResidenceZoneKey  = residenceZoneKey,
                    RetiredAdults     = retiredAdults,
                    SampleType        = sampleType,
                    Size = size,
                    VehiclesAvailable = vehiclesAvailable,
                    Workers           = workers
                }
            }
            ;

            HouseholdWrapper wrapper = new HouseholdWrapper(household)
            {
                PersonPersister            = new TestPersonPersister(persons),
                PersonWrapperCreator       = new TestPersonWrapperCreator(),
                HouseholdDayPersister      = new TestHouseholdDayPersister(),
                HouseholdDayWrapperCreator = new TestHouseholdDayWrapperCreator(),
                HouseholdPersister         = new TestHouseholdPersister(),
            };

            return(wrapper);
        }
Ejemplo n.º 26
0
        public void TestHouseholdWrapperCarsLessFlag()
        {
            Global.Configuration = new Configuration();
            Global.Configuration.HouseholdSamplingRateOneInX = 1;
            List <IPerson> persons = new List <IPerson>
            {
                new Person {
                    Age = 37, PersonType = Constants.PersonType.FULL_TIME_WORKER, WorkerType = 1
                }
            };
            HouseholdWrapper wrapper = TestHelper.GetHouseholdWrapper(persons);

            wrapper.Init();
            Assert.Equal(0, wrapper.GetCarsLessThanDriversFlag(1));
            Assert.Equal(0, wrapper.GetCarsLessThanDriversFlag(0));
            Assert.Equal(0, wrapper.GetCarsLessThanDriversFlag(2));
            Assert.Equal(0, wrapper.GetCarsLessThanWorkersFlag(1));
            Assert.Equal(0, wrapper.GetCarsLessThanWorkersFlag(2));
            Assert.Equal(0, wrapper.GetCarsLessThanWorkersFlag(0));
            Assert.Equal(true, wrapper.Has1Driver);
            Assert.Equal(false, wrapper.Has2Drivers);
            Assert.Equal(false, wrapper.Has3Drivers);
            Assert.Equal(false, wrapper.Has4OrMoreDrivers);
            Assert.Equal(true, wrapper.Has2OrLessFullOrPartTimeWorkers);
            Assert.Equal(true, wrapper.Has3OrLessFullOrPartTimeWorkers);
            Assert.Equal(true, wrapper.Has4OrLessFullOrPartTimeWorkers);
            Assert.Equal(false, wrapper.HasMoreDriversThan1);
            Assert.Equal(false, wrapper.HasMoreDriversThan2);
            Assert.Equal(false, wrapper.HasMoreDriversThan3);
            Assert.Equal(false, wrapper.HasMoreDriversThan4);
            Assert.Equal(false, wrapper.HasNoFullOrPartTimeWorker);

            persons = new List <IPerson>
            {
                new Person {
                    Age = 37, PersonType = Constants.PersonType.FULL_TIME_WORKER, WorkerType = 1
                },
                new Person {
                    Age = 37, PersonType = Constants.PersonType.FULL_TIME_WORKER, WorkerType = 1
                }
            };
            wrapper = TestHelper.GetHouseholdWrapper(persons);
            wrapper.Init();
            Assert.Equal(1, wrapper.GetCarsLessThanDriversFlag(1));
            Assert.Equal(0, wrapper.GetCarsLessThanDriversFlag(2));
            Assert.Equal(1, wrapper.GetCarsLessThanWorkersFlag(1));
            Assert.Equal(0, wrapper.GetCarsLessThanWorkersFlag(2));
            Assert.Equal(false, wrapper.Has1Driver);
            Assert.Equal(true, wrapper.Has2Drivers);
            Assert.Equal(false, wrapper.Has3Drivers);
            Assert.Equal(false, wrapper.Has4OrMoreDrivers);
            Assert.Equal(true, wrapper.Has2OrLessFullOrPartTimeWorkers);
            Assert.Equal(true, wrapper.Has3OrLessFullOrPartTimeWorkers);
            Assert.Equal(true, wrapper.Has4OrLessFullOrPartTimeWorkers);
            Assert.Equal(true, wrapper.HasMoreDriversThan1);
            Assert.Equal(false, wrapper.HasMoreDriversThan2);
            Assert.Equal(false, wrapper.HasMoreDriversThan3);
            Assert.Equal(false, wrapper.HasMoreDriversThan4);
            Assert.Equal(false, wrapper.HasNoFullOrPartTimeWorker);

            persons = new List <IPerson>
            {
                new Person {
                    Age = 37, PersonType = Constants.PersonType.FULL_TIME_WORKER, WorkerType = 1
                },
                new Person {
                    Age = 37, PersonType = Constants.PersonType.FULL_TIME_WORKER, WorkerType = 1
                },
                new Person {
                    Age = 7, PersonType = Constants.PersonType.CHILD_AGE_5_THROUGH_15, StudentType = 1
                }
            };
            wrapper = TestHelper.GetHouseholdWrapper(persons);
            wrapper.Init();
            Assert.Equal(1, wrapper.GetCarsLessThanDriversFlag(1));
            Assert.Equal(0, wrapper.GetCarsLessThanDriversFlag(2));
            Assert.Equal(1, wrapper.GetCarsLessThanWorkersFlag(1));
            Assert.Equal(0, wrapper.GetCarsLessThanWorkersFlag(2));
            Assert.Equal(false, wrapper.Has1Driver);
            Assert.Equal(true, wrapper.Has2Drivers);
            Assert.Equal(false, wrapper.Has3Drivers);
            Assert.Equal(false, wrapper.Has4OrMoreDrivers);
            Assert.Equal(true, wrapper.Has2OrLessFullOrPartTimeWorkers);
            Assert.Equal(true, wrapper.Has3OrLessFullOrPartTimeWorkers);
            Assert.Equal(true, wrapper.Has4OrLessFullOrPartTimeWorkers);
            Assert.Equal(true, wrapper.HasMoreDriversThan1);
            Assert.Equal(false, wrapper.HasMoreDriversThan2);
            Assert.Equal(false, wrapper.HasMoreDriversThan3);
            Assert.Equal(false, wrapper.HasMoreDriversThan4);
            Assert.Equal(false, wrapper.HasNoFullOrPartTimeWorker);

            persons = new List <IPerson>
            {
                new Person {
                    Age = 37, PersonType = Constants.PersonType.FULL_TIME_WORKER, WorkerType = 1
                },
                new Person {
                    Age = 37, PersonType = Constants.PersonType.FULL_TIME_WORKER, WorkerType = 1
                },
                new Person {
                    Age = 37, PersonType = Constants.PersonType.FULL_TIME_WORKER, WorkerType = 1
                },
            };
            wrapper = TestHelper.GetHouseholdWrapper(persons);
            wrapper.Init();
            Assert.Equal(1, wrapper.GetCarsLessThanDriversFlag(1));
            Assert.Equal(1, wrapper.GetCarsLessThanDriversFlag(2));
            Assert.Equal(0, wrapper.GetCarsLessThanDriversFlag(3));
            Assert.Equal(1, wrapper.GetCarsLessThanWorkersFlag(1));
            Assert.Equal(1, wrapper.GetCarsLessThanWorkersFlag(2));
            Assert.Equal(0, wrapper.GetCarsLessThanWorkersFlag(3));
            Assert.Equal(false, wrapper.Has1Driver);
            Assert.Equal(false, wrapper.Has2Drivers);
            Assert.Equal(true, wrapper.Has3Drivers);
            Assert.Equal(false, wrapper.Has4OrMoreDrivers);
            Assert.Equal(false, wrapper.Has2OrLessFullOrPartTimeWorkers);
            Assert.Equal(true, wrapper.Has3OrLessFullOrPartTimeWorkers);
            Assert.Equal(true, wrapper.Has4OrLessFullOrPartTimeWorkers);
            Assert.Equal(true, wrapper.HasMoreDriversThan1);
            Assert.Equal(true, wrapper.HasMoreDriversThan2);
            Assert.Equal(false, wrapper.HasMoreDriversThan3);
            Assert.Equal(false, wrapper.HasMoreDriversThan4);
            Assert.Equal(false, wrapper.HasNoFullOrPartTimeWorker);

            persons = new List <IPerson>
            {
                new Person {
                    Age = 37, PersonType = Constants.PersonType.FULL_TIME_WORKER, WorkerType = 1
                },
                new Person {
                    Age = 37, PersonType = Constants.PersonType.PART_TIME_WORKER, WorkerType = 1
                },
                new Person {
                    Age = 37, PersonType = Constants.PersonType.RETIRED_ADULT, WorkerType = 0
                },
            };
            wrapper = TestHelper.GetHouseholdWrapper(persons);
            wrapper.Init();
            Assert.Equal(1, wrapper.GetCarsLessThanDriversFlag(1));
            Assert.Equal(1, wrapper.GetCarsLessThanDriversFlag(2));
            Assert.Equal(0, wrapper.GetCarsLessThanDriversFlag(3));
            Assert.Equal(1, wrapper.GetCarsLessThanWorkersFlag(1));
            Assert.Equal(0, wrapper.GetCarsLessThanWorkersFlag(2));
            Assert.Equal(0, wrapper.GetCarsLessThanWorkersFlag(3));
            Assert.Equal(false, wrapper.Has1Driver);
            Assert.Equal(false, wrapper.Has2Drivers);
            Assert.Equal(true, wrapper.Has3Drivers);
            Assert.Equal(false, wrapper.Has4OrMoreDrivers);
            Assert.Equal(true, wrapper.Has2OrLessFullOrPartTimeWorkers);
            Assert.Equal(true, wrapper.Has3OrLessFullOrPartTimeWorkers);
            Assert.Equal(true, wrapper.Has4OrLessFullOrPartTimeWorkers);
            Assert.Equal(true, wrapper.HasMoreDriversThan1);
            Assert.Equal(true, wrapper.HasMoreDriversThan2);
            Assert.Equal(false, wrapper.HasMoreDriversThan3);
            Assert.Equal(false, wrapper.HasMoreDriversThan4);
            Assert.Equal(false, wrapper.HasNoFullOrPartTimeWorker);

            persons = new List <IPerson>
            {
                new Person {
                    Age = 37, PersonType = Constants.PersonType.FULL_TIME_WORKER, WorkerType = 1
                },
                new Person {
                    Age = 37, PersonType = Constants.PersonType.PART_TIME_WORKER, WorkerType = 1
                },
                new Person {
                    Age = 37, PersonType = Constants.PersonType.RETIRED_ADULT, WorkerType = 0
                },
                new Person {
                    Age = 37, PersonType = Constants.PersonType.FULL_TIME_WORKER, WorkerType = 1
                },
                new Person {
                    Age = 37, PersonType = Constants.PersonType.PART_TIME_WORKER, WorkerType = 1
                },
                new Person {
                    Age = 37, PersonType = Constants.PersonType.RETIRED_ADULT, WorkerType = 0
                },
                new Person {
                    Age = 37, PersonType = Constants.PersonType.PART_TIME_WORKER, WorkerType = 1
                },
            };
            wrapper = TestHelper.GetHouseholdWrapper(persons);
            wrapper.Init();
            Assert.Equal(1, wrapper.GetCarsLessThanDriversFlag(1));
            Assert.Equal(1, wrapper.GetCarsLessThanDriversFlag(2));
            Assert.Equal(1, wrapper.GetCarsLessThanDriversFlag(3));
            Assert.Equal(1, wrapper.GetCarsLessThanWorkersFlag(1));
            Assert.Equal(1, wrapper.GetCarsLessThanWorkersFlag(2));
            Assert.Equal(1, wrapper.GetCarsLessThanWorkersFlag(3));
            Assert.Equal(false, wrapper.Has1Driver);
            Assert.Equal(false, wrapper.Has2Drivers);
            Assert.Equal(false, wrapper.Has3Drivers);
            Assert.Equal(true, wrapper.Has4OrMoreDrivers);
            Assert.Equal(false, wrapper.Has2OrLessFullOrPartTimeWorkers);
            Assert.Equal(false, wrapper.Has3OrLessFullOrPartTimeWorkers);
            Assert.Equal(false, wrapper.Has4OrLessFullOrPartTimeWorkers);
            Assert.Equal(true, wrapper.HasMoreDriversThan1);
            Assert.Equal(true, wrapper.HasMoreDriversThan2);
            Assert.Equal(true, wrapper.HasMoreDriversThan3);
            Assert.Equal(true, wrapper.HasMoreDriversThan4);
            Assert.Equal(false, wrapper.HasNoFullOrPartTimeWorker);


            persons = new List <IPerson>
            {
                new Person {
                    Age = 37, PersonType = Constants.PersonType.RETIRED_ADULT, WorkerType = 0
                },
            };
            wrapper = TestHelper.GetHouseholdWrapper(persons);
            wrapper.Init();
            Assert.Equal(0, wrapper.GetCarsLessThanDriversFlag(1));
            Assert.Equal(0, wrapper.GetCarsLessThanDriversFlag(2));
            Assert.Equal(0, wrapper.GetCarsLessThanDriversFlag(3));
            Assert.Equal(0, wrapper.GetCarsLessThanWorkersFlag(1));
            Assert.Equal(0, wrapper.GetCarsLessThanWorkersFlag(2));
            Assert.Equal(0, wrapper.GetCarsLessThanWorkersFlag(3));
            Assert.Equal(true, wrapper.Has1Driver);
            Assert.Equal(false, wrapper.Has2Drivers);
            Assert.Equal(false, wrapper.Has3Drivers);
            Assert.Equal(false, wrapper.Has4OrMoreDrivers);
            Assert.Equal(true, wrapper.Has2OrLessFullOrPartTimeWorkers);
            Assert.Equal(true, wrapper.Has3OrLessFullOrPartTimeWorkers);
            Assert.Equal(true, wrapper.Has4OrLessFullOrPartTimeWorkers);
            Assert.Equal(false, wrapper.HasMoreDriversThan1);
            Assert.Equal(false, wrapper.HasMoreDriversThan2);
            Assert.Equal(false, wrapper.HasMoreDriversThan3);
            Assert.Equal(false, wrapper.HasMoreDriversThan4);
            Assert.Equal(true, wrapper.HasNoFullOrPartTimeWorker);
        }
Ejemplo n.º 27
0
        public void TestPersonWrapper()
        {
            Global.Configuration = new Configuration {
                HouseholdSamplingRateOneInX = 1
            };
            int             autoDistanceToUsualSchool = 1;
            int             autoDistanceToUsualWork   = 2;
            int             autoTimeToUsualSchool     = 3;
            int             autoTimeToUsualWork       = 4;
            int             gender                       = 2;
            int             id                           = 99;
            int             paperDiary                   = 5;
            int             payParkingAtWorkplace        = 1;
            int             personType                   = Constants.PersonType.CHILD_UNDER_5;
            int             proxyResponse                = 6;
            int             sequence                     = 7;
            int             transitPassOwnershipFlag     = 1;
            int             usualArrivalPeriodToWork     = 2;
            int             usualDeparturePeriodFromWork = 3;
            int             usualModeToWork              = 4;
            CondensedParcel usualSchoolParcel            = new CondensedParcel();
            int             usualSchoolParcelId          = 5;
            int             usualSchoolZoneKey           = 6;
            CondensedParcel usualWorkParcel              = new CondensedParcel();
            int             usualWorkParcelId            = 7;
            int             usualWorkZoneKey             = 8;
            bool            worksAtHome                  = false;

            List <IPerson> persons = new List <IPerson>()
            {
                new Person()
                {
                    AutoDistanceToUsualSchool = autoDistanceToUsualSchool,
                    AutoDistanceToUsualWork   = autoDistanceToUsualWork,
                    AutoTimeToUsualSchool     = autoTimeToUsualSchool,
                    AutoTimeToUsualWork       = autoTimeToUsualWork,
                    Gender                       = gender,
                    Id                           = id,
                    PaperDiary                   = paperDiary,
                    PaidParkingAtWorkplace       = payParkingAtWorkplace,
                    PersonType                   = personType,
                    ProxyResponse                = proxyResponse,
                    Sequence                     = sequence,
                    TransitPassOwnership         = transitPassOwnershipFlag,
                    UsualArrivalPeriodToWork     = usualArrivalPeriodToWork,
                    UsualDeparturePeriodFromWork = usualDeparturePeriodFromWork,
                    UsualModeToWork              = usualModeToWork,
                    UsualSchoolParcelId          = usualSchoolParcelId,
                    UsualSchoolZoneKey           = usualSchoolZoneKey,
                    UsualWorkParcelId            = usualWorkParcelId,
                    UsualWorkZoneKey             = usualWorkZoneKey,
                }
            };
            HouseholdWrapper household = TestHelper.GetHouseholdWrapper(persons);
            PersonWrapper    wrapper   = new PersonWrapper(persons[0], household)
            {
                UsualSchoolParcel = usualSchoolParcel, UsualWorkParcel = usualWorkParcel
            };                                                                                                                                                     //TestHelper.GetPersonWrapper(age: 37, personType: Constants.PersonType.FULL_TIME_WORKER,

            //                          gender: 1, workerType: 1, studentType: 0, persons:persons);
            Assert.Equal(autoDistanceToUsualSchool, wrapper.AutoDistanceToUsualSchool);
            Assert.Equal(autoDistanceToUsualWork, wrapper.AutoDistanceToUsualWork);
            Assert.Equal(autoTimeToUsualSchool, wrapper.AutoTimeToUsualSchool);
            Assert.Equal(autoTimeToUsualWork, wrapper.AutoTimeToUsualWork);
            Assert.Equal(gender, wrapper.Gender);
            Assert.Equal(household, wrapper.Household);
            Assert.Equal(id, wrapper.Id);
            Assert.Equal(paperDiary, wrapper.PaperDiary);
            Assert.Equal(payParkingAtWorkplace, wrapper.PayToParkAtWorkplaceFlag);
            Assert.Equal(personType, wrapper.PersonType);
            Assert.Equal(proxyResponse, wrapper.ProxyResponse);
            Assert.Equal(sequence, wrapper.Sequence);

            Assert.Equal(transitPassOwnershipFlag, wrapper.TransitPassOwnershipFlag);
            Assert.Equal(usualArrivalPeriodToWork, wrapper.UsualArrivalPeriodToWork);
            Assert.Equal(usualDeparturePeriodFromWork, wrapper.UsualDeparturePeriodFromWork);
            Assert.Equal(usualModeToWork, wrapper.UsualModeToWork);
            Assert.Equal(usualSchoolParcel, wrapper.UsualSchoolParcel);
            Assert.Equal(usualSchoolParcelId, wrapper.UsualSchoolParcelId);
            Assert.Equal(usualSchoolZoneKey, wrapper.UsualSchoolZoneKey);
            Assert.Equal(usualWorkParcel, wrapper.UsualWorkParcel);
            Assert.Equal(usualWorkParcelId, wrapper.UsualWorkParcelId);
            Assert.Equal(usualWorkZoneKey, wrapper.UsualWorkZoneKey);
            Assert.Equal(worksAtHome, wrapper.WorksAtHome);
        }
Ejemplo n.º 28
0
        private void RunModel(ChoiceProbabilityCalculator choiceProbabilityCalculator, HouseholdWrapper household, int choice = Constants.DEFAULT_VALUE)
        {
            //
            double workTourLogsumDifference = 0D; // (full or part-time workers) full car ownership vs. no car ownership

            double countTransitPasses = 0D;

            foreach (Framework.DomainModels.Wrappers.IPersonWrapper person in household.Persons)
            {
                if (person.TransitPassOwnership == 1)
                {
                    countTransitPasses++;
                }
                if (person.IsWorker && person.UsualWorkParcel != null && person.UsualWorkParcelId != household.ResidenceParcelId)
                {
                    int destinationArrivalTime   = ChoiceModelUtility.GetDestinationArrivalTime(Global.Settings.Models.WorkTourModeModel);
                    int destinationDepartureTime = ChoiceModelUtility.GetDestinationDepartureTime(Global.Settings.Models.WorkTourModeModel);

                    ChoiceProbabilityCalculator.Alternative nestedAlternative1 = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().RunNested(person, household.ResidenceParcel, person.UsualWorkParcel, destinationArrivalTime, destinationDepartureTime, household.HouseholdTotals.DrivingAgeMembers, 0.0);
                    ChoiceProbabilityCalculator.Alternative nestedAlternative2 = Global.ChoiceModelSession.Get <WorkTourModeTimeModel>().RunNested(person, household.ResidenceParcel, person.UsualWorkParcel, destinationArrivalTime, destinationDepartureTime, 0, 0.0);

                    workTourLogsumDifference += nestedAlternative1 == null ? 0 : nestedAlternative1.ComputeLogsum();
                    workTourLogsumDifference -= nestedAlternative2 == null ? 0 : nestedAlternative2.ComputeLogsum();
                }
            }

            int oldestAge   = (from persons in household.Persons select persons.Age).Max();
            int youngestAge = (from persons in household.Persons select persons.Age).Min();

            int noTransitPasses = countTransitPasses == 0 ? 1 : 0;

            int votSegment = household.GetVotALSegment();
            int taSegment  = household.ResidenceParcel.TransitAccessSegment();

            //var aggregateLogsumDifference = // full car ownership vs. no car ownership
            //    Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.OneOrMoreCarsPerAdult][votSegment][taSegment] -
            //    Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.NoCars][votSegment][taSegment];

            double noCarAggLogsum =
                Global.AggregateLogsums[household.ResidenceZoneId][Global.Settings.Purposes.HomeBasedComposite][Global.Settings.CarOwnerships.NoCars][votSegment][taSegment];

            double distanceToStop
                = household.ResidenceParcel.GetDistanceToTransit() > 0
                      ? Math.Min(household.ResidenceParcel.GetDistanceToTransit(), 2 * Global.Settings.DistanceUnitsPerMile)  // JLBscale
                      : 2 * Global.Settings.DistanceUnitsPerMile;

            int ruralFlag = household.ResidenceParcel.RuralFlag();

            double discretionaryIncome = (household.Income / 10000 - (1.2 * Math.Log(household.Size) + 2.0));


            //home parcel buffer variables
            double foodRetailServiceMedicalLogBuffer1 = Math.Log(1 + household.ResidenceParcel.FoodRetailServiceMedicalLogBuffer1());
            double intrDens = Math.Log(1 + household.ResidenceParcel.IntersectionDensity34Buffer2());

            // 0 AUTOS

            ChoiceProbabilityCalculator.Alternative alternative = choiceProbabilityCalculator.GetAlternative(0, true, choice == 0);

            alternative.Choice = 0;

            alternative.AddUtilityTerm(1, household.Has1Driver.ToFlag());
            alternative.AddUtilityTerm(2, household.Has2Drivers.ToFlag());
            alternative.AddUtilityTerm(3, household.Has3Drivers.ToFlag());
            alternative.AddUtilityTerm(4, household.Has4OrMoreDrivers.ToFlag());
            alternative.AddUtilityTerm(5, household.HasNoFullOrPartTimeWorker.ToFlag());
            alternative.AddUtilityTerm(8, household.HouseholdTotals.UniversityStudentsPerDrivingAgeMembers);
            alternative.AddUtilityTerm(9, household.HouseholdTotals.DrivingAgeStudentsPerDrivingAgeMembers);
            alternative.AddUtilityTerm(12, household.Has0To25KIncome.ToFlag());
            alternative.AddUtilityTerm(13, discretionaryIncome);
            alternative.AddUtilityTerm(14, household.HasIncomeOver50K.ToFlag());
            alternative.AddUtilityTerm(16, household.HasMissingIncome.ToFlag());
            alternative.AddUtilityTerm(17, workTourLogsumDifference);
            alternative.AddUtilityTerm(21, Math.Log(distanceToStop));
            alternative.AddUtilityTerm(23, Math.Log(1 + household.ResidenceParcel.ParkingOffStreetPaidDailyPriceBuffer2 / 100));
            alternative.AddUtilityTerm(28, noTransitPasses);
            alternative.AddUtilityTerm(29, intrDens);
            alternative.AddUtilityTerm(31, household.HasChildrenUnder16.ToFlag());
            alternative.AddUtilityTerm(33, (household.Has50To75KIncome).ToFlag() * noCarAggLogsum);
            alternative.AddUtilityTerm(34, (household.Has75KPlusIncome).ToFlag() * noCarAggLogsum);
            alternative.AddUtilityTerm(35, (youngestAge > 70).ToFlag());
            alternative.AddUtilityTerm(36, (oldestAge < 35).ToFlag());

            // 1 AUTO

            alternative = choiceProbabilityCalculator.GetAlternative(1, true, choice == 1);

            alternative.Choice = 1;

            alternative.AddUtilityTerm(37, household.Has2Drivers.ToFlag());
            alternative.AddUtilityTerm(38, household.Has3Drivers.ToFlag());
            alternative.AddUtilityTerm(39, household.Has4OrMoreDrivers.ToFlag());
            alternative.AddUtilityTerm(5, household.Has1OrLessFullOrPartTimeWorkers.ToFlag());
            alternative.AddUtilityTerm(8, household.HouseholdTotals.UniversityStudentsPerDrivingAgeMembers);
            alternative.AddUtilityTerm(9, household.HouseholdTotals.DrivingAgeStudentsPerDrivingAgeMembers);
            alternative.AddUtilityTerm(41, household.Has0To25KIncome.ToFlag());
            alternative.AddUtilityTerm(45, household.HasMissingIncome.ToFlag());
            alternative.AddUtilityTerm(19, discretionaryIncome);
            alternative.AddUtilityTerm(17, workTourLogsumDifference * household.HasMoreDriversThan1.ToFlag());
            alternative.AddUtilityTerm(23, Math.Log(1 + household.ResidenceParcel.ParkingOffStreetPaidDailyPriceBuffer2 / 100) * household.HasMoreDriversThan1.ToFlag());
            alternative.AddUtilityTerm(46, intrDens);
            alternative.AddUtilityTerm(35, (youngestAge > 70).ToFlag());
            alternative.AddUtilityTerm(36, (oldestAge < 35).ToFlag());
            alternative.AddUtilityTerm(48, household.HasChildrenUnder16.ToFlag());

            // 2 AUTOS

            alternative = choiceProbabilityCalculator.GetAlternative(2, true, choice == 2);

            alternative.Choice = 2;

            alternative.AddUtilityTerm(50, household.Has1Driver.ToFlag());
            alternative.AddUtilityTerm(51, household.Has3Drivers.ToFlag());
            alternative.AddUtilityTerm(52, household.Has4OrMoreDrivers.ToFlag());
            alternative.AddUtilityTerm(5, household.Has2OrLessFullOrPartTimeWorkers.ToFlag());
            alternative.AddUtilityTerm(17, workTourLogsumDifference * household.HasMoreDriversThan2.ToFlag());
            alternative.AddUtilityTerm(23, Math.Log(1 + household.ResidenceParcel.ParkingOffStreetPaidDailyPriceBuffer2 / 100) * household.HasMoreDriversThan2.ToFlag());
            alternative.AddUtilityTerm(27, ruralFlag);

            // 3 AUTOS

            alternative = choiceProbabilityCalculator.GetAlternative(3, true, choice == 3);

            alternative.Choice = 3;

            alternative.AddUtilityTerm(70, household.Has1Driver.ToFlag());
            alternative.AddUtilityTerm(71, household.Has2Drivers.ToFlag());
            alternative.AddUtilityTerm(72, household.Has4OrMoreDrivers.ToFlag());
            alternative.AddUtilityTerm(5, household.Has3OrLessFullOrPartTimeWorkers.ToFlag());
            alternative.AddUtilityTerm(91, household.HouseholdTotals.PartTimeWorkersPerDrivingAgeMembers);
            alternative.AddUtilityTerm(92, household.HouseholdTotals.RetiredAdultsPerDrivingAgeMembers);
            alternative.AddUtilityTerm(93, household.HouseholdTotals.UniversityStudentsPerDrivingAgeMembers);
            alternative.AddUtilityTerm(94, household.HouseholdTotals.DrivingAgeStudentsPerDrivingAgeMembers);
            alternative.AddUtilityTerm(96, household.HouseholdTotals.ChildrenUnder5PerDrivingAgeMembers);
            alternative.AddUtilityTerm(73, household.Has0To25KIncome.ToFlag());
            alternative.AddUtilityTerm(75, household.Has100KPlusIncome.ToFlag());
            alternative.AddUtilityTerm(76, household.HasMissingIncome.ToFlag());
            alternative.AddUtilityTerm(17, workTourLogsumDifference * household.HasMoreDriversThan3.ToFlag());
            alternative.AddUtilityTerm(23, Math.Log(1 + household.ResidenceParcel.ParkingOffStreetPaidDailyPriceBuffer2 / 100) * household.HasMoreDriversThan3.ToFlag());
            alternative.AddUtilityTerm(79, ruralFlag);

            // 4+ AUTOS
            alternative = choiceProbabilityCalculator.GetAlternative(4, true, choice == 4);

            alternative.Choice = 4;

            alternative.AddUtilityTerm(100, household.Has1Driver.ToFlag());
            alternative.AddUtilityTerm(101, household.Has2Drivers.ToFlag());
            alternative.AddUtilityTerm(102, household.Has3Drivers.ToFlag());
            alternative.AddUtilityTerm(5, household.Has4OrLessFullOrPartTimeWorkers.ToFlag());
            alternative.AddUtilityTerm(91, household.HouseholdTotals.PartTimeWorkersPerDrivingAgeMembers);
            alternative.AddUtilityTerm(92, household.HouseholdTotals.RetiredAdultsPerDrivingAgeMembers);
            alternative.AddUtilityTerm(93, household.HouseholdTotals.UniversityStudentsPerDrivingAgeMembers);
            alternative.AddUtilityTerm(94, household.HouseholdTotals.DrivingAgeStudentsPerDrivingAgeMembers);
            alternative.AddUtilityTerm(96, household.HouseholdTotals.ChildrenUnder5PerDrivingAgeMembers);
            alternative.AddUtilityTerm(107, household.Has0To25KIncome.ToFlag());
            alternative.AddUtilityTerm(108, household.Has50To75KIncome.ToFlag());
            alternative.AddUtilityTerm(109, household.Has75KPlusIncome.ToFlag());
            alternative.AddUtilityTerm(110, household.HasMissingIncome.ToFlag());
            alternative.AddUtilityTerm(17, workTourLogsumDifference * household.HasMoreDriversThan4.ToFlag());
            alternative.AddUtilityTerm(23, Math.Log(1 + household.ResidenceParcel.ParkingOffStreetPaidDailyPriceBuffer2 / 100) * household.HasMoreDriversThan4.ToFlag());
            alternative.AddUtilityTerm(111, ruralFlag);
        }
Ejemplo n.º 29
0
        public static PersonWrapper GetPersonWrapper(int age = 35, int personType = Constants.PersonType.FULL_TIME_WORKER, int gender = 1, int workerType = 0, int studentType = 0, List <IPerson> persons = null, HouseholdWrapper household = null, int income = 25000, int sequence = 0)
        {
            if (persons == null)
            {
                persons = new List <IPerson>
                {
                    new Person()
                    {
                        Age         = age,
                        PersonType  = personType,
                        Gender      = gender,
                        WorkerType  = workerType,
                        StudentType = studentType,
                        Sequence    = sequence,
                    }
                };
            }
            if (household == null)
            {
                household = GetHouseholdWrapper(persons, income: income);
            }
            household.Init();
            PersonWrapper wrapper = new PersonWrapper(persons[0], household);

            return(wrapper);
        }
Ejemplo n.º 30
0
        public void TestHouseholdWrapperChildren()
        {
            Global.Configuration = new Configuration();
            Global.Configuration.HouseholdSamplingRateOneInX = 1;
            List <IPerson> persons = new List <IPerson>
            {
                new Person {
                    Age = 37, PersonType = Constants.PersonType.FULL_TIME_WORKER, WorkerType = 1
                }
            };
            HouseholdWrapper wrapper = TestHelper.GetHouseholdWrapper(persons);

            wrapper.Init();

            Assert.Equal(false, wrapper.HasChildrenAge5Through15);
            Assert.Equal(false, wrapper.HasChildrenUnder16);
            Assert.Equal(false, wrapper.HasChildrenUnder5);
            Assert.Equal(false, wrapper.HasChildren);


            persons = new List <IPerson>
            {
                new Person {
                    Age = 37, PersonType = Constants.PersonType.FULL_TIME_WORKER, WorkerType = 1
                },
                new Person {
                    Age = 4, PersonType = Constants.PersonType.CHILD_UNDER_5, WorkerType = 0
                },
            };
            wrapper = TestHelper.GetHouseholdWrapper(persons);
            wrapper.Init();

            Assert.Equal(false, wrapper.HasChildrenAge5Through15);
            Assert.Equal(true, wrapper.HasChildrenUnder16);
            Assert.Equal(true, wrapper.HasChildrenUnder5);
            Assert.Equal(true, wrapper.HasChildren);

            persons = new List <IPerson>
            {
                new Person {
                    Age = 37, PersonType = Constants.PersonType.FULL_TIME_WORKER, WorkerType = 1
                },
                new Person {
                    Age = 7, PersonType = Constants.PersonType.CHILD_AGE_5_THROUGH_15, WorkerType = 0
                },
            };
            wrapper = TestHelper.GetHouseholdWrapper(persons);
            wrapper.Init();

            Assert.Equal(true, wrapper.HasChildrenAge5Through15);
            Assert.Equal(true, wrapper.HasChildrenUnder16);
            Assert.Equal(false, wrapper.HasChildrenUnder5);
            Assert.Equal(true, wrapper.HasChildren);

            persons = new List <IPerson>
            {
                new Person {
                    Age = 37, PersonType = Constants.PersonType.FULL_TIME_WORKER, WorkerType = 1
                },
                new Person {
                    Age = 7, PersonType = Constants.PersonType.CHILD_AGE_5_THROUGH_15, WorkerType = 0
                },
                new Person {
                    Age = 4, PersonType = Constants.PersonType.CHILD_UNDER_5, WorkerType = 0
                },
            };
            wrapper = TestHelper.GetHouseholdWrapper(persons);
            wrapper.Init();

            Assert.Equal(true, wrapper.HasChildrenAge5Through15);
            Assert.Equal(true, wrapper.HasChildrenUnder16);
            Assert.Equal(true, wrapper.HasChildrenUnder5);
            Assert.Equal(true, wrapper.HasChildren);

            persons = new List <IPerson>
            {
                new Person {
                    Age = 37, PersonType = Constants.PersonType.FULL_TIME_WORKER, WorkerType = 1
                },
                new Person {
                    Age = 17, PersonType = Constants.PersonType.DRIVING_AGE_STUDENT, WorkerType = 0
                },
            };
            wrapper = TestHelper.GetHouseholdWrapper(persons);
            wrapper.Init();

            Assert.Equal(false, wrapper.HasChildrenAge5Through15);
            Assert.Equal(false, wrapper.HasChildrenUnder16);
            Assert.Equal(false, wrapper.HasChildrenUnder5);
            Assert.Equal(true, wrapper.HasChildren);
        }