diff --git a/src/Main.java b/src/Main.java index 8ce48d5accf2744f5c6e98e9ef65dc8cc5375b3e..2e2086af14822928cf8c31d692bc21beaa5e08c4 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 2dee6e96943499a17521cb3f38d1f905e4c87dda..8c1e624e0e1b2c66eacd27b79c8e8c3cb60bdfac 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 0000000000000000000000000000000000000000..97906e8a6522f87d9abe75ae78ae1c2273193807 --- /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<>(); + } +}