solution optimale pour problème #2
This commit is contained in:
parent
2c85c9aeae
commit
1f06504908
1 changed files with 79 additions and 17 deletions
|
@ -7,9 +7,11 @@ import org.chocosolver.solver.variables.BoolVar;
|
|||
import org.chocosolver.solver.Solver;
|
||||
import org.chocosolver.solver.search.limits.FailCounter;
|
||||
import org.chocosolver.solver.constraints.nary.automata.FA.FiniteAutomaton;
|
||||
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];
|
||||
|
@ -69,22 +71,26 @@ public class ProductionHoraire {
|
|||
BoolVar[][] LignesE = model.boolVarMatrix("E",N,N_PERIODE);
|
||||
|
||||
BoolVar[][] ColonnesE = new BoolVar[N_PERIODE][N];
|
||||
for (int i = 0; i < N_PERIODE; i++) {
|
||||
for (int j = 0; j < N; j++) {
|
||||
for (Integer i = 0; i < N_PERIODE; i++) {
|
||||
for (Integer j = 0; j < N; j++) {
|
||||
ColonnesE[i][j] = LignesE[j][i];
|
||||
}
|
||||
}
|
||||
|
||||
// Contrainte du nombre requis d'employés
|
||||
// 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 (int i=0; i < N_PERIODE; i++) {
|
||||
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-1-MIN_PERIODE;
|
||||
|
||||
FiniteAutomaton FA = new FiniteAutomaton("0*1{"+
|
||||
|
@ -104,24 +110,80 @@ public class ProductionHoraire {
|
|||
|
||||
// Contrainte du motif d'horaire et du nombre minimum et maximum d'heures
|
||||
|
||||
for (int i=0; i<N; i++){
|
||||
for (Integer i=0; i<N; i++){
|
||||
model.regular(LignesE[i],FA).post();
|
||||
model.sum(LignesE[i], ">=", IVMIN_H);
|
||||
model.sum(LignesE[i], "<=", IVMAX_H);
|
||||
model.sum(LignesE[i], ">=", IVMIN_H).post();
|
||||
model.sum(LignesE[i], "<=", IVMAX_H).post();
|
||||
}
|
||||
|
||||
// Creation du solveur
|
||||
Solver solver = model.getSolver();
|
||||
// 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();
|
||||
|
||||
// Résolution du modèle
|
||||
solver.findSolution();
|
||||
for (int i = 0; i < N; i++) {
|
||||
for (int j = 0; j < N_PERIODE; j++) {
|
||||
System.out.print(LignesE[i][j].getValue());
|
||||
System.out.print(" ");
|
||||
}
|
||||
System.out.println("");
|
||||
}
|
||||
|
||||
System.out.println("### Résolution ###");
|
||||
|
||||
Solution maSolution = solver.findOptimalSolution(PERTE,Model.MINIMIZE);
|
||||
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue