public static VisitScheduleForSeason BuildSeasonSchedule(long seasonStartTick) { int numVisits = numVisitsRange.RandomInRange; List <VisitItinerary> visitSchedule = new List <VisitItinerary>(); int attempts = 0; while (visitSchedule.Count < numVisits && attempts < 500) { int numVisitors = numVisitorsRange.RandomInRange; int duration = visitDurationRangeTicks.RandomInRange; long start = seasonStartTick + startTickRangeRel.RandomInRange; VisitItinerary newItinerary = new VisitItinerary(numVisitors, start, duration); if (!visitSchedule.Any(i => i.Overlaps(newItinerary, bufferBetweenVisits))) { visitSchedule.Add(newItinerary); } attempts++; } return(new VisitScheduleForSeason(GenDate.SeasonAt(seasonStartTick), visitSchedule)); }
public bool Overlaps(VisitItinerary otherItinerary, int bufferBetweenVisits) { return(this.StartTickAbs <= (otherItinerary.EndTickAbs + bufferBetweenVisits) && (this.EndTickAbs + bufferBetweenVisits) >= otherItinerary.StartTickAbs); }