Première ébauche du code pour le travail de session

- Creation de la classe mainClass.
- Creation du package InitalSchedule qui contient les fonctions qui permettront de générer une banque d'horaire à soumettre au simulateur.

TODO :
- Ajouter des contraintes pour les employés à temps partiel, car leur quart de travail ne font pas de sens.
- Calculer les coûts des salaires et des profits générés et implanter une fonction objectif à optimiser.
This commit is contained in:
DESKTOP-55SK9QE\frabe 2018-03-18 16:22:30 -04:00
parent 5fdcc60194
commit f5309b7f8d
14 changed files with 866 additions and 316 deletions

11
.project Normal file
View file

@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Travail de session</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
</buildSpec>
<natures>
</natures>
</projectDescription>

View file

@ -1,118 +1,118 @@
import org.chocosolver.solver.Model;
import org.chocosolver.solver.Solver;
import org.chocosolver.solver.variables.IntVar;
import org.chocosolver.solver.constraints.extension.Tuples;
public class Exercice1 {
public static final int HEURISTIQUE_DEFAUT = 0;
public static final int HEURISTIQUE_DOMOVERWDEG = 1;
public static final int HEURISTIQUE_IMPACT_BASED_SEARCH = 2;
public static final int HEURISTIQUE_ACTIVITY = 3;
public static final String COHERENCE_BORNES = "BC";
public static final String COHERENCE_DOMAINES = "AC";
public static final int RESTART_AUCUN = 0;
public static final int RESTART_LUBY = 1;
public static final int RESTART_GEOMETRIQUE = 2;
public static void main(String[] args) {
final int N = 4;
final int F = 4;
final String coherence = COHERENCE_BORNES;
Model model = new Model("Quatre cubes");
// Énumération des combinaisons dans un tableau. 1: rouge, 2:vert, 3:bleu, 4:jaune
int[][] tableauCubeUn = new int[][]{
{3,4,1,2},{3,2,1,1},{3,2,1,4},{3,1,1,2},
{2,3,4,1},{2,2,4,1},{2,1,4,3},{2,1,4,2},
{1,2,3,4},{1,2,3,1},{1,4,3,2},{1,1,3,2},
{4,2,2,1},{4,3,2,1},{4,1,2,2},{4,1,2,3},
{2,4,1,2},{2,1,1,3},{2,2,1,4},{2,3,1,1},
{1,4,2,2},{1,3,2,1},{1,2,2,4},{1,1,2,3},
};
int[][] tableauCubeDeux = new int[][]{
{4,2,3,2},{4,1,3,3},{4,2,3,2},{4,3,3,1},
{2,1,2,3},{2,3,2,1},{2,3,2,4},{2,4,2,3},
{3,1,4,3},{3,3,4,1},{3,2,4,2},{3,2,4,2},
{2,1,2,3},{2,3,2,1},{2,4,2,3},{2,3,2,4},
{1,3,3,4},{1,4,3,3},{1,2,3,2},{1,2,3,2},
{3,4,1,3},{3,3,1,4},{3,2,1,2},{3,2,1,2},
};
int[][] tableauCubeTrois = new int[][]{
{3,4,1,4},{3,4,1,4},{3,2,1,4},{3,4,1,2},
{4,4,2,4},{4,4,2,4},{4,1,2,3},{4,3,2,1},
{1,4,3,4},{1,4,3,4},{1,4,3,2},{1,2,3,4},
{2,4,4,4},{2,4,4,4},{2,1,4,3},{2,3,4,1},
{4,4,4,2},{4,2,4,4},{4,3,4,1},{4,1,4,3},
{4,4,4,2},{4,2,4,4},{4,3,4,1},{4,1,4,3},
};
int[][] tableauCubeQuatre = new int[][]{
{3,1,4,2},{3,2,4,1},{3,1,4,4},{3,4,4,1},
{1,1,4,2},{1,2,4,1},{1,4,4,3},{1,3,4,4},
{4,1,3,2},{4,2,3,1},{4,1,3,4},{4,4,3,1},
{4,1,1,2},{4,2,1,1},{4,3,1,4},{4,4,1,3},
{2,3,1,4},{2,4,1,3},{2,1,1,4},{2,4,1,1},
{1,4,2,3},{1,3,2,4},{1,1,2,4},{1,4,2,1},
};
// Création des tuples à partir des tableaux pour implémenter les contraintes table.
Tuples tuplesCubeUn = new Tuples(tableauCubeUn, true);
Tuples tuplesCubeDeux = new Tuples(tableauCubeDeux, true);
Tuples tuplesCubeTrois = new Tuples(tableauCubeTrois, true);
Tuples tuplesCubeQuatre = new Tuples(tableauCubeQuatre, true);
IntVar[][] facesCubes = model.intVarMatrix("x", N, F, 1, 4, false);
model.table(facesCubes[0], tuplesCubeUn).post();
model.table(facesCubes[1], tuplesCubeDeux).post();
model.table(facesCubes[2], tuplesCubeTrois).post();
model.table(facesCubes[3], tuplesCubeQuatre).post();
// On créé la transpose de la matrice facesCubes pour pouvoir effectuer la contrainte ALLDIFFERENT.
IntVar[][] faceRectangulaires = new IntVar[F][N];
for (int noFace = 0; noFace < F; noFace++) {
for (int noCube = 0; noCube < N; noCube++) {
faceRectangulaires[noFace][noCube] = facesCubes[noCube][noFace];
}
model.allDifferent(faceRectangulaires[noFace], coherence).post();
}
// Creation et lancement du solveur.
Solver solver = model.getSolver();
solver.findSolution();
// On affiche la solution.
System.out.print(" ");
for (int noCube = 0; noCube < N; noCube++) {
System.out.print(" Cube ");
System.out.print(noCube);
System.out.print(" ");
}
System.out.println("");
for (int noFace = 0; noFace < F; noFace++) {
System.out.print(" Face ");
System.out.print(noFace);
System.out.print(" ");
for (int noCube = 0; noCube < N; noCube++) {
if (faceRectangulaires[noFace][noCube].getValue() == 1) {
System.out.print(" R ");
}else if (faceRectangulaires[noFace][noCube].getValue() == 2) {
System.out.print(" V ");
}else if (faceRectangulaires[noFace][noCube].getValue() == 3) {
System.out.print(" B ");
}else {
System.out.print(" J ");
}
System.out.print(" ");
}
System.out.println("");
}
solver.printStatistics();
}
}
import org.chocosolver.solver.Model;
import org.chocosolver.solver.Solver;
import org.chocosolver.solver.variables.IntVar;
import org.chocosolver.solver.constraints.extension.Tuples;
public class Exercice1 {
public static final int HEURISTIQUE_DEFAUT = 0;
public static final int HEURISTIQUE_DOMOVERWDEG = 1;
public static final int HEURISTIQUE_IMPACT_BASED_SEARCH = 2;
public static final int HEURISTIQUE_ACTIVITY = 3;
public static final String COHERENCE_BORNES = "BC";
public static final String COHERENCE_DOMAINES = "AC";
public static final int RESTART_AUCUN = 0;
public static final int RESTART_LUBY = 1;
public static final int RESTART_GEOMETRIQUE = 2;
public static void main(String[] args) {
final int N = 4;
final int F = 4;
final String coherence = COHERENCE_BORNES;
Model model = new Model("Quatre cubes");
// Énumération des combinaisons dans un tableau. 1: rouge, 2:vert, 3:bleu, 4:jaune
int[][] tableauCubeUn = new int[][]{
{3,4,1,2},{3,2,1,1},{3,2,1,4},{3,1,1,2},
{2,3,4,1},{2,2,4,1},{2,1,4,3},{2,1,4,2},
{1,2,3,4},{1,2,3,1},{1,4,3,2},{1,1,3,2},
{4,2,2,1},{4,3,2,1},{4,1,2,2},{4,1,2,3},
{2,4,1,2},{2,1,1,3},{2,2,1,4},{2,3,1,1},
{1,4,2,2},{1,3,2,1},{1,2,2,4},{1,1,2,3},
};
int[][] tableauCubeDeux = new int[][]{
{4,2,3,2},{4,1,3,3},{4,2,3,2},{4,3,3,1},
{2,1,2,3},{2,3,2,1},{2,3,2,4},{2,4,2,3},
{3,1,4,3},{3,3,4,1},{3,2,4,2},{3,2,4,2},
{2,1,2,3},{2,3,2,1},{2,4,2,3},{2,3,2,4},
{1,3,3,4},{1,4,3,3},{1,2,3,2},{1,2,3,2},
{3,4,1,3},{3,3,1,4},{3,2,1,2},{3,2,1,2},
};
int[][] tableauCubeTrois = new int[][]{
{3,4,1,4},{3,4,1,4},{3,2,1,4},{3,4,1,2},
{4,4,2,4},{4,4,2,4},{4,1,2,3},{4,3,2,1},
{1,4,3,4},{1,4,3,4},{1,4,3,2},{1,2,3,4},
{2,4,4,4},{2,4,4,4},{2,1,4,3},{2,3,4,1},
{4,4,4,2},{4,2,4,4},{4,3,4,1},{4,1,4,3},
{4,4,4,2},{4,2,4,4},{4,3,4,1},{4,1,4,3},
};
int[][] tableauCubeQuatre = new int[][]{
{3,1,4,2},{3,2,4,1},{3,1,4,4},{3,4,4,1},
{1,1,4,2},{1,2,4,1},{1,4,4,3},{1,3,4,4},
{4,1,3,2},{4,2,3,1},{4,1,3,4},{4,4,3,1},
{4,1,1,2},{4,2,1,1},{4,3,1,4},{4,4,1,3},
{2,3,1,4},{2,4,1,3},{2,1,1,4},{2,4,1,1},
{1,4,2,3},{1,3,2,4},{1,1,2,4},{1,4,2,1},
};
// Création des tuples à partir des tableaux pour implémenter les contraintes table.
Tuples tuplesCubeUn = new Tuples(tableauCubeUn, true);
Tuples tuplesCubeDeux = new Tuples(tableauCubeDeux, true);
Tuples tuplesCubeTrois = new Tuples(tableauCubeTrois, true);
Tuples tuplesCubeQuatre = new Tuples(tableauCubeQuatre, true);
IntVar[][] facesCubes = model.intVarMatrix("x", N, F, 1, 4, false);
model.table(facesCubes[0], tuplesCubeUn).post();
model.table(facesCubes[1], tuplesCubeDeux).post();
model.table(facesCubes[2], tuplesCubeTrois).post();
model.table(facesCubes[3], tuplesCubeQuatre).post();
// On créé la transpose de la matrice facesCubes pour pouvoir effectuer la contrainte ALLDIFFERENT.
IntVar[][] faceRectangulaires = new IntVar[F][N];
for (int noFace = 0; noFace < F; noFace++) {
for (int noCube = 0; noCube < N; noCube++) {
faceRectangulaires[noFace][noCube] = facesCubes[noCube][noFace];
}
model.allDifferent(faceRectangulaires[noFace], coherence).post();
}
// Creation et lancement du solveur.
Solver solver = model.getSolver();
solver.findSolution();
// On affiche la solution.
System.out.print(" ");
for (int noCube = 0; noCube < N; noCube++) {
System.out.print(" Cube ");
System.out.print(noCube);
System.out.print(" ");
}
System.out.println("");
for (int noFace = 0; noFace < F; noFace++) {
System.out.print(" Face ");
System.out.print(noFace);
System.out.print(" ");
for (int noCube = 0; noCube < N; noCube++) {
if (faceRectangulaires[noFace][noCube].getValue() == 1) {
System.out.print(" R ");
}else if (faceRectangulaires[noFace][noCube].getValue() == 2) {
System.out.print(" V ");
}else if (faceRectangulaires[noFace][noCube].getValue() == 3) {
System.out.print(" B ");
}else {
System.out.print(" J ");
}
System.out.print(" ");
}
System.out.println("");
}
solver.printStatistics();
}
}

