Skip to content
Snippets Groups Projects
Commit 5c98ea4e authored by juliano.souzaluz's avatar juliano.souzaluz
Browse files

Update Simplex.java

fin de phase terminée, à revoir : couts et autres problèmes
parent 8fdd310f
No related branches found
No related tags found
No related merge requests found
...@@ -8,6 +8,7 @@ public class Simplex { ...@@ -8,6 +8,7 @@ public class Simplex {
private int y; private int y;
private int nbPivot; private int nbPivot;
private static double EPSILON = 0E-7; private static double EPSILON = 0E-7;
private int nbContraintes;
public Matrix getTabAux() { public Matrix getTabAux() {
return tabAux; return tabAux;
...@@ -21,13 +22,14 @@ public class Simplex { ...@@ -21,13 +22,14 @@ public class Simplex {
return nbPivot; return nbPivot;
} }
public Simplex(int x, int y, int nbSousCondition) { public Simplex(int x, int y, int nbSousCondition, int nbContraintes) {
this.x = x; this.x = x;
this.y = y; this.y = y;
this.matEcart = new Matrix(x, y); this.matEcart = new Matrix(x, y);
this.nbSousCondition = nbSousCondition; this.nbSousCondition = nbSousCondition;
this.tabAux = new Matrix(x + 2, y + nbSousCondition + 1); this.tabAux = new Matrix(x + 2, y + nbSousCondition + 1);
this.nbPivot = 0; this.nbPivot = 0;
this.nbContraintes = nbContraintes;
} }
void createSimplex(Equation eq, int nbContraintes) { void createSimplex(Equation eq, int nbContraintes) {
...@@ -66,6 +68,7 @@ public class Simplex { ...@@ -66,6 +68,7 @@ public class Simplex {
} }
void tabAux(int line) { void tabAux(int line) {
// TODO : A REVOIR CETTE PARTIE
double[] tabRes = new double[this.y + this.nbSousCondition + 1]; double[] tabRes = new double[this.y + this.nbSousCondition + 1];
Arrays.fill(tabRes, 1.0); Arrays.fill(tabRes, 1.0);
for (int j = 0; j < this.y; j++) { for (int j = 0; j < this.y; j++) {
...@@ -73,11 +76,17 @@ public class Simplex { ...@@ -73,11 +76,17 @@ public class Simplex {
double res = this.matEcart.getData(line, j) * -1; double res = this.matEcart.getData(line, j) * -1;
this.matEcart.setData(line, j, res); this.matEcart.setData(line, j, res);
} }
for (int i = 0; i < this.x; i++) double tmpSum = 0;
for (int i = 0; i < this.x; i++) {
//tabRes[j] -= Math.abs(this.matEcart.getData(i, j)); //tabRes[j] -= Math.abs(this.matEcart.getData(i, j));
tabRes[j] -= this.matEcart.getData(i, j); tmpSum += -1 * this.matEcart.getData(i, j);
tabRes[j] -= 1; //tabRes[j] -= this.matEcart.getData(i, j);
}
tabRes[j] = tmpSum;
System.out.print(tmpSum + " ");
} }
System.out.println();
// FIN DU TODO
// -2 car => tabRes[(tabRes.length-1) - (this.nbSousCondition - 1)]; // -2 car => tabRes[(tabRes.length-1) - (this.nbSousCondition - 1)];
tabRes[tabRes.length - 1] = tabRes[tabRes.length - this.nbSousCondition - 2]; tabRes[tabRes.length - 1] = tabRes[tabRes.length - this.nbSousCondition - 2];
...@@ -94,37 +103,23 @@ public class Simplex { ...@@ -94,37 +103,23 @@ public class Simplex {
this.tabAux.setData(i, j, this.matEcart.getData(i, j - this.matEcart.getX())); this.tabAux.setData(i, j, this.matEcart.getData(i, j - this.matEcart.getX()));
} }
} }
this.tabAux.matrixPrint("Tableau auxiliaire ", 2); this.tabAux.printTabAux("Tableau auxiliaire", this.nbContraintes, this.nbSousCondition, this.tabAux.getY() - this.matEcart.getY() - 1);
pivot(this.tabAux); pivot(this.tabAux);
double solutionOptimale = this.tabAux.getData(this.tabAux.getX() - 1, this.tabAux.getY() - 1); double solutionOptimale = this.tabAux.getData(this.tabAux.getX() - 1, this.tabAux.getY() - 1);
// si la dernière case est négative, il faut envoyer le tableau "basique" dans la méthode du pivot if (solutionOptimale > 0 + EPSILON) {
/*if (solutionOptimale < 0) { System.out.println("Il n'y a pas de solutions admissibles pour ce problème.");
Matrix newMat = this.matEcart; // pour récupérer les bonnes tailles initiales }
newMat.matrixFill(newMat.getX(), newMat.getY(), tabAux.getDatas()); if (solutionOptimale == 0) {
pivot(newMat); // Il y a une solution optimale
// Il faut enlever les variables auxilaires
} else if (solutionOptimale > 0) { Matrix res = new Matrix(matEcart.getX(), matEcart.getY());
// si elle est positive , il n'y a pas de solutions admissibles res.matrixFill(res.getX(), res.getY(), tabAux.getDatas());
System.out.println("Il n'y a pas de solutions admissibles pour ce problème"); res.matrixPrint("Petit tableau", 2);
} else // = 0 nbPivot = 0;
{ pivot(res);
System.out.println("Le min/max est 0"); res.matrixPrint("Résultat ", 3);
}*/ System.out.println("Nombre de pivot : " + nbPivot);
if (solutionOptimale > 0) {
System.out.println("Il n'y a pas de solutions admissibles pour ce problème");
} else {
Matrix newMat = this.matEcart; // pour récupérer les bonnes tailles initiales
newMat.matrixFill(newMat.getX(), newMat.getY(), tabAux.getDatas());
//newMat.matrixPrint("Nouvelle matrice ", 3);
this.nbPivot = 0;
pivot(newMat);
newMat.matrixPrint("Résultat", 3);
} }
/*if (solutionOptimale <= EPSILON + 0 || solutionOptimale >= 0 - EPSILON) {
// il faut s'assurer que la base ne contient aucune variable auxiliaire
System.out.println("il faut s'assurer que la base ne contient aucune variable auxiliaire");
}*/
} }
int getFirstNeg(Matrix mat) { int getFirstNeg(Matrix mat) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment