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

last update

parent b4554495
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ import java.util.List;
public class Equation {
private String sens;
private int nbContraintes;
private final List<Double> funcObj;
private final List<Double> rightVec;
private final Double[][] mat;
......@@ -37,6 +38,19 @@ public class Equation {
}
}
public int getNbContraintes() {
if(this.nbContraintes != -1)
return this.nbContraintes;
else {
System.err.println("Une erreur a été détectée");
return -1;
}
}
public void setNbContraintes(int nbContraintes) {
this.nbContraintes = nbContraintes;
}
public List<Double> getFuncObj() {
return funcObj;
}
......@@ -61,11 +75,17 @@ public class Equation {
this.mat[w][h] = n;
}
public Equation(int width) {
/**
* Constructeur
* @param w hauteur de la matrice
* @param h largeur de la matrice
*/
public Equation(int w, int h) {
this.sens = null;
this.funcObj = new ArrayList<>();
this.rightVec = new ArrayList<>();
mat = new Double[width][5];
this.nbContraintes = h;
mat = new Double[w][h];
}
/**
......@@ -99,7 +119,7 @@ public class Equation {
public int createEq(String[] elements, int line) {
try {
// vecteur de droite
switch (elements[5]) {
switch (elements[getNbContraintes()]) {
case "=": // Si ax=b => ax <= b; ax >= b
double res = Double.parseDouble(elements[elements.length - 1]);
// Vecteur de droite
......@@ -110,7 +130,7 @@ public class Equation {
else setRightVec(-res);
// Matrice
for (int i = 0; i < 5; i++) {
for (int i = 0; i < getNbContraintes(); i++) {
double tmp = Double.parseDouble(elements[i]);
setMat(tmp, line, i);
// Si 0.0, ne pas écrire -0.0
......@@ -125,7 +145,7 @@ public class Equation {
setRightVec(-Double.parseDouble(elements[elements.length - 1]));
// Matrice
for (int i = 0; i < 5; i++)
for (int i = 0; i < getNbContraintes(); i++)
setMat(-Double.parseDouble(elements[i]), line, i);
break;
case "<=":
......@@ -133,7 +153,7 @@ public class Equation {
setRightVec(Double.parseDouble(elements[elements.length - 1]));
// Matrice
for (int i = 0; i < 5; i++)
for (int i = 0; i < getNbContraintes(); i++)
setMat(Double.parseDouble(elements[i]), line, i);
break;
default:
......@@ -149,7 +169,7 @@ public class Equation {
/**
* Print les vecteurs et la matrice
*/
public void printEq(int width) {
public void printEq(int w) {
// Sens
System.out.println("Sens: " + getSens());
......@@ -161,8 +181,8 @@ public class Equation {
System.out.println("Matrice Amxn:");
// Matrice Amxn
for (int i = 0; i < width; i++) {
for (int j = 0; j < 5; j++) {
for (int i = 0; i < w; i++) {
for (int j = 0; j < getNbContraintes(); j++) {
if (getMatAtId(i, j) < 0.0)
System.out.print(getMatAtId(i, j) + " ");
else
......
......@@ -18,6 +18,16 @@ public class Main {
}
return count - 1; // A cause de la premiere ligne
}
/**
* Compter le nombre d'inéquations S.C
* @param sc scanner
* @return le nombre d'inéquations S.C
*/
private static Integer nbContraintes(Scanner sc) {
String firstLine = sc.nextLine();
String[] elements = firstLine.split(";");
return elements.length - 1; // Enlever le sens de la fonction
}
/**
* Fonction main
......@@ -31,8 +41,10 @@ public class Main {
String[] elements;
int widthMat = nbLines(sc);
sc = new Scanner(f); // remettre le scanner à la première ligne
Equation eq = new Equation(widthMat*2); // lignes supp au cas où, il y a des "="
int contraintes = nbContraintes(sc);
sc = new Scanner(f); // remettre le scanner à la première ligne
int line = 0;
Equation eq = new Equation(widthMat*2, contraintes); // lignes supp au cas où, il y a des "="
// Max / Min + function obj
String firstLine = sc.nextLine();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment