Esempio n. 1
0
        private SubCalendarEvent[] getInterferringSubEvents(TimeLine EventRange, List<CalendarEvent> NonCommitedCalendarEvemts=null)
        {

            //CalendarEvent MyCalendarEvent
            List<SubCalendarEvent> MyArrayOfInterferringSubCalendarEvents = new List<SubCalendarEvent>(0);//List that stores the InterFerring List
            int i = 0;
            int lengthOfCalendarSubEvent = 0;
            foreach (KeyValuePair<string, CalendarEvent> MyCalendarEventDictionaryEntry in AllEventDictionary)
            {
                i = 0;
                if (MyCalendarEventDictionaryEntry.Value.RepetitionStatus)
                {
                    lengthOfCalendarSubEvent = MyCalendarEventDictionaryEntry.Value.AllRepeatSubCalendarEvents.Length;
                    SubCalendarEvent[] ArrayOfSubcalendarEventsFromRepeatingEvents = MyCalendarEventDictionaryEntry.Value.AllRepeatSubCalendarEvents;


                    for (i = 0; i < lengthOfCalendarSubEvent; i++)
                    {
                        //if ((EventRange.IsDateTimeWithin(ArrayOfSubcalendarEventsFromRepeatingEvents[i].Start)) || (EventRange.IsDateTimeWithin(ArrayOfSubcalendarEventsFromRepeatingEvents[i].End)))
                        if (EventRange.InterferringTimeLine(ArrayOfSubcalendarEventsFromRepeatingEvents[i].RangeTimeLine) != null)
                        {
                            MyArrayOfInterferringSubCalendarEvents.Add(ArrayOfSubcalendarEventsFromRepeatingEvents[i]);
                        }
                    }
                }
                else
                {
                    lengthOfCalendarSubEvent = MyCalendarEventDictionaryEntry.Value.AllEvents.Length;

                    for (i = 0; i < lengthOfCalendarSubEvent; i++)
                    {

                        //if ((EventRange.IsDateTimeWithin(MyCalendarEventDictionaryEntry.Value.AllEvents[i].Start)) || (EventRange.IsDateTimeWithin(MyCalendarEventDictionaryEntry.Value.AllEvents[i].End)))

                            if (EventRange.InterferringTimeLine(MyCalendarEventDictionaryEntry.Value.AllEvents[i].RangeTimeLine) != null)
                        {
                            MyArrayOfInterferringSubCalendarEvents.Add(MyCalendarEventDictionaryEntry.Value.AllEvents[i]);
                        }
                    }
                }
            }

            if (NonCommitedCalendarEvemts != null)
            {
                foreach ( CalendarEvent eachCalendarEvent in NonCommitedCalendarEvemts)
                {
                    i = 0;
                    if (eachCalendarEvent.RepetitionStatus)
                    {
                        lengthOfCalendarSubEvent = eachCalendarEvent.AllRepeatSubCalendarEvents.Length;
                        SubCalendarEvent[] ArrayOfSubcalendarEventsFromRepeatingEvents = eachCalendarEvent.AllRepeatSubCalendarEvents;


                        for (i = 0; i < lengthOfCalendarSubEvent; i++)
                        {
                            //if ((EventRange.IsDateTimeWithin(ArrayOfSubcalendarEventsFromRepeatingEvents[i].Start)) || (EventRange.IsDateTimeWithin(ArrayOfSubcalendarEventsFromRepeatingEvents[i].End)))
                            if (EventRange.InterferringTimeLine(ArrayOfSubcalendarEventsFromRepeatingEvents[i].RangeTimeLine) != null)
                            {
                                MyArrayOfInterferringSubCalendarEvents.Add(ArrayOfSubcalendarEventsFromRepeatingEvents[i]);
                            }
                        }
                    }
                    else
                    {
                        lengthOfCalendarSubEvent = eachCalendarEvent.AllEvents.Length;
                        for (i = 0; i < lengthOfCalendarSubEvent; i++)
                        {

                            //if ((EventRange.IsDateTimeWithin(MyCalendarEventDictionaryEntry.Value.AllEvents[i].Start)) || (EventRange.IsDateTimeWithin(MyCalendarEventDictionaryEntry.Value.AllEvents[i].End)))

                            if (EventRange.InterferringTimeLine(eachCalendarEvent.AllEvents[i].RangeTimeLine) != null)
                            {
                                MyArrayOfInterferringSubCalendarEvents.Add(eachCalendarEvent.AllEvents[i]);
                            }
                        }
                    }
                }
            }

            return MyArrayOfInterferringSubCalendarEvents.ToArray();
        }
Esempio n. 2
0
        List<mTuple<bool, SubCalendarEvent>> stitchRestrictedSubCalendarEvent(List<mTuple<bool, SubCalendarEvent>> Arg1, TimeLine RestrictingTimeLine)
        {
            /*
             * Description: function tries to stitich Restricted SubCalEvents. It starts with the most restricted within timeline as the first node. This first node pins itself to the right It stitches the tree towards the right of the node. Makes a recursive call to stitchRestrictedSubCalendarEvent. pin the returned List and itself to the right hand side then tries to stitck the left hand side
             */
            List<mTuple<bool, SubCalendarEvent>> retValue = Arg1.ToList();

            TimeSpan SumOfAllSubCalEvent = Utility.SumOfActiveDuration(Utility.mTupleToSubCalEvents(Arg1));
            if (RestrictingTimeLine.TimelineSpan <= SumOfAllSubCalEvent)
            {
                ;
            }

            List<mTuple<bool, SubCalendarEvent>> CopyOfAllList = Arg1.ToList();


            if (retValue.Count < 1)//if arg1 is empty return the list
            {
                return retValue;
            }
            List<SubCalendarEvent> AllSubCalEvents = Utility.mTupleToSubCalEvents(Arg1);
            List<mTuple<TimeLine, SubCalendarEvent>> AvaialableTimeSpan = new List<mTuple<TimeLine, SubCalendarEvent>>();
            int indexOfSmallest = -2222;
            int i=0;


            TimeLine InterferringTimeLine = RestrictingTimeLine.CreateCopy();
            TimeSpan SmallestAssignedTimeSpan = new TimeSpan(3650, 0, 0, 0);//sets the smallest TimeSpan To 10 years
            DateTime SmallestDateTime = new DateTime(3000, 12, 31);
            /*if (SmallestAssignedTimeSpan < ZeroTimeSpan)
            { 
                SmallestAssignedTimeSpan=
            }*/

            foreach (SubCalendarEvent eachSubCalendarEvent in AllSubCalEvents)//gets the feasible timeLine foreach SubCalendarEvent
            {
                InterferringTimeLine = RestrictingTimeLine.InterferringTimeLine(eachSubCalendarEvent.getCalendarEventRange);
                if ((InterferringTimeLine != null)&&(InterferringTimeLine.TimelineSpan>=eachSubCalendarEvent.ActiveDuration))
                {
                    
                    AvaialableTimeSpan.Add(new mTuple<TimeLine, SubCalendarEvent>(InterferringTimeLine, eachSubCalendarEvent));
                    TimeSpan CurrentRealignedTimeSpan = InterferringTimeLine.TimelineSpan - eachSubCalendarEvent.ActiveDuration;

                    if (CurrentRealignedTimeSpan <= ZeroTimeSpan)
                    {
                        ;
                    }

                    if ((CurrentRealignedTimeSpan <= SmallestAssignedTimeSpan))//Checks if the remaining timeSpan is less than currently smallest fittable remaining space
                    {
                        if (AllSubCalEvents[i].getCalendarEventRange.End < SmallestDateTime)
                        {
                            indexOfSmallest = i;
                            SmallestAssignedTimeSpan = CurrentRealignedTimeSpan;
                            SmallestDateTime=AllSubCalEvents[indexOfSmallest].getCalendarEventRange.End;
                        }
                    }
                }


                i++;
            }

            

            //Build Strict Towards right of the tree
            if (AvaialableTimeSpan.Count > 0)
            {
                int InitialSmallest = indexOfSmallest;
                
                indexOfSmallest = AvaialableTimeSpan.Select(obj => obj.Item2).ToList().IndexOf(AllSubCalEvents[indexOfSmallest]);   
                AvaialableTimeSpan[indexOfSmallest].Item2.PinSubEventsToStart(RestrictingTimeLine);
                mTuple<bool, SubCalendarEvent> PivotNode = CopyOfAllList.Where(obj => (obj.Item2 == AvaialableTimeSpan[indexOfSmallest].Item2)).ToList()[0];


                DateTime StartTimeOfRightTree = PivotNode.Item2.End;
                DateTime EndTimeOfRightTree = RestrictingTimeLine.End;
                TimeLine RightTimeLine = new TimeLine(StartTimeOfRightTree, EndTimeOfRightTree);

                CopyOfAllList.Remove(PivotNode);

                Tuple<SubCalendarEvent, SubCalendarEvent> BoundaryElement = new Tuple<SubCalendarEvent,SubCalendarEvent>(null,PivotNode.Item2);
                
                Dictionary<TimeSpan, Dictionary<string, mTuple<bool, SubCalendarEvent>>> PossibleEntries_Cpy= new Dictionary<TimeSpan,Dictionary<string,mTuple<bool,SubCalendarEvent>>>();
                foreach(mTuple<bool, SubCalendarEvent> eachmtuple in CopyOfAllList)
                {
                    if(PossibleEntries_Cpy.ContainsKey(eachmtuple.Item2.RangeSpan))
                    {
                        
                        PossibleEntries_Cpy[eachmtuple.Item2.RangeSpan].Add(eachmtuple.Item2.ID,eachmtuple);
                    }
                    else
                    {
                        PossibleEntries_Cpy.Add(eachmtuple.Item2.RangeSpan, new Dictionary<string,mTuple<bool,SubCalendarEvent>>());
                        PossibleEntries_Cpy[eachmtuple.Item2.RangeSpan].Add(eachmtuple.Item2.ID,eachmtuple);
                    }
                }
                TimeLine RangeForSnugElements = new TimeLine(RestrictingTimeLine.Start, PivotNode.Item2.Start);
                List<SubCalendarEvent> OptimizedForLeft = OptimizeArrangeOfSubCalEvent(RangeForSnugElements, BoundaryElement, new List<mTuple<int, TimeSpanWithStringID>>(), PossibleEntries_Cpy, 0);
                //OptimizedForLeft = new List<SubCalendarEvent>();
                CopyOfAllList.RemoveAll(obj => OptimizedForLeft.Contains(obj.Item2));

                List<mTuple<bool, SubCalendarEvent>> rightTreeResult = stitchRestrictedSubCalendarEvent(CopyOfAllList, RightTimeLine);
                
                if (rightTreeResult.Contains(PivotNode))
                {
                    ;
                }

                List<mTuple<bool, SubCalendarEvent>> snugFitForLeftTree = Utility.SubCalEventsTomTuple(OptimizedForLeft, true);

                rightTreeResult.Insert(0, PivotNode);
                snugFitForLeftTree.AddRange(rightTreeResult);
                rightTreeResult = snugFitForLeftTree;
                List<SubCalendarEvent> JustSubCalevents = Utility.mTupleToSubCalEvents(rightTreeResult).ToList();
                if (!Utility.PinSubEventsToEnd(JustSubCalevents, RestrictingTimeLine))
                {
                    ;
                };

                //Build Strict Towards Left of the tree
                DateTime StartTimeOfleftTree = RestrictingTimeLine.Start;
                DateTime EndTimeOfLeftTree = rightTreeResult[0].Item2.Start;
                TimeLine LeftTimeLine = new TimeLine(StartTimeOfleftTree, EndTimeOfLeftTree);
                JustSubCalevents = Utility.mTupleToSubCalEvents(rightTreeResult).ToList();

                CopyOfAllList.RemoveAll(obj => JustSubCalevents.Contains(obj.Item2));

                //CopyOfAllList.RemoveAll(obj => rightTreeResult.Contains(obj));
                
                List<mTuple<bool, SubCalendarEvent>> LeftTreeResult = stitchRestrictedSubCalendarEvent(CopyOfAllList, LeftTimeLine);
                retValue = LeftTreeResult.Concat(rightTreeResult).ToList();
                if (!Utility.PinSubEventsToEnd(Utility.mTupleToSubCalEvents(retValue), RestrictingTimeLine))
                {
                    ;
                };
            }
            else //if there are no feasible TimeLine that are withing RestrictingTimeLine that can also contain a subcalevent
            {
                return new List<mTuple<bool, SubCalendarEvent>>();
            }
            return retValue;

        }
