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

debug

parent 5f2c9aaa
Branches
No related tags found
No related merge requests found
......@@ -169,6 +169,15 @@ public class Equation {
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
*/
......
import java.io.File;
import java.io.FileNotFoundException;
import java.util.Arrays;
import java.util.Scanner;
import java.util.concurrent.TimeUnit;
......@@ -71,16 +72,18 @@ public class Main {
eq.printEq(line);
// Tableau initiale
Simplex spx = new Simplex(4, 6);
Simplex spx = new Simplex(line+1, line + 3);
spx.createMatEcart(eq);
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
if (spx.which_phase())
spx.tabAux();
else
spx.pivot(0);
else {
spx.pivot();
spx.printSimplex("pivot");
}
sc.close();
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
......
......@@ -3,6 +3,10 @@ public class Simplex {
private final int x;
private final int y;
public Double[][] getMatEcart() {
return matEcart;
}
public void setMatEcartById(Double d, int x, int y) {
matEcart[x][y] = d;
}
......@@ -39,7 +43,7 @@ public class Simplex {
}
// 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);
// Fonction obj
......@@ -55,10 +59,10 @@ public class Simplex {
* @return true = phase 1 | false = phase 2
*/
boolean which_phase(){
boolean res = true;
boolean res = false;
for (int i = 0; i < x; i++) {
if(signe(matEcart[i][y - 1]))
res = false;
if(!signe(matEcart[i][y - 1]))
res = true;
}
return res;
}
......@@ -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;
int id = ligneSortante(y);
double pivot = this.matEcart[id][y];
int id = ligneSortante(firstNeg);
double pivot = this.matEcart[id][firstNeg];
for (int i = 0; i < this.y; i++) {
this.matEcart[id][i] /= pivot;
}
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++) {
if (i != id) {
this.matEcart[i][j] -= pivot * this.matEcart[id][j];
......@@ -84,9 +97,8 @@ public class Simplex {
for (int j = 0; j < this.y; j++)
if (!signe(this.matEcart[x - 1][j])) {
has_neg = true;
y = j;
}
if (has_neg) pivot(y);
if (has_neg) pivot();
}
......
......@@ -2,3 +2,4 @@ max;8;9;
2;5;<=;12;
50;5;<=;150;
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