blob: 4b676b1935ce5a7f8203a73077ee7d6f02a193a4 (
plain)
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
import java.util.Map;
import java.util.List;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.nio.charset.StandardCharsets;
public class Solutions
{
private static String load_file (final String filename)
throws IOException
{
return
new String
(
Files.readAllBytes(Paths.get(filename)),
StandardCharsets.UTF_8
);
}
public static boolean print (final String sol_file, final String pp_file)
throws IOException
{
final String pp_content;
final QuickSolParser qsp;
List<String[]> solution;
pp_content = load_file(pp_file);
qsp = new QuickSolParser(sol_file);
for (;;)
{
solution = qsp.next_solution();
if (solution == null)
{
return true;
}
if (!handle_solution(solution, pp_content))
{
return false;
}
}
}
private static boolean handle_solution
(
final List<String[]> solution,
String pp_content
)
{
for (final String[] sol_data: solution)
{
final SolutionItem si;
si = SolutionItem.get_item_from_id(sol_data[1]);
if (si == null)
{
System.err.println
(
"[E] There is no element in the model with an ID of \""
+ sol_data[1]
+ "\", yet the solution file refers to it."
);
return false;
}
for (final Map.Entry<String, String> me: si.get_functions_data())
{
final String keyword;
keyword = me.getKey().toUpperCase();
pp_content =
pp_content.replace
(
(
"$"
+ sol_data[0]
+ "."
+ keyword
+ "$"
),
(
keyword.endsWith("ID") ?
me.getValue() :
Strings.get_string_from_id(me.getValue())
)
);
}
}
System.out.println(pp_content);
return true;
}
}
|