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

correction d'un premier bug

parent 25cd95d8
No related branches found
No related tags found
No related merge requests found
......@@ -7,6 +7,7 @@ public class Simplex {
private int x;
private int y;
private int nbPivot;
private static double EPSILON = 0E-7;
public Matrix getTabAux() {
return tabAux;
......@@ -88,24 +89,40 @@ public class Simplex {
}
}
this.tabAux.matrixPrint("Tableau auxiliaire ", 2);
double valLastCase = this.tabAux.getData(this.tabAux.getX() - 1, this.tabAux.getY() - 1);
pivot(this.tabAux);
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 (valLastCase < 0) {
pivot(tabAux);
System.out.println("Nombre de pivot: " + getNbPivot());
/*if (solutionOptimale < 0) {
Matrix newMat = this.matEcart; // pour récupérer les bonnes tailles initiales
newMat.matrixFill(newMat.getX(), newMat.getY(), tabAux.getDatas());
pivot(newMat);
} else if (valLastCase > 0) {
} else if (solutionOptimale > 0) {
// si elle est positive , il n'y a pas de solutions admissibles
System.out.println("Il n'y a pas de solutions admissibles pour ce problème");
} else // = 0
{
System.out.println("Le min/max est 0");
}*/
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);
}
/*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) {
for (int j = 0; j < this.y; j++) {
if (signe(mat.getData(this.x, j))) return j;
for (int j = 0; j < mat.getY(); j++) {
if (signe(mat.getData(mat.getX() - 1, j))) return j;
}
return -1;
}
......@@ -116,36 +133,46 @@ public class Simplex {
if (firstNeg == -1) return; // si pas de négatif
boolean has_neg = false;
int id = ligneSortante(mat, firstNeg);
double pivot = mat.getData(id, firstNeg);
for (int i = 0; i < this.y; i++) {
mat.setData(id, i, mat.getData(id, i) / pivot);
double val_pivot = mat.getData(id, firstNeg);
for (int i = 0; i < mat.getY(); i++) {
mat.setData(id, i, mat.getData(id, i) / val_pivot);
}
for (int i = 0; i < this.x + 1; i++) {
pivot = mat.getData(i, firstNeg);
for (int j = 0; j < this.y; j++) {
for (int i = 0; i < mat.getX(); i++) {
val_pivot = mat.getData(i, firstNeg);
for (int j = 0; j < mat.getY(); j++) {
if (i != id) {
mat.setData(i, j, mat.getData(i, j) - pivot * mat.getData(id, j));
mat.setData(i, j, mat.getData(i, j) - val_pivot * mat.getData(id, j));
}
}
}
mat.matrixPrint("Pivot numéro " + this.nbPivot, 2);
for (int j = 0; j < this.y; j++)
if (signe(mat.getData(this.x, j))) {
//mat.matrixPrint("Pivot numéro " + this.nbPivot, 2);
for (int j = 0; j < mat.getY(); j++)
if (signe(mat.getData(mat.getX() - 1, j))) {
has_neg = true;
if (has_neg) {
break;
}
}
if (has_neg)
pivot(mat);
}
int ligneSortante(Matrix mat, int y) {
int id = 0;
double tmp = mat.getData(id, this.y - 1) / mat.getData(id, y);
for (int i = 1; i < this.x - 1; i++) {
double tmp_s = mat.getData(i, this.y - 1) / mat.getData(i, y);
if (tmp_s < tmp) {
id = i;
tmp = tmp_s;
while (mat.getData(id, y) < 0) {
id++;
}
double tmp = mat.getData(id, mat.getY() - 1) / mat.getData(id, y);
double tmp_s;
for (int i = 1; i < mat.getX() - 1; i++) {
if (mat.getData(i, y) > 0) {
tmp_s = mat.getData(i, mat.getY() - 1) / mat.getData(i, y);
if (tmp_s < tmp) {
id = i;
tmp = tmp_s;
}
}
}
return id;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment