Example #1
0
        static bool isSubCalendarEventAlreadyInList(SubCalendarEvent MySubCalendarEvent, List<SubCalendarEvent> MyListCopy)
        {
            foreach (SubCalendarEvent SubCalendarElement in MyListCopy)
            {
                if (MySubCalendarEvent.ID == SubCalendarElement.ID)
                {
                    return true;
                }
            }

            return false;
        }
 public ClumpSubCalendarEvent(List<SubCalendarEvent> Appendables, TimeLine BoundaryTimeLine)
 {
     Appendables=Appendables.OrderBy(obj => obj.getCalendarEventRange.End).ToList();
     SubCalendarEvent RelativeSubEvent = Appendables[0];
     Appendables.Remove(RelativeSubEvent);
     ClumpSubCalendarEvent myThis = new ClumpSubCalendarEvent(RelativeSubEvent, Appendables, BoundaryTimeLine.CreateCopy());
     SubCalEventsOverLapWithBase = myThis.SubCalEventsOverLapWithBase;
     //List<SubCalendarEvent> NonOverLapping;
     BaseEvent= myThis.BaseEvent;
     this.BoundaryTimeLine =myThis.BoundaryTimeLine;
     //List<SubCalendarEvent> BaseClump;
     //List<ClumpSubCalendarEvent> NonOverLapping_Clump;
     BreakOffClump= myThis.BreakOffClump;
     ClumpedResults= myThis.ClumpedResults;
     BaseReferenceStartTime = myThis.BaseReferenceStartTime;
 }
        public void DeleteAppointment(SubCalendarEvent ActiveSection, string NameOfParentCalendarEvent, string entryID)
        {
            #if EnableOutlook
            if (entryID == "")
            {
                return;
            }
            Outlook.Application outlookApp = new Microsoft.Office.Interop.Outlook.Application();
            Outlook.MAPIFolder calendar = outlookApp.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderCalendar);

            Outlook.Items calendarItems = calendar.Items;
            try
            {
                string SubJectString = ActiveSection.ID + "**" + NameOfParentCalendarEvent;
                if (ActiveSection.isComplete)
                {
                    //SubJectString = ActiveSection.ID + "*\u221A*" + NameOfParentCalendarEvent;
                }
                Outlook.AppointmentItem item = calendarItems[SubJectString] as Outlook.AppointmentItem;
                item.Delete();
            }
            catch
            {
                return;
            }
            /*Outlook.RecurrencePattern pattern =
                item.GetRecurrencePattern();
            Outlook.AppointmentItem itemDelete = pattern.
                GetOccurrence(new DateTime(2006, 6, 28, 8, 0, 0));

            if (itemDelete != null)
            {
                itemDelete.Delete();
            }*/
            #endif
        }
 public static int CompareByStartDate(SubCalendarEvent SubCalendarEvent1, SubCalendarEvent SubCalendarEvent2)
 {
     return SubCalendarEvent1.Start.CompareTo(SubCalendarEvent2.Start);
 }
 public SubCalendarEvent createCopy()
 {
     SubCalendarEvent MySubCalendarEventCopy = new SubCalendarEvent(this.ID, new DateTime(Start.Ticks), new DateTime(End.Ticks), BusyFrame.CreateCopy(), this.RigidSchedule, this.isEnabled, this.UiParams.createCopy(), this.Notes.createCopy(), this.Complete, this.LocationData, new TimeLine(CalendarEventRange.Start, CalendarEventRange.End));
     //MySubCalendarEventCopy.LocationData = LocationData;//note check for possible reference issues for future versions
     /*MySubCalendarEventCopy.SubEventID = SubEventID;
     MySubCalendarEventCopy.BusyFrame = BusyFrame;
     MySubCalendarEventCopy.StartDateTime = StartDateTime;
     MySubCalendarEventCopy.EndDateTime = EndDateTime;
     MySubCalendarEventCopy.EventDuration = EventDuration;
     MySubCalendarEventCopy.RigidSchedule = RigidSchedule;
     MySubCalendarEventCopy.SchedulStatus = SchedulStatus;
     MySubCalendarEventCopy.otherPartyID = otherPartyID;
     MySubCalendarEventCopy.EventPreDeadline = EventPreDeadline;
     MySubCalendarEventCopy.EventRepetition = EventRepetition;*/
     MySubCalendarEventCopy.ThirdPartyID = this.ThirdPartyID;
     return MySubCalendarEventCopy;
 }
Example #6
0
        virtual public bool shiftEvent(TimeSpan ChangeInTime, SubCalendarEvent[] UpdatedSubCalEvents)
        {
            TimeLine UpdatedTimeLine = new TimeLine(this.Start+ChangeInTime,this.End+ChangeInTime);
            
            foreach (SubCalendarEvent eachSubCalendarEvent in UpdatedSubCalEvents)
            { 
                if(!(UpdatedTimeLine.IsTimeLineWithin(eachSubCalendarEvent.RangeTimeLine)))
                {
                    return false;
                }
            }
            StartDateTime = StartDateTime + ChangeInTime;
            EndDateTime = EndDateTime + ChangeInTime;
            ArrayOfSubEvents = UpdatedSubCalEvents.ToArray();

            return true;
        }
Example #7
0
 bool isSubCalendarEventInList(SubCalendarEvent SubCalendarEventToCheck, List<SubCalendarEvent> MyCurrentList)
 {
     foreach (SubCalendarEvent MySubCalendarEvent in MyCurrentList)
     {
         if (SubCalendarEventToCheck.ID == MySubCalendarEvent.ID)
         {
             return true;
         }
     }
     return false;
 }
 public double Distance(SubCalendarEvent firstCity, SubCalendarEvent secondCity)
 {
     return DistanceMatrix[firstCity.SubEvent_ID.getLevelID(0)][Horizontal.IndexOf(secondCity.SubEvent_ID.getLevelID(0))];
 }
Example #9
0
        /*SubCalendarEvent[] generateSubEvent(SubCalendarEvent[] ArrayOfEvents, int NumberOfSplit, TimeSpan TotalActiveDurationSubEvents, string ParentID)
        {
            TimeSpan TimeSpanEvent = EndDateTime - StartDateTime;
            //new TimeSpan((long)((().TotalSeconds/ ArrayOfEvents.Length)*100000000));
            TimeSpanEvent = new TimeSpan(((long)TimeSpanEvent.TotalMilliseconds * 10000) / ArrayOfEvents.Length);
            TimeSpan ActiveDurationPerSubEvents = new TimeSpan((long)(((TotalActiveDurationSubEvents.TotalSeconds) * 10000000) / ArrayOfEvents.Length));
            DateTime SubStart;
            DateTime SubEnd;
            for (int i = 0; i < ArrayOfEvents.Length; i++)
            {
                SubStart = StartDateTime.AddSeconds(TimeSpanEvent.TotalSeconds * i);
                SubEnd = StartDateTime.AddSeconds(TimeSpanEvent.TotalSeconds * (i + 1));
                ArrayOfEvents[i] = new SubCalendarEvent(ActiveDurationPerSubEvents, SubStart, SubEnd, PrepTime, ParentID);
            }

            return ArrayOfEvents;
        }*/


        public CalendarEvent createCopy()
        {
            CalendarEvent MyCalendarEventCopy = new SubCalendarEvent();
            MyCalendarEventCopy.EventDuration = new TimeSpan(EventDuration.Ticks);
            MyCalendarEventCopy.CalendarEventName = CalendarEventName.ToString();
            MyCalendarEventCopy.StartDateTime = new DateTime(StartDateTime.Ticks);
            MyCalendarEventCopy.EndDateTime = new DateTime(EndDateTime.Ticks);
            MyCalendarEventCopy.EventPreDeadline = new TimeSpan(EventPreDeadline.Ticks);
            MyCalendarEventCopy.PrepTime = new TimeSpan(PrepTime.Ticks);
            MyCalendarEventCopy.Priority = Priority;
            MyCalendarEventCopy.RepetitionFlag = RepetitionFlag;
            MyCalendarEventCopy.EventRepetition = EventRepetition.CreateCopy();// EventRepetition != null ? EventRepetition.CreateCopy() : EventRepetition;
            //protected bool Completed = false;
            MyCalendarEventCopy.RigidSchedule = RigidSchedule;//hack
            MyCalendarEventCopy.Splits = Splits;
            MyCalendarEventCopy.TimePerSplit = new TimeSpan(TimePerSplit.Ticks);
            MyCalendarEventCopy.CalendarEventID = CalendarEventID;//hack
            MyCalendarEventCopy.EventSequence = EventSequence.CreateCopy();
            MyCalendarEventCopy.ArrayOfSubEvents = ArrayOfSubEvents.ToArray();

            MyCalendarEventCopy.LocationData = LocationData;//hack you might need to make copy

            for (int i = 0; i < MyCalendarEventCopy.ArrayOfSubEvents.Length; i++)
            {
                MyCalendarEventCopy.ArrayOfSubEvents[i] = MyCalendarEventCopy.ArrayOfSubEvents[i].createCopy();
            }

            MyCalendarEventCopy.SchedulStatus = SchedulStatus;
            MyCalendarEventCopy.otherPartyID = otherPartyID == null ? null : otherPartyID.ToString();
            return MyCalendarEventCopy;
        }
Example #10
0
 public Bee(int status, SubCalendarEvent[] memoryMatrix, double measureOfQuality, int numberOfVisits)
 {
     this.status = status;
     this.memoryMatrix = new SubCalendarEvent[memoryMatrix.Length];
     Array.Copy(memoryMatrix, this.memoryMatrix, memoryMatrix.Length);
     this.measureOfQuality = measureOfQuality;
     this.numberOfVisits = numberOfVisits;
 }
Example #11
0
        /*QUICK SORT SECTION END*/

        public BusyTimeLine[] CheckIfMyRangeAlreadyHasSchedule(BusyTimeLine[] BusySlots, SubCalendarEvent MySubEvent)
        {
            List<BusyTimeLine> InvadingEvents = new List<BusyTimeLine>();
            int i = 0;
            for (; i < BusySlots.Length; i++)
            {
                if ((BusySlots[i].End > MySubEvent.Start) && (BusySlots[i].End < MySubEvent.End))
                {
                    InvadingEvents.Add(BusySlots[i]);
                }
            }


            InvadingEvents = SortBusyTimeline(InvadingEvents, true);


            return InvadingEvents.ToArray();
        }
Example #12
0
            SubCalendarEvent[] ReadSubSchedulesFromXMLNode(XmlNode MyXmlNode, CalendarEvent MyParent)
            {
                SubCalendarEvent[] MyArrayOfNodes = new SubCalendarEvent[MyXmlNode.ChildNodes.Count];
                string ID = "";
                DateTime Start = new DateTime();
                DateTime End = new DateTime();
                TimeSpan SubScheduleDuration = new TimeSpan();
                TimeSpan PrepTime = new TimeSpan();
                BusyTimeLine BusySlot = new BusyTimeLine();
                bool Enabled;
                for (int i = 0; i < MyXmlNode.ChildNodes.Count; i++)
                {
                    BusyTimeLine SubEventActivePeriod = new BusyTimeLine(MyXmlNode.ChildNodes[i].SelectSingleNode("ID").InnerText, stringToDateTime(MyXmlNode.ChildNodes[i].SelectSingleNode("ActiveStartTime").InnerText), stringToDateTime(MyXmlNode.ChildNodes[i].SelectSingleNode("ActiveEndTime").InnerText));
                    ID = MyXmlNode.ChildNodes[i].SelectSingleNode("ID").InnerText;
                    Start = DateTime.Parse(MyXmlNode.ChildNodes[i].SelectSingleNode("ActiveStartTime").InnerText);
                    End = DateTime.Parse(MyXmlNode.ChildNodes[i].SelectSingleNode("ActiveEndTime").InnerText);
                    BusySlot = new BusyTimeLine(ID, Start, End);
                    PrepTime = new TimeSpan(ConvertToMinutes(MyXmlNode.ChildNodes[i].SelectSingleNode("PrepTime").InnerText) * 60 * 10000000);
                    //stringToDateTime();
                    Start = DateTime.Parse(MyXmlNode.ChildNodes[i].SelectSingleNode("StartTime").InnerText);
                    End = DateTime.Parse(MyXmlNode.ChildNodes[i].SelectSingleNode("EndTime").InnerText);
                    Enabled=Convert.ToBoolean(MyXmlNode.ChildNodes[i].SelectSingleNode("Enabled").InnerText);
                    bool CompleteFlag = Convert.ToBoolean(MyXmlNode.ChildNodes[i].SelectSingleNode("Complete").InnerText);
                    Location var1 = getLocation(MyXmlNode.ChildNodes[i]);
                    MiscData noteData = getMiscData(MyXmlNode.ChildNodes[i]);
                    EventDisplay UiData = getDisplayUINode(MyXmlNode.ChildNodes[i]);

                    MyArrayOfNodes[i] = new SubCalendarEvent(ID, BusySlot, Start, End, PrepTime, MyParent.ID, MyParent.Rigid, Enabled, UiData, noteData, CompleteFlag, var1, MyParent.RangeTimeLine);
                    MyArrayOfNodes[i].ThirdPartyID = MyXmlNode.ChildNodes[i].SelectSingleNode("ThirdPartyID").InnerText;//this is a hack to just update the Third partyID
                }

                return MyArrayOfNodes;
            }
Example #13
0
            public XmlElement CreateSubScheduleNode(SubCalendarEvent MySubEvent)
            {
                XmlDocument xmldoc = new XmlDocument();
                XmlElement MyEventSubScheduleNode = xmldoc.CreateElement("EventSubSchedule");

                DateTime StartTime = MySubEvent.Start;
                StartTime = Truncate(StartTime, TimeSpan.FromSeconds(1));
                DateTime EndTime = MySubEvent.End;
                EndTime = Truncate(EndTime, TimeSpan.FromSeconds(1));
                TimeSpan EventTimeSpan = MySubEvent.ActiveDuration;
                long AllSecs = (long)EventTimeSpan.TotalSeconds;
                long AllTicks = (long)EventTimeSpan.TotalMilliseconds;
                long DiffSecs = (long)(EndTime - StartTime).TotalSeconds;
                long DiffTicks = (long)(EndTime - StartTime).TotalMilliseconds;
                EventTimeSpan = new TimeSpan(AllSecs * 10000000);
                if ((EndTime - StartTime) != EventTimeSpan)
                {
                    EndTime = StartTime.Add(EventTimeSpan);
                }

                MyEventSubScheduleNode.PrependChild(xmldoc.CreateElement("EndTime"));
                MyEventSubScheduleNode.ChildNodes[0].InnerText = EndTime.ToString();
                MyEventSubScheduleNode.PrependChild(xmldoc.CreateElement("StartTime"));
                MyEventSubScheduleNode.ChildNodes[0].InnerText = StartTime.ToString();
                MyEventSubScheduleNode.PrependChild(xmldoc.CreateElement("Duration"));
                MyEventSubScheduleNode.ChildNodes[0].InnerText = EventTimeSpan.ToString();
                MyEventSubScheduleNode.PrependChild(xmldoc.CreateElement("ActiveEndTime"));
                MyEventSubScheduleNode.ChildNodes[0].InnerText = EndTime.ToString();
                MyEventSubScheduleNode.PrependChild(xmldoc.CreateElement("ActiveStartTime"));
                MyEventSubScheduleNode.ChildNodes[0].InnerText = StartTime.ToString();
                MyEventSubScheduleNode.PrependChild(xmldoc.CreateElement("PrepTime"));
                MyEventSubScheduleNode.ChildNodes[0].InnerText = MySubEvent.Preparation.ToString();
                MyEventSubScheduleNode.PrependChild(xmldoc.CreateElement("ThirdPartyID"));
                MyEventSubScheduleNode.ChildNodes[0].InnerText = MySubEvent.ThirdPartyID;
                //MyEventSubScheduleNode.PrependChild(xmldoc.CreateElement("Name"));
                //MyEventSubScheduleNode.ChildNodes[0].InnerText = MySubEvent.Name.ToString();
                MyEventSubScheduleNode.PrependChild(xmldoc.CreateElement("ID"));
                MyEventSubScheduleNode.ChildNodes[0].InnerText = MySubEvent.ID.ToString();
                MyEventSubScheduleNode.PrependChild(xmldoc.CreateElement("Enabled"));
                MyEventSubScheduleNode.ChildNodes[0].InnerText = MySubEvent.isEnabled.ToString();
                MyEventSubScheduleNode.PrependChild(xmldoc.CreateElement("Complete"));
                MyEventSubScheduleNode.ChildNodes[0].InnerText = MySubEvent.isComplete.ToString();
                MyEventSubScheduleNode.PrependChild(xmldoc.CreateElement("Location"));
                MyEventSubScheduleNode.ChildNodes[0].InnerXml = CreateLocationNode(MySubEvent.myLocation, "EventSubScheduleLocation").InnerXml;
                MyEventSubScheduleNode.PrependChild(xmldoc.CreateElement("UIParams"));
                MyEventSubScheduleNode.ChildNodes[0].InnerXml = createDisplayUINode(MySubEvent.UIParam, "UIParams").InnerXml;
                MyEventSubScheduleNode.PrependChild(xmldoc.CreateElement("MiscData"));
                MyEventSubScheduleNode.ChildNodes[0].InnerXml = createMiscDataNode(MySubEvent.Notes, "MiscData").InnerXml;

                return MyEventSubScheduleNode;
            }
