This repository was archived by the owner on Oct 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTest.java
More file actions
70 lines (59 loc) · 2.18 KB
/
Copy pathTest.java
File metadata and controls
70 lines (59 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import java.util.spi.AbstractResourceBundleProvider;
import static java.lang.System.exit;
import static java.util.stream.Collectors.toList;
class Test {
public static void main(String[] args) {
boolean limitato=true;
Matrice matrice = fileParsing("prova.txt");
matrice.stampaMatrice();
while(limitato) {
if (matrice.trovaVariabileEntrante() <= 0)
break;
limitato=matrice.trovaVariabileUscente();
matrice.cambioBase();
matrice.aggiornaFunzioneObbiettivo();
matrice.stampaMatrice();
}
matrice.printVariabiliInBase();
}
static public Matrice fileParsing(String file) {
List<String> lines = null;
int i = 0;
String[] sub;
double[] knownCoeff = new double[3];
double[] targetFunction = new double[0];
double[][] matrice = new double[3][5];
try (BufferedReader in = new BufferedReader(new FileReader(file))) {
lines = in.lines().collect(toList());
} catch (IOException e) {
System.err.println(e.getMessage());
}
if (lines == null) {
System.out.println("non riesco a leggere il file\n");
exit(1);
}
for (String line : lines) {
if (i == 0)
targetFunction = Arrays.stream(line.split(" ")).map(Double::valueOf).mapToDouble(Double::doubleValue).toArray();
else {
sub = line.split(" ");
for (int j = 0; j < 5; j++)
matrice[i - 1][j] = Double.parseDouble(sub[j]);
knownCoeff[i - 1] = Double.parseDouble(sub[5]);
}
i++;
}
if (i != 4) {
System.out.println("file male formattato:\ncoefficienti della funzione obbiettivo\n" +
"matrice dei coefficienti\n\n" +
"Esempio:\n2 1\n1 1 1 0 0 1\n1 3 0 1 0 6\n1 0 0 0 1 4\n");
exit(1);
}
return new Matrice(matrice, knownCoeff, targetFunction);
}
}