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

push petite correction

parent 857b1698
Branches
No related tags found
No related merge requests found
......@@ -7,11 +7,11 @@ import java.util.concurrent.TimeUnit;
public class Main {
/**
* Compter le nombre d'inéquations S.C
* Compter le nombre de variables S.C
* @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;
while (sc.hasNextLine()) {
count++;
......@@ -40,7 +40,7 @@ public class Main {
File f = new File("src/inputNonAdmissible.txt");
Scanner sc = new Scanner(f);
String[] elements;
int widthMat = nbLines(sc);
int widthMat = nbVariables(sc);
sc = new Scanner(f); // remettre le scanner à la première ligne
int contraintes = nbContraintes(sc);
sc = new Scanner(f); // remettre le scanner à la première ligne
......@@ -71,9 +71,9 @@ public class Main {
// Print
eq.printEq(line);
// Tableau initiale
// Tableau initial
Simplex spx = new Simplex(widthMat, line+1, line + 3);
spx.createSimplex(eq);
spx.createSimplex(eq,contraintes);
spx.printSimplex("Tableau");
// true = phase 1 membres de droite pas admissible | false = phase 2 membres de droite admissible
......
......@@ -19,8 +19,7 @@ public class Simplex {
this.tabAux = new Matrix(x + nbLines + 1, y + 1);
}
void createSimplex(Equation eq) {
int nbContraintes = eq.getNbContraintes();
void createSimplex(Equation eq, int nbContraintes) {
// Matrice Amxn
for (int i = 0; i < this.x; i++) {
for (int j = 0; j < this.y; j++) {
......@@ -38,39 +37,41 @@ public class Simplex {
// Fonction obj
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.
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
*
* @return true = phase 1 | false = phase 2
*/
int which_phase(){
int which_phase() {
int res = -1;
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;
}
void tabAux(int line) {
Double[] tabRes = new Double[this.y];
Arrays.fill(tabRes, 0.0);
for (int j = 0; j < this.y; j ++) {
if(this.matEcart.getData(line, j) != 0.0) {
for (int j = 0; j < this.y; j++) {
if (this.matEcart.getData(line, j) != 0.0) {
double res = this.matEcart.getData(line, j) * -1;
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);
}
for (int i = 0; i < this.x + nbLines + 1; i ++) {
for (int j = 0; j < this.y + 1; j ++) {
if(i < this.x && j < this.y)
for (int i = 0; i < this.x + nbLines + 1; i++) {
for (int j = 0; j < this.y + 1; j++) {
if (i < this.x && j < this.y)
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));
else if (j == this.y)
this.tabAux.setData(i, j, tabRes[i]);
......@@ -80,7 +81,7 @@ public class Simplex {
int getFirstNeg() {
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;
}
......@@ -115,7 +116,7 @@ public class Simplex {
double tmp = this.matEcart.getData(id, this.y - 1) / this.matEcart.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);
if(tmp_s < tmp) {
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