void TestTimeList()
        {
            List<Event> ListOfEvents = new List<Event>();
            Event Event1 = new Event();
            Event Event2 = new Event();
            Event1.Name = "Tiskaus";
            Event2.Name = "Sali";
            Event1.StartTime = new DateTime(2013, 3, 12, 11, 0, 0);
            Event1.EndTime = new DateTime(2013, 3, 12, 12, 0, 0);
            Event2.StartTime = new DateTime(2013, 3, 12, 14, 0, 0);
            Event2.EndTime = new DateTime(2013, 3, 12, 14, 30, 0);

            ListOfEvents.Add(Event1);
            ListOfEvents.Add(Event2);

            TimeList ListOfTimes = new TimeList(ListOfEvents);

            Debug.WriteLine(ListOfTimes.GetTimeIndex(60));
            Debug.WriteLine(ListOfTimes.GetTimeIndex(90));
            Debug.WriteLine(ListOfTimes.GetTimeIndex(75));
        }
Exemple #2
0
        public Algo(List<Event> pEventList, TodoList pTodoList, Action pCallback)
        {
            //aikaa_kaikelle = kuinka paljon aikaa tarvitaan kaikkien listassa olevien toteutukseen
            todolist = pTodoList;

            PopulateSorting();

            //tee timelist
            timelist = new TimeList(pEventList);

            // OPERATE
            // NOW => PANIC
            TodoEvent now = GetNextASAP();
            while (now != null) {
                Panic(now);
                now = GetNextASAP();
            }

            //for DL in DLs
            TodoEvent dl = GetNextDL();
            while (dl != null) {
                //	timeRqd = DL.Duration() * 3/2
                int time_required = (int)dl.Required.TotalMinutes;
                //	counter = timeRqd * 2
                int counter = time_required * 2;

                // deadlinen index, puolitettu tarvittaessa
                int end_index = timelist.GetTimeIndex(dl.GetTimeToDeadline());

                // start_index iteroidaan alaspäin
                int start_index = end_index - 1;
                // kuinka paljon tultiin alaspäin
                int duration = 0;

                while (start_index > 0) {
                    TimeList.Time element = timelist.GetElement(start_index);
                    // lisätään jokatapauksessa duration
                    duration += (int)element.Span.TotalMinutes;
                    // jos saadaan lisää tyhjää aikaa
                    if (element.Priority == Priority.FREE) {
                        counter -= (int)element.Span.TotalMinutes;
                    }
                    // jos tultiin tarpeeksi pitkälle
                    if (counter < 0) {
                        duration += counter;
                        int start_instance = dl.GetTimeToDeadline() - duration;
                        start_index = timelist.GetTimeIndex(start_instance);
                    }
                }
                if (timelist.GetTimeBetween(start_index, end_index) < time_required) {
                    Panic(dl);
                }
                TimeList list_dl = CropAndSort(start_index, end_index, timelist);
                Position(dl, list_dl);

                dl = GetNextDL();
            } // LOOP WHILE THERE IS DL

            // sijoita ensin continuous
            foreach (TodoEvent te in sortedLazy) {
                if (!te.Split) {
                    Position(te, timelist);
                }
            }
            // sijoita sitten jaettavat
            foreach (TodoEvent te in sortedLazy) {
                if (te.Split) {
                    Position(te, timelist);
                }
            }

            pCallback.Invoke();
        }