Esempio n. 3
0
        public TimeLine InterferringTimeLine(TimeLine PossibleTimeLine)
        {
            DateTime InterferringStarTime;
            DateTime InterferringEndTime;
            if ((this.Start == PossibleTimeLine.Start) && (this.End == PossibleTimeLine.End))//checks if both "this and "PossibleTimeLine" are within the same range
            {
                return this.CreateCopy();
            }

            if (this.doesTimeLineInterfere(PossibleTimeLine))
            {
                InterferringStarTime = PossibleTimeLine.Start;
                if (this.Start > PossibleTimeLine.Start)
                {
                    InterferringStarTime = this.Start;
                }

                InterferringEndTime = this.End;
                if (this.End > PossibleTimeLine.End)
                {
                    InterferringEndTime = PossibleTimeLine.End;
                }

                return new TimeLine(InterferringStarTime, InterferringEndTime);
            }
            else
            {
                if (PossibleTimeLine.doesTimeLineInterfere(this))
                return PossibleTimeLine.InterferringTimeLine(this);//checks if PossibleTimeLine is the same as or bigger than "this" timeline
            }

            return null;
        }
Esempio n. 4
0
        private SubCalendarEvent[] getInterferringSubEvents(TimeLine EventRange, List<CalendarEvent> NonCommitedCalendarEvemts = null)
        {

#if enableMultithreading
            ConcurrentBag<SubCalendarEvent> MyArrayOfInterferringSubCalendarEvents = new ConcurrentBag<SubCalendarEvent>();//List that stores the InterFerring List

            int lengthOfCalendarSubEvent = 0;


            Parallel.ForEach(AllEventDictionary, MyCalendarEventDictionaryEntry =>
            {
                int i = 0;
                if (MyCalendarEventDictionaryEntry.Value.RepetitionStatus)
                {
                    SubCalendarEvent[] ArrayOfSubcalendarEventsFromRepeatingEvents = MyCalendarEventDictionaryEntry.Value.AllActiveRepeatSubCalendarEvents.Where(obj => obj != null).ToArray();//hack alert you should be able to remove the LINQ test for null
                    lengthOfCalendarSubEvent = ArrayOfSubcalendarEventsFromRepeatingEvents.Length;
                    Parallel.ForEach(MyCalendarEventDictionaryEntry.Value.AllActiveRepeatSubCalendarEvents.Where(obj => obj != null).Where(obj => EventRange.InterferringTimeLine(obj.RangeTimeLine) != null), EacSubCal =>
                    {
                        MyArrayOfInterferringSubCalendarEvents.Add(EacSubCal);
                    }
                    );
                }
                else
                {
                    SubCalendarEvent[] ArrayOfSubcalendarEventsFromNonRepeatingEvents = MyCalendarEventDictionaryEntry.Value.AllActiveSubEvents.Where(obj => obj != null).ToArray();//hack alert you should be able to remove the LINQ test for null
                    lengthOfCalendarSubEvent = ArrayOfSubcalendarEventsFromNonRepeatingEvents.Length;


                    Parallel.ForEach(MyCalendarEventDictionaryEntry.Value.AllActiveSubEvents.Where(obj => obj != null).Where(obj => EventRange.InterferringTimeLine(obj.RangeTimeLine) != null), EacSubCal =>
                    {
                        MyArrayOfInterferringSubCalendarEvents.Add(EacSubCal);
                    }
                    );
                }
            }
            );

            if (NonCommitedCalendarEvemts != null)
            {
                foreach (CalendarEvent eachCalendarEvent in NonCommitedCalendarEvemts)
                {

                    int i = 0;
                    if (eachCalendarEvent.RepetitionStatus)
                    {
                        lengthOfCalendarSubEvent = eachCalendarEvent.AllActiveRepeatSubCalendarEvents.Length;
                        SubCalendarEvent[] ArrayOfSubcalendarEventsFromRepeatingEvents = eachCalendarEvent.AllActiveRepeatSubCalendarEvents;

                        Parallel.ForEach(eachCalendarEvent.AllActiveRepeatSubCalendarEvents.Where(obj => obj != null).Where(obj => EventRange.InterferringTimeLine(obj.RangeTimeLine) != null), EacSubCal =>
                        {
                            MyArrayOfInterferringSubCalendarEvents.Add(EacSubCal);
                        }
                        );



                        /*
                        for (i = 0; i < lengthOfCalendarSubEvent; i++)
                        {
                            //if ((EventRange.IsDateTimeWithin(ArrayOfSubcalendarEventsFromRepeatingEvents[i].Start)) || (EventRange.IsDateTimeWithin(ArrayOfSubcalendarEventsFromRepeatingEvents[i].End)))
                            if (EventRange.InterferringTimeLine(ArrayOfSubcalendarEventsFromRepeatingEvents[i].RangeTimeLine) != null)
                            {
                                MyArrayOfInterferringSubCalendarEvents.Add(ArrayOfSubcalendarEventsFromRepeatingEvents[i]);
                            }
                        }*/
                    }
                    else
                    {
                        SubCalendarEvent[] ArrayOfSubcalendarEventsFromNonRepeatingEvents = eachCalendarEvent.AllActiveSubEvents.Where(obj => obj != null).ToArray();//hack alert you should be able to remove the LINQ test for null
                        lengthOfCalendarSubEvent = ArrayOfSubcalendarEventsFromNonRepeatingEvents.Length;

                        Parallel.ForEach(eachCalendarEvent.AllActiveSubEvents.Where(obj => obj != null).Where(obj => EventRange.InterferringTimeLine(obj.RangeTimeLine) != null), EacSubCal =>
                        {
                            MyArrayOfInterferringSubCalendarEvents.Add(EacSubCal);
                        }
                        );



                        /*for (i = 0; i < lengthOfCalendarSubEvent; i++)
                        {

                            //if ((EventRange.IsDateTimeWithin(MyCalendarEventDictionaryEntry.Value.AllEvents[i].Start)) || (EventRange.IsDateTimeWithin(MyCalendarEventDictionaryEntry.Value.AllEvents[i].End)))
                            //if (MyCalendarEventDictionaryEntry.Value.AllEvents[i]!=null)
                            {
                                if (EventRange.InterferringTimeLine(ArrayOfSubcalendarEventsFromNonRepeatingEvents[i].RangeTimeLine) != null)
                                {
                                    MyArrayOfInterferringSubCalendarEvents.Add(ArrayOfSubcalendarEventsFromNonRepeatingEvents[i]);
                                }
                            }
                        }*/
                    }
                }
            }

            return MyArrayOfInterferringSubCalendarEvents.ToArray();

















            /////////////////



           
#else
            List<SubCalendarEvent> MyArrayOfInterferringSubCalendarEvents = new List<SubCalendarEvent>(0);//List that stores the InterFerring List
            int lengthOfCalendarSubEvent = 0;

            IEnumerable<KeyValuePair<string, CalendarEvent>> content = AllEventDictionary.Where(obj => obj.Value.isActive);

            foreach (KeyValuePair<string, CalendarEvent> MyCalendarEventDictionaryEntry in AllEventDictionary.Where(obj=>obj.Value.isActive))
            {
                int i = 0;
                if (MyCalendarEventDictionaryEntry.Value.ID == "373")
                {
                    ;
                }
                if (MyCalendarEventDictionaryEntry.Value.RepetitionStatus)
                {
                    if (MyCalendarEventDictionaryEntry.Value.ID == "373")
                    {
                        ;
                    }

                    SubCalendarEvent[] ArrayOfSubcalendarEventsFromRepeatingEvents = MyCalendarEventDictionaryEntry.Value.ActiveRepeatSubCalendarEvents.Where(obj => obj != null).ToArray();//hack alert you should be able to remove the LINQ test for null
                    lengthOfCalendarSubEvent = ArrayOfSubcalendarEventsFromRepeatingEvents.Length;
                    MyArrayOfInterferringSubCalendarEvents.AddRange(MyCalendarEventDictionaryEntry.Value.ActiveRepeatSubCalendarEvents.Where(obj => obj != null).Where(obj => EventRange.InterferringTimeLine(obj.RangeTimeLine) != null).ToList());
                }
                else
                {
                    SubCalendarEvent[] ArrayOfSubcalendarEventsFromNonRepeatingEvents = MyCalendarEventDictionaryEntry.Value.ActiveSubEvents.Where(obj => obj != null).ToArray();//hack alert you should be able to remove the LINQ test for null
                    lengthOfCalendarSubEvent = ArrayOfSubcalendarEventsFromNonRepeatingEvents.Length;
                    MyArrayOfInterferringSubCalendarEvents.AddRange(MyCalendarEventDictionaryEntry.Value.ActiveSubEvents.Where(obj => obj != null).Where(obj => EventRange.InterferringTimeLine(obj.RangeTimeLine) != null).ToList());
                }
            }

            if (NonCommitedCalendarEvemts != null)
            {
                foreach (CalendarEvent eachCalendarEvent in NonCommitedCalendarEvemts)
                {

                    int i = 0;
                    if (eachCalendarEvent.RepetitionStatus)
                    {
                        lengthOfCalendarSubEvent = eachCalendarEvent.ActiveRepeatSubCalendarEvents.Length;
                        SubCalendarEvent[] ArrayOfSubcalendarEventsFromRepeatingEvents = eachCalendarEvent.ActiveRepeatSubCalendarEvents;

                        MyArrayOfInterferringSubCalendarEvents.AddRange(eachCalendarEvent.ActiveRepeatSubCalendarEvents.Where(obj => obj != null).Where(obj => EventRange.InterferringTimeLine(obj.RangeTimeLine) != null).ToList());
                        /*for (i = 0; i < lengthOfCalendarSubEvent; i++)
                        {
                            //if ((EventRange.IsDateTimeWithin(ArrayOfSubcalendarEventsFromRepeatingEvents[i].Start)) || (EventRange.IsDateTimeWithin(ArrayOfSubcalendarEventsFromRepeatingEvents[i].End)))
                            if (EventRange.InterferringTimeLine(ArrayOfSubcalendarEventsFromRepeatingEvents[i].RangeTimeLine) != null)
                            {
                                MyArrayOfInterferringSubCalendarEvents.Add(ArrayOfSubcalendarEventsFromRepeatingEvents[i]);
                            }
                        }*/
                    }
                    else
                    {
                        SubCalendarEvent[] ArrayOfSubcalendarEventsFromNonRepeatingEvents = eachCalendarEvent.ActiveSubEvents.Where(obj => obj != null).ToArray();//hack alert you should be able to remove the LINQ test for null
                        lengthOfCalendarSubEvent = ArrayOfSubcalendarEventsFromNonRepeatingEvents.Length;


                        MyArrayOfInterferringSubCalendarEvents.AddRange(eachCalendarEvent.ActiveSubEvents.Where(obj => obj != null).Where(obj => EventRange.InterferringTimeLine(obj.RangeTimeLine) != null).ToList());
                        /*
                        for (i = 0; i < lengthOfCalendarSubEvent; i++)
                        {

                            //if ((EventRange.IsDateTimeWithin(MyCalendarEventDictionaryEntry.Value.AllEvents[i].Start)) || (EventRange.IsDateTimeWithin(MyCalendarEventDictionaryEntry.Value.AllEvents[i].End)))
                            //if (MyCalendarEventDictionaryEntry.Value.AllEvents[i]!=null)
                            {
                                if (EventRange.InterferringTimeLine(ArrayOfSubcalendarEventsFromNonRepeatingEvents[i].RangeTimeLine) != null)
                                {
                                    MyArrayOfInterferringSubCalendarEvents.Add(ArrayOfSubcalendarEventsFromNonRepeatingEvents[i]);
                                }
                            }
                        }*/
                    }
                }
            }

            return MyArrayOfInterferringSubCalendarEvents.ToArray();
#endif
        }
Esempio n. 5
0
 public IEnumerable<SubCalendarEvent> getInterferringSubEvents(TimeLine EventRange, IEnumerable<SubCalendarEvent> PossibleSubCalEVents)//gets list of subcalendar event in which the busytimeline interfer with Event range
 {
     return PossibleSubCalEVents.Where(obj => (EventRange.InterferringTimeLine(obj.ActiveSlot) != null));
 }
Esempio n. 6
0
        List<SubCalendarEvent> PlaceSubCalEventInLowestCostPosition(TimeLine MyLimitingTimeLine, SubCalendarEvent mySubcalevent, List<SubCalendarEvent> OptimizedArrangementOfEvent)
        {

            /**Hack Solution Start, this just assumes all events are right next to each other and appends mySubcalevetn to the end. It also shifts this sub cal event to represent this shift **/
            DateTime RelativeStartTime = MyLimitingTimeLine.Start + Utility.SumOfActiveDuration(OptimizedArrangementOfEvent);
            TimeLine encasingTimeLine = MyLimitingTimeLine.InterferringTimeLine(mySubcalevent.getCalendarEventRange);

            IEnumerable<SubCalendarEvent> Interferringevents = getInterferringSubEvents(encasingTimeLine, OptimizedArrangementOfEvent);
            List<SubCalendarEvent> ListSofar = Interferringevents.ToList();

            List<List<SubCalendarEvent>> AllPertinentList = new List<List<SubCalendarEvent>>();
            List<SubCalendarEvent> retValue = OptimizedArrangementOfEvent.ToList();
            retValue.Add(mySubcalevent);

#if EnableRestrictedLocationOptimization
            int NumberOfLists = ListSofar.Count;
            int LastInt = 0;
            List<SubCalendarEvent> currList;

            if (ListSofar.Count > 0)
            {
                ListSofar.RemoveAt(0);
                IEnumerable<int> AllValidIndexes = ListSofar.Select(obj => OptimizedArrangementOfEvent.IndexOf(obj));
                foreach (int eachInt in AllValidIndexes)
                {
                    currList = OptimizedArrangementOfEvent.ToList();
                    currList.Insert(eachInt, mySubcalevent);
                    AllPertinentList.Add(currList);
                    LastInt = eachInt;
                }

                currList = OptimizedArrangementOfEvent.ToList();
                currList.Insert(LastInt + 1, mySubcalevent);
                AllPertinentList.Add(currList);
                List<List<SubCalendarEvent>> ListThatWorks = new List<List<SubCalendarEvent>>();

                foreach (List<SubCalendarEvent> eachList in AllPertinentList)
                {
                    if (Utility.PinSubEventsToStart(eachList, MyLimitingTimeLine))
                    {
#if createCopyOfImplementation
                        List<SubCalendarEvent> eachListCpy = eachList.Select(obj => obj.createCopy()).ToList();
                        ListThatWorks.Add(eachListCpy);
#else
                        ListThatWorks.Add(eachList);
#endif
                    }
                }

                double lowestSofar = double.MaxValue;
            
                foreach (List<SubCalendarEvent> eachList in ListThatWorks)
                {
                    double currDistance = Utility.calculateDistance(eachList.ToList(), CalendarEvent.DistanceMatrix);
                    if (currDistance < lowestSofar)
                    { 
                        lowestSofar=currDistance;
#if createCopyOfImplementation    
                        retValue = eachList.SelectMany(obj => retValue.Where(obj0 => obj0.ID == obj.ID)).ToList(); ;
#else
                        retValue =eachList;
#endif

                    }
                }
            }

            Utility.PinSubEventsToStart(retValue, MyLimitingTimeLine);

#endif

            return retValue;
        }