internal static int GetDistributionID(ITashaHousehold household, Activity activity) { int baseOffset = 0; int childOffset = 0; int adultOffset = 0; int statusOffset = 0; var projectStatus = SchedulerHousehold.GetWorkSchoolProjectStatus(household); if (activity == Activity.JointOther) { baseOffset = 158; } else { baseOffset = 238; } if (household.NumberOfChildren > 0) { childOffset = 0; } else { childOffset = 12; } if (household.NumberOfAdults == 1) { adultOffset = 0; } else if (household.NumberOfAdults == 2) { adultOffset = 1; } else if (household.NumberOfAdults >= 3) { adultOffset = 2; } if (projectStatus == HouseholdWorkSchoolProjectStatus.NoWorkOrSchool) { statusOffset = 0; } else if (projectStatus == HouseholdWorkSchoolProjectStatus.NoEveningWorkOrSchool) { statusOffset = 1; } else if (projectStatus == HouseholdWorkSchoolProjectStatus.EveningWorkOrSchool) { statusOffset = 2; } else { statusOffset = 3; //WorkSchoolProjectStatus.DayAndEveningWorkOrShool } return((baseOffset + childOffset) + (adultOffset * 4) + statusOffset); }
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 void GraphTripPurpose(Distribution.DistributionInformation[] distributionData) { TashaHousehold Household = new TashaHousehold(); TashaPerson person = new TashaPerson(); List <int> primaryWork = new List <int>(); person.Licence = false; person.Male = GenderLocal; SchedulerHousehold.CreateHouseholdProjects(Household); SchedulerPerson.InitializePersonalProjects(person); SchedulerPerson.GenerateWorkSchoolSchedule(person, null); SchedulerTripChain.GetTripChain(person); var trip = SchedulerTrip.GetTrip(0); Occupation[] Occupations = { Occupation.Professional, Occupation.Manufacturing, Occupation.Retail, Occupation.Office, Occupation.Unknown, Occupation.NotEmployed }; LoadDistributioNumbers(person, primaryWork, Occupations); float[] data = new float[this.StartTimeQuantums]; foreach (int ID in primaryWork) { var table = distributionData[ID].StartTimeFrequency; for (int i = 0; i < this.StartTimeQuantums; i++) { for (int j = 0; j < this.MaxFrequencyLocal; j++) { data[i] += table[i][j]; } } } // Make all data in terms of percentages of total. float sum = data.Sum(); for (int number = 0; number < data.Length; number++) { data[number] = data[number] / sum * 100; Writer.WriteLine("{0}, {1}", (Time.FromMinutes((60 * 4) + number * (1440 / this.StartTimeQuantums))), data[number]); } GenerateChart(String.Format("OfficeDur.png"), data, "Time of Day", "Probability"); }
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); }