} // enoughTimeInDay public bool hasEventBeenScheduled(Event e) { int numberTimesScheduled = chromosome.FindAll(delegate(Gene g) { return(g.getEvent() == e); }).Count; int expectedNumberOfTimes = Program.events.FindAll(delegate(Event evt) { return(evt == e); }).Count *e.getDuration(); if (e.getWeekly()) { expectedNumberOfTimes *= 2; } if (numberTimesScheduled == expectedNumberOfTimes) { return(true); } else { return(false); } } // hasEventBeenScheduled
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); }
} // 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
public bool hasEventBeenScheduled(Event e) { int numberTimesScheduled = chromosome.FindAll(delegate(Gene g) { return g.getEvent() == e; }).Count; int expectedNumberOfTimes = Program.events.FindAll(delegate(Event evt) { return evt == e; }).Count * e.getDuration(); if (e.getWeekly()) expectedNumberOfTimes *= 2; if (numberTimesScheduled == expectedNumberOfTimes) return true; else return false; }