diff options
author | 2019-03-20 20:39:28 -0400 | |
---|---|---|
committer | 2020-06-07 19:33:22 -0400 | |
commit | 513a5afe3a8663ad30112f7e3c0e66137938e635 (patch) | |
tree | e9ae81f529712a372bd203cb0ef2a19b9b224c95 /Tests/ca.mcgill.ecse.dslreasoner.yakindu.test/bin/ca/mcgill | |
parent | Implement Containment mapping (partially) and revisit enum mapping (diff) | |
download | VIATRA-Generator-513a5afe3a8663ad30112f7e3c0e66137938e635.tar.gz VIATRA-Generator-513a5afe3a8663ad30112f7e3c0e66137938e635.tar.zst VIATRA-Generator-513a5afe3a8663ad30112f7e3c0e66137938e635.zip |
Add gitignore, commit everything
Diffstat (limited to 'Tests/ca.mcgill.ecse.dslreasoner.yakindu.test/bin/ca/mcgill')
3 files changed, 179 insertions, 0 deletions
diff --git a/Tests/ca.mcgill.ecse.dslreasoner.yakindu.test/bin/ca/mcgill/ecse/dslreasoner/yakindu/test/.YakinduTest.xtendbin b/Tests/ca.mcgill.ecse.dslreasoner.yakindu.test/bin/ca/mcgill/ecse/dslreasoner/yakindu/test/.YakinduTest.xtendbin new file mode 100644 index 00000000..d0f61cf1 --- /dev/null +++ b/Tests/ca.mcgill.ecse.dslreasoner.yakindu.test/bin/ca/mcgill/ecse/dslreasoner/yakindu/test/.YakinduTest.xtendbin | |||
Binary files differ | |||
diff --git a/Tests/ca.mcgill.ecse.dslreasoner.yakindu.test/bin/ca/mcgill/ecse/dslreasoner/yakindu/test/.gitignore b/Tests/ca.mcgill.ecse.dslreasoner.yakindu.test/bin/ca/mcgill/ecse/dslreasoner/yakindu/test/.gitignore new file mode 100644 index 00000000..5d3de4ba --- /dev/null +++ b/Tests/ca.mcgill.ecse.dslreasoner.yakindu.test/bin/ca/mcgill/ecse/dslreasoner/yakindu/test/.gitignore | |||
@@ -0,0 +1 @@ | |||
/.YakinduTest.java._trace | |||
diff --git a/Tests/ca.mcgill.ecse.dslreasoner.yakindu.test/bin/ca/mcgill/ecse/dslreasoner/yakindu/test/YakinduTest.xtend b/Tests/ca.mcgill.ecse.dslreasoner.yakindu.test/bin/ca/mcgill/ecse/dslreasoner/yakindu/test/YakinduTest.xtend new file mode 100644 index 00000000..b6aae6ab --- /dev/null +++ b/Tests/ca.mcgill.ecse.dslreasoner.yakindu.test/bin/ca/mcgill/ecse/dslreasoner/yakindu/test/YakinduTest.xtend | |||
@@ -0,0 +1,178 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.yakindu.test | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.YakindummPackage | ||
4 | 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.EcoreMetamodelDescriptor | ||
7 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicProblemBuilder | ||
8 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicStructureBuilder | ||
9 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicResult | ||
10 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.ModelResult | ||
11 | import hu.bme.mit.inf.dslreasoner.logic2ecore.Logic2Ecore | ||
12 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2Logic | ||
13 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.InstanceModel2Logic | ||
14 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation | ||
15 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation.PartialInterpretation2Gml | ||
16 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner | ||
17 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration | ||
18 | import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace | ||
19 | import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace | ||
20 | import java.util.LinkedList | ||
21 | import java.util.List | ||
22 | import org.eclipse.emf.ecore.EAttribute | ||
23 | import org.eclipse.emf.ecore.EClass | ||
24 | import org.eclipse.emf.ecore.EEnum | ||
25 | import org.eclipse.emf.ecore.EEnumLiteral | ||
26 | import org.eclipse.emf.ecore.EObject | ||
27 | import org.eclipse.emf.ecore.EPackage | ||
28 | import org.eclipse.emf.ecore.EReference | ||
29 | import org.eclipse.emf.ecore.resource.Resource | ||
30 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl | ||
31 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.SolutionScope | ||
32 | |||
33 | class YakinduTest { | ||
34 | |||
35 | static String inWS = "input" | ||
36 | static String outWS = "output" | ||
37 | static String imName = "Yakindu.xmi" | ||
38 | |||
39 | def static void main(String[] args) { | ||
40 | val Ecore2Logic ecore2Logic = new Ecore2Logic | ||
41 | val Logic2Ecore logic2Ecore = new Logic2Ecore(ecore2Logic) | ||
42 | val Viatra2Logic viatra2Logic = new Viatra2Logic(ecore2Logic) | ||
43 | val InstanceModel2Logic instanceModel2Logic = new InstanceModel2Logic | ||
44 | |||
45 | // Workspace setup | ||
46 | val inputs = new FileSystemWorkspace(inWS + '''/''', "") | ||
47 | val workspace = new FileSystemWorkspace(outWS + '''/''', "") | ||
48 | workspace.initAndClear | ||
49 | |||
50 | // Logicproblem writing setup | ||
51 | val reg = Resource.Factory.Registry.INSTANCE | ||
52 | val map = reg.extensionToFactoryMap | ||
53 | map.put("logicproblem", new XMIResourceFactoryImpl) | ||
54 | |||
55 | println("Input and output workspaces are created") | ||
56 | |||
57 | //loading the modeling environment | ||
58 | val metamodel = loadMetamodel(YakindummPackage.eINSTANCE) // TODO | ||
59 | val partialModel = loadPartialModel(inputs, imName) | ||
60 | // val queries = loadQueries(metamodel, Patterns.instance) | ||
61 | val modelGenerationProblem = ecore2Logic.transformMetamodel(metamodel, new Ecore2LogicConfiguration()) | ||
62 | var modelExtensionProblem = instanceModel2Logic.transform(modelGenerationProblem, partialModel) | ||
63 | // var validModelExtensionProblem = viatra2Logic.transformQueries(queries, modelExtensionProblem, new Viatra2LogicConfiguration) | ||
64 | var problem = modelExtensionProblem.output | ||
65 | |||
66 | println("Modelling environment Loaded") | ||
67 | |||
68 | |||
69 | val ss = new SolutionScope() | ||
70 | ss.numberOfRequiredSolution = 5 | ||
71 | |||
72 | var reasoner = new ViatraReasoner | ||
73 | val vampireConfig = new ViatraReasonerConfiguration => [ | ||
74 | // add configuration things, in config file first | ||
75 | // it.documentationLevel = DocumentationLevel::FULL | ||
76 | it.solutionScope = ss | ||
77 | it.typeScopes.maxNewElements = 10 | ||
78 | it.typeScopes.minNewElements = 5 | ||
79 | ] | ||
80 | |||
81 | println("Problem Ready") | ||
82 | |||
83 | var LogicResult solution = reasoner.solve(problem, vampireConfig, workspace) | ||
84 | |||
85 | println("Problem solved") | ||
86 | |||
87 | val interpretations = reasoner.getInterpretations(solution as ModelResult) | ||
88 | val models = new LinkedList | ||
89 | for (interpretation : interpretations) { | ||
90 | // val extension b = new LogicStructureBuilder | ||
91 | // val extension a = new LogicProblemBuilder | ||
92 | |||
93 | val instanceModel = logic2Ecore.transformInterpretation(interpretation, modelGenerationProblem.trace) | ||
94 | models += instanceModel | ||
95 | } | ||
96 | |||
97 | solution.writeSolution(workspace, models) | ||
98 | // print((solution as ModelResult).representation.get(0)) | ||
99 | // val soln = ((solution as ModelResult).representation.get(0) as VampireModel) | ||
100 | // println(soln.confirmations) | ||
101 | // println((solution as ModelResult).representation) | ||
102 | // modelFound = !soln.confirmations.filter [ | ||
103 | // class == VLSFiniteModelImpl | ||
104 | // ].isEmpty | ||
105 | } | ||
106 | |||
107 | // def static Map<Type, Integer> getTypeMap(Map<Class, Integer> classMap, EcoreMetamodelDescriptor metamodel, | ||
108 | // Ecore2Logic e2l, Ecore2Logic_Trace trace) { | ||
109 | // val typeMap = new HashMap<Type, Integer> | ||
110 | // val listMap = metamodel.classes.toMap[s|s.name] | ||
111 | // | ||
112 | // for (Class elem : classMap.keySet) { | ||
113 | // typeMap.put(e2l.TypeofEClass( | ||
114 | // trace, | ||
115 | // listMap.get(elem.simpleName) | ||
116 | // ), classMap.get(elem)) | ||
117 | // } | ||
118 | // return typeMap | ||
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 | def static writeSolution(LogicResult solution, ReasonerWorkspace workspace, List<EObject> models) { | ||
152 | if(solution instanceof ModelResult) { | ||
153 | val representations = solution.representation | ||
154 | |||
155 | for(representationIndex : 0..<representations.size) { | ||
156 | val representation = representations.get(representationIndex) | ||
157 | val representationNumber = representationIndex + 1 | ||
158 | if(representation instanceof PartialInterpretation) { | ||
159 | // workspace.writeModel(representation, '''solution«representationNumber».partialinterpretation''') | ||
160 | val partialInterpretation2GML = new PartialInterpretation2Gml | ||
161 | val gml = partialInterpretation2GML.transform(representation) | ||
162 | //ecore2GML.transform(root) | ||
163 | workspace.writeText('''solution«representationNumber»Visualisation.gml''',gml) | ||
164 | |||
165 | } else { | ||
166 | workspace.writeText('''solution«representationNumber».txt''',representation.toString) | ||
167 | } | ||
168 | } | ||
169 | |||
170 | for(modelIndex : 0..<models.size) { | ||
171 | val model = models.get(modelIndex) | ||
172 | val representationNumber = modelIndex + 1 | ||
173 | workspace.writeModel(model,'''model«representationNumber».xmi''') | ||
174 | } | ||
175 | println("Solution saved and visualised") | ||
176 | } | ||
177 | } | ||
178 | } | ||