Skip to content
Snippets Groups Projects
Commit a008e66b authored by thibault.capt's avatar thibault.capt
Browse files

debug

parent 5f2c9aaa
No related branches found
No related tags found
No related merge requests found
...@@ -169,6 +169,15 @@ public class Equation { ...@@ -169,6 +169,15 @@ public class Equation {
return line; return line;
} }
public int getNbLineMat() {
for (int i = 0; i < 7; i++) {
for (int j = 0; j < nbContraintes; j++) {
}
}
return 0;
}
/** /**
* Print les vecteurs et la matrice * Print les vecteurs et la matrice
*/ */
......
import java.io.File; import java.io.File;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner; import java.util.Scanner;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
...@@ -71,16 +72,18 @@ public class Main { ...@@ -71,16 +72,18 @@ public class Main {
eq.printEq(line); eq.printEq(line);
// Tableau initiale // Tableau initiale
Simplex spx = new Simplex(4, 6); Simplex spx = new Simplex(line+1, line + 3);
spx.createMatEcart(eq); spx.createMatEcart(eq);
spx.printSimplex("Tableau"); spx.printSimplex("Tableau");
//System.out.println(Arrays.deepToString(spx.getMatEcart()));
// true = phase 1 membres de droite pas admissible | false = phase 2 membres de droite admissible // true = phase 1 membres de droite pas admissible | false = phase 2 membres de droite admissible
if (spx.which_phase()) if (spx.which_phase())
spx.tabAux(); spx.tabAux();
else else {
spx.pivot(0); spx.pivot();
spx.printSimplex("pivot"); spx.printSimplex("pivot");
}
sc.close(); sc.close();
} catch (FileNotFoundException e) { } catch (FileNotFoundException e) {
throw new RuntimeException(e); throw new RuntimeException(e);
......
...@@ -3,6 +3,10 @@ public class Simplex { ...@@ -3,6 +3,10 @@ public class Simplex {
private final int x; private final int x;
private final int y; private final int y;
public Double[][] getMatEcart() {
return matEcart;
}
public void setMatEcartById(Double d, int x, int y) { public void setMatEcartById(Double d, int x, int y) {
matEcart[x][y] = d; matEcart[x][y] = d;
} }
...@@ -39,7 +43,7 @@ public class Simplex { ...@@ -39,7 +43,7 @@ public class Simplex {
} }
// Membre de droite // Membre de droite
for (int i = 0; i <= nbContraintes; i++) for (int i = 0; i <= x-2; i++)
setMatEcartById(eq.getRightVec().get(i), i, y-1); setMatEcartById(eq.getRightVec().get(i), i, y-1);
// Fonction obj // Fonction obj
...@@ -55,10 +59,10 @@ public class Simplex { ...@@ -55,10 +59,10 @@ public class Simplex {
* @return true = phase 1 | false = phase 2 * @return true = phase 1 | false = phase 2
*/ */
boolean which_phase(){ boolean which_phase(){
boolean res = true; boolean res = false;
for (int i = 0; i < x; i++) { for (int i = 0; i < x; i++) {
if(signe(matEcart[i][y - 1])) if(!signe(matEcart[i][y - 1]))
res = false; res = true;
} }
return res; return res;
} }
...@@ -66,15 +70,24 @@ public class Simplex { ...@@ -66,15 +70,24 @@ public class Simplex {
} }
void pivot(int y) { int getFirstNeg() {
for (int j = 0; j < this.y; j++) {
if(!signe(matEcart[x-1][j])) return j;
}
return -1;
}
void pivot() {
int firstNeg = getFirstNeg();
if (firstNeg == -1) return;
boolean has_neg = false; boolean has_neg = false;
int id = ligneSortante(y); int id = ligneSortante(firstNeg);
double pivot = this.matEcart[id][y]; double pivot = this.matEcart[id][firstNeg];
for (int i = 0; i < this.y; i++) { for (int i = 0; i < this.y; i++) {
this.matEcart[id][i] /= pivot; this.matEcart[id][i] /= pivot;
} }
for (int i = 0; i < this.x; i++) { for (int i = 0; i < this.x; i++) {
pivot = this.matEcart[i][y]; pivot = this.matEcart[i][firstNeg];
for (int j = 0; j < this.y; j++) { for (int j = 0; j < this.y; j++) {
if (i != id) { if (i != id) {
this.matEcart[i][j] -= pivot * this.matEcart[id][j]; this.matEcart[i][j] -= pivot * this.matEcart[id][j];
...@@ -84,9 +97,8 @@ public class Simplex { ...@@ -84,9 +97,8 @@ public class Simplex {
for (int j = 0; j < this.y; j++) for (int j = 0; j < this.y; j++)
if (!signe(this.matEcart[x - 1][j])) { if (!signe(this.matEcart[x - 1][j])) {
has_neg = true; has_neg = true;
y = j;
} }
if (has_neg) pivot(y); if (has_neg) pivot();
} }
......
...@@ -2,3 +2,4 @@ max;8;9; ...@@ -2,3 +2,4 @@ max;8;9;
2;5;<=;12; 2;5;<=;12;
50;5;<=;150; 50;5;<=;150;
5;50;<=;100; 5;50;<=;100;
1;2;<=;-1;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment