Select Git revision
Simplex.java
Simplex.java 2.52 KiB
public class Simplex {
private final Double[][] matEcart;
private int width;
private int height;
public int getWidth() {
return width;
}
public void setWidth(int width) {
this.width = width;
}
public int getHeight() {
return height;
}
public void setHeight(int height) {
this.height = height;
}
public Double getMatEcartById(int i, int j) {
return matEcart[i][j];
}
public Double[][] getMatEcart() {
return matEcart;
}
public void setMatEcartById(Double d, int i, int j) {
matEcart[i][j] = d;
}
public Simplex(int w, int h) {
this.width = w;
this.height = h;
this.matEcart = new Double[w][h];
}
public Simplex() {
this.width = 0;
this.height = 0;
this.matEcart = new Double[0][0];
}
void printSimplex() {
System.out.println("Tableau: ");
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
if (matEcart[i][j] < 0.0)
System.out.print(matEcart[i][j] + " ");
else
System.out.print(" " + matEcart[i][j] + " ");
}
System.out.println();
}
}
void createMatEcart(Equation eq) {
int nbContraintes = eq.getNbContraintes();
// Matrice Amxn
for (int i = 0; i < width; i++) {
for (int j = 0; j < height; j++) {
if (j < nbContraintes) {
setMatEcartById(eq.getMatAtId(i, j), i, j);
} else {
setMatEcartById(j - nbContraintes == i ? 1.0 : 0.0, i, j);
}
}
}
// Membre de droite
for (int i = 0; i <= nbContraintes; i++)
setMatEcartById(eq.getRightVec().get(i), i, height-1);
// Fonction obj
for (int i = 0; i < nbContraintes; i++)
setMatEcartById(eq.getFuncObj().get(i), width-1, i);
// 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;
}
}