private static void ProcessWorkAtHome(ITashaPerson person, Schedule workSchedule, Random random, int householdPD, int workPD, GenerationAdjustment[] generationAdjustments) { int freq_A = TimeTable.GetFrequency(person, Activity.WorkAtHomeBusiness, random, householdPD, workPD, generationAdjustments); Time duration, startTime; for (int i = 0; i < freq_A; i++) { bool success = false; short attempt = 0; while (!success && (attempt < Scheduler.EpisodeSchedulingAttempts)) { if (!TimeTable.GetStartTime(person, Activity.WorkAtHomeBusiness, freq_A, random, out startTime)) { success = false; attempt++; continue; } if (!TimeTable.GetDuration(person, Activity.WorkAtHomeBusiness, startTime, Time.EndOfDay - startTime, random, out duration)) { success = false; attempt++; continue; } Time endTime = startTime + duration; SchedulerHousehold.CheckAndUpdateLatestWorkingTime(person.Household, endTime); Episode wahBusinessEpisode; wahBusinessEpisode = new ActivityEpisode(0, new TimeWindow(startTime, endTime), Activity.WorkAtHomeBusiness, person); if (!workSchedule.Insert(wahBusinessEpisode, random)) { success = false; attempt++; } else { success = true; } } } }
private static bool GenerateWorkEpisodes(this ITashaHousehold household, Random random, GenerationAdjustment[] generationAdjustments) { var householdPD = household.HomeZone.PlanningDistrict; foreach (ITashaPerson person in household.Persons) { // people need to be older than "11" to be allowed to work if (person.Age < Scheduler.MinimumWorkingAge) { continue; } // Check to see if they are in a regular job type case Project workProject = person.GetWorkProject(); Schedule workSchedule = workProject.Schedule; if ((person.Occupation == Occupation.NotEmployed) | (person.Occupation == Occupation.Unknown)) { continue; } if (((person.EmploymentStatus == TTSEmploymentStatus.FullTime) | (person.EmploymentStatus == TTSEmploymentStatus.PartTime))) { var empZone = person.EmploymentZone; int workPD = empZone == null ? 0 : empZone.PlanningDistrict; if (person.EmploymentZone == null) { //continue; throw new XTMFRuntimeException("There was a person whom had no employment zone however was a full-time/part-time worker!"); } //Employment zone doesn't exist so generate our own based on distributions if (person.EmploymentZone.ZoneNumber == TashaRuntime.ZoneSystem.RoamingZoneNumber) { GenerateWorkBusinessEpisode(person, workSchedule, random, householdPD, workPD, generationAdjustments); continue; } int freq = TimeTable.GetFrequency(person, Activity.PrimaryWork, random, householdPD, workPD, generationAdjustments); if (freq <= 0) { continue; } Time startTime = Time.Zero; Time duration = Time.Zero; bool success = false; for (int i = 0; i < freq; i++) { for (int attempts = 0; attempts < Scheduler.EpisodeSchedulingAttempts; attempts++) { // If we use an and here the compiler can't prove that we assign to duration if (!TimeTable.GetStartTime(person, Activity.PrimaryWork, freq, random, out startTime)) { continue; } if (TimeTable.GetDuration(person, Activity.PrimaryWork, startTime, random, out duration)) { // if we got the duration, success lets continue on success = true; break; } } // if we were unable to get a duration if (!success) { // try the next person continue; } Time endTime = startTime + duration; SchedulerHousehold.CheckAndUpdateLatestWorkingTime(person.Household, endTime); Episode primWorkEpisode; primWorkEpisode = new ActivityEpisode(0, new TimeWindow(startTime, endTime), Activity.PrimaryWork, person); primWorkEpisode.Zone = person.EmploymentZone; if (!workSchedule.Insert(primWorkEpisode, random) && i == 0) { throw new XTMFRuntimeException("Failed to insert the primary work episode into the work project!"); } //set up work business activities ProcessWorkBusiness(person, workSchedule, random, primWorkEpisode, householdPD, workPD, generationAdjustments); //set up secondary work activities ProcessSecondaryWork(person, workSchedule, random, primWorkEpisode, householdPD, workPD, generationAdjustments); //set up return home from work activities ProcessReturnHomeFromWork(person, workSchedule, random, primWorkEpisode, householdPD, workPD, generationAdjustments); } } // Check to see if they work from home else if (person.Age >= 19 && ((person.EmploymentStatus == TTSEmploymentStatus.WorkAtHome_FullTime) | (person.EmploymentStatus == TTSEmploymentStatus.WorkAtHome_PartTime))) { ProcessWorkAtHome(person, workSchedule, random, householdPD, householdPD, generationAdjustments); } // If they don't work, just continue on } return(true); }