diff --git a/Travail_de_session/InitialSchedules/ModelInitialSchedules.java b/Travail_de_session/InitialSchedules/ModelInitialSchedules.java index f899b7f..4e22544 100644 --- a/Travail_de_session/InitialSchedules/ModelInitialSchedules.java +++ b/Travail_de_session/InitialSchedules/ModelInitialSchedules.java @@ -114,7 +114,7 @@ public class ModelInitialSchedules { 0, this.maxPartTimeEmployee + this.maxFullTimeEmployee, true); // Variable pour les périodes de travail par jour des travailleurs à temps partiel - this.workPeriodsOfPartTimeEmployees = chocoModelInitialSchedules.boolVarMatrix(this.maxPartTimeEmployee * this.myScheduleParameters.daysPerSchedule + /*this.workPeriodsOfPartTimeEmployees = chocoModelInitialSchedules.boolVarMatrix(this.maxPartTimeEmployee * this.myScheduleParameters.daysPerSchedule , this.myScheduleParameters.workPeriodsPerDay); for (int employee = 0; employee < this.maxPartTimeEmployee; employee++) { @@ -125,7 +125,7 @@ public class ModelInitialSchedules { 0, this.myScheduleParameters.workPeriodsPerDay); } - } + }*/ } private void createModelConstraints() { @@ -136,8 +136,14 @@ public class ModelInitialSchedules { this.myScheduleParameters.enumerationWorkPeriodsSchedulesOfFullTimeEmployees).post(); } - // Constraintes pour compter le nombre d'heures travaillees par les differents employes for (int employee = 0; employee < this.maxPartTimeEmployee; employee++) { + chocoModelInitialSchedules.table(this.workPeriodsSchedulesOfPartTimeEmployees[employee], + this.myScheduleParameters.enumerationWorkPeriodsSchedulesOfPartTimeEmployees).post(); + } + + + // Constraintes pour compter le nombre d'heures travaillees par les differents employes + /*for (int employee = 0; employee < this.maxPartTimeEmployee; employee++) { chocoModelInitialSchedules.count(chocoModelInitialSchedules.intVar(1), this.workPeriodsSchedulesOfPartTimeEmployees[employee], this.workingPeriodsPerPartTimeEmployees[employee]).post(); @@ -146,7 +152,7 @@ public class ModelInitialSchedules { chocoModelInitialSchedules.count(chocoModelInitialSchedules.intVar(1), this.workPeriodsSchedulesOfFullTimeEmployees[employee], this.workingPeriodsPerFullTimeEmployees[employee]).post(); - } + }*/ // Constraintes pour borner le nombre d'heures travaillees par les employes a temps partiel for (int employee = 0; employee < this.maxPartTimeEmployee; employee++) { @@ -179,13 +185,13 @@ public class ModelInitialSchedules { // Contrainte pour forcer des heures consécutives par jour pour les employés à temps partiel - for (int employee = 0; employee < this.maxPartTimeEmployee; employee++) { + /*for (int employee = 0; employee < this.maxPartTimeEmployee; employee++) { for (int day = 0; day < this.myScheduleParameters.daysPerSchedule; day++) { chocoModelInitialSchedules.table( this.workPeriodsOfPartTimeEmployees[employee * this.myScheduleParameters.daysPerSchedule + day], this.myScheduleParameters.ValidPartTimeEmployeeShiftTuples).post(); } - } + }*/ @@ -196,10 +202,10 @@ public class ModelInitialSchedules { // chocoModelInitialSchedules.lexLessEq(this.workPeriodsSchedulesOfPartTimeEmployees[employee], // this.workPeriodsSchedulesOfPartTimeEmployees[employee+1]).post(); // } - for (int employee = 0; employee < (this.maxFullTimeEmployee-1); employee++){ - chocoModelInitialSchedules.lexLessEq(this.workPeriodsSchedulesOfFullTimeEmployees[employee], - this.workPeriodsSchedulesOfFullTimeEmployees[employee+1]).post(); - } +// for (int employee = 0; employee < (this.maxFullTimeEmployee-1); employee++){ +// chocoModelInitialSchedules.lexLessEq(this.workPeriodsSchedulesOfFullTimeEmployees[employee], +// this.workPeriodsSchedulesOfFullTimeEmployees[employee+1]).post(); +// } } diff --git a/Travail_de_session/InitialSchedules/ParametersInitialSchedules.java b/Travail_de_session/InitialSchedules/ParametersInitialSchedules.java index 1b35e1f..0e9733c 100644 --- a/Travail_de_session/InitialSchedules/ParametersInitialSchedules.java +++ b/Travail_de_session/InitialSchedules/ParametersInitialSchedules.java @@ -5,16 +5,15 @@ import org.chocosolver.solver.constraints.extension.Tuples; public class ParametersInitialSchedules { public int workPeriodsPerDay; - int shiftWorkPerDay; + int NbFullTimeSolutions; public int daysPerSchedule; public int workPeriodsPerSchedule; int totalWorkedPeriodsInSchedule; - int hoursPerWorkPeriod; - - int fixedCostOfPartTimeEmployeesPerSchedule; + int NbPartTimeSolutions; + Tuples enumerationWorkPeriodsSchedulesOfPartTimeEmployees; int hourlyRateOfPartTimeEmployees; - int minWorkingHoursOfPartTimeEmployeesPerSchedule; - int maxWorkingHoursOfPartTimeEmployeesPerSchedule; + private int shiftWorkPerDay; + private int hoursPerWorkPeriod; int minWorkingPeriodsOfPartTimeEmployeesPerSchedule; int maxWorkingPeriodsOfPartTimeEmployeesPerSchedule; @@ -27,11 +26,13 @@ public class ParametersInitialSchedules { int maxWorkingPeriodsOfFullTimeEmployeesPerSchedule; int workingHoursPaidAtRegularHourlyRatePerSchedule; + private int fixedCostOfPartTimeEmployeesPerSchedule; + private int minWorkingHoursOfPartTimeEmployeesPerSchedule; public int[] requiredWorkforce; Tuples enumerationWorkPeriodsSchedulesOfFullTimeEmployees; - - Tuples ValidPartTimeEmployeeShiftTuples; + private int maxWorkingHoursOfPartTimeEmployeesPerSchedule; + private Tuples ValidPartTimeEmployeeShiftTuples; public ParametersInitialSchedules() { @@ -40,6 +41,7 @@ public class ParametersInitialSchedules { this.setFullTimeEmployeesParameters(); this.setRequiredWorkforce(); this.setWorkPeriodsSchedulesOfFullTimeEmployees(); + this.setWorkPeriodsSchedulesOfPartTimeEmployees(); this.setValidPartTimeEmployeeShiftTuples(); } @@ -82,7 +84,7 @@ public class ParametersInitialSchedules { this.requiredWorkforce = new int[this.daysPerSchedule * this.workPeriodsPerDay]; this.totalWorkedPeriodsInSchedule = 0; - int[] dailyRequiredWorkforce = new int[]{2, 2, 4, 4, 3, 3}; + int[] dailyRequiredWorkforce = new int[]{2, 2, 3, 3, 1, 1}; for (int day = 0; day < this.daysPerSchedule; day++) { for(int shift = 0; shift < this.workPeriodsPerDay; shift++) { this.requiredWorkforce[day * this.workPeriodsPerDay + shift] = dailyRequiredWorkforce[shift]; @@ -94,15 +96,24 @@ public class ParametersInitialSchedules { private void setWorkPeriodsSchedulesOfFullTimeEmployees() { - ValidDailySchedules v = new ValidDailySchedules(); + ValidDailySchedules validDailyFullTimeSchedules = new ValidDailySchedules(daysPerSchedule, + 10, + 10, + 0, + 5, + 7, + 12, + 4); - int[][] dailySchedulesOfFullTimeEmployees = v.dailySchedulesOfFullTimeEmployees; + NbFullTimeSolutions = validDailyFullTimeSchedules.getNbSolutions(); + + int[][] dailySchedulesOfFullTimeEmployees = validDailyFullTimeSchedules.getValidSchedules(); int[][] workPeriodsSchedulesOfFullTimeEmployees - = new int[v.length() * this.shiftWorkPerDay][this.workPeriodsPerSchedule]; + = new int[NbFullTimeSolutions * this.shiftWorkPerDay][this.workPeriodsPerSchedule]; // Cette fonction sera a ameliorer avec des sous-fonctions, car elle n'est pas tres explicite. - for (int scheduleNumber = 0; scheduleNumber < v.length(); scheduleNumber++) { + for (int scheduleNumber = 0; scheduleNumber < NbFullTimeSolutions; scheduleNumber++) { for (int day = 0; day < this.daysPerSchedule; day++) { for (int shiftNumber = 0; shiftNumber < this.shiftWorkPerDay; shiftNumber++) { if (dailySchedulesOfFullTimeEmployees[scheduleNumber][day] == 1 && shiftNumber == 0) { @@ -143,6 +154,126 @@ public class ParametersInitialSchedules { = new Tuples(workPeriodsSchedulesOfFullTimeEmployees, true); } + private void setWorkPeriodsSchedulesOfPartTimeEmployees() { + + ValidDailySchedules validDailyPartTimeSchedules = new ValidDailySchedules(daysPerSchedule, + 4, + 6, + 0, + 7, + 7, + 14, + 6); + + NbPartTimeSolutions = validDailyPartTimeSchedules.getNbSolutions(); + + int[][] dailySchedulesOfPartTimeEmployees = validDailyPartTimeSchedules.getValidSchedules(); + + int maxShiftConfig = 5; + + int[][] workPeriodsSchedulesOfPartTimeEmployees + = new int[NbPartTimeSolutions * 5][this.workPeriodsPerSchedule]; + + // Cette fonction sera a ameliorer avec des sous-fonctions, car elle n'est pas tres explicite. + for (int scheduleNumber = 0; scheduleNumber < NbPartTimeSolutions; scheduleNumber++) { + for (int day = 0; day < this.daysPerSchedule; day++) { + for (int shiftNumber = 0; shiftNumber < maxShiftConfig; shiftNumber++) { + System.out.println("Schedule:" + scheduleNumber + "day:" + day + "Shift:" + shiftNumber); + if (dailySchedulesOfPartTimeEmployees[scheduleNumber][day] == 1 && shiftNumber == 0) { + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 0] = 1; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 1] = 1; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 2] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 3] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 4] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 5] = 0; + } else if (dailySchedulesOfPartTimeEmployees[scheduleNumber][day] == 1 && shiftNumber == 1) { + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 0] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 1] = 1; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 2] = 1; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 3] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 4] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 5] = 0; + } else if (dailySchedulesOfPartTimeEmployees[scheduleNumber][day] == 1 && shiftNumber == 2) { + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 0] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 1] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 2] = 1; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 3] = 1; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 4] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 5] = 0; + } else if (dailySchedulesOfPartTimeEmployees[scheduleNumber][day] == 1 && shiftNumber == 3) { + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 0] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 1] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 2] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 3] = 1; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 4] = 1; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 5] = 0; + } else if (dailySchedulesOfPartTimeEmployees[scheduleNumber][day] == 1 && shiftNumber == 4) { + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 0] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 1] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 2] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 3] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 4] = 1; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 5] = 1; + /*} else if (dailySchedulesOfPartTimeEmployees[scheduleNumber][day] == 1 && shiftNumber == 5) { + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 0] = 1; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 1] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 2] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 3] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 4] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 5] = 0; + } else if (dailySchedulesOfPartTimeEmployees[scheduleNumber][day] == 1 && shiftNumber == 6) { + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 0] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 1] = 1; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 2] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 3] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 4] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 5] = 0; + } else if (dailySchedulesOfPartTimeEmployees[scheduleNumber][day] == 1 && shiftNumber == 7) { + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 0] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 1] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 2] = 1; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 3] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 4] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 5] = 0; + } else if (dailySchedulesOfPartTimeEmployees[scheduleNumber][day] == 1 && shiftNumber == 8) { + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 0] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 1] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 2] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 3] = 1; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 4] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 5] = 0; + } else if (dailySchedulesOfPartTimeEmployees[scheduleNumber][day] == 1 && shiftNumber == 9) { + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 0] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 1] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 2] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 3] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 4] = 1; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 5] = 0; + } else if (dailySchedulesOfPartTimeEmployees[scheduleNumber][day] == 1 && shiftNumber == 10) { + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 0] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 1] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 2] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 3] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 4] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 5] = 1;*/ + } else if (dailySchedulesOfPartTimeEmployees[scheduleNumber][day] == 0) { + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 0] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 1] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 2] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 3] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 4] = 0; + workPeriodsSchedulesOfPartTimeEmployees[scheduleNumber * maxShiftConfig + shiftNumber][day * this.workPeriodsPerDay + 5] = 0; + } + } + } + } + + // Creation des tuples a partir du tableau pour creer les 3 types de quart de travail (nuit, jour soir). + this.enumerationWorkPeriodsSchedulesOfPartTimeEmployees + = new Tuples(workPeriodsSchedulesOfPartTimeEmployees, true); + } + + private void setValidPartTimeEmployeeShiftTuples() { this.ValidPartTimeEmployeeShiftTuples = new ValidPartTimeEmployeeShift().makeTuples(); } diff --git a/Travail_de_session/InitialSchedules/ValidDailySchedules.java b/Travail_de_session/InitialSchedules/ValidDailySchedules.java index 7524c32..03a6c4f 100644 --- a/Travail_de_session/InitialSchedules/ValidDailySchedules.java +++ b/Travail_de_session/InitialSchedules/ValidDailySchedules.java @@ -1,34 +1,90 @@ package InitialSchedules; -public class ValidDailySchedules { - int[][] dailySchedulesOfFullTimeEmployees; +import org.chocosolver.solver.Model; +import org.chocosolver.solver.Solution; +import org.chocosolver.solver.constraints.nary.automata.FA.FiniteAutomaton; +import org.chocosolver.solver.constraints.nary.automata.FA.IAutomaton; +import org.chocosolver.solver.variables.BoolVar; +import org.chocosolver.solver.variables.IntVar; - public ValidDailySchedules() { - this.dailySchedulesOfFullTimeEmployees = new int[][]{ - {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, - {0, 1, 1, 1, 1, 0, 0, 1, 0, 1, 1, 1, 1, 1}, - {0, 1, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1}, - {0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1}, - {0, 1, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1}, - {1, 0, 1, 1, 1, 0, 0, 1, 1, 0, 1, 1, 1, 1}, - {1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1}, - {1, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1}, - {1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 0, 1, 1, 1}, - {1, 1, 0, 1, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1}, - {1, 1, 1, 0, 1, 0, 0, 1, 1, 1, 1, 0, 1, 1}, - {1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0}, - {1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0}, - {1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0}, - {1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0}, - {1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 1, 0, 0}, - {1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 1, 0, 0}, - {1, 1, 1, 1, 0, 1, 1, 0, 1, 1, 1, 1, 0, 0}, - {1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 0}, - {1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 1, 1, 0, 0}, - {1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0},}; +import java.util.List; + +public class ValidDailySchedules { + + int[][] ValidSchedules; + private int nbSolutions; + + ValidDailySchedules(int nbPeriodes, int nbPeriodesTravailleesMin, int nbPeriodesTravailleesMax, int p1Min, int p1Max, int p2Min, int p2Max, int nbMaxConsecutif) { + + Model model = new Model("Horaire de " + nbPeriodes + "-periodes"); + BoolVar[] horaire = new BoolVar[nbPeriodes]; + for (int p = 0; p < nbPeriodes; p++) { + horaire[p] = model.boolVar("P_" + p); + } + + BoolVar[] horaires1 = new BoolVar[p1Max - p1Min]; + BoolVar[] horaires2 = new BoolVar[p1Max - p1Min]; + + IntVar sumhoraire1 = model.intVar("SP_1", 0, nbPeriodes); + IntVar sumhoraire2 = model.intVar("SP_2", 0, nbPeriodes); + + for (int p = 0; p < p1Max - p1Min; p++) horaires1[p] = horaire[p1Min + p]; + for (int p = 0; p < p2Max - p2Min; p++) horaires2[p] = horaire[p2Min + p]; + + /* Travaille entre le nombre minimum et maximum de périodes */ + model.sum(horaire, ">=", nbPeriodesTravailleesMin).post(); + model.sum(horaire, "<=", nbPeriodesTravailleesMax).post(); + + /* Travaille autant dans les deux sous-périodes */ + model.sum(horaires1, "=", sumhoraire1).post(); + model.sum(horaires2, "=", sumhoraire2).post(); + model.arithm(sumhoraire1, "=", sumhoraire2).post(); + + /*Travaille une fin de semaine sur deux*/ + model.arithm(horaire[5], "=", horaire[6]).post(); + model.arithm(horaire[12], "=", horaire[13]).post(); + model.arithm(horaire[5], "!=", horaire[12]).post(); + + /*Respect du maximum consecutif*/ + IAutomaton automatonConsecutif = new FiniteAutomaton("[01]*1{" + (nbMaxConsecutif + 1) + "," + nbPeriodes + "}[01]*"); + BoolVar respecteMaxConsecutif = model.regular(horaire, automatonConsecutif).reify(); + model.arithm(respecteMaxConsecutif, "=", 0).post(); + + /* Trouver les solutions*/ + List solutions = model.getSolver().findAllSolutions(); + + this.nbSolutions = solutions.size() + 1; + + ValidSchedules = new int[this.nbSolutions][nbPeriodes]; + + /* Itérer sur les solutions */ + int iterSolutions = 0; + System.out.println("Valid Full Time Schedules:"); + for (Solution solution : solutions) { + if (solution != null) { + System.out.print(iterSolutions + "::"); + for (int iterPeriod = 0; iterPeriod < nbPeriodes; iterPeriod++) { + ValidSchedules[iterSolutions][iterPeriod] = solution.getIntVal(horaire[iterPeriod]); + System.out.print(ValidSchedules[iterSolutions][iterPeriod]); + } + System.out.print("\n"); + iterSolutions++; + } + } + /* La solution additionnelle où le travailleur ne travaille pas*/ + System.out.print(this.nbSolutions - 1 + "::"); + for (int iterPeriod = 0; iterPeriod < nbPeriodes; iterPeriod++) { + ValidSchedules[this.nbSolutions - 1][iterPeriod] = 0; + System.out.print(ValidSchedules[this.nbSolutions - 1][iterPeriod]); + } + System.out.print("\n"); } - public int length() { - return this.dailySchedulesOfFullTimeEmployees.length; + public int getNbSolutions() { + return this.nbSolutions; + } + + public int[][] getValidSchedules() { + return ValidSchedules; } } diff --git a/Travail_de_session/MainClass.java b/Travail_de_session/MainClass.java index 53ef6db..152f201 100644 --- a/Travail_de_session/MainClass.java +++ b/Travail_de_session/MainClass.java @@ -1,17 +1,15 @@ //import AbsenceSchedules.AbsenceSchedulesArray; + +import AbsenceSchedules.AbsenceSchedulesArray; +import ScheduleUtil.SchedulesArray; +import SchedulesRecovery.RecoveredSchedulesArray; import jdistlib.rng.MersenneTwister; import jdistlib.rng.RandomEngine; -import org.chocosolver.solver.Model; -import org.chocosolver.solver.Solution; import org.chocosolver.solver.Solver; import org.chocosolver.solver.exception.ContradictionException; -import ScheduleUtil.SchedulesArray; -import AbsenceSchedules.AbsenceSchedulesArray; -import SchedulesRecovery.RecoveredSchedulesArray; import java.util.ArrayList; import java.util.List; -import java.lang.*; @@ -53,20 +51,21 @@ public class MainClass { solverInitialSchedules.showDashboard(); /*solverInitialSchedules.setSearch(Search.domOverWDegSearch(myModelInitialSchedules.allWorkPeriods));*/ // solverInitialSchedules.setRestartOnSolutions(); /*Sans restart, toutes les horaires sont identiques*/ - solverInitialSchedules.limitSolution(5); + //solverInitialSchedules.limitSolution(5); //solverInitialSchedules.limitTime(10000); - List myInitialSchedulesSolutions; -// myInitialSchedulesSolutions = solverInitialSchedules.findAllOptimalSolutions -// (myModelInitialSchedules.TotalEmployeesSalary, Model.MINIMIZE); + //List myInitialSchedulesSolutions; + //myInitialSchedulesSolutions = solverInitialSchedules.findAllOptimalSolutions + // (myModelInitialSchedules.TotalEmployeesSalary, Model.MINIMIZE); - myInitialSchedulesSolutions = solverInitialSchedules.findAllSolutions (); + solverInitialSchedules.findSolution(); + //myInitialSchedulesSolutions = solverInitialSchedules.findAllSolutions(); solverInitialSchedules.printStatistics(); // Création de l'objet banque d'horaire, qui est une liste d'objets de type InitialSchedulesArray, qui contiennent chacun deux tableaux. - for (Solution CurrentSolution : myInitialSchedulesSolutions) { + /*for (Solution CurrentSolution : myInitialSchedulesSolutions) { SchedulesArray isa = new SchedulesArray(myModelInitialSchedules, CurrentSolution); initialSchedulesArrayList.add(isa); - } + }*/ // Pour afficher les horaires initiales SchedulesWindows.ShowSchedulesFrame intialSchedulesViewer = new SchedulesWindows.ShowSchedulesFrame(initialSchedulesArrayList, "Initial Schedules");