diff options
Diffstat (limited to 'subprojects/store-dse/src/test/java/tools/refinery/store/dse/DesignSpaceExplorationTest.java')
-rw-r--r-- | subprojects/store-dse/src/test/java/tools/refinery/store/dse/DesignSpaceExplorationTest.java | 607 |
1 files changed, 0 insertions, 607 deletions
diff --git a/subprojects/store-dse/src/test/java/tools/refinery/store/dse/DesignSpaceExplorationTest.java b/subprojects/store-dse/src/test/java/tools/refinery/store/dse/DesignSpaceExplorationTest.java deleted file mode 100644 index 91e33f4a..00000000 --- a/subprojects/store-dse/src/test/java/tools/refinery/store/dse/DesignSpaceExplorationTest.java +++ /dev/null | |||
@@ -1,607 +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 | import tools.refinery.store.model.ModelStore; | ||
10 | import tools.refinery.store.query.ModelQueryAdapter; | ||
11 | import tools.refinery.store.query.dnf.Query; | ||
12 | import tools.refinery.store.dse.internal.TransformationRule; | ||
13 | import tools.refinery.store.dse.strategy.BestFirstStrategy; | ||
14 | import tools.refinery.store.dse.strategy.DepthFirstStrategy; | ||
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 static org.junit.jupiter.api.Assertions.assertEquals; | ||
22 | |||
23 | class DesignSpaceExplorationTest { | ||
24 | // private static final Symbol<Boolean> namedElement = Symbol.of("NamedElement", 1); | ||
25 | // private static final Symbol<Boolean> attribute = Symbol.of("Attribute", 1); | ||
26 | // private static final Symbol<Boolean> method = Symbol.of("Method", 1); | ||
27 | // private static final Symbol<Boolean> dataDependency = Symbol.of("DataDependency", 2); | ||
28 | // private static final Symbol<Boolean> functionalDependency = Symbol.of("FunctionalDependency", 2); | ||
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 createObjectTest() { | ||
50 | var store = ModelStore.builder() | ||
51 | .with(ViatraModelQueryAdapter.builder()) | ||
52 | .with(DesignSpaceExplorationAdapter.builder() | ||
53 | .strategy(new DepthFirstStrategy().withDepthLimit(0))) | ||
54 | .build(); | ||
55 | |||
56 | var model = store.createEmptyModel(); | ||
57 | var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
58 | |||
59 | assertEquals(0, dseAdapter.getModelSize()); | ||
60 | |||
61 | var newModel = dseAdapter.createObject(); | ||
62 | var newModelId = newModel.get(0); | ||
63 | var newClass1 = dseAdapter.createObject(); | ||
64 | var newClass1Id = newClass1.get(0); | ||
65 | var newClass2 = dseAdapter.createObject(); | ||
66 | var newClass2Id = newClass2.get(0); | ||
67 | var newField = dseAdapter.createObject(); | ||
68 | var newFieldId = newField.get(0); | ||
69 | |||
70 | assertEquals(0, newModelId); | ||
71 | assertEquals(1, newClass1Id); | ||
72 | assertEquals(2, newClass2Id); | ||
73 | assertEquals(3, newFieldId); | ||
74 | assertEquals(4, dseAdapter.getModelSize()); | ||
75 | } | ||
76 | |||
77 | @Test | ||
78 | void deleteMiddleObjectTest() { | ||
79 | var store = ModelStore.builder() | ||
80 | .with(ViatraModelQueryAdapter.builder()) | ||
81 | .with(DesignSpaceExplorationAdapter.builder() | ||
82 | .strategy(new DepthFirstStrategy())) | ||
83 | .build(); | ||
84 | |||
85 | var model = store.createEmptyModel(); | ||
86 | var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
87 | |||
88 | assertEquals(0, dseAdapter.getModelSize()); | ||
89 | |||
90 | var newObject0 = dseAdapter.createObject(); | ||
91 | var newObject0Id = newObject0.get(0); | ||
92 | var newObject1 = dseAdapter.createObject(); | ||
93 | var newObject1Id = newObject1.get(0); | ||
94 | var newObject2 = dseAdapter.createObject(); | ||
95 | var newObject2Id = newObject2.get(0); | ||
96 | var newObject3 = dseAdapter.createObject(); | ||
97 | var newObject3Id = newObject3.get(0); | ||
98 | |||
99 | assertEquals(0, newObject0Id); | ||
100 | assertEquals(1, newObject1Id); | ||
101 | assertEquals(2, newObject2Id); | ||
102 | assertEquals(3, newObject3Id); | ||
103 | assertEquals(4, dseAdapter.getModelSize()); | ||
104 | |||
105 | dseAdapter.deleteObject(newObject1); | ||
106 | assertEquals(4, dseAdapter.getModelSize()); | ||
107 | |||
108 | var newObject4 = dseAdapter.createObject(); | ||
109 | var newObject4Id = newObject4.get(0); | ||
110 | assertEquals(4, newObject4Id); | ||
111 | assertEquals(5, dseAdapter.getModelSize()); | ||
112 | |||
113 | dseAdapter.deleteObject(newObject4); | ||
114 | assertEquals(5, dseAdapter.getModelSize()); | ||
115 | } | ||
116 | |||
117 | @Test | ||
118 | void DFSTrivialTest() { | ||
119 | var store = ModelStore.builder() | ||
120 | .symbols(classModel) | ||
121 | .with(ViatraModelQueryAdapter.builder()) | ||
122 | .with(DesignSpaceExplorationAdapter.builder() | ||
123 | .strategy(new DepthFirstStrategy().withDepthLimit(0))) | ||
124 | .build(); | ||
125 | |||
126 | var model = store.createEmptyModel(); | ||
127 | var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
128 | |||
129 | var states = dseAdapter.explore(); | ||
130 | assertEquals(1, states.size()); | ||
131 | } | ||
132 | |||
133 | @Test | ||
134 | void DFSOneRuleTest() { | ||
135 | var createClassPrecondition = Query.of("CreateClassPrecondition", | ||
136 | (builder, model) -> builder.clause( | ||
137 | classModelView.call(model) | ||
138 | )); | ||
139 | |||
140 | var createClassRule = new TransformationRule("CreateClass", | ||
141 | createClassPrecondition, | ||
142 | (model) -> { | ||
143 | var classesInterpretation = model.getInterpretation(classes); | ||
144 | var classElementInterpretation = model.getInterpretation(classElement); | ||
145 | return ((Tuple activation) -> { | ||
146 | var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
147 | var modelElement = activation.get(0); | ||
148 | |||
149 | var newClassElement = dseAdapter.createObject(); | ||
150 | var newClassElementId = newClassElement.get(0); | ||
151 | |||
152 | classesInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
153 | classElementInterpretation.put(Tuple.of(newClassElementId), true); | ||
154 | }); | ||
155 | }); | ||
156 | |||
157 | var store = ModelStore.builder() | ||
158 | .symbols(classModel, classElement, classes) | ||
159 | .with(ViatraModelQueryAdapter.builder() | ||
160 | .queries(createClassPrecondition)) | ||
161 | .with(DesignSpaceExplorationAdapter.builder() | ||
162 | .transformations(createClassRule) | ||
163 | .strategy(new DepthFirstStrategy().withDepthLimit(0) | ||
164 | )) | ||
165 | .build(); | ||
166 | |||
167 | var model = store.createEmptyModel(); | ||
168 | var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
169 | var queryEngine = model.getAdapter(ModelQueryAdapter.class); | ||
170 | |||
171 | var modelElementInterpretation = model.getInterpretation(classModel); | ||
172 | modelElementInterpretation.put(dseAdapter.createObject(), true); | ||
173 | queryEngine.flushChanges(); | ||
174 | |||
175 | var states = dseAdapter.explore(); | ||
176 | assertEquals(1, states.size()); | ||
177 | } | ||
178 | |||
179 | @Test | ||
180 | void DFSContinueTest() { | ||
181 | var createClassPrecondition = Query.of("CreateClassPrecondition", | ||
182 | (builder, model) -> builder.clause( | ||
183 | classModelView.call(model) | ||
184 | )); | ||
185 | |||
186 | var createClassRule = new TransformationRule("CreateClass", | ||
187 | createClassPrecondition, | ||
188 | (model) -> { | ||
189 | var classesInterpretation = model.getInterpretation(classes); | ||
190 | var classElementInterpretation = model.getInterpretation(classElement); | ||
191 | return ((Tuple activation) -> { | ||
192 | var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
193 | var modelElement = activation.get(0); | ||
194 | |||
195 | var newClassElement = dseAdapter.createObject(); | ||
196 | var newClassElementId = newClassElement.get(0); | ||
197 | |||
198 | classesInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
199 | classElementInterpretation.put(Tuple.of(newClassElementId), true); | ||
200 | }); | ||
201 | }); | ||
202 | |||
203 | var store = ModelStore.builder() | ||
204 | .symbols(classModel, classElement, classes) | ||
205 | .with(ViatraModelQueryAdapter.builder() | ||
206 | .queries(createClassPrecondition)) | ||
207 | .with(DesignSpaceExplorationAdapter.builder() | ||
208 | .transformations(createClassRule) | ||
209 | .strategy(new DepthFirstStrategy().withDepthLimit(4).continueIfHardObjectivesFulfilled() | ||
210 | )) | ||
211 | .build(); | ||
212 | |||
213 | var model = store.createEmptyModel(); | ||
214 | var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
215 | var queryEngine = model.getAdapter(ModelQueryAdapter.class); | ||
216 | |||
217 | var modelElementInterpretation = model.getInterpretation(classModel); | ||
218 | modelElementInterpretation.put(dseAdapter.createObject(), true); | ||
219 | queryEngine.flushChanges(); | ||
220 | |||
221 | var states = dseAdapter.explore(); | ||
222 | assertEquals(5, states.size()); | ||
223 | } | ||
224 | |||
225 | @Test | ||
226 | void DFSCompletenessTest() { | ||
227 | var createClassPrecondition = Query.of("CreateClassPrecondition", | ||
228 | (builder, model) -> builder.clause( | ||
229 | classModelView.call(model) | ||
230 | )); | ||
231 | |||
232 | var createClassRule = new TransformationRule("CreateClass", | ||
233 | createClassPrecondition, | ||
234 | (model) -> { | ||
235 | var classesInterpretation = model.getInterpretation(classes); | ||
236 | var classElementInterpretation = model.getInterpretation(classElement); | ||
237 | return ((Tuple activation) -> { | ||
238 | var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
239 | var modelElement = activation.get(0); | ||
240 | |||
241 | var newClassElement = dseAdapter.createObject(); | ||
242 | var newClassElementId = newClassElement.get(0); | ||
243 | |||
244 | classesInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
245 | classElementInterpretation.put(Tuple.of(newClassElementId), true); | ||
246 | }); | ||
247 | }); | ||
248 | |||
249 | var createFeaturePrecondition = Query.of("CreateFeaturePrecondition", | ||
250 | (builder, model) -> builder.clause( | ||
251 | classModelView.call(model) | ||
252 | )); | ||
253 | |||
254 | var createFeatureRule = new TransformationRule("CreateFeature", | ||
255 | createFeaturePrecondition, | ||
256 | (model) -> { | ||
257 | var featuresInterpretation = model.getInterpretation(features); | ||
258 | var featureInterpretation = model.getInterpretation(feature); | ||
259 | return ((Tuple activation) -> { | ||
260 | var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
261 | var modelElement = activation.get(0); | ||
262 | |||
263 | var newClassElement = dseAdapter.createObject(); | ||
264 | var newClassElementId = newClassElement.get(0); | ||
265 | |||
266 | featuresInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
267 | featureInterpretation.put(Tuple.of(newClassElementId), true); | ||
268 | }); | ||
269 | }); | ||
270 | |||
271 | var store = ModelStore.builder() | ||
272 | .symbols(classModel, classElement, classes, feature, features, isEncapsulatedBy, encapsulates) | ||
273 | .with(ViatraModelQueryAdapter.builder() | ||
274 | .queries(createClassPrecondition, createFeaturePrecondition)) | ||
275 | .with(DesignSpaceExplorationAdapter.builder() | ||
276 | .transformations(createClassRule, createFeatureRule) | ||
277 | .strategy(new DepthFirstStrategy().withDepthLimit(10).continueIfHardObjectivesFulfilled() | ||
278 | )) | ||
279 | .build(); | ||
280 | |||
281 | var model = store.createEmptyModel(); | ||
282 | var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
283 | var queryEngine = model.getAdapter(ModelQueryAdapter.class); | ||
284 | |||
285 | var modelElementInterpretation = model.getInterpretation(classModel); | ||
286 | modelElementInterpretation.put(dseAdapter.createObject(), true); | ||
287 | queryEngine.flushChanges(); | ||
288 | |||
289 | var states = dseAdapter.explore(); | ||
290 | assertEquals(2047, states.size()); | ||
291 | } | ||
292 | |||
293 | @Test | ||
294 | void DFSSolutionLimitTest() { | ||
295 | var createClassPrecondition = Query.of("CreateClassPrecondition", | ||
296 | (builder, model) -> builder.clause( | ||
297 | classModelView.call(model) | ||
298 | )); | ||
299 | |||
300 | var createClassRule = new TransformationRule("CreateClass", | ||
301 | createClassPrecondition, | ||
302 | (model) -> { | ||
303 | var classesInterpretation = model.getInterpretation(classes); | ||
304 | var classElementInterpretation = model.getInterpretation(classElement); | ||
305 | return ((Tuple activation) -> { | ||
306 | var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
307 | var modelElement = activation.get(0); | ||
308 | |||
309 | var newClassElement = dseAdapter.createObject(); | ||
310 | var newClassElementId = newClassElement.get(0); | ||
311 | |||
312 | classesInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
313 | classElementInterpretation.put(Tuple.of(newClassElementId), true); | ||
314 | }); | ||
315 | }); | ||
316 | |||
317 | var createFeaturePrecondition = Query.of("CreateFeaturePrecondition", | ||
318 | (builder, model) -> builder.clause( | ||
319 | classModelView.call(model) | ||
320 | )); | ||
321 | |||
322 | var createFeatureRule = new TransformationRule("CreateFeature", | ||
323 | createFeaturePrecondition, | ||
324 | (model) -> { | ||
325 | var featuresInterpretation = model.getInterpretation(features); | ||
326 | var featureInterpretation = model.getInterpretation(feature); | ||
327 | return ((Tuple activation) -> { | ||
328 | var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
329 | var modelElement = activation.get(0); | ||
330 | |||
331 | var newClassElement = dseAdapter.createObject(); | ||
332 | var newClassElementId = newClassElement.get(0); | ||
333 | |||
334 | featuresInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
335 | featureInterpretation.put(Tuple.of(newClassElementId), true); | ||
336 | }); | ||
337 | }); | ||
338 | |||
339 | var store = ModelStore.builder() | ||
340 | .symbols(classModel, classElement, classes, feature, features, isEncapsulatedBy, encapsulates) | ||
341 | .with(ViatraModelQueryAdapter.builder() | ||
342 | .queries(createClassPrecondition, createFeaturePrecondition)) | ||
343 | .with(DesignSpaceExplorationAdapter.builder() | ||
344 | .transformations(createClassRule, createFeatureRule) | ||
345 | .strategy(new DepthFirstStrategy().withSolutionLimit(222) | ||
346 | .continueIfHardObjectivesFulfilled() | ||
347 | )) | ||
348 | .build(); | ||
349 | |||
350 | var model = store.createEmptyModel(); | ||
351 | var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
352 | var queryEngine = model.getAdapter(ModelQueryAdapter.class); | ||
353 | |||
354 | var modelElementInterpretation = model.getInterpretation(classModel); | ||
355 | modelElementInterpretation.put(dseAdapter.createObject(), true); | ||
356 | queryEngine.flushChanges(); | ||
357 | |||
358 | var states = dseAdapter.explore(); | ||
359 | assertEquals(222, states.size()); | ||
360 | } | ||
361 | |||
362 | @Test | ||
363 | void BeFSTrivialTest() { | ||
364 | var store = ModelStore.builder() | ||
365 | .symbols(classModel) | ||
366 | .with(ViatraModelQueryAdapter.builder()) | ||
367 | .with(DesignSpaceExplorationAdapter.builder() | ||
368 | .strategy(new BestFirstStrategy().withDepthLimit(0))) | ||
369 | .build(); | ||
370 | |||
371 | var model = store.createEmptyModel(); | ||
372 | var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
373 | |||
374 | var states = dseAdapter.explore(); | ||
375 | assertEquals(1, states.size()); | ||
376 | } | ||
377 | |||
378 | @Test | ||
379 | void BeFSOneRuleTest() { | ||
380 | var createClassPrecondition = Query.of("CreateClassPrecondition", | ||
381 | (builder, model) -> builder.clause( | ||
382 | classModelView.call(model) | ||
383 | )); | ||
384 | |||
385 | var createClassRule = new TransformationRule("CreateClass", | ||
386 | createClassPrecondition, | ||
387 | (model) -> { | ||
388 | var classesInterpretation = model.getInterpretation(classes); | ||
389 | var classElementInterpretation = model.getInterpretation(classElement); | ||
390 | return ((Tuple activation) -> { | ||
391 | var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
392 | var modelElement = activation.get(0); | ||
393 | |||
394 | var newClassElement = dseAdapter.createObject(); | ||
395 | var newClassElementId = newClassElement.get(0); | ||
396 | |||
397 | classesInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
398 | classElementInterpretation.put(Tuple.of(newClassElementId), true); | ||
399 | }); | ||
400 | }); | ||
401 | |||
402 | var store = ModelStore.builder() | ||
403 | .symbols(classModel, classElement, classes) | ||
404 | .with(ViatraModelQueryAdapter.builder() | ||
405 | .queries(createClassPrecondition)) | ||
406 | .with(DesignSpaceExplorationAdapter.builder() | ||
407 | .transformations(createClassRule) | ||
408 | .strategy(new BestFirstStrategy().withDepthLimit(4) | ||
409 | )) | ||
410 | .build(); | ||
411 | |||
412 | var model = store.createEmptyModel(); | ||
413 | var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
414 | var queryEngine = model.getAdapter(ModelQueryAdapter.class); | ||
415 | |||
416 | var modelElementInterpretation = model.getInterpretation(classModel); | ||
417 | modelElementInterpretation.put(dseAdapter.createObject(), true); | ||
418 | queryEngine.flushChanges(); | ||
419 | |||
420 | var states = dseAdapter.explore(); | ||
421 | assertEquals(1, states.size()); | ||
422 | } | ||
423 | |||
424 | @Test | ||
425 | void BeFSContinueTest() { | ||
426 | var createClassPrecondition = Query.of("CreateClassPrecondition", | ||
427 | (builder, model) -> builder.clause( | ||
428 | classModelView.call(model) | ||
429 | )); | ||
430 | |||
431 | var createClassRule = new TransformationRule("CreateClass", | ||
432 | createClassPrecondition, | ||
433 | (model) -> { | ||
434 | var classesInterpretation = model.getInterpretation(classes); | ||
435 | var classElementInterpretation = model.getInterpretation(classElement); | ||
436 | return ((Tuple activation) -> { | ||
437 | var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
438 | var modelElement = activation.get(0); | ||
439 | |||
440 | var newClassElement = dseAdapter.createObject(); | ||
441 | var newClassElementId = newClassElement.get(0); | ||
442 | |||
443 | classesInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
444 | classElementInterpretation.put(Tuple.of(newClassElementId), true); | ||
445 | }); | ||
446 | }); | ||
447 | |||
448 | var store = ModelStore.builder() | ||
449 | .symbols(classModel, classElement, classes) | ||
450 | .with(ViatraModelQueryAdapter.builder() | ||
451 | .queries(createClassPrecondition)) | ||
452 | .with(DesignSpaceExplorationAdapter.builder() | ||
453 | .transformations(createClassRule) | ||
454 | .strategy(new BestFirstStrategy().withDepthLimit(4).continueIfHardObjectivesFulfilled() | ||
455 | )) | ||
456 | .build(); | ||
457 | |||
458 | var model = store.createEmptyModel(); | ||
459 | var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
460 | var queryEngine = model.getAdapter(ModelQueryAdapter.class); | ||
461 | |||
462 | var modelElementInterpretation = model.getInterpretation(classModel); | ||
463 | modelElementInterpretation.put(dseAdapter.createObject(), true); | ||
464 | queryEngine.flushChanges(); | ||
465 | |||
466 | var states = dseAdapter.explore(); | ||
467 | assertEquals(5, states.size()); | ||
468 | } | ||
469 | |||
470 | @Test | ||
471 | void BeFSCompletenessTest() { | ||
472 | var createClassPrecondition = Query.of("CreateClassPrecondition", | ||
473 | (builder, model) -> builder.clause( | ||
474 | classModelView.call(model) | ||
475 | )); | ||
476 | |||
477 | var createClassRule = new TransformationRule("CreateClass", | ||
478 | createClassPrecondition, | ||
479 | (model) -> { | ||
480 | var classesInterpretation = model.getInterpretation(classes); | ||
481 | var classElementInterpretation = model.getInterpretation(classElement); | ||
482 | return ((Tuple activation) -> { | ||
483 | var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
484 | var modelElement = activation.get(0); | ||
485 | |||
486 | var newClassElement = dseAdapter.createObject(); | ||
487 | var newClassElementId = newClassElement.get(0); | ||
488 | |||
489 | classesInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
490 | classElementInterpretation.put(Tuple.of(newClassElementId), true); | ||
491 | }); | ||
492 | }); | ||
493 | |||
494 | var createFeaturePrecondition = Query.of("CreateFeaturePrecondition", | ||
495 | (builder, model) -> builder.clause( | ||
496 | classModelView.call(model) | ||
497 | )); | ||
498 | |||
499 | var createFeatureRule = new TransformationRule("CreateFeature", | ||
500 | createFeaturePrecondition, | ||
501 | (model) -> { | ||
502 | var featuresInterpretation = model.getInterpretation(features); | ||
503 | var featureInterpretation = model.getInterpretation(feature); | ||
504 | return ((Tuple activation) -> { | ||
505 | var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
506 | var modelElement = activation.get(0); | ||
507 | |||
508 | var newClassElement = dseAdapter.createObject(); | ||
509 | var newClassElementId = newClassElement.get(0); | ||
510 | |||
511 | featuresInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
512 | featureInterpretation.put(Tuple.of(newClassElementId), true); | ||
513 | }); | ||
514 | }); | ||
515 | |||
516 | var store = ModelStore.builder() | ||
517 | .symbols(classModel, classElement, classes, feature, features, isEncapsulatedBy, encapsulates) | ||
518 | .with(ViatraModelQueryAdapter.builder() | ||
519 | .queries(createClassPrecondition, createFeaturePrecondition)) | ||
520 | .with(DesignSpaceExplorationAdapter.builder() | ||
521 | .transformations(createClassRule, createFeatureRule) | ||
522 | .strategy(new BestFirstStrategy().withDepthLimit(10).continueIfHardObjectivesFulfilled() | ||
523 | )) | ||
524 | .build(); | ||
525 | |||
526 | var model = store.createEmptyModel(); | ||
527 | var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
528 | var queryEngine = model.getAdapter(ModelQueryAdapter.class); | ||
529 | |||
530 | var modelElementInterpretation = model.getInterpretation(classModel); | ||
531 | modelElementInterpretation.put(dseAdapter.createObject(), true); | ||
532 | queryEngine.flushChanges(); | ||
533 | |||
534 | var states = dseAdapter.explore(); | ||
535 | assertEquals(2047, states.size()); | ||
536 | } | ||
537 | |||
538 | @Test | ||
539 | void BeFSSolutionLimitTest() { | ||
540 | var createClassPrecondition = Query.of("CreateClassPrecondition", | ||
541 | (builder, model) -> builder.clause( | ||
542 | classModelView.call(model) | ||
543 | )); | ||
544 | |||
545 | var createClassRule = new TransformationRule("CreateClass", | ||
546 | createClassPrecondition, | ||
547 | (model) -> { | ||
548 | var classesInterpretation = model.getInterpretation(classes); | ||
549 | var classElementInterpretation = model.getInterpretation(classElement); | ||
550 | return ((Tuple activation) -> { | ||
551 | var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
552 | var modelElement = activation.get(0); | ||
553 | |||
554 | var newClassElement = dseAdapter.createObject(); | ||
555 | var newClassElementId = newClassElement.get(0); | ||
556 | |||
557 | classesInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
558 | classElementInterpretation.put(Tuple.of(newClassElementId), true); | ||
559 | }); | ||
560 | }); | ||
561 | |||
562 | var createFeaturePrecondition = Query.of("CreateFeaturePrecondition", | ||
563 | (builder, model) -> builder.clause( | ||
564 | classModelView.call(model) | ||
565 | )); | ||
566 | |||
567 | var createFeatureRule = new TransformationRule("CreateFeature", | ||
568 | createFeaturePrecondition, | ||
569 | (model) -> { | ||
570 | var featuresInterpretation = model.getInterpretation(features); | ||
571 | var featureInterpretation = model.getInterpretation(feature); | ||
572 | return ((Tuple activation) -> { | ||
573 | var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
574 | var modelElement = activation.get(0); | ||
575 | |||
576 | var newClassElement = dseAdapter.createObject(); | ||
577 | var newClassElementId = newClassElement.get(0); | ||
578 | |||
579 | featuresInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
580 | featureInterpretation.put(Tuple.of(newClassElementId), true); | ||
581 | }); | ||
582 | }); | ||
583 | |||
584 | var store = ModelStore.builder() | ||
585 | .symbols(classModel, classElement, classes, feature, features, isEncapsulatedBy, encapsulates) | ||
586 | .with(ViatraModelQueryAdapter.builder() | ||
587 | .queries(createClassPrecondition, createFeaturePrecondition)) | ||
588 | .with(DesignSpaceExplorationAdapter.builder() | ||
589 | .transformations(createClassRule, createFeatureRule) | ||
590 | .strategy(new BestFirstStrategy().withSolutionLimit(222) | ||
591 | .continueIfHardObjectivesFulfilled() | ||
592 | )) | ||
593 | .build(); | ||
594 | |||
595 | var model = store.createEmptyModel(); | ||
596 | var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
597 | var queryEngine = model.getAdapter(ModelQueryAdapter.class); | ||
598 | |||
599 | var modelElementInterpretation = model.getInterpretation(classModel); | ||
600 | modelElementInterpretation.put(dseAdapter.createObject(), true); | ||
601 | queryEngine.flushChanges(); | ||
602 | |||
603 | var states = dseAdapter.explore(); | ||
604 | assertEquals(222, states.size()); | ||
605 | } | ||
606 | |||
607 | } | ||