From a008e66b5a10523b0c18f9758d49f7def5e7a46b Mon Sep 17 00:00:00 2001 From: "thibault.capt" <thibault.capt@etu.hesge.ch> Date: Mon, 12 Dec 2022 14:43:49 +0100 Subject: [PATCH] debug --- src/Equation.java | 9 +++++++++ src/Main.java | 11 +++++++---- src/Simplex.java | 32 ++++++++++++++++++++++---------- src/input.txt | 3 ++- 4 files changed, 40 insertions(+), 15 deletions(-) diff --git a/src/Equation.java b/src/Equation.java index 71d1907..e00e57e 100644 --- a/src/Equation.java +++ b/src/Equation.java @@ -169,6 +169,15 @@ public class Equation { return line; } + public int getNbLineMat() { + for (int i = 0; i < 7; i++) { + for (int j = 0; j < nbContraintes; j++) { + + } + } + return 0; + } + /** * Print les vecteurs et la matrice */ diff --git a/src/Main.java b/src/Main.java index c2c14d5..7dc3b8f 100644 --- a/src/Main.java +++ b/src/Main.java @@ -1,5 +1,6 @@ import java.io.File; import java.io.FileNotFoundException; +import java.util.Arrays; import java.util.Scanner; import java.util.concurrent.TimeUnit; @@ -71,16 +72,18 @@ public class Main { eq.printEq(line); // Tableau initiale - Simplex spx = new Simplex(4, 6); + Simplex spx = new Simplex(line+1, line + 3); spx.createMatEcart(eq); spx.printSimplex("Tableau"); + //System.out.println(Arrays.deepToString(spx.getMatEcart())); // true = phase 1 membres de droite pas admissible | false = phase 2 membres de droite admissible if (spx.which_phase()) spx.tabAux(); - else - spx.pivot(0); - spx.printSimplex("pivot"); + else { + spx.pivot(); + spx.printSimplex("pivot"); + } sc.close(); } catch (FileNotFoundException e) { throw new RuntimeException(e); diff --git a/src/Simplex.java b/src/Simplex.java index a7db097..2d2b797 100644 --- a/src/Simplex.java +++ b/src/Simplex.java @@ -3,6 +3,10 @@ public class Simplex { private final int x; private final int y; + public Double[][] getMatEcart() { + return matEcart; + } + public void setMatEcartById(Double d, int x, int y) { matEcart[x][y] = d; } @@ -39,7 +43,7 @@ public class Simplex { } // Membre de droite - for (int i = 0; i <= nbContraintes; i++) + for (int i = 0; i <= x-2; i++) setMatEcartById(eq.getRightVec().get(i), i, y-1); // Fonction obj @@ -55,10 +59,10 @@ public class Simplex { * @return true = phase 1 | false = phase 2 */ boolean which_phase(){ - boolean res = true; + boolean res = false; for (int i = 0; i < x; i++) { - if(signe(matEcart[i][y - 1])) - res = false; + if(!signe(matEcart[i][y - 1])) + res = true; } return res; } @@ -66,15 +70,24 @@ public class Simplex { } - void pivot(int y) { + int getFirstNeg() { + for (int j = 0; j < this.y; j++) { + if(!signe(matEcart[x-1][j])) return j; + } + return -1; + } + + void pivot() { + int firstNeg = getFirstNeg(); + if (firstNeg == -1) return; boolean has_neg = false; - int id = ligneSortante(y); - double pivot = this.matEcart[id][y]; + int id = ligneSortante(firstNeg); + double pivot = this.matEcart[id][firstNeg]; for (int i = 0; i < this.y; i++) { this.matEcart[id][i] /= pivot; } for (int i = 0; i < this.x; i++) { - pivot = this.matEcart[i][y]; + pivot = this.matEcart[i][firstNeg]; for (int j = 0; j < this.y; j++) { if (i != id) { this.matEcart[i][j] -= pivot * this.matEcart[id][j]; @@ -84,9 +97,8 @@ public class Simplex { for (int j = 0; j < this.y; j++) if (!signe(this.matEcart[x - 1][j])) { has_neg = true; - y = j; } - if (has_neg) pivot(y); + if (has_neg) pivot(); } diff --git a/src/input.txt b/src/input.txt index 0bb445b..0a54580 100644 --- a/src/input.txt +++ b/src/input.txt @@ -1,4 +1,5 @@ max;8;9; 2;5;<=;12; 50;5;<=;150; -5;50;<=;100; \ No newline at end of file +5;50;<=;100; +1;2;<=;-1; \ No newline at end of file -- GitLab