private void honorUserSchedules() { Set<String> toRemove = new HashSet<String>(); List<Work> unscheduled = new ArrayList<Work>(); for (Work work : works) { DriverContext driver = fetchDriver(work.getDriver()); if (driver == null) { unscheduled.add(work); continue; } toRemove.add(driver.getName()); schedules.addSchedule(createSchedule(work, driver)); } for (String driver : toRemove) drivers.remove(driver); works = unscheduled; }
private void doSchedule(Work work) { int driverNum = allocMap.length; int base = work.getWorkers() / driverNum; int extra = work.getWorkers() % driverNum; for (int i = 0; i < driverNum; i++) allocMap[i] = base; int lower = allocIdx; int upper = lower + extra; for (int i = lower; i < upper; i++) allocMap[i % driverNum]++; allocIdx = upper % driverNum; int idx = 0; int offset = 0; int workers = 0; for (DriverContext driver : drivers.values()) { if ((workers = allocMap[idx++]) == 0) continue; schedules.addSchedule(createSchedule(work, driver, offset, workers)); offset += workers; } }