Example #1
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);
        }
Example #2
0
        private static bool GenerateJointOtherEpisodes(this ITashaHousehold household, Random random)
        {
            //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);

                Time duration, startTime;
                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 startTime))
                        {
                            success = false;
                            attempt++;
                            continue;
                        }
                        if(!TimeTable.GetDuration(household, Activity.JointOther, startTime, random, out duration))
                        {
                            success = false;
                            attempt++;
                            continue;
                        }

                        if(duration == Time.Zero || startTime == Time.Zero)
                        {
                            success = false;
                            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(0,
                                    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
                            {
                                success = false;
                                attempt++;
                            }
                        }
                    }
                }
            }

            return true;
        }
Example #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);
        }
Example #4
0
        private static bool GenerateJointMarketEpisodes(this ITashaHousehold household, Random random)
        {
            // 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);
                // Processes each of those trips
                for(int i = 0; i < howManyTimes; i++)
                {
                    Time startTime, duration;
                    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 startTime))
                        {
                            continue;
                        }
                        if(!TimeTable.GetDuration(household, Activity.JointMarket, startTime, random, out 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 = false;
                        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(0,
                                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;
        }