Пример #1
0
        } // scheduleEventFromList

        private void bookSlots(Slot s, Gene g)
        {
            if (g.getEvent().getWeekly() && s.getWeek() == "B")
            {
                s = getCorrespondingSlot(s);
            }

            for (int i = 0; i < g.getEvent().getDuration(); i++)
            {
                int slotIndex = Program.slots.IndexOf(s);
                slotIndex += i;
                s          = Program.slots[slotIndex];
                chromosome.Add(new Gene(s, g.getEvent(), g.getRoom(), g.getCannotChange()));

                slotIndex = Program.slots.IndexOf(s);
                slotIndex++;
                if (slotIndex < Program.slots.Count)
                {
                    s = Program.slots[slotIndex];
                }

                if (g.getEvent().getWeekly())
                {
                    chromosome.Add(new Gene(s, g.getEvent(), g.getRoom(), g.getCannotChange()));
                }
            }
        }
Пример #2
0
        } // scheduleUnscheduableEvents

        public Slot getCorrespondingSlot(Slot selectedSlot)
        {
            return(Program.slots.Find(delegate(Slot compareSlot)
            {
                return (compareSlot.getDay() == selectedSlot.getDay() &&
                        compareSlot.getTime() == selectedSlot.getTime() &&
                        compareSlot.getWeek() != selectedSlot.getWeek());
            }));
        } // getCorrespondingSlot
Пример #3
0
        } // getCorrespondingSlot

        public bool enoughTimeInDay(Slot s, Event e)
        {
            List <Slot> remainingSlotsInDay = new List <Slot>();

            for (int i = 0; i < Program.slots.Count; i++)
            {
                if ((Program.slots[i].getDay() == s.getDay()) && (Program.slots[i].getWeek() == s.getWeek()))
                {
                    remainingSlotsInDay.Add(Program.slots[i]);
                }
            }

            if (((remainingSlotsInDay.IndexOf(s) + e.getDuration()) > remainingSlotsInDay.Count))
            {
                return(false);
            }
            else
            {
                return(true);
            }
        } // enoughTimeInDay
Пример #4
0
        } // findAvailableRooms

        public void scheduleEvent(Event e)
        {
            /* Choose a random slot to attempt to schedule this event in */
            Slot selectedSlot = Program.slots[random.Next(Program.slots.Count)];

            if (e.getWeekly() && selectedSlot.getWeek() == "B")
            {
                selectedSlot = getCorrespondingSlot(selectedSlot);
            }

            List <Room> availableRooms = findAvailableRooms(e.getRoomSize(), e.getActivity());
            Room        selectedRoom   = null;

            bool scheduable = false;

            /* If there is enough time remaining in the day to schedule this event
             * at this slot, try to find a room that is available and does not cause
             * a clash */
            if (enoughTimeInDay(selectedSlot, e))
            {
                int i = 0;
                while ((i < availableRooms.Count) && (!scheduable))
                {
                    selectedRoom = availableRooms[i];
                    bool clashes = doClashesExist(selectedSlot, e, selectedRoom);
                    if (!clashes && e.getWeekly())
                    {
                        clashes = doClashesExist(getCorrespondingSlot(selectedSlot), e, selectedRoom);
                    }
                    if (!clashes)
                    {
                        scheduable = true;
                    }
                    i++;
                }
            }

            /* if this random slot is not feasible then go from this slot + 1 to the end of the
             * slots list trying to schedule this event in each slot */
            if (!scheduable)
            {
                int selectedSlotIndex = Program.slots.IndexOf(selectedSlot);
                int i = selectedSlotIndex + 2;
                while ((i < Program.slots.Count) && (!scheduable))
                {
                    selectedSlot = Program.slots[i];
                    if (enoughTimeInDay(selectedSlot, e))
                    {
                        int j = 0;
                        while ((j < availableRooms.Count) && (!scheduable))
                        {
                            selectedRoom = availableRooms[j];
                            bool clashes = doClashesExist(selectedSlot, e, selectedRoom);
                            if (!clashes && e.getWeekly())
                            {
                                clashes = doClashesExist(getCorrespondingSlot(selectedSlot), e, selectedRoom);
                            }
                            if (!clashes)
                            {
                                scheduable = true;
                            }
                            j++;
                        }
                    }
                    i += 2;
                }

                /* go from the beginning of the slots to the slot that was initially chosen - 1
                 * only if a slot hasn't been found */
                if (!scheduable)
                {
                    i = 0;
                    while ((i < selectedSlotIndex) && (!scheduable))
                    {
                        selectedSlot = Program.slots[i];
                        if (enoughTimeInDay(selectedSlot, e))
                        {
                            int j = 0;
                            while ((j < availableRooms.Count) && (!scheduable))
                            {
                                selectedRoom = availableRooms[j];
                                bool clashes = doClashesExist(selectedSlot, e, selectedRoom);
                                if (!clashes && e.getWeekly())
                                {
                                    clashes = doClashesExist(getCorrespondingSlot(selectedSlot), e, selectedRoom);
                                }
                                if (!clashes)
                                {
                                    scheduable = true;
                                }
                                j++;
                            }
                        }
                        i += 2;
                    }
                }
            }

            if (scheduable)
            {
                Gene aGene = new Gene(selectedSlot, e, selectedRoom, false);
                bookSlots(selectedSlot, aGene);
            }
            else
            {
                unscheduableEvents.Add(e);
            }
        } // scheduleEvent
Пример #5
0
        public bool enoughTimeInDay(Slot s, Event e)
        {
            List<Slot> remainingSlotsInDay = new List<Slot>();
              for (int i = 0; i < Program.slots.Count; i++)
              {
            if ((Program.slots[i].getDay() == s.getDay()) && (Program.slots[i].getWeek() == s.getWeek()))
              remainingSlotsInDay.Add(Program.slots[i]);
              }

              if (((remainingSlotsInDay.IndexOf(s) + e.getDuration()) > remainingSlotsInDay.Count))
            return false;
              else
            return true;
        }
Пример #6
0
        private void bookSlots(Slot s, Gene g)
        {
            if (g.getEvent().getWeekly() && s.getWeek() == "B")
            s = getCorrespondingSlot(s);

              for (int i = 0; i < g.getEvent().getDuration(); i++)
              {
            int slotIndex = Program.slots.IndexOf(s);
            slotIndex += i;
            s = Program.slots[slotIndex];
            chromosome.Add(new Gene(s, g.getEvent(), g.getRoom(), g.getCannotChange()));

            slotIndex = Program.slots.IndexOf(s);
            slotIndex++;
            if (slotIndex < Program.slots.Count)
              s = Program.slots[slotIndex];

            if (g.getEvent().getWeekly())
              chromosome.Add(new Gene(s, g.getEvent(), g.getRoom(), g.getCannotChange()));
              }
        }
Пример #7
0
 public Slot getCorrespondingSlot(Slot selectedSlot)
 {
     return Program.slots.Find(delegate(Slot compareSlot)
                                       {
                                         return (compareSlot.getDay() == selectedSlot.getDay() &&
                                         compareSlot.getTime() == selectedSlot.getTime() &&
                                         compareSlot.getWeek() != selectedSlot.getWeek());
                                       });
 }