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

correction d'un bug , il faut verifier les resultats

parent edbdb978
No related branches found
No related tags found
No related merge requests found
......@@ -41,7 +41,7 @@ public class Main {
public static void main(String[] args) throws FileNotFoundException, RuntimeException {
long start = System.nanoTime();
File f = new File("src/inputNonAdmissible.txt");
File f = new File("src/input.txt");
Scanner sc = new Scanner(f);
String[] elements;
int sousCondition = nbSc(sc), line = 0;
......@@ -84,7 +84,7 @@ public class Main {
if (phase != -1) {
spx.tabAux(phase);
} else {
spx.pivot();
spx.pivot(spx.getMatEcart());
spx.printSimplex(spx.getMatEcart(), "pivot", 3);
System.out.println("Nombre de pivot: " + spx.getNbPivot());
}
......
......@@ -91,13 +91,7 @@ public class Simplex {
double valLastCase = 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) {
Matrix newMatEcart = this.matEcart;
newMatEcart.matrixFill(this.matEcart.getX(), this.matEcart.getY(), this.tabAux.getDatas());
newMatEcart.matrixPrint("Nouvelle matrice ", 2);
this.matEcart = newMatEcart;
//this.matEcart = this.tabAux;
pivot();
printSimplex(getMatEcart(), "pivot", 3);
pivot(tabAux);
System.out.println("Nombre de pivot: " + getNbPivot());
} else if (valLastCase > 0) {
......@@ -109,45 +103,46 @@ public class Simplex {
}
}
int getFirstNeg() {
int getFirstNeg(Matrix mat) {
for (int j = 0; j < this.y; j++) {
if (signe(this.matEcart.getData(this.x, j))) return j;
if (signe(mat.getData(this.x, j))) return j;
}
return -1;
}
void pivot() {
void pivot(Matrix mat) {
this.nbPivot += 1;
int firstNeg = getFirstNeg();
int firstNeg = getFirstNeg(mat);
if (firstNeg == -1) return; // si pas de négatif
boolean has_neg = false;
int id = ligneSortante(firstNeg);
double pivot = this.matEcart.getData(id, firstNeg);
int id = ligneSortante(mat, firstNeg);
double pivot = mat.getData(id, firstNeg);
for (int i = 0; i < this.y; i++) {
this.matEcart.setData(id, i, this.matEcart.getData(id, i) / pivot);
mat.setData(id, i, mat.getData(id, i) / pivot);
}
for (int i = 0; i < this.x + 1; i++) {
pivot = this.matEcart.getData(i, firstNeg);
pivot = mat.getData(i, firstNeg);
for (int j = 0; j < this.y; j++) {
if (i != id) {
this.matEcart.setData(i, j, this.matEcart.getData(i, j) - pivot * this.matEcart.getData(id, j));
mat.setData(i, j, mat.getData(i, j) - pivot * mat.getData(id, j));
}
}
}
mat.matrixPrint("Pivot numéro " + this.nbPivot, 2);
for (int j = 0; j < this.y; j++)
if (signe(this.matEcart.getData(this.x, j))) {
if (signe(mat.getData(this.x, j))) {
has_neg = true;
}
if (has_neg)
pivot();
pivot(mat);
}
int ligneSortante(int y) {
int ligneSortante(Matrix mat, int y) {
int id = 0;
double tmp = this.matEcart.getData(id, this.y - 1) / this.matEcart.getData(id, y);
double tmp = mat.getData(id, this.y - 1) / mat.getData(id, y);
for (int i = 1; i < this.x - 1; i++) {
double tmp_s = this.matEcart.getData(i, this.y - 1) / this.matEcart.getData(i, y);
double tmp_s = mat.getData(i, this.y - 1) / mat.getData(i, y);
if (tmp_s < tmp) {
id = i;
tmp = tmp_s;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment