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 | 179 |
1 files changed, 155 insertions, 24 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 index f4644407..91e33f4a 100644 --- 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 | |||
@@ -17,11 +17,10 @@ import tools.refinery.store.query.view.AnySymbolView; | |||
17 | import tools.refinery.store.query.view.KeyOnlyView; | 17 | import tools.refinery.store.query.view.KeyOnlyView; |
18 | import tools.refinery.store.representation.Symbol; | 18 | import tools.refinery.store.representation.Symbol; |
19 | import tools.refinery.store.tuple.Tuple; | 19 | import tools.refinery.store.tuple.Tuple; |
20 | import tools.refinery.visualization.ModelVisualizerAdapter; | ||
21 | 20 | ||
22 | import static org.junit.jupiter.api.Assertions.assertEquals; | 21 | import static org.junit.jupiter.api.Assertions.assertEquals; |
23 | 22 | ||
24 | public class DesignSpaceExplorationTest { | 23 | class DesignSpaceExplorationTest { |
25 | // private static final Symbol<Boolean> namedElement = Symbol.of("NamedElement", 1); | 24 | // private static final Symbol<Boolean> namedElement = Symbol.of("NamedElement", 1); |
26 | // private static final Symbol<Boolean> attribute = Symbol.of("Attribute", 1); | 25 | // private static final Symbol<Boolean> attribute = Symbol.of("Attribute", 1); |
27 | // private static final Symbol<Boolean> method = Symbol.of("Method", 1); | 26 | // private static final Symbol<Boolean> method = Symbol.of("Method", 1); |
@@ -50,7 +49,8 @@ public class DesignSpaceExplorationTest { | |||
50 | void createObjectTest() { | 49 | void createObjectTest() { |
51 | var store = ModelStore.builder() | 50 | var store = ModelStore.builder() |
52 | .with(ViatraModelQueryAdapter.builder()) | 51 | .with(ViatraModelQueryAdapter.builder()) |
53 | .with(DesignSpaceExplorationAdapter.builder()) | 52 | .with(DesignSpaceExplorationAdapter.builder() |
53 | .strategy(new DepthFirstStrategy().withDepthLimit(0))) | ||
54 | .build(); | 54 | .build(); |
55 | 55 | ||
56 | var model = store.createEmptyModel(); | 56 | var model = store.createEmptyModel(); |
@@ -78,7 +78,8 @@ public class DesignSpaceExplorationTest { | |||
78 | void deleteMiddleObjectTest() { | 78 | void deleteMiddleObjectTest() { |
79 | var store = ModelStore.builder() | 79 | var store = ModelStore.builder() |
80 | .with(ViatraModelQueryAdapter.builder()) | 80 | .with(ViatraModelQueryAdapter.builder()) |
81 | .with(DesignSpaceExplorationAdapter.builder()) | 81 | .with(DesignSpaceExplorationAdapter.builder() |
82 | .strategy(new DepthFirstStrategy())) | ||
82 | .build(); | 83 | .build(); |
83 | 84 | ||
84 | var model = store.createEmptyModel(); | 85 | var model = store.createEmptyModel(); |
@@ -118,9 +119,8 @@ public class DesignSpaceExplorationTest { | |||
118 | var store = ModelStore.builder() | 119 | var store = ModelStore.builder() |
119 | .symbols(classModel) | 120 | .symbols(classModel) |
120 | .with(ViatraModelQueryAdapter.builder()) | 121 | .with(ViatraModelQueryAdapter.builder()) |
121 | .with(ModelVisualizerAdapter.builder()) | ||
122 | .with(DesignSpaceExplorationAdapter.builder() | 122 | .with(DesignSpaceExplorationAdapter.builder() |
123 | .strategy(new DepthFirstStrategy(0))) | 123 | .strategy(new DepthFirstStrategy().withDepthLimit(0))) |
124 | .build(); | 124 | .build(); |
125 | 125 | ||
126 | var model = store.createEmptyModel(); | 126 | var model = store.createEmptyModel(); |
@@ -158,10 +158,9 @@ public class DesignSpaceExplorationTest { | |||
158 | .symbols(classModel, classElement, classes) | 158 | .symbols(classModel, classElement, classes) |
159 | .with(ViatraModelQueryAdapter.builder() | 159 | .with(ViatraModelQueryAdapter.builder() |
160 | .queries(createClassPrecondition)) | 160 | .queries(createClassPrecondition)) |
161 | .with(ModelVisualizerAdapter.builder()) | ||
162 | .with(DesignSpaceExplorationAdapter.builder() | 161 | .with(DesignSpaceExplorationAdapter.builder() |
163 | .transformations(createClassRule) | 162 | .transformations(createClassRule) |
164 | .strategy(new DepthFirstStrategy(4) | 163 | .strategy(new DepthFirstStrategy().withDepthLimit(0) |
165 | )) | 164 | )) |
166 | .build(); | 165 | .build(); |
167 | 166 | ||
@@ -205,10 +204,9 @@ public class DesignSpaceExplorationTest { | |||
205 | .symbols(classModel, classElement, classes) | 204 | .symbols(classModel, classElement, classes) |
206 | .with(ViatraModelQueryAdapter.builder() | 205 | .with(ViatraModelQueryAdapter.builder() |
207 | .queries(createClassPrecondition)) | 206 | .queries(createClassPrecondition)) |
208 | .with(ModelVisualizerAdapter.builder()) | ||
209 | .with(DesignSpaceExplorationAdapter.builder() | 207 | .with(DesignSpaceExplorationAdapter.builder() |
210 | .transformations(createClassRule) | 208 | .transformations(createClassRule) |
211 | .strategy(new DepthFirstStrategy(4).continueIfHardObjectivesFulfilled() | 209 | .strategy(new DepthFirstStrategy().withDepthLimit(4).continueIfHardObjectivesFulfilled() |
212 | )) | 210 | )) |
213 | .build(); | 211 | .build(); |
214 | 212 | ||
@@ -274,10 +272,9 @@ public class DesignSpaceExplorationTest { | |||
274 | .symbols(classModel, classElement, classes, feature, features, isEncapsulatedBy, encapsulates) | 272 | .symbols(classModel, classElement, classes, feature, features, isEncapsulatedBy, encapsulates) |
275 | .with(ViatraModelQueryAdapter.builder() | 273 | .with(ViatraModelQueryAdapter.builder() |
276 | .queries(createClassPrecondition, createFeaturePrecondition)) | 274 | .queries(createClassPrecondition, createFeaturePrecondition)) |
277 | .with(ModelVisualizerAdapter.builder()) | ||
278 | .with(DesignSpaceExplorationAdapter.builder() | 275 | .with(DesignSpaceExplorationAdapter.builder() |
279 | .transformations(createClassRule, createFeatureRule) | 276 | .transformations(createClassRule, createFeatureRule) |
280 | .strategy(new DepthFirstStrategy(10).continueIfHardObjectivesFulfilled() | 277 | .strategy(new DepthFirstStrategy().withDepthLimit(10).continueIfHardObjectivesFulfilled() |
281 | )) | 278 | )) |
282 | .build(); | 279 | .build(); |
283 | 280 | ||
@@ -294,13 +291,81 @@ public class DesignSpaceExplorationTest { | |||
294 | } | 291 | } |
295 | 292 | ||
296 | @Test | 293 | @Test |
297 | void BFSTrivialTest() { | 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() { | ||
298 | var store = ModelStore.builder() | 364 | var store = ModelStore.builder() |
299 | .symbols(classModel) | 365 | .symbols(classModel) |
300 | .with(ViatraModelQueryAdapter.builder()) | 366 | .with(ViatraModelQueryAdapter.builder()) |
301 | .with(ModelVisualizerAdapter.builder()) | ||
302 | .with(DesignSpaceExplorationAdapter.builder() | 367 | .with(DesignSpaceExplorationAdapter.builder() |
303 | .strategy(new BestFirstStrategy(0))) | 368 | .strategy(new BestFirstStrategy().withDepthLimit(0))) |
304 | .build(); | 369 | .build(); |
305 | 370 | ||
306 | var model = store.createEmptyModel(); | 371 | var model = store.createEmptyModel(); |
@@ -311,7 +376,7 @@ public class DesignSpaceExplorationTest { | |||
311 | } | 376 | } |
312 | 377 | ||
313 | @Test | 378 | @Test |
314 | void BFSOneRuleTest() { | 379 | void BeFSOneRuleTest() { |
315 | var createClassPrecondition = Query.of("CreateClassPrecondition", | 380 | var createClassPrecondition = Query.of("CreateClassPrecondition", |
316 | (builder, model) -> builder.clause( | 381 | (builder, model) -> builder.clause( |
317 | classModelView.call(model) | 382 | classModelView.call(model) |
@@ -338,10 +403,9 @@ public class DesignSpaceExplorationTest { | |||
338 | .symbols(classModel, classElement, classes) | 403 | .symbols(classModel, classElement, classes) |
339 | .with(ViatraModelQueryAdapter.builder() | 404 | .with(ViatraModelQueryAdapter.builder() |
340 | .queries(createClassPrecondition)) | 405 | .queries(createClassPrecondition)) |
341 | .with(ModelVisualizerAdapter.builder()) | ||
342 | .with(DesignSpaceExplorationAdapter.builder() | 406 | .with(DesignSpaceExplorationAdapter.builder() |
343 | .transformations(createClassRule) | 407 | .transformations(createClassRule) |
344 | .strategy(new BestFirstStrategy(4) | 408 | .strategy(new BestFirstStrategy().withDepthLimit(4) |
345 | )) | 409 | )) |
346 | .build(); | 410 | .build(); |
347 | 411 | ||
@@ -358,7 +422,7 @@ public class DesignSpaceExplorationTest { | |||
358 | } | 422 | } |
359 | 423 | ||
360 | @Test | 424 | @Test |
361 | void BFSContinueTest() { | 425 | void BeFSContinueTest() { |
362 | var createClassPrecondition = Query.of("CreateClassPrecondition", | 426 | var createClassPrecondition = Query.of("CreateClassPrecondition", |
363 | (builder, model) -> builder.clause( | 427 | (builder, model) -> builder.clause( |
364 | classModelView.call(model) | 428 | classModelView.call(model) |
@@ -385,10 +449,9 @@ public class DesignSpaceExplorationTest { | |||
385 | .symbols(classModel, classElement, classes) | 449 | .symbols(classModel, classElement, classes) |
386 | .with(ViatraModelQueryAdapter.builder() | 450 | .with(ViatraModelQueryAdapter.builder() |
387 | .queries(createClassPrecondition)) | 451 | .queries(createClassPrecondition)) |
388 | .with(ModelVisualizerAdapter.builder()) | ||
389 | .with(DesignSpaceExplorationAdapter.builder() | 452 | .with(DesignSpaceExplorationAdapter.builder() |
390 | .transformations(createClassRule) | 453 | .transformations(createClassRule) |
391 | .strategy(new BestFirstStrategy(4).continueIfHardObjectivesFulfilled() | 454 | .strategy(new BestFirstStrategy().withDepthLimit(4).continueIfHardObjectivesFulfilled() |
392 | )) | 455 | )) |
393 | .build(); | 456 | .build(); |
394 | 457 | ||
@@ -405,7 +468,7 @@ public class DesignSpaceExplorationTest { | |||
405 | } | 468 | } |
406 | 469 | ||
407 | @Test | 470 | @Test |
408 | void BFSCompletenessTest() { | 471 | void BeFSCompletenessTest() { |
409 | var createClassPrecondition = Query.of("CreateClassPrecondition", | 472 | var createClassPrecondition = Query.of("CreateClassPrecondition", |
410 | (builder, model) -> builder.clause( | 473 | (builder, model) -> builder.clause( |
411 | classModelView.call(model) | 474 | classModelView.call(model) |
@@ -454,10 +517,9 @@ public class DesignSpaceExplorationTest { | |||
454 | .symbols(classModel, classElement, classes, feature, features, isEncapsulatedBy, encapsulates) | 517 | .symbols(classModel, classElement, classes, feature, features, isEncapsulatedBy, encapsulates) |
455 | .with(ViatraModelQueryAdapter.builder() | 518 | .with(ViatraModelQueryAdapter.builder() |
456 | .queries(createClassPrecondition, createFeaturePrecondition)) | 519 | .queries(createClassPrecondition, createFeaturePrecondition)) |
457 | .with(ModelVisualizerAdapter.builder()) | ||
458 | .with(DesignSpaceExplorationAdapter.builder() | 520 | .with(DesignSpaceExplorationAdapter.builder() |
459 | .transformations(createClassRule, createFeatureRule) | 521 | .transformations(createClassRule, createFeatureRule) |
460 | .strategy(new BestFirstStrategy(10).continueIfHardObjectivesFulfilled() | 522 | .strategy(new BestFirstStrategy().withDepthLimit(10).continueIfHardObjectivesFulfilled() |
461 | )) | 523 | )) |
462 | .build(); | 524 | .build(); |
463 | 525 | ||
@@ -473,4 +535,73 @@ public class DesignSpaceExplorationTest { | |||
473 | assertEquals(2047, states.size()); | 535 | assertEquals(2047, states.size()); |
474 | } | 536 | } |
475 | 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 | |||
476 | } | 607 | } |