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

Update Simplex.java

parent 293e49d1
Branches
No related tags found
No related merge requests found
...@@ -69,36 +69,41 @@ public class Simplex { ...@@ -69,36 +69,41 @@ public class Simplex {
void tabAux(int line) { void tabAux(int line) {
double[] tabRes = new double[this.y + this.nbSousCondition + 1]; double[] tabRes = new double[this.y + this.nbSousCondition + 1];
Arrays.fill(tabRes, 1.0); Arrays.fill(tabRes, 1.0);
for (int j = 0; j < this.y; j++) { for (int i = 0; i < this.x; i++) {
if (this.matEcart.getData(line, j) != 0.0) { for (int j = 0; j < this.y; j++) {
double res = this.matEcart.getData(line, j) * -1; double data = this.matEcart.getData(this.x, j);
this.matEcart.setData(line, j, res); if (data < 0) {
System.out.println(data);
}
} }
}
for (int j = 0; j < this.y; j++) {
double tmpSum = 0; double tmpSum = 0;
for (int i = 0; i < this.x; i++) { for (int i = 0; i < this.x; i++) {
tmpSum += -1 * this.matEcart.getData(i, j); tmpSum += -1 * this.matEcart.getData(i, j);
} }
tabRes[j] = tmpSum; tabRes[j] = tmpSum;
} }
System.out.println();
// -2 car => tabRes[(tabRes.length-1) - (this.nbSousCondition - 1)]; // -2 car => tabRes[(tabRes.length-1) - (this.nbSousCondition - 1)];
tabRes[tabRes.length - 1] = tabRes[tabRes.length - this.nbSousCondition - 2]; tabRes[tabRes.length - 1] = tabRes[tabRes.length - this.nbSousCondition - 2];
tabRes[tabRes.length - this.nbSousCondition - 2] = 0; tabRes[tabRes.length - this.nbSousCondition - 2] = 0;
for (int i = 0; i < this.tabAux.getX(); i++) { for (int i = 0; i < this.tabAux.getX(); i++) {
for (int j = 0; j < this.tabAux.getY(); j++) { for (int j = 0; j < this.tabAux.getY(); j++) {
if (i < this.matEcart.getX() && j < this.matEcart.getY()) if (i < this.matEcart.getX() && j < this.matEcart.getY()) {
this.tabAux.setData(i, j, this.matEcart.getData(i, j)); this.tabAux.setData(i, j, this.matEcart.getData(i, j));
} else if (i == this.tabAux.getX() - 1) {
else if (i == this.tabAux.getX() - 1)
this.tabAux.setData(i, j, tabRes[j]); this.tabAux.setData(i, j, tabRes[j]);
} else // membre de droite à la fin du tab
else // membre de droite à la fin du tab {
this.tabAux.setData(i, j, this.matEcart.getData(i, j - this.matEcart.getX())); this.tabAux.setData(i, j, this.matEcart.getData(i, j - this.matEcart.getX()));
}
} }
System.out.println();
} }
this.tabAux.printTabAux("Tableau auxiliaire", this.nbContraintes, this.nbSousCondition, this.tabAux.getY() - this.matEcart.getY() - 1); this.tabAux.printTabAux("Tableau auxiliaire", this.nbContraintes, this.nbSousCondition, this.tabAux.getY() - this.matEcart.getY() - 1);
pivot(this.tabAux); //pivot(this.tabAux);
double solutionOptimale = this.tabAux.getData(this.tabAux.getX() - 1, this.tabAux.getY() - 1); double solutionOptimale = this.tabAux.getData(this.tabAux.getX() - 1, this.tabAux.getY() - 1);
if (solutionOptimale > 0 + EPSILON) { if (solutionOptimale > 0 + EPSILON) {
System.out.println("Il n'y a pas de solutions admissibles pour ce problème."); System.out.println("Il n'y a pas de solutions admissibles pour ce problème.");
...@@ -110,7 +115,7 @@ public class Simplex { ...@@ -110,7 +115,7 @@ public class Simplex {
res.matrixFill(res.getX(), res.getY(), tabAux.getDatas()); res.matrixFill(res.getX(), res.getY(), tabAux.getDatas());
res.matrixPrint("Petit tableau", 2); res.matrixPrint("Petit tableau", 2);
nbPivot = 0; nbPivot = 0;
pivot(res); //pivot(res);
res.matrixPrint("Résultat ", 3); res.matrixPrint("Résultat ", 3);
System.out.println("Nombre de pivot : " + nbPivot); System.out.println("Nombre de pivot : " + nbPivot);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment