diff --git a/src/Simplex.java b/src/Simplex.java index acc58ec6c783b024ad527de236e096880c789f3c..2d3d7bb34d40c2aeee1185583682056d1e59192a 100644 --- a/src/Simplex.java +++ b/src/Simplex.java @@ -8,7 +8,7 @@ public class Simplex { private final int ligne; // Ligne private final int colonne; // Colonne private int nbPivot; - private static final double EPSILON = 1E-40; + private static final double EPSILON = 1E-7; private final int nbContraintes; public Matrix getMatEcart() { @@ -145,7 +145,6 @@ public class Simplex { // remplir la nouvelle matrice avec les valeurs de la matrice auxiliaire, mais dans la taille de la matrice d'écart res.matrixFill(res.getLine(), res.getCol(), tabAux.getDatas()); if (debugging) res.matrixPrint("Petit tableau"); - nbPivot = 0; // reset du nombre de pivots, on pourrait implémenter un pivot de phase 1 et un pivot de phase 2 // retour a la phase 2 avec le pivot sur la nouvelle matrice pivot(res, true); if (debugging) { @@ -164,10 +163,22 @@ public class Simplex { * @return la colonne du premier négatif rencontré */ int getFirstNeg(Matrix mat) { - for (int j = 0; j < mat.getCol() - 1; j++) { + int id = -1; + double tmpVal = 0; + double val = 0; + /*for (int j = 0; j < mat.getCol() - 1; j++) { if (signe(mat.getData(mat.getLine() - 1, j))) return j; + }*/ + for (int j = 0; j < mat.getCol() - 1; j++) { + tmpVal = mat.getData(mat.getLine() - 1, j); + if (signe(tmpVal)) { + if (val > tmpVal) { + val = tmpVal; + id = j; + } + } } - return -1; + return id; } /** @@ -281,12 +292,6 @@ public class Simplex { int line = m.getLine() - 1; int col = m.getCol() - 1; - System.out.println("-------------------Solution-------------------"); - System.out.println("Status: Optimal"); - System.out.format("Size: %d rows, %d cols\n", m.getLine(), m.getCol()); - System.out.println("Obj value: " + -1 * m.getData(line, col)); - System.out.println("Nombre de pivot(s) réalisé(s) sur le petit tableau post phase 1: " + this.nbPivot); - System.out.println("Time: " + time + " ms"); System.out.println("-------------------Variables------------------"); System.out.println("Variables:"); for (int i = 0; i < line; i++) { @@ -298,8 +303,20 @@ public class Simplex { if (m.getData(line, i) != 0.0) System.out.format("Z_Cstr_%d: = %.4f \n", i, m.getData(line, i)); } + System.out.println("-------------------Solution-------------------"); + System.out.println("Status: Optimal"); + System.out.format("Size: %d rows, %d cols\n", m.getLine(), m.getCol()); + System.out.println("Obj value: " + -1 * m.getData(line, col)); + System.out.println("Nombre de pivot(s) réalisé(s) sur le petit tableau post phase 1: " + this.nbPivot); + System.out.println("Time: " + time + " ms"); } + /** + * Retourne True ou False en fonction du signe, True si négatif + * + * @param x La valeur + * @return True si négatif + */ boolean signe(Double x) { return x < 0; }