Example #14
0
        string SubCalendarEventToString(SubCalendarEvent arg1,string NameOfEvent,string CalendarID)
        {
            /*
             * This funciton takes a non repeat CalendarEvent and converts it to a JSON formatted string;
             */
            string IDString="\""+arg1.ID+"\"";
            string SubCalTotalString = "";
            string SubCalCalendarName = "\"" + NameOfEvent + "\"";
            string SubCalStartDate = "\"" + arg1.Start.ToString() + "\"";
            string SubCalEndDate = "\"" + arg1.End.ToString() + "\"";
            string SubCalTotalDuration = "\"" + arg1.ActiveDuration.ToString() + "\"";
            string SubCalRigid = "\"" + arg1.Rigid + "\"";
            string SubCalAddressDescription = "\"" + arg1.myLocation.Description + "\"";
            string SubCalAddress = "\"" + arg1.myLocation.Address + "\"";
            string SubCalCalEventStart = "\"" + arg1.getCalendarEventRange.Start + "\"";
            string SubCalCalEventEnd = "\"" + arg1.getCalendarEventRange.End + "\"";
            string SubCalEventLong = "\"" + arg1.myLocation.YCoordinate+ "\"";
            string SubCalEventLat = "\"" + arg1.myLocation.XCoordinate + "\"";
            CalendarID = "\"" + CalendarID + "\"";

            SubCalTotalString = "{\"ID\":" + IDString + ",\"CalendarID\":" + CalendarID + ",\"SubCalCalendarName\":" + SubCalCalendarName + ",\"SubCalStartDate\":" + SubCalStartDate + ",\"SubCalEndDate\":" + SubCalEndDate + ",\"SubCalTotalDuration\":" + SubCalTotalDuration + ",\"SubCalRigid\":" + SubCalRigid + ",\"SubCalAddressDescription\": " + SubCalAddressDescription + ",\"SubCalAddress\":" + SubCalAddress + ",\"SubCalCalEventStart\":" + SubCalCalEventStart + ",\"SubCalCalEventEnd\":" + SubCalCalEventEnd + ",\"SubCalEventLong\":" + SubCalEventLong + ",\"SubCalEventLat\":" + SubCalEventLat + "}";
            string retValue = SubCalTotalString;
            return retValue;
        }
 public SubCalendarEventListCounter(SubCalendarEvent StartingSubCalendarEvent, string ParentID)
 {
     this.ParentID = ParentID;
     ListOfSubCalEvents = new List<SubCalendarEvent>() { StartingSubCalendarEvent };
     CurrentIndex = 0;
 }
Example #16
0
        public CalendarEvent GenerateRigidSubEvents(CalendarEvent MyCalendarEvent)
        {
            int i = 0;
            List<SubCalendarEvent> MyArrayOfSubEvents = new List<SubCalendarEvent>();
            for (; i < MyCalendarEvent.AllEvents.Length; i++)
            {

            }

            if (MyCalendarEvent.RepetitionStatus)
            {
                
                SubCalendarEvent MySubEvent = new SubCalendarEvent(MyCalendarEvent.ActiveDuration, MyCalendarEvent.Repeat.Range.Start, MyCalendarEvent.Repeat.Range.End, MyCalendarEvent.Preparation, MyCalendarEvent.ID,MyCalendarEvent.Rigid, MyCalendarEvent.myLocation, MyCalendarEvent.RangeTimeLine);
   
                
                //new SubCalendarEvent(MyCalendarEvent.End, MyCalendarEvent.Repeat.Range.Start, MyCalendarEvent.Repeat.Range.End, MyCalendarEvent.Preparation, MyCalendarEvent.ID);

                for (; MySubEvent.Start < MyCalendarEvent.Repeat.Range.End; )
                {
                    MyArrayOfSubEvents.Add(MySubEvent);
                    switch (MyCalendarEvent.Repeat.Frequency)
                    {
                        case "DAILY":
                            {
                                MySubEvent = new SubCalendarEvent(MyCalendarEvent.ActiveDuration, MyCalendarEvent.Repeat.Range.Start.AddDays(1), MyCalendarEvent.Repeat.Range.End.AddDays(1), MyCalendarEvent.Preparation, MyCalendarEvent.ID,MyCalendarEvent.Rigid, MyCalendarEvent.myLocation, MyCalendarEvent.RangeTimeLine);
                                break;
                            }
                        case "WEEKLY":
                            {
                                MySubEvent = new SubCalendarEvent(MyCalendarEvent.ActiveDuration, MyCalendarEvent.Repeat.Range.Start.AddDays(7), MyCalendarEvent.Repeat.Range.End.AddDays(7), MyCalendarEvent.Preparation, MyCalendarEvent.ID, MyCalendarEvent.Rigid, MyCalendarEvent.myLocation, MyCalendarEvent.RangeTimeLine);
                                break;
                            }
                        case "BI-WEEKLY":
                            {
                                MySubEvent = new SubCalendarEvent(MyCalendarEvent.ActiveDuration, MyCalendarEvent.Repeat.Range.Start.AddDays(14), MyCalendarEvent.Repeat.Range.End.AddDays(14), MyCalendarEvent.Preparation, MyCalendarEvent.ID, MyCalendarEvent.Rigid, MyCalendarEvent.myLocation, MyCalendarEvent.RangeTimeLine);
                                break;
                            }
                        case "MONTHLY":
                            {
                                MySubEvent = new SubCalendarEvent(MyCalendarEvent.ActiveDuration, MyCalendarEvent.Repeat.Range.Start.AddMonths(1), MyCalendarEvent.Repeat.Range.End.AddMonths(1), MyCalendarEvent.Preparation, MyCalendarEvent.ID, MyCalendarEvent.Rigid, MyCalendarEvent.myLocation, MyCalendarEvent.RangeTimeLine);
                                break;
                            }
                        case "YEARLY":
                            {
                                MySubEvent = new SubCalendarEvent(MyCalendarEvent.ActiveDuration, MyCalendarEvent.Repeat.Range.Start.AddYears(1), MyCalendarEvent.Repeat.Range.End.AddYears(1), MyCalendarEvent.Preparation, MyCalendarEvent.ID, MyCalendarEvent.Rigid, MyCalendarEvent.myLocation, MyCalendarEvent.RangeTimeLine);
                                break;
                            }
                    }


                }
            }

            return MyCalendarEvent;
            //
        }
        public bool UpdateThis(SubCalendarEvent SubEventEntry)
        {
            if ((this.ID == SubEventEntry.ID)&&canExistWithinTimeLine(SubEventEntry.getCalendarEventRange))
            {
                StartDateTime= SubEventEntry.Start;
                EndDateTime= SubEventEntry.End;
                BusyFrame.updateBusyTimeLine(SubEventEntry.BusyFrame);
                AvailablePreceedingFreeSpace = SubEventEntry.AvailablePreceedingFreeSpace;
                RigidSchedule = SubEventEntry.Rigid;
                CalendarEventRange = SubEventEntry.CalendarEventRange;
                EventLocation = SubEventEntry.LocationData;
                Enabled = SubEventEntry.Enabled;
                ThirdPartyID = SubEventEntry.ThirdPartyID;
                return true;
            }

            throw new Exception("Error Detected: Trying to update SubCalendar Event with non matching ID");
        }
