From 52fcbd6b889f19476f50582e99b380458e000bcf Mon Sep 17 00:00:00 2001 From: "thibault.capt" <thibault.capt@etu.hesge.ch> Date: Mon, 19 Dec 2022 14:27:47 +0100 Subject: [PATCH] change code for list --- src/Main.java | 5 +++-- src/Simplex.java | 41 +++++++++++++++++++++++++++++++++++------ src/Simplex2.java | 16 ++++++++++++++++ 3 files changed, 54 insertions(+), 8 deletions(-) create mode 100644 src/Simplex2.java diff --git a/src/Main.java b/src/Main.java index 8ce48d5..2e2086a 100644 --- a/src/Main.java +++ b/src/Main.java @@ -72,7 +72,7 @@ public class Main { eq.printEq(line); // Tableau initiale - Simplex spx = new Simplex(line+1, line + 3); + Simplex spx = new Simplex(line+1, line + 3, widthMat); spx.createMatEcart(eq); spx.printSimplex("Tableau"); //System.out.println(Arrays.deepToString(spx.getMatEcart())); @@ -81,7 +81,8 @@ public class Main { int phase = spx.which_phase(); if (phase != -1) { spx.tabAux(phase); - spx.printSimplex("Tableau aux"); + System.out.println("Tableau Auxiliaire:"); + System.out.println(Arrays.deepToString(spx.getTabAux())); } else { spx.pivot(); diff --git a/src/Simplex.java b/src/Simplex.java index 2dee6e9..8c1e624 100644 --- a/src/Simplex.java +++ b/src/Simplex.java @@ -1,7 +1,12 @@ +import java.util.Arrays; + public class Simplex { - private final Double[][] matEcart; - private final int x; - private final int y; + private Double[][] matEcart; + private Double[][] tabAux; + + private int nbLines; + private int x; + private int y; public Double[][] getMatEcart() { return matEcart; @@ -11,21 +16,32 @@ public class Simplex { matEcart[x][y] = d; } - public Simplex(int x, int y) { + public Double[][] getTabAux() { + return tabAux; + } + + public void setTabAux(Double[][] tabAux) { + this.tabAux = tabAux; + } + + public Simplex(int x, int y, int nbLines) { this.x = x; this.y = y; this.matEcart = new Double[x][y]; + this.nbLines = nbLines; + this.tabAux = new Double[x + nbLines + 1][y + 1]; } void printSimplex(String s) { System.out.println(s + ": "); for (int i = 0; i < x; i++) { + System.out.print("["); for (int j = 0; j < y; j++) { System.out.printf(matEcart[i][j] < 0.0 ? String.format("%.2f ", matEcart[i][j]) : String.format(" %.2f ", matEcart[i][j])); } - System.out.println(); + System.out.println("]"); } } @@ -67,12 +83,25 @@ public class Simplex { return res; } void tabAux(int line) { - // TODO mettre en positif membre de droite + Double[] tabRes = new Double[y]; + Arrays.fill(tabRes, 0.0); for (int j = 0; j < y; j ++) { if( matEcart[line][j] != 0.0) { double res = matEcart[line][j] * -1; setMatEcartById(res, line, j); } + for (int i = 0; i < x-1; i ++) + tabRes[j] -= matEcart[i][j]; + } + for (int i = 0; i < x + nbLines + 1; i ++) { + for (int j = 0; j < y + 1; j ++) { + if(i < x && j < y) + tabAux[i][j] = matEcart[i][j]; + else if(i >= x) + tabAux[i][j] = matEcart[i - 5][j]; + else if (j == y) + tabAux[i][j] = tabRes[i]; + } } } diff --git a/src/Simplex2.java b/src/Simplex2.java new file mode 100644 index 0000000..97906e8 --- /dev/null +++ b/src/Simplex2.java @@ -0,0 +1,16 @@ +import java.util.ArrayList; +import java.util.List; + +public class Simplex2 { + private int nbLines; + private int x; + private int y; + private ArrayList<ArrayList<Double>> simplex; + + public Simplex2(int nbLines, int x, int y, ArrayList<ArrayList<Double>> simplex) { + this.nbLines = nbLines; + this.x = x; + this.y = y; + this.simplex = new ArrayList<>(); + } +} -- GitLab