diff options
Diffstat (limited to 'Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/run/RunGenerator.xtend')
-rw-r--r-- | Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/run/RunGenerator.xtend | 151 |
1 files changed, 0 insertions, 151 deletions
diff --git a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/run/RunGenerator.xtend b/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/run/RunGenerator.xtend deleted file mode 100644 index 8bd70919..00000000 --- a/Tests/MODELS2020-CaseStudies/case.study.pledge.queries/src/run/RunGenerator.xtend +++ /dev/null | |||
@@ -1,151 +0,0 @@ | |||
1 | package run | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic | ||
4 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2LogicConfiguration | ||
5 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace | ||
6 | import hu.bme.mit.inf.dslreasoner.ecore2logic.EcoreMetamodelDescriptor | ||
7 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Type | ||
8 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicResult | ||
9 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.impl.ModelResultImpl | ||
10 | import hu.bme.mit.inf.dslreasoner.logic2ecore.Logic2Ecore | ||
11 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2Logic | ||
12 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2LogicConfiguration | ||
13 | import hu.bme.mit.inf.dslreasoner.viatra2logic.ViatraQuerySetDescriptor | ||
14 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.InstanceModel2Logic | ||
15 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner | ||
16 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration | ||
17 | import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace | ||
18 | import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace | ||
19 | import java.io.PrintWriter | ||
20 | import java.text.SimpleDateFormat | ||
21 | import java.util.Date | ||
22 | import java.util.HashMap | ||
23 | import java.util.List | ||
24 | import java.util.Map | ||
25 | import org.eclipse.emf.ecore.EAttribute | ||
26 | import org.eclipse.emf.ecore.EClass | ||
27 | import org.eclipse.emf.ecore.EEnum | ||
28 | import org.eclipse.emf.ecore.EEnumLiteral | ||
29 | import org.eclipse.emf.ecore.EObject | ||
30 | import org.eclipse.emf.ecore.EPackage | ||
31 | import org.eclipse.emf.ecore.EReference | ||
32 | import org.eclipse.emf.ecore.resource.Resource | ||
33 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl | ||
34 | import org.eclipse.viatra.query.runtime.api.IQueryGroup | ||
35 | import Taxation.TaxationPackage | ||
36 | |||
37 | class GenerateScenarios { | ||
38 | def static void main(String[] args) { | ||
39 | val Ecore2Logic ecore2Logic = new Ecore2Logic | ||
40 | // val Logic2Ecore logic2Ecore = new Logic2Ecore(ecore2Logic) | ||
41 | // val Viatra2Logic viatra2Logic = new Viatra2Logic(ecore2Logic) | ||
42 | // val InstanceModel2Logic instanceModel2Logic = new InstanceModel2Logic | ||
43 | // Workspace setup | ||
44 | val Date date = new Date(System.currentTimeMillis) | ||
45 | val SimpleDateFormat format = new SimpleDateFormat("dd-HHmm"); | ||
46 | val formattedDate = format.format(date) | ||
47 | |||
48 | val workspace = new FileSystemWorkspace('''output/''' + formattedDate + '''/''', "") | ||
49 | workspace.initAndClear | ||
50 | |||
51 | // Logicproblem writing setup | ||
52 | val reg = Resource.Factory.Registry.INSTANCE | ||
53 | val map = reg.extensionToFactoryMap | ||
54 | map.put("logicproblem", new XMIResourceFactoryImpl) | ||
55 | |||
56 | println("Input and output workspaces are created") | ||
57 | |||
58 | print(TaxationPackage.eINSTANCE.getEClassifiers.filter(EClass).toList.get(0)) | ||
59 | |||
60 | val metamodel = loadMetamodel(TaxationPackage.eINSTANCE) | ||
61 | // val partialModel = loadPartialModel(inputs, "yakindu/Yakindu.xmi") | ||
62 | // val queries = loadQueries(metamodel, Patterns.instance) | ||
63 | println("DSL loaded") | ||
64 | |||
65 | val SIZE = 10 | ||
66 | var REPS = 1 | ||
67 | |||
68 | val RUNTIME = 300 | ||
69 | |||
70 | val modelGenerationProblem = ecore2Logic.transformMetamodel(metamodel, new Ecore2LogicConfiguration()) | ||
71 | // var modelExtensionProblem = instanceModel2Logic.transform(modelGenerationProblem, partialModel) | ||
72 | // var validModelExtensionProblem = viatra2Logic.transformQueries(queries, modelExtensionProblem, | ||
73 | // new Viatra2LogicConfiguration) | ||
74 | var problem = modelGenerationProblem.output | ||
75 | workspace.writeModel(problem, "scenario.logicproblem") | ||
76 | println("Problem created") | ||
77 | |||
78 | for (var i = 0; i <= REPS; i++) { | ||
79 | |||
80 | var ViatraReasoner reasoner = new ViatraReasoner | ||
81 | |||
82 | // ///////////////////////////////////////////////////// | ||
83 | // Define Config File | ||
84 | val solverConfig = new ViatraReasonerConfiguration => [ | ||
85 | // add configuration things, in config file first | ||
86 | // it.documentationLevel = DocumentationLevel::FULL | ||
87 | // it.iteration = iter | ||
88 | it.runtimeLimit = RUNTIME | ||
89 | it.typeScopes.maxNewElements = SIZE | ||
90 | it.typeScopes.minNewElements = SIZE | ||
91 | ] | ||
92 | |||
93 | var solution = reasoner.solve(problem, solverConfig, workspace) | ||
94 | print("Problem Solved") | ||
95 | |||
96 | // Run Garbage Collector | ||
97 | val Runtime r = Runtime.getRuntime(); | ||
98 | r.gc(); | ||
99 | r.gc(); | ||
100 | r.gc(); | ||
101 | Thread.sleep(3000) | ||
102 | } | ||
103 | |||
104 | } | ||
105 | |||
106 | def static Map<Type, Integer> getTypeMap(Map<Class, Integer> classMap, EcoreMetamodelDescriptor metamodel, | ||
107 | Ecore2Logic e2l, Ecore2Logic_Trace trace) { | ||
108 | val typeMap = new HashMap<Type, Integer> | ||
109 | val listMap = metamodel.classes.toMap[s|s.name] | ||
110 | |||
111 | for (Class elem : classMap.keySet) { | ||
112 | typeMap.put(e2l.TypeofEClass( | ||
113 | trace, | ||
114 | listMap.get(elem.simpleName) | ||
115 | ), classMap.get(elem)) | ||
116 | } | ||
117 | return typeMap | ||
118 | } | ||
119 | |||
120 | def static loadMetamodel(EPackage pckg) { | ||
121 | val List<EClass> classes = pckg.getEClassifiers.filter(EClass).toList | ||
122 | val List<EEnum> enums = pckg.getEClassifiers.filter(EEnum).toList | ||
123 | val List<EEnumLiteral> literals = enums.map[getELiterals].flatten.toList | ||
124 | val List<EReference> references = classes.map[getEReferences].flatten.toList | ||
125 | val List<EAttribute> attributes = classes.map[getEAttributes].flatten.toList | ||
126 | return new EcoreMetamodelDescriptor(classes, #{}, false, enums, literals, references, attributes) | ||
127 | } | ||
128 | |||
129 | def static loadPartialModel(ReasonerWorkspace inputs, String path) { | ||
130 | Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put("*", new XMIResourceFactoryImpl()) | ||
131 | inputs.readModel(EObject, path).eResource.contents | ||
132 | // inputs.readModel(EObject,"FamInstance.xmi").eResource.allContents.toList | ||
133 | } | ||
134 | |||
135 | def static loadQueries(EcoreMetamodelDescriptor metamodel, IQueryGroup i) { | ||
136 | val patterns = i.specifications.toList | ||
137 | val wfPatterns = patterns.filter[it.allAnnotations.exists[it.name == "Constraint"]].toSet | ||
138 | val derivedFeatures = emptyMap | ||
139 | // NO DERIVED FEATURES | ||
140 | // val derivedFeatures = new LinkedHashMap | ||
141 | // derivedFeatures.put(i.type,metamodel.attributes.filter[it.name == "type"].head) | ||
142 | // derivedFeatures.put(i.model,metamodel.references.filter[it.name == "model"].head) | ||
143 | val res = new ViatraQuerySetDescriptor( | ||
144 | patterns, | ||
145 | wfPatterns, | ||
146 | derivedFeatures | ||
147 | ) | ||
148 | return res | ||
149 | } | ||
150 | |||
151 | } | ||