Example #18
0
        } // GenerateRandomMemoryMatrix()

        public SubCalendarEvent[] GenerateNeighborMemoryMatrix(SubCalendarEvent[] memoryMatrix)
        {
            SubCalendarEvent[] result = new SubCalendarEvent[memoryMatrix.Length];
            Array.Copy(memoryMatrix, result, memoryMatrix.Length);

            int Beginning = 0;
            int End = result.Length;

            switch (BeginningAndEnd)
            {
                case 1://must Beginning with City
                    {
                        Beginning = 1;
                        End = result.Length;
                    }
                    break;
                case 2://must End with City
                    {
                        Beginning = 0;
                        End = result.Length-1;
                    }
                    break;
                case 3://must end and Begin with Cities
                    {
                        Beginning = 1;
                        End = result.Length-1;
                    }
                    break;
                default:
                    { 
                        Beginning = 0;
                        End = result.Length;
                    }
                    break;
            }

            int ranIndex = random.Next(Beginning, End); // [0, Length-1] inclusive
            int adjIndex;
            if (ranIndex == End - 1)
                adjIndex = Beginning;
            else
                adjIndex = ranIndex + 1;

            SubCalendarEvent tmp = result[ranIndex];
            result[ranIndex] = result[adjIndex];
            result[adjIndex] = tmp;

            return result;
        } // GenerateNeighborMemoryMatrix()
Example #19
0
        static public double AverageToAllNodes(SubCalendarEvent MySubEvents, List<SubCalendarEvent> allSubCalEvents, Dictionary<string, List<Double>> DistanceMatrix)
        {
            double retValue = 0;

            List<string> AllIds = allSubCalEvents.Select(obj => obj.SubEvent_ID.getLevelID(0)).ToList();
            List<string> Allkeys = DistanceMatrix.Keys.ToList();
            string iIndex = MySubEvents.SubEvent_ID.getLevelID(0);
            int i = 0;
            
            while (i < allSubCalEvents.Count)
            {
                string jIndex = AllIds[i];
                int valueIndexofkeyValuePair = Allkeys.IndexOf(jIndex);
                double increment = DistanceMatrix[iIndex][valueIndexofkeyValuePair];

                retValue += increment;
                i++;
            }

            retValue /= allSubCalEvents.Count;
            return retValue;
        }
Example #20
0
 private SubCalendarEvent AssignSubEventTimeSlot(SubCalendarEvent MySubEvent)
 {
     BusyTimeLine[] ArrayOfInvadingEvents = CheckIfMyRangeAlreadyHasSchedule(CompleteSchedule.OccupiedSlots, MySubEvent);
     TimeLine[] AvailableFreeSpots = getAllFreeSpots(new TimeLine(MySubEvent.Start, MySubEvent.End));
     for (int i = 0; i < AvailableFreeSpots.Length; i++)
     {
         if (AvailableFreeSpots[i].TimelineSpan > (MySubEvent.ActiveDuration))
         {
             DateTime DurationStartTime;
             TimeSpan MyTimeSpan = new TimeSpan((((AvailableFreeSpots[i].TimelineSpan - MySubEvent.ActiveDuration).Milliseconds) / 2) * 10000);
             DurationStartTime = AvailableFreeSpots[i].Start.Add(MyTimeSpan);
             MySubEvent.ActiveSlot = new BusyTimeLine(MySubEvent.ID, DurationStartTime, DurationStartTime.Add(MySubEvent.ActiveDuration));
         }
     }
     return MySubEvent;
 }
Example #21
0
        } // TravelingSalesmanHive ctor


        public SubCalendarEvent[] GenerateRandomMemoryMatrix()
        {
            SubCalendarEvent[] result = new SubCalendarEvent[this.citiesData.cities.Length]; // // problem-specific
            
            
            //Dictionary<string, int> DictCount = new Dictionary<string, int>();
            Dictionary<string, List<SubCalendarEvent>> DictCities = new Dictionary<string, List<SubCalendarEvent>>();

            for (int j = 0; j < this.citiesData.cities.Length; j++)
            {
                if (DictCities.ContainsKey(this.citiesData.cities[j].SubEvent_ID.getLevelID(0)))
                {
                    //++DictCount[this.citiesData.cities[j].SubEvent_ID.getLevelID(0)];
                    DictCities[this.citiesData.cities[j].SubEvent_ID.getLevelID(0)].Add(this.citiesData.cities[j]);
                }
                else
                {
                    //DictCount.Add(this.citiesData.cities[j].SubEvent_ID.getLevelID(0), 1);
                    DictCities.Add(this.citiesData.cities[j].SubEvent_ID.getLevelID(0), new List<SubCalendarEvent>() { this.citiesData.cities[j] });
                }
            }

            
            int resultIndex = 0;
            int MaxResultIndex=this.citiesData.cities.Length;
            switch (BeginningAndEnd)
            {
                case 1://must Beginning with City
                    {
                        result[0] = this.citiesData.cities[0];
                        string ConcernedIndex = result[0].SubEvent_ID.getLevelID(0);
                        DictCities[ConcernedIndex].Remove(result[0]);
                        if (DictCities[ConcernedIndex].Count < 1)
                        {
                            DictCities.Remove(ConcernedIndex);
                        }
                        resultIndex=1;
                    }
                    break;
                case 2://must End with City
                    {
                        result[this.citiesData.cities.Length - 1] = this.citiesData.cities[this.citiesData.cities.Length - 1];
                        string ConcernedIndex = result[this.citiesData.cities.Length - 1].SubEvent_ID.getLevelID(0);
                        DictCities[ConcernedIndex].Remove(result[this.citiesData.cities.Length - 1]);
                        if (DictCities[ConcernedIndex].Count < 1)
                        {
                            DictCities.Remove(ConcernedIndex);
                        }
                        MaxResultIndex-=1;
                    }
                    break;
                case 3://must end and Begin with Cities
                    {
                        result[0] = this.citiesData.cities[0];
                        resultIndex=1;
                        result[this.citiesData.cities.Length - 1] = this.citiesData.cities[this.citiesData.cities.Length - 1];
                        MaxResultIndex-=1;

                        string ConcernedIndex=result[0].SubEvent_ID.getLevelID(0);
                        DictCities[ConcernedIndex].Remove(result[0]);
                        if (DictCities[ConcernedIndex].Count < 1)
                        {
                            DictCities.Remove(ConcernedIndex);
                        }
                        ConcernedIndex = result[this.citiesData.cities.Length - 1].SubEvent_ID.getLevelID(0);
                        DictCities[ConcernedIndex].Remove(result[this.citiesData.cities.Length - 1]);
                        if (DictCities[ConcernedIndex].Count < 1)
                        {
                            DictCities.Remove(ConcernedIndex);
                        }
                    }
                    break;
                default:
                    {
                        ;
                    }
                    break;
            }


            List<string> AllNodeNames = DictCities.Keys.ToList();
            List<string> ResultName = new List<string>();

            while (resultIndex < MaxResultIndex)
            {
                for (int i = 0; i < AllNodeNames.Count; i++) // Fisher-Yates (Knuth) shuffle
                {
                    int r = random.Next(i, AllNodeNames.Count);
                    SubCalendarEvent temp;

                    if (DictCities[AllNodeNames[r]].Count > 0)
                    {
                        string sTemp = AllNodeNames[r];
                        AllNodeNames[r] = AllNodeNames[i];
                        AllNodeNames[i] = sTemp;
                        temp = DictCities[sTemp][0];
                        DictCities[sTemp].RemoveAt(0);
                        result[resultIndex++] = temp;
                        //result[i] = temp;
                        if (DictCities[sTemp].Count < 1)
                        {
                            DictCities.Remove(sTemp);
                            AllNodeNames.Remove(sTemp);
                            --i;
                        }
                    }
                    else
                    {
                        ;
                    }
                    /*//SubCalendarEvent temp = result[r];
                    result[r] = result[i];
                    result[i] = temp;*/
                }



            }





            /*
            Array.Copy(this.citiesData.cities, result, this.citiesData.cities.Length);

            for (int i = 0; i < result.Length; i++) // Fisher-Yates (Knuth) shuffle
            {
                int r = random.Next(i, result.Length);
                SubCalendarEvent temp = result[r]; 
                result[r] = result[i]; 
                result[i] = temp;
            }*/
            return result;
        } // GenerateRandomMemoryMatrix()
        /*public ClumpSubCalendarEvent(List<SubCalendarEvent> BaseClump, List<SubCalendarEvent> Appendables, TimeLine BoundaryTimeLine)
        {
            int i = 0;
            NonOverLapping_Clump = new List<ClumpSubCalendarEvent>();
            OverLapping_Clump = new List<ClumpSubCalendarEvent>();
            List<SubCalendarEvent> UnClumppable = new List<SubCalendarEvent>();
            if (BaseClump.Count < 1)
            {
                if (Appendables.Count > 0)
                {
                    Appendables = Appendables.OrderBy(obj => obj.getCalendarEventRange.End).ToList();
                    SubCalendarEvent RelativeSubEvent = Appendables[0];
                    Appendables.Remove(Appendables[0]);
                    ClumpSubCalendarEvent myThis = new ClumpSubCalendarEvent(RelativeSubEvent, Appendables, BoundaryTimeLine);
                    NonOverLapping_Clump = myThis.NonOverLapping_Clump;
                    BaseEvent = myThis.BaseEvent;
                    NonOverLapping_Clump = myThis.NonOverLapping_Clump;
                    OverLapping_Clump = myThis.OverLapping_Clump;
                    ReferenceStartTime = myThis.ReferenceStartTime;
                    SubCalEventsOverLapWithBase = myThis.SubCalEventsOverLapWithBase;
                    BreakOffClump = myThis.BreakOffClump;

                }

            }
            else
            {
                BaseEvent = BaseClump[0];//this can be reevaluated to cater to the most constrained. i.e the one with limted a later sart time and percentage fill for whatever is left.
                ReferenceStartTime = BaseEvent.getCalendarEventRange.End < BoundaryTimeLine.End ? BaseEvent.getCalendarEventRange.End : BoundaryTimeLine.End;
                foreach (SubCalendarEvent mySubCalendarEvent in BaseClump)
                {
                    ReferenceStartTime -= BaseEvent.ActiveDuration;
                }

                for (; i < Appendables.Count; i++)
                {

                    List<SubCalendarEvent> ReferenceClump = new List<SubCalendarEvent>(BaseClump);
                    DateTime TimeLimit = ReferenceStartTime - Appendables[i].ActiveDuration;
                    bool Zero = (Appendables[i].getCalendarEventRange.Start <= TimeLimit);
                    bool One = (TimeLimit >= BoundaryTimeLine.Start);
                    //bool Two = (BoundaryTimeLine.TimelineSpan >= Appendables[i].EventTimeLine.TimelineSpan);

                    if (Zero && One)// && Two)
                    {
                        List<SubCalendarEvent> Removed_Unnecessary = Appendables.ToList();
                        List<SubCalendarEvent> ExtendedList = ReferenceClump.ToList();
                        Removed_Unnecessary.Remove(Appendables[i]);
                        ExtendedList.Add((Appendables[i]));
                        ClumpSubCalendarEvent NewClump = new ClumpSubCalendarEvent(ExtendedList, Removed_Unnecessary, BoundaryTimeLine);
                        NonOverLapping_Clump.Add(NewClump);
                        if (CompleteResolvedNonOverlapping.Count > 100)//This is a hack to resolve the memory issue
                        {
                            break;
                        }
                    }
                    else
                    {
                        SubCalEventsOverLapWithBase.Add(Appendables[i]);
                    }

                    if (SubCalEventsOverLapWithBase.Count > 0)
                    {
                        SubCalendarEvent BreakOffSubCalEvent = SubCalEventsOverLapWithBase[0];
                        SubCalEventsOverLapWithBase.Remove(BreakOffSubCalEvent);
                        BreakOffClump = new ClumpSubCalendarEvent(BreakOffSubCalEvent, SubCalEventsOverLapWithBase, new TimeLine((getLeftMostPossibleStartLine(BaseEvent, BoundaryTimeLine) + BaseEvent.ActiveDuration), BoundaryTimeLine.End));
                    }

                }
            }
        }*/
        DateTime getLeftMostPossibleStartLine(SubCalendarEvent Sorted, TimeLine Boundary)
        {
            if (Boundary.Start >= Sorted.getCalendarEventRange.Start)
            {
                return new DateTime(Boundary.Start.Ticks);
            }
            else
            {
                return new DateTime(Sorted.getCalendarEventRange.Start.Ticks);
            }
        }
Example #23
0
        } // GenerateNeighborMemoryMatrix()

        public double MeasureOfQuality(SubCalendarEvent[] memoryMatrix)
        {
            double answer = 0.0;
            for (int i = 0; i < memoryMatrix.Length - 1; ++i)
            {
                SubCalendarEvent c1 = memoryMatrix[i];
                SubCalendarEvent c2 = memoryMatrix[i + 1];
                double d = this.citiesData.Distance(c1, c2);
                answer += d;
            }
            return answer;
        } // MeasureOfQuality()
 ClumpSubCalendarEvent populateClumpedResults(DateTime BaseEndTime,SubCalendarEvent refSubCalendarEvent, ClumpSubCalendarEvent refClumpSubCalendarEvent, DateTime RefereceStartTime, TimeLine BoundaryTimeLine)
 {
     List<SubCalendarEvent> Arg1 = ClumpedResults.Keys.ToList();
     bool temp = Arg1.Remove(refSubCalendarEvent);
     refClumpSubCalendarEvent = new ClumpSubCalendarEvent(RefereceStartTime,BaseEndTime, Arg1, BoundaryTimeLine);
     return refClumpSubCalendarEvent;
 }
Example #25
0
 public Coordinate(int name, SubCalendarEvent MyEvent)
 {
     Name = name;
     Event = MyEvent;
     ID = MyEvent.SubEvent_ID.getStringIDAtLevel(0);
 }
        public ClumpSubCalendarEvent(SubCalendarEvent BaseSubCalendarEvent, List<SubCalendarEvent> Appendables, TimeLine BoundaryTimeLine)
        {
            SubCalEventsOverLapWithBase = new List<SubCalendarEvent>();

            BaseEvent = BaseSubCalendarEvent;
            DateTime var1 = BaseEvent.getCalendarEventRange.End < BoundaryTimeLine.End ? BaseEvent.getCalendarEventRange.End : BoundaryTimeLine.End;//hack assumes base can fit within boundary
            this.BoundaryTimeLine = new TimeLine(BoundaryTimeLine.Start, var1);
            DateTime  ReferenceStartTime = var1 - BaseEvent.ActiveDuration;
            BreakOffClump = null;
            ClumpedResults = new Dictionary<SubCalendarEvent, ClumpSubCalendarEvent>();
            int i = 0;
            for (; i < Appendables.Count; i++)
            {
                List<SubCalendarEvent> ReferenceClump = new List<SubCalendarEvent>();
                ReferenceClump.Add(BaseSubCalendarEvent);
                DateTime TimeLimit = ReferenceStartTime - Appendables[i].ActiveDuration;
                bool Zero = (Appendables[i].getCalendarEventRange.Start <= TimeLimit);
                bool One = (TimeLimit >= BoundaryTimeLine.Start);
                //bool Two = (BoundaryTimeLine.TimelineSpan>=Appendables[i].EventTimeLine.TimelineSpan);//this is a hack, since the length of SubcalEvent Event TimeLine is the same length of time as its busy time span

                if (Zero && One)// && Two)
                {
                    List<SubCalendarEvent> Removed_Unnecessary = Appendables.ToList();
            //                    List<SubCalendarEvent> ExtendedList = ReferenceClump.ToList();
                    SubCalendarEvent RelativeSubEvent = Appendables[i];

                    Removed_Unnecessary.Remove(RelativeSubEvent);

              //                  ExtendedList.Add((Appendables[i]));
                    ClumpedResults.Add(RelativeSubEvent, null);

                    //NonOverLapping_Clump.Add();
                    if (Removed_Unnecessary.Count > 0)
                    {

                        ++Completed;
                        if (Completed >= 100)
                        {
                            break;
                        }
                    }
                }
                else
                {
                    //List<SubCalendarEvent> Removed_Unnecessary = Appendables.ToList();
                    //List<SubCalendarEvent> ExtendedList = ReferenceClump.ToList();
                    //Removed_Unnecessary.Remove(Appendables[i]);
                    SubCalEventsOverLapWithBase.Add(Appendables[i]);
                }
            }

            List<SubCalendarEvent> arg1=ClumpedResults.Keys.ToList();
            //if(arg1!=null)
            {
                int j=0;
                DateTime BaseReferenceEndTime = BaseEvent.getCalendarEventRange.End > BoundaryTimeLine.End ? BoundaryTimeLine.End : BaseEvent.getCalendarEventRange.End;//End Time for Base to be used as the reference for the current base end time
                for (;j<arg1.Count;j++)
                {

                    ClumpedResults[arg1[j]] = populateClumpedResults(BaseReferenceEndTime, arg1[j], ClumpedResults[arg1[j]], ReferenceStartTime - arg1[j].ActiveDuration, BoundaryTimeLine);
                }

            }

            if (SubCalEventsOverLapWithBase.Count > 0)
            {
                SubCalendarEvent BreakOffSubCalEvent = SubCalEventsOverLapWithBase[0];
                SubCalEventsOverLapWithBase.Remove(BreakOffSubCalEvent);
                BreakOffClump = new ClumpSubCalendarEvent(BreakOffSubCalEvent, SubCalEventsOverLapWithBase, new TimeLine((getLeftMostPossibleStartLine(BaseEvent, BoundaryTimeLine) + BaseEvent.ActiveDuration), BoundaryTimeLine.End));
            }
            List<SubCalendarEvent> Fittable = new List<SubCalendarEvent>();
        }
Example #27
0
        virtual public bool updateSubEvent(EventID SubEventID,SubCalendarEvent UpdatedSubEvent)
        {
            if (this.RepetitionStatus)
            {
                foreach (CalendarEvent MyCalendarEvent in Repeat.RecurringCalendarEvents)
                {
                    if (MyCalendarEvent.updateSubEvent(SubEventID, UpdatedSubEvent))
                    {
                        return true;
                    }
                }
            }
            else 
            {
                int i = 0;
                for (i = 0; i < ArrayOfSubEvents.Length;i++)
                {
                    if (ArrayOfSubEvents[i].ID == SubEventID.ToString())
                    {
                        SubCalendarEvent NewSubCalEvent = new SubCalendarEvent(UpdatedSubEvent.ID, UpdatedSubEvent.Start, UpdatedSubEvent.End, UpdatedSubEvent.ActiveSlot, UpdatedSubEvent.Rigid, UpdatedSubEvent.myLocation, this.RangeTimeLine);
                        string thirdPartyID = ArrayOfSubEvents[i].ThirdPartyID;
                        ArrayOfSubEvents[i] = NewSubCalEvent;
                        ArrayOfSubEvents[i].ThirdPartyID = thirdPartyID;
                        return true;
                    }
                }
            }

            return false;
        }
 public static double CalculateDistance(SubCalendarEvent Arg1,SubCalendarEvent Arg2)
 {
     if(Arg1.SubEvent_ID.getStringIDAtLevel(0)==Arg1.SubEvent_ID.getStringIDAtLevel(0))
     {
         return double.MaxValue;
     }
     else
     {
         return Location.calculateDistance(Arg1.myLocation,Arg2.myLocation);
     }
 }
Example #29
0
 public CalendarEvent(CalendarEvent MyUpdated, SubCalendarEvent[] MySubEvents)
 {
     CalendarEventName = MyUpdated.Name;
     
     StartDateTime = MyUpdated.StartDateTime;
     EndDateTime = MyUpdated.End;
     EventSequence = new TimeLine(StartDateTime, EndDateTime);
     EventDuration = MyUpdated.ActiveDuration;
     Splits = MyUpdated.Splits;
     PrepTime = MyUpdated.PrepTime;
     EventPreDeadline = MyUpdated.PreDeadline;
     RigidSchedule = MyUpdated.Rigid;
     TimePerSplit = MyUpdated.TimePerSplit;
     ArrayOfSubEvents = new SubCalendarEvent[Splits];
     if (MyUpdated.ID != null)
     {
         CalendarEventID = new EventID(MyUpdated.ID.Split('_'));
     }
     //CalendarEventID = new EventID(new string[] { EventIDGenerator.generate().ToString() });
     //ArrayOfSubEvents = generateSubEvent(ArrayOfSubEvents, 4, EventDuration, CalendarEventID.ToString());
     ArrayOfSubEvents = MySubEvents;
     SchedulStatus = false;
     EventRepetition = MyUpdated.Repeat;
     LocationData = MyUpdated.LocationData;
     UpdateLocationMatrix(LocationData);
     EventSequence = new TimeLine(StartDateTime, EndDateTime);
     //EventRepetition = new Repetition(EventRepetition.Enable, this, EventRepetition.Range, EventRepetition.Frequency);
 }
 public static int CompareByEndDate(SubCalendarEvent SubCalendarEvent1, SubCalendarEvent SubCalendarEvent2)
 {
     return SubCalendarEvent1.End.CompareTo(SubCalendarEvent2.End);
 }