diff options
author | ArenBabikian <aren.babikian@mail.mcgill.ca> | 2020-05-09 19:09:06 -0400 |
---|---|---|
committer | ArenBabikian <aren.babikian@mail.mcgill.ca> | 2020-05-09 19:09:06 -0400 |
commit | 79ae20115e73597fbaf18d5429d7b2788dd4efb6 (patch) | |
tree | 4cb6e0d6755673db275f454fa2525f51c13126c7 /Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run | |
parent | uninvolved objects are filled with a default value (diff) | |
download | VIATRA-Generator-79ae20115e73597fbaf18d5429d7b2788dd4efb6.tar.gz VIATRA-Generator-79ae20115e73597fbaf18d5429d7b2788dd4efb6.tar.zst VIATRA-Generator-79ae20115e73597fbaf18d5429d7b2788dd4efb6.zip |
Adjust PLEDEG Java Case Study file
Diffstat (limited to 'Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run')
-rw-r--r-- | Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run/GeneratePledgeModels.xtend | 331 |
1 files changed, 223 insertions, 108 deletions
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run/GeneratePledgeModels.xtend b/Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run/GeneratePledgeModels.xtend index ff0e1d03..3f5855d8 100644 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run/GeneratePledgeModels.xtend +++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run/GeneratePledgeModels.xtend | |||
@@ -1,6 +1,7 @@ | |||
1 | package run | 1 | package run |
2 | 2 | ||
3 | import Taxation.TaxationPackage | 3 | import Taxation.TaxationPackage |
4 | import familytree.FamilytreePackage | ||
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic | 5 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic |
5 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2LogicConfiguration | 6 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2LogicConfiguration |
6 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace | 7 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace |
@@ -11,6 +12,7 @@ import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type | |||
11 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem | 12 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem |
12 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicResult | 13 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicResult |
13 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.ModelResult | 14 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.ModelResult |
15 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.impl.ModelResultImpl | ||
14 | import hu.bme.mit.inf.dslreasoner.logic2ecore.Logic2Ecore | 16 | import hu.bme.mit.inf.dslreasoner.logic2ecore.Logic2Ecore |
15 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2Logic | 17 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2Logic |
16 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2LogicConfiguration | 18 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2LogicConfiguration |
@@ -18,12 +20,12 @@ import hu.bme.mit.inf.dslreasoner.viatra2logic.ViatraQuerySetDescriptor | |||
18 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.InstanceModel2Logic | 20 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.InstanceModel2Logic |
19 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | 21 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation |
20 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation.PartialInterpretation2Gml | 22 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation.PartialInterpretation2Gml |
21 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.DebugConfiguration | ||
22 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner | 23 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner |
23 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration | 24 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration |
24 | import hu.bme.mit.inf.dslreasoner.visualisation.pi2graphviz.GraphvizVisualiser | 25 | import hu.bme.mit.inf.dslreasoner.visualisation.pi2graphviz.GraphvizVisualiser |
25 | import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace | 26 | import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace |
26 | import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace | 27 | import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace |
28 | import java.io.PrintWriter | ||
27 | import java.math.BigDecimal | 29 | import java.math.BigDecimal |
28 | import java.text.SimpleDateFormat | 30 | import java.text.SimpleDateFormat |
29 | import java.util.Date | 31 | import java.util.Date |
@@ -31,6 +33,7 @@ import java.util.HashMap | |||
31 | import java.util.List | 33 | import java.util.List |
32 | import java.util.Map | 34 | import java.util.Map |
33 | import java.util.TreeSet | 35 | import java.util.TreeSet |
36 | import org.eclipse.emf.common.util.EList | ||
34 | import org.eclipse.emf.ecore.EAttribute | 37 | import org.eclipse.emf.ecore.EAttribute |
35 | import org.eclipse.emf.ecore.EClass | 38 | import org.eclipse.emf.ecore.EClass |
36 | import org.eclipse.emf.ecore.EEnum | 39 | import org.eclipse.emf.ecore.EEnum |
@@ -43,118 +46,216 @@ import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl | |||
43 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup | 46 | import org.eclipse.viatra.query.patternlanguage.emf.EMFPatternLanguageStandaloneSetup |
44 | import org.eclipse.viatra.query.runtime.api.IQueryGroup | 47 | import org.eclipse.viatra.query.runtime.api.IQueryGroup |
45 | import org.eclipse.viatra.query.runtime.rete.matcher.ReteEngine | 48 | import org.eclipse.viatra.query.runtime.rete.matcher.ReteEngine |
49 | import queries.Case_study_A | ||
50 | import queries.FamilyTreeConstraints | ||
46 | 51 | ||
47 | class GeneratePledgeModels { | 52 | class GeneratePledgeModels { |
48 | def static void main(String[] args) { | 53 | static val SIZE_LB = 20 |
49 | val x = (new EMFPatternLanguageStandaloneSetup).createInjectorAndDoEMFRegistration | 54 | static val SIZE_UB = 20 |
50 | // //PatternLanguageWithRSSetup.createInjectorAndDoEMFRegistration | 55 | static val SIZE_MUL = 1 |
51 | // ApplicationConfigurationStandaloneSetup.doSetup | 56 | static val SIZE_INC = 5 |
52 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("xmi", new XMIResourceFactoryImpl) | 57 | |
53 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("logicproblem", new XMIResourceFactoryImpl) | 58 | static var REPS = 1 |
54 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("partialmodel", new XMIResourceFactoryImpl) | 59 | static val RUNTIME = 600 |
55 | ReteEngine.getClass | 60 | |
56 | 61 | static val DOMAIN = "FamilyTree" // "FamilyTree", "Taxation" | |
57 | val Ecore2Logic ecore2Logic = new Ecore2Logic | 62 | static val QUERIES = false |
58 | val Logic2Ecore logic2Ecore = new Logic2Ecore(ecore2Logic) | 63 | static val INDIV_WRT = true |
59 | val Viatra2Logic viatra2Logic = new Viatra2Logic(ecore2Logic) | 64 | static val GLOBAL_WRT = true |
60 | val InstanceModel2Logic instanceModel2Logic = new InstanceModel2Logic | 65 | static val q2t = if(QUERIES) "Y" else "N" |
61 | 66 | ||
62 | // Workspace setup | 67 | def static void main(String[] args) { |
63 | val Date date = new Date(System.currentTimeMillis) | 68 | (new EMFPatternLanguageStandaloneSetup).createInjectorAndDoEMFRegistration |
64 | val SimpleDateFormat format = new SimpleDateFormat("dd-HHmm"); | 69 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("xmi", new XMIResourceFactoryImpl) |
65 | val formattedDate = format.format(date) | 70 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("logicproblem", new XMIResourceFactoryImpl) |
66 | 71 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("partialmodel", new XMIResourceFactoryImpl) | |
67 | val inputs = new FileSystemWorkspace('''inputs/''', "") | 72 | ReteEngine.getClass |
68 | val workspace = new FileSystemWorkspace('''output/''' + formattedDate + '''/''', "") | 73 | val Ecore2Logic ecore2Logic = new Ecore2Logic |
69 | val debug = new FileSystemWorkspace('''output/''' + formattedDate + '''/debug/''', "") | 74 | val Logic2Ecore logic2Ecore = new Logic2Ecore(ecore2Logic) |
70 | workspace.initAndClear | 75 | val Viatra2Logic viatra2Logic = new Viatra2Logic(ecore2Logic) |
71 | 76 | val InstanceModel2Logic instanceModel2Logic = new InstanceModel2Logic | |
72 | println("Input and output workspaces are created") | 77 | |
73 | 78 | // Workspace setup | |
74 | // print(TaxationPackage.eINSTANCE.getEClassifiers.filter(EClass).toList.get(0)) | 79 | val Date date = new Date(System.currentTimeMillis) |
75 | //* | 80 | val SimpleDateFormat format = new SimpleDateFormat("dd-HHmm"); |
76 | val metamodel = loadMetamodel(TaxationPackage.eINSTANCE) | 81 | val formattedDate = format.format(date) |
77 | val partialModel = loadPartialModel(inputs, "Household.xmi") | 82 | |
78 | // val queries = loadQueries(metamodel, Case_study_A.instance) | 83 | val inputs = new FileSystemWorkspace('''inputs/''', "") |
79 | /*/ | 84 | val dataws = new FileSystemWorkspace('''output/''', "") |
80 | val metamodel = loadMetamodel(FamilytreePackage.eINSTANCE) | 85 | val modelsws = new FileSystemWorkspace('''output/''' + formattedDate + '''/models/''', "") |
81 | // val partialModel = loadPartialModel(inputs, "yakindu/Yakindu.xmi") | 86 | val workspace = new FileSystemWorkspace('''output/''' + formattedDate + '''/''', "") |
82 | val queries = loadQueries(metamodel, FamilyTreeConstraints.instance) | 87 | val debug = new FileSystemWorkspace('''output/''' + DOMAIN + "-" + formattedDate + '''/debug/''', "") |
83 | // */ | 88 | workspace.initAndClear |
84 | println("DSL loaded") | 89 | modelsws.initAndClear |
85 | 90 | ||
86 | val SIZE = 2 | 91 | println("Input and output workspaces are created") |
87 | var REPS = 1 | 92 | |
88 | val RUNTIME = 600 | 93 | // ////////////////////////// |
89 | 94 | // DOMAIN | |
90 | // ///////////////////////// | 95 | var EcoreMetamodelDescriptor metamodel = null |
91 | // Prepare Problem | 96 | var EList<EObject> partialModel = null |
92 | val modelGenerationProblem = ecore2Logic.transformMetamodel(metamodel, new Ecore2LogicConfiguration()) | 97 | var ViatraQuerySetDescriptor queries = null |
93 | var problem = modelGenerationProblem.output | 98 | switch DOMAIN { |
94 | 99 | case "Taxation": { | |
95 | // val modelExtensionProblem = instanceModel2Logic.transform(modelGenerationProblem, partialModel) | 100 | metamodel = loadMetamodel(TaxationPackage.eINSTANCE) |
96 | // problem = modelExtensionProblem.output | 101 | partialModel = loadPartialModel(inputs, "Household.xmi") |
97 | // val validModelExtensionProblem = viatra2Logic.transformQueries(queries, modelGenerationProblem, | 102 | queries = loadQueries(metamodel, Case_study_A.instance) |
98 | // new Viatra2LogicConfiguration) | 103 | } |
99 | // problem = validModelExtensionProblem.output | 104 | case "FamilyTree": { |
100 | debug.writeModel(problem, "problem.logicproblem") | 105 | metamodel = loadMetamodel(FamilytreePackage.eINSTANCE) |
101 | println("Problem created") | 106 | partialModel = loadPartialModel(inputs, "FamilyTree.xmi") |
102 | // End Prepare Problem | 107 | queries = loadQueries(metamodel, FamilyTreeConstraints.instance) |
103 | // ///////////////////////// | 108 | } |
109 | default: { | ||
110 | System.err.println("Unsupported Domain") | ||
111 | throw new Exception | ||
112 | } | ||
113 | } | ||
114 | println("DSL loaded") | ||
115 | |||
116 | // ///////////////////////// | ||
117 | // Prepare Problem | ||
118 | val modelGenerationProblem = ecore2Logic.transformMetamodel(metamodel, new Ecore2LogicConfiguration()) | ||
119 | var problem = modelGenerationProblem.output | ||
120 | val modelExtensionProblem = instanceModel2Logic.transform(modelGenerationProblem, partialModel) | ||
121 | problem = modelExtensionProblem.output | ||
122 | if (QUERIES) { | ||
123 | val validModelExtensionProblem = viatra2Logic.transformQueries(queries, modelExtensionProblem, | ||
124 | new Viatra2LogicConfiguration) | ||
125 | problem = validModelExtensionProblem.output | ||
126 | } | ||
127 | // debug.writeModel(problem, "problem.logicproblem") | ||
128 | println("Problem created") | ||
129 | // ///////////////////////// | ||
130 | // BEGIN RUN | ||
131 | var PrintWriter global_writer = null | ||
132 | val header = "domain, queries?,size,model?,timeout,measuredTime,TransformatonTime,SolverTime\n" | ||
133 | if (GLOBAL_WRT) { | ||
134 | global_writer = new PrintWriter( | ||
135 | workspace.workspaceURI + "//_" + DOMAIN + SIZE_LB + "to" + SIZE_UB + "x" + REPS + "q" + q2t + "-" + | ||
136 | formattedDate + ".csv") | ||
137 | global_writer.append(header) | ||
138 | } | ||
139 | |||
140 | var NEXT_INC = SIZE_INC | ||
141 | for (var size = SIZE_LB; size <= SIZE_UB; size += NEXT_INC) { | ||
142 | NEXT_INC *= SIZE_MUL | ||
143 | |||
144 | var PrintWriter indiv_writer = null | ||
145 | if (INDIV_WRT) { | ||
146 | indiv_writer = new PrintWriter( // TODO | ||
147 | workspace.workspaceURI + "//__" + DOMAIN + "Sz" + size + "x" + REPS + "q" + q2t + "-" + formattedDate + | ||
148 | ".csv") | ||
149 | indiv_writer.append(header) | ||
150 | } | ||
151 | |||
152 | println() | ||
153 | println("DOMAIN: " + DOMAIN + ", SIZE=" + size) | ||
154 | |||
104 | for (var i = 0; i < REPS; i++) { | 155 | for (var i = 0; i < REPS; i++) { |
105 | 156 | ||
106 | var ViatraReasoner reasoner = new ViatraReasoner | 157 | print("<<Run number " + i + ">> : ") |
158 | |||
159 | var ViatraReasoner reasoner = new ViatraReasoner | ||
107 | 160 | ||
108 | // ///////////////////////////////////////////////////// | 161 | // ///////////////////////////////////////////////////// |
109 | // Define Config File | 162 | // Define Config File |
110 | val knownIntegers = new TreeSet<Integer> | 163 | val knownIntegers = new TreeSet<Integer> |
111 | knownIntegers.addAll(0) | 164 | knownIntegers.addAll(0, 10, 20, 30, 40, 50) |
112 | 165 | ||
113 | val knownReals = new TreeSet<BigDecimal> | 166 | val knownReals = new TreeSet<BigDecimal> |
114 | knownReals.addAll(new BigDecimal("0.0")) | 167 | knownReals.addAll(new BigDecimal("0.0")) |
115 | 168 | ||
116 | val knownStrings = new TreeSet<String> | 169 | val knownStrings = new TreeSet<String> |
117 | knownStrings.addAll("r0", "r1", "r2") | 170 | knownStrings.addAll("r0", "r1", "r2", "r3", "r4", "r5", "r6") |
118 | 171 | ||
119 | val solverConfig = new ViatraReasonerConfiguration => [ | 172 | val curSize = size |
120 | it.documentationLevel = DocumentationLevel::FULL | 173 | val solverConfig = new ViatraReasonerConfiguration => [ |
121 | it.debugCongiguration = new DebugConfiguration => [logging = true] | 174 | it.documentationLevel = DocumentationLevel::NONE |
122 | it.runtimeLimit = RUNTIME | 175 | // it.debugCongiguration = new DebugConfiguration => [logging = true] |
123 | // it.typeScopes.maxNewElements = SIZE | 176 | it.runtimeLimit = RUNTIME |
124 | // it.typeScopes.minNewElements = 3 | 177 | // it.typeScopes.maxNewElements = SIZE |
125 | if(!knownIntegers.isEmpty) it.typeScopes.knownIntegers = knownIntegers | 178 | it.typeScopes.minNewElements = curSize |
126 | if(!knownReals.isEmpty) it.typeScopes.knownReals = knownReals | ||
127 | // if(!knownStrings.isEmpty) it.typeScopes.knownStrings = knownStrings | ||
128 | ] | ||
129 | 179 | ||
130 | println("Run #" + i + ":") | 180 | // if(!knownIntegers.isEmpty) it.typeScopes.knownIntegers = knownIntegers |
131 | val startTime = System.currentTimeMillis | 181 | if(!knownReals.isEmpty) it.typeScopes.knownReals = knownReals |
132 | var solution = reasoner.solve(problem, solverConfig, debug) | 182 | // if(!knownStrings.isEmpty) it.typeScopes.knownStrings = knownStrings |
133 | val totalTime = System.currentTimeMillis - startTime | 183 | ] |
134 | 184 | ||
135 | println(" Problem Solved") | 185 | val startTime = System.currentTimeMillis |
136 | solution.writeStats(totalTime, solverConfig) | 186 | var solution = reasoner.solve(problem, solverConfig, debug) |
187 | val measuredTime = System.currentTimeMillis - startTime | ||
137 | 188 | ||
189 | print("<<END") | ||
190 | |||
191 | val toAddtoCSV = DOMAIN + "," + QUERIES + "," + size + "," + (solution.class == ModelResultImpl).toString + | ||
192 | "," + RUNTIME + "," + measuredTime / 1000.0 + "," + solution.statistics.transformationTime / 1000.0 + | ||
193 | "," + solution.statistics.solverTime / 1000.0 + "\n" | ||
194 | |||
195 | if (GLOBAL_WRT) global_writer.append(toAddtoCSV) | ||
196 | // { | ||
197 | // global_writer.append(DOMAIN + ",") | ||
198 | // global_writer.append(QUERIES + ",") | ||
199 | // global_writer.append(size + ",") | ||
200 | // global_writer.append((solution.class == ModelResultImpl).toString + ",") | ||
201 | // global_writer.append(RUNTIME + ",") | ||
202 | // global_writer.append(measuredTime / 1000.0 + ",") | ||
203 | // | ||
204 | // global_writer.append(solution.statistics.transformationTime / 1000.0 + ",") | ||
205 | // global_writer.append(solution.statistics.solverTime / 1000.0 + "") | ||
206 | // global_writer.append("\n") | ||
207 | // } | ||
208 | if (INDIV_WRT) indiv_writer.append(toAddtoCSV) | ||
209 | // { | ||
210 | // indiv_writer.append(DOMAIN + ",") | ||
211 | // indiv_writer.append(QUERIES + ",") | ||
212 | // indiv_writer.append(size + ",") | ||
213 | // indiv_writer.append((solution.class == ModelResultImpl).toString + ",") | ||
214 | // global_writer.append(RUNTIME + ",") | ||
215 | // indiv_writer.append(measuredTime / 1000.0 + ",") | ||
216 | // | ||
217 | // indiv_writer.append(solution.statistics.transformationTime / 1000.0 + ",") | ||
218 | // indiv_writer.append(solution.statistics.solverTime / 1000.0 + "") | ||
219 | // indiv_writer.append("\n") | ||
220 | // } | ||
221 | |||
222 | println("->" + measuredTime / 1000.0 + "s") | ||
223 | |||
224 | // solution.writeStats(totalTime, solverConfig) | ||
225 | try { | ||
138 | if (solution instanceof ModelResult) { | 226 | if (solution instanceof ModelResult) { |
139 | solution.writeRepresentation(workspace, i) | 227 | solution.writeInterpretation(logic2Ecore, modelsws, size + "_" + i, reasoner, modelGenerationProblem) |
140 | solution.writeInterpretation(logic2Ecore, workspace, i, reasoner, modelGenerationProblem) | 228 | println(" (XMI Success)") |
141 | println(" Solution saved and visualised") | 229 | } |
142 | } else | 230 | } catch (Exception e) { |
143 | println(" Returned: " + solution.class.simpleName.toString) | 231 | System.err.println(" (XMI Error)" + e.message) |
144 | 232 | } | |
145 | // println("Stats Created") | 233 | |
146 | // Run Garbage Collector | 234 | try { |
147 | val Runtime r = Runtime.getRuntime(); | 235 | if (solution instanceof ModelResult) { |
148 | r.gc(); | 236 | solution.writeRepresentation(modelsws, size + "_" + i) |
149 | r.gc(); | 237 | println(" (VIZ Success) >>") |
150 | r.gc(); | 238 | } |
151 | Thread.sleep(3000) | 239 | } catch (Exception e) { |
240 | System.err.println(" (VIZ Error)" + e.message + ">>") | ||
152 | } | 241 | } |
153 | println("---End---") | ||
154 | 242 | ||
243 | println() | ||
244 | // Run Garbage Collector | ||
245 | val Runtime r = Runtime.getRuntime(); | ||
246 | r.gc(); | ||
247 | r.gc(); | ||
248 | r.gc(); | ||
249 | Thread.sleep(3000) | ||
155 | } | 250 | } |
251 | if(INDIV_WRT) indiv_writer.close | ||
252 | } | ||
253 | if(GLOBAL_WRT) global_writer.close | ||
254 | } | ||
255 | |||
256 | def | ||
156 | 257 | ||
157 | def static Map<Type, Integer> getTypeMap(Map<Class, Integer> classMap, EcoreMetamodelDescriptor metamodel, | 258 | static Map<Type, Integer> getTypeMap(Map<Class, Integer> classMap, EcoreMetamodelDescriptor metamodel, |
158 | Ecore2Logic e2l, Ecore2Logic_Trace trace) { | 259 | Ecore2Logic e2l, Ecore2Logic_Trace trace) { |
159 | val typeMap = new HashMap<Type, Integer> | 260 | val typeMap = new HashMap<Type, Integer> |
160 | val listMap = metamodel.classes.toMap[s|s.name] | 261 | val listMap = metamodel.classes.toMap[s|s.name] |
@@ -168,7 +269,9 @@ class GeneratePledgeModels { | |||
168 | return typeMap | 269 | return typeMap |
169 | } | 270 | } |
170 | 271 | ||
171 | def static loadMetamodel(EPackage pckg) { | 272 | def |
273 | |||
274 | static loadMetamodel(EPackage pckg) { | ||
172 | val List<EClass> classes = pckg.getEClassifiers.filter(EClass).toList | 275 | val List<EClass> classes = pckg.getEClassifiers.filter(EClass).toList |
173 | val List<EEnum> enums = pckg.getEClassifiers.filter(EEnum).toList | 276 | val List<EEnum> enums = pckg.getEClassifiers.filter(EEnum).toList |
174 | val List<EEnumLiteral> literals = enums.map[getELiterals].flatten.toList | 277 | val List<EEnumLiteral> literals = enums.map[getELiterals].flatten.toList |
@@ -177,13 +280,17 @@ class GeneratePledgeModels { | |||
177 | return new EcoreMetamodelDescriptor(classes, #{}, false, enums, literals, references, attributes) | 280 | return new EcoreMetamodelDescriptor(classes, #{}, false, enums, literals, references, attributes) |
178 | } | 281 | } |
179 | 282 | ||
180 | def static loadPartialModel(ReasonerWorkspace inputs, String path) { | 283 | def |
284 | |||
285 | static loadPartialModel(ReasonerWorkspace inputs, String path) { | ||
181 | Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl()) | 286 | Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl()) |
182 | inputs.readModel(EObject, path).eResource.contents | 287 | inputs.readModel(EObject, path).eResource.contents |
183 | // inputs.readModel(EObject,"FamInstance.xmi").eResource.allContents.toList | 288 | // inputs.readModel(EObject,"FamInstance.xmi").eResource.allContents.toList |
184 | } | 289 | } |
185 | 290 | ||
186 | def static loadQueries(EcoreMetamodelDescriptor metamodel, IQueryGroup i) { | 291 | def |
292 | |||
293 | static loadQueries(EcoreMetamodelDescriptor metamodel, IQueryGroup i) { | ||
187 | val patterns = i.specifications.toList | 294 | val patterns = i.specifications.toList |
188 | val wfPatterns = patterns.filter[it.allAnnotations.exists[it.name == "Constraint"]].toSet | 295 | val wfPatterns = patterns.filter[it.allAnnotations.exists[it.name == "Constraint"]].toSet |
189 | val derivedFeatures = emptyMap | 296 | val derivedFeatures = emptyMap |
@@ -199,37 +306,45 @@ class GeneratePledgeModels { | |||
199 | return res | 306 | return res |
200 | } | 307 | } |
201 | 308 | ||
202 | def static writeInterpretation(LogicResult solution, Logic2Ecore logic2Ecore, ReasonerWorkspace workspace, int i, | 309 | def |
203 | ViatraReasoner reasoner, TracedOutput<LogicProblem, Ecore2Logic_Trace> mgProb) { | 310 | |
311 | static writeInterpretation(LogicResult solution, Logic2Ecore logic2Ecore, ReasonerWorkspace workspace, | ||
312 | String id, ViatraReasoner reasoner, TracedOutput<LogicProblem, Ecore2Logic_Trace> mgProb) { | ||
204 | val interpretations = reasoner.getInterpretations(solution as ModelResult) | 313 | val interpretations = reasoner.getInterpretations(solution as ModelResult) |
205 | for (interpIndex : 0 ..< interpretations.size) { | 314 | for (interpIndex : 0 ..< interpretations.size) { |
206 | // val extension b = new LogicStructureBuilder | 315 | // val extension b = new LogicStructureBuilder |
207 | // val extension a = new LogicProblemBuilder | 316 | // val extension a = new LogicProblemBuilder |
208 | val interpretation = interpretations.get(interpIndex) | 317 | val interpretation = interpretations.get(interpIndex) |
209 | val model = logic2Ecore.transformInterpretation(interpretation, mgProb.trace) | 318 | val model = logic2Ecore.transformInterpretation(interpretation, mgProb.trace) |
210 | workspace.writeModel(model, '''solution«i»_«interpIndex».xmi''') | 319 | // println(model) |
320 | workspace.writeModel(model, '''sol-«id»_«interpIndex».xmi''') | ||
211 | } | 321 | } |
212 | } | 322 | } |
213 | 323 | ||
214 | def static writeRepresentation(LogicResult solution, ReasonerWorkspace workspace, int i) { | 324 | def |
325 | |||
326 | static writeRepresentation(LogicResult solution, ReasonerWorkspace workspace, String id) { | ||
215 | val representations = solution.representation | 327 | val representations = solution.representation |
216 | for (representationIndex : 0 ..< representations.size) { | 328 | for (representationIndex : 0 ..< representations.size) { |
217 | val representation = representations.get(representationIndex) | 329 | val representation = representations.get(representationIndex) |
218 | if (representation instanceof PartialInterpretation) { | 330 | if (representation instanceof PartialInterpretation) { |
219 | val gml = (new PartialInterpretation2Gml).transform(representation) | 331 | val gml = (new PartialInterpretation2Gml).transform(representation) |
220 | workspace.writeText('''solution«i»_«representationIndex».gml''', gml) | 332 | workspace.writeText('''sol-«id»_«representationIndex».gml''', gml) |
221 | 333 | ||
222 | val png = (new GraphvizVisualiser).visualiseConcretization(representation) | 334 | val png = (new GraphvizVisualiser).visualiseConcretization(representation) |
223 | png.writeToFile(workspace, '''solution«i»_«representationIndex».png''') | 335 | // println(png) |
336 | png.writeToFile(workspace, '''sol-«id»_«representationIndex».png''') | ||
224 | 337 | ||
225 | // workspace.writeModel(representation, '''solution«representationIndex».partialintrpretation''') | 338 | // workspace.writeModel(representation, '''solution«representationIndex».partialintrpretation''') |
226 | } else { | 339 | } else { |
227 | workspace.writeText('''solution«representationIndex».txt''', representation.toString) | 340 | workspace.writeText('''sol-«representationIndex».txt''', representation.toString) |
228 | } | 341 | } |
229 | } | 342 | } |
230 | } | 343 | } |
231 | 344 | ||
232 | def static writeStats(LogicResult solution, long time, ViatraReasonerConfiguration config) { | 345 | def |
346 | |||
347 | static writeStats(LogicResult solution, long time, ViatraReasonerConfiguration config) { | ||
233 | val stats = solution.statistics | 348 | val stats = solution.statistics |
234 | println(" Statistics:") | 349 | println(" Statistics:") |
235 | // for (e : stats.entries.filter[name.substring(0, 9) == "_Solution"]) { | 350 | // for (e : stats.entries.filter[name.substring(0, 9) == "_Solution"]) { |