diff options
author | 2020-05-10 20:56:55 -0400 | |
---|---|---|
committer | 2020-05-10 20:56:55 -0400 | |
commit | fb99d0d2a8ddcd7bad3b1f59152328e76ae8edb6 (patch) | |
tree | 4ee9262ebb91eb6bf8a84af0f771d6c4366c7b0d /Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run/GenerateFromConfig.xtend | |
parent | Satelite case study update for Models-Attribute paper (diff) | |
download | VIATRA-Generator-fb99d0d2a8ddcd7bad3b1f59152328e76ae8edb6.tar.gz VIATRA-Generator-fb99d0d2a8ddcd7bad3b1f59152328e76ae8edb6.tar.zst VIATRA-Generator-fb99d0d2a8ddcd7bad3b1f59152328e76ae8edb6.zip |
Fix PLEDGE Case Study File
Diffstat (limited to 'Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run/GenerateFromConfig.xtend')
-rw-r--r-- | Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run/GenerateFromConfig.xtend | 274 |
1 files changed, 274 insertions, 0 deletions
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run/GenerateFromConfig.xtend b/Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run/GenerateFromConfig.xtend new file mode 100644 index 00000000..859a4455 --- /dev/null +++ b/Tests/MODELS2020-CaseStudies/case.study.pledge.run/src/run/GenerateFromConfig.xtend | |||
@@ -0,0 +1,274 @@ | |||
1 | package run | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigSpecification | ||
4 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ConfigurationScript | ||
5 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.FileSpecification | ||
6 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.GenerationTask | ||
7 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.IntervallNumber | ||
8 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ObjectTypeScope | ||
9 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.RuntimeEntry | ||
10 | import hu.bme.mit.inf.dslreasoner.application.applicationConfiguration.ScopeSpecification | ||
11 | import hu.bme.mit.inf.dslreasoner.application.execution.ScriptExecutor | ||
12 | import hu.bme.mit.inf.dslreasoner.application.execution.StandaloneScriptExecutor | ||
13 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic | ||
14 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace | ||
15 | import hu.bme.mit.inf.dslreasoner.ecore2logic.EcoreMetamodelDescriptor | ||
16 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput | ||
17 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type | ||
18 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem | ||
19 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicResult | ||
20 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.ModelResult | ||
21 | import hu.bme.mit.inf.dslreasoner.logic2ecore.Logic2Ecore | ||
22 | import hu.bme.mit.inf.dslreasoner.viatra2logic.ViatraQuerySetDescriptor | ||
23 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
24 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation.PartialInterpretation2Gml | ||
25 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner | ||
26 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration | ||
27 | import hu.bme.mit.inf.dslreasoner.visualisation.pi2graphviz.GraphvizVisualiser | ||
28 | import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace | ||
29 | import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace | ||
30 | import java.io.PrintWriter | ||
31 | import java.math.BigDecimal | ||
32 | import java.text.SimpleDateFormat | ||
33 | import java.util.ArrayList | ||
34 | import java.util.Date | ||
35 | import java.util.HashMap | ||
36 | import java.util.List | ||
37 | import java.util.Map | ||
38 | import org.eclipse.core.runtime.NullProgressMonitor | ||
39 | import org.eclipse.emf.ecore.EAttribute | ||
40 | import org.eclipse.emf.ecore.EClass | ||
41 | import org.eclipse.emf.ecore.EEnum | ||
42 | import org.eclipse.emf.ecore.EEnumLiteral | ||
43 | import org.eclipse.emf.ecore.EObject | ||
44 | import org.eclipse.emf.ecore.EPackage | ||
45 | import org.eclipse.emf.ecore.EReference | ||
46 | import org.eclipse.emf.ecore.resource.Resource | ||
47 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl | ||
48 | import org.eclipse.viatra.query.runtime.api.IQueryGroup | ||
49 | |||
50 | class GenerateFromConfig { | ||
51 | static val SIZE_LB = 1 | ||
52 | static val SIZE_UB = 1 | ||
53 | static val SIZE_MUL = 1 | ||
54 | static val SIZE_INC = 5 | ||
55 | |||
56 | static var REPS = 1 | ||
57 | static val RUNTIME = 2100 | ||
58 | |||
59 | static val DOMAIN = "Taxation" // "FamilyTree", "Taxation" | ||
60 | static val QUERIES = true | ||
61 | static val INITIAL = true | ||
62 | static val INDIV_WRT = false | ||
63 | static val GLOBAL_WRT = false | ||
64 | static val q2t = if(QUERIES) "Y" else "N" | ||
65 | |||
66 | def static void main(String[] args) { | ||
67 | Resource.Factory.Registry.INSTANCE.extensionToFactoryMap.put("xmi", new XMIResourceFactoryImpl) | ||
68 | |||
69 | // Workspace setup | ||
70 | val Date date = new Date(System.currentTimeMillis) | ||
71 | val SimpleDateFormat format = new SimpleDateFormat("dd-HHmm"); | ||
72 | val formattedDate = DOMAIN + "-" + format.format(date) | ||
73 | |||
74 | val workspace = new FileSystemWorkspace('''output/''' + formattedDate + '''/''', "") | ||
75 | workspace.initAndClear | ||
76 | |||
77 | println("Input and output workspaces are created") | ||
78 | |||
79 | val executor = new ScriptExecutor | ||
80 | val path = "config//generic" + DOMAIN + ".vsconfig" | ||
81 | var ConfigurationScript config = StandaloneScriptExecutor.loadScript(path) | ||
82 | |||
83 | println("Config File loaded") | ||
84 | |||
85 | // ///////////////////////// | ||
86 | // BEGIN RUN | ||
87 | var PrintWriter global_writer = null | ||
88 | val header = "domain, queries?,size,model?,timeout,measuredTime,TransformatonTime,SolverTime\n" | ||
89 | if (GLOBAL_WRT) { | ||
90 | global_writer = new PrintWriter( | ||
91 | workspace.workspaceURI + "//_" + DOMAIN + SIZE_LB + "to" + SIZE_UB + "x" + REPS + "q" + q2t + "-" + | ||
92 | formattedDate + ".csv") | ||
93 | global_writer.append(header) | ||
94 | } | ||
95 | |||
96 | var NEXT_INC = SIZE_INC | ||
97 | for (var size = SIZE_LB; size <= SIZE_UB; size += NEXT_INC) { | ||
98 | NEXT_INC *= SIZE_MUL | ||
99 | |||
100 | var PrintWriter indiv_writer = null | ||
101 | if (INDIV_WRT) { | ||
102 | indiv_writer = new PrintWriter( // TODO | ||
103 | workspace.workspaceURI + "//__" + DOMAIN + "Sz" + size + "x" + REPS + "q" + q2t + "-" + formattedDate + | ||
104 | ".csv") | ||
105 | indiv_writer.append(header) | ||
106 | } | ||
107 | |||
108 | println() | ||
109 | println("DOMAIN: " + DOMAIN + ", SIZE=" + size) | ||
110 | |||
111 | for (var i = 0; i < REPS; i++) { | ||
112 | |||
113 | print("<<Run number " + i + ">> : ") | ||
114 | |||
115 | |||
116 | // ///////////////////////////////////////////////////// | ||
117 | // Define Config File | ||
118 | val knownIntegers = new ArrayList<Integer> | ||
119 | knownIntegers.addAll(0, 10, 20, 30, 40, 50) | ||
120 | |||
121 | val knownReals = new ArrayList<BigDecimal> | ||
122 | knownReals.addAll(new BigDecimal("0.0")) | ||
123 | |||
124 | val knownStrings = new ArrayList<String> | ||
125 | knownStrings.addAll("r0", "r1", "r2", "r3", "r4", "r5", "r6") | ||
126 | |||
127 | val outputPath = "output/" + formattedDate + "/size" + size + "/run" + i + "/models/" | ||
128 | val debugPath = "output/" + formattedDate + "/size" + size + "/run" + i + "/debug/" | ||
129 | val logPath = debugPath + "log.txt" | ||
130 | val statsPath = debugPath + "statistics.csv" | ||
131 | |||
132 | // Adjust configuration | ||
133 | val genTask = config.commands.get(0) as GenerationTask | ||
134 | if(!QUERIES) genTask.patterns = null | ||
135 | if(!INITIAL) genTask.partialModel = null | ||
136 | |||
137 | val scopeSpec = genTask.scope as ScopeSpecification | ||
138 | val objScope = scopeSpec.scopes.get(0) as ObjectTypeScope | ||
139 | val interval = objScope.number as IntervallNumber | ||
140 | interval.min = size | ||
141 | interval.maxUnlimited = true | ||
142 | |||
143 | val configScope = genTask.config as ConfigSpecification | ||
144 | val runtimeEntry = configScope.entries.get(0) as RuntimeEntry | ||
145 | runtimeEntry.millisecLimit = RUNTIME | ||
146 | |||
147 | // TODO add known ints, reals, string... | ||
148 | val debug = genTask.debugFolder as FileSpecification | ||
149 | debug.path = debugPath | ||
150 | val output = genTask.tagetFolder as FileSpecification | ||
151 | output.path = outputPath | ||
152 | val log = genTask.targetLogFile as FileSpecification | ||
153 | log.path = logPath | ||
154 | val stats = genTask.targetStatisticsFile as FileSpecification | ||
155 | stats.path = statsPath | ||
156 | |||
157 | // workspace.writeModel(config, '''x.xmi''') | ||
158 | val startTime = System.currentTimeMillis | ||
159 | executor.executeScript(config, new NullProgressMonitor) | ||
160 | val measuredTime = System.currentTimeMillis - startTime | ||
161 | |||
162 | println("<<END ->" + measuredTime / 1000.0 + "s >>\n") | ||
163 | |||
164 | // val toAddtoCSV = DOMAIN + "," + QUERIES + "," + size + "," + | ||
165 | // (solution.class == ModelResultImpl).toString + "," + RUNTIME + "," + measuredTime / 1000.0 + "," + | ||
166 | // solution.statistics.transformationTime / 1000.0 + "," + solution.statistics.solverTime / 1000.0 + | ||
167 | // "\n" | ||
168 | // | ||
169 | // if(GLOBAL_WRT) global_writer.append(toAddtoCSV) | ||
170 | // if(INDIV_WRT) indiv_writer.append(toAddtoCSV) | ||
171 | // solution.writeStats(totalTime, solverConfig) | ||
172 | // Run Garbage Collector | ||
173 | val Runtime r = Runtime.getRuntime(); | ||
174 | r.gc(); | ||
175 | r.gc(); | ||
176 | r.gc(); | ||
177 | Thread.sleep(3000) | ||
178 | } | ||
179 | if(INDIV_WRT) indiv_writer.close | ||
180 | } | ||
181 | if(GLOBAL_WRT) global_writer.close | ||
182 | } | ||
183 | |||
184 | def static Map<Type, Integer> getTypeMap(Map<Class, Integer> classMap, EcoreMetamodelDescriptor metamodel, | ||
185 | Ecore2Logic e2l, Ecore2Logic_Trace trace) { | ||
186 | val typeMap = new HashMap<Type, Integer> | ||
187 | val listMap = metamodel.classes.toMap[s|s.name] | ||
188 | |||
189 | for (Class elem : classMap.keySet) { | ||
190 | typeMap.put(e2l.TypeofEClass( | ||
191 | trace, | ||
192 | listMap.get(elem.simpleName) | ||
193 | ), classMap.get(elem)) | ||
194 | } | ||
195 | return typeMap | ||
196 | } | ||
197 | |||
198 | def static loadMetamodel(EPackage pckg) { | ||
199 | val List<EClass> classes = pckg.getEClassifiers.filter(EClass).toList | ||
200 | val List<EEnum> enums = pckg.getEClassifiers.filter(EEnum).toList | ||
201 | val List<EEnumLiteral> literals = enums.map[getELiterals].flatten.toList | ||
202 | val List<EReference> references = classes.map[getEReferences].flatten.toList | ||
203 | val List<EAttribute> attributes = classes.map[getEAttributes].flatten.toList | ||
204 | return new EcoreMetamodelDescriptor(classes, #{}, false, enums, literals, references, attributes) | ||
205 | } | ||
206 | |||
207 | def static loadPartialModel(ReasonerWorkspace inputs, String path) { | ||
208 | Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl()) | ||
209 | inputs.readModel(EObject, path).eResource.contents | ||
210 | // inputs.readModel(EObject,"FamInstance.xmi").eResource.allContents.toList | ||
211 | } | ||
212 | |||
213 | def static loadQueries(EcoreMetamodelDescriptor metamodel, IQueryGroup i) { | ||
214 | val patterns = i.specifications.toList | ||
215 | val wfPatterns = patterns.filter[it.allAnnotations.exists[it.name == "Constraint"]].toSet | ||
216 | val derivedFeatures = emptyMap | ||
217 | // NO DERIVED FEATURES | ||
218 | // val derivedFeatures = new LinkedHashMap | ||
219 | // derivedFeatures.put(i.type,metamodel.attributes.filter[it.name == "type"].head) | ||
220 | // derivedFeatures.put(i.model,metamodel.references.filter[it.name == "model"].head) | ||
221 | val res = new ViatraQuerySetDescriptor( | ||
222 | patterns, | ||
223 | wfPatterns, | ||
224 | derivedFeatures | ||
225 | ) | ||
226 | return res | ||
227 | } | ||
228 | |||
229 | def static writeInterpretation(LogicResult solution, Logic2Ecore logic2Ecore, ReasonerWorkspace workspace, | ||
230 | String id, ViatraReasoner reasoner, TracedOutput<LogicProblem, Ecore2Logic_Trace> mgProb) { | ||
231 | val interpretations = reasoner.getInterpretations(solution as ModelResult) | ||
232 | for (interpIndex : 0 ..< interpretations.size) { | ||
233 | // val extension b = new LogicStructureBuilder | ||
234 | // val extension a = new LogicProblemBuilder | ||
235 | val interpretation = interpretations.get(interpIndex) | ||
236 | val model = logic2Ecore.transformInterpretation(interpretation, mgProb.trace) | ||
237 | // println(model) | ||
238 | workspace.writeModel(model, '''sol-«id»_«interpIndex».xmi''') | ||
239 | } | ||
240 | } | ||
241 | |||
242 | def static writeRepresentation(LogicResult solution, ReasonerWorkspace workspace, String id) { | ||
243 | val representations = solution.representation | ||
244 | for (representationIndex : 0 ..< representations.size) { | ||
245 | val representation = representations.get(representationIndex) | ||
246 | if (representation instanceof PartialInterpretation) { | ||
247 | val gml = (new PartialInterpretation2Gml).transform(representation) | ||
248 | workspace.writeText('''sol-«id»_«representationIndex».gml''', gml) | ||
249 | |||
250 | val png = (new GraphvizVisualiser).visualiseConcretization(representation) | ||
251 | // println(png) | ||
252 | png.writeToFile(workspace, '''sol-«id»_«representationIndex».png''') | ||
253 | |||
254 | // workspace.writeModel(representation, '''solution«representationIndex».partialintrpretation''') | ||
255 | } else { | ||
256 | workspace.writeText('''sol-«representationIndex».txt''', representation.toString) | ||
257 | } | ||
258 | } | ||
259 | } | ||
260 | |||
261 | def static writeStats(LogicResult solution, long time, ViatraReasonerConfiguration config) { | ||
262 | val stats = solution.statistics | ||
263 | println(" Statistics:") | ||
264 | // for (e : stats.entries.filter[name.substring(0, 9) == "_Solution"]) { | ||
265 | // println(" " + e.name + ": " + (e as IntStatisticEntry).value + " ms") | ||
266 | // } | ||
267 | println( | ||
268 | " #new nodes : [" + config.typeScopes.minNewElements + ".." + | ||
269 | (if(config.typeScopes.maxNewElements == 2147483647) "*" else config.typeScopes.maxNewElements) + "]") | ||
270 | println(" \"solve\" time: " + time as double / 1000 + " s") | ||
271 | |||
272 | // println("<<End Statistics>>") | ||
273 | } | ||
274 | } | ||