Ajout de commentaires dans le code de l'exercice 1 et modification de quelques équations dans le no1 du rapport.
This commit is contained in:
parent
40048a805d
commit
d5ce45bfbe
2 changed files with 46 additions and 23 deletions
|
@ -16,12 +16,15 @@ public class Exercice1 {
|
|||
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");
|
||||
|
||||
// Ajout des tuples. 1: rouge, 2:vert, 3:bleu, 4:jaune
|
||||
// É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},
|
||||
|
@ -55,43 +58,54 @@ public class Exercice1 {
|
|||
{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", 4, 4, 1, 4, false);
|
||||
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();
|
||||
|
||||
IntVar[][] faceRectangulaires = new IntVar[4][4];
|
||||
|
||||
for (int noFace = 0; noFace < 4; noFace++) {
|
||||
for (int noCube = 0; noCube < 4; noCube++) {
|
||||
// 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 du solveur
|
||||
// Creation et lancement du solveur.
|
||||
Solver solver = model.getSolver();
|
||||
|
||||
solver.findSolution();
|
||||
|
||||
for (int noFace = 0; noFace < 4; noFace++) {
|
||||
for (int noCube = 0; noCube < 4; noCube++) {
|
||||
|
||||
// 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 ");
|
||||
System.out.print(" R ");
|
||||
}else if (faceRectangulaires[noFace][noCube].getValue() == 2) {
|
||||
System.out.print(" V ");
|
||||
System.out.print(" V ");
|
||||
}else if (faceRectangulaires[noFace][noCube].getValue() == 3) {
|
||||
System.out.print(" B ");
|
||||
System.out.print(" B ");
|
||||
}else {
|
||||
System.out.print(" J ");
|
||||
System.out.print(" J ");
|
||||
}
|
||||
|
||||
System.out.print(" ");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue