Skip to content
Snippets Groups Projects
Commit 52fcbd6b authored by thibault.capt's avatar thibault.capt
Browse files

change code for list

parent ac69e371
No related branches found
No related tags found
No related merge requests found
...@@ -72,7 +72,7 @@ public class Main { ...@@ -72,7 +72,7 @@ public class Main {
eq.printEq(line); eq.printEq(line);
// Tableau initiale // Tableau initiale
Simplex spx = new Simplex(line+1, line + 3); Simplex spx = new Simplex(line+1, line + 3, widthMat);
spx.createMatEcart(eq); spx.createMatEcart(eq);
spx.printSimplex("Tableau"); spx.printSimplex("Tableau");
//System.out.println(Arrays.deepToString(spx.getMatEcart())); //System.out.println(Arrays.deepToString(spx.getMatEcart()));
...@@ -81,7 +81,8 @@ public class Main { ...@@ -81,7 +81,8 @@ public class Main {
int phase = spx.which_phase(); int phase = spx.which_phase();
if (phase != -1) { if (phase != -1) {
spx.tabAux(phase); spx.tabAux(phase);
spx.printSimplex("Tableau aux"); System.out.println("Tableau Auxiliaire:");
System.out.println(Arrays.deepToString(spx.getTabAux()));
} }
else { else {
spx.pivot(); spx.pivot();
......
import java.util.Arrays;
public class Simplex { public class Simplex {
private final Double[][] matEcart; private Double[][] matEcart;
private final int x; private Double[][] tabAux;
private final int y;
private int nbLines;
private int x;
private int y;
public Double[][] getMatEcart() { public Double[][] getMatEcart() {
return matEcart; return matEcart;
...@@ -11,21 +16,32 @@ public class Simplex { ...@@ -11,21 +16,32 @@ public class Simplex {
matEcart[x][y] = d; 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.x = x;
this.y = y; this.y = y;
this.matEcart = new Double[x][y]; this.matEcart = new Double[x][y];
this.nbLines = nbLines;
this.tabAux = new Double[x + nbLines + 1][y + 1];
} }
void printSimplex(String s) { void printSimplex(String s) {
System.out.println(s + ": "); System.out.println(s + ": ");
for (int i = 0; i < x; i++) { for (int i = 0; i < x; i++) {
System.out.print("[");
for (int j = 0; j < y; j++) { for (int j = 0; j < y; j++) {
System.out.printf(matEcart[i][j] < 0.0 ? System.out.printf(matEcart[i][j] < 0.0 ?
String.format("%.2f ", matEcart[i][j]) : String.format("%.2f ", matEcart[i][j]) :
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 { ...@@ -67,12 +83,25 @@ public class Simplex {
return res; return res;
} }
void tabAux(int line) { 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 ++) { for (int j = 0; j < y; j ++) {
if( matEcart[line][j] != 0.0) { if( matEcart[line][j] != 0.0) {
double res = matEcart[line][j] * -1; double res = matEcart[line][j] * -1;
setMatEcartById(res, line, j); 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];
}
} }
} }
......
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<>();
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment