diff --git a/Travail_de_session/InitialSchedules/InitialSchedulesArray.java b/Travail_de_session/InitialSchedules/InitialSchedulesArray.java new file mode 100644 index 0000000..d5b6847 --- /dev/null +++ b/Travail_de_session/InitialSchedules/InitialSchedulesArray.java @@ -0,0 +1,30 @@ +package InitialSchedules; + +import org.chocosolver.solver.Solution; + +public class InitialSchedulesArray { + + public int[][] InitialPartTimeSchedules; + public int[][] InitialFullTimeSchedules; + private ModelInitialSchedules myModelInitialSchedules; + private Solution mySolution; + + public InitialSchedulesArray(ModelInitialSchedules m, Solution s) { + this.myModelInitialSchedules = m; + this.mySolution = s; + this.InitialPartTimeSchedules = new int[myModelInitialSchedules.maxPartTimeEmployee][myModelInitialSchedules.myScheduleParameters.workPeriodsPerSchedule]; + this.InitialFullTimeSchedules = new int[myModelInitialSchedules.maxFullTimeEmployee][myModelInitialSchedules.myScheduleParameters.workPeriodsPerSchedule]; + for (int workPeriod = 0; workPeriod < myModelInitialSchedules.myScheduleParameters.workPeriodsPerSchedule; workPeriod++) { + for (int employee = 0; employee < myModelInitialSchedules.maxPartTimeEmployee; employee++) { + this.InitialPartTimeSchedules[employee][workPeriod] = mySolution.getIntVal(myModelInitialSchedules.workPeriodsSchedulesOfPartTimeEmployees[employee][workPeriod]); + } + } + + for (int workPeriod = 0; workPeriod < myModelInitialSchedules.myScheduleParameters.workPeriodsPerSchedule; workPeriod++) { + for (int employee = 0; employee < myModelInitialSchedules.maxFullTimeEmployee; employee++) { + this.InitialFullTimeSchedules[employee][workPeriod] = mySolution.getIntVal(myModelInitialSchedules.workPeriodsSchedulesOfFullTimeEmployees[employee][workPeriod]); + } + } + + } +} diff --git a/Travail_de_session/InitialSchedules/ModelInitialSchedules.java b/Travail_de_session/InitialSchedules/ModelInitialSchedules.java index b9f49f2..b3204f1 100644 --- a/Travail_de_session/InitialSchedules/ModelInitialSchedules.java +++ b/Travail_de_session/InitialSchedules/ModelInitialSchedules.java @@ -15,7 +15,7 @@ public class ModelInitialSchedules { // private final int RESTART_AUCUN = 0; // private final int RESTART_LUBY = 1; // private final int RESTART_GEOMETRIQUE = 2; - private ParametersInitialSchedules myScheduleParameters; + public ParametersInitialSchedules myScheduleParameters; public int maxPartTimeEmployee; public int maxFullTimeEmployee; diff --git a/Travail_de_session/MainClass.java b/Travail_de_session/MainClass.java index e30d368..570d24e 100644 --- a/Travail_de_session/MainClass.java +++ b/Travail_de_session/MainClass.java @@ -1,5 +1,10 @@ -import org.chocosolver.solver.Model; +import InitialSchedules.InitialSchedulesArray; +import org.chocosolver.solver.Solution; import org.chocosolver.solver.Solver; +import org.chocosolver.solver.exception.ContradictionException; + +import java.util.ArrayList; +import java.util.List; public class MainClass { @@ -22,17 +27,46 @@ public class MainClass { = new InitialSchedules.ModelInitialSchedules(myScheduleParameters); Solver solverInitialSchedules = myModelInitialSchedules.chocoModelInitialSchedules.getSolver(); - solverInitialSchedules.showDashboard(); + + try { + solverInitialSchedules.propagate(); + } catch (ContradictionException e) { + System.err.println("Caught ContradictionException: " + e.getMessage()); + solverInitialSchedules.getEngine().flush(); + } catch (Exception e) { + System.err.println("Caught Exception: " + e.getMessage()); + } + + //solverInitialSchedules.showDashboard(); /*solverInitialSchedules.setSearch(Search.domOverWDegSearch(myModelInitialSchedules.allWorkPeriods));*/ + //solverInitialSchedules.setRestartOnSolutions(); /*Sans restart, toutes les horaires sont identiques*/ + solverInitialSchedules.limitSolution(100); solverInitialSchedules.limitTime(10000); - solverInitialSchedules.findAllOptimalSolutions - (myModelInitialSchedules.TotalEmployeesSalary, Model.MINIMIZE); + List myInitialSchedulesSolutions; + myInitialSchedulesSolutions = solverInitialSchedules.findAllSolutions + (/*myModelInitialSchedules.TotalEmployeesSalary, Model.MINIMIZE*/); + // fonction pour reduire le nombre d'horaire dans la banque d'horaire. -// InitialSchedules.UtilInitialSchedules.refineInitialSchedules(bestInitialSchedules); + // InitialSchedules.UtilInitialSchedules.refineInitialSchedules(bestInitialSchedules); // On pourrait creer un petit interface pour afficher les horaires optimales et les statistiques. InitialSchedules.UtilInitialSchedules.printSolutionResults(myModelInitialSchedules, myScheduleParameters); solverInitialSchedules.printStatistics(); - //TODO Creer objet banque horaire + // Création de l'objet banque d'horaire, qui est une liste d'objets de type InitialSchedulesArray, qui contiennent chacun deux tableaux. + + List InitialSchedulesArrayList = new ArrayList<>(); + + for (Solution CurrentSolution : myInitialSchedulesSolutions) { + InitialSchedulesArray isa = new InitialSchedules.InitialSchedulesArray(myModelInitialSchedules, CurrentSolution); + InitialSchedulesArrayList.add(isa); + } + + // Imprimer la liste de matrices + /*for (InitialSchedulesArray isa: InitialSchedulesArrayList) { + System.out.println(Arrays.deepToString(isa.InitialPartTimeSchedules)); + } + for (InitialSchedulesArray isa: InitialSchedulesArrayList) { + System.out.println(Arrays.deepToString(isa.InitialFullTimeSchedules)); + }*/ } }