diff --git a/src/Main.java b/src/Main.java index 87b167a0466784f299fd7caf7ea2ff8fd9f15f38..344975b5e1f37f502e64cd5ddda00f16f7522c5b 100644 --- a/src/Main.java +++ b/src/Main.java @@ -93,20 +93,24 @@ public class Main { // true = phase 1 membres de droite pas admissible | false = phase 2 membres de droite admissible if (spx.which_phase()) { - spx.tabAux(); + Matrix m = spx.tabAux(); + long stop = System.nanoTime(); + long duration = TimeUnit.MILLISECONDS.convert(stop - start, TimeUnit.NANOSECONDS); + spx.resultPrint(m, duration); } else { spx.pivot(spx.getMatEcart(), false); if(debugging) { spx.printSimplex(spx.getMatEcart(), "Résultat"); System.out.println("Nombre de pivot: " + spx.getNbPivot()); } + // Mesure du temps + long stop = System.nanoTime(); + long duration = TimeUnit.MILLISECONDS.convert(stop - start, TimeUnit.NANOSECONDS); + spx.resultPrint(spx.getMatEcart(), duration); } sc.close(); - // Mesure du temps - long stop = System.nanoTime(); - long duration = TimeUnit.MILLISECONDS.convert(stop - start, TimeUnit.NANOSECONDS); - System.out.println("Temps d'exécution: " + duration + " ms"); + } } diff --git a/src/Simplex.java b/src/Simplex.java index e76eb234eaeb551352011f61fcb2ce47a2893587..e102f07bc18299483eeab7e566b9a0618fdd81e7 100644 --- a/src/Simplex.java +++ b/src/Simplex.java @@ -64,7 +64,7 @@ public class Simplex { return false; } - void tabAux() { + Matrix tabAux() { if (debugging) System.out.println(); double[] tabRes = new double[this.colonne + this.nbSousCondition + 1]; Arrays.fill(tabRes, 1.0); @@ -100,12 +100,12 @@ public class Simplex { } } } - if(debugging) this.tabAux.printTabAux("Tableau auxiliaire", this.nbContraintes, this.nbSousCondition, + if (debugging) this.tabAux.printTabAux("Tableau auxiliaire", this.nbContraintes, this.nbSousCondition, this.tabAux.getCol() - this.matEcart.getCol() - 1); pivot(this.tabAux, true); double solutionOptimale = this.tabAux.getData(this.tabAux.getLine() - 1, this.tabAux.getCol() - 1); - if (solutionOptimale > 0 + EPSILON) { + if (solutionOptimale > EPSILON) { System.out.println("Il n'y a pas de solutions admissibles pour ce problème."); } if (Math.abs(solutionOptimale) < EPSILON || solutionOptimale == 0) { @@ -120,7 +120,9 @@ public class Simplex { res.matrixPrint("Matrice Résultat "); System.out.println("Nombre de pivot : " + nbPivot); } + return res; } + return null; } int getFirstNeg(Matrix mat) { @@ -193,6 +195,26 @@ public class Simplex { mat.matrixPrint(s); } + public void resultPrint(Matrix m, long time) { + 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++) { + System.out.format("X[%d]: = %.4f \n", i, m.getData(i, col)); + } + + for (int i = 0; i < col; i++) { + System.out.format("Z_Cstr_%d: = %.4f \n", i, m.getData(line, i)); + } + } + boolean signe(Double x) { return x < 0; }