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 pathSimplesso.java
More file actions
85 lines (74 loc) · 3.13 KB
/
Copy pathSimplesso.java
File metadata and controls
85 lines (74 loc) · 3.13 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;
import static java.lang.System.exit;
import static java.util.stream.Collectors.toList;
class Simplesso {
public static void main(String[] args) {
Matrice matrice;
boolean massimo = false;
if (args.length == 0) {
System.out.println("non è stato specificato alcun argomento, procedo tramite riga di comando\n");
matrice = new Matrice();
} else {
if (args[0].equals("-h")) {
System.out.println("java Simplesso <file> [<riga pivot><colonna pivot>]\ninserire gli argomenti riguardo al pivot solo se si intende partire da una base in particolare\n" +
"inserire come argomento il path del file contenente:\n" +
"coefficienti della funzione obbiettivo\nmatrice 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(0);
}
matrice = fileParsing(args[0]);
if (args.length == 3)
matrice.cambioBase(Integer.parseInt(args[1]),Integer.parseInt(args[2]));
}
matrice.stampaMatrice();
while(!massimo) {
if (matrice.trovaVariabileEntrante() <= 0)
break;
massimo=matrice.trovaVariabileUscente();
System.out.println("entra x" + matrice.getVaribileEntrante() + "\nesce x" + matrice.getVariabileUscente() + "\n");
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);
}
}