diff options
Diffstat (limited to 'subprojects/store-dse/src/test/java/tools/refinery/store/dse/TransformationRuleTest.java')
-rw-r--r-- | subprojects/store-dse/src/test/java/tools/refinery/store/dse/TransformationRuleTest.java | 414 |
1 files changed, 0 insertions, 414 deletions
diff --git a/subprojects/store-dse/src/test/java/tools/refinery/store/dse/TransformationRuleTest.java b/subprojects/store-dse/src/test/java/tools/refinery/store/dse/TransformationRuleTest.java deleted file mode 100644 index 43b04e0d..00000000 --- a/subprojects/store-dse/src/test/java/tools/refinery/store/dse/TransformationRuleTest.java +++ /dev/null | |||
@@ -1,414 +0,0 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.dse; | ||
7 | |||
8 | import org.junit.jupiter.api.Test; | ||
9 | // | ||
10 | //import tools.refinery.store.dse.transition.DesignSpaceExplorationAdapter; | ||
11 | //import tools.refinery.store.model.ModelStore; | ||
12 | //import tools.refinery.store.query.ModelQueryAdapter; | ||
13 | //import tools.refinery.store.query.dnf.Query; | ||
14 | //import tools.refinery.store.dse.transition.TransformationRule; | ||
15 | //import tools.refinery.store.query.viatra.ViatraModelQueryAdapter; | ||
16 | //import tools.refinery.store.query.view.AnySymbolView; | ||
17 | //import tools.refinery.store.query.view.KeyOnlyView; | ||
18 | //import tools.refinery.store.representation.Symbol; | ||
19 | //import tools.refinery.store.tuple.Tuple; | ||
20 | // | ||
21 | //import java.util.List; | ||
22 | //import java.util.Map; | ||
23 | // | ||
24 | //import static org.junit.jupiter.api.Assertions.assertEquals; | ||
25 | //import static tools.refinery.store.query.literal.Literals.not; | ||
26 | //import static tools.refinery.store.dse.tests.QueryAssertions.assertResults; | ||
27 | // | ||
28 | class TransformationRuleTest { | ||
29 | // | ||
30 | // private static final Symbol<Boolean> classModel = Symbol.of("ClassModel", 1); | ||
31 | // private static final Symbol<Boolean> classElement = Symbol.of("ClassElement", 1); | ||
32 | // private static final Symbol<Boolean> feature = Symbol.of("Feature", 1); | ||
33 | // | ||
34 | // private static final Symbol<Boolean> isEncapsulatedBy = Symbol.of("IsEncapsulatedBy", 2); | ||
35 | // private static final Symbol<Boolean> encapsulates = Symbol.of("Encapsulates", 2); | ||
36 | // | ||
37 | // private static final Symbol<Boolean> features = Symbol.of("Features", 2); | ||
38 | // private static final Symbol<Boolean> classes = Symbol.of("Classes", 2); | ||
39 | // | ||
40 | // private static final AnySymbolView classModelView = new KeyOnlyView<>(classModel); | ||
41 | // private static final AnySymbolView classElementView = new KeyOnlyView<>(classElement); | ||
42 | // private static final AnySymbolView featureView = new KeyOnlyView<>(feature); | ||
43 | // private static final AnySymbolView isEncapsulatedByView = new KeyOnlyView<>(isEncapsulatedBy); | ||
44 | // private static final AnySymbolView encapsulatesView = new KeyOnlyView<>(encapsulates); | ||
45 | // private static final AnySymbolView featuresView = new KeyOnlyView<>(features); | ||
46 | // private static final AnySymbolView classesView = new KeyOnlyView<>(classes); | ||
47 | // | ||
48 | // @Test | ||
49 | // void activationsTest() { | ||
50 | // var assignFeaturePreconditionHelper = Query.of("AssignFeaturePreconditionHelper", | ||
51 | // (builder, model, c, f) -> builder.clause( | ||
52 | // classElementView.call(c), | ||
53 | // classesView.call(model, c), | ||
54 | // encapsulatesView.call(c, f) | ||
55 | // )); | ||
56 | // | ||
57 | // var assignFeaturePrecondition = Query.of("AssignFeaturePrecondition", (builder, c2, f) | ||
58 | // -> builder.clause((model, c1) -> List.of( | ||
59 | // classModelView.call(model), | ||
60 | // featureView.call(f), | ||
61 | // classElementView.call(c2), | ||
62 | // featuresView.call(model, f), | ||
63 | // classesView.call(model, c1), | ||
64 | // not(assignFeaturePreconditionHelper.call(model, c2, f)), | ||
65 | // not(encapsulatesView.call(c2, f)) | ||
66 | // ))); | ||
67 | // | ||
68 | // var deleteEmptyClassPrecondition = Query.of("DeleteEmptyClassPrecondition", | ||
69 | // (builder, model, c) -> builder.clause((f) -> List.of( | ||
70 | // classModelView.call(model), | ||
71 | // classElementView.call(c), | ||
72 | // featuresView.call(model, f), | ||
73 | // not(encapsulatesView.call(c, f)) | ||
74 | // ))); | ||
75 | // | ||
76 | // TransformationRule assignFeatureRule = new TransformationRule("AssignFeature", | ||
77 | // assignFeaturePrecondition, | ||
78 | // (model) -> { | ||
79 | // var isEncapsulatedByInterpretation = model.getInterpretation(isEncapsulatedBy); | ||
80 | // return ((Tuple activation) -> { | ||
81 | // var feature = activation.get(0); | ||
82 | // var classElement = activation.get(1); | ||
83 | // | ||
84 | // isEncapsulatedByInterpretation.put(Tuple.of(feature, classElement), true); | ||
85 | // }); | ||
86 | // }); | ||
87 | // | ||
88 | // TransformationRule deleteEmptyClassRule = new TransformationRule("DeleteEmptyClass", | ||
89 | // deleteEmptyClassPrecondition, | ||
90 | // (model) -> { | ||
91 | // var classesInterpretation = model.getInterpretation(classes); | ||
92 | // var classElementInterpretation = model.getInterpretation(classElement); | ||
93 | // return ((Tuple activation) -> { | ||
94 | // var modelElement = activation.get(0); | ||
95 | // var classElement = activation.get(1); | ||
96 | // | ||
97 | // classesInterpretation.put(Tuple.of(modelElement, classElement), false); | ||
98 | // classElementInterpretation.put(Tuple.of(classElement), false); | ||
99 | // }); | ||
100 | // }); | ||
101 | // | ||
102 | // | ||
103 | // var store = ModelStore.builder() | ||
104 | // .symbols(classModel, classElement, feature, isEncapsulatedBy, encapsulates, classes, features) | ||
105 | // .with(ViatraModelQueryAdapter.builder() | ||
106 | // .queries(assignFeaturePrecondition, assignFeaturePreconditionHelper, | ||
107 | // deleteEmptyClassPrecondition)) | ||
108 | // .with(DesignSpaceExplorationAdapter.builder() | ||
109 | // .strategy(new DepthFirstStrategy().withDepthLimit(0))) | ||
110 | // .build(); | ||
111 | // | ||
112 | // var model = store.createEmptyModel(); | ||
113 | // var queryEngine = model.getAdapter(ModelQueryAdapter.class); | ||
114 | // assignFeatureRule.prepare(model, queryEngine); | ||
115 | // deleteEmptyClassRule.prepare(model, queryEngine); | ||
116 | // | ||
117 | // var classModelInterpretation = model.getInterpretation(classModel); | ||
118 | // var classElementInterpretation = model.getInterpretation(classElement); | ||
119 | // var featureInterpretation = model.getInterpretation(feature); | ||
120 | // var featuresInterpretation = model.getInterpretation(features); | ||
121 | // var classesInterpretation = model.getInterpretation(classes); | ||
122 | // | ||
123 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
124 | // var newModel = dseAdapter.createObject(); | ||
125 | // var newModelId = newModel.get(0); | ||
126 | // var newClass1 = dseAdapter.createObject(); | ||
127 | // var newClass1Id = newClass1.get(0); | ||
128 | // var newClass2 = dseAdapter.createObject(); | ||
129 | // var newClass2Id = newClass2.get(0); | ||
130 | // var newField = dseAdapter.createObject(); | ||
131 | // var newFieldId = newField.get(0); | ||
132 | // | ||
133 | // classModelInterpretation.put(newModel, true); | ||
134 | // classElementInterpretation.put(newClass1, true); | ||
135 | // classElementInterpretation.put(newClass2, true); | ||
136 | // featureInterpretation.put(newField, true); | ||
137 | // classesInterpretation.put(Tuple.of(newModelId, newClass1Id), true); | ||
138 | // classesInterpretation.put(Tuple.of(newModelId, newClass2Id), true); | ||
139 | // featuresInterpretation.put(Tuple.of(newModelId, newFieldId), true); | ||
140 | // | ||
141 | // queryEngine.flushChanges(); | ||
142 | // | ||
143 | // var assignFeatureRuleActivations = assignFeatureRule.getAllActivationsAsResultSet(); | ||
144 | // var deleteEmptyClassRuleActivations = deleteEmptyClassRule.getAllActivationsAsResultSet(); | ||
145 | // | ||
146 | // assertResults(Map.of( | ||
147 | // Tuple.of(newClass1Id, newFieldId), true, | ||
148 | // Tuple.of(newClass2Id, newFieldId), true | ||
149 | // ), assignFeatureRuleActivations); | ||
150 | // | ||
151 | // assertResults(Map.of( | ||
152 | // Tuple.of(newModelId, newClass1Id), true, | ||
153 | // Tuple.of(newModelId, newClass2Id), true | ||
154 | // ), deleteEmptyClassRuleActivations); | ||
155 | // } | ||
156 | // | ||
157 | // @Test | ||
158 | // void randomActivationTest() { | ||
159 | // var deleteEmptyClassPrecondition = Query.of("DeleteEmptyClassPrecondition", | ||
160 | // (builder, model, c) -> builder.clause((f) -> List.of( | ||
161 | // classModelView.call(model), | ||
162 | // classElementView.call(c), | ||
163 | // featuresView.call(model, f), | ||
164 | // not(encapsulatesView.call(c, f)) | ||
165 | // ))); | ||
166 | // | ||
167 | // TransformationRule deleteEmptyClassRule0 = new TransformationRule("DeleteEmptyClass0", | ||
168 | // deleteEmptyClassPrecondition, | ||
169 | // (model) -> { | ||
170 | // var classesInterpretation = model.getInterpretation(classes); | ||
171 | // var classElementInterpretation = model.getInterpretation(classElement); | ||
172 | // return ((Tuple activation) -> { | ||
173 | // var modelElement = activation.get(0); | ||
174 | // var classElement = activation.get(1); | ||
175 | // | ||
176 | // classesInterpretation.put(Tuple.of(modelElement, classElement), false); | ||
177 | // classElementInterpretation.put(Tuple.of(classElement), false); | ||
178 | // }); | ||
179 | // }, | ||
180 | // 0L); | ||
181 | // | ||
182 | // TransformationRule deleteEmptyClassRule1 = new TransformationRule("DeleteEmptyClass1", | ||
183 | // deleteEmptyClassPrecondition, | ||
184 | // (model) -> { | ||
185 | // var classesInterpretation = model.getInterpretation(classes); | ||
186 | // var classElementInterpretation = model.getInterpretation(classElement); | ||
187 | // return ((Tuple activation) -> { | ||
188 | // var modelElement = activation.get(0); | ||
189 | // var classElement = activation.get(1); | ||
190 | // | ||
191 | // classesInterpretation.put(Tuple.of(modelElement, classElement), false); | ||
192 | // classElementInterpretation.put(Tuple.of(classElement), false); | ||
193 | // }); | ||
194 | // }, | ||
195 | // 78634L); | ||
196 | // | ||
197 | // var store = ModelStore.builder() | ||
198 | // .symbols(classModel, classElement, feature, isEncapsulatedBy, encapsulates, classes, features) | ||
199 | // .with(ViatraModelQueryAdapter.builder() | ||
200 | // .queries(deleteEmptyClassPrecondition)) | ||
201 | // .with(DesignSpaceExplorationAdapter.builder() | ||
202 | // .strategy(new DepthFirstStrategy().withDepthLimit(0))) | ||
203 | // .build(); | ||
204 | // | ||
205 | // var model = store.createEmptyModel(); | ||
206 | // var queryEngine = model.getAdapter(ModelQueryAdapter.class); | ||
207 | // deleteEmptyClassRule0.prepare(model, queryEngine); | ||
208 | // deleteEmptyClassRule1.prepare(model, queryEngine); | ||
209 | // | ||
210 | // var classModelInterpretation = model.getInterpretation(classModel); | ||
211 | // var classElementInterpretation = model.getInterpretation(classElement); | ||
212 | // var featureInterpretation = model.getInterpretation(feature); | ||
213 | // var featuresInterpretation = model.getInterpretation(features); | ||
214 | // var classesInterpretation = model.getInterpretation(classes); | ||
215 | // | ||
216 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
217 | // var newModel = dseAdapter.createObject(); | ||
218 | // var newModelId = newModel.get(0); | ||
219 | // var newClass1 = dseAdapter.createObject(); | ||
220 | // var newClass1Id = newClass1.get(0); | ||
221 | // var newClass2 = dseAdapter.createObject(); | ||
222 | // var newClass2Id = newClass2.get(0); | ||
223 | // var newField = dseAdapter.createObject(); | ||
224 | // var newFieldId = newField.get(0); | ||
225 | // | ||
226 | // classModelInterpretation.put(newModel, true); | ||
227 | // classElementInterpretation.put(newClass1, true); | ||
228 | // classElementInterpretation.put(newClass2, true); | ||
229 | // featureInterpretation.put(newField, true); | ||
230 | // classesInterpretation.put(Tuple.of(newModelId, newClass1Id), true); | ||
231 | // classesInterpretation.put(Tuple.of(newModelId, newClass2Id), true); | ||
232 | // featuresInterpretation.put(Tuple.of(newModelId, newFieldId), true); | ||
233 | // | ||
234 | // queryEngine.flushChanges(); | ||
235 | // | ||
236 | // | ||
237 | // var activation0 = deleteEmptyClassRule0.getRandomActivation().activation(); | ||
238 | // var activation1 = deleteEmptyClassRule1.getRandomActivation().activation(); | ||
239 | // | ||
240 | // assertResults(Map.of( | ||
241 | // Tuple.of(newModelId, newClass1Id), true, | ||
242 | // Tuple.of(newModelId, newClass2Id), true | ||
243 | // ), deleteEmptyClassRule0.getAllActivationsAsResultSet()); | ||
244 | // | ||
245 | // assertResults(Map.of( | ||
246 | // Tuple.of(newModelId, newClass1Id), true, | ||
247 | // Tuple.of(newModelId, newClass2Id), true | ||
248 | // ), deleteEmptyClassRule1.getAllActivationsAsResultSet()); | ||
249 | // | ||
250 | // assertEquals(Tuple.of(newModelId, newClass2Id), activation0); | ||
251 | // assertEquals(Tuple.of(newModelId, newClass1Id), activation1); | ||
252 | // | ||
253 | // } | ||
254 | // | ||
255 | // @Test | ||
256 | // void fireTest() { | ||
257 | // var deleteEmptyClassPrecondition = Query.of("DeleteEmptyClassPrecondition", | ||
258 | // (builder, model, c) -> builder.clause((f) -> List.of( | ||
259 | // classModelView.call(model), | ||
260 | // classElementView.call(c), | ||
261 | // featuresView.call(model, f), | ||
262 | // not(encapsulatesView.call(c, f)) | ||
263 | // ))); | ||
264 | // | ||
265 | // TransformationRule deleteEmptyClassRule = new TransformationRule("DeleteEmptyClass", | ||
266 | // deleteEmptyClassPrecondition, | ||
267 | // (model) -> { | ||
268 | // var classesInterpretation = model.getInterpretation(classes); | ||
269 | // var classElementInterpretation = model.getInterpretation(classElement); | ||
270 | // return ((Tuple activation) -> { | ||
271 | // var modelElement = activation.get(0); | ||
272 | // var classElement = activation.get(1); | ||
273 | // | ||
274 | // classesInterpretation.put(Tuple.of(modelElement, classElement), false); | ||
275 | // classElementInterpretation.put(Tuple.of(classElement), false); | ||
276 | // }); | ||
277 | // }); | ||
278 | // | ||
279 | // var store = ModelStore.builder() | ||
280 | // .symbols(classModel, classElement, feature, isEncapsulatedBy, encapsulates, classes, features) | ||
281 | // .with(ViatraModelQueryAdapter.builder() | ||
282 | // .queries(deleteEmptyClassPrecondition)) | ||
283 | // .with(DesignSpaceExplorationAdapter.builder() | ||
284 | // .strategy(new DepthFirstStrategy().withDepthLimit(0))) | ||
285 | // .build(); | ||
286 | // | ||
287 | // var model = store.createEmptyModel(); | ||
288 | // var queryEngine = model.getAdapter(ModelQueryAdapter.class); | ||
289 | // deleteEmptyClassRule.prepare(model, queryEngine); | ||
290 | // | ||
291 | // var classModelInterpretation = model.getInterpretation(classModel); | ||
292 | // var classElementInterpretation = model.getInterpretation(classElement); | ||
293 | // var featureInterpretation = model.getInterpretation(feature); | ||
294 | // var featuresInterpretation = model.getInterpretation(features); | ||
295 | // var classesInterpretation = model.getInterpretation(classes); | ||
296 | // | ||
297 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
298 | // var newModel = dseAdapter.createObject(); | ||
299 | // var newModelId = newModel.get(0); | ||
300 | // var newClass1 = dseAdapter.createObject(); | ||
301 | // var newClass1Id = newClass1.get(0); | ||
302 | // var newClass2 = dseAdapter.createObject(); | ||
303 | // var newClass2Id = newClass2.get(0); | ||
304 | // var newField = dseAdapter.createObject(); | ||
305 | // var newFieldId = newField.get(0); | ||
306 | // | ||
307 | // classModelInterpretation.put(newModel, true); | ||
308 | // classElementInterpretation.put(newClass1, true); | ||
309 | // classElementInterpretation.put(newClass2, true); | ||
310 | // featureInterpretation.put(newField, true); | ||
311 | // classesInterpretation.put(Tuple.of(newModelId, newClass1Id), true); | ||
312 | // classesInterpretation.put(Tuple.of(newModelId, newClass2Id), true); | ||
313 | // featuresInterpretation.put(Tuple.of(newModelId, newFieldId), true); | ||
314 | // | ||
315 | // queryEngine.flushChanges(); | ||
316 | // | ||
317 | // assertResults(Map.of( | ||
318 | // Tuple.of(newModelId, newClass1Id), true, | ||
319 | // Tuple.of(newModelId, newClass2Id), true | ||
320 | // ), deleteEmptyClassRule.getAllActivationsAsResultSet()); | ||
321 | // | ||
322 | // | ||
323 | // deleteEmptyClassRule.fireActivation(Tuple.of(0, 1)); | ||
324 | // | ||
325 | // assertResults(Map.of( | ||
326 | // Tuple.of(newModelId, newClass1Id), false, | ||
327 | // Tuple.of(newModelId, newClass2Id), true | ||
328 | // ), deleteEmptyClassRule.getAllActivationsAsResultSet()); | ||
329 | // } | ||
330 | // | ||
331 | // @Test | ||
332 | // void randomFireTest() { | ||
333 | // var deleteEmptyClassPrecondition = Query.of("DeleteEmptyClassPrecondition", | ||
334 | // (builder, model, c) -> builder.clause((f) -> List.of( | ||
335 | // classModelView.call(model), | ||
336 | // classElementView.call(c), | ||
337 | // featuresView.call(model, f), | ||
338 | // not(encapsulatesView.call(c, f)) | ||
339 | // ))); | ||
340 | // | ||
341 | // TransformationRule deleteEmptyClassRule = new TransformationRule("DeleteEmptyClass0", | ||
342 | // deleteEmptyClassPrecondition, | ||
343 | // (model) -> { | ||
344 | // var classesInterpretation = model.getInterpretation(classes); | ||
345 | // var classElementInterpretation = model.getInterpretation(classElement); | ||
346 | // return ((Tuple activation) -> { | ||
347 | // var modelElement = activation.get(0); | ||
348 | // var classElement = activation.get(1); | ||
349 | // | ||
350 | // classesInterpretation.put(Tuple.of(modelElement, classElement), false); | ||
351 | // classElementInterpretation.put(Tuple.of(classElement), false); | ||
352 | // }); | ||
353 | // }, | ||
354 | // 0L); | ||
355 | // | ||
356 | // var store = ModelStore.builder() | ||
357 | // .symbols(classModel, classElement, feature, isEncapsulatedBy, encapsulates, classes, features) | ||
358 | // .with(ViatraModelQueryAdapter.builder() | ||
359 | // .queries(deleteEmptyClassPrecondition)) | ||
360 | // .with(DesignSpaceExplorationAdapter.builder() | ||
361 | // .strategy(new DepthFirstStrategy().withDepthLimit(0))) | ||
362 | // .build(); | ||
363 | // | ||
364 | // var model = store.createEmptyModel(); | ||
365 | // var queryEngine = model.getAdapter(ModelQueryAdapter.class); | ||
366 | // deleteEmptyClassRule.prepare(model, queryEngine); | ||
367 | // | ||
368 | // var classModelInterpretation = model.getInterpretation(classModel); | ||
369 | // var classElementInterpretation = model.getInterpretation(classElement); | ||
370 | // var featureInterpretation = model.getInterpretation(feature); | ||
371 | // var featuresInterpretation = model.getInterpretation(features); | ||
372 | // var classesInterpretation = model.getInterpretation(classes); | ||
373 | // | ||
374 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
375 | // var newModel = dseAdapter.createObject(); | ||
376 | // var newModelId = newModel.get(0); | ||
377 | // var newClass1 = dseAdapter.createObject(); | ||
378 | // var newClass1Id = newClass1.get(0); | ||
379 | // var newClass2 = dseAdapter.createObject(); | ||
380 | // var newClass2Id = newClass2.get(0); | ||
381 | // var newField = dseAdapter.createObject(); | ||
382 | // var newFieldId = newField.get(0); | ||
383 | // | ||
384 | // classModelInterpretation.put(newModel, true); | ||
385 | // classElementInterpretation.put(newClass1, true); | ||
386 | // classElementInterpretation.put(newClass2, true); | ||
387 | // featureInterpretation.put(newField, true); | ||
388 | // classesInterpretation.put(Tuple.of(newModelId, newClass1Id), true); | ||
389 | // classesInterpretation.put(Tuple.of(newModelId, newClass2Id), true); | ||
390 | // featuresInterpretation.put(Tuple.of(newModelId, newFieldId), true); | ||
391 | // | ||
392 | // queryEngine.flushChanges(); | ||
393 | // | ||
394 | // assertResults(Map.of( | ||
395 | // Tuple.of(newModelId, newClass1Id), true, | ||
396 | // Tuple.of(newModelId, newClass2Id), true | ||
397 | // ), deleteEmptyClassRule.getAllActivationsAsResultSet()); | ||
398 | // | ||
399 | // deleteEmptyClassRule.fireRandomActivation(); | ||
400 | // | ||
401 | // assertResults(Map.of( | ||
402 | // Tuple.of(newModelId, newClass1Id), true, | ||
403 | // Tuple.of(newModelId, newClass2Id), false | ||
404 | // ), deleteEmptyClassRule.getAllActivationsAsResultSet()); | ||
405 | // | ||
406 | // deleteEmptyClassRule.fireRandomActivation(); | ||
407 | // | ||
408 | // assertResults(Map.of( | ||
409 | // Tuple.of(newModelId, newClass1Id), false, | ||
410 | // Tuple.of(newModelId, newClass2Id), false | ||
411 | // ), deleteEmptyClassRule.getAllActivationsAsResultSet()); | ||
412 | // | ||
413 | // } | ||
414 | } | ||