View file

@ -1,198 +1,198 @@
import org.chocosolver.solver.Model;
import org.chocosolver.solver.Solution;
import org.chocosolver.solver.Solver;
import org.chocosolver.solver.constraints.Constraint;
import org.chocosolver.solver.exception.ContradictionException;
import org.chocosolver.solver.search.limits.FailCounter;
import org.chocosolver.solver.search.strategy.Search;
import org.chocosolver.solver.search.strategy.selectors.variables.DomOverWDeg;
import org.chocosolver.solver.search.strategy.selectors.variables.ImpactBased;
import org.chocosolver.solver.variables.IntVar;
import org.chocosolver.solver.variables.BoolVar;
import java.io.*;
import java.util.Arrays;
public class Exercice2FB {
public static final int HEURISTIQUE_DEFAUT = 0;
public static final int HEURISTIQUE_DOMOVERWDEG = 1;
public static final int HEURISTIQUE_IMPACT_BASED_SEARCH = 2;
public static final int HEURISTIQUE_ACTIVITY = 3;
public static final String COHERENCE_BORNES = "BC";
public static final String COHERENCE_DOMAINES = "AC";
public static final int RESTART_AUCUN = 0;
public static final int RESTART_LUBY = 1;
public static final int RESTART_GEOMETRIQUE = 2;
public static void main(String[] args) {
final int p = 16;
String fileName = "instance.txt";
String line = null;
int[] PARAMETRES_HORAIRE = new int[4];
int[] NBR_EMPLOYES_REQUIS = new int[p];
int[] NBR_EMPLOYES_SOUHAITES = new int[p];
try {
FileReader fileReader =
new FileReader(fileName);
BufferedReader bufferedReader =
new BufferedReader(fileReader);
if((line = bufferedReader.readLine()) != null) {
String[] arrayLine= line.split("\\s+");
PARAMETRES_HORAIRE[0] = Integer.parseInt(arrayLine[0]);
PARAMETRES_HORAIRE[1] = Integer.parseInt(arrayLine[1]);
PARAMETRES_HORAIRE[2] = Integer.parseInt(arrayLine[2]);
PARAMETRES_HORAIRE[3] = Integer.parseInt(arrayLine[3]);
}
if((line = bufferedReader.readLine()) != null) {
String[] arrayLine= line.split("\\s+");
for (int i = 0 ; i < p ; i++) {
NBR_EMPLOYES_REQUIS[i] = Integer.parseInt(arrayLine[i]);
}
}
if((line = bufferedReader.readLine()) != null) {
String[] arrayLine= line.split("\\s+");
for (int i = 0 ; i < p ; i++) {
NBR_EMPLOYES_SOUHAITES[i] = Integer.parseInt(arrayLine[i]);
}
}
bufferedReader.close();
}
catch(FileNotFoundException ex) {
System.out.println(
"Unable to open file '" +
fileName + "'");
}
catch(IOException ex) {
System.out.println(
"Error reading file '"
+ fileName + "'");
}
final int N = PARAMETRES_HORAIRE[0];
final int MIN_H = PARAMETRES_HORAIRE[1];
final int MAX_H = PARAMETRES_HORAIRE[2];
final int MIN_PERIODE = PARAMETRES_HORAIRE[3];
Model model = new Model("Optimisation Employes");
IntVar heure_pause[] = model.intVarArray("HEURE_PAUSE", N, MIN_PERIODE, p-MIN_PERIODE-1, true);
IntVar heure_debut[] = model.intVarArray("HEURE_DEBUT", N, 0, p-MIN_H, true);
IntVar heure_fin[] = model.intVarArray("HEURE_FIN", N, p-MIN_H, p, true);
// Creation des contraintes
for (int i = 0; i < N; i++) {
model.arithm(heure_debut[i], "<=", heure_pause[i], "-", MIN_PERIODE).post();
model.arithm(heure_fin[i], ">=", heure_pause[i], "+", (MIN_PERIODE + 1) ).post();
}
IntVar[] heures_employe = model.intVarArray("C", N, MIN_H, MAX_H, true);
for (int i = 0; i < N; i++) {
model.arithm(heures_employe[i], "=", heure_fin[i], "-", heure_debut[i]).post();
}
// Creation de la transpose de la matrice horaire.
IntVar[][] horaire = model.intVarMatrix(p, N, 0, 1);
IntVar[] nbr_employe = model.intVarArray("C", p, 0, N, true);
for (int i = 0; i < p; i++) {
for (int j = 0; j < N; j++) {
BoolVar c1 = model.arithm(heure_pause[j], "!=", i).reify();
BoolVar c2 = model.arithm(heure_debut[j], "<=", i).reify();
BoolVar c3 = model.arithm(heure_fin[j], ">", i).reify();
model.ifThenElse(model.and(c1, c2, c3), model.arithm(horaire[i][j], "=", 1), model.arithm(horaire[i][j], "=", 0));
}
model.count(model.intVar(1), horaire[i], nbr_employe[i]).post();
model.arithm(nbr_employe[i], ">=", NBR_EMPLOYES_REQUIS[i]).post();
}
IntVar[] diff_employe = model.intVarArray("DIFF_EMPLOYE", p, 0, N);
IntVar[] diff_employe_abs = model.intVarArray("DIFF_EMPLOYE_ABS", p, 0, N);
IntVar[] perte = model.intVarArray("COST", p, 0, 20 * N, true);
for (int i = 0; i < p; i++) {
model.arithm(diff_employe[i], "=", nbr_employe[i] , "-", NBR_EMPLOYES_SOUHAITES[i]).post();
model.absolute(diff_employe_abs[i], diff_employe[i]).post();
model.times(diff_employe_abs[i], model.intVar(20), perte[i]).post();
}
int[] coeffs = new int[p];
Arrays.fill(coeffs, 0, p, 1);
IntVar tot_perte = model.intVar("TOTAL_COST", 0, 20 * N * p, true);
model.scalar(perte , coeffs , "=", tot_perte).post();
// Creation du solveur
Solver solver = model.getSolver();
Solution best = solver.findOptimalSolution(tot_perte, Model.MINIMIZE);
for (int i = 0; i < N; i++) {
System.out.print("Heure_debut : ");
System.out.print(best.getIntVal(heure_debut[i]));
System.out.print(" ");
System.out.print("Heure_pause : ");
System.out.print(best.getIntVal(heure_pause[i]));
System.out.print(" ");
System.out.print("Heure_fin : ");
System.out.print(best.getIntVal(heure_fin[i]));
System.out.println("");
}
System.out.print(9);
System.out.print(" | ");
System.out.print(" ");
System.out.print(" | ");
for (int j = 10; j < 17; j++) {
System.out.print(j);
System.out.print("| ");
System.out.print(" ");
System.out.print("| ");
}
System.out.print("Nbr_heures_travaillees_incluant_pause");
System.out.println("");
for (int i = 0; i < N; i++) {
for (int j = 0; j < p; j++) {
if (best.getIntVal(horaire[j][i]) == 1)
System.out.print("1");
else
System.out.print(" ");
System.out.print(" | ");
}
System.out.print(best.getIntVal(heures_employe[i]));
System.out.println("");
}
for (int i = 0; i < p; i++) {
System.out.print(best.getIntVal(nbr_employe[i]));
System.out.print(" | ");
}
System.out.print("Nbr_employes");
System.out.println("");
for (int i = 0; i < p; i++) {
System.out.print(NBR_EMPLOYES_REQUIS[i]);
System.out.print(" | ");
}
System.out.print("Nbr_employes_requis");
System.out.println("");
for (int i = 0; i < p; i++) {
System.out.print(NBR_EMPLOYES_SOUHAITES[i]);
System.out.print(" | ");
}
System.out.print("Nbr_employes_souhaites");
System.out.println("");
for (int i = 0; i < p; i++) {
System.out.print(best.getIntVal(perte[i]));
if(best.getIntVal(perte[i])==0) {
System.out.print(" | ");
}else {
System.out.print("| ");
}
}
System.out.print("perte");
System.out.println("");
System.out.print("perte_totale : ");
System.out.print(best.getIntVal(tot_perte));
System.out.println("");
solver.printStatistics();
}
}
import org.chocosolver.solver.Model;
import org.chocosolver.solver.Solution;
import org.chocosolver.solver.Solver;
import org.chocosolver.solver.constraints.Constraint;
import org.chocosolver.solver.exception.ContradictionException;
import org.chocosolver.solver.search.limits.FailCounter;
import org.chocosolver.solver.search.strategy.Search;
import org.chocosolver.solver.search.strategy.selectors.variables.DomOverWDeg;
import org.chocosolver.solver.search.strategy.selectors.variables.ImpactBased;
import org.chocosolver.solver.variables.IntVar;
import org.chocosolver.solver.variables.BoolVar;
import java.io.*;
import java.util.Arrays;
public class Exercice2FB {
public static final int HEURISTIQUE_DEFAUT = 0;
public static final int HEURISTIQUE_DOMOVERWDEG = 1;
public static final int HEURISTIQUE_IMPACT_BASED_SEARCH = 2;
public static final int HEURISTIQUE_ACTIVITY = 3;
public static final String COHERENCE_BORNES = "BC";
public static final String COHERENCE_DOMAINES = "AC";
public static final int RESTART_AUCUN = 0;
public static final int RESTART_LUBY = 1;
public static final int RESTART_GEOMETRIQUE = 2;
public static void main(String[] args) {
final int p = 16;
String fileName = "instance.txt";
String line = null;
int[] PARAMETRES_HORAIRE = new int[4];
int[] NBR_EMPLOYES_REQUIS = new int[p];
int[] NBR_EMPLOYES_SOUHAITES = new int[p];
try {
FileReader fileReader =
new FileReader(fileName);
BufferedReader bufferedReader =
new BufferedReader(fileReader);
if((line = bufferedReader.readLine()) != null) {
String[] arrayLine= line.split("\\s+");
PARAMETRES_HORAIRE[0] = Integer.parseInt(arrayLine[0]);
PARAMETRES_HORAIRE[1] = Integer.parseInt(arrayLine[1]);
PARAMETRES_HORAIRE[2] = Integer.parseInt(arrayLine[2]);
PARAMETRES_HORAIRE[3] = Integer.parseInt(arrayLine[3]);
}
if((line = bufferedReader.readLine()) != null) {
String[] arrayLine= line.split("\\s+");
for (int i = 0 ; i < p ; i++) {
NBR_EMPLOYES_REQUIS[i] = Integer.parseInt(arrayLine[i]);
}
}
if((line = bufferedReader.readLine()) != null) {
String[] arrayLine= line.split("\\s+");
for (int i = 0 ; i < p ; i++) {
NBR_EMPLOYES_SOUHAITES[i] = Integer.parseInt(arrayLine[i]);
}
}
bufferedReader.close();
}
catch(FileNotFoundException ex) {
System.out.println(
"Unable to open file '" +
fileName + "'");
}
catch(IOException ex) {
System.out.println(
"Error reading file '"
+ fileName + "'");
}
final int N = PARAMETRES_HORAIRE[0];
final int MIN_H = PARAMETRES_HORAIRE[1];
final int MAX_H = PARAMETRES_HORAIRE[2];
final int MIN_PERIODE = PARAMETRES_HORAIRE[3];
Model model = new Model("Optimisation Employes");
IntVar heure_pause[] = model.intVarArray("HEURE_PAUSE", N, MIN_PERIODE, p-MIN_PERIODE-1, true);
IntVar heure_debut[] = model.intVarArray("HEURE_DEBUT", N, 0, p-MIN_H, true);
IntVar heure_fin[] = model.intVarArray("HEURE_FIN", N, p-MIN_H, p, true);
// Creation des contraintes
for (int i = 0; i < N; i++) {
model.arithm(heure_debut[i], "<=", heure_pause[i], "-", MIN_PERIODE).post();
model.arithm(heure_fin[i], ">=", heure_pause[i], "+", (MIN_PERIODE + 1) ).post();
}
IntVar[] heures_employe = model.intVarArray("C", N, MIN_H, MAX_H, true);
for (int i = 0; i < N; i++) {
model.arithm(heures_employe[i], "=", heure_fin[i], "-", heure_debut[i]).post();
}
// Creation de la transpose de la matrice horaire.
IntVar[][] horaire = model.intVarMatrix(p, N, 0, 1);
IntVar[] nbr_employe = model.intVarArray("C", p, 0, N, true);
for (int i = 0; i < p; i++) {
for (int j = 0; j < N; j++) {
BoolVar c1 = model.arithm(heure_pause[j], "!=", i).reify();
BoolVar c2 = model.arithm(heure_debut[j], "<=", i).reify();
BoolVar c3 = model.arithm(heure_fin[j], ">", i).reify();
model.ifThenElse(model.and(c1, c2, c3), model.arithm(horaire[i][j], "=", 1), model.arithm(horaire[i][j], "=", 0));
}
model.count(model.intVar(1), horaire[i], nbr_employe[i]).post();
model.arithm(nbr_employe[i], ">=", NBR_EMPLOYES_REQUIS[i]).post();
}
IntVar[] diff_employe = model.intVarArray("DIFF_EMPLOYE", p, 0, N);
IntVar[] diff_employe_abs = model.intVarArray("DIFF_EMPLOYE_ABS", p, 0, N);
IntVar[] perte = model.intVarArray("COST", p, 0, 20 * N, true);
for (int i = 0; i < p; i++) {
model.arithm(diff_employe[i], "=", nbr_employe[i] , "-", NBR_EMPLOYES_SOUHAITES[i]).post();
model.absolute(diff_employe_abs[i], diff_employe[i]).post();
model.times(diff_employe_abs[i], model.intVar(20), perte[i]).post();
}
int[] coeffs = new int[p];
Arrays.fill(coeffs, 0, p, 1);
IntVar tot_perte = model.intVar("TOTAL_COST", 0, 20 * N * p, true);
model.scalar(perte , coeffs , "=", tot_perte).post();
// Creation du solveur
Solver solver = model.getSolver();
Solution best = solver.findOptimalSolution(tot_perte, Model.MINIMIZE);
for (int i = 0; i < N; i++) {
System.out.print("Heure_debut : ");
System.out.print(best.getIntVal(heure_debut[i]));
System.out.print(" ");
System.out.print("Heure_pause : ");
System.out.print(best.getIntVal(heure_pause[i]));
System.out.print(" ");
System.out.print("Heure_fin : ");
System.out.print(best.getIntVal(heure_fin[i]));
System.out.println("");
}
System.out.print(9);
System.out.print(" | ");
System.out.print(" ");
System.out.print(" | ");
for (int j = 10; j < 17; j++) {
System.out.print(j);
System.out.print("| ");
System.out.print(" ");
System.out.print("| ");
}
System.out.print("Nbr_heures_travaillees_incluant_pause");
System.out.println("");
for (int i = 0; i < N; i++) {
for (int j = 0; j < p; j++) {
if (best.getIntVal(horaire[j][i]) == 1)
System.out.print("1");
else
System.out.print(" ");
System.out.print(" | ");
}
System.out.print(best.getIntVal(heures_employe[i]));
System.out.println("");
}
for (int i = 0; i < p; i++) {
System.out.print(best.getIntVal(nbr_employe[i]));
System.out.print(" | ");
}
System.out.print("Nbr_employes");
System.out.println("");
for (int i = 0; i < p; i++) {
System.out.print(NBR_EMPLOYES_REQUIS[i]);
System.out.print(" | ");
}
System.out.print("Nbr_employes_requis");
System.out.println("");
for (int i = 0; i < p; i++) {
System.out.print(NBR_EMPLOYES_SOUHAITES[i]);
System.out.print(" | ");
}
System.out.print("Nbr_employes_souhaites");
System.out.println("");
for (int i = 0; i < p; i++) {
System.out.print(best.getIntVal(perte[i]));
if(best.getIntVal(perte[i])==0) {
System.out.print(" | ");
}else {
System.out.print("| ");
}
}
System.out.print("perte");
System.out.println("");
System.out.print("perte_totale : ");
System.out.print(best.getIntVal(tot_perte));
System.out.println("");
solver.printStatistics();
}
}

View file

@ -0,0 +1,163 @@
package InitialSchedules;
import org.chocosolver.solver.Model;
import org.chocosolver.solver.variables.BoolVar;
import org.chocosolver.solver.variables.IntVar;
public class ModelInitialSchedules {
// private final int HEURISTIQUE_DEFAUT = 0;
// private final int HEURISTIQUE_DOMOVERWDEG = 1;
// private final int HEURISTIQUE_IMPACT_BASED_SEARCH = 2;
// private final int HEURISTIQUE_ACTIVITY = 3;
// private final String COHERENCE_BORNES = "BC";
// private final String COHERENCE_DOMAINES = "AC";
// private final int RESTART_AUCUN = 0;
// private final int RESTART_LUBY = 1;
// private final int RESTART_GEOMETRIQUE = 2;
private ParametersInitialSchedules myScheduleParameters;
public int maxPartTimeEmployee;
public int maxFullTimeEmployee;
public IntVar workPeriodsSchedulesOfPartTimeEmployees[][];
private IntVar transposeWorkPeriodsSchedulesOfPartTimeEmployees[][];
public IntVar workPeriodsSchedulesOfFullTimeEmployees[][];
private IntVar transposeWorkPeriodsSchedulesOfFullTimeEmployees[][];
public IntVar workingPeriodsPerPartTimeEmployees[];
public IntVar partTimeEmployeesPerWorkPeriods[];
public IntVar workingPeriodsPerFullTimeEmployees[];
public IntVar fullTimeEmployeesPerWorkPeriods[];
public IntVar employeesPerWorkPeriods[];
public Model chocoModelInitialSchedules;
public IntVar scheduleProfit;
public ModelInitialSchedules(ParametersInitialSchedules myScheduleParameters){
this.myScheduleParameters = myScheduleParameters;
this.chocoModelInitialSchedules = new Model("Model Initial Schedules");
this.createEmployeesVariables ();
this.createScheduleVariables ();
this.createModelConstraints();
this.createModelObjectiveFunction();
}
private void createEmployeesVariables () {
this.maxPartTimeEmployee = (int) Math.ceil((double)myScheduleParameters.totalWorkedPeriodsInSchedule /
myScheduleParameters.minWorkingPeriodsOfPartTimeEmployeesPerSchedule);
this.maxFullTimeEmployee = (int) Math.ceil((double)myScheduleParameters.totalWorkedPeriodsInSchedule /
myScheduleParameters.workingPeriodsOfFullTimeEmployeesPerSchedule);
}
private void createScheduleVariables () {
// Variable pour l'horaire des employes
this.workPeriodsSchedulesOfPartTimeEmployees = chocoModelInitialSchedules.intVarMatrix
(this.maxPartTimeEmployee, this.myScheduleParameters.workPeriodsPerSchedule, 0, 1);
this.workPeriodsSchedulesOfFullTimeEmployees = chocoModelInitialSchedules.intVarMatrix
(this.maxFullTimeEmployee, this.myScheduleParameters.workPeriodsPerSchedule, 0, 1);
// Variable pour faire le compte du nombre d'heures des employes
this.workingPeriodsPerPartTimeEmployees = chocoModelInitialSchedules.intVarArray
(this.maxPartTimeEmployee, 0, this.myScheduleParameters.workPeriodsPerSchedule, true);
this.workingPeriodsPerFullTimeEmployees = chocoModelInitialSchedules.intVarArray
(this.maxFullTimeEmployee, 0, this.myScheduleParameters.workPeriodsPerSchedule, true);
// Creer la transpose des horaires pour compter les elements des colonnes
this.transposeWorkPeriodsSchedulesOfPartTimeEmployees = chocoModelInitialSchedules.intVarMatrix
(this.myScheduleParameters.workPeriodsPerSchedule, this.maxPartTimeEmployee, 0, 1);
for (int workPeriod = 0; workPeriod < this.myScheduleParameters.workPeriodsPerSchedule; workPeriod++) {
for (int employee = 0 ; employee < this.maxPartTimeEmployee ; employee++) {
this.transposeWorkPeriodsSchedulesOfPartTimeEmployees[workPeriod][employee] =
this.workPeriodsSchedulesOfPartTimeEmployees[employee][workPeriod];
}
}
this.transposeWorkPeriodsSchedulesOfFullTimeEmployees = chocoModelInitialSchedules.intVarMatrix
(this.myScheduleParameters.workPeriodsPerSchedule, this.maxFullTimeEmployee, 0, 1);
for (int workPeriod = 0; workPeriod < this.myScheduleParameters.workPeriodsPerSchedule; workPeriod++) {
for (int employee = 0 ; employee < this.maxFullTimeEmployee ; employee++) {
this.transposeWorkPeriodsSchedulesOfFullTimeEmployees[workPeriod][employee] =
this.workPeriodsSchedulesOfFullTimeEmployees[employee][workPeriod];
}
}
// Variable pour faire le compte du nombre d'employes par periode de travail
this.partTimeEmployeesPerWorkPeriods = chocoModelInitialSchedules.intVarArray
(this.myScheduleParameters.workPeriodsPerSchedule, 0, this.maxPartTimeEmployee, true);
this.fullTimeEmployeesPerWorkPeriods = chocoModelInitialSchedules.intVarArray
(this.myScheduleParameters.workPeriodsPerSchedule, 0, this.maxFullTimeEmployee, true);
this.employeesPerWorkPeriods = chocoModelInitialSchedules.intVarArray
(this.myScheduleParameters.workPeriodsPerSchedule,
0, this.maxPartTimeEmployee + this.maxFullTimeEmployee, true);
}
private void createModelConstraints () {
// Constrainte tableau pour choisir un type d'horaire dans les horaires possibles
for (int employee = 0 ; employee < this.maxFullTimeEmployee ; employee++) {
chocoModelInitialSchedules.table(this.workPeriodsSchedulesOfFullTimeEmployees[employee],
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.count(chocoModelInitialSchedules.intVar(1),
this.workPeriodsSchedulesOfPartTimeEmployees[employee],
this.workingPeriodsPerPartTimeEmployees[employee]).post();
}
for (int employee = 0 ; employee < this.maxFullTimeEmployee ; employee++) {
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++) {
BoolVar isWorkingEmployee = chocoModelInitialSchedules.arithm(
this.workingPeriodsPerPartTimeEmployees[employee], ">", 0).reify();
chocoModelInitialSchedules.ifThen(isWorkingEmployee,
chocoModelInitialSchedules.arithm(
this.workingPeriodsPerPartTimeEmployees[employee], ">=",
this.myScheduleParameters.minWorkingPeriodsOfPartTimeEmployeesPerSchedule));
chocoModelInitialSchedules.arithm(this.workingPeriodsPerPartTimeEmployees[employee], "<=",
this.myScheduleParameters.maxWorkingPeriodsOfPartTimeEmployeesPerSchedule).post();
}
// Constraintes pour compter le nombre d'employes par periode de travail et s'assurer qu'il
// satisfait la demande en employes
for (int workPeriod = 0; workPeriod < this.myScheduleParameters.workPeriodsPerSchedule; workPeriod++) {
chocoModelInitialSchedules.count(chocoModelInitialSchedules.intVar(1),
transposeWorkPeriodsSchedulesOfPartTimeEmployees[workPeriod],
this.partTimeEmployeesPerWorkPeriods[workPeriod]).post();
chocoModelInitialSchedules.count(chocoModelInitialSchedules.intVar(1),
transposeWorkPeriodsSchedulesOfFullTimeEmployees[workPeriod],
this.fullTimeEmployeesPerWorkPeriods[workPeriod]).post();
chocoModelInitialSchedules.arithm(this.partTimeEmployeesPerWorkPeriods[workPeriod], "+",
this.fullTimeEmployeesPerWorkPeriods[workPeriod], "=",
this.myScheduleParameters.requiredWorkforce[workPeriod]).post();
chocoModelInitialSchedules.arithm(this.partTimeEmployeesPerWorkPeriods[workPeriod], "+",
this.fullTimeEmployeesPerWorkPeriods[workPeriod], "=",
this.employeesPerWorkPeriods[workPeriod]).post();
}
}
private void createModelObjectiveFunction () {
// this.scheduleProfit = chocoModelInitialSchedules.intVar("TOTAL_COST", 0, 20 * N * p, true);
// chocoModelInitialSchedules.scalar(perte , coeffs , "=", this.scheduleProfit).post();
}
}

View file

@ -0,0 +1,237 @@
package InitialSchedules;
import org.chocosolver.solver.constraints.extension.Tuples;
public class ParametersInitialSchedules {
int workPeriodsPerDay;
int shiftWorkPerDay;
int daysPerSchedule;
int workPeriodsPerSchedule;
int totalWorkedPeriodsInSchedule;
double hoursPerWorkPeriod;
double fixedCostOfPartTimeEmployeesPerSchedule;
double hourlyRateOfPartTimeEmployees;
double minWorkingHoursOfPartTimeEmployeesPerSchedule;
double maxWorkingHoursOfPartTimeEmployeesPerSchedule;
int minWorkingPeriodsOfPartTimeEmployeesPerSchedule;
int maxWorkingPeriodsOfPartTimeEmployeesPerSchedule;
double fixedCostOfFullTimeEmployeesPerSchedule;
double regularHourlyRateOfFullTimeEmployees;
double overtimeHourlyRateOfFullTimeEmployees;
double workingHoursOfFullTimeEmployeesPerSchedule;
double maxWorkingHoursOfFullTimeEmployeesPerSchedule;
int workingPeriodsOfFullTimeEmployeesPerSchedule;
int maxWorkingPeriodsOfFullTimeEmployeesPerSchedule;
double workingHoursPaidAtRegularHourlyRatePerSchedule;
public int[] requiredWorkforce;
Tuples enumerationWorkPeriodsSchedulesOfFullTimeEmployees;
public ParametersInitialSchedules() {
this.setGeneralParameters ();
this.setPartTimeEmployeesParameters ();
this.setFullTimeEmployeesParameters ();
this.setRequiredWorkforce ();
this.setWorkPeriodsSchedulesOfFullTimeEmployees ();
}
private void setGeneralParameters () {
this.workPeriodsPerDay = 6;
this.shiftWorkPerDay = 3;
this.daysPerSchedule = 14;
this.hoursPerWorkPeriod = 4;
this.workPeriodsPerSchedule = this.workPeriodsPerDay * this.daysPerSchedule;
}
private void setPartTimeEmployeesParameters () {
this.fixedCostOfPartTimeEmployeesPerSchedule = 50;
this.hourlyRateOfPartTimeEmployees = 12; // To simulate lower productivity
this.minWorkingHoursOfPartTimeEmployeesPerSchedule = 32;
this.maxWorkingHoursOfPartTimeEmployeesPerSchedule = 64;
this.minWorkingPeriodsOfPartTimeEmployeesPerSchedule =
(int) (this.minWorkingHoursOfPartTimeEmployeesPerSchedule / this.hoursPerWorkPeriod);
this.maxWorkingPeriodsOfPartTimeEmployeesPerSchedule =
(int) (this.maxWorkingHoursOfPartTimeEmployeesPerSchedule / this.hoursPerWorkPeriod);
}
private void setFullTimeEmployeesParameters () {
this.fixedCostOfFullTimeEmployeesPerSchedule = 50;
this.regularHourlyRateOfFullTimeEmployees = 10;
this.overtimeHourlyRateOfFullTimeEmployees = 15;
this.workingHoursOfFullTimeEmployeesPerSchedule = 80;
this.maxWorkingHoursOfFullTimeEmployeesPerSchedule = 120;
this.workingPeriodsOfFullTimeEmployeesPerSchedule =
(int) (this.workingHoursOfFullTimeEmployeesPerSchedule / this.hoursPerWorkPeriod);
this.maxWorkingPeriodsOfFullTimeEmployeesPerSchedule =
(int) (this.maxWorkingHoursOfFullTimeEmployeesPerSchedule / this.hoursPerWorkPeriod);
this.workingHoursPaidAtRegularHourlyRatePerSchedule = 80;
}
private void setRequiredWorkforce () {
this.requiredWorkforce = new int[this.daysPerSchedule*this.workPeriodsPerDay];
this.totalWorkedPeriodsInSchedule = 0;
for (int day = 0; day < this.daysPerSchedule; day++) {
// A ameliorer
this.requiredWorkforce[day*this.workPeriodsPerDay+0] = 2;
this.requiredWorkforce[day*this.workPeriodsPerDay+1] = 2;
this.requiredWorkforce[day*this.workPeriodsPerDay+2] = 4;
this.requiredWorkforce[day*this.workPeriodsPerDay+3] = 4;
this.requiredWorkforce[day*this.workPeriodsPerDay+4] = 3;
this.requiredWorkforce[day*this.workPeriodsPerDay+5] = 3;
this.totalWorkedPeriodsInSchedule += (2*2 + 2*4 + 2*3);
}
}
private void setWorkPeriodsSchedulesOfFullTimeEmployees () {
int[][] 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},
};
int possibleDailyScheduleOfFullTimeEmployees = dailySchedulesOfFullTimeEmployees.length;
int[][] workPeriodsSchedulesOfFullTimeEmployees =
new int[possibleDailyScheduleOfFullTimeEmployees*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 < possibleDailyScheduleOfFullTimeEmployees; scheduleNumber++) {
for (int day = 0; day < this.daysPerSchedule ; day++) {
for (int shiftNumber = 0; shiftNumber < this.shiftWorkPerDay; shiftNumber++) {
if (dailySchedulesOfFullTimeEmployees[scheduleNumber][day] == 1 && shiftNumber == 0){
workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber*this.shiftWorkPerDay+shiftNumber]
[day*this.workPeriodsPerDay+0] = 1;
workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber*this.shiftWorkPerDay+shiftNumber]
[day*this.workPeriodsPerDay+1] = 1;
workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber*this.shiftWorkPerDay+shiftNumber]
[day*this.workPeriodsPerDay+2] = 0;
workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber*this.shiftWorkPerDay+shiftNumber]
[day*this.workPeriodsPerDay+3] = 0;
workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber*this.shiftWorkPerDay+shiftNumber]
[day*this.workPeriodsPerDay+4] = 0;
workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber*this.shiftWorkPerDay+shiftNumber]
[day*this.workPeriodsPerDay+5] = 0;
} else if (dailySchedulesOfFullTimeEmployees[scheduleNumber][day] == 1 && shiftNumber == 1){
workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber*this.shiftWorkPerDay+shiftNumber]
[day*this.workPeriodsPerDay+0] = 0;
workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber*this.shiftWorkPerDay+shiftNumber]
[day*this.workPeriodsPerDay+1] = 0;
workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber*this.shiftWorkPerDay+shiftNumber]
[day*this.workPeriodsPerDay+2] = 1;
workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber*this.shiftWorkPerDay+shiftNumber]
[day*this.workPeriodsPerDay+3] = 1;
workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber*this.shiftWorkPerDay+shiftNumber]
[day*this.workPeriodsPerDay+4] = 0;
workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber*this.shiftWorkPerDay+shiftNumber]
[day*this.workPeriodsPerDay+5] = 0;
} else if (dailySchedulesOfFullTimeEmployees[scheduleNumber][day] == 1 && shiftNumber == 2){
workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber*this.shiftWorkPerDay+shiftNumber]
[day*this.workPeriodsPerDay+0] = 0;
workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber*this.shiftWorkPerDay+shiftNumber]
[day*this.workPeriodsPerDay+1] = 0;
workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber*this.shiftWorkPerDay+shiftNumber]
[day*this.workPeriodsPerDay+2] = 0;
workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber*this.shiftWorkPerDay+shiftNumber]
[day*this.workPeriodsPerDay+3] = 0;
workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber*this.shiftWorkPerDay+shiftNumber]
[day*this.workPeriodsPerDay+4] = 1;
workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber*this.shiftWorkPerDay+shiftNumber]
[day*this.workPeriodsPerDay+5] = 1;
} else if (dailySchedulesOfFullTimeEmployees[scheduleNumber][day] == 0) {
workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber*this.shiftWorkPerDay+shiftNumber]
[day*this.workPeriodsPerDay+0] = 0;
workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber*this.shiftWorkPerDay+shiftNumber]
[day*this.workPeriodsPerDay+1] = 0;
workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber*this.shiftWorkPerDay+shiftNumber]
[day*this.workPeriodsPerDay+2] = 0;
workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber*this.shiftWorkPerDay+shiftNumber]
[day*this.workPeriodsPerDay+3] = 0;
workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber*this.shiftWorkPerDay+shiftNumber]
[day*this.workPeriodsPerDay+4] = 0;
workPeriodsSchedulesOfFullTimeEmployees[scheduleNumber*this.shiftWorkPerDay+shiftNumber]
[day*this.workPeriodsPerDay+5] = 0;
}
}
}
}
// Creation des tuples à partir du tableau pour creer les 3 types de quart de travail (nuit, jour soir).
this.enumerationWorkPeriodsSchedulesOfFullTimeEmployees =
new Tuples(workPeriodsSchedulesOfFullTimeEmployees, true);
}
// A implementer plus tard si l'on veut travailler avec des fichiers texte
public ParametersInitialSchedules(String fileName) {
// String line = null;
// try {
// FileReader fileReader =
// new FileReader(fileName);
//
// BufferedReader bufferedReader =
// new BufferedReader(fileReader);
//
// if((line = bufferedReader.readLine()) != null) {
// String[] arrayLine= line.split("\\s+");
// PARAMETRES_HORAIRE[0] = Integer.parseInt(arrayLine[0]);
// PARAMETRES_HORAIRE[1] = Integer.parseInt(arrayLine[1]);
// PARAMETRES_HORAIRE[2] = Integer.parseInt(arrayLine[2]);
// PARAMETRES_HORAIRE[3] = Integer.parseInt(arrayLine[3]);
// }
// if((line = bufferedReader.readLine()) != null) {
// String[] arrayLine= line.split("\\s+");
// for (int i = 0 ; i < p ; i++) {
// NBR_EMPLOYES_REQUIS[i] = Integer.parseInt(arrayLine[i]);
// }
// }
// if((line = bufferedReader.readLine()) != null) {
// String[] arrayLine= line.split("\\s+");
// for (int i = 0 ; i < p ; i++) {
// NBR_EMPLOYES_SOUHAITES[i] = Integer.parseInt(arrayLine[i]);
// }
// }
// bufferedReader.close();
// }
// catch(FileNotFoundException ex) {
// System.out.println(
// "Unable to open file '" +
// fileName + "'");
// }
// catch(IOException ex) {
// System.out.println(
// "Error reading file '"
// + fileName + "'");
// }
}
}

View file

@ -0,0 +1,96 @@
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%6 == 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("");
}
}

View file

@ -0,0 +1,43 @@
import org.chocosolver.solver.Solver;
public class MainClass {
public static void main(String[] args) {
// Le main ne devrait contenir que les 5 fonctions correspondantes aux etapes du pipeline
generateInitialSchedule ();
// 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 () {
InitialSchedules.ParametersInitialSchedules myScheduleParameters =
new InitialSchedules.ParametersInitialSchedules ();
InitialSchedules.ModelInitialSchedules myModelInitialSchedules =
new InitialSchedules.ModelInitialSchedules (myScheduleParameters);
Solver solverInitialSchedules = myModelInitialSchedules.chocoModelInitialSchedules.getSolver();
solverInitialSchedules.findSolution();
// Solution bestInitialSchedules = solverInitialSchedules.findOptimalSolution
// (myModelInitialSchedules.scheduleProfit, 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.
InitialSchedules.UtilInitialSchedules.printSolutionResults(myModelInitialSchedules, myScheduleParameters);
solverInitialSchedules.printStatistics();
}
}

BIN
tp/rapport.synctex.gz Normal file

Binary file not shown.