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

mode debug et autre

parent 30c5b718
Branches
No related tags found
No related merge requests found
...@@ -38,13 +38,21 @@ public class Main { ...@@ -38,13 +38,21 @@ public class Main {
* @param args arguments en entrées * @param args arguments en entrées
*/ */
public static void main(String[] args) throws FileNotFoundException, RuntimeException { public static void main(String[] args) throws FileNotFoundException, RuntimeException {
long start = System.nanoTime();
Scanner readFile = new Scanner(System.in); Scanner readFile = new Scanner(System.in);
System.out.println("Entrez le nom du fichier à tester, il doit se situer dans le dossier src."); System.out.println("Entrez le nom du fichier à tester SANS EXTENSION, il doit se situer dans le dossier src. (Ex: input)");
//String nameFile = readFile.nextLine(); String nameFile = readFile.nextLine();
String nameFile = "network2.txt"; File f = new File("src/" + nameFile + ".txt");
//String nameFile = "input.txt"; System.out.println("Souhaitez vous activer le débogage ? y / n");
File f = new File("src/" + nameFile); String readingDebug = readFile.nextLine();
boolean debugging = false;
switch (readingDebug) {
case "y" -> debugging = true;
case "n" -> debugging = false;
default -> System.err.println("Une erreur a été détectée lors de la saisie du débogage");
}
long start = System.nanoTime();
Scanner sc = new Scanner(f); Scanner sc = new Scanner(f);
String[] elements; String[] elements;
int sousCondition = nbSc(sc), line = 0; int sousCondition = nbSc(sc), line = 0;
...@@ -78,7 +86,8 @@ public class Main { ...@@ -78,7 +86,8 @@ public class Main {
eq.printEq(); eq.printEq();
// Tableau initial // Tableau initial
Simplex spx = new Simplex(eq.getMat().getLine(), eq.getMat().getLine() + eq.getMat().getCol() + 1, line, contraintes); Simplex spx = new Simplex(eq.getMat().getLine(), eq.getMat().getLine() + eq.getMat().getCol() + 1,
line, contraintes, debugging);
spx.createSimplex(eq, contraintes); spx.createSimplex(eq, contraintes);
spx.printSimplex(spx.getMatEcart(), "Tableau initial"); spx.printSimplex(spx.getMatEcart(), "Tableau initial");
...@@ -87,8 +96,10 @@ public class Main { ...@@ -87,8 +96,10 @@ public class Main {
spx.tabAux(); spx.tabAux();
} else { } else {
spx.pivot(spx.getMatEcart(), false); spx.pivot(spx.getMatEcart(), false);
spx.printSimplex(spx.getMatEcart(), "Résultat"); if(debugging) {
System.out.println("Nombre de pivot: " + spx.getNbPivot()); spx.printSimplex(spx.getMatEcart(), "Résultat");
System.out.println("Nombre de pivot: " + spx.getNbPivot());
}
} }
sc.close(); sc.close();
......
import java.util.Arrays; import java.util.Arrays;
public class Simplex { public class Simplex {
private boolean debugging;
private Matrix matEcart; private Matrix matEcart;
private Matrix tabAux; private Matrix tabAux;
private int nbSousCondition; private int nbSousCondition;
...@@ -18,7 +19,7 @@ public class Simplex { ...@@ -18,7 +19,7 @@ public class Simplex {
return nbPivot; return nbPivot;
} }
public Simplex(int ligne, int colonne, int nbSousCondition, int nbContraintes) { public Simplex(int ligne, int colonne, int nbSousCondition, int nbContraintes, boolean debugging) {
this.ligne = ligne; this.ligne = ligne;
this.colonne = colonne; this.colonne = colonne;
this.matEcart = new Matrix(ligne, colonne); this.matEcart = new Matrix(ligne, colonne);
...@@ -26,6 +27,7 @@ public class Simplex { ...@@ -26,6 +27,7 @@ public class Simplex {
this.tabAux = new Matrix(ligne + 2, colonne + nbSousCondition + 1); this.tabAux = new Matrix(ligne + 2, colonne + nbSousCondition + 1);
this.nbPivot = 0; this.nbPivot = 0;
this.nbContraintes = nbContraintes; this.nbContraintes = nbContraintes;
this.debugging = debugging;
} }
void createSimplex(Equation eq, int nbContraintes) { void createSimplex(Equation eq, int nbContraintes) {
...@@ -63,7 +65,7 @@ public class Simplex { ...@@ -63,7 +65,7 @@ public class Simplex {
} }
void tabAux() { void tabAux() {
System.out.println(); if (debugging) System.out.println();
double[] tabRes = new double[this.colonne + this.nbSousCondition + 1]; double[] tabRes = new double[this.colonne + this.nbSousCondition + 1];
Arrays.fill(tabRes, 1.0); Arrays.fill(tabRes, 1.0);
for (int i = 0; i < this.colonne; i++) { for (int i = 0; i < this.colonne; i++) {
...@@ -98,7 +100,9 @@ public class Simplex { ...@@ -98,7 +100,9 @@ public class Simplex {
} }
} }
} }
this.tabAux.printTabAux("Tableau auxiliaire", this.nbContraintes, this.nbSousCondition, this.tabAux.getCol() - this.matEcart.getCol() - 1); if(debugging) this.tabAux.printTabAux("Tableau auxiliaire", this.nbContraintes, this.nbSousCondition,
this.tabAux.getCol() - this.matEcart.getCol() - 1);
pivot(this.tabAux, true); pivot(this.tabAux, true);
double solutionOptimale = this.tabAux.getData(this.tabAux.getLine() - 1, this.tabAux.getCol() - 1); double solutionOptimale = this.tabAux.getData(this.tabAux.getLine() - 1, this.tabAux.getCol() - 1);
if (solutionOptimale > 0 + EPSILON) { if (solutionOptimale > 0 + EPSILON) {
...@@ -109,11 +113,13 @@ public class Simplex { ...@@ -109,11 +113,13 @@ public class Simplex {
// Il faut enlever les variables auxilaires // Il faut enlever les variables auxilaires
Matrix res = new Matrix(matEcart.getLine(), matEcart.getCol()); Matrix res = new Matrix(matEcart.getLine(), matEcart.getCol());
res.matrixFill(res.getLine(), res.getCol(), tabAux.getDatas()); res.matrixFill(res.getLine(), res.getCol(), tabAux.getDatas());
res.matrixPrint("Petit tableau"); if (debugging) res.matrixPrint("Petit tableau");
nbPivot = 0; nbPivot = 0;
pivot(res, true); pivot(res, true);
res.matrixPrint("Résultat "); if (debugging) {
System.out.println("Nombre de pivot : " + nbPivot); res.matrixPrint("Matrice Résultat ");
System.out.println("Nombre de pivot : " + nbPivot);
}
} }
} }
...@@ -125,8 +131,8 @@ public class Simplex { ...@@ -125,8 +131,8 @@ public class Simplex {
} }
/** /**
* @param mat * @param mat Matrix
* @param phase true => phase 1 | false => phase 2 * @param phase true => phase 1 | false => phase 2
*/ */
void pivot(Matrix mat, boolean phase) { void pivot(Matrix mat, boolean phase) {
this.nbPivot += 1; this.nbPivot += 1;
...@@ -148,10 +154,12 @@ public class Simplex { ...@@ -148,10 +154,12 @@ public class Simplex {
} }
} }
} }
mat.matrixPrint("Pivot numéro " + this.nbPivot); if (debugging) {
System.out.println("colonne du pivot: " + firstNeg); mat.matrixPrint("Pivot numéro " + this.nbPivot);
System.out.println("ligne du pivot: " + id); System.out.println("colonne du pivot: " + firstNeg);
System.out.println("Valeur du pivot: " + val_pivot); System.out.println("ligne du pivot: " + id);
System.out.println("Valeur du pivot: " + val_pivot);
}
for (int j = 0; j < mat.getCol(); j++) for (int j = 0; j < mat.getCol(); j++)
if (signe(mat.getData(mat.getLine() - 1, j))) { if (signe(mat.getData(mat.getLine() - 1, j))) {
has_neg = true; has_neg = true;
...@@ -159,11 +167,10 @@ public class Simplex { ...@@ -159,11 +167,10 @@ public class Simplex {
} }
if (has_neg) if (has_neg)
pivot(mat, phase); pivot(mat, phase);
} }
int ligneSortante(Matrix mat, int y, boolean phase) { int ligneSortante(Matrix mat, int y, boolean phase) {
int depth = phase ? mat.getLine() - 2: mat.getLine() - 1; int depth = phase ? mat.getLine() - 2 : mat.getLine() - 1;
int id = 0; int id = 0;
while (!(mat.getData(id, y) > 0) && mat.getData(id, depth) >= 0) { while (!(mat.getData(id, y) > 0) && mat.getData(id, depth) >= 0) {
id++; id++;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment