private ShiftTable GenerateSchedule(ShiftTable OptionsTable, ShiftTable schedule) { ShiftTable weeklyShifts = new ShiftTable(this.weeklyShifts); GenerateScheduleRandomPass(OptionsTable, weeklyShifts, schedule); bool done = false; bool shiftAdded = false; int optionsNum = OptionsTable.tableSize(); while (!done) { shiftAdded = false; for (int i = 0; i < optionsNum; i++) { Shift option = OptionsTable.getShiftFromTable(i); if (weeklyShifts.shiftExists(option.getDay(), option.getBegin_Time(), option.getEnd_Time())) { if (schedule.optionLegal(option)) { schedule.AddShift(option); OptionsTable.RemoveShift(option); optionsNum--; weeklyShifts.RemoveShift(option.getDay(), option.getBegin_Time(), option.getEnd_Time()); shiftAdded = true; break; } } } // for () if (shiftAdded == false) { done = true; } } return schedule; }
private void GenerateScheduleRandomPass(ShiftTable OptionsTable, ShiftTable weeklyShifts, ShiftTable schedule) { Random rnd = new Random(); int optionsNum = OptionsTable.tableSize(); while (optionsNum > 0) { int i = rnd.Next(0, optionsNum); Shift option = OptionsTable.getShiftFromTable(i); if (weeklyShifts.shiftExists(option.getDay(), option.getBegin_Time(), option.getEnd_Time())) { if (schedule.optionLegal(option)) { schedule.AddShift(option); weeklyShifts.RemoveShift(option.getDay(), option.getBegin_Time(), option.getEnd_Time()); } } OptionsTable.RemoveShift(option); optionsNum--; } //while (optionsNum > 0)... }