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

push petite correction

parent 857b1698
Branches
Tags
No related merge requests found
...@@ -7,11 +7,11 @@ import java.util.concurrent.TimeUnit; ...@@ -7,11 +7,11 @@ import java.util.concurrent.TimeUnit;
public class Main { public class Main {
/** /**
* Compter le nombre d'inéquations S.C * Compter le nombre de variables S.C
* @param sc scanner * @param sc scanner
* @return le nombre d'inéquations S.C * @return le nombre de variables S.C
*/ */
private static Integer nbLines(Scanner sc) { private static Integer nbVariables(Scanner sc) {
int count = 0; int count = 0;
while (sc.hasNextLine()) { while (sc.hasNextLine()) {
count++; count++;
...@@ -40,7 +40,7 @@ public class Main { ...@@ -40,7 +40,7 @@ public class Main {
File f = new File("src/inputNonAdmissible.txt"); File f = new File("src/inputNonAdmissible.txt");
Scanner sc = new Scanner(f); Scanner sc = new Scanner(f);
String[] elements; String[] elements;
int widthMat = nbLines(sc); int widthMat = nbVariables(sc);
sc = new Scanner(f); // remettre le scanner à la première ligne sc = new Scanner(f); // remettre le scanner à la première ligne
int contraintes = nbContraintes(sc); int contraintes = nbContraintes(sc);
sc = new Scanner(f); // remettre le scanner à la première ligne sc = new Scanner(f); // remettre le scanner à la première ligne
...@@ -71,9 +71,9 @@ public class Main { ...@@ -71,9 +71,9 @@ public class Main {
// Print // Print
eq.printEq(line); eq.printEq(line);
// Tableau initiale // Tableau initial
Simplex spx = new Simplex(widthMat, line+1, line + 3); Simplex spx = new Simplex(widthMat, line+1, line + 3);
spx.createSimplex(eq); spx.createSimplex(eq,contraintes);
spx.printSimplex("Tableau"); spx.printSimplex("Tableau");
// 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
......
...@@ -19,8 +19,7 @@ public class Simplex { ...@@ -19,8 +19,7 @@ public class Simplex {
this.tabAux = new Matrix(x + nbLines + 1, y + 1); this.tabAux = new Matrix(x + nbLines + 1, y + 1);
} }
void createSimplex(Equation eq) { void createSimplex(Equation eq, int nbContraintes) {
int nbContraintes = eq.getNbContraintes();
// Matrice Amxn // Matrice Amxn
for (int i = 0; i < this.x; i++) { for (int i = 0; i < this.x; i++) {
for (int j = 0; j < this.y; j++) { for (int j = 0; j < this.y; j++) {
...@@ -38,39 +37,41 @@ public class Simplex { ...@@ -38,39 +37,41 @@ public class Simplex {
// Fonction obj // Fonction obj
for (int i = 0; i < nbContraintes; i++) for (int i = 0; i < nbContraintes; i++)
this.matEcart.setData(this.x-1, i, eq.getFuncObj().get(i)); this.matEcart.setData(this.x - 1, i, eq.getFuncObj().get(i));
// overwrite la matrice en bas à droite qui est à 1. // overwrite la matrice en bas à droite qui est à 1.
this.matEcart.setData( this.x - 1, this.y - 1, 0.0); this.matEcart.setData(this.x - 1, this.y - 1, 0.0);
} }
/** /**
* Si b[i] < 0 phase 1 sinon phase 2 * Si b[i] < 0 phase 1 sinon phase 2
*
* @return true = phase 1 | false = phase 2 * @return true = phase 1 | false = phase 2
*/ */
int which_phase(){ int which_phase() {
int res = -1; int res = -1;
for (int i = 0; i < this.x; i++) { for (int i = 0; i < this.x; i++) {
if(signe(this.matEcart.getData(i, this.y - 1))) res = i; if (signe(this.matEcart.getData(i, this.y - 1))) res = i;
} }
return res; return res;
} }
void tabAux(int line) { void tabAux(int line) {
Double[] tabRes = new Double[this.y]; Double[] tabRes = new Double[this.y];
Arrays.fill(tabRes, 0.0); Arrays.fill(tabRes, 0.0);
for (int j = 0; j < this.y; j ++) { for (int j = 0; j < this.y; j++) {
if(this.matEcart.getData(line, j) != 0.0) { if (this.matEcart.getData(line, j) != 0.0) {
double res = this.matEcart.getData(line, j) * -1; double res = this.matEcart.getData(line, j) * -1;
this.matEcart.setData(line, j, res); this.matEcart.setData(line, j, res);
} }
for (int i = 0; i < this.x-1; i ++) for (int i = 0; i < this.x - 1; i++)
tabRes[j] -= this.matEcart.getData(i, j); tabRes[j] -= this.matEcart.getData(i, j);
} }
for (int i = 0; i < this.x + nbLines + 1; i ++) { for (int i = 0; i < this.x + nbLines + 1; i++) {
for (int j = 0; j < this.y + 1; j ++) { for (int j = 0; j < this.y + 1; j++) {
if(i < this.x && j < this.y) if (i < this.x && j < this.y)
this.tabAux.setData(i, j, this.matEcart.getData(i, j)); this.tabAux.setData(i, j, this.matEcart.getData(i, j));
else if(i >= this.x) else if (i >= this.x)
this.tabAux.setData(i, j, this.matEcart.getData(i - 5, j)); this.tabAux.setData(i, j, this.matEcart.getData(i - 5, j));
else if (j == this.y) else if (j == this.y)
this.tabAux.setData(i, j, tabRes[i]); this.tabAux.setData(i, j, tabRes[i]);
...@@ -80,7 +81,7 @@ public class Simplex { ...@@ -80,7 +81,7 @@ public class Simplex {
int getFirstNeg() { int getFirstNeg() {
for (int j = 0; j < this.y; j++) { for (int j = 0; j < this.y; j++) {
if(signe(this.matEcart.getData(this.x - 1, j))) return j; if (signe(this.matEcart.getData(this.x - 1, j))) return j;
} }
return -1; return -1;
} }
...@@ -115,7 +116,7 @@ public class Simplex { ...@@ -115,7 +116,7 @@ public class Simplex {
double tmp = this.matEcart.getData(id, this.y - 1) / this.matEcart.getData(id, y); double tmp = this.matEcart.getData(id, this.y - 1) / this.matEcart.getData(id, y);
for (int i = 1; i < this.x - 1; i++) { 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 = this.matEcart.getData(i, this.y - 1) / this.matEcart.getData(i, y);
if(tmp_s < tmp) { if (tmp_s < tmp) {
id = i; id = i;
tmp = tmp_s; tmp = tmp_s;
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment