diff --git a/src/Main.java b/src/Main.java index 0eb5357c8eb317de4765dfc54424a29090269b09..cf90ffcc9dca6a2796bb88586d1d5e703657c136 100644 --- a/src/Main.java +++ b/src/Main.java @@ -41,7 +41,7 @@ public class Main { public static void main(String[] args) throws FileNotFoundException, RuntimeException { long start = System.nanoTime(); - File f = new File("src/inputNonAdmissible.txt"); + File f = new File("src/input.txt"); Scanner sc = new Scanner(f); String[] elements; int sousCondition = nbSc(sc), line = 0; @@ -84,7 +84,7 @@ public class Main { if (phase != -1) { spx.tabAux(phase); } else { - spx.pivot(); + spx.pivot(spx.getMatEcart()); 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 cb4e4d7f529a597312f388b6a398c3faf89774ca..4b88f387acb40f5c0afce32da6b1f8af63ecd202 100644 --- a/src/Simplex.java +++ b/src/Simplex.java @@ -91,13 +91,7 @@ public class Simplex { 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); + pivot(tabAux); System.out.println("Nombre de pivot: " + getNbPivot()); } else if (valLastCase > 0) { @@ -109,45 +103,46 @@ public class Simplex { } } - int getFirstNeg() { + int getFirstNeg(Matrix mat) { for (int j = 0; j < this.y; j++) { - if (signe(this.matEcart.getData(this.x, j))) return j; + if (signe(mat.getData(this.x, j))) return j; } return -1; } - void pivot() { + void pivot(Matrix mat) { this.nbPivot += 1; - int firstNeg = getFirstNeg(); + int firstNeg = getFirstNeg(mat); if (firstNeg == -1) return; // si pas de négatif boolean has_neg = false; - int id = ligneSortante(firstNeg); - double pivot = this.matEcart.getData(id, firstNeg); + int id = ligneSortante(mat, firstNeg); + double pivot = mat.getData(id, firstNeg); for (int i = 0; i < this.y; i++) { - this.matEcart.setData(id, i, this.matEcart.getData(id, i) / pivot); + mat.setData(id, i, mat.getData(id, i) / pivot); } for (int i = 0; i < this.x + 1; i++) { - pivot = this.matEcart.getData(i, firstNeg); + pivot = mat.getData(i, firstNeg); for (int j = 0; j < this.y; j++) { if (i != id) { - this.matEcart.setData(i, j, this.matEcart.getData(i, j) - pivot * this.matEcart.getData(id, j)); + mat.setData(i, j, mat.getData(i, j) - pivot * mat.getData(id, j)); } } } + mat.matrixPrint("Pivot numéro " + this.nbPivot, 2); for (int j = 0; j < this.y; j++) - if (signe(this.matEcart.getData(this.x, j))) { + if (signe(mat.getData(this.x, j))) { has_neg = true; } if (has_neg) - pivot(); + pivot(mat); } - int ligneSortante(int y) { + int ligneSortante(Matrix mat, int y) { int id = 0; - double tmp = this.matEcart.getData(id, this.y - 1) / this.matEcart.getData(id, y); + double tmp = mat.getData(id, this.y - 1) / mat.getData(id, y); for (int i = 1; i < this.x - 1; i++) { - double tmp_s = this.matEcart.getData(i, this.y - 1) / this.matEcart.getData(i, y); + double tmp_s = mat.getData(i, this.y - 1) / mat.getData(i, y); if (tmp_s < tmp) { id = i; tmp = tmp_s;