Exemple #1
0
        /// <summary>
        /// Funky function directly from Tasha original
        /// </summary>
        /// <param name="person"></param>
        /// <returns></returns>
        internal static PersonWorkSchoolProjectStatus GetWorkSchoolProjectStatus(ITashaPerson person)
        {
            //TashaTime workSchoolStartTime = (person["SData"] as SchedulerPersonData).;
            Time workSchoolStartTime = SchedulerPerson.GetWorkSchoolStartTime(person);
            Time workSchoolEndTime   = SchedulerPerson.GetWorkSchoolEndTime(person);

            PersonWorkSchoolProjectStatus workSchoolProjectStatus = PersonWorkSchoolProjectStatus.NoWorkOrSchool;

            if (workSchoolStartTime <= Time.StartOfDay)
            {
                workSchoolProjectStatus = PersonWorkSchoolProjectStatus.NoWorkOrSchool;
            }
            else if ((workSchoolEndTime - workSchoolStartTime) >= Scheduler.FullTimeActivity)
            {
                if (workSchoolEndTime <= new Time()
                {
                    Hours = 14
                })
                {
                    workSchoolProjectStatus = PersonWorkSchoolProjectStatus.FullTimeNoEveningWorkOrSchool;
                }
                else if (workSchoolStartTime >= new Time()
                {
                    Hours = 9
                })
                {
                    workSchoolProjectStatus = PersonWorkSchoolProjectStatus.FullTimeEveningWorkOrSchool;
                }
                else
                {
                    workSchoolProjectStatus = PersonWorkSchoolProjectStatus.FullTimeDayAndEveningWorkOrSchool;
                }
            }
            else if (workSchoolEndTime - workSchoolStartTime < Scheduler.FullTimeActivity)
            {
                if (workSchoolEndTime <= new Time()
                {
                    Hours = 9
                })
                {
                    workSchoolProjectStatus = PersonWorkSchoolProjectStatus.PartTimeDay;
                }
                else if (workSchoolEndTime <= new Time()
                {
                    Hours = 14
                })
                {
                    workSchoolProjectStatus = PersonWorkSchoolProjectStatus.PartTimeEvening;
                }
                else
                {
                    workSchoolProjectStatus = PersonWorkSchoolProjectStatus.Other;
                }
            }

            return(workSchoolProjectStatus);
        }
Exemple #2
0
        private static bool GenerateJointOtherEpisodes(this ITashaHousehold household, Random random, GenerationAdjustment[] generationAdjustments)
        {
            var householdPD = household.HomeZone.PlanningDistrict;

            //make sure there at least 2 people and one adult
            if ((household.Persons.Length >= 2) & (household.NumberOfAdults > 0))
            {
                int freqJ            = TimeTable.GetFrequency(household, Activity.JointOther, random, householdPD, 0, generationAdjustments);
                int numEpisodeAdults = Distribution.GetNumAdultsJointEpisode(household, random,
                                                                             Activity.JointOther);

                for (int i = 0; i < freqJ; i++)
                {
                    bool success = false;
                    int  attempt = 0;
                    while (!success && attempt < Scheduler.EpisodeSchedulingAttempts)
                    {
                        if (!TimeTable.GetStartTime(household, Activity.JointOther, freqJ, random, out Time startTime))
                        {
                            attempt++;
                            continue;
                        }
                        if (!TimeTable.GetDuration(household, Activity.JointOther, startTime, random, out Time duration))
                        {
                            attempt++;
                            continue;
                        }

                        if (duration == Time.Zero || startTime == Time.Zero)
                        {
                            attempt++;
                        }
                        else
                        {
                            Time endTime = startTime + duration;
                            List <ITashaPerson> availableAdults = new List <ITashaPerson>();
                            foreach (ITashaPerson person in household.Persons)
                            {
                                Time workSchoolStartTime = SchedulerPerson.GetWorkSchoolStartTime(person);
                                Time workSchoolEndTime   = SchedulerPerson.GetWorkSchoolEndTime(person);
                                bool available           = false;
                                if (workSchoolStartTime > endTime ||
                                    workSchoolEndTime < startTime ||
                                    workSchoolStartTime == Time.Zero)
                                {
                                    available = true;
                                }
                                if (person.Age >= 16 && available)
                                {
                                    availableAdults.Add(person);
                                }
                            }

                            if (availableAdults.Count >= numEpisodeAdults && availableAdults.Count > 0)
                            {
                                Episode jointOtherEpisode;
                                var     owner = availableAdults[0];
                                jointOtherEpisode = new ActivityEpisode(new TimeWindow(startTime, endTime), Activity.JointOther, owner);

                                for (int j = 0; j < numEpisodeAdults; j++)
                                {
                                    jointOtherEpisode.AddPerson(availableAdults[j]);
                                }

                                Project  jointOtherProject  = household.GetJointOtherProject();
                                Schedule jointOtherSchedule = jointOtherProject.Schedule;
                                bool     inserted           = jointOtherSchedule.Insert(jointOtherEpisode, random);
                                success = true;

                                if (!inserted)
                                {
                                    success = false;
                                    attempt++;
                                }
                            }
                            else
                            {
                                attempt++;
                            }
                        }
                    }
                }
            }

            return(true);
        }
Exemple #3
0
        private static bool GenerateJointMarketEpisodes(this ITashaHousehold household, Random random, GenerationAdjustment[] generationAdjustment)
        {
            var householdPD = household.HomeZone.PlanningDistrict;
            // initialize available adults
            var availableAdults = new List <ITashaPerson>(household.Persons.Length);

            // We can only do this with households with more than one person
            if (household.Persons.Length >= 2 && household.NumberOfAdults > 0)
            {
                // Figure out how many times this home is going to go on a joint market trip
                int howManyTimes = TimeTable.GetFrequency(household, Activity.JointMarket, random, householdPD, 0, generationAdjustment);
                // Processes each of those trips
                for (int i = 0; i < howManyTimes; i++)
                {
                    int numEpisodeAdults = Distribution.GetNumAdultsJointEpisode(household, random,
                                                                                 Activity.JointMarket);
                    bool success = false;
                    // continue to try until either we get it to work or we fail to schedule this episode
                    for (int attempt = 0; !success && attempt < Scheduler.EpisodeSchedulingAttempts; attempt++)
                    {
                        if (!TimeTable.GetStartTime(household, Activity.JointMarket, random, out Time startTime))
                        {
                            continue;
                        }
                        if (!TimeTable.GetDuration(household, Activity.JointMarket, startTime, random, out Time duration))
                        {
                            continue;
                        }
                        // Now that we have our start time and duration, compute our end time
                        Time endTime = startTime + duration;
                        if (availableAdults.Count > 0)
                        {
                            availableAdults.Clear();
                        }
                        Time workSchoolStartTime, workSchoolEndTime;
                        bool available;
                        foreach (var person in household.Persons)
                        {
                            workSchoolStartTime = SchedulerPerson.GetWorkSchoolStartTime(person);
                            workSchoolEndTime   = SchedulerPerson.GetWorkSchoolEndTime(person);

                            // this person is available if
                            available = (workSchoolStartTime > endTime) | (workSchoolEndTime < startTime) | (workSchoolStartTime == Time.Zero);

                            if (person.Age >= 16 && available)
                            {
                                availableAdults.Add(person);
                            }
                        }

                        if ((availableAdults.Count > 0) & (availableAdults.Count >= numEpisodeAdults))
                        {
                            Episode jointMarketEpisode;
                            jointMarketEpisode = new ActivityEpisode(new TimeWindow(startTime, endTime), Activity.JointMarket,
                                                                     availableAdults[0]);

                            foreach (ITashaPerson adult in availableAdults)
                            {
                                jointMarketEpisode.AddPerson(adult);
                            }

                            Project  jointMarketProject  = household.GetJointMarketProject();
                            Schedule jointMarketSchedule = jointMarketProject.Schedule;
                            bool     insert = jointMarketSchedule.Insert(jointMarketEpisode, random);

                            success = insert;
                        }
                    }
                }
            }
            return(true);
        }