diff --git a/src/Simplex.java b/src/Simplex.java index c0c38ea47c86bc3a7f97c062ddbfd8152923f293..95625d916576029e691d2630559046921ffc8611 100644 --- a/src/Simplex.java +++ b/src/Simplex.java @@ -8,6 +8,7 @@ public class Simplex { private int y; private int nbPivot; private static double EPSILON = 0E-7; + private int nbContraintes; public Matrix getTabAux() { return tabAux; @@ -21,13 +22,14 @@ public class Simplex { return nbPivot; } - public Simplex(int x, int y, int nbSousCondition) { + public Simplex(int x, int y, int nbSousCondition, int nbContraintes) { this.x = x; this.y = y; this.matEcart = new Matrix(x, y); this.nbSousCondition = nbSousCondition; this.tabAux = new Matrix(x + 2, y + nbSousCondition + 1); this.nbPivot = 0; + this.nbContraintes = nbContraintes; } void createSimplex(Equation eq, int nbContraintes) { @@ -66,6 +68,7 @@ public class Simplex { } void tabAux(int line) { + // TODO : A REVOIR CETTE PARTIE double[] tabRes = new double[this.y + this.nbSousCondition + 1]; Arrays.fill(tabRes, 1.0); for (int j = 0; j < this.y; j++) { @@ -73,11 +76,17 @@ public class Simplex { double res = this.matEcart.getData(line, j) * -1; this.matEcart.setData(line, j, res); } - for (int i = 0; i < this.x; i++) + double tmpSum = 0; + for (int i = 0; i < this.x; i++) { //tabRes[j] -= Math.abs(this.matEcart.getData(i, j)); - tabRes[j] -= this.matEcart.getData(i, j); - tabRes[j] -= 1; + tmpSum += -1 * this.matEcart.getData(i, j); + //tabRes[j] -= this.matEcart.getData(i, j); + } + tabRes[j] = tmpSum; + System.out.print(tmpSum + " "); } + System.out.println(); + // FIN DU TODO // -2 car => tabRes[(tabRes.length-1) - (this.nbSousCondition - 1)]; tabRes[tabRes.length - 1] = tabRes[tabRes.length - this.nbSousCondition - 2]; @@ -94,37 +103,23 @@ public class Simplex { this.tabAux.setData(i, j, this.matEcart.getData(i, j - this.matEcart.getX())); } } - this.tabAux.matrixPrint("Tableau auxiliaire ", 2); + this.tabAux.printTabAux("Tableau auxiliaire", this.nbContraintes, this.nbSousCondition, this.tabAux.getY() - this.matEcart.getY() - 1); pivot(this.tabAux); double solutionOptimale = 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 (solutionOptimale < 0) { - Matrix newMat = this.matEcart; // pour récupérer les bonnes tailles initiales - newMat.matrixFill(newMat.getX(), newMat.getY(), tabAux.getDatas()); - pivot(newMat); - - } else if (solutionOptimale > 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"); - }*/ - - if (solutionOptimale > 0) { - System.out.println("Il n'y a pas de solutions admissibles pour ce problème"); - } else { - Matrix newMat = this.matEcart; // pour récupérer les bonnes tailles initiales - newMat.matrixFill(newMat.getX(), newMat.getY(), tabAux.getDatas()); - //newMat.matrixPrint("Nouvelle matrice ", 3); - this.nbPivot = 0; - pivot(newMat); - newMat.matrixPrint("Résultat", 3); + if (solutionOptimale > 0 + EPSILON) { + System.out.println("Il n'y a pas de solutions admissibles pour ce problème."); + } + if (solutionOptimale == 0) { + // Il y a une solution optimale + // Il faut enlever les variables auxilaires + Matrix res = new Matrix(matEcart.getX(), matEcart.getY()); + res.matrixFill(res.getX(), res.getY(), tabAux.getDatas()); + res.matrixPrint("Petit tableau", 2); + nbPivot = 0; + pivot(res); + res.matrixPrint("Résultat ", 3); + System.out.println("Nombre de pivot : " + nbPivot); } - /*if (solutionOptimale <= EPSILON + 0 || solutionOptimale >= 0 - EPSILON) { - // il faut s'assurer que la base ne contient aucune variable auxiliaire - System.out.println("il faut s'assurer que la base ne contient aucune variable auxiliaire"); - }*/ } int getFirstNeg(Matrix mat) {