private void UpdateBestResult(FreeSlot freeSlot) { BestResultForMainSearch bestResult = new BestResultForMainSearch(new List <IDefinedActivity>(freeSlot.tmpActivitiesFirst), Break); if (freeSlot.BestResultFirst.CoverTime < bestResult.CoverTime) { freeSlot.BestResultFirst = bestResult; } }
private void UpdateBestResultAfterDivide(FreeSlot freeSlot, BestResultForMainSearch result) { BestResultForMainSearch newBestResult = new BestResultForMainSearch(new List <IDefinedActivity>(result.ResultList), Break); if (newBestResult.CoverTime > freeSlot.BestResultFirst.CoverTime) { freeSlot.BestResultFirst = newBestResult; } }
private bool FirstRecursion(List <IDefinedActivity> sourceActivities, FreeSlot freeSlot, bool remove = true) { foreach (var activity in sourceActivities) { if (Fit(activity, freeSlot, freeSlot.tmpActivitiesFirst)) { bool isFixed = InsertItem(activity, freeSlot); UpdateBestResult(freeSlot); if (IsFinished(freeSlot)) { return(true); } if (isFixed) { var dividedTimes = DivideFreeSlotsIntoTwoParts(freeSlot, freeSlot.tmpActivitiesFirst); var tmpBestResult = new BestResultForMainSearch(new List <IDefinedActivity>(), Break); tmpBestResult.ResultList.AddRange(freeSlot.tmpActivitiesFirst); foreach (var time in dividedTimes) { List <IDefinedActivity> saved = freeSlot.tmpActivitiesFirst; FirstRecursion(GetRemainingItemsFix(sourceActivities, freeSlot.tmpActivitiesFirst).ToList(), time, true); tmpBestResult.ResultList.AddRange(time.BestResultFirst.ResultList); freeSlot.tmpActivitiesFirst = saved.Concat(time.BestResultFirst.ResultList).ToList(); } UpdateBestResultAfterDivide(freeSlot, tmpBestResult); } else { var saved = freeSlot.tmpActivitiesFirst; if (FirstRecursion(GetRemainingItems(sourceActivities, freeSlot.tmpActivitiesFirst).ToList(), freeSlot, false)) { return(true); } freeSlot.tmpActivitiesFirst = saved; } if (remove) { freeSlot.tmpActivitiesFirst.Clear(); } else { freeSlot.tmpActivitiesFirst.RemoveAt(freeSlot.tmpActivitiesFirst.Count - 1); } } } return(false); }
public FreeSlot(DateTime start, DateTime end, TimeSpan breakValue, bool first = true) { _isFirst = first; Start = start; End = end; Break = breakValue; if (_isFirst) { tmpActivitiesFirst = new List <IDefinedActivity>(); BestResultFirst = new BestResultForMainSearch(new List <IDefinedActivity>(), Break); } else { tmpActivitiesLast = new List <FlexibleActivityItem>(); BestResultLast = new BestResultForSideSearch(new List <FlexibleActivityItem>(), Break); } }