ajout du générateur d'absences

This commit is contained in:
François Pelletier 2018-03-26 23:57:03 -04:00
parent 2d090e167c
commit 48a2beaaf3
5 changed files with 132 additions and 16 deletions

View file

@ -0,0 +1,41 @@
package AbsenceSchedules;
import InitialSchedules.InitialSchedulesArray;
import jdistlib.rng.RandomEngine;
public class AbsenceSchedulesArray {
private int[][] PartTimeSchedules;
private int[][] FullTimeSchedules;
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];
}
}
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];
}
}
}
public int[][] getFullTimeSchedules() {
return FullTimeSchedules;
}
public int[][] getPartTimeSchedules() {
return PartTimeSchedules;
}
}

View file

@ -0,0 +1,33 @@
package AbsenceSchedules;
import jdistlib.Binomial;
import jdistlib.rng.RandomEngine;
public class AbsencesVector {
private int[] AbsencesVector;
private double probAbsence = 0.02;
private double probReturn = 0.50;
public AbsencesVector(int length, RandomEngine r) {
int current = 1;
AbsencesVector = new int[length];
Binomial b1 = new Binomial(1, probAbsence);
b1.setRandomEngine(r);
Binomial b2 = new Binomial(1, probReturn);
b2.setRandomEngine(r);
for (int i = 0; i < length; i++) {
if (current == 1) {
current = (int) b1.random();
AbsencesVector[i] = current;
} else {
current = (int) b2.random();
AbsencesVector[i] = current;
}
}
}
public int[] getAbsencesVector() {
return AbsencesVector;
}
}

View file

@ -4,27 +4,52 @@ import org.chocosolver.solver.Solution;
public class InitialSchedulesArray {
public int[][] InitialPartTimeSchedules;
public int[][] InitialFullTimeSchedules;
private int[][] PartTimeSchedules;
private int[][] FullTimeSchedules;
private int maxPartTimeEmployee;
private int maxFullTimeEmployee;
private int workPeriodsPerSchedule;
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]);
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 < myModelInitialSchedules.myScheduleParameters.workPeriodsPerSchedule; workPeriod++) {
for (int employee = 0; employee < myModelInitialSchedules.maxFullTimeEmployee; employee++) {
this.InitialFullTimeSchedules[employee][workPeriod] = mySolution.getIntVal(myModelInitialSchedules.workPeriodsSchedulesOfFullTimeEmployees[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;
}
}

View file

@ -1,4 +1,7 @@
import AbsenceSchedules.AbsenceSchedulesArray;
import InitialSchedules.InitialSchedulesArray;
import jdistlib.rng.MersenneTwister;
import jdistlib.rng.RandomEngine;
import org.chocosolver.solver.Solution;
import org.chocosolver.solver.Solver;
import org.chocosolver.solver.exception.ContradictionException;
@ -11,14 +14,17 @@ public class MainClass {
public static void main(String[] args) {
// Le main ne devrait contenir que les 5 fonctions correspondantes aux etapes du pipeline
generateInitialSchedule();
List<InitialSchedules.InitialSchedulesArray> InitialSchedulesArrayList = generateInitialSchedule();
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 void generateInitialSchedule() {
private static List<InitialSchedules.InitialSchedulesArray> generateInitialSchedule() {
List<InitialSchedules.InitialSchedulesArray> InitialSchedulesArrayList = new ArrayList<>();
InitialSchedules.ParametersInitialSchedules myScheduleParameters
= new InitialSchedules.ParametersInitialSchedules();
@ -40,7 +46,7 @@ public class MainClass {
//solverInitialSchedules.showDashboard();
/*solverInitialSchedules.setSearch(Search.domOverWDegSearch(myModelInitialSchedules.allWorkPeriods));*/
//solverInitialSchedules.setRestartOnSolutions(); /*Sans restart, toutes les horaires sont identiques*/
solverInitialSchedules.limitSolution(100);
solverInitialSchedules.limitSolution(2);
solverInitialSchedules.limitTime(10000);
List<Solution> myInitialSchedulesSolutions;
myInitialSchedulesSolutions = solverInitialSchedules.findAllSolutions
@ -54,7 +60,6 @@ public class MainClass {
// Création de l'objet banque d'horaire, qui est une liste d'objets de type InitialSchedulesArray, qui contiennent chacun deux tableaux.
List<InitialSchedules.InitialSchedulesArray> InitialSchedulesArrayList = new ArrayList<>();
for (Solution CurrentSolution : myInitialSchedulesSolutions) {
InitialSchedulesArray isa = new InitialSchedules.InitialSchedulesArray(myModelInitialSchedules, CurrentSolution);
@ -68,5 +73,17 @@ public class MainClass {
for (InitialSchedulesArray isa: InitialSchedulesArrayList) {
System.out.println(Arrays.deepToString(isa.InitialFullTimeSchedules));
}*/
return InitialSchedulesArrayList;
}
private static void GenerateAbsencesSchedule(List<InitialSchedules.InitialSchedulesArray> 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()));
}
}
}

Binary file not shown.