private static bool GenerateIndividualOtherEpisodes(this ITashaHousehold household, Random random, GenerationAdjustment[] generationAdjustments) { int householdPD = household.HomeZone.PlanningDistrict; foreach (var person in household.Persons) { if (!person.Child) { var empZone = person.EmploymentZone; int workPD = empZone == null ? 0 : empZone.PlanningDistrict; int freqO = TimeTable.GetFrequency(person, Activity.IndividualOther, random, householdPD, workPD, generationAdjustments); int outerAttempts = 0; for (int i = 0; i < freqO; i++) { bool success = false; for (int attempt = 0; !success && (attempt < Scheduler.EpisodeSchedulingAttempts); attempt++) { if (!TimeTable.GetStartTime(person, Activity.IndividualOther, freqO, random, out Time startTimeO)) { continue; } if (!TimeTable.GetDuration(person, Activity.IndividualOther, startTimeO, random, out Time durationO)) { continue; } var endTime = startTimeO + durationO; if (endTime > Time.EndOfDay + TashaRuntime.EndOfDay + Time.OneQuantum) { continue; } Episode otherEpisode; otherEpisode = new ActivityEpisode(new TimeWindow(startTimeO, endTime), Activity.IndividualOther, person); Project workProject = person.GetWorkProject(); Schedule workProjSchedule = workProject.Schedule; Project schoolProject = person.GetSchoolProject(); Schedule schoolProjSchedule = schoolProject.Schedule; Time overlap = workProjSchedule.CheckOverlap(otherEpisode) + schoolProjSchedule.CheckOverlap(otherEpisode); float percentOverlap = overlap / durationO; if (percentOverlap < Scheduler.PercentOverlapAllowed || attempt == Scheduler.EpisodeSchedulingAttempts - 1) { Project otherProject = person.GetOtherProject(); Schedule otherSchedule = otherProject.Schedule; if (otherSchedule.Insert(otherEpisode, random)) { //inserted ok success = true; } } } if ((outerAttempts++) < Scheduler.EpisodeSchedulingAttempts && !success) { i = -1; Project otherProject = person.GetOtherProject(); Schedule otherSchedule = otherProject.Schedule; otherSchedule.Clear(); } } } } return(true); }
private static bool GenerateIndividualMarketEpisodes(this ITashaHousehold household, Random random, GenerationAdjustment[] generationAdjustments) { int householdPD = household.HomeZone.PlanningDistrict; foreach (var person in household.Persons) { if (!person.Child) { var empZone = person.EmploymentZone; int workPD = empZone == null ? 0 : empZone.PlanningDistrict; int freqI = TimeTable.GetFrequency(person, Activity.Market, random, householdPD, workPD, generationAdjustments); int outerAttempts = 0; for (int j = 0; j < freqI; ++j) { bool success = false; for (int attempt = 0; attempt < Scheduler.EpisodeSchedulingAttempts && !success; attempt++) { if (!TimeTable.GetStartTime(person, Activity.Market, random, out Time startTime)) { continue; } if (!TimeTable.GetDuration(person, Activity.Market, startTime, random, out Time duration)) { continue; } var endTime = startTime + duration; if (endTime > Time.EndOfDay + TashaRuntime.EndOfDay + Time.OneQuantum) { continue; } //instantiate a temporary individual market episode on the heap space and store pointer in p_marketEpisode var window = new TimeWindow(startTime, startTime + duration); Episode marketEpisode = new ActivityEpisode(window, Activity.Market, person); Project workProject = person.GetWorkProject(); Schedule workProjSchedule = workProject.Schedule; Project schoolProject = person.GetSchoolProject(); Schedule schoolProjSchedule = schoolProject.Schedule; Time overlap = workProjSchedule.CheckOverlap(marketEpisode) + schoolProjSchedule.CheckOverlap(marketEpisode); float percentOverlap = overlap / duration; if (percentOverlap < Scheduler.PercentOverlapAllowed || attempt == Scheduler.EpisodeSchedulingAttempts - 1) { Project marketProject = person.GetMarketProject(); Schedule marketSchedule = marketProject.Schedule; if (marketSchedule.Insert(marketEpisode, random)) { //inserted ok success = true; } } } if ((outerAttempts++) < Scheduler.EpisodeSchedulingAttempts && !success) { j = -1; Project marketProject = person.GetMarketProject(); Schedule marketSchedule = marketProject.Schedule; marketSchedule.Clear(); } } } } return(true); }