diff options
author | 2023-09-07 23:08:09 +0200 | |
---|---|---|
committer | 2023-09-07 23:08:47 +0200 | |
commit | 59dff3ea8673e402c576d94a28ec26d3ab181a92 (patch) | |
tree | fcc769ea25605a8cd7289c76784db9bfab68defa /subprojects/store-dse/src/test/java | |
parent | Merge remote-tracking branch 'nagilooh/datastructure' into partial-interpreta... (diff) | |
download | refinery-59dff3ea8673e402c576d94a28ec26d3ab181a92.tar.gz refinery-59dff3ea8673e402c576d94a28ec26d3ab181a92.tar.zst refinery-59dff3ea8673e402c576d94a28ec26d3ab181a92.zip |
fix(dse): best-first strategy
The query engine must be flushed after firing a tranformation activation.
Diffstat (limited to 'subprojects/store-dse/src/test/java')
-rw-r--r-- | subprojects/store-dse/src/test/java/tools/refinery/store/dse/CRAExamplesTest.java | 35 | ||||
-rw-r--r-- | subprojects/store-dse/src/test/java/tools/refinery/store/dse/DebugTest.java | 4 |
2 files changed, 25 insertions, 14 deletions
diff --git a/subprojects/store-dse/src/test/java/tools/refinery/store/dse/CRAExamplesTest.java b/subprojects/store-dse/src/test/java/tools/refinery/store/dse/CRAExamplesTest.java index 685b88bd..63da6cc3 100644 --- a/subprojects/store-dse/src/test/java/tools/refinery/store/dse/CRAExamplesTest.java +++ b/subprojects/store-dse/src/test/java/tools/refinery/store/dse/CRAExamplesTest.java | |||
@@ -11,10 +11,11 @@ import tools.refinery.store.dse.modification.DanglingEdges; | |||
11 | import tools.refinery.store.dse.modification.ModificationAdapter; | 11 | import tools.refinery.store.dse.modification.ModificationAdapter; |
12 | import tools.refinery.store.dse.strategy.BestFirstStoreManager; | 12 | import tools.refinery.store.dse.strategy.BestFirstStoreManager; |
13 | import tools.refinery.store.dse.tests.DummyCriterion; | 13 | import tools.refinery.store.dse.tests.DummyCriterion; |
14 | import tools.refinery.store.dse.tests.DummyRandomCriterion; | ||
15 | import tools.refinery.store.dse.tests.DummyRandomObjective; | 14 | import tools.refinery.store.dse.tests.DummyRandomObjective; |
16 | import tools.refinery.store.dse.transition.DesignSpaceExplorationAdapter; | 15 | import tools.refinery.store.dse.transition.DesignSpaceExplorationAdapter; |
17 | import tools.refinery.store.dse.transition.Rule; | 16 | import tools.refinery.store.dse.transition.Rule; |
17 | import tools.refinery.store.dse.transition.objectives.Criteria; | ||
18 | import tools.refinery.store.dse.transition.objectives.Objectives; | ||
18 | import tools.refinery.store.model.ModelStore; | 19 | import tools.refinery.store.model.ModelStore; |
19 | import tools.refinery.store.query.ModelQueryAdapter; | 20 | import tools.refinery.store.query.ModelQueryAdapter; |
20 | import tools.refinery.store.query.dnf.Query; | 21 | import tools.refinery.store.query.dnf.Query; |
@@ -59,6 +60,12 @@ class CRAExamplesTest { | |||
59 | methodView.call(f) | 60 | methodView.call(f) |
60 | )); | 61 | )); |
61 | 62 | ||
63 | private static final RelationalQuery unEncapsulatedFeature = Query.of("unEncapsulatedFeature", | ||
64 | (builder, f) -> builder.clause( | ||
65 | feature.call(f), | ||
66 | not(encapsulatesView.call(Variable.of(), f)) | ||
67 | )); | ||
68 | |||
62 | private static final Rule assignFeatureRule = Rule.of("AssignFeature", (builder, f, c1) -> builder | 69 | private static final Rule assignFeatureRule = Rule.of("AssignFeature", (builder, f, c1) -> builder |
63 | .clause( | 70 | .clause( |
64 | feature.call(f), | 71 | feature.call(f), |
@@ -66,24 +73,24 @@ class CRAExamplesTest { | |||
66 | not(encapsulatesView.call(Variable.of(), f)) | 73 | not(encapsulatesView.call(Variable.of(), f)) |
67 | ) | 74 | ) |
68 | .action( | 75 | .action( |
69 | add(encapsulates, f, c1) | 76 | add(encapsulates, c1, f) |
70 | )); | 77 | )); |
71 | 78 | ||
72 | private static final Rule deleteEmptyClassRule = Rule.of("DeleteEmptyClass", (builder, c) -> builder | 79 | private static final Rule deleteEmptyClassRule = Rule.of("DeleteEmptyClass", (builder, c) -> builder |
73 | .clause((f) -> List.of( | 80 | .clause( |
74 | classElementView.call(c), | 81 | classElementView.call(c), |
75 | not(encapsulatesView.call(c, f)) | 82 | not(encapsulatesView.call(c, Variable.of())) |
76 | )) | 83 | ) |
77 | .action( | 84 | .action( |
78 | remove(classElement, c), | 85 | remove(classElement, c), |
79 | delete(c, DanglingEdges.IGNORE) | 86 | delete(c, DanglingEdges.IGNORE) |
80 | )); | 87 | )); |
81 | 88 | ||
82 | private static final Rule createClassRule = Rule.of("CreateClass", (builder, f) -> builder | 89 | private static final Rule createClassRule = Rule.of("CreateClass", (builder, f) -> builder |
83 | .clause((c) -> List.of( | 90 | .clause( |
84 | feature.call(f), | 91 | feature.call(f), |
85 | not(encapsulatesView.call(f, c)) | 92 | not(encapsulatesView.call(Variable.of(), f)) |
86 | )) | 93 | ) |
87 | .action((newClass) -> List.of( | 94 | .action((newClass) -> List.of( |
88 | create(newClass), | 95 | create(newClass), |
89 | add(classElement, newClass), | 96 | add(classElement, newClass), |
@@ -110,7 +117,7 @@ class CRAExamplesTest { | |||
110 | .symbols(classElement, encapsulates, attribute, method, dataDependency, functionalDependency, name) | 117 | .symbols(classElement, encapsulates, attribute, method, dataDependency, functionalDependency, name) |
111 | .with(ViatraModelQueryAdapter.builder()) | 118 | .with(ViatraModelQueryAdapter.builder()) |
112 | .with(ModelVisualizerAdapter.builder() | 119 | .with(ModelVisualizerAdapter.builder() |
113 | .withOutputpath("test_output") | 120 | .withOutputPath("test_output") |
114 | .withFormat(FileFormat.DOT) | 121 | .withFormat(FileFormat.DOT) |
115 | .withFormat(FileFormat.SVG) | 122 | .withFormat(FileFormat.SVG) |
116 | .saveStates() | 123 | .saveStates() |
@@ -119,8 +126,11 @@ class CRAExamplesTest { | |||
119 | .with(ModificationAdapter.builder()) | 126 | .with(ModificationAdapter.builder()) |
120 | .with(DesignSpaceExplorationAdapter.builder() | 127 | .with(DesignSpaceExplorationAdapter.builder() |
121 | .transformations(assignFeatureRule, deleteEmptyClassRule, createClassRule, moveFeatureRule) | 128 | .transformations(assignFeatureRule, deleteEmptyClassRule, createClassRule, moveFeatureRule) |
122 | .objectives(new DummyRandomObjective()) | 129 | .objectives(Objectives.sum( |
123 | .accept(new DummyRandomCriterion()) | 130 | new DummyRandomObjective(), |
131 | Objectives.count(unEncapsulatedFeature) | ||
132 | )) | ||
133 | .accept(Criteria.whenNoMatch(unEncapsulatedFeature)) | ||
124 | .exclude(new DummyCriterion(false))) | 134 | .exclude(new DummyCriterion(false))) |
125 | .build(); | 135 | .build(); |
126 | 136 | ||
@@ -192,9 +202,10 @@ class CRAExamplesTest { | |||
192 | var initialVersion = model.commit(); | 202 | var initialVersion = model.commit(); |
193 | queryEngine.flushChanges(); | 203 | queryEngine.flushChanges(); |
194 | 204 | ||
195 | var bestFirst = new BestFirstStoreManager(store); | 205 | var bestFirst = new BestFirstStoreManager(store, 50); |
196 | bestFirst.startExploration(initialVersion); | 206 | bestFirst.startExploration(initialVersion); |
197 | var resultStore = bestFirst.getSolutionStore(); | 207 | var resultStore = bestFirst.getSolutionStore(); |
198 | System.out.println("states size: " + resultStore.getSolutions().size()); | 208 | System.out.println("states size: " + resultStore.getSolutions().size()); |
209 | model.getAdapter(ModelVisualizerAdapter.class).visualize(bestFirst.getVisualizationStore()); | ||
199 | } | 210 | } |
200 | } | 211 | } |
diff --git a/subprojects/store-dse/src/test/java/tools/refinery/store/dse/DebugTest.java b/subprojects/store-dse/src/test/java/tools/refinery/store/dse/DebugTest.java index baa7c8a4..b912eba3 100644 --- a/subprojects/store-dse/src/test/java/tools/refinery/store/dse/DebugTest.java +++ b/subprojects/store-dse/src/test/java/tools/refinery/store/dse/DebugTest.java | |||
@@ -64,7 +64,7 @@ class DebugTest { | |||
64 | .symbols(classModel, classElement, feature, classes, features) | 64 | .symbols(classModel, classElement, feature, classes, features) |
65 | .with(ViatraModelQueryAdapter.builder()) | 65 | .with(ViatraModelQueryAdapter.builder()) |
66 | .with(ModelVisualizerAdapter.builder() | 66 | .with(ModelVisualizerAdapter.builder() |
67 | .withOutputpath("test_output") | 67 | .withOutputPath("test_output") |
68 | .withFormat(FileFormat.DOT) | 68 | .withFormat(FileFormat.DOT) |
69 | .withFormat(FileFormat.SVG) | 69 | .withFormat(FileFormat.SVG) |
70 | .saveStates() | 70 | .saveStates() |
@@ -91,7 +91,7 @@ class DebugTest { | |||
91 | var initialVersion = model.commit(); | 91 | var initialVersion = model.commit(); |
92 | queryEngine.flushChanges(); | 92 | queryEngine.flushChanges(); |
93 | 93 | ||
94 | var bestFirst = new BestFirstStoreManager(store); | 94 | var bestFirst = new BestFirstStoreManager(store, 50); |
95 | bestFirst.startExploration(initialVersion); | 95 | bestFirst.startExploration(initialVersion); |
96 | var resultStore = bestFirst.getSolutionStore(); | 96 | var resultStore = bestFirst.getSolutionStore(); |
97 | System.out.println("states size: " + resultStore.getSolutions().size()); | 97 | System.out.println("states size: " + resultStore.getSolutions().size()); |