From 54eca9baa6f9699b3d0bbbb32070e3c421ab1a37 Mon Sep 17 00:00:00 2001 From: "Francois Berube\\frabe" Date: Fri, 30 Mar 2018 00:31:20 -0400 Subject: [PATCH] =?UTF-8?q?Cr=C3=A9ation=20d'une=20interface=20pour=20la?= =?UTF-8?q?=20visualisation=20des=20horaires=20initales=20et=20des=20horai?= =?UTF-8?q?res=20avec=20absences?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Ajout de l'héritage entre les classes AbsenceScheduleArray et ScheduleArray. TODO : Toujours pas capable de générer des horaires différentes. --- .../AbsenceSchedulesArray.java | 49 ++--- .../InitialSchedulesArray.java | 55 ------ .../ParametersInitialSchedules.java | 8 +- .../UtilInitialSchedules.java | 97 --------- Travail_de_session/MainClass.java | 71 ++++--- .../ScheduleUtil/PrintSchedules.java | 86 ++++++++ .../ScheduleUtil/SchedulesArray.java | 187 ++++++++++++++++++ .../SchedulesWindows/ShowSchedulesFrame.form | 120 +++++++++++ .../SchedulesWindows/ShowSchedulesFrame.java | 139 +++++++++++++ 9 files changed, 590 insertions(+), 222 deletions(-) delete mode 100644 Travail_de_session/InitialSchedules/InitialSchedulesArray.java delete mode 100644 Travail_de_session/InitialSchedules/UtilInitialSchedules.java create mode 100644 Travail_de_session/ScheduleUtil/PrintSchedules.java create mode 100644 Travail_de_session/ScheduleUtil/SchedulesArray.java create mode 100644 Travail_de_session/SchedulesWindows/ShowSchedulesFrame.form create mode 100644 Travail_de_session/SchedulesWindows/ShowSchedulesFrame.java diff --git a/Travail_de_session/AbsenceSchedules/AbsenceSchedulesArray.java b/Travail_de_session/AbsenceSchedules/AbsenceSchedulesArray.java index f35cfcf..3e1f5f6 100644 --- a/Travail_de_session/AbsenceSchedules/AbsenceSchedulesArray.java +++ b/Travail_de_session/AbsenceSchedules/AbsenceSchedulesArray.java @@ -1,41 +1,32 @@ package AbsenceSchedules; -import InitialSchedules.InitialSchedulesArray; +import InitialSchedules.ModelInitialSchedules; +import ScheduleUtil.SchedulesArray; import jdistlib.rng.RandomEngine; +import org.chocosolver.solver.Solution; -public class AbsenceSchedulesArray { - private int[][] PartTimeSchedules; - private int[][] FullTimeSchedules; +public class AbsenceSchedulesArray extends SchedulesArray{ - public AbsenceSchedulesArray(InitialSchedulesArray I, RandomEngine r) { - - int mpte = I.getMaxPartTimeEmployee(); - int mfte = I.getMaxFullTimeEmployee(); - int[][] pts = I.getPartTimeSchedules(); - int[][] fts = I.getFullTimeSchedules(); - int wps = I.getWorkPeriodsPerSchedule(); - PartTimeSchedules = new int[mpte][wps]; - FullTimeSchedules = new int[mfte][wps]; - - for (int i = 0; i < I.getMaxPartTimeEmployee(); i++) { - int[] a = new AbsencesVector(wps, r).getAbsencesVector(); - for (int j = 0; j < wps; j++) { - this.PartTimeSchedules[i][j] = pts[i][j] * a[j]; + public AbsenceSchedulesArray(SchedulesArray myScheduleArray) { + super(myScheduleArray); + } + + public void generateAbsences(RandomEngine r) { + for (int i = 0; i < this.maxPartTimeEmployee; i++) { + int[] a = new AbsencesVector(this.workPeriodsPerSchedule, r).getAbsencesVector(); + for (int j = 0; j < this.workPeriodsPerSchedule; j++) { + this.PartTimeSchedules[i][j] = this.PartTimeSchedules[i][j] * a[j]; } } - for (int i = 0; i < I.getMaxFullTimeEmployee(); i++) { - int[] a = new AbsencesVector(wps, r).getAbsencesVector(); - for (int j = 0; j < wps; j++) { - this.FullTimeSchedules[i][j] = fts[i][j] * a[j]; + for (int i = 0; i < this.maxFullTimeEmployee; i++) { + int[] a = new AbsencesVector(this.workPeriodsPerSchedule, r).getAbsencesVector(); + for (int j = 0; j < this.workPeriodsPerSchedule; j++) { + this.FullTimeSchedules[i][j] = this.FullTimeSchedules[i][j] * a[j]; } } + updateEmployeesPerWorkPeriod(); + updateWorkingPeriodsPerPartTimeEmployees(); + updateWorkingPeriodsPerFullTimeEmployees(); } - public int[][] getFullTimeSchedules() { - return FullTimeSchedules; - } - - public int[][] getPartTimeSchedules() { - return PartTimeSchedules; - } } \ No newline at end of file diff --git a/Travail_de_session/InitialSchedules/InitialSchedulesArray.java b/Travail_de_session/InitialSchedules/InitialSchedulesArray.java deleted file mode 100644 index 75adf84..0000000 --- a/Travail_de_session/InitialSchedules/InitialSchedulesArray.java +++ /dev/null @@ -1,55 +0,0 @@ -package InitialSchedules; - -import org.chocosolver.solver.Solution; - -public class InitialSchedulesArray { - - private int[][] PartTimeSchedules; - private int[][] FullTimeSchedules; - private int maxPartTimeEmployee; - private int maxFullTimeEmployee; - private int workPeriodsPerSchedule; - private ModelInitialSchedules myModelInitialSchedules; - - public InitialSchedulesArray(ModelInitialSchedules m, Solution s) { - this.myModelInitialSchedules = m; - Solution mySolution = s; - this.maxPartTimeEmployee = myModelInitialSchedules.maxPartTimeEmployee; - this.maxFullTimeEmployee = myModelInitialSchedules.maxFullTimeEmployee; - this.workPeriodsPerSchedule = myModelInitialSchedules.myScheduleParameters.workPeriodsPerSchedule; - - this.PartTimeSchedules = new int[this.maxPartTimeEmployee][this.workPeriodsPerSchedule]; - this.FullTimeSchedules = new int[this.maxFullTimeEmployee][this.workPeriodsPerSchedule]; - for (int workPeriod = 0; workPeriod < this.workPeriodsPerSchedule; workPeriod++) { - for (int employee = 0; employee < this.maxPartTimeEmployee; employee++) { - this.PartTimeSchedules[employee][workPeriod] = mySolution.getIntVal(myModelInitialSchedules.workPeriodsSchedulesOfPartTimeEmployees[employee][workPeriod]); - } - } - - for (int workPeriod = 0; workPeriod < this.workPeriodsPerSchedule; workPeriod++) { - for (int employee = 0; employee < this.maxFullTimeEmployee; employee++) { - this.FullTimeSchedules[employee][workPeriod] = mySolution.getIntVal(myModelInitialSchedules.workPeriodsSchedulesOfFullTimeEmployees[employee][workPeriod]); - } - } - } - - public int getMaxFullTimeEmployee() { - return maxFullTimeEmployee; - } - - public int getMaxPartTimeEmployee() { - return maxPartTimeEmployee; - } - - public int getWorkPeriodsPerSchedule() { - return workPeriodsPerSchedule; - } - - public int[][] getFullTimeSchedules() { - return FullTimeSchedules; - } - - public int[][] getPartTimeSchedules() { - return PartTimeSchedules; - } -} diff --git a/Travail_de_session/InitialSchedules/ParametersInitialSchedules.java b/Travail_de_session/InitialSchedules/ParametersInitialSchedules.java index 4f166b5..1b35e1f 100644 --- a/Travail_de_session/InitialSchedules/ParametersInitialSchedules.java +++ b/Travail_de_session/InitialSchedules/ParametersInitialSchedules.java @@ -4,10 +4,10 @@ import org.chocosolver.solver.constraints.extension.Tuples; public class ParametersInitialSchedules { - int workPeriodsPerDay; + public int workPeriodsPerDay; int shiftWorkPerDay; - int daysPerSchedule; - int workPeriodsPerSchedule; + public int daysPerSchedule; + public int workPeriodsPerSchedule; int totalWorkedPeriodsInSchedule; int hoursPerWorkPeriod; @@ -82,7 +82,7 @@ public class ParametersInitialSchedules { this.requiredWorkforce = new int[this.daysPerSchedule * this.workPeriodsPerDay]; this.totalWorkedPeriodsInSchedule = 0; - int[] dailyRequiredWorkforce = new int[]{1, 1, 1, 1, 1, 1}; + int[] dailyRequiredWorkforce = new int[]{2, 2, 4, 4, 3, 3}; for (int day = 0; day < this.daysPerSchedule; day++) { for(int shift = 0; shift < this.workPeriodsPerDay; shift++) { this.requiredWorkforce[day * this.workPeriodsPerDay + shift] = dailyRequiredWorkforce[shift]; diff --git a/Travail_de_session/InitialSchedules/UtilInitialSchedules.java b/Travail_de_session/InitialSchedules/UtilInitialSchedules.java deleted file mode 100644 index 9285298..0000000 --- a/Travail_de_session/InitialSchedules/UtilInitialSchedules.java +++ /dev/null @@ -1,97 +0,0 @@ -package InitialSchedules; - -// classe statique pour mettre fonction utilitaire -public class UtilInitialSchedules { - - private UtilInitialSchedules() { - } - - public static void refineInitialSchedules() { - // A implementer si on veut rafiner la banque d'horaires initiales - } - - public static void printSolutionResults(ModelInitialSchedules myModelInitialSchedules, ParametersInitialSchedules myScheduleParameters) { - // Cette fonction sera a ameliorer avec des sous-fonctions, car elle n'est pas tres explicite. - System.out.print("Schedule Day "); - for (int day = 1; day <= myScheduleParameters.daysPerSchedule; day++) { - System.out.print(day); - System.out.print(" "); - if (day < 10) { - System.out.print(" "); - } - System.out.print("|"); - } - System.out.print("Worked Periods"); - System.out.println(""); - System.out.println("Part-Time Employees"); - int partTimeemployeeNo = 1; - for (int employee = 0; employee < myModelInitialSchedules.maxPartTimeEmployee; employee++) { - if (myModelInitialSchedules.workingPeriodsPerPartTimeEmployees[employee].getValue() >= 0) { - System.out.print("Employee "); - System.out.print(partTimeemployeeNo); - System.out.print(" "); - if (partTimeemployeeNo < 10) { - System.out.print(" "); - } - for (int workPeriod = 0; workPeriod < myScheduleParameters.workPeriodsPerSchedule; workPeriod++) { - if (myModelInitialSchedules.workPeriodsSchedulesOfPartTimeEmployees[employee][workPeriod].getValue() == 1) { - System.out.print("1"); - } else { - System.out.print("0"); - - } - if (workPeriod % myScheduleParameters.workPeriodsPerDay == 5 && workPeriod != 0) { - System.out.print("|"); - } - } - System.out.print(myModelInitialSchedules.workingPeriodsPerPartTimeEmployees[employee].getValue()); - System.out.println(""); - partTimeemployeeNo++; - } - } - int fullTimeemployeeNo = 1; - System.out.println("Full-Time Employees"); - for (int employee = 0; employee < myModelInitialSchedules.maxFullTimeEmployee; employee++) { - if (myModelInitialSchedules.workingPeriodsPerFullTimeEmployees[employee].getValue() >= 0) { - System.out.print("Employee "); - System.out.print(fullTimeemployeeNo); - System.out.print(" "); - if (fullTimeemployeeNo < 10) { - System.out.print(" "); - } - for (int workPeriod = 0; workPeriod < myScheduleParameters.workPeriodsPerSchedule; workPeriod++) { - if (myModelInitialSchedules.workPeriodsSchedulesOfFullTimeEmployees[employee][workPeriod].getValue() == 1) { - System.out.print("1"); - } else { - System.out.print("0"); - - } - if (workPeriod % 6 == 5 && workPeriod != 0) { - System.out.print("|"); - } - } - System.out.print(myModelInitialSchedules.workingPeriodsPerFullTimeEmployees[employee].getValue()); - System.out.println(""); - fullTimeemployeeNo++; - } - } - System.out.print("Working Employees "); - for (int workPeriod = 0; workPeriod < myScheduleParameters.workPeriodsPerSchedule; workPeriod++) { - System.out.print(myModelInitialSchedules.employeesPerWorkPeriods[workPeriod].getValue()); - if (workPeriod % 6 == 5 && workPeriod != 0) { - System.out.print("|"); - } - } - System.out.println(""); - System.out.print("Required Workforce "); - for (int workPeriod = 0; workPeriod < myScheduleParameters.workPeriodsPerSchedule; workPeriod++) { - System.out.print(myScheduleParameters.requiredWorkforce[workPeriod]); - if (workPeriod % 6 == 5 && workPeriod != 0) { - System.out.print("|"); - } - } - System.out.println(""); - - } - -} diff --git a/Travail_de_session/MainClass.java b/Travail_de_session/MainClass.java index c5af916..d7248c5 100644 --- a/Travail_de_session/MainClass.java +++ b/Travail_de_session/MainClass.java @@ -1,31 +1,35 @@ -import AbsenceSchedules.AbsenceSchedulesArray; -import InitialSchedules.InitialSchedulesArray; +//import AbsenceSchedules.AbsenceSchedulesArray; 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 java.util.ArrayList; import java.util.List; +import java.lang.*; + + public class MainClass { public static void main(String[] args) { // Le main ne devrait contenir que les 5 fonctions correspondantes aux etapes du pipeline - List InitialSchedulesArrayList = generateInitialSchedule(); + List initialSchedulesArrayList = generateInitialSchedule(); - GenerateAbsencesSchedule(InitialSchedulesArrayList); + GenerateAbsencesSchedule(initialSchedulesArrayList); // Creer les simulation avec une autre classe. Faire un nouveau package de fonctions. // Algo de recouvrement d'absences. Faire un nouveau package de fonctions. // Trouver meilleure solution et l'afficher. } - private static List generateInitialSchedule() { + private static List generateInitialSchedule() { - List InitialSchedulesArrayList = new ArrayList<>(); + List initialSchedulesArrayList = new ArrayList<>(); InitialSchedules.ParametersInitialSchedules myScheduleParameters = new InitialSchedules.ParametersInitialSchedules(); @@ -44,50 +48,43 @@ public class MainClass { System.err.println("Caught Exception: " + e.getMessage()); } - //solverInitialSchedules.showDashboard(); + solverInitialSchedules.showDashboard(); /*solverInitialSchedules.setSearch(Search.domOverWDegSearch(myModelInitialSchedules.allWorkPeriods));*/ - //solverInitialSchedules.setRestartOnSolutions(); /*Sans restart, toutes les horaires sont identiques*/ - solverInitialSchedules.limitSolution(1); - solverInitialSchedules.limitTime(10000); +// solverInitialSchedules.setRestartOnSolutions(); /*Sans restart, toutes les horaires sont identiques*/ + solverInitialSchedules.limitSolution(2); + //solverInitialSchedules.limitTime(10000); List myInitialSchedulesSolutions; - /*myInitialSchedulesSolutions = solverInitialSchedules.findAllOptimalSolutions - (myModelInitialSchedules.TotalEmployeesSalary, Model.MINIMIZE);*/ +// myInitialSchedulesSolutions = solverInitialSchedules.findAllOptimalSolutions +// (myModelInitialSchedules.TotalEmployeesSalary, Model.MINIMIZE); - myInitialSchedulesSolutions = solverInitialSchedules.findAllSolutions - (); - - // 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. - InitialSchedules.UtilInitialSchedules.printSolutionResults(myModelInitialSchedules, myScheduleParameters); + 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) { - InitialSchedulesArray isa = new InitialSchedules.InitialSchedulesArray(myModelInitialSchedules, CurrentSolution); - InitialSchedulesArrayList.add(isa); + SchedulesArray isa = new SchedulesArray(myModelInitialSchedules, CurrentSolution); + initialSchedulesArrayList.add(isa); } + + // Pour afficher les horaires initiales + SchedulesWindows.ShowSchedulesFrame intialSchedulesViewer = new SchedulesWindows.ShowSchedulesFrame(initialSchedulesArrayList, "Initial Schedules"); - // 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)); - }*/ - - return InitialSchedulesArrayList; + return initialSchedulesArrayList; } - private static void GenerateAbsencesSchedule(List InitialSchedulesArrayList) { + private static void GenerateAbsencesSchedule(List initialSchedulesArrayList) { + RandomEngine r = new MersenneTwister(123456789); - for (InitialSchedulesArray Schedule : InitialSchedulesArrayList) { - AbsenceSchedulesArray a = new AbsenceSchedulesArray(Schedule, r); - //System.out.println(Arrays.deepToString(a.getPartTimeSchedules())); - //System.out.println(Arrays.deepToString(a.getFullTimeSchedules())); + List absenceSchedulesArrayList = new ArrayList<>(); + for (SchedulesArray initialSchedule : initialSchedulesArrayList) { + +// SchedulesArray copyInitialSchedule = initialSchedule.clone(); + AbsenceSchedulesArray absenceSchedule = new AbsenceSchedulesArray(initialSchedule); + absenceSchedule.generateAbsences(r); + absenceSchedulesArrayList.add(absenceSchedule); } + // Pour afficher les horaires avec absence + SchedulesWindows.ShowSchedulesFrame absenceSchedulesViewer = new SchedulesWindows.ShowSchedulesFrame(absenceSchedulesArrayList, "Absence Schedules"); } } diff --git a/Travail_de_session/ScheduleUtil/PrintSchedules.java b/Travail_de_session/ScheduleUtil/PrintSchedules.java new file mode 100644 index 0000000..34f0c01 --- /dev/null +++ b/Travail_de_session/ScheduleUtil/PrintSchedules.java @@ -0,0 +1,86 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package ScheduleUtil; + + +/** + * + * @author frabe + */ + +// classe statique pour mettre fonction utilitaire +public class PrintSchedules { + + public static String getFormattedSchedule(SchedulesArray schedule) { + // Cette fonction sera a ameliorer avec des sous-fonctions, car elle n'est pas tres explicite. + StringBuilder sbuf = new StringBuilder(); + sbuf.append(String.format("%-31s", "Schedule Day")); + for (int day = 1; day <= schedule.getDaysPerSchedule(); day++) { + sbuf.append(String.format("%02d" + "%18s" + "%s", day, "" , "|")); + } + sbuf.append(" Worked Periods\n"); + + sbuf.append("Part-Time Employees\n"); + for (int employee = 0; employee < schedule.getMaxPartTimeEmployee(); employee++) { + sbuf.append(String.format("%s" + "%02d" + "%-20s","Employee ", employee, " ")); + + for (int workPeriod = 0; workPeriod < schedule.getWorkPeriodsPerSchedule(); workPeriod++) { + if (schedule.isPartTimeEmployeeWorking(employee,workPeriod)) { + sbuf.append(String.format("%2d", 1)); + } else { + sbuf.append(String.format("%2d", 0)); + } + if (workPeriod % schedule.getWorkPeriodPerDay()== 5 && workPeriod != 0) { + sbuf.append(String.format("%2s" + "%-2s", "" , "|")); + } + } + + sbuf.append(String.format("%02d" + "%s", schedule.getWorkingPeriodsPerPartTimeEmployees(employee), "\n")); + } + + sbuf.append("Full-Time Employees\n"); + for (int employee = 0; employee < schedule.getMaxFullTimeEmployee(); employee++) { + sbuf.append(String.format("%-5s" + "%02d" + "%-20s","Employee ", employee, " ")); + + for (int workPeriod = 0; workPeriod < schedule.getWorkPeriodsPerSchedule(); workPeriod++) { + if (schedule.isFullTimeEmployeeWorking(employee,workPeriod)) { + sbuf.append(String.format("%2d", 1)); + } else { + sbuf.append(String.format("%2d", 0)); + } + if (workPeriod % schedule.getWorkPeriodPerDay()== 5 && workPeriod != 0) { + sbuf.append(String.format("%2s" + "%-2s", "" , "|")); + } + } + sbuf.append(String.format("%02d" + "%s", schedule.getWorkingPeriodsPerFullTimeEmployees(employee), "\n")); + + } + + sbuf.append(String.format("%-24s", "Working Employees ")); + for (int workPeriod = 0; workPeriod < schedule.getWorkPeriodsPerSchedule(); workPeriod++) { + sbuf.append(String.format("%2d", schedule.getEmployeesPerWorkPeriod(workPeriod))); + if (workPeriod % schedule.getWorkPeriodPerDay() == 5 && workPeriod != 0) { + sbuf.append(String.format("%2s" + "%-2s", "" , "|")); + } + } + sbuf.append("\n"); + + sbuf.append(String.format("%-25s", "Required Workforce ")); + for (int workPeriod = 0; workPeriod < schedule.getWorkPeriodsPerSchedule(); workPeriod++) { + sbuf.append(String.format("%2d", schedule.getRequiredWorkForce(workPeriod))); + if (workPeriod % schedule.getWorkPeriodPerDay() == 5 && workPeriod != 0) { + sbuf.append(String.format("%2s" + "%-2s", "" , "|")); + } + } + sbuf.append("\n"); + + return sbuf.toString(); + + } + + +} + diff --git a/Travail_de_session/ScheduleUtil/SchedulesArray.java b/Travail_de_session/ScheduleUtil/SchedulesArray.java new file mode 100644 index 0000000..f62217a --- /dev/null +++ b/Travail_de_session/ScheduleUtil/SchedulesArray.java @@ -0,0 +1,187 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package ScheduleUtil; + +import InitialSchedules.*; +import jdistlib.rng.RandomEngine; +import org.chocosolver.solver.Solution; + + + +/** + * + * @author frabe + */ +public class SchedulesArray { + + protected int[][] PartTimeSchedules; + protected int[][] FullTimeSchedules; + protected int[] employeesPerWorkPeriod; + protected int[] workingPeriodsPerPartTimeEmployees; + protected int[] workingPeriodsPerFullTimeEmployees; + protected int maxPartTimeEmployee; + protected int maxFullTimeEmployee; + protected int workPeriodsPerSchedule; + protected int workPeriodsPerDay; + protected int daysPerSchedule; + protected ModelInitialSchedules myModelInitialSchedules; + + protected SchedulesArray() { + + } + + // Constructeur Copie + protected SchedulesArray(SchedulesArray myScheduleArray) { + + this.maxPartTimeEmployee = myScheduleArray.maxPartTimeEmployee; + this.maxFullTimeEmployee = myScheduleArray.maxFullTimeEmployee; + this.workPeriodsPerSchedule = myScheduleArray.workPeriodsPerSchedule; + this.workPeriodsPerDay = myScheduleArray.workPeriodsPerDay; + this.daysPerSchedule = myScheduleArray.daysPerSchedule; + this.myModelInitialSchedules = myScheduleArray.myModelInitialSchedules; + + this.PartTimeSchedules = new int[this.maxPartTimeEmployee][this.workPeriodsPerSchedule]; + this.FullTimeSchedules = new int[this.maxFullTimeEmployee][this.workPeriodsPerSchedule]; + for (int workPeriod = 0; workPeriod < this.workPeriodsPerSchedule; workPeriod++) { + for (int employee = 0; employee < this.maxPartTimeEmployee; employee++) { + this.PartTimeSchedules[employee][workPeriod] = myScheduleArray.PartTimeSchedules[employee][workPeriod]; + } + } + + for (int workPeriod = 0; workPeriod < this.workPeriodsPerSchedule; workPeriod++) { + for (int employee = 0; employee < this.maxFullTimeEmployee; employee++) { + this.FullTimeSchedules[employee][workPeriod] = myScheduleArray.FullTimeSchedules[employee][workPeriod]; + } + } + + this.employeesPerWorkPeriod = new int[this.workPeriodsPerSchedule]; + this.workingPeriodsPerPartTimeEmployees = new int[this.maxPartTimeEmployee]; + this.workingPeriodsPerFullTimeEmployees = new int[this.maxFullTimeEmployee]; + + updateEmployeesPerWorkPeriod(); + updateWorkingPeriodsPerPartTimeEmployees(); + updateWorkingPeriodsPerFullTimeEmployees(); + + } + + public SchedulesArray(ModelInitialSchedules m, Solution s) { + this.myModelInitialSchedules = m; + Solution mySolution = s; + this.maxPartTimeEmployee = myModelInitialSchedules.maxPartTimeEmployee; + this.maxFullTimeEmployee = myModelInitialSchedules.maxFullTimeEmployee; + this.workPeriodsPerSchedule = myModelInitialSchedules.myScheduleParameters.workPeriodsPerSchedule; + this.workPeriodsPerDay = myModelInitialSchedules.myScheduleParameters.workPeriodsPerDay; + this.daysPerSchedule = myModelInitialSchedules.myScheduleParameters.daysPerSchedule; + + this.PartTimeSchedules = new int[this.maxPartTimeEmployee][this.workPeriodsPerSchedule]; + this.FullTimeSchedules = new int[this.maxFullTimeEmployee][this.workPeriodsPerSchedule]; + for (int workPeriod = 0; workPeriod < this.workPeriodsPerSchedule; workPeriod++) { + for (int employee = 0; employee < this.maxPartTimeEmployee; employee++) { + this.PartTimeSchedules[employee][workPeriod] = mySolution.getIntVal(myModelInitialSchedules.workPeriodsSchedulesOfPartTimeEmployees[employee][workPeriod]); + } + } + + for (int workPeriod = 0; workPeriod < this.workPeriodsPerSchedule; workPeriod++) { + for (int employee = 0; employee < this.maxFullTimeEmployee; employee++) { + this.FullTimeSchedules[employee][workPeriod] = mySolution.getIntVal(myModelInitialSchedules.workPeriodsSchedulesOfFullTimeEmployees[employee][workPeriod]); + } + } + + this.employeesPerWorkPeriod = new int[this.workPeriodsPerSchedule]; + this.workingPeriodsPerPartTimeEmployees = new int[this.maxPartTimeEmployee]; + this.workingPeriodsPerFullTimeEmployees = new int[this.maxFullTimeEmployee]; + + updateEmployeesPerWorkPeriod(); + updateWorkingPeriodsPerPartTimeEmployees(); + updateWorkingPeriodsPerFullTimeEmployees(); + + } + + protected void updateEmployeesPerWorkPeriod() { + + for (int workPeriod = 0; workPeriod < this.workPeriodsPerSchedule; workPeriod++) { + this.employeesPerWorkPeriod[workPeriod] = 0; + for (int employee = 0; employee < this.maxPartTimeEmployee; employee++) { + this.employeesPerWorkPeriod[workPeriod] += this.PartTimeSchedules[employee][workPeriod]; + } + for (int employee = 0; employee < this.maxFullTimeEmployee; employee++) { + this.employeesPerWorkPeriod[workPeriod] += this.FullTimeSchedules[employee][workPeriod]; + } + } + } + + protected void updateWorkingPeriodsPerPartTimeEmployees() { + + for (int employee = 0; employee < this.maxPartTimeEmployee; employee++) { + this.workingPeriodsPerPartTimeEmployees[employee] = 0; + for (int workPeriod = 0; workPeriod < this.workPeriodsPerSchedule; workPeriod++) { + this.workingPeriodsPerPartTimeEmployees[employee] += this.PartTimeSchedules[employee][workPeriod]; + } + } + } + + protected void updateWorkingPeriodsPerFullTimeEmployees() { + + for (int employee = 0; employee < this.maxFullTimeEmployee; employee++) { + this.workingPeriodsPerFullTimeEmployees[employee] = 0; + for (int workPeriod = 0; workPeriod < this.workPeriodsPerSchedule; workPeriod++) { + this.workingPeriodsPerFullTimeEmployees[employee] += this.FullTimeSchedules[employee][workPeriod]; + } + } + } + + public int getMaxFullTimeEmployee() { + return maxFullTimeEmployee; + } + + public int getMaxPartTimeEmployee() { + return maxPartTimeEmployee; + } + + public int getWorkPeriodsPerSchedule() { + return workPeriodsPerSchedule; + } + + public int getDaysPerSchedule() { + return daysPerSchedule; + } + + public int getWorkPeriodPerDay() { + return workPeriodsPerDay; + } + + public int[][] getFullTimeSchedules() { + return FullTimeSchedules; + } + + public int[][] getPartTimeSchedules() { + return PartTimeSchedules; + } + + public boolean isPartTimeEmployeeWorking(int employee, int workPeriod) { + return PartTimeSchedules[employee][workPeriod] == 1; + } + + public boolean isFullTimeEmployeeWorking(int employee, int workPeriod) { + return FullTimeSchedules[employee][workPeriod] == 1; + } + + public int getRequiredWorkForce(int workPeriod) { + return myModelInitialSchedules.myScheduleParameters.requiredWorkforce[workPeriod]; + } + + public int getEmployeesPerWorkPeriod(int workPeriod) { + return employeesPerWorkPeriod[workPeriod]; + } + + public int getWorkingPeriodsPerPartTimeEmployees(int employee) { + return workingPeriodsPerPartTimeEmployees[employee]; + } + + public int getWorkingPeriodsPerFullTimeEmployees(int employee) { + return workingPeriodsPerFullTimeEmployees[employee]; + } +} diff --git a/Travail_de_session/SchedulesWindows/ShowSchedulesFrame.form b/Travail_de_session/SchedulesWindows/ShowSchedulesFrame.form new file mode 100644 index 0000000..8f7e824 --- /dev/null +++ b/Travail_de_session/SchedulesWindows/ShowSchedulesFrame.form @@ -0,0 +1,120 @@ + + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/Travail_de_session/SchedulesWindows/ShowSchedulesFrame.java b/Travail_de_session/SchedulesWindows/ShowSchedulesFrame.java new file mode 100644 index 0000000..29f1f12 --- /dev/null +++ b/Travail_de_session/SchedulesWindows/ShowSchedulesFrame.java @@ -0,0 +1,139 @@ +/* + * To change this license header, choose License Headers in Project Properties. + * To change this template file, choose Tools | Templates + * and open the template in the editor. + */ +package SchedulesWindows; + +import java.util.*; + +/** + * + * @author frabe + */ +public class ShowSchedulesFrame extends javax.swing.JFrame { + + private List schedulesArrayList; + private String title; + /** + * Creates new form ShowSchedulesFrame + */ + public ShowSchedulesFrame(List schedulesArrayList, String title) { + this.schedulesArrayList = schedulesArrayList; + this.title = title; + initComponents(); + init(); + } + + private void init() { + setTitle(title); + setVisible(true); + changeScheduleNumberScrollBar.setMinimum(1); + int numberOfSchedules = this.schedulesArrayList.size(); + changeScheduleNumberScrollBar.setMaximum(numberOfSchedules); + changeScheduleNumberScrollBar.setBlockIncrement(numberOfSchedules/10); + changeScheduleNumberScrollBar.setVisibleAmount(numberOfSchedules/10); + changeScheduleNumberScrollBar.setUnitIncrement(1); + } + + + + @SuppressWarnings("unchecked") + // //GEN-BEGIN:initComponents + private void initComponents() { + + mainPanel = new javax.swing.JPanel(); + changeScheduleNumberScrollBar = new javax.swing.JScrollBar(); + jScrollPane1 = new javax.swing.JScrollPane(); + scheduleViewerArea = new javax.swing.JTextArea(); + jLabel1 = new javax.swing.JLabel(); + textSolutionNumber = new javax.swing.JLabel(); + + setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE); + setPreferredSize(new java.awt.Dimension(1400, 1000)); + + mainPanel.setPreferredSize(new java.awt.Dimension(1400, 1000)); + + changeScheduleNumberScrollBar.addAdjustmentListener(new java.awt.event.AdjustmentListener() { + public void adjustmentValueChanged(java.awt.event.AdjustmentEvent evt) { + changeScheduleNumberScrollBarAdjustmentValueChanged(evt); + } + }); + + scheduleViewerArea.setEditable(false); + scheduleViewerArea.setColumns(20); + scheduleViewerArea.setRows(5); + jScrollPane1.setViewportView(scheduleViewerArea); + + jLabel1.setText("Solution number"); + + textSolutionNumber.setText("0"); + + javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel); + mainPanel.setLayout(mainPanelLayout); + mainPanelLayout.setHorizontalGroup( + mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(mainPanelLayout.createSequentialGroup() + .addContainerGap() + .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(changeScheduleNumberScrollBar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addComponent(jScrollPane1)) + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(18, 18, 18) + .addComponent(textSolutionNumber, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGap(0, 1166, Short.MAX_VALUE))) + .addContainerGap()) + ); + mainPanelLayout.setVerticalGroup( + mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, mainPanelLayout.createSequentialGroup() + .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) + .addComponent(jLabel1) + .addComponent(textSolutionNumber)) + .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) + .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(changeScheduleNumberScrollBar, javax.swing.GroupLayout.PREFERRED_SIZE, 900, javax.swing.GroupLayout.PREFERRED_SIZE) + .addGroup(mainPanelLayout.createSequentialGroup() + .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 900, javax.swing.GroupLayout.PREFERRED_SIZE) + .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))) + ); + + javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); + getContentPane().setLayout(layout); + layout.setHorizontalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addComponent(mainPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) + ); + layout.setVerticalGroup( + layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) + .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() + .addGap(0, 0, 0) + .addComponent(mainPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 900, Short.MAX_VALUE)) + ); + + pack(); + }// //GEN-END:initComponents + + private void changeScheduleNumberScrollBarAdjustmentValueChanged(java.awt.event.AdjustmentEvent evt) {//GEN-FIRST:event_changeScheduleNumberScrollBarAdjustmentValueChanged + // TODO add your handling code here: + int scrollBarValue = evt.getValue(); + textSolutionNumber.setText(String.valueOf(scrollBarValue)); + refreshScheduleText(scrollBarValue); + }//GEN-LAST:event_changeScheduleNumberScrollBarAdjustmentValueChanged + + private void refreshScheduleText(int scrollBarValue) { + scheduleViewerArea.setText(ScheduleUtil.PrintSchedules.getFormattedSchedule(schedulesArrayList.get(scrollBarValue-1))); + } + + // Variables declaration - do not modify//GEN-BEGIN:variables + private javax.swing.JScrollBar changeScheduleNumberScrollBar; + private javax.swing.JLabel jLabel1; + private javax.swing.JScrollPane jScrollPane1; + private javax.swing.JPanel mainPanel; + private javax.swing.JTextArea scheduleViewerArea; + private javax.swing.JLabel textSolutionNumber; + // End of variables declaration//GEN-END:variables +}