public Employee[] createSchedule2() //create the schedule { if (isSchedulePos()) { EmployeeQueue empQue = new EmployeeQueue(emp); Queue <Employee> que = empQue.queueRandom(rand); long brokenCount = 0; for (int w = 0; w < getWorkWeek(); w++) { for (int p = 0; p < posit.Length; p++) { for (int l = 0; l < sTime.Length; l++) { for (int z = 0; z < empPerShift()[w, p]; z++) { bool shiftFilled = false; bool checkDoubles = false; do { Employee tempEmployee = que.Dequeue(); if (tempEmployee.getName().Equals("Alex Four")) { shiftFilled = false; int a = 1; a++; } if (tempEmployee.isWork(w, sTime[l], posit[p], checkDoubles, hour[p])) { foreach (Employee e in emp) { if (e.getName().Equals(tempEmployee.getName())) { e.setSche(w, sTime[l], posit[p]); shiftFilled = true; } } } if (que.Count == 0 && !shiftFilled) { brokenCount++; if (brokenCount > 1000) { return(null); } que = empQue.queueRandom(rand); checkDoubles = true; int b = 0; int totalEmployeesPosition = 0; foreach (Employee e in emp) { int a = 0; foreach (String positions in e.getPositions()) { if (positions.Equals(posit[p])) { totalEmployeesPosition++; foreach (String s in e.getSchedule()) { if (!s.Equals("None")) { a += s.Split('/').Length; if (a == hour[p]) { b++; } } } } } } if (b == totalEmployeesPosition) { hour[p]++; } } if (shiftFilled) { que = empQue.queueRandom(rand); } } while (!shiftFilled); } } } } } return(emp); }
public Employee[] createSched() //create schedule by week volume { if (isSchedulePos()) { EmployeeQueue empQue = new EmployeeQueue(emp); Queue <Employee> que = empQue.queueRandom(rand); long brokenCount = 0; foreach (int i in getWeek()) { for (int x = 0; x < posit.Length; x++) { for (int y = 0; y < sTime.Length; y++) { for (int z = 0; z < empPerShift()[i, x]; z++) { bool shiftFilled = false; bool checkDoubles = false; do { Employee tempEmp = que.Dequeue(); if (tempEmp.getName().Equals("Alex Four")) { shiftFilled = false; int a = 1; a++; } if (tempEmp.isWork(i, sTime[y], posit[x], checkDoubles, hour[x])) { foreach (Employee e in emp) { if (e.getName().Equals(tempEmp.getName())) { e.setSche(i, sTime[y], posit[x]); shiftFilled = true; } } } if (que.Count == 0 && !shiftFilled) { brokenCount++; if (brokenCount > 1000) { return(null); } que = empQue.queueRandom(rand); checkDoubles = true; int b = 0; int totalEmployeesPosition = 0; foreach (Employee e in emp) { int a = 0; foreach (String positions in e.getPositions()) { if (positions.Equals(posit[x])) { totalEmployeesPosition++; foreach (String s in e.getSchedule()) { if (!s.Equals("None")) { a += s.Split('/').Length; if (a == hour[x]) { b++; } } } } } } if (b == totalEmployeesPosition) { hour[x]++; } } if (shiftFilled) { que = empQue.queueRandom(rand); } } while (!shiftFilled); } } } } } return(emp); }