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:
parent
5fdcc60194
commit
f5309b7f8d
14 changed files with 866 additions and 316 deletions
118
tp/code/TP/Exercice1.java
Normal file
118
tp/code/TP/Exercice1.java
Normal file
|
@ -0,0 +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();
|
||||
}
|
||||
}
|
||||
|
198
tp/code/TP/Exercice2FB.java
Normal file
198
tp/code/TP/Exercice2FB.java
Normal file
|
@ -0,0 +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();
|
||||
|
||||
}
|
||||
}
|
220
tp/code/TP/ProductionHoraire.java
Normal file
220
tp/code/TP/ProductionHoraire.java
Normal file
|
@ -0,0 +1,220 @@
|
|||
import java.nio.file.*;
|
||||
import java.io.IOException;
|
||||
import java.util.*;
|
||||
import org.chocosolver.solver.exception.ContradictionException;
|
||||
import org.chocosolver.solver.Model;
|
||||
import org.chocosolver.solver.variables.IntVar;
|
||||
import org.chocosolver.solver.variables.BoolVar;
|
||||
import org.chocosolver.solver.Solver;
|
||||
import org.chocosolver.solver.search.strategy.Search;
|
||||
import org.chocosolver.solver.search.limits.FailCounter;
|
||||
import org.chocosolver.solver.constraints.nary.automata.FA.FiniteAutomaton;
|
||||
import org.chocosolver.solver.search.strategy.selectors.variables.ImpactBased;
|
||||
import org.chocosolver.solver.Solution;
|
||||
|
||||
public class ProductionHoraire {
|
||||
public static final int N_PERIODE = 16;
|
||||
public static final int VALEUR_PERTE = 20;
|
||||
public static void main(String[] args) {
|
||||
|
||||
String instancePath = args[0];
|
||||
|
||||
// lecture des lignes du fichier d'instance
|
||||
String[] variablesInstance = null;
|
||||
String[] strLigne2 = null;
|
||||
String[] strLigne3 = null;
|
||||
try {
|
||||
List<String> lignesInstance = Files.readAllLines(Paths.get(instancePath));
|
||||
variablesInstance = lignesInstance.get(0).split("\\s+");
|
||||
strLigne2 = lignesInstance.get(1).split("\\s+");
|
||||
strLigne3 = lignesInstance.get(2).split("\\s+");
|
||||
}
|
||||
catch (IOException e){
|
||||
System.err.println("Caught IOException: " + e.getMessage());
|
||||
}
|
||||
catch (Exception e){
|
||||
System.err.println("Caught Exception: " + e.getMessage());
|
||||
}
|
||||
|
||||
// traitement de la 1re ligne
|
||||
Integer N = Integer.valueOf(variablesInstance[0]);
|
||||
Integer MIN_H = Integer.valueOf(variablesInstance[1]);
|
||||
Integer MAX_H = Integer.valueOf(variablesInstance[2]);
|
||||
Integer MIN_PERIODE = Integer.valueOf(variablesInstance[3]);
|
||||
|
||||
// traitement de la 2e ligne
|
||||
List<Integer> nbEmployesRequis = new ArrayList<>();
|
||||
for (String s: strLigne2) {
|
||||
Integer i = Integer.valueOf(s);
|
||||
nbEmployesRequis.add(i);
|
||||
}
|
||||
// traitement de la 3e ligne
|
||||
List<Integer> nbEmployesSouhaite = new ArrayList<>();
|
||||
for (String s: strLigne3) {
|
||||
Integer i = Integer.valueOf(s);
|
||||
nbEmployesSouhaite.add(i);
|
||||
}
|
||||
|
||||
// Vérification du fichier d'instance
|
||||
System.out.println("### Debut Validation Lecture Instance ###");
|
||||
System.out.println("N="+N.toString());
|
||||
System.out.println("MIN_H="+MIN_H.toString());
|
||||
System.out.println("MAX_H="+MAX_H.toString());
|
||||
System.out.println("MIN_PERIODE="+MIN_PERIODE.toString());
|
||||
System.out.println("nbEmployesRequis="+nbEmployesRequis.toString());
|
||||
System.out.println("nbEmployesSouhaite="+nbEmployesSouhaite.toString());
|
||||
System.out.println("### Fin Validation Lecture Instance ###");
|
||||
|
||||
Model model = new Model("Production Horaire");
|
||||
|
||||
// Création d'une matrice E de dimensions N x N_PERIODE de variables e(i,j) dont les domaines sont des variables binaires.
|
||||
// E(i,j)=0 signifie que l'employé i est au repos à la période j.
|
||||
// E(i,j)=1 signifie que l'employé i travaille à la période j.
|
||||
|
||||
BoolVar[][] LignesE = model.boolVarMatrix("E",N,N_PERIODE);
|
||||
|
||||
// Transposition de la matrice E
|
||||
BoolVar[][] ColonnesE = new BoolVar[N_PERIODE][N];
|
||||
for (Integer i = 0; i < N_PERIODE; i++) {
|
||||
for (Integer j = 0; j < N; j++) {
|
||||
ColonnesE[i][j] = LignesE[j][i];
|
||||
}
|
||||
}
|
||||
|
||||
// Vecteur contenant toutes les variables de la matrice dans un seul vecteur
|
||||
BoolVar[] toutesLesVariables = new BoolVar[N * N_PERIODE];
|
||||
for (Integer i = 0; i < N * N_PERIODE; i++) {
|
||||
toutesLesVariables[i] = LignesE[i / N_PERIODE][i % N];
|
||||
}
|
||||
|
||||
// Création de la contrainte du nombre requis d'employés
|
||||
|
||||
System.out.println("### Création: contrainte du nombre requis d'employés ###");
|
||||
|
||||
IntVar[] IVnbEmployesRequis = new IntVar[N_PERIODE];
|
||||
for (Integer i=0; i < N_PERIODE; i++) {
|
||||
IVnbEmployesRequis[i] = model.intVar(nbEmployesRequis.get(i));
|
||||
model.sum(ColonnesE[i], ">=", IVnbEmployesRequis[i]).post();
|
||||
}
|
||||
|
||||
// Création de l'automate fini pour la contrainte du motif d'horaire
|
||||
|
||||
System.out.println("### Création: contrainte du motif d'horaire ###");
|
||||
|
||||
Integer MAX_PERIODE = MAX_H-MIN_PERIODE-1;
|
||||
Integer MAX_PERIODE_REPOS = N_PERIODE-MIN_H-1;
|
||||
|
||||
String strAutomaton = "0{0,"+
|
||||
MAX_PERIODE_REPOS.toString()+
|
||||
"}1{"+
|
||||
MIN_PERIODE.toString()+
|
||||
","+
|
||||
MAX_PERIODE.toString()+
|
||||
"}01{"+
|
||||
MIN_PERIODE.toString()+
|
||||
","+
|
||||
MAX_PERIODE.toString()+
|
||||
"}0{0,"+
|
||||
MAX_PERIODE_REPOS.toString()+
|
||||
"}";
|
||||
|
||||
System.out.println("Expression régulière:"+strAutomaton);
|
||||
FiniteAutomaton FA = new FiniteAutomaton(strAutomaton);
|
||||
|
||||
// Constantes pour la contrainte du nombre minimum et maximum d'heures
|
||||
|
||||
IntVar MIN_H_TRAVAILLE = model.intVar(MIN_H-1);
|
||||
IntVar MAX_H_TRAVAILLE = model.intVar(MAX_H-1);
|
||||
|
||||
// Contrainte du motif d'horaire et du nombre minimum et maximum d'heures
|
||||
|
||||
for (Integer i=0; i<N; i++){
|
||||
model.regular(LignesE[i],FA).post();
|
||||
model.sum(LignesE[i], ">=", MIN_H_TRAVAILLE).post();
|
||||
model.sum(LignesE[i], "<=", MAX_H_TRAVAILLE).post();
|
||||
}
|
||||
|
||||
// Optimisation du nombre souhaité d'employés
|
||||
|
||||
System.out.println("### Création: Optimisation ###");
|
||||
|
||||
IntVar[] IVnbEmployesSouhaite = new IntVar[N_PERIODE];
|
||||
IntVar[] IVnbEmployesEffectif = new IntVar[N_PERIODE];
|
||||
IntVar[] IVnbEmployesDistance = new IntVar[N_PERIODE];
|
||||
|
||||
for (Integer i=0; i < N_PERIODE; i++) {
|
||||
IVnbEmployesEffectif[i] = model.intVar("nbEmployesEffectif",0,N);
|
||||
IVnbEmployesSouhaite[i] = model.intVar("nbEmployesSouhaite"+i.toString(),
|
||||
nbEmployesSouhaite.get(i));
|
||||
IVnbEmployesDistance[i] = model.intVar("nbEmployesDistance",0,N);
|
||||
model.sum(ColonnesE[i],"=",IVnbEmployesEffectif[i]).post();
|
||||
model.distance(IVnbEmployesEffectif[i],
|
||||
IVnbEmployesSouhaite[i],
|
||||
"=",
|
||||
IVnbEmployesDistance[i]).post();
|
||||
}
|
||||
|
||||
IntVar PERTE = model.intVar("perte",0,N*N_PERIODE);
|
||||
model.sum(IVnbEmployesDistance,"=",PERTE).post();
|
||||
|
||||
//model.setObjective(Model.MINIMIZE, PERTE);
|
||||
|
||||
// Creation du solveur
|
||||
|
||||
System.out.println("### Création: Solveur ###");
|
||||
|
||||
Solver solver = model.getSolver();
|
||||
|
||||
try {
|
||||
solver.propagate();
|
||||
}
|
||||
catch (ContradictionException e) {
|
||||
System.err.println("Caught ContradictionException: " + e.getMessage());
|
||||
solver.getEngine().flush();
|
||||
}
|
||||
catch (Exception e){
|
||||
System.err.println("Caught Exception: " + e.getMessage());
|
||||
}
|
||||
|
||||
// Résolution du modèle
|
||||
|
||||
System.out.println("### Résolution ###");
|
||||
|
||||
Solution maSolution = solver.findOptimalSolution(PERTE,Model.MINIMIZE);
|
||||
|
||||
// Affichage des résultats
|
||||
|
||||
System.out.println("### Meilleure Solution ###");
|
||||
|
||||
for (Integer i = 0; i < N; i++) {
|
||||
System.out.print("Employé "+i+": ");
|
||||
for (Integer j = 0; j < N_PERIODE; j++) {
|
||||
System.out.print(maSolution.getIntVal(LignesE[i][j]));
|
||||
System.out.print(" ");
|
||||
}
|
||||
System.out.println("");
|
||||
}
|
||||
|
||||
System.out.println("\nEmployés Totaux");
|
||||
System.out.print(" ");
|
||||
for (Integer j = 0; j < N_PERIODE; j++){
|
||||
System.out.print(maSolution.getIntVal(IVnbEmployesEffectif[j]));
|
||||
System.out.print(" ");
|
||||
}
|
||||
|
||||
System.out.println("\nEmployés Souhaités");
|
||||
System.out.print(" ");
|
||||
for (Integer j = 0; j < N_PERIODE; j++){
|
||||
System.out.print(maSolution.getIntVal(IVnbEmployesSouhaite[j]));
|
||||
System.out.print(" ");
|
||||
}
|
||||
System.out.println("");
|
||||
|
||||
Integer PERTE_OPT = solver.getBestSolutionValue().intValue()*VALEUR_PERTE;
|
||||
System.out.println("\nPerte optimale:"+PERTE_OPT.toString()+"$\n");
|
||||
|
||||
System.out.println("### Statistiques ###");
|
||||
|
||||
solver.printStatistics();
|
||||
}
|
||||
}
|
BIN
tp/code/TP/choco-solver-4.0.6-with-dependencies.jar
Normal file
BIN
tp/code/TP/choco-solver-4.0.6-with-dependencies.jar
Normal file
Binary file not shown.
3
tp/code/TP/instance.txt
Normal file
3
tp/code/TP/instance.txt
Normal file
|
@ -0,0 +1,3 @@
|
|||
5 10 14 3
|
||||
1 1 1 1 1 1 1 1 1 1 1 1 1 1 2 2
|
||||
1 2 3 4 5 4 2 3 4 3 5 5 4 3 3 3
|
12
tp/code/TP/makefile
Normal file
12
tp/code/TP/makefile
Normal file
|
@ -0,0 +1,12 @@
|
|||
all: ProductionHoraire.class Exercice1.class Exercice2FB.class
|
||||
|
||||
%.class: %.java
|
||||
javac -cp .:choco-solver-4.0.6-with-dependencies.jar $<
|
||||
|
||||
run:
|
||||
java -cp .:choco-solver-4.0.6-with-dependencies.jar Exercice1
|
||||
java -cp .:choco-solver-4.0.6-with-dependencies.jar ProductionHoraire instance.txt
|
||||
java -cp .:choco-solver-4.0.6-with-dependencies.jar Exercice2FB instance.txt
|
||||
|
||||
clean:
|
||||
rm *.class
|
0
tp/code/TP/probleme1.java
Normal file
0
tp/code/TP/probleme1.java
Normal file
Loading…
Add table
Add a link
Reference in a new issue