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

nouvelle manière de parcourir les négatifs

parent 6695b259
No related branches found
No related tags found
No related merge requests found
......@@ -8,7 +8,7 @@ public class Simplex {
private final int ligne; // Ligne
private final int colonne; // Colonne
private int nbPivot;
private static final double EPSILON = 1E-40;
private static final double EPSILON = 1E-7;
private final int nbContraintes;
public Matrix getMatEcart() {
......@@ -145,7 +145,6 @@ public class Simplex {
// remplir la nouvelle matrice avec les valeurs de la matrice auxiliaire, mais dans la taille de la matrice d'écart
res.matrixFill(res.getLine(), res.getCol(), tabAux.getDatas());
if (debugging) res.matrixPrint("Petit tableau");
nbPivot = 0; // reset du nombre de pivots, on pourrait implémenter un pivot de phase 1 et un pivot de phase 2
// retour a la phase 2 avec le pivot sur la nouvelle matrice
pivot(res, true);
if (debugging) {
......@@ -164,10 +163,22 @@ public class Simplex {
* @return la colonne du premier négatif rencontré
*/
int getFirstNeg(Matrix mat) {
for (int j = 0; j < mat.getCol() - 1; j++) {
int id = -1;
double tmpVal = 0;
double val = 0;
/*for (int j = 0; j < mat.getCol() - 1; j++) {
if (signe(mat.getData(mat.getLine() - 1, j))) return j;
}*/
for (int j = 0; j < mat.getCol() - 1; j++) {
tmpVal = mat.getData(mat.getLine() - 1, j);
if (signe(tmpVal)) {
if (val > tmpVal) {
val = tmpVal;
id = j;
}
}
}
return -1;
return id;
}
/**
......@@ -281,12 +292,6 @@ public class Simplex {
int line = m.getLine() - 1;
int col = m.getCol() - 1;
System.out.println("-------------------Solution-------------------");
System.out.println("Status: Optimal");
System.out.format("Size: %d rows, %d cols\n", m.getLine(), m.getCol());
System.out.println("Obj value: " + -1 * m.getData(line, col));
System.out.println("Nombre de pivot(s) réalisé(s) sur le petit tableau post phase 1: " + this.nbPivot);
System.out.println("Time: " + time + " ms");
System.out.println("-------------------Variables------------------");
System.out.println("Variables:");
for (int i = 0; i < line; i++) {
......@@ -298,8 +303,20 @@ public class Simplex {
if (m.getData(line, i) != 0.0)
System.out.format("Z_Cstr_%d: = %.4f \n", i, m.getData(line, i));
}
System.out.println("-------------------Solution-------------------");
System.out.println("Status: Optimal");
System.out.format("Size: %d rows, %d cols\n", m.getLine(), m.getCol());
System.out.println("Obj value: " + -1 * m.getData(line, col));
System.out.println("Nombre de pivot(s) réalisé(s) sur le petit tableau post phase 1: " + this.nbPivot);
System.out.println("Time: " + time + " ms");
}
/**
* Retourne True ou False en fonction du signe, True si négatif
*
* @param x La valeur
* @return True si négatif
*/
boolean signe(Double x) {
return x < 0;
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment