From b3b3223cc13d278adcac1f171041fff5f2405dbe Mon Sep 17 00:00:00 2001 From: "thibault.capt" <thibault.capt@etu.hesge.ch> Date: Mon, 28 Nov 2022 14:45:41 +0100 Subject: [PATCH] update --- src/Main.java | 11 ++++++++++- src/Simplex.java | 31 ++++++++++++++++++++++++++++--- src/input.txt | 3 ++- 3 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/Main.java b/src/Main.java index 13853e3..d638b90 100644 --- a/src/Main.java +++ b/src/Main.java @@ -71,10 +71,19 @@ public class Main { // Print eq.printEq(line); - Simplex spx = new Simplex(4, 6); + // Tableau initiale + Simplex spx = new Simplex(5, 6); spx.createMatEcart(eq); + + // true = phase 1 | false = phase 2 + if (spx.which_phase()) + spx.tabAux(); + else + spx.pivot(); + spx.printSimplex(); + sc.close(); } catch (FileNotFoundException e) { throw new RuntimeException(e); diff --git a/src/Simplex.java b/src/Simplex.java index 1d37d1c..2997089 100644 --- a/src/Simplex.java +++ b/src/Simplex.java @@ -59,12 +59,13 @@ public class Simplex { void createMatEcart(Equation eq) { int nbContraintes = eq.getNbContraintes(); // Matrice Amxn - for (int i = 0; i < width; i++){ + for (int i = 0; i < width; i++) { for (int j = 0; j < height; j++) { - if(j < nbContraintes) + if (j < nbContraintes) { setMatEcartById(eq.getMatAtId(i, j), i, j); - else + } else { setMatEcartById(j - nbContraintes == i ? 1.0 : 0.0, i, j); + } } } @@ -79,4 +80,28 @@ public class Simplex { // overwrite la mat en bas à droite qui est à 1 setMatEcartById(0.0, width - 1, height - 1); } + + /** + * Si b[i] < 0 phase 1 sinon phase 2 + * @return true = phase 1 | false = phase 2 + */ + boolean which_phase(){ + boolean res = true; + for (int i = 0; i < width; i++) { + if(!signe(matEcart[i][height - 1])) + res = false; + } + return res; + } + void tabAux() { + + } + + void pivot() { + + } + + boolean signe(Double x) { + return x >= 0; + } } diff --git a/src/input.txt b/src/input.txt index 0bb445b..4c90baa 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;-1000;<=;-1; \ No newline at end of file -- GitLab