diff options
Diffstat (limited to 'Tests/ca.mcgill.ecse.dslreasoner.yakindu.test/xtend-gen/ca/mcgill/ecse/dslreasoner')
3 files changed, 189 insertions, 0 deletions
diff --git a/Tests/ca.mcgill.ecse.dslreasoner.yakindu.test/xtend-gen/ca/mcgill/ecse/dslreasoner/yakindu/test/.YakinduTest.xtendbin b/Tests/ca.mcgill.ecse.dslreasoner.yakindu.test/xtend-gen/ca/mcgill/ecse/dslreasoner/yakindu/test/.YakinduTest.xtendbin new file mode 100644 index 00000000..139dcdc7 --- /dev/null +++ b/Tests/ca.mcgill.ecse.dslreasoner.yakindu.test/xtend-gen/ca/mcgill/ecse/dslreasoner/yakindu/test/.YakinduTest.xtendbin | |||
Binary files differ | |||
diff --git a/Tests/ca.mcgill.ecse.dslreasoner.yakindu.test/xtend-gen/ca/mcgill/ecse/dslreasoner/yakindu/test/.gitignore b/Tests/ca.mcgill.ecse.dslreasoner.yakindu.test/xtend-gen/ca/mcgill/ecse/dslreasoner/yakindu/test/.gitignore new file mode 100644 index 00000000..5d3de4ba --- /dev/null +++ b/Tests/ca.mcgill.ecse.dslreasoner.yakindu.test/xtend-gen/ca/mcgill/ecse/dslreasoner/yakindu/test/.gitignore | |||
@@ -0,0 +1 @@ | |||
/.YakinduTest.java._trace | |||
diff --git a/Tests/ca.mcgill.ecse.dslreasoner.yakindu.test/xtend-gen/ca/mcgill/ecse/dslreasoner/yakindu/test/YakinduTest.java b/Tests/ca.mcgill.ecse.dslreasoner.yakindu.test/xtend-gen/ca/mcgill/ecse/dslreasoner/yakindu/test/YakinduTest.java new file mode 100644 index 00000000..fd1d1f4c --- /dev/null +++ b/Tests/ca.mcgill.ecse.dslreasoner.yakindu.test/xtend-gen/ca/mcgill/ecse/dslreasoner/yakindu/test/YakinduTest.java | |||
@@ -0,0 +1,188 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.yakindu.test; | ||
2 | |||
3 | import com.google.common.collect.Iterables; | ||
4 | import hu.bme.mit.inf.dslreasoner.domains.yakindu.sgraph.yakindumm.YakindummPackage; | ||
5 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic; | ||
6 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2LogicConfiguration; | ||
7 | import hu.bme.mit.inf.dslreasoner.ecore2logic.Ecore2Logic_Trace; | ||
8 | import hu.bme.mit.inf.dslreasoner.ecore2logic.EcoreMetamodelDescriptor; | ||
9 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.LogicModelInterpretation; | ||
10 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.SolutionScope; | ||
11 | import hu.bme.mit.inf.dslreasoner.logic.model.builder.TracedOutput; | ||
12 | import hu.bme.mit.inf.dslreasoner.logic.model.logicproblem.LogicProblem; | ||
13 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.LogicResult; | ||
14 | import hu.bme.mit.inf.dslreasoner.logic.model.logicresult.ModelResult; | ||
15 | import hu.bme.mit.inf.dslreasoner.logic2ecore.Logic2Ecore; | ||
16 | import hu.bme.mit.inf.dslreasoner.viatra2logic.Viatra2Logic; | ||
17 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretation2logic.InstanceModel2Logic; | ||
18 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.partialinterpretation.PartialInterpretation; | ||
19 | import hu.bme.mit.inf.dslreasoner.viatrasolver.partialinterpretationlanguage.visualisation.PartialInterpretation2Gml; | ||
20 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasoner; | ||
21 | import hu.bme.mit.inf.dslreasoner.viatrasolver.reasoner.ViatraReasonerConfiguration; | ||
22 | import hu.bme.mit.inf.dslreasoner.workspace.FileSystemWorkspace; | ||
23 | import hu.bme.mit.inf.dslreasoner.workspace.ReasonerWorkspace; | ||
24 | import java.util.Collections; | ||
25 | import java.util.LinkedList; | ||
26 | import java.util.List; | ||
27 | import java.util.Map; | ||
28 | import org.eclipse.emf.common.util.EList; | ||
29 | import org.eclipse.emf.ecore.EAttribute; | ||
30 | import org.eclipse.emf.ecore.EClass; | ||
31 | import org.eclipse.emf.ecore.EEnum; | ||
32 | import org.eclipse.emf.ecore.EEnumLiteral; | ||
33 | import org.eclipse.emf.ecore.EObject; | ||
34 | import org.eclipse.emf.ecore.EPackage; | ||
35 | import org.eclipse.emf.ecore.EReference; | ||
36 | import org.eclipse.emf.ecore.resource.Resource; | ||
37 | import org.eclipse.emf.ecore.xmi.impl.XMIResourceFactoryImpl; | ||
38 | import org.eclipse.xtend2.lib.StringConcatenation; | ||
39 | import org.eclipse.xtext.xbase.lib.CollectionLiterals; | ||
40 | import org.eclipse.xtext.xbase.lib.Exceptions; | ||
41 | import org.eclipse.xtext.xbase.lib.ExclusiveRange; | ||
42 | import org.eclipse.xtext.xbase.lib.Functions.Function1; | ||
43 | import org.eclipse.xtext.xbase.lib.InputOutput; | ||
44 | import org.eclipse.xtext.xbase.lib.IterableExtensions; | ||
45 | import org.eclipse.xtext.xbase.lib.ListExtensions; | ||
46 | import org.eclipse.xtext.xbase.lib.ObjectExtensions; | ||
47 | import org.eclipse.xtext.xbase.lib.Procedures.Procedure1; | ||
48 | |||
49 | @SuppressWarnings("all") | ||
50 | public class YakinduTest { | ||
51 | private static String inWS = "input"; | ||
52 | |||
53 | private static String outWS = "output"; | ||
54 | |||
55 | private static String imName = "Yakindu.xmi"; | ||
56 | |||
57 | public static void main(final String[] args) { | ||
58 | try { | ||
59 | final Ecore2Logic ecore2Logic = new Ecore2Logic(); | ||
60 | final Logic2Ecore logic2Ecore = new Logic2Ecore(ecore2Logic); | ||
61 | final Viatra2Logic viatra2Logic = new Viatra2Logic(ecore2Logic); | ||
62 | final InstanceModel2Logic instanceModel2Logic = new InstanceModel2Logic(); | ||
63 | StringConcatenation _builder = new StringConcatenation(); | ||
64 | _builder.append("/"); | ||
65 | String _plus = (YakinduTest.inWS + _builder); | ||
66 | final FileSystemWorkspace inputs = new FileSystemWorkspace(_plus, ""); | ||
67 | StringConcatenation _builder_1 = new StringConcatenation(); | ||
68 | _builder_1.append("/"); | ||
69 | String _plus_1 = (YakinduTest.outWS + _builder_1); | ||
70 | final FileSystemWorkspace workspace = new FileSystemWorkspace(_plus_1, ""); | ||
71 | workspace.initAndClear(); | ||
72 | final Resource.Factory.Registry reg = Resource.Factory.Registry.INSTANCE; | ||
73 | final Map<String, Object> map = reg.getExtensionToFactoryMap(); | ||
74 | XMIResourceFactoryImpl _xMIResourceFactoryImpl = new XMIResourceFactoryImpl(); | ||
75 | map.put("logicproblem", _xMIResourceFactoryImpl); | ||
76 | InputOutput.<String>println("Input and output workspaces are created"); | ||
77 | final EcoreMetamodelDescriptor metamodel = YakinduTest.loadMetamodel(YakindummPackage.eINSTANCE); | ||
78 | final EList<EObject> partialModel = YakinduTest.loadPartialModel(inputs, YakinduTest.imName); | ||
79 | Ecore2LogicConfiguration _ecore2LogicConfiguration = new Ecore2LogicConfiguration(); | ||
80 | final TracedOutput<LogicProblem, Ecore2Logic_Trace> modelGenerationProblem = ecore2Logic.transformMetamodel(metamodel, _ecore2LogicConfiguration); | ||
81 | TracedOutput<LogicProblem, Ecore2Logic_Trace> modelExtensionProblem = instanceModel2Logic.transform(modelGenerationProblem, partialModel); | ||
82 | LogicProblem problem = modelExtensionProblem.getOutput(); | ||
83 | InputOutput.<String>println("Modelling environment Loaded"); | ||
84 | final SolutionScope ss = new SolutionScope(); | ||
85 | ss.numberOfRequiredSolution = 5; | ||
86 | ViatraReasoner reasoner = new ViatraReasoner(); | ||
87 | ViatraReasonerConfiguration _viatraReasonerConfiguration = new ViatraReasonerConfiguration(); | ||
88 | final Procedure1<ViatraReasonerConfiguration> _function = (ViatraReasonerConfiguration it) -> { | ||
89 | it.solutionScope = ss; | ||
90 | it.typeScopes.maxNewElements = 10; | ||
91 | it.typeScopes.minNewElements = 5; | ||
92 | }; | ||
93 | final ViatraReasonerConfiguration vampireConfig = ObjectExtensions.<ViatraReasonerConfiguration>operator_doubleArrow(_viatraReasonerConfiguration, _function); | ||
94 | InputOutput.<String>println("Problem Ready"); | ||
95 | LogicResult solution = reasoner.solve(problem, vampireConfig, workspace); | ||
96 | InputOutput.<String>println("Problem solved"); | ||
97 | final List<? extends LogicModelInterpretation> interpretations = reasoner.getInterpretations(((ModelResult) solution)); | ||
98 | final LinkedList<EObject> models = new LinkedList<EObject>(); | ||
99 | for (final LogicModelInterpretation interpretation : interpretations) { | ||
100 | { | ||
101 | final EObject instanceModel = logic2Ecore.transformInterpretation(interpretation, modelGenerationProblem.getTrace()); | ||
102 | models.add(instanceModel); | ||
103 | } | ||
104 | } | ||
105 | YakinduTest.writeSolution(solution, workspace, models); | ||
106 | } catch (Throwable _e) { | ||
107 | throw Exceptions.sneakyThrow(_e); | ||
108 | } | ||
109 | } | ||
110 | |||
111 | public static EcoreMetamodelDescriptor loadMetamodel(final EPackage pckg) { | ||
112 | final List<EClass> classes = IterableExtensions.<EClass>toList(Iterables.<EClass>filter(pckg.getEClassifiers(), EClass.class)); | ||
113 | final List<EEnum> enums = IterableExtensions.<EEnum>toList(Iterables.<EEnum>filter(pckg.getEClassifiers(), EEnum.class)); | ||
114 | final Function1<EEnum, EList<EEnumLiteral>> _function = (EEnum it) -> { | ||
115 | return it.getELiterals(); | ||
116 | }; | ||
117 | final List<EEnumLiteral> literals = IterableExtensions.<EEnumLiteral>toList(Iterables.<EEnumLiteral>concat(ListExtensions.<EEnum, EList<EEnumLiteral>>map(enums, _function))); | ||
118 | final Function1<EClass, EList<EReference>> _function_1 = (EClass it) -> { | ||
119 | return it.getEReferences(); | ||
120 | }; | ||
121 | final List<EReference> references = IterableExtensions.<EReference>toList(Iterables.<EReference>concat(ListExtensions.<EClass, EList<EReference>>map(classes, _function_1))); | ||
122 | final Function1<EClass, EList<EAttribute>> _function_2 = (EClass it) -> { | ||
123 | return it.getEAttributes(); | ||
124 | }; | ||
125 | final List<EAttribute> attributes = IterableExtensions.<EAttribute>toList(Iterables.<EAttribute>concat(ListExtensions.<EClass, EList<EAttribute>>map(classes, _function_2))); | ||
126 | return new EcoreMetamodelDescriptor(classes, Collections.<EClass>unmodifiableSet(CollectionLiterals.<EClass>newHashSet()), false, enums, literals, references, attributes); | ||
127 | } | ||
128 | |||
129 | public static EList<EObject> loadPartialModel(final ReasonerWorkspace inputs, final String path) { | ||
130 | EList<EObject> _xblockexpression = null; | ||
131 | { | ||
132 | Map<String, Object> _extensionToFactoryMap = Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap(); | ||
133 | XMIResourceFactoryImpl _xMIResourceFactoryImpl = new XMIResourceFactoryImpl(); | ||
134 | _extensionToFactoryMap.put("*", _xMIResourceFactoryImpl); | ||
135 | _xblockexpression = inputs.<EObject>readModel(EObject.class, path).eResource().getContents(); | ||
136 | } | ||
137 | return _xblockexpression; | ||
138 | } | ||
139 | |||
140 | public static String writeSolution(final LogicResult solution, final ReasonerWorkspace workspace, final List<EObject> models) { | ||
141 | String _xifexpression = null; | ||
142 | if ((solution instanceof ModelResult)) { | ||
143 | String _xblockexpression = null; | ||
144 | { | ||
145 | final EList<Object> representations = ((ModelResult)solution).getRepresentation(); | ||
146 | int _size = representations.size(); | ||
147 | ExclusiveRange _doubleDotLessThan = new ExclusiveRange(0, _size, true); | ||
148 | for (final Integer representationIndex : _doubleDotLessThan) { | ||
149 | { | ||
150 | final Object representation = representations.get((representationIndex).intValue()); | ||
151 | final int representationNumber = ((representationIndex).intValue() + 1); | ||
152 | if ((representation instanceof PartialInterpretation)) { | ||
153 | final PartialInterpretation2Gml partialInterpretation2GML = new PartialInterpretation2Gml(); | ||
154 | final String gml = partialInterpretation2GML.transform(((PartialInterpretation)representation)); | ||
155 | StringConcatenation _builder = new StringConcatenation(); | ||
156 | _builder.append("solution"); | ||
157 | _builder.append(representationNumber); | ||
158 | _builder.append("Visualisation.gml"); | ||
159 | workspace.writeText(_builder.toString(), gml); | ||
160 | } else { | ||
161 | StringConcatenation _builder_1 = new StringConcatenation(); | ||
162 | _builder_1.append("solution"); | ||
163 | _builder_1.append(representationNumber); | ||
164 | _builder_1.append(".txt"); | ||
165 | workspace.writeText(_builder_1.toString(), representation.toString()); | ||
166 | } | ||
167 | } | ||
168 | } | ||
169 | int _size_1 = models.size(); | ||
170 | ExclusiveRange _doubleDotLessThan_1 = new ExclusiveRange(0, _size_1, true); | ||
171 | for (final Integer modelIndex : _doubleDotLessThan_1) { | ||
172 | { | ||
173 | final EObject model = models.get((modelIndex).intValue()); | ||
174 | final int representationNumber = ((modelIndex).intValue() + 1); | ||
175 | StringConcatenation _builder = new StringConcatenation(); | ||
176 | _builder.append("model"); | ||
177 | _builder.append(representationNumber); | ||
178 | _builder.append(".xmi"); | ||
179 | workspace.writeModel(model, _builder.toString()); | ||
180 | } | ||
181 | } | ||
182 | _xblockexpression = InputOutput.<String>println("Solution saved and visualised"); | ||
183 | } | ||
184 | _xifexpression = _xblockexpression; | ||
185 | } | ||
186 | return _xifexpression; | ||
187 | } | ||
188 | } | ||