public Gene() { this.slot = new Slot(); this.evt = new Event(); this.room = new Room(); cannotChange = false; }
public Gene(Slot slot, Event evt, Room room, bool cannotChange) { this.slot = slot; this.evt = evt; this.room = room; this.cannotChange = cannotChange; }
/* Checks for any clashes between groups and rooms for a particular slot */ public bool doClashesExist(Slot s, Event e, Room r) { int indexOfSelectedSlot = Program.slots.IndexOf(s); bool clashes = false; int i = 0; // ensure there are no index out of bound errors if ((indexOfSelectedSlot + e.getDuration()) >= Program.slots.Count) clashes = true; /* Check that there are no clashes for any hours of the event */ while ((i < e.getDuration()) && (!clashes)) { List<Gene> eventsAtThisTime = new List<Gene>(); foreach (Gene g in chromosome) { if (g.getSlot() == s) eventsAtThisTime.Add(g); } int j = 0; while ((j < eventsAtThisTime.Count) && (!clashes)) { if ((eventsAtThisTime[j].getEvent().getGroups().Intersect(e.getGroups()).Count() > 0) || (eventsAtThisTime[j].getRoom() == r && r != Program.lunchRoom)) clashes = true; j++; } s = Program.slots[++indexOfSelectedSlot]; i++; } return clashes; }
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; }
public SlotEventGroupsKey(Slot slot, string[] groups) { this.slot = slot; this.groups = groups.ToList(); }
private void scheduleLists(Slot s, List<Gene> p1, List<Gene> p2, Chromosome child) { List<Gene> combinedList = new List<Gene>(); combinedList.AddRange(p1.Intersect(p2)); foreach (Gene g in combinedList) { if (p1.Contains(g)) p1.Remove(g); if (p2.Contains(g)) p2.Contains(g); } combinedList.AddRange(p1); combinedList.AddRange(p2); combinedList.RemoveAll(delegate(Gene g) { return g.getCannotChange() == true || g.getEvent().getCourse() == "Lunch"; }); combinedList.Reverse(); for (int i = combinedList.Count; i > 0; i--) { bool success = child.scheduleEventFromList(s, combinedList[i - 1]); if (!success) child.unscheduableEvents.Add(combinedList[i - 1].getEvent()); combinedList.Remove(combinedList[i - 1]); } child.scheduleUnscheduableEvents(s); }
public void setSlot(Slot newSlot) { slot = Program.slots[Program.slots.IndexOf(newSlot)]; }
/* this method is required as some places the chromosome is viewed * as a Chromosome instead of a List<Gene> */ public void add(Slot s, Event e, Room r, bool cannotChange) { chromosome.Add(new Gene(s, e, r, cannotChange)); }
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())); } }
public void scheduleUnscheduableEvents(Slot s) { Slot originalSlot = s; for (int i = unscheduableEvents.Count; i > 0; i--) { s = originalSlot; if (hasEventBeenScheduled(unscheduableEvents[i - 1])) unscheduableEvents.Remove(unscheduableEvents[i - 1]); else { if (enoughTimeInDay(s, unscheduableEvents[i - 1])) { List<Room> possibleRooms = findAvailableRooms(unscheduableEvents[i - 1].getRoomSize(), unscheduableEvents[i - 1].getActivity()); bool stop = false; int j = 0; while ((j < possibleRooms.Count) && (!stop)) { bool clashes = doClashesExist(s, unscheduableEvents[i - 1], possibleRooms[j]); if (!clashes && unscheduableEvents[i-1].getWeekly()) clashes = doClashesExist(getCorrespondingSlot(s), unscheduableEvents[i-1], possibleRooms[j]); if (!clashes) { stop = true; Gene aGene = new Gene(s, unscheduableEvents[i-1], possibleRooms[j], unscheduableEvents[i-1].getWeekly()); bookSlots(s, aGene); } j++; } } } } }
public bool scheduleEventFromList(Slot s, Gene g) { if (!hasEventBeenScheduled(g.getEvent())) { bool clashes = doClashesExist(s, g.getEvent(), g.getRoom()); if (!clashes && g.getEvent().getWeekly()) clashes = doClashesExist(getCorrespondingSlot(s), g.getEvent(), g.getRoom()); if (!clashes && enoughTimeInDay(s, g.getEvent())) { bookSlots(s, g); return true; } else return false; } return true; }
public bool hasLunchBeenScheduled(Slot s, Event e) { int numberTimesScheduled = (from g in chromosome where g.getEvent() == e && g.getSlot().getDay() == s.getDay() select g).Count(); if (numberTimesScheduled == 1) return true; else return false; }
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()); }); }
public SlotEventGroupsKey(Slot slot, string[] groups) { this.slot = slot; this.groups = groups.ToList(); } // constructor