public bool CheckCompatibility(DormActivities otherActivities, out SortedSet <int> overlapping) { if (!otherActivities.AvailableMultiDormActivitiesToday.Overlaps(AvailableMultiDormActivitiesToday)) { var interDorm = DormPriorities[otherActivities.Dorm]; interDorm.Options = 0; if (!otherActivities.AvailableMultiDormActivities.Overlaps(AvailableMultiDormActivities)) { interDorm.AvailableToday = false; UsedUpOtherDorms.Add(interDorm); DormPriorities.Remove(otherActivities.Dorm); overlapping = null; } else { overlapping = new SortedSet <int>(AvailableMultiDormActivities); overlapping.IntersectWith(otherActivities.AvailableMultiDormActivities); } return(false); } else { overlapping = new SortedSet <int>(AvailableMultiDormActivitiesToday); overlapping.IntersectWith(otherActivities.AvailableMultiDormActivitiesToday); return(true); } }
public void ScheduleActivity(ActivityInfo activity, ScheduledActivity scheduledActivity) { if (!activity.Flags.HasFlag(ActivityFlags.Manual) && (!activity.Flags.HasFlag(ActivityFlags.Exclusive) || !activity.Flags.HasFlag(ActivityFlags.Excess))) { TotalScheduledDuration += activity.Duration; } else { TotalManualDuration += activity.Duration; } bool repeatable = activity.Flags.HasFlag(ActivityFlags.Repeatable); bool multiDorm = activity.Flags.HasFlag(ActivityFlags.MultiDorm); AvailableActivitiesToday.Remove(activity.ID); if (multiDorm) { AvailableMultiDormActivitiesToday.Remove(activity.ID); } bool clear = !repeatable; if (repeatable) { if (!RepeatableHistory.Add(activity.ID)) { clear = true; } else { if (ActivityPriorities.TryGetValue(activity.ID, out int activityPriority)) { if (--activityPriority == 0) { ActivityPriorities.Remove(activity.ID); } } else { ActivityPriorities.Add(activity.ID, -1); } } /*if (!RepeatableTodayHistory.Add(activity.ID)) * throw new IndexOutOfRangeException("Activity repeated twice the same day.");*/ } if (clear) { AvailableActivities.Remove(activity.ID); if (multiDorm) { AvailableMultiDormActivities.Remove(activity.ID); } } ActivitiesDoneToday.Add(activity.ID); if (activity.IncompatibleActivities.Any()) { AvailableActivitiesToday.ExceptWith(activity.IncompatibleActivities); AvailableMultiDormActivitiesToday.ExceptWith(activity.IncompatibleActivities); } ScheduleHistory.Add(scheduledActivity.Abbreviation); if (scheduledActivity.HasOther) { if (scheduledActivity.Dorm == Dorm) { if ( DormPriorities.TryGetValue( scheduledActivity.OtherDorm, out InterDormTracking otherDorm ) && otherDorm.ScheduleActivity( scheduledActivity, !OtherDormsDoneToday.Add(scheduledActivity.OtherDorm), repeatable, multiDorm ) ) { UsedUpOtherDorms.Add((InterDormTracking)otherDorm.Clone()); DormPriorities.Remove(scheduledActivity.OtherDorm); } } } else { DormPriorities[Dorm].ScheduleActivity(scheduledActivity, false, repeatable, multiDorm); OtherDormsDoneToday.Add(Dorm); } }