diff --git a/src/Main.java b/src/Main.java index bc537ad7955431c78982d73647832f60355739ba..0eb5357c8eb317de4765dfc54424a29090269b09 100644 --- a/src/Main.java +++ b/src/Main.java @@ -83,10 +83,9 @@ public class Main { int phase = spx.which_phase(); if (phase != -1) { spx.tabAux(phase); - spx.printSimplex(spx.getTabAux(), "Tableau Auxiliaire", 3); } else { spx.pivot(); - spx.printSimplex(spx.getMatEcart(),"pivot", 3); + spx.printSimplex(spx.getMatEcart(), "pivot", 3); System.out.println("Nombre de pivot: " + spx.getNbPivot()); } diff --git a/src/Simplex.java b/src/Simplex.java index 1465fe5f96bd8954008f1089f9eff7268eb03cfb..cb4e4d7f529a597312f388b6a398c3faf89774ca 100644 --- a/src/Simplex.java +++ b/src/Simplex.java @@ -11,9 +11,11 @@ public class Simplex { public Matrix getTabAux() { return tabAux; } + public Matrix getMatEcart() { return matEcart; } + public int getNbPivot() { return nbPivot; } @@ -79,14 +81,31 @@ public class Simplex { for (int j = 0; j < this.tabAux.getY(); j++) { if (i < this.matEcart.getX() && j < this.matEcart.getY()) this.tabAux.setData(i, j, this.matEcart.getData(i, j)); - else if(i == this.tabAux.getX() - 1) + else if (i == this.tabAux.getX() - 1) this.tabAux.setData(i, j, tabRes[j]); else - this.tabAux.setData(i, j, this.matEcart.getData(i, j-5)); + this.tabAux.setData(i, j, this.matEcart.getData(i, j - this.matEcart.getX())); } } - if(signe(this.tabAux.getData(this.tabAux.getX(), this.tabAux.getY()))) { + this.tabAux.matrixPrint("Tableau auxiliaire ", 2); + double valLastCase = this.tabAux.getData(this.tabAux.getX() - 1, this.tabAux.getY() - 1); + // si la dernière case est négative, il faut envoyer le tableau "basique" dans la méthode du pivot + if (valLastCase < 0) { + Matrix newMatEcart = this.matEcart; + newMatEcart.matrixFill(this.matEcart.getX(), this.matEcart.getY(), this.tabAux.getDatas()); + newMatEcart.matrixPrint("Nouvelle matrice ", 2); + this.matEcart = newMatEcart; + //this.matEcart = this.tabAux; + pivot(); + printSimplex(getMatEcart(), "pivot", 3); + System.out.println("Nombre de pivot: " + getNbPivot()); + } else if (valLastCase > 0) { + // si elle est positive , il n'y a pas de solutions admissibles + System.out.println("Il n'y a pas de solutions admissibles pour ce problème"); + } else // = 0 + { + System.out.println("Le min/max est 0"); } }