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 {
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();
......
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];
}
}
}
......
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