From d091fa4217cb7152f31167c7ffffbef937fc7836 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pelletier?= Date: Sat, 24 Mar 2018 13:24:44 -0400 Subject: [PATCH] Ajout d'une fonction d'optimisation sur les salaires --- .../ModelInitialSchedules.java | 69 +++++++++++++++++-- .../ParametersInitialSchedules.java | 24 +++---- Travail_de_session/MainClass.java | 13 ++-- 3 files changed, 82 insertions(+), 24 deletions(-) diff --git a/Travail_de_session/InitialSchedules/ModelInitialSchedules.java b/Travail_de_session/InitialSchedules/ModelInitialSchedules.java index 594a3dd..b9f49f2 100644 --- a/Travail_de_session/InitialSchedules/ModelInitialSchedules.java +++ b/Travail_de_session/InitialSchedules/ModelInitialSchedules.java @@ -37,6 +37,7 @@ public class ModelInitialSchedules { public IntVar employeesPerWorkPeriods[]; public Model chocoModelInitialSchedules; + public IntVar TotalEmployeesSalary; public IntVar scheduleProfit; public ModelInitialSchedules(ParametersInitialSchedules myScheduleParameters) { @@ -66,8 +67,8 @@ public class ModelInitialSchedules { private void createScheduleVariables() { // Variable pour l'horaire des employes - this.workPeriodsSchedulesOfPartTimeEmployees = chocoModelInitialSchedules.boolVarMatrix(this.maxPartTimeEmployee, this.myScheduleParameters.workPeriodsPerSchedule); this.workPeriodsSchedulesOfFullTimeEmployees = chocoModelInitialSchedules.boolVarMatrix(this.maxFullTimeEmployee, this.myScheduleParameters.workPeriodsPerSchedule); + this.workPeriodsSchedulesOfPartTimeEmployees = chocoModelInitialSchedules.boolVarMatrix(this.maxPartTimeEmployee, this.myScheduleParameters.workPeriodsPerSchedule); // Vecteur de toutes les variables /*this.allWorkPeriods = chocoModelInitialSchedules.boolVarArray((this.maxPartTimeEmployee+this.maxFullTimeEmployee)*this.myScheduleParameters.workPeriodsPerSchedule); @@ -176,7 +177,7 @@ public class ModelInitialSchedules { this.employeesPerWorkPeriods[workPeriod]).post(); } - // Contrainte pour heures consécutives des employés à temps partiel + // 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 day = 0; day < this.myScheduleParameters.daysPerSchedule; day++) { @@ -194,17 +195,75 @@ public class ModelInitialSchedules { /*for (int employee = 0; employee < (this.maxPartTimeEmployee-1); employee++){ chocoModelInitialSchedules.lexLessEq(this.workPeriodsSchedulesOfPartTimeEmployees[employee], this.workPeriodsSchedulesOfPartTimeEmployees[employee+1]).post(); - }*/ - /*for (int employee = 0; employee < (this.maxFullTimeEmployee-1); employee++){ + } + for (int employee = 0; employee < (this.maxFullTimeEmployee-1); employee++){ chocoModelInitialSchedules.lexLessEq(this.workPeriodsSchedulesOfFullTimeEmployees[employee], this.workPeriodsSchedulesOfFullTimeEmployees[employee+1]).post(); }*/ - } private void createModelObjectiveFunction() { + // Calcul du nombre de périodes travaillées par chaque type d'employés dans l'horaire + + IntVar[] NumberOfPartTimeEmployeesPerPeriod = + chocoModelInitialSchedules.intVarArray(this.myScheduleParameters.workPeriodsPerSchedule, + 0, + this.maxPartTimeEmployee, true); + IntVar[] NumberOfFullTimeEmployeesPerPeriod = + chocoModelInitialSchedules.intVarArray(this.myScheduleParameters.workPeriodsPerSchedule, + 0, + this.maxFullTimeEmployee, true); + + for (int workPeriod = 0; workPeriod < this.myScheduleParameters.workPeriodsPerSchedule; workPeriod++) { + chocoModelInitialSchedules.sum(transposeWorkPeriodsSchedulesOfPartTimeEmployees[workPeriod], + "=", NumberOfPartTimeEmployeesPerPeriod[workPeriod]).post(); + chocoModelInitialSchedules.sum(transposeWorkPeriodsSchedulesOfFullTimeEmployees[workPeriod], + "=", NumberOfFullTimeEmployeesPerPeriod[workPeriod]).post(); + } + + IntVar NumberOfPartTimeEmployeesPeriods = + chocoModelInitialSchedules.intVar( + 0, this.maxPartTimeEmployee * this.myScheduleParameters.workPeriodsPerSchedule, true); + IntVar NumberOfFullTimeEmployeesPeriods = + chocoModelInitialSchedules.intVar( + 0, this.maxPartTimeEmployee * this.myScheduleParameters.workPeriodsPerSchedule, true); + + chocoModelInitialSchedules.sum(NumberOfPartTimeEmployeesPerPeriod, "=", NumberOfPartTimeEmployeesPeriods).post(); + chocoModelInitialSchedules.sum(NumberOfFullTimeEmployeesPerPeriod, "=", NumberOfFullTimeEmployeesPeriods).post(); + + // Calcul du salaire versé + IntVar PartTimeEmployeesSalary = + chocoModelInitialSchedules.intVar(1000, this.maxPartTimeEmployee * + this.myScheduleParameters.workPeriodsPerSchedule * + this.myScheduleParameters.hourlyRateOfPartTimeEmployees, true); + + IntVar FullTimeEmployeesSalary = + chocoModelInitialSchedules.intVar(1000, this.maxFullTimeEmployee * + this.myScheduleParameters.workPeriodsPerSchedule * + this.myScheduleParameters.regularHourlyRateOfFullTimeEmployees, true); + + this.TotalEmployeesSalary = chocoModelInitialSchedules.intVar(0, this.maxPartTimeEmployee * + this.myScheduleParameters.workPeriodsPerSchedule * + this.myScheduleParameters.hourlyRateOfPartTimeEmployees + + this.maxFullTimeEmployee * + this.myScheduleParameters.workPeriodsPerSchedule * + this.myScheduleParameters.regularHourlyRateOfFullTimeEmployees, true); + + IntVar HourlyRateOfPartTimeEmployees = + chocoModelInitialSchedules.intVar(this.myScheduleParameters.hourlyRateOfPartTimeEmployees); + IntVar regularHourlyRateOfFullTimeEmployees = + chocoModelInitialSchedules.intVar(this.myScheduleParameters.regularHourlyRateOfFullTimeEmployees); + + chocoModelInitialSchedules.arithm(NumberOfPartTimeEmployeesPeriods, "*", HourlyRateOfPartTimeEmployees, "=", PartTimeEmployeesSalary).post(); + chocoModelInitialSchedules.arithm(NumberOfFullTimeEmployeesPeriods, "*", regularHourlyRateOfFullTimeEmployees, "=", FullTimeEmployeesSalary).post(); + + chocoModelInitialSchedules.arithm(PartTimeEmployeesSalary, "+", FullTimeEmployeesSalary, "=", this.TotalEmployeesSalary).post(); + + //TODO: Inclure les frais fixes par employé + + // this.scheduleProfit = chocoModelInitialSchedules.intVar("TOTAL_COST", 0, 20 * N * p, true); // chocoModelInitialSchedules.scalar(perte , coeffs , "=", this.scheduleProfit).post(); } diff --git a/Travail_de_session/InitialSchedules/ParametersInitialSchedules.java b/Travail_de_session/InitialSchedules/ParametersInitialSchedules.java index df1f8f0..7775ed8 100644 --- a/Travail_de_session/InitialSchedules/ParametersInitialSchedules.java +++ b/Travail_de_session/InitialSchedules/ParametersInitialSchedules.java @@ -9,24 +9,24 @@ public class ParametersInitialSchedules { int daysPerSchedule; int workPeriodsPerSchedule; int totalWorkedPeriodsInSchedule; - double hoursPerWorkPeriod; + int hoursPerWorkPeriod; - double fixedCostOfPartTimeEmployeesPerSchedule; - double hourlyRateOfPartTimeEmployees; - double minWorkingHoursOfPartTimeEmployeesPerSchedule; - double maxWorkingHoursOfPartTimeEmployeesPerSchedule; + int fixedCostOfPartTimeEmployeesPerSchedule; + int hourlyRateOfPartTimeEmployees; + int minWorkingHoursOfPartTimeEmployeesPerSchedule; + int maxWorkingHoursOfPartTimeEmployeesPerSchedule; int minWorkingPeriodsOfPartTimeEmployeesPerSchedule; int maxWorkingPeriodsOfPartTimeEmployeesPerSchedule; - double fixedCostOfFullTimeEmployeesPerSchedule; - double regularHourlyRateOfFullTimeEmployees; - double overtimeHourlyRateOfFullTimeEmployees; - double workingHoursOfFullTimeEmployeesPerSchedule; - double maxWorkingHoursOfFullTimeEmployeesPerSchedule; + int fixedCostOfFullTimeEmployeesPerSchedule; + int regularHourlyRateOfFullTimeEmployees; + int overtimeHourlyRateOfFullTimeEmployees; + int workingHoursOfFullTimeEmployeesPerSchedule; + int maxWorkingHoursOfFullTimeEmployeesPerSchedule; int workingPeriodsOfFullTimeEmployeesPerSchedule; int maxWorkingPeriodsOfFullTimeEmployeesPerSchedule; - double workingHoursPaidAtRegularHourlyRatePerSchedule; + int workingHoursPaidAtRegularHourlyRatePerSchedule; public int[] requiredWorkforce; Tuples enumerationWorkPeriodsSchedulesOfFullTimeEmployees; @@ -48,7 +48,7 @@ public class ParametersInitialSchedules { this.workPeriodsPerDay = 6; this.shiftWorkPerDay = 3; this.daysPerSchedule = 14; - this.hoursPerWorkPeriod = 4; + this.hoursPerWorkPeriod = 24 / this.workPeriodsPerDay; this.workPeriodsPerSchedule = this.workPeriodsPerDay * this.daysPerSchedule; } diff --git a/Travail_de_session/MainClass.java b/Travail_de_session/MainClass.java index 787c605..e30d368 100644 --- a/Travail_de_session/MainClass.java +++ b/Travail_de_session/MainClass.java @@ -1,3 +1,4 @@ +import org.chocosolver.solver.Model; import org.chocosolver.solver.Solver; public class MainClass { @@ -21,13 +22,11 @@ public class MainClass { = new InitialSchedules.ModelInitialSchedules(myScheduleParameters); Solver solverInitialSchedules = myModelInitialSchedules.chocoModelInitialSchedules.getSolver(); - /*solverInitialSchedules.setSearch(Search.domOverWDegSearch(myModelInitialSchedules.allWorkPeriods)); - solverInitialSchedules.limitSolution(10); - solverInitialSchedules.findAllSolutions();*/ - solverInitialSchedules.findSolution(); -// Solution bestInitialSchedules = solverInitialSchedules.findOptimalSolution -// (myModelInitialSchedules.scheduleProfit, Model.MINIMIZE); - + solverInitialSchedules.showDashboard(); + /*solverInitialSchedules.setSearch(Search.domOverWDegSearch(myModelInitialSchedules.allWorkPeriods));*/ + solverInitialSchedules.limitTime(10000); + solverInitialSchedules.findAllOptimalSolutions + (myModelInitialSchedules.TotalEmployeesSalary, Model.MINIMIZE); // fonction pour reduire le nombre d'horaire dans la banque d'horaire. // InitialSchedules.UtilInitialSchedules.refineInitialSchedules(bestInitialSchedules); // On pourrait creer un petit interface pour afficher les horaires optimales et les statistiques.