List<List<string>> generateCombinationForSpecficTimeSpanStringID(int Count, List<mTuple<string, int>> PossibleCalEvents) { int CountCpy = Count; int i = 0; List<List<string>> retValue = new System.Collections.Generic.List<System.Collections.Generic.List<string>>(); if (Count == 0) { return retValue; } for (; i < PossibleCalEvents.Count; i++) { List<mTuple<string, int>> PossibleCalEvents_Param = PossibleCalEvents.ToList(); PossibleCalEvents_Param[i] = new mTuple<string, int>(PossibleCalEvents_Param[i].Item1, PossibleCalEvents_Param[i].Item2); mTuple<string, int> refSubCalEventUmbrella = PossibleCalEvents_Param[i]; //refSubCalEventUmbrella = if (refSubCalEventUmbrella.Item2 > 0) { --refSubCalEventUmbrella.Item2; List<List<string>> receivedCombination = generateCombinationForSpecficTimeSpanStringID(CountCpy - 1, PossibleCalEvents_Param); foreach (List<string> eachList in receivedCombination) { eachList.Add(refSubCalEventUmbrella.Item1); } if (receivedCombination.Count < 1) { receivedCombination.Add(new System.Collections.Generic.List<string>() { refSubCalEventUmbrella.Item1 }); } retValue.AddRange(receivedCombination); } PossibleCalEvents.RemoveAt(i); --i; } return retValue; }
List<List<SubCalendarEvent>> SpreadOutEvents(List<List<SubCalendarEvent>> AlreadyAlignedEvents, Double AverageOccupiedSchedule, List<TimeLine> AllFreeSpots, Dictionary<TimeLine, Dictionary<TimeSpan, Dictionary<string, mTuple<bool, SubCalendarEvent>>>> AllPossibleEvents, List<List<SubCalendarEvent>> RestrictedElements) { //Function takes a List Of TimeLines that have been compressed towards the left of a timeLine and Attempts to spread them out List<List<SubCalendarEvent>> retValue = new List<List<SubCalendarEvent>>(); Dictionary<TimeLine, List<mTuple<double, SubCalendarEvent>>> MovableElements_Dict = new Dictionary<TimeLine, List<mTuple<double, SubCalendarEvent>>>(); List<mTuple<double, SubCalendarEvent>> TotalMovableList = new List<mTuple<double, SubCalendarEvent>>(); Dictionary<SubCalendarEvent, Tuple<int, TimeLine>> SubCalEventCurrentlyAssignedTImeLine = new Dictionary<SubCalendarEvent, Tuple<int, TimeLine>>(); Dictionary<TimeLine, mTuple<TimeSpan, TimeSpan>> TImeLine_ToAverageTimeSpan = new Dictionary<TimeLine, mTuple<TimeSpan, TimeSpan>>();//holds the current timeline to mtuple of ideal average timespan and current total active timespan Dictionary<TimeLine, mTuple<int, double>> TimeLineOccupancy = new Dictionary<TimeLine, mTuple<int, double>>(); int j = 0; List<mTuple<TimeLine, int>> LessThanAverage = new List<mTuple<TimeLine, int>>(); List<mTuple<TimeLine, int>> AboveAverage = new List<mTuple<TimeLine, int>>(); Dictionary<SubCalendarEvent, List<mTuple<TimeLine, int>>> TimeLineAndPossibleCalendarEvents = new Dictionary<SubCalendarEvent, List<mTuple<TimeLine, int>>>(); foreach (TimeLine eachTimeLine in AllFreeSpots) { TimeSpan TotalActiveSpan = Utility.SumOfActiveDuration(AlreadyAlignedEvents[j]); TimeSpan AverageTimeSpan = new TimeSpan((long)(AverageOccupiedSchedule * (double)eachTimeLine.TimelineSpan.Ticks)); TImeLine_ToAverageTimeSpan.Add(eachTimeLine, new mTuple<TimeSpan, TimeSpan>(AverageTimeSpan, TotalActiveSpan)); double Occupancy = (double)TotalActiveSpan.Ticks / (double)eachTimeLine.TimelineSpan.Ticks;// percentage of active duration relative to the size of the TimeLine Timespan TimeLineOccupancy.Add(eachTimeLine, new mTuple<int, double>(j - 1, Occupancy)); if (Occupancy > AverageOccupiedSchedule) { AboveAverage.Add(new mTuple<TimeLine, int>(eachTimeLine, j)); List<SubCalendarEvent> AlreadyAssigned = AlreadyAlignedEvents[j]; List<SubCalendarEvent> RestrictedSubCalevent = RestrictedElements[j]; List<SubCalendarEvent> MovableElements = AlreadyAssigned.ToList(); MovableElements = MovableElements.Where(obj => (!RestrictedSubCalevent.Contains(obj))).ToList(); IEnumerable<KeyValuePair<SubCalendarEvent, Tuple<int, TimeLine>>> ListOFeachKeyValuePair = MovableElements.Select(obj => new KeyValuePair<SubCalendarEvent, Tuple<int, TimeLine>>(obj, new Tuple<int, TimeLine>(j, AllFreeSpots[j]))); foreach (KeyValuePair<SubCalendarEvent, Tuple<int, TimeLine>> eachKeyValuePair in ListOFeachKeyValuePair) { SubCalEventCurrentlyAssignedTImeLine.Add(eachKeyValuePair.Key, eachKeyValuePair.Value); } List<mTuple<double, SubCalendarEvent>> MovableForDict = MovableElements.Select(obj => new mTuple<double, SubCalendarEvent>(DistanceSolver.AverageToAllNodes(obj.myLocation, MovableElements.Where(obj1 => obj1 != obj).ToList().Select(obj2 => obj2.myLocation).ToList()), obj)).ToList(); MovableForDict.Sort(delegate(mTuple<double, SubCalendarEvent> A, mTuple<double, SubCalendarEvent> B) { return A.Item1.CompareTo(B.Item1); /*if(A.Item1==B.Item1) return 0; else{ A.Item1.CompareTo(A.Item1) }*/ }); TotalMovableList.AddRange(MovableForDict); MovableElements_Dict.Add(AllFreeSpots[j], MovableForDict); } else { if (Occupancy < AverageOccupiedSchedule) { double ExcessPercentageSpace = AverageOccupiedSchedule - Occupancy; mTuple<TimeLine, int> LessThanAverageEntry = new mTuple<TimeLine, int>(eachTimeLine, j); LessThanAverage.Add(LessThanAverageEntry); IEnumerable<KeyValuePair<TimeSpan, Dictionary<string, mTuple<bool, SubCalendarEvent>>>> DictOfPosSubCals0 = AllPossibleEvents[eachTimeLine].Select(obj => obj); IEnumerable<Dictionary<string, mTuple<bool, SubCalendarEvent>>> DictOfPosSubCals1 = DictOfPosSubCals0.Select(obj => obj.Value); //List<List<KeyValuePair<string, mTuple<bool, SubCalendarEvent>>>> DictOfPosSubCals0List = AllPossibleEvents[eachTimeLine].Select(obj => obj.Value).ToList(); //IEnumerable<KeyValuePair<string, mTuple<bool, SubCalendarEvent>>> DictOfPosSubCals = AllPossibleEvents[eachTimeLine].SelectMany(obj=>obj.Value); IEnumerable<SubCalendarEvent> DictOfPosSubCals = AllPossibleEvents[eachTimeLine].SelectMany(obj => obj.Value).Select(obj => obj.Value.Item2); TimeSpan SpaceTogetAverage = new TimeSpan((long)(ExcessPercentageSpace * (double)eachTimeLine.TimelineSpan.Ticks)); List<mTuple<double, SubCalendarEvent>> CompatibleWithTimeLine = PopulateCompatibleList(TotalMovableList, DictOfPosSubCals.ToList(), eachTimeLine, SpaceTogetAverage); CompatibleWithTimeLine.AddRange(Utility.SubCalEventsTomTuple(AlreadyAlignedEvents[j], (double)100)); foreach (SubCalendarEvent eeachSubCalendarEvent in CompatibleWithTimeLine.Select(obj=>obj.Item2)) { if (TimeLineAndPossibleCalendarEvents.ContainsKey(eeachSubCalendarEvent)) { TimeLineAndPossibleCalendarEvents[eeachSubCalendarEvent].Add(LessThanAverageEntry); } else { TimeLineAndPossibleCalendarEvents.Add(eeachSubCalendarEvent, new List<mTuple<TimeLine, int>> { (LessThanAverageEntry) }); } } } } j++; } Dictionary<TimeLine, List<SubCalendarEvent>> OptimumAssignment = AllFreeSpots.ToDictionary(obj => obj, obj=>new List<SubCalendarEvent>()); foreach (KeyValuePair<SubCalendarEvent, List<mTuple<TimeLine, int>>> eachKeyValuePair in TimeLineAndPossibleCalendarEvents) { //find best spots for int OptimumLocation = GetBestNodeToInsertSelf(AlreadyAlignedEvents, eachKeyValuePair.Key, eachKeyValuePair.Value, CalendarEvent.DistanceMatrix, OptimumAssignment); mTuple<TimeLine,int> OptimumIndex= eachKeyValuePair.Value[OptimumLocation]; OptimumAssignment[OptimumIndex.Item1].Add(eachKeyValuePair.Key); } foreach (TimeLine eachTimeLine in LessThanAverage.Select(obj => obj.Item1)) { j=AllFreeSpots.IndexOf(eachTimeLine); TimeSpan TotalActiveSpan = Utility.SumOfActiveDuration(AlreadyAlignedEvents[j]); TimeSpan AverageTimeSpan = new TimeSpan((long)(AverageOccupiedSchedule * (double)eachTimeLine.TimelineSpan.Ticks)); //TImeLine_ToAverageTimeSpan.Add(eachTimeLine, new mTuple<TimeSpan, TimeSpan>(AverageTimeSpan, TotalActiveSpan)); double Occupancy = (double)TotalActiveSpan.Ticks / (double)eachTimeLine.TimelineSpan.Ticks;// percentage of active duration relative to the size of the TimeLine Timespan Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>> CompatibleWithListForFunCall = new Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>(); Dictionary<SubCalendarEvent, BusyTimeLine> SubCalendarEvent_OldTImeLine = new Dictionary<SubCalendarEvent, BusyTimeLine>();//Dictionary stores the Subcalendar event old TimeLine, just incase the do not get reassigned to the current timeline Dictionary<TimeSpan, Dictionary<string, mTuple<bool, SubCalendarEvent>>> PossibleEventsForFuncCall = new Dictionary<TimeSpan, Dictionary<string, mTuple<bool, SubCalendarEvent>>>(); List<mTuple<bool, SubCalendarEvent>> restrictedForFuncCall = Utility.SubCalEventsTomTuple(AlreadyAlignedEvents[j], true); foreach (SubCalendarEvent eachmTuple in OptimumAssignment[eachTimeLine]) { TimeSpan ActiveTimeSpan = eachmTuple.ActiveDuration; string subcalStringID = eachmTuple.ID; SubCalendarEvent_OldTImeLine.Add(eachmTuple, eachmTuple.ActiveSlot.CreateCopy()); if (CompatibleWithListForFunCall.ContainsKey(ActiveTimeSpan)) { ++CompatibleWithListForFunCall[ActiveTimeSpan].Item1; ; } else { CompatibleWithListForFunCall.Add(ActiveTimeSpan, new mTuple<int, TimeSpanWithStringID>(1, new TimeSpanWithStringID(eachmTuple.ActiveDuration, ActiveTimeSpan.Ticks.ToString()))); } if (PossibleEventsForFuncCall.ContainsKey(ActiveTimeSpan)) { PossibleEventsForFuncCall[ActiveTimeSpan].Add(subcalStringID, new mTuple<bool, SubCalendarEvent>(true, eachmTuple)); } else { PossibleEventsForFuncCall.Add(ActiveTimeSpan, new Dictionary<string, mTuple<bool, SubCalendarEvent>>()); PossibleEventsForFuncCall[ActiveTimeSpan].Add(subcalStringID, new mTuple<bool, SubCalendarEvent>(true, eachmTuple)); } } List<mTuple<bool, SubCalendarEvent>> UpdatedListForTimeLine = stitchUnRestrictedSubCalendarEvent(eachTimeLine, restrictedForFuncCall, PossibleEventsForFuncCall, CompatibleWithListForFunCall, Occupancy);//attempts to add new events into to the timelines with lesser occupancy than average TimeSpan OccupiedSpace = Utility.SumOfActiveDuration(UpdatedListForTimeLine.Select(obj => obj.Item2).ToList());//checks for how much space is used up TimeSpan ExcessSpace = OccupiedSpace - AverageTimeSpan;//checks how much excees if (ExcessSpace.Ticks > 0)//tries to trim the UpdatedListForTimeLine. This is done by removing an element in the updated list until its detected that the origin timeline is below or equal to its average { IEnumerable<SubCalendarEvent> NewlyAddedElements = (UpdatedListForTimeLine.Where(obj => !AlreadyAlignedEvents[j].Contains(obj.Item2))).Select(obj => obj.Item2);//retrieves the newly added elements List<mTuple<double, SubCalendarEvent>> NewlyAddedElementsWithCost = NewlyAddedElements.Select(obj => new mTuple<double, SubCalendarEvent>(DistanceSolver.AverageToAllNodes(obj.myLocation, UpdatedListForTimeLine.Select(obj3 => obj3.Item2).Where(obj1 => obj1 != obj).ToList().Select(obj2 => obj2.myLocation).ToList()), obj)).ToList();//creates mtuple of cost and subcal events Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>> CompatibilityListFOrTIghtestForExtraAverga = new Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>(); Dictionary<TimeSpan, List<mTuple<double, SubCalendarEvent>>> CompatibilityListForNewlyAddedElements = new Dictionary<TimeSpan, List<mTuple<double, SubCalendarEvent>>>(); foreach (mTuple<double, SubCalendarEvent> eachmTUple in NewlyAddedElementsWithCost) { if (CompatibilityListForNewlyAddedElements.ContainsKey(eachmTUple.Item2.ActiveDuration)) { CompatibilityListForNewlyAddedElements[eachmTUple.Item2.ActiveDuration].Add(eachmTUple); //CompatibilityListForNewlyAddedElements[eachmTUple.Item2.ActiveDuration] = Utility.RandomizeIEnumerable(CompatibilityListForNewlyAddedElements[eachmTUple.Item2.ActiveDuration]); CompatibilityListForNewlyAddedElements[eachmTUple.Item2.ActiveDuration].Sort(delegate(mTuple<double, SubCalendarEvent> A, mTuple<double, SubCalendarEvent> B) { return A.Item1.CompareTo(B.Item1); }); } else { CompatibilityListForNewlyAddedElements.Add(eachmTUple.Item2.ActiveDuration, new List<mTuple<double, SubCalendarEvent>>() { eachmTUple }); } if (CompatibilityListFOrTIghtestForExtraAverga.ContainsKey(eachmTUple.Item2.ActiveDuration)) { ++CompatibilityListFOrTIghtestForExtraAverga[eachmTUple.Item2.ActiveDuration].Item1; } else { CompatibilityListFOrTIghtestForExtraAverga.Add(eachmTUple.Item2.ActiveDuration, new mTuple<int, TimeSpanWithStringID>(1, new TimeSpanWithStringID(eachmTUple.Item2.ActiveDuration, eachmTUple.Item2.ActiveDuration.Ticks.ToString()))); } } TimeSpan Space_NonAverage = TimeSpan.FromTicks((long)((1 - AverageOccupiedSchedule) * eachTimeLine.TimelineSpan.Ticks));//Space derive from subtracting the calculated expected average timespan for this time line from thie timeline //ExcessSpace = Space_NonAverage; SnugArray CompatibilityToBestAverageFit = new SnugArray(CompatibilityListFOrTIghtestForExtraAverga.Values.ToList(), ExcessSpace); List<Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>> AllPossibleTIghtExcessFits = CompatibilityToBestAverageFit.MySnugPossibleEntries; AllPossibleTIghtExcessFits = SnugArray.SortListSnugPossibilities_basedOnTimeSpan(AllPossibleTIghtExcessFits); Dictionary<int, List<Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>>>> tightestElements = SnugArray.SortListSnugPossibilities_basedOnNumberOfDiffering(AllPossibleTIghtExcessFits); if (tightestElements.Count > 0) { AllPossibleTIghtExcessFits = tightestElements.OrderBy(obj => obj.Key).Last().Value; } //SnugArray.SortListSnugPossibilities_basedOnTimeSpan(AllPossibleTIghtExcessFits); List<mTuple<double, SubCalendarEvent>> removedElements = new List<mTuple<double, SubCalendarEvent>>();//stores element that dont get reassigned to this current timeLine if (AllPossibleTIghtExcessFits.Count > 0) { Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>> TIghtestFit = AllPossibleTIghtExcessFits[AllPossibleTIghtExcessFits.Count - 1]; foreach (KeyValuePair<TimeSpan, mTuple<int, TimeSpanWithStringID>> eachKeyValuePair in TIghtestFit)//Hack alert: Assumes tightest fit is most diverse { while (eachKeyValuePair.Value.Item1 > 0) { removedElements.Add(CompatibilityListForNewlyAddedElements[eachKeyValuePair.Value.Item2.timeSpan][CompatibilityListForNewlyAddedElements[eachKeyValuePair.Value.Item2.timeSpan].Count - 1]); CompatibilityListForNewlyAddedElements[eachKeyValuePair.Value.Item2.timeSpan].RemoveAt(CompatibilityListForNewlyAddedElements[eachKeyValuePair.Value.Item2.timeSpan].Count - 1); --eachKeyValuePair.Value.Item1; } } } NewlyAddedElements = CompatibilityListForNewlyAddedElements.SelectMany(obj => obj.Value).Select(obj => obj.Item2); UpdatedListForTimeLine.RemoveAll(obj => removedElements.Select(obj1 => obj1.Item2).Contains(obj.Item2));//use LINQ to remove elements currently in "removedElements" List<SubCalendarEvent> ListOfNewlyAddeedElements = NewlyAddedElements.ToList(); TimeSpan AllSumTImeSpan = Utility.SumOfActiveDuration(ListOfNewlyAddeedElements); removedElements.ForEach(obj => obj.Item2.shiftEvent(SubCalendarEvent_OldTImeLine[obj.Item2].Start - obj.Item2.ActiveSlot.Start)); Dictionary<int, List<List<SubCalendarEvent>>> CurrentlyAssignedSubCalevents = new Dictionary<int, List<List<SubCalendarEvent>>>();//stores the index of each subcalendarevent timeline and its fellow Subcal events. Key= Index Of Current timeline. OuteList is grouping for each calendar event. Inner List is each Subcalevent within Calevent //ListOfNewlyAddeedElements = Utility.RandomizeIEnumerable(ListOfNewlyAddeedElements); for (int i = 0; i < ListOfNewlyAddeedElements.Count; i++)//removes Each reassigned element from its currently attached field { SubCalendarEvent eachSubCalendarEvent = ListOfNewlyAddeedElements[i]; Tuple<int, TimeLine> CurrentMatchingField = SubCalEventCurrentlyAssignedTImeLine[eachSubCalendarEvent]; mTuple<TimeSpan, TimeSpan> AverageTimeSpanAndTotalTimeSpan = TImeLine_ToAverageTimeSpan[CurrentMatchingField.Item2]; if (((AverageTimeSpanAndTotalTimeSpan.Item2 - eachSubCalendarEvent.ActiveDuration) >= AverageTimeSpanAndTotalTimeSpan.Item1)) { AverageTimeSpanAndTotalTimeSpan.Item2 -= eachSubCalendarEvent.ActiveDuration; AlreadyAlignedEvents[CurrentMatchingField.Item1].Remove(eachSubCalendarEvent); SubCalEventCurrentlyAssignedTImeLine[eachSubCalendarEvent] = new Tuple<int, TimeLine>(j, AllFreeSpots[j]); Dictionary<TimeLine, Dictionary<string, Dictionary<string, mTuple<bool, SubCalendarEvent>>>> AllPossibleEvents222222; TotalMovableList.RemoveAll(obj => NewlyAddedElements.Contains(obj.Item2));//removes the newly added element from Total possible movable elements AllPossibleEvents[AllFreeSpots[j]][eachSubCalendarEvent.ActiveDuration].Remove(eachSubCalendarEvent.ID); if (AllPossibleEvents[AllFreeSpots[j]][eachSubCalendarEvent.ActiveDuration].Count < 1) { AllPossibleEvents[AllFreeSpots[j]].Remove(eachSubCalendarEvent.ActiveDuration); } } else { ListOfNewlyAddeedElements.Remove(eachSubCalendarEvent); eachSubCalendarEvent.shiftEvent(SubCalendarEvent_OldTImeLine[eachSubCalendarEvent].Start - eachSubCalendarEvent.ActiveSlot.Start); --i; } } NewlyAddedElements = ListOfNewlyAddeedElements; AlreadyAlignedEvents[j].AddRange(NewlyAddedElements); TotalActiveSpan = Utility.SumOfActiveDuration(AlreadyAlignedEvents[j]); AverageTimeSpan = new TimeSpan((long)(AverageOccupiedSchedule * (double)eachTimeLine.TimelineSpan.Ticks)); Occupancy = (double)TotalActiveSpan.Ticks / (double)eachTimeLine.TimelineSpan.Ticks;// percentage of active duration relative to the size of the TimeLine Timespan } } Dictionary<TimeLine, List<SubCalendarEvent>> CompatibleList = new Dictionary<TimeLine, List<SubCalendarEvent>>();//this Dictionary stores keyValuepair of a TimeLine and Subcalevents that can work within said timeLine that are not part of the currently assigned set; retValue = AlreadyAlignedEvents.ToList(); return retValue; }
List<List<SubCalendarEvent>> generateCombinationForDifferentEntries(Dictionary<TimeSpan, mTuple<int, TimeSpanWithStringID>> CompatibleWithList, Dictionary<TimeSpan, Dictionary<string, mTuple<bool, SubCalendarEvent>>> PossibleEntries) { /* * Function attempts to generate multiple combinations of compatible sub calendar event for Snug fit entry * CompatibleWithList is an snug fit result * PossibleEntries are the possible sub calendar that can be used in the combinatorial result */ ++CountCall; if (CountCall == 4) { ; } List<List<List<string>>> MAtrixedSet = new System.Collections.Generic.List<System.Collections.Generic.List<System.Collections.Generic.List<string>>>(); Dictionary<string, mTuple<int, List<SubCalendarEvent>>> var4 = new System.Collections.Generic.Dictionary<string, mTuple<int, System.Collections.Generic.List<SubCalendarEvent>>>(); List<List<SubCalendarEvent>> retValue = new System.Collections.Generic.List<System.Collections.Generic.List<SubCalendarEvent>>(); foreach (KeyValuePair<TimeSpan, mTuple<int, TimeSpanWithStringID>> eachKeyValuePair0 in CompatibleWithList)//loops every timespan in Snug FIt possibility { TimeSpan eachTimeSpan = eachKeyValuePair0.Key; Dictionary<string, mTuple<bool, SubCalendarEvent>> var1 = PossibleEntries[eachTimeSpan]; List<List<string>> receivedValue = new System.Collections.Generic.List<System.Collections.Generic.List<string>>(); Dictionary<string, int> var2 = new System.Collections.Generic.Dictionary<string, int>(); foreach (KeyValuePair<string, mTuple<bool, SubCalendarEvent>> eachKeyValuePair in var1) { string ParentID = eachKeyValuePair.Value.Item2.SubEvent_ID.getStringIDAtLevel(0); if (var2.ContainsKey(ParentID)) { ++var2[ParentID]; var4[ParentID].Item2.Add(eachKeyValuePair.Value.Item2); } else { var2.Add(ParentID, 1); List<SubCalendarEvent> var5 = new System.Collections.Generic.List<SubCalendarEvent>(); var5.Add(eachKeyValuePair.Value.Item2); var4.Add(ParentID, new mTuple<int, System.Collections.Generic.List<SubCalendarEvent>>(0, var5)); } } List<mTuple<string, int>> PossibleCalEvents = new System.Collections.Generic.List<mTuple<string, int>>(); foreach (KeyValuePair<string, int> eachKeyValuePair in var2) { PossibleCalEvents.Add(new mTuple<string, int>(eachKeyValuePair.Key, eachKeyValuePair.Value)); } List<List<string>> var3 = generateCombinationForSpecficTimeSpanStringID(eachKeyValuePair0.Value.Item1, PossibleCalEvents); MAtrixedSet.Add(var3); } List<List<string>> serializedList = Utility.SerializeList(MAtrixedSet); foreach (List<string> eachList in serializedList)//serializedList has a list of fittable ParentIDs, the loop replaces each List of strings with List of subCalendarEvents { List<SubCalendarEvent> var6 = new System.Collections.Generic.List<SubCalendarEvent>(); mTuple<int, List<SubCalendarEvent>> var7 = new mTuple<int, System.Collections.Generic.List<SubCalendarEvent>>(0, new System.Collections.Generic.List<SubCalendarEvent>()); foreach (string eachString in eachList) { var7 = var4[eachString]; var6.Add(var7.Item2[var7.Item1++]); } foreach (KeyValuePair<string, mTuple<int, List<SubCalendarEvent>>> eachKeyValuePair in var4) { eachKeyValuePair.Value.Item1 = 0; } //var7.Item1 = 0; retValue.Add(var6); } return retValue; }
List<SubCalendarEvent> resolveInTo24HourSlots(List<SubCalendarEvent> currentListOfSubCalendarElements, TimeLine limitingTimeLine, mTuple<SubCalendarEvent,SubCalendarEvent>edgeElements=null) { //function takes a full freespot and tries to spread it out into 24 hour sections //this is done by intially sending every subcalevenet towards the end of the Timeline after which it takes 24hour chunks and attempts to List<SubCalendarEvent> currentListOfSubCalendarElements_cpy = currentListOfSubCalendarElements.ToList(); Utility.PinSubEventsToStart(currentListOfSubCalendarElements_cpy, limitingTimeLine); TimeLine limitingTimeLine_cpy = limitingTimeLine.CreateCopy(); limitingTimeLine.AddBusySlots(currentListOfSubCalendarElements_cpy.Select(obj => obj.ActiveSlot)); List<TimeLineWithEdgeElements> AllFreeSpots = limitingTimeLine_cpy.getAllFreeSlotsWithEdges().ToList(); AllFreeSpots=AllFreeSpots.Where(obj => obj.TimelineSpan.Ticks > 0).OrderBy(obj=>obj.End).ToList(); for (int i = AllFreeSpots.Count() - 1; AllFreeSpots.Count() > 0; ) { TimeLine eachTimeLine = AllFreeSpots[i]; List<SubCalendarEvent> reassignedElements = TossEndWards(currentListOfSubCalendarElements, eachTimeLine);//tries to toss any subcalendarevent towards the end reassignedElements=reassignedElements.OrderBy(obj => obj.End).ToList(); Utility.PinSubEventsToEnd(reassignedElements, eachTimeLine); SubCalendarEvent lastElement;// = reassignedElements.Last(); currentListOfSubCalendarElements.RemoveAll(obj => reassignedElements.Contains(obj)); if (reassignedElements.Count > 0) { lastElement = reassignedElements.First(); limitingTimeLine = new TimeLine(limitingTimeLine.Start, lastElement.Start); } else { currentListOfSubCalendarElements.OrderBy(obj => obj.End); if (currentListOfSubCalendarElements.Count > 0)//hack alert you need to coscious of coliision scenario { lastElement = currentListOfSubCalendarElements.Last(); lastElement.PinToEnd(limitingTimeLine); currentListOfSubCalendarElements.Remove(lastElement); limitingTimeLine = new TimeLine(limitingTimeLine.Start, lastElement.Start); } else { break; } } Utility.PinSubEventsToStart(currentListOfSubCalendarElements, limitingTimeLine); limitingTimeLine.AddBusySlots(currentListOfSubCalendarElements.Select(obj => obj.ActiveSlot)); AllFreeSpots = limitingTimeLine.getAllFreeSlotsWithEdges().ToList(); i = AllFreeSpots.Count() - 1; } TimeSpan TotalDuration = Utility.SumOfActiveDuration(currentListOfSubCalendarElements_cpy); double Occupancy = (double)TotalDuration.Ticks / (double)limitingTimeLine_cpy.TimelineSpan.Ticks; List<SubCalendarEvent> currentListOfSubCalendarElements_cpy_ref = currentListOfSubCalendarElements_cpy.ToList(); Dictionary<string, mTuple<SubCalendarEvent, BusyTimeLine>> currentListOfSubCalendarElements_cpy_ref_Dict = currentListOfSubCalendarElements_cpy_ref.ToDictionary(obj => obj.ID, obj => new mTuple<SubCalendarEvent, BusyTimeLine>(obj, obj.ActiveSlot.CreateCopy())); TimeLine limitingTimeLine_cpy_cpy_ref = limitingTimeLine_cpy.CreateCopy(); List<SubCalendarEvent> FullyUpdated = new List<SubCalendarEvent>(); while(true) { Tuple<List<SubCalendarEvent>, TimeLine> CollectionUpdated = every24Interval(currentListOfSubCalendarElements_cpy_ref, limitingTimeLine_cpy_cpy_ref, Occupancy, currentListOfSubCalendarElements_cpy_ref_Dict); TimeSpan currTotalDuration = Utility.SumOfActiveDuration(CollectionUpdated.Item1); double currOccupancy =-8898; if(CollectionUpdated.Item2.TimelineSpan.Ticks>0) { currOccupancy = (double)currTotalDuration.Ticks / (double)CollectionUpdated.Item2.TimelineSpan.Ticks; } if (currOccupancy > Occupancy) { ; } FullyUpdated.AddRange(CollectionUpdated.Item1); limitingTimeLine_cpy_cpy_ref = new TimeLine(CollectionUpdated.Item2.End, limitingTimeLine_cpy_cpy_ref.End); currentListOfSubCalendarElements_cpy_ref.RemoveAll(obj => FullyUpdated.Contains(obj)); if ((currentListOfSubCalendarElements_cpy_ref.Count < 1) || (limitingTimeLine_cpy_cpy_ref.TimelineSpan.Ticks <= 0)) { break; } } currentListOfSubCalendarElements_cpy = currentListOfSubCalendarElements_cpy.OrderBy(obj => obj.End).ToList(); List<SubCalendarEvent> retValue = currentListOfSubCalendarElements_cpy; return retValue; }