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

travailler avec arraylist et pas double[][]

parent 734a0c98
No related branches found
No related tags found
No related merge requests found
......@@ -219,3 +219,4 @@ replay_pid*
*.Identifier
log.txt
/.idea/
......@@ -5,7 +5,6 @@ import java.util.Scanner;
import java.util.concurrent.TimeUnit;
public class Main {
/**
* Compter le nombre d'inéquations S.C
* @param sc scanner
......@@ -34,9 +33,8 @@ public class Main {
* Fonction main
* @param args arguments en entrées
*/
public static void main(String[] args) {
public static void main(String[] args) throws Exception {
long start = System.nanoTime();
try {
File f = new File("src/input.txt");
Scanner sc = new Scanner(f);
String[] elements;
......@@ -76,6 +74,11 @@ public class Main {
spx.createSimplex(eq);
spx.printSimplex("Tableau");
// Tableau initiale
//Simplex spx = new Simplex(line+1, line + 3, widthMat);
//spx.createMatEcart(eq);
//spx.printSimplex("Tableau");
// true = phase 1 membres de droite pas admissible | false = phase 2 membres de droite admissible
int phase = spx.which_phase();
if (phase != -1) {
......@@ -89,9 +92,6 @@ public class Main {
}
sc.close();
} catch (FileNotFoundException e) {
throw new RuntimeException(e);
}
long stop = System.nanoTime();
long duration = TimeUnit.MILLISECONDS.convert(stop - start, TimeUnit.NANOSECONDS);
System.out.println("Temps d'exécution: " + duration + " ms");
......
......@@ -19,7 +19,7 @@ public class Simplex2 {
this.nbLines = nbLines;
this.x = x;
this.y = y;
this.simplex = new ArrayList<ArrayList<Double>>();
this.simplex = new ArrayList<>();
}
public void printSimplex(String title) {
......@@ -84,10 +84,9 @@ public class Simplex2 {
private int ligneSortante(int y) {
int id = 0;
int i = 0;
double tmp = simplex.get(id).get(this.y-1) / simplex.get(id).get(y);
for (ArrayList<Double> doubles : simplex) {
double tmp_s = doubles.get(this.y-1) / doubles.get(y-1);
for (int i = 1; i < this.x - 1; i++) {
double tmp_s = simplex.get(i).get(this.y -1) / simplex.get(i).get(y);
if(tmp_s < tmp) {
id = i;
tmp = tmp_s;
......@@ -98,20 +97,27 @@ public class Simplex2 {
}
void pivot() {
// TODO Verif pivot id fausse
int firstNeg = getFirstNeg();
if(firstNeg == -1) return;
boolean has_neg = false;
int id = ligneSortante(firstNeg);
double pivot = simplex.get(id).get(firstNeg);
ArrayList<Double> tmp = new ArrayList<>();
for (Double d : simplex.get(id))
d /= pivot;
tmp.add(d / pivot);
simplex.set(id, tmp);
tmp = new ArrayList<>();
int id_tmp = 0;
for (ArrayList<Double> doubles : simplex) {
pivot = doubles.get(firstNeg);
for (Double d : doubles) {
if(doubles.indexOf(d) != id) {
d -= pivot * simplex.get(id).get(doubles.indexOf(d));
}
if(doubles.indexOf(d) != id)
tmp.add(pivot * simplex.get(id).get(doubles.indexOf(d)));
id_tmp ++;
}
simplex.set(id_tmp, tmp);
}
for (Double d : simplex.get(x-1)) {
if(signe(d)) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment