blob: d5cc650f8029dbb2168a33fac4b162a73bdf5c87 (
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
105
106
107
108
109
110
111
112
113
114
|
/* FIXME: Finer imports */
import java.util.*;
import java.io.*;
public class Main
{
private static Parameters PARAMETERS;
private static int path_counter = 0;
public static void main (final String... args)
{
final FileWriter output;
final Collection<Path> all_paths;
final Collection<List<Node>> all_subpaths;
PARAMETERS = new Parameters(args);
if (!PARAMETERS.are_valid())
{
return;
}
try
{
ControlFlow.load_file(PARAMETERS.get_model_file());
}
catch (final Exception e)
{
System.err.println
(
"[E] Could not load model file \""
+ PARAMETERS.get_model_file()
+ "\":"
);
e.printStackTrace();
return;
}
all_paths = Path.get_all_paths_from(PARAMETERS.get_root_node());
all_subpaths = new ArrayList<List<Node>>();
for (final Path p: all_paths)
{
all_subpaths.addAll(p.get_all_subpaths());
}
try
{
output = new FileWriter(PARAMETERS.get_output_file());
for (final List<Node> tuple: all_subpaths)
{
node_tuple_to_predicates(tuple, output);
}
output.close();
}
catch (final Exception e)
{
System.err.println
(
"[E] Could not write to output file \""
+ PARAMETERS.get_model_file()
+ "\":"
);
e.printStackTrace();
return;
}
}
private static void node_tuple_to_predicates
(
final List<Node> tuple,
final FileWriter out
)
throws IOException
{
final String id;
final int tuple_size;
tuple_size = tuple.size();
id = (PARAMETERS.get_id_prefix() + path_counter);
path_counter += 1;
out.write("(add_element path " + id + ")\n");
out.write("(is_path_of " + id + " " + tuple.get(0) + ")\n");
for (int i = 0; i < tuple_size; ++i)
{
out.write("(contains_node " + id + " " + tuple.get(i) + ")\n");
for (int j = (i + 1); j < tuple_size; ++j)
{
out.write
(
"(is_before "
+ id
+ " "
+ tuple.get(i)
+ " "
+ tuple.get(j)
+ ")\n"
);
}
}
}
}
|