ajout de documentation et optimisation de l'automate fini
This commit is contained in:
parent
1f06504908
commit
789bc73cd4
2 changed files with 127 additions and 13 deletions
|
@ -1,12 +1,15 @@
|
|||
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 {
|
||||
|
@ -64,12 +67,13 @@ public class ProductionHoraire {
|
|||
|
||||
Model model = new Model("Production Horaire");
|
||||
|
||||
// Création d'une matrice de dimensions N x N_PERIODE de variables E(i,j) dont les domaines sont des variables binaires.
|
||||
// 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++) {
|
||||
|
@ -77,6 +81,12 @@ public class ProductionHoraire {
|
|||
}
|
||||
}
|
||||
|
||||
// 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 ###");
|
||||
|
@ -91,18 +101,26 @@ public class ProductionHoraire {
|
|||
|
||||
System.out.println("### Création: contrainte du motif d'horaire ###");
|
||||
|
||||
Integer MAX_PERIODE = MAX_H-1-MIN_PERIODE;
|
||||
|
||||
FiniteAutomaton FA = new FiniteAutomaton("0*1{"+
|
||||
MIN_PERIODE.toString()+
|
||||
","+
|
||||
MAX_PERIODE.toString()+
|
||||
"}01{"+
|
||||
MIN_PERIODE.toString()+
|
||||
","+
|
||||
MAX_PERIODE.toString()+
|
||||
"}0*");
|
||||
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 IVMIN_H = model.intVar(MIN_H-1);
|
||||
|
@ -147,12 +165,29 @@ public class ProductionHoraire {
|
|||
|
||||
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());
|
||||
}
|
||||
|
||||
// Améliore un peu la performance
|
||||
|
||||
solver.setRestartOnSolutions();
|
||||
|
||||
// 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++) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue