1 package eu.simuline.relana.sys;
2
3 import eu.simuline.relana.model.CClassLoader;
4 import eu.simuline.relana.model.CClass;
5 import eu.simuline.relana.model.FlatCInstance;
6 import eu.simuline.relana.model.SInstance;
7 import eu.simuline.relana.model.InstanceLocator;
8
9
10 import eu.simuline.util.sgml.SGMLParser;
11
12 import org.xml.sax.SAXException;
13
14 import org.antlr.v4.runtime.RecognitionException;
15
16 import java.net.URL;
17 import java.net.MalformedURLException;
18
19 import java.io.InputStreamReader;
20 import java.io.BufferedReader;
21 import java.io.IOException;
22
23
24 import java.util.Set;
25 import java.util.Map;
26 import java.util.HashMap;
27 import java.util.List;
28 import java.util.Arrays;
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 public abstract class Relana {
54 public Relana() {
55
56 }
57
58 public static void main(String[] args)
59 throws MalformedURLException, IOException, SAXException,
60 RecognitionException {
61 if (args.length != 1) {
62 throw new IllegalArgumentException
63 ("Expected a single argument: the project file " +
64 "but found " + Arrays.asList(args) + ". ");
65 }
66
67
68
69 URL proj = new URL(args[0]);
70 InputStreamReader projectStr =
71 new InputStreamReader(proj.openStream(), "UTF-8");
72 SGMLParser projectParser = new SGMLParser();
73 projectParser.parseXML(true);
74 Project project = new Project();
75 projectParser.setContentHandler(project);
76 projectParser.setExceptionHandler(project);
77 projectParser.parse(new BufferedReader(projectStr));
78 System.out.println("project: " + project);
79
80
81 CClassLoader loader = new CClassLoader(project.getLibrary());
82 CClass cClass = loader.loadCClass(project.getBaseClass());
83 System.out.println("cClass: " + cClass);
84 Set<CClass.SClassDecl> decls = cClass.getEffectsRec();
85
86 for (CClass.SClassDecl decl : decls) {
87 if (decl.isInput()) {
88 throw new IllegalArgumentException
89 ("Found declaration of input variable " + decl + ". ");
90 }
91 }
92
93
94 FlatCInstance flatCInstance = cClass.getInstance().flatten();
95 System.out.println("cInstance: " + flatCInstance);
96
97
98 Set<InstanceLocator> outServ = project.getOutputEffects();
99 System.out.println("outServ: " + outServ);
100 Map<List<String>, SInstance> observables =
101 new HashMap<List<String>, SInstance>();
102 for (InstanceLocator loc : outServ) {
103 SInstance serv = flatCInstance.getEffect(loc);
104 CClass.SClassDecl decl = cClass.getEffectDecl(loc.getPath());
105 if (!decl.isOutput()) {
106 throw new IllegalArgumentException
107 ("Found non-output variable " + loc + ". ");
108 }
109
110
111 observables.put(loc.getPath(), serv);
112 }
113
114
115
116 System.out.println("observables: " + observables);
117 System.out.println("\nprobabilities: ");
118
119 for (List<String> obs : observables.keySet()) {
120 System.out.println("\nobs : " + obs +
121 " has prob " + flatCInstance.getProb(obs));
122
123 }
124 }
125 }