diff options
Diffstat (limited to 'subprojects/store-dse/src/test/java')
6 files changed, 90 insertions, 1239 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 831b9ff0..685b88bd 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 | |||
@@ -7,19 +7,18 @@ package tools.refinery.store.dse; | |||
7 | 7 | ||
8 | import org.junit.jupiter.api.Disabled; | 8 | import org.junit.jupiter.api.Disabled; |
9 | import org.junit.jupiter.api.Test; | 9 | import org.junit.jupiter.api.Test; |
10 | import tools.refinery.store.dse.modification.DanglingEdges; | ||
10 | import tools.refinery.store.dse.modification.ModificationAdapter; | 11 | import tools.refinery.store.dse.modification.ModificationAdapter; |
11 | import tools.refinery.store.dse.strategy.BestFirstStoreManager; | 12 | import tools.refinery.store.dse.strategy.BestFirstStoreManager; |
13 | import tools.refinery.store.dse.tests.DummyCriterion; | ||
12 | import tools.refinery.store.dse.tests.DummyRandomCriterion; | 14 | import tools.refinery.store.dse.tests.DummyRandomCriterion; |
13 | import tools.refinery.store.dse.tests.DummyRandomObjective; | 15 | import tools.refinery.store.dse.tests.DummyRandomObjective; |
14 | import tools.refinery.store.dse.transition.DesignSpaceExplorationAdapter; | 16 | import tools.refinery.store.dse.transition.DesignSpaceExplorationAdapter; |
15 | import tools.refinery.store.dse.tests.DummyCriterion; | 17 | import tools.refinery.store.dse.transition.Rule; |
16 | import tools.refinery.store.dse.tests.DummyObjective; | ||
17 | import tools.refinery.store.model.ModelStore; | 18 | import tools.refinery.store.model.ModelStore; |
18 | import tools.refinery.store.query.ModelQueryAdapter; | 19 | import tools.refinery.store.query.ModelQueryAdapter; |
19 | import tools.refinery.store.query.dnf.FunctionalQuery; | ||
20 | import tools.refinery.store.query.dnf.Query; | 20 | import tools.refinery.store.query.dnf.Query; |
21 | import tools.refinery.store.query.dnf.RelationalQuery; | 21 | import tools.refinery.store.query.dnf.RelationalQuery; |
22 | import tools.refinery.store.dse.transition.TransformationRule; | ||
23 | import tools.refinery.store.query.term.Variable; | 22 | import tools.refinery.store.query.term.Variable; |
24 | import tools.refinery.store.query.viatra.ViatraModelQueryAdapter; | 23 | import tools.refinery.store.query.viatra.ViatraModelQueryAdapter; |
25 | import tools.refinery.store.query.view.AnySymbolView; | 24 | import tools.refinery.store.query.view.AnySymbolView; |
@@ -32,195 +31,102 @@ import tools.refinery.visualization.internal.FileFormat; | |||
32 | 31 | ||
33 | import java.util.List; | 32 | import java.util.List; |
34 | 33 | ||
34 | import static tools.refinery.store.dse.modification.actions.ModificationActionLiterals.create; | ||
35 | import static tools.refinery.store.dse.modification.actions.ModificationActionLiterals.delete; | ||
36 | import static tools.refinery.store.dse.transition.actions.ActionLiterals.add; | ||
37 | import static tools.refinery.store.dse.transition.actions.ActionLiterals.remove; | ||
35 | import static tools.refinery.store.query.literal.Literals.not; | 38 | import static tools.refinery.store.query.literal.Literals.not; |
36 | 39 | ||
37 | class CRAExamplesTest { | 40 | class CRAExamplesTest { |
38 | |||
39 | private static final Symbol<String> name = Symbol.of("Name", 1, String.class); | 41 | private static final Symbol<String> name = Symbol.of("Name", 1, String.class); |
40 | |||
41 | // private static final Symbol<Boolean> classModel = Symbol.of("ClassModel", 1); | ||
42 | private static final Symbol<Boolean> classElement = Symbol.of("ClassElement", 1); | 42 | private static final Symbol<Boolean> classElement = Symbol.of("ClassElement", 1); |
43 | // private static final Symbol<Boolean> feature = Symbol.of("Feature", 1); | ||
44 | private static final Symbol<Boolean> attribute = Symbol.of("Attribute", 1); | 43 | private static final Symbol<Boolean> attribute = Symbol.of("Attribute", 1); |
45 | private static final Symbol<Boolean> method = Symbol.of("Method", 1); | 44 | private static final Symbol<Boolean> method = Symbol.of("Method", 1); |
46 | |||
47 | // private static final Symbol<Boolean> isEncapsulatedBy = Symbol.of("IsEncapsulatedBy", 2); | ||
48 | private static final Symbol<Boolean> encapsulates = Symbol.of("Encapsulates", 2); | 45 | private static final Symbol<Boolean> encapsulates = Symbol.of("Encapsulates", 2); |
49 | private static final Symbol<Boolean> dataDependency = Symbol.of("DataDependency", 2); | 46 | private static final Symbol<Boolean> dataDependency = Symbol.of("DataDependency", 2); |
50 | private static final Symbol<Boolean> functionalDependency = Symbol.of("FunctionalDependency", 2); | 47 | private static final Symbol<Boolean> functionalDependency = Symbol.of("FunctionalDependency", 2); |
51 | 48 | ||
52 | private static final Symbol<Boolean> features = Symbol.of("Features", 2); | ||
53 | private static final Symbol<Boolean> classes = Symbol.of("Classes", 2); | ||
54 | |||
55 | // private static final AnySymbolView classModelView = new KeyOnlyView<>(classModel); | ||
56 | private static final AnySymbolView classElementView = new KeyOnlyView<>(classElement); | 49 | private static final AnySymbolView classElementView = new KeyOnlyView<>(classElement); |
57 | // private static final AnySymbolView featureView = new KeyOnlyView<>(feature); | ||
58 | private static final AnySymbolView attributeView = new KeyOnlyView<>(attribute); | 50 | private static final AnySymbolView attributeView = new KeyOnlyView<>(attribute); |
59 | private static final AnySymbolView methodView = new KeyOnlyView<>(method); | 51 | private static final AnySymbolView methodView = new KeyOnlyView<>(method); |
60 | // private static final AnySymbolView isEncapsulatedByView = new KeyOnlyView<>(isEncapsulatedBy); | ||
61 | private static final AnySymbolView encapsulatesView = new KeyOnlyView<>(encapsulates); | 52 | private static final AnySymbolView encapsulatesView = new KeyOnlyView<>(encapsulates); |
62 | private static final AnySymbolView dataDependencyView = new KeyOnlyView<>(dataDependency); | ||
63 | private static final AnySymbolView functionalDependencyView = new KeyOnlyView<>(functionalDependency); | ||
64 | private static final AnySymbolView featuresView = new KeyOnlyView<>(features); | ||
65 | private static final AnySymbolView classesView = new KeyOnlyView<>(classes); | ||
66 | 53 | ||
67 | /*Example Transformation rules*/ | 54 | private static final RelationalQuery feature = Query.of("Feature", (builder, f) -> builder |
68 | private static final RelationalQuery feature = Query.of("Feature", | ||
69 | (builder, f) -> builder.clause( | ||
70 | attributeView.call(f)) | ||
71 | .clause( | 55 | .clause( |
72 | methodView.call(f)) | 56 | attributeView.call(f) |
73 | ); | 57 | ) |
74 | 58 | .clause( | |
75 | private static final RelationalQuery assignFeaturePreconditionHelper = Query.of("AssignFeaturePreconditionHelper", | 59 | methodView.call(f) |
76 | (builder, c, f) -> builder.clause( | ||
77 | classElementView.call(c), | ||
78 | // classesView.call(model, c), | ||
79 | encapsulatesView.call(c, f) | ||
80 | )); | 60 | )); |
81 | 61 | ||
82 | private static final RelationalQuery assignFeaturePrecondition = Query.of("AssignFeaturePrecondition", | 62 | private static final Rule assignFeatureRule = Rule.of("AssignFeature", (builder, f, c1) -> builder |
83 | (builder, f, c1) -> builder.clause((c2) -> List.of( | 63 | .clause( |
84 | // classModelView.call(model), | ||
85 | feature.call(f), | 64 | feature.call(f), |
86 | classElementView.call(c1), | 65 | classElementView.call(c1), |
87 | // featuresView.call(model, f), | 66 | not(encapsulatesView.call(Variable.of(), f)) |
88 | not(assignFeaturePreconditionHelper.call(c2, f)), | 67 | ) |
89 | not(encapsulatesView.call(c1, f)) | 68 | .action( |
90 | ))); | 69 | add(encapsulates, f, c1) |
70 | )); | ||
91 | 71 | ||
92 | private static final RelationalQuery deleteEmptyClassPrecondition = Query.of("DeleteEmptyClassPrecondition", | 72 | private static final Rule deleteEmptyClassRule = Rule.of("DeleteEmptyClass", (builder, c) -> builder |
93 | (builder, c) -> builder.clause((f) -> List.of( | 73 | .clause((f) -> List.of( |
94 | // classModelView.call(model), | ||
95 | classElementView.call(c), | 74 | classElementView.call(c), |
96 | // featuresView.call(model, f), | ||
97 | not(encapsulatesView.call(c, f)) | 75 | not(encapsulatesView.call(c, f)) |
98 | ))); | 76 | )) |
99 | 77 | .action( | |
100 | private static final RelationalQuery createClassPreconditionHelper = Query.of("CreateClassPreconditionHelper", | 78 | remove(classElement, c), |
101 | (builder, f, c) -> builder.clause( | 79 | delete(c, DanglingEdges.IGNORE) |
102 | classElementView.call(c), | ||
103 | // classesView.call(model, c), | ||
104 | encapsulatesView.call(c, f) | ||
105 | )); | 80 | )); |
106 | 81 | ||
107 | private static final RelationalQuery createClassPrecondition = Query.of("CreateClassPrecondition", | 82 | private static final Rule createClassRule = Rule.of("CreateClass", (builder, f) -> builder |
108 | (builder, f) -> builder.clause((c) -> List.of( | 83 | .clause((c) -> List.of( |
109 | // classModelView.call(model), | ||
110 | feature.call(f), | 84 | feature.call(f), |
111 | not(createClassPreconditionHelper.call(f, c)) | 85 | not(encapsulatesView.call(f, c)) |
86 | )) | ||
87 | .action((newClass) -> List.of( | ||
88 | create(newClass), | ||
89 | add(classElement, newClass), | ||
90 | add(encapsulates, newClass, f) | ||
112 | ))); | 91 | ))); |
113 | 92 | ||
114 | private static final RelationalQuery moveFeaturePrecondition = Query.of("MoveFeature", | 93 | private static final Rule moveFeatureRule = Rule.of("MoveFeature", (builder, c1, c2, f) -> builder |
115 | (builder, c1, c2, f) -> builder.clause( | 94 | .clause( |
116 | // classModelView.call(model), | ||
117 | classElementView.call(c1), | 95 | classElementView.call(c1), |
118 | classElementView.call(c2), | 96 | classElementView.call(c2), |
119 | c1.notEquivalent(c2), | 97 | c1.notEquivalent(c2), |
120 | feature.call(f), | 98 | feature.call(f), |
121 | // classesView.call(model, c1), | ||
122 | // classesView.call(model, c2), | ||
123 | // featuresView.call(model, f), | ||
124 | encapsulatesView.call(c1, f) | 99 | encapsulatesView.call(c1, f) |
100 | ) | ||
101 | .action( | ||
102 | remove(encapsulates, c1, f), | ||
103 | add(encapsulates, c2, f) | ||
125 | )); | 104 | )); |
126 | 105 | ||
127 | private static final TransformationRule assignFeatureRule = new TransformationRule("AssignFeature", | ||
128 | assignFeaturePrecondition, | ||
129 | (model) -> { | ||
130 | // var isEncapsulatedByInterpretation = model.getInterpretation(isEncapsulatedBy); | ||
131 | var encapsulatesInterpretation = model.getInterpretation(encapsulates); | ||
132 | return ((Tuple activation) -> { | ||
133 | var feature = activation.get(0); | ||
134 | var classElement = activation.get(1); | ||
135 | |||
136 | // isEncapsulatedByInterpretation.put(Tuple.of(feature, classElement), true); | ||
137 | encapsulatesInterpretation.put(Tuple.of(classElement, feature), true); | ||
138 | }); | ||
139 | }); | ||
140 | |||
141 | private static final TransformationRule deleteEmptyClassRule = new TransformationRule("DeleteEmptyClass", | ||
142 | deleteEmptyClassPrecondition, | ||
143 | (model) -> { | ||
144 | // var classesInterpretation = model.getInterpretation(classes); | ||
145 | var classElementInterpretation = model.getInterpretation(classElement); | ||
146 | return ((Tuple activation) -> { | ||
147 | // TODO: can we move modificationAdapter outside? | ||
148 | var modificationAdapter = model.getAdapter(ModificationAdapter.class); | ||
149 | // var modelElement = activation.get(0); | ||
150 | var classElement = activation.get(0); | ||
151 | |||
152 | // classesInterpretation.put(Tuple.of(modelElement, classElement), false); | ||
153 | classElementInterpretation.put(Tuple.of(classElement), false); | ||
154 | modificationAdapter.deleteObject(Tuple.of(classElement)); | ||
155 | }); | ||
156 | }); | ||
157 | |||
158 | private static final TransformationRule createClassRule = new TransformationRule("CreateClass", | ||
159 | createClassPrecondition, | ||
160 | (model) -> { | ||
161 | var classElementInterpretation = model.getInterpretation(classElement); | ||
162 | // var classesInterpretation = model.getInterpretation(classes); | ||
163 | var encapsulatesInterpretation = model.getInterpretation(encapsulates); | ||
164 | return ((Tuple activation) -> { | ||
165 | // TODO: can we move modificationAdapter outside? | ||
166 | var modificationAdapter = model.getAdapter(ModificationAdapter.class); | ||
167 | // var modelElement = activation.get(0); | ||
168 | var feature = activation.get(0); | ||
169 | |||
170 | var newClassElement = modificationAdapter.createObject(); | ||
171 | var newClassElementId = newClassElement.get(0); | ||
172 | classElementInterpretation.put(newClassElement, true); | ||
173 | // classesInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
174 | encapsulatesInterpretation.put(Tuple.of(newClassElementId, feature), true); | ||
175 | }); | ||
176 | }); | ||
177 | |||
178 | private static final TransformationRule moveFeatureRule = new TransformationRule("MoveFeature", | ||
179 | moveFeaturePrecondition, | ||
180 | (model) -> { | ||
181 | var encapsulatesInterpretation = model.getInterpretation(encapsulates); | ||
182 | return ((Tuple activation) -> { | ||
183 | var classElement1 = activation.get(0); | ||
184 | var classElement2 = activation.get(1); | ||
185 | var feature = activation.get(2); | ||
186 | |||
187 | encapsulatesInterpretation.put(Tuple.of(classElement1, feature), false); | ||
188 | encapsulatesInterpretation.put(Tuple.of(classElement2, feature), true); | ||
189 | }); | ||
190 | }); | ||
191 | |||
192 | @Test | 106 | @Test |
193 | @Disabled("This test is only for debugging purposes") | 107 | @Disabled("This test is only for debugging purposes") |
194 | void craTest() { | 108 | void craTest() { |
195 | var store = ModelStore.builder() | 109 | var store = ModelStore.builder() |
196 | .symbols(classElement, encapsulates, classes, features, attribute, method, dataDependency, | 110 | .symbols(classElement, encapsulates, attribute, method, dataDependency, functionalDependency, name) |
197 | functionalDependency, name) | 111 | .with(ViatraModelQueryAdapter.builder()) |
198 | .with(ViatraModelQueryAdapter.builder() | ||
199 | .queries(feature, assignFeaturePreconditionHelper, assignFeaturePrecondition, | ||
200 | deleteEmptyClassPrecondition, createClassPreconditionHelper, createClassPrecondition, | ||
201 | moveFeaturePrecondition)) | ||
202 | .with(ModelVisualizerAdapter.builder() | 112 | .with(ModelVisualizerAdapter.builder() |
203 | .withOutputpath("test_output") | 113 | .withOutputpath("test_output") |
204 | .withFormat(FileFormat.DOT) | 114 | .withFormat(FileFormat.DOT) |
205 | .withFormat(FileFormat.SVG) | 115 | .withFormat(FileFormat.SVG) |
206 | .saveStates() | 116 | .saveStates() |
207 | .saveDesignSpace() | 117 | .saveDesignSpace()) |
208 | ) | ||
209 | .with(StateCoderAdapter.builder()) | 118 | .with(StateCoderAdapter.builder()) |
210 | .with(ModificationAdapter.builder()) | 119 | .with(ModificationAdapter.builder()) |
211 | .with(DesignSpaceExplorationAdapter.builder() | 120 | .with(DesignSpaceExplorationAdapter.builder() |
212 | .transformations(assignFeatureRule, deleteEmptyClassRule, createClassRule, moveFeatureRule) | 121 | .transformations(assignFeatureRule, deleteEmptyClassRule, createClassRule, moveFeatureRule) |
213 | .objectives(new DummyRandomObjective()) | 122 | .objectives(new DummyRandomObjective()) |
214 | .accept(new DummyRandomCriterion()) | 123 | .accept(new DummyRandomCriterion()) |
215 | .exclude(new DummyCriterion(false)) | 124 | .exclude(new DummyCriterion(false))) |
216 | ) | ||
217 | .build(); | 125 | .build(); |
218 | 126 | ||
219 | var model = store.createEmptyModel(); | 127 | var model = store.createEmptyModel(); |
220 | // modificationAdapter.setRandom(1); | ||
221 | var queryEngine = model.getAdapter(ModelQueryAdapter.class); | 128 | var queryEngine = model.getAdapter(ModelQueryAdapter.class); |
222 | 129 | ||
223 | // var modelInterpretation = model.getInterpretation(classModel); | ||
224 | var nameInterpretation = model.getInterpretation(name); | 130 | var nameInterpretation = model.getInterpretation(name); |
225 | var methodInterpretation = model.getInterpretation(method); | 131 | var methodInterpretation = model.getInterpretation(method); |
226 | var attributeInterpretation = model.getInterpretation(attribute); | 132 | var attributeInterpretation = model.getInterpretation(attribute); |
@@ -229,7 +135,6 @@ class CRAExamplesTest { | |||
229 | 135 | ||
230 | var modificationAdapter = model.getAdapter(ModificationAdapter.class); | 136 | var modificationAdapter = model.getAdapter(ModificationAdapter.class); |
231 | 137 | ||
232 | // var modelElement = modificationAdapter.createObject(); | ||
233 | var method1 = modificationAdapter.createObject(); | 138 | var method1 = modificationAdapter.createObject(); |
234 | var method1Id = method1.get(0); | 139 | var method1Id = method1.get(0); |
235 | var method2 = modificationAdapter.createObject(); | 140 | var method2 = modificationAdapter.createObject(); |
@@ -259,9 +164,6 @@ class CRAExamplesTest { | |||
259 | nameInterpretation.put(attribute4, "A4"); | 164 | nameInterpretation.put(attribute4, "A4"); |
260 | nameInterpretation.put(attribute5, "A5"); | 165 | nameInterpretation.put(attribute5, "A5"); |
261 | 166 | ||
262 | |||
263 | |||
264 | // modelInterpretation.put(modelElement, true); | ||
265 | methodInterpretation.put(method1, true); | 167 | methodInterpretation.put(method1, true); |
266 | methodInterpretation.put(method2, true); | 168 | methodInterpretation.put(method2, true); |
267 | methodInterpretation.put(method3, true); | 169 | methodInterpretation.put(method3, true); |
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 87c3892a..baa7c8a4 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 | |||
@@ -9,110 +9,73 @@ import org.junit.jupiter.api.Disabled; | |||
9 | import org.junit.jupiter.api.Test; | 9 | import org.junit.jupiter.api.Test; |
10 | import tools.refinery.store.dse.modification.ModificationAdapter; | 10 | import tools.refinery.store.dse.modification.ModificationAdapter; |
11 | import tools.refinery.store.dse.strategy.BestFirstStoreManager; | 11 | import tools.refinery.store.dse.strategy.BestFirstStoreManager; |
12 | import tools.refinery.store.dse.tests.DummyCriterion; | ||
13 | import tools.refinery.store.dse.tests.DummyObjective; | ||
14 | import tools.refinery.store.dse.tests.DummyRandomCriterion; | 12 | import tools.refinery.store.dse.tests.DummyRandomCriterion; |
15 | import tools.refinery.store.dse.tests.DummyRandomObjective; | 13 | import tools.refinery.store.dse.tests.DummyRandomObjective; |
16 | import tools.refinery.store.dse.transition.DesignSpaceExplorationAdapter; | 14 | import tools.refinery.store.dse.transition.DesignSpaceExplorationAdapter; |
17 | import tools.refinery.store.dse.transition.TransformationRule; | 15 | import tools.refinery.store.dse.transition.Rule; |
18 | import tools.refinery.store.model.ModelStore; | 16 | import tools.refinery.store.model.ModelStore; |
19 | import tools.refinery.store.query.ModelQueryAdapter; | 17 | import tools.refinery.store.query.ModelQueryAdapter; |
20 | import tools.refinery.store.query.dnf.Query; | ||
21 | import tools.refinery.store.query.viatra.ViatraModelQueryAdapter; | 18 | import tools.refinery.store.query.viatra.ViatraModelQueryAdapter; |
22 | import tools.refinery.store.query.view.AnySymbolView; | 19 | import tools.refinery.store.query.view.AnySymbolView; |
23 | import tools.refinery.store.query.view.KeyOnlyView; | 20 | import tools.refinery.store.query.view.KeyOnlyView; |
24 | import tools.refinery.store.representation.Symbol; | 21 | import tools.refinery.store.representation.Symbol; |
25 | import tools.refinery.store.statecoding.StateCoderAdapter; | 22 | import tools.refinery.store.statecoding.StateCoderAdapter; |
26 | import tools.refinery.store.tuple.Tuple; | ||
27 | import tools.refinery.visualization.ModelVisualizerAdapter; | 23 | import tools.refinery.visualization.ModelVisualizerAdapter; |
28 | import tools.refinery.visualization.internal.FileFormat; | 24 | import tools.refinery.visualization.internal.FileFormat; |
29 | 25 | ||
26 | import java.util.List; | ||
27 | |||
28 | import static tools.refinery.store.dse.modification.actions.ModificationActionLiterals.create; | ||
29 | import static tools.refinery.store.dse.transition.actions.ActionLiterals.add; | ||
30 | |||
30 | class DebugTest { | 31 | class DebugTest { |
31 | private static final Symbol<Boolean> classModel = Symbol.of("ClassModel", 1); | 32 | private static final Symbol<Boolean> classModel = Symbol.of("ClassModel", 1); |
32 | private static final Symbol<Boolean> classElement = Symbol.of("ClassElement", 1); | 33 | private static final Symbol<Boolean> classElement = Symbol.of("ClassElement", 1); |
33 | private static final Symbol<Boolean> feature = Symbol.of("Feature", 1); | 34 | private static final Symbol<Boolean> feature = Symbol.of("Feature", 1); |
34 | |||
35 | private static final Symbol<Boolean> isEncapsulatedBy = Symbol.of("IsEncapsulatedBy", 2); | ||
36 | private static final Symbol<Boolean> encapsulates = Symbol.of("Encapsulates", 2); | ||
37 | |||
38 | private static final Symbol<Boolean> features = Symbol.of("Features", 2); | 35 | private static final Symbol<Boolean> features = Symbol.of("Features", 2); |
39 | private static final Symbol<Boolean> classes = Symbol.of("Classes", 2); | 36 | private static final Symbol<Boolean> classes = Symbol.of("Classes", 2); |
40 | 37 | ||
41 | private static final AnySymbolView classModelView = new KeyOnlyView<>(classModel); | 38 | private static final AnySymbolView classModelView = new KeyOnlyView<>(classModel); |
42 | private static final AnySymbolView classElementView = new KeyOnlyView<>(classElement); | ||
43 | private static final AnySymbolView featureView = new KeyOnlyView<>(feature); | ||
44 | private static final AnySymbolView isEncapsulatedByView = new KeyOnlyView<>(isEncapsulatedBy); | ||
45 | private static final AnySymbolView encapsulatesView = new KeyOnlyView<>(encapsulates); | ||
46 | private static final AnySymbolView featuresView = new KeyOnlyView<>(features); | ||
47 | private static final AnySymbolView classesView = new KeyOnlyView<>(classes); | ||
48 | |||
49 | 39 | ||
50 | @Test | 40 | @Test |
51 | @Disabled("This test is only for debugging purposes") | 41 | @Disabled("This test is only for debugging purposes") |
52 | void BFSTest() { | 42 | void BFSTest() { |
53 | var createClassPrecondition = Query.of("CreateClassPrecondition", | 43 | var createClassRule = Rule.of("CreateClass", (builder, model) -> builder |
54 | (builder, model) -> builder.clause( | 44 | .clause( |
55 | classModelView.call(model) | 45 | classModelView.call(model) |
56 | )); | 46 | ) |
57 | 47 | .action((newClassElement) -> List.of( | |
58 | var createClassRule = new TransformationRule("CreateClass", | 48 | create(newClassElement), |
59 | createClassPrecondition, | 49 | add(classElement, newClassElement), |
60 | (model) -> { | 50 | add(classes, model, newClassElement) |
61 | var classesInterpretation = model.getInterpretation(classes); | 51 | ))); |
62 | var classElementInterpretation = model.getInterpretation(classElement); | 52 | |
63 | return ((Tuple activation) -> { | 53 | var createFeatureRule = Rule.of("CreateFeature", (builder, model) -> builder |
64 | var dseAdapter = model.getAdapter(ModificationAdapter.class); | 54 | .clause( |
65 | var modelElement = activation.get(0); | ||
66 | |||
67 | var newClassElement = dseAdapter.createObject(); | ||
68 | var newClassElementId = newClassElement.get(0); | ||
69 | |||
70 | classesInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
71 | classElementInterpretation.put(Tuple.of(newClassElementId), true); | ||
72 | }); | ||
73 | }); | ||
74 | |||
75 | var createFeaturePrecondition = Query.of("CreateFeaturePrecondition", | ||
76 | (builder, model) -> builder.clause( | ||
77 | classModelView.call(model) | 55 | classModelView.call(model) |
78 | )); | 56 | ) |
79 | 57 | .action((newFeature) -> List.of( | |
80 | var createFeatureRule = new TransformationRule("CreateFeature", | 58 | create(newFeature), |
81 | createFeaturePrecondition, | 59 | add(feature, newFeature), |
82 | (model) -> { | 60 | add(features, model, newFeature) |
83 | var featuresInterpretation = model.getInterpretation(features); | 61 | ))); |
84 | var featureInterpretation = model.getInterpretation(feature); | ||
85 | return ((Tuple activation) -> { | ||
86 | var dseAdapter = model.getAdapter(ModificationAdapter.class); | ||
87 | var modelElement = activation.get(0); | ||
88 | |||
89 | var newClassElement = dseAdapter.createObject(); | ||
90 | var newClassElementId = newClassElement.get(0); | ||
91 | |||
92 | featuresInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
93 | featureInterpretation.put(Tuple.of(newClassElementId), true); | ||
94 | }); | ||
95 | }); | ||
96 | 62 | ||
97 | var store = ModelStore.builder() | 63 | var store = ModelStore.builder() |
98 | .symbols(classModel, classElement, feature, isEncapsulatedBy, encapsulates, classes, features) | 64 | .symbols(classModel, classElement, feature, classes, features) |
99 | .with(ViatraModelQueryAdapter.builder() | 65 | .with(ViatraModelQueryAdapter.builder()) |
100 | .queries(createClassPrecondition, createFeaturePrecondition)) | ||
101 | .with(ModelVisualizerAdapter.builder() | 66 | .with(ModelVisualizerAdapter.builder() |
102 | .withOutputpath("test_output") | 67 | .withOutputpath("test_output") |
103 | .withFormat(FileFormat.DOT) | 68 | .withFormat(FileFormat.DOT) |
104 | .withFormat(FileFormat.SVG) | 69 | .withFormat(FileFormat.SVG) |
105 | .saveStates() | 70 | .saveStates() |
106 | .saveDesignSpace() | 71 | .saveDesignSpace()) |
107 | ) | ||
108 | .with(StateCoderAdapter.builder()) | 72 | .with(StateCoderAdapter.builder()) |
109 | .with(ModificationAdapter.builder()) | 73 | .with(ModificationAdapter.builder()) |
110 | .with(DesignSpaceExplorationAdapter.builder() | 74 | .with(DesignSpaceExplorationAdapter.builder() |
111 | .transformations(createClassRule, createFeatureRule) | 75 | .transformations(createClassRule, createFeatureRule) |
112 | .objectives(new DummyRandomObjective()) | 76 | .objectives(new DummyRandomObjective()) |
113 | .accept(new DummyRandomCriterion()) | 77 | .accept(new DummyRandomCriterion()) |
114 | .exclude(new DummyRandomCriterion()) | 78 | .exclude(new DummyRandomCriterion())) |
115 | ) | ||
116 | .build(); | 79 | .build(); |
117 | 80 | ||
118 | var model = store.createEmptyModel(); | 81 | var model = store.createEmptyModel(); |
@@ -128,11 +91,9 @@ class DebugTest { | |||
128 | var initialVersion = model.commit(); | 91 | var initialVersion = model.commit(); |
129 | queryEngine.flushChanges(); | 92 | queryEngine.flushChanges(); |
130 | 93 | ||
131 | |||
132 | var bestFirst = new BestFirstStoreManager(store); | 94 | var bestFirst = new BestFirstStoreManager(store); |
133 | bestFirst.startExploration(initialVersion); | 95 | bestFirst.startExploration(initialVersion); |
134 | var resultStore = bestFirst.getSolutionStore(); | 96 | var resultStore = bestFirst.getSolutionStore(); |
135 | System.out.println("states size: " + resultStore.getSolutions().size()); | 97 | System.out.println("states size: " + resultStore.getSolutions().size()); |
136 | |||
137 | } | 98 | } |
138 | } | 99 | } |
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 f5f13433..00000000 --- a/subprojects/store-dse/src/test/java/tools/refinery/store/dse/DesignSpaceExplorationTest.java +++ /dev/null | |||
@@ -1,596 +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 tools.refinery.store.query.view.AnySymbolView; | ||
9 | import tools.refinery.store.query.view.KeyOnlyView; | ||
10 | import tools.refinery.store.representation.Symbol; | ||
11 | |||
12 | class DesignSpaceExplorationTest { | ||
13 | // private static final Symbol<Boolean> namedElement = Symbol.of("NamedElement", 1); | ||
14 | // private static final Symbol<Boolean> attribute = Symbol.of("Attribute", 1); | ||
15 | // private static final Symbol<Boolean> method = Symbol.of("Method", 1); | ||
16 | // private static final Symbol<Boolean> dataDependency = Symbol.of("DataDependency", 2); | ||
17 | // private static final Symbol<Boolean> functionalDependency = Symbol.of("FunctionalDependency", 2); | ||
18 | |||
19 | private static final Symbol<Boolean> classModel = Symbol.of("ClassModel", 1); | ||
20 | private static final Symbol<Boolean> classElement = Symbol.of("ClassElement", 1); | ||
21 | private static final Symbol<Boolean> feature = Symbol.of("Feature", 1); | ||
22 | |||
23 | private static final Symbol<Boolean> isEncapsulatedBy = Symbol.of("IsEncapsulatedBy", 2); | ||
24 | private static final Symbol<Boolean> encapsulates = Symbol.of("Encapsulates", 2); | ||
25 | |||
26 | private static final Symbol<Boolean> features = Symbol.of("Features", 2); | ||
27 | private static final Symbol<Boolean> classes = Symbol.of("Classes", 2); | ||
28 | |||
29 | private static final AnySymbolView classModelView = new KeyOnlyView<>(classModel); | ||
30 | private static final AnySymbolView classElementView = new KeyOnlyView<>(classElement); | ||
31 | private static final AnySymbolView featureView = new KeyOnlyView<>(feature); | ||
32 | private static final AnySymbolView isEncapsulatedByView = new KeyOnlyView<>(isEncapsulatedBy); | ||
33 | private static final AnySymbolView encapsulatesView = new KeyOnlyView<>(encapsulates); | ||
34 | private static final AnySymbolView featuresView = new KeyOnlyView<>(features); | ||
35 | private static final AnySymbolView classesView = new KeyOnlyView<>(classes); | ||
36 | |||
37 | // @Test | ||
38 | // void createObjectTest() { | ||
39 | // var store = ModelStore.builder() | ||
40 | // .with(ViatraModelQueryAdapter.builder()) | ||
41 | // .with(DesignSpaceExplorationAdapter.builder() | ||
42 | // .strategy(new DepthFirstStrategy().withDepthLimit(0))) | ||
43 | // .build(); | ||
44 | // | ||
45 | // var model = store.createEmptyModel(); | ||
46 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
47 | // | ||
48 | // assertEquals(0, dseAdapter.getModelSize()); | ||
49 | // | ||
50 | // var newModel = dseAdapter.createObject(); | ||
51 | // var newModelId = newModel.get(0); | ||
52 | // var newClass1 = dseAdapter.createObject(); | ||
53 | // var newClass1Id = newClass1.get(0); | ||
54 | // var newClass2 = dseAdapter.createObject(); | ||
55 | // var newClass2Id = newClass2.get(0); | ||
56 | // var newField = dseAdapter.createObject(); | ||
57 | // var newFieldId = newField.get(0); | ||
58 | // | ||
59 | // assertEquals(0, newModelId); | ||
60 | // assertEquals(1, newClass1Id); | ||
61 | // assertEquals(2, newClass2Id); | ||
62 | // assertEquals(3, newFieldId); | ||
63 | // assertEquals(4, dseAdapter.getModelSize()); | ||
64 | // } | ||
65 | |||
66 | // @Test | ||
67 | // void deleteMiddleObjectTest() { | ||
68 | // var store = ModelStore.builder() | ||
69 | // .with(ViatraModelQueryAdapter.builder()) | ||
70 | // .with(DesignSpaceExplorationAdapter.builder() | ||
71 | // .strategy(new DepthFirstStrategy())) | ||
72 | // .build(); | ||
73 | // | ||
74 | // var model = store.createEmptyModel(); | ||
75 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
76 | // | ||
77 | // assertEquals(0, dseAdapter.getModelSize()); | ||
78 | // | ||
79 | // var newObject0 = dseAdapter.createObject(); | ||
80 | // var newObject0Id = newObject0.get(0); | ||
81 | // var newObject1 = dseAdapter.createObject(); | ||
82 | // var newObject1Id = newObject1.get(0); | ||
83 | // var newObject2 = dseAdapter.createObject(); | ||
84 | // var newObject2Id = newObject2.get(0); | ||
85 | // var newObject3 = dseAdapter.createObject(); | ||
86 | // var newObject3Id = newObject3.get(0); | ||
87 | // | ||
88 | // assertEquals(0, newObject0Id); | ||
89 | // assertEquals(1, newObject1Id); | ||
90 | // assertEquals(2, newObject2Id); | ||
91 | // assertEquals(3, newObject3Id); | ||
92 | // assertEquals(4, dseAdapter.getModelSize()); | ||
93 | // | ||
94 | // dseAdapter.deleteObject(newObject1); | ||
95 | // assertEquals(4, dseAdapter.getModelSize()); | ||
96 | // | ||
97 | // var newObject4 = dseAdapter.createObject(); | ||
98 | // var newObject4Id = newObject4.get(0); | ||
99 | // assertEquals(4, newObject4Id); | ||
100 | // assertEquals(5, dseAdapter.getModelSize()); | ||
101 | // | ||
102 | // dseAdapter.deleteObject(newObject4); | ||
103 | // assertEquals(5, dseAdapter.getModelSize()); | ||
104 | // } | ||
105 | // | ||
106 | // @Test | ||
107 | // void DFSTrivialTest() { | ||
108 | // var store = ModelStore.builder() | ||
109 | // .symbols(classModel) | ||
110 | // .with(ViatraModelQueryAdapter.builder()) | ||
111 | // .with(DesignSpaceExplorationAdapter.builder() | ||
112 | // .strategy(new DepthFirstStrategy().withDepthLimit(0))) | ||
113 | // .build(); | ||
114 | // | ||
115 | // var model = store.createEmptyModel(); | ||
116 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
117 | // | ||
118 | // var states = dseAdapter.explore(); | ||
119 | // assertEquals(1, states.size()); | ||
120 | // } | ||
121 | // | ||
122 | // @Test | ||
123 | // void DFSOneRuleTest() { | ||
124 | // var createClassPrecondition = Query.of("CreateClassPrecondition", | ||
125 | // (builder, model) -> builder.clause( | ||
126 | // classModelView.call(model) | ||
127 | // )); | ||
128 | // | ||
129 | // var createClassRule = new TransformationRule("CreateClass", | ||
130 | // createClassPrecondition, | ||
131 | // (model) -> { | ||
132 | // var classesInterpretation = model.getInterpretation(classes); | ||
133 | // var classElementInterpretation = model.getInterpretation(classElement); | ||
134 | // return ((Tuple activation) -> { | ||
135 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
136 | // var modelElement = activation.get(0); | ||
137 | // | ||
138 | // var newClassElement = dseAdapter.createObject(); | ||
139 | // var newClassElementId = newClassElement.get(0); | ||
140 | // | ||
141 | // classesInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
142 | // classElementInterpretation.put(Tuple.of(newClassElementId), true); | ||
143 | // }); | ||
144 | // }); | ||
145 | // | ||
146 | // var store = ModelStore.builder() | ||
147 | // .symbols(classModel, classElement, classes) | ||
148 | // .with(ViatraModelQueryAdapter.builder() | ||
149 | // .queries(createClassPrecondition)) | ||
150 | // .with(DesignSpaceExplorationAdapter.builder() | ||
151 | // .transformations(createClassRule) | ||
152 | // .strategy(new DepthFirstStrategy().withDepthLimit(0) | ||
153 | // )) | ||
154 | // .build(); | ||
155 | // | ||
156 | // var model = store.createEmptyModel(); | ||
157 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
158 | // var queryEngine = model.getAdapter(ModelQueryAdapter.class); | ||
159 | // | ||
160 | // var modelElementInterpretation = model.getInterpretation(classModel); | ||
161 | // modelElementInterpretation.put(dseAdapter.createObject(), true); | ||
162 | // queryEngine.flushChanges(); | ||
163 | // | ||
164 | // var states = dseAdapter.explore(); | ||
165 | // assertEquals(1, states.size()); | ||
166 | // } | ||
167 | // | ||
168 | // @Test | ||
169 | // void DFSContinueTest() { | ||
170 | // var createClassPrecondition = Query.of("CreateClassPrecondition", | ||
171 | // (builder, model) -> builder.clause( | ||
172 | // classModelView.call(model) | ||
173 | // )); | ||
174 | // | ||
175 | // var createClassRule = new TransformationRule("CreateClass", | ||
176 | // createClassPrecondition, | ||
177 | // (model) -> { | ||
178 | // var classesInterpretation = model.getInterpretation(classes); | ||
179 | // var classElementInterpretation = model.getInterpretation(classElement); | ||
180 | // return ((Tuple activation) -> { | ||
181 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
182 | // var modelElement = activation.get(0); | ||
183 | // | ||
184 | // var newClassElement = dseAdapter.createObject(); | ||
185 | // var newClassElementId = newClassElement.get(0); | ||
186 | // | ||
187 | // classesInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
188 | // classElementInterpretation.put(Tuple.of(newClassElementId), true); | ||
189 | // }); | ||
190 | // }); | ||
191 | // | ||
192 | // var store = ModelStore.builder() | ||
193 | // .symbols(classModel, classElement, classes) | ||
194 | // .with(ViatraModelQueryAdapter.builder() | ||
195 | // .queries(createClassPrecondition)) | ||
196 | // .with(DesignSpaceExplorationAdapter.builder() | ||
197 | // .transformations(createClassRule) | ||
198 | // .strategy(new DepthFirstStrategy().withDepthLimit(4).continueIfHardObjectivesFulfilled() | ||
199 | // )) | ||
200 | // .build(); | ||
201 | // | ||
202 | // var model = store.createEmptyModel(); | ||
203 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
204 | // var queryEngine = model.getAdapter(ModelQueryAdapter.class); | ||
205 | // | ||
206 | // var modelElementInterpretation = model.getInterpretation(classModel); | ||
207 | // modelElementInterpretation.put(dseAdapter.createObject(), true); | ||
208 | // queryEngine.flushChanges(); | ||
209 | // | ||
210 | // var states = dseAdapter.explore(); | ||
211 | // assertEquals(5, states.size()); | ||
212 | // } | ||
213 | // | ||
214 | // @Test | ||
215 | // void DFSCompletenessTest() { | ||
216 | // var createClassPrecondition = Query.of("CreateClassPrecondition", | ||
217 | // (builder, model) -> builder.clause( | ||
218 | // classModelView.call(model) | ||
219 | // )); | ||
220 | // | ||
221 | // var createClassRule = new TransformationRule("CreateClass", | ||
222 | // createClassPrecondition, | ||
223 | // (model) -> { | ||
224 | // var classesInterpretation = model.getInterpretation(classes); | ||
225 | // var classElementInterpretation = model.getInterpretation(classElement); | ||
226 | // return ((Tuple activation) -> { | ||
227 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
228 | // var modelElement = activation.get(0); | ||
229 | // | ||
230 | // var newClassElement = dseAdapter.createObject(); | ||
231 | // var newClassElementId = newClassElement.get(0); | ||
232 | // | ||
233 | // classesInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
234 | // classElementInterpretation.put(Tuple.of(newClassElementId), true); | ||
235 | // }); | ||
236 | // }); | ||
237 | // | ||
238 | // var createFeaturePrecondition = Query.of("CreateFeaturePrecondition", | ||
239 | // (builder, model) -> builder.clause( | ||
240 | // classModelView.call(model) | ||
241 | // )); | ||
242 | // | ||
243 | // var createFeatureRule = new TransformationRule("CreateFeature", | ||
244 | // createFeaturePrecondition, | ||
245 | // (model) -> { | ||
246 | // var featuresInterpretation = model.getInterpretation(features); | ||
247 | // var featureInterpretation = model.getInterpretation(feature); | ||
248 | // return ((Tuple activation) -> { | ||
249 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
250 | // var modelElement = activation.get(0); | ||
251 | // | ||
252 | // var newClassElement = dseAdapter.createObject(); | ||
253 | // var newClassElementId = newClassElement.get(0); | ||
254 | // | ||
255 | // featuresInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
256 | // featureInterpretation.put(Tuple.of(newClassElementId), true); | ||
257 | // }); | ||
258 | // }); | ||
259 | // | ||
260 | // var store = ModelStore.builder() | ||
261 | // .symbols(classModel, classElement, classes, feature, features, isEncapsulatedBy, encapsulates) | ||
262 | // .with(ViatraModelQueryAdapter.builder() | ||
263 | // .queries(createClassPrecondition, createFeaturePrecondition)) | ||
264 | // .with(DesignSpaceExplorationAdapter.builder() | ||
265 | // .transformations(createClassRule, createFeatureRule) | ||
266 | // .strategy(new DepthFirstStrategy().withDepthLimit(10).continueIfHardObjectivesFulfilled() | ||
267 | // )) | ||
268 | // .build(); | ||
269 | // | ||
270 | // var model = store.createEmptyModel(); | ||
271 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
272 | // var queryEngine = model.getAdapter(ModelQueryAdapter.class); | ||
273 | // | ||
274 | // var modelElementInterpretation = model.getInterpretation(classModel); | ||
275 | // modelElementInterpretation.put(dseAdapter.createObject(), true); | ||
276 | // queryEngine.flushChanges(); | ||
277 | // | ||
278 | // var states = dseAdapter.explore(); | ||
279 | // assertEquals(2047, states.size()); | ||
280 | // } | ||
281 | // | ||
282 | // @Test | ||
283 | // void DFSSolutionLimitTest() { | ||
284 | // var createClassPrecondition = Query.of("CreateClassPrecondition", | ||
285 | // (builder, model) -> builder.clause( | ||
286 | // classModelView.call(model) | ||
287 | // )); | ||
288 | // | ||
289 | // var createClassRule = new TransformationRule("CreateClass", | ||
290 | // createClassPrecondition, | ||
291 | // (model) -> { | ||
292 | // var classesInterpretation = model.getInterpretation(classes); | ||
293 | // var classElementInterpretation = model.getInterpretation(classElement); | ||
294 | // return ((Tuple activation) -> { | ||
295 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
296 | // var modelElement = activation.get(0); | ||
297 | // | ||
298 | // var newClassElement = dseAdapter.createObject(); | ||
299 | // var newClassElementId = newClassElement.get(0); | ||
300 | // | ||
301 | // classesInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
302 | // classElementInterpretation.put(Tuple.of(newClassElementId), true); | ||
303 | // }); | ||
304 | // }); | ||
305 | // | ||
306 | // var createFeaturePrecondition = Query.of("CreateFeaturePrecondition", | ||
307 | // (builder, model) -> builder.clause( | ||
308 | // classModelView.call(model) | ||
309 | // )); | ||
310 | // | ||
311 | // var createFeatureRule = new TransformationRule("CreateFeature", | ||
312 | // createFeaturePrecondition, | ||
313 | // (model) -> { | ||
314 | // var featuresInterpretation = model.getInterpretation(features); | ||
315 | // var featureInterpretation = model.getInterpretation(feature); | ||
316 | // return ((Tuple activation) -> { | ||
317 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
318 | // var modelElement = activation.get(0); | ||
319 | // | ||
320 | // var newClassElement = dseAdapter.createObject(); | ||
321 | // var newClassElementId = newClassElement.get(0); | ||
322 | // | ||
323 | // featuresInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
324 | // featureInterpretation.put(Tuple.of(newClassElementId), true); | ||
325 | // }); | ||
326 | // }); | ||
327 | // | ||
328 | // var store = ModelStore.builder() | ||
329 | // .symbols(classModel, classElement, classes, feature, features, isEncapsulatedBy, encapsulates) | ||
330 | // .with(ViatraModelQueryAdapter.builder() | ||
331 | // .queries(createClassPrecondition, createFeaturePrecondition)) | ||
332 | // .with(DesignSpaceExplorationAdapter.builder() | ||
333 | // .transformations(createClassRule, createFeatureRule) | ||
334 | // .strategy(new DepthFirstStrategy().withSolutionLimit(222) | ||
335 | // .continueIfHardObjectivesFulfilled() | ||
336 | // )) | ||
337 | // .build(); | ||
338 | // | ||
339 | // var model = store.createEmptyModel(); | ||
340 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
341 | // var queryEngine = model.getAdapter(ModelQueryAdapter.class); | ||
342 | // | ||
343 | // var modelElementInterpretation = model.getInterpretation(classModel); | ||
344 | // modelElementInterpretation.put(dseAdapter.createObject(), true); | ||
345 | // queryEngine.flushChanges(); | ||
346 | // | ||
347 | // var states = dseAdapter.explore(); | ||
348 | // assertEquals(222, states.size()); | ||
349 | // } | ||
350 | // | ||
351 | // @Test | ||
352 | // void BeFSTrivialTest() { | ||
353 | // var store = ModelStore.builder() | ||
354 | // .symbols(classModel) | ||
355 | // .with(ViatraModelQueryAdapter.builder()) | ||
356 | // .with(DesignSpaceExplorationAdapter.builder() | ||
357 | // .strategy(new BestFirstStrategy().withDepthLimit(0))) | ||
358 | // .build(); | ||
359 | // | ||
360 | // var model = store.createEmptyModel(); | ||
361 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
362 | // | ||
363 | // var states = dseAdapter.explore(); | ||
364 | // assertEquals(1, states.size()); | ||
365 | // } | ||
366 | // | ||
367 | // @Test | ||
368 | // void BeFSOneRuleTest() { | ||
369 | // var createClassPrecondition = Query.of("CreateClassPrecondition", | ||
370 | // (builder, model) -> builder.clause( | ||
371 | // classModelView.call(model) | ||
372 | // )); | ||
373 | // | ||
374 | // var createClassRule = new TransformationRule("CreateClass", | ||
375 | // createClassPrecondition, | ||
376 | // (model) -> { | ||
377 | // var classesInterpretation = model.getInterpretation(classes); | ||
378 | // var classElementInterpretation = model.getInterpretation(classElement); | ||
379 | // return ((Tuple activation) -> { | ||
380 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
381 | // var modelElement = activation.get(0); | ||
382 | // | ||
383 | // var newClassElement = dseAdapter.createObject(); | ||
384 | // var newClassElementId = newClassElement.get(0); | ||
385 | // | ||
386 | // classesInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
387 | // classElementInterpretation.put(Tuple.of(newClassElementId), true); | ||
388 | // }); | ||
389 | // }); | ||
390 | // | ||
391 | // var store = ModelStore.builder() | ||
392 | // .symbols(classModel, classElement, classes) | ||
393 | // .with(ViatraModelQueryAdapter.builder() | ||
394 | // .queries(createClassPrecondition)) | ||
395 | // .with(DesignSpaceExplorationAdapter.builder() | ||
396 | // .transformations(createClassRule) | ||
397 | // .strategy(new BestFirstStrategy().withDepthLimit(4) | ||
398 | // )) | ||
399 | // .build(); | ||
400 | // | ||
401 | // var model = store.createEmptyModel(); | ||
402 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
403 | // var queryEngine = model.getAdapter(ModelQueryAdapter.class); | ||
404 | // | ||
405 | // var modelElementInterpretation = model.getInterpretation(classModel); | ||
406 | // modelElementInterpretation.put(dseAdapter.createObject(), true); | ||
407 | // queryEngine.flushChanges(); | ||
408 | // | ||
409 | // var states = dseAdapter.explore(); | ||
410 | // assertEquals(1, states.size()); | ||
411 | // } | ||
412 | // | ||
413 | // @Test | ||
414 | // void BeFSContinueTest() { | ||
415 | // var createClassPrecondition = Query.of("CreateClassPrecondition", | ||
416 | // (builder, model) -> builder.clause( | ||
417 | // classModelView.call(model) | ||
418 | // )); | ||
419 | // | ||
420 | // var createClassRule = new TransformationRule("CreateClass", | ||
421 | // createClassPrecondition, | ||
422 | // (model) -> { | ||
423 | // var classesInterpretation = model.getInterpretation(classes); | ||
424 | // var classElementInterpretation = model.getInterpretation(classElement); | ||
425 | // return ((Tuple activation) -> { | ||
426 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
427 | // var modelElement = activation.get(0); | ||
428 | // | ||
429 | // var newClassElement = dseAdapter.createObject(); | ||
430 | // var newClassElementId = newClassElement.get(0); | ||
431 | // | ||
432 | // classesInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
433 | // classElementInterpretation.put(Tuple.of(newClassElementId), true); | ||
434 | // }); | ||
435 | // }); | ||
436 | // | ||
437 | // var store = ModelStore.builder() | ||
438 | // .symbols(classModel, classElement, classes) | ||
439 | // .with(ViatraModelQueryAdapter.builder() | ||
440 | // .queries(createClassPrecondition)) | ||
441 | // .with(DesignSpaceExplorationAdapter.builder() | ||
442 | // .transformations(createClassRule) | ||
443 | // .strategy(new BestFirstStrategy().withDepthLimit(4).continueIfHardObjectivesFulfilled() | ||
444 | // )) | ||
445 | // .build(); | ||
446 | // | ||
447 | // var model = store.createEmptyModel(); | ||
448 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
449 | // var queryEngine = model.getAdapter(ModelQueryAdapter.class); | ||
450 | // | ||
451 | // var modelElementInterpretation = model.getInterpretation(classModel); | ||
452 | // modelElementInterpretation.put(dseAdapter.createObject(), true); | ||
453 | // queryEngine.flushChanges(); | ||
454 | // | ||
455 | // var states = dseAdapter.explore(); | ||
456 | // assertEquals(5, states.size()); | ||
457 | // } | ||
458 | // | ||
459 | // @Test | ||
460 | // void BeFSCompletenessTest() { | ||
461 | // var createClassPrecondition = Query.of("CreateClassPrecondition", | ||
462 | // (builder, model) -> builder.clause( | ||
463 | // classModelView.call(model) | ||
464 | // )); | ||
465 | // | ||
466 | // var createClassRule = new TransformationRule("CreateClass", | ||
467 | // createClassPrecondition, | ||
468 | // (model) -> { | ||
469 | // var classesInterpretation = model.getInterpretation(classes); | ||
470 | // var classElementInterpretation = model.getInterpretation(classElement); | ||
471 | // return ((Tuple activation) -> { | ||
472 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
473 | // var modelElement = activation.get(0); | ||
474 | // | ||
475 | // var newClassElement = dseAdapter.createObject(); | ||
476 | // var newClassElementId = newClassElement.get(0); | ||
477 | // | ||
478 | // classesInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
479 | // classElementInterpretation.put(Tuple.of(newClassElementId), true); | ||
480 | // }); | ||
481 | // }); | ||
482 | // | ||
483 | // var createFeaturePrecondition = Query.of("CreateFeaturePrecondition", | ||
484 | // (builder, model) -> builder.clause( | ||
485 | // classModelView.call(model) | ||
486 | // )); | ||
487 | // | ||
488 | // var createFeatureRule = new TransformationRule("CreateFeature", | ||
489 | // createFeaturePrecondition, | ||
490 | // (model) -> { | ||
491 | // var featuresInterpretation = model.getInterpretation(features); | ||
492 | // var featureInterpretation = model.getInterpretation(feature); | ||
493 | // return ((Tuple activation) -> { | ||
494 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
495 | // var modelElement = activation.get(0); | ||
496 | // | ||
497 | // var newClassElement = dseAdapter.createObject(); | ||
498 | // var newClassElementId = newClassElement.get(0); | ||
499 | // | ||
500 | // featuresInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
501 | // featureInterpretation.put(Tuple.of(newClassElementId), true); | ||
502 | // }); | ||
503 | // }); | ||
504 | // | ||
505 | // var store = ModelStore.builder() | ||
506 | // .symbols(classModel, classElement, classes, feature, features, isEncapsulatedBy, encapsulates) | ||
507 | // .with(ViatraModelQueryAdapter.builder() | ||
508 | // .queries(createClassPrecondition, createFeaturePrecondition)) | ||
509 | // .with(DesignSpaceExplorationAdapter.builder() | ||
510 | // .transformations(createClassRule, createFeatureRule) | ||
511 | // .strategy(new BestFirstStrategy().withDepthLimit(10).continueIfHardObjectivesFulfilled() | ||
512 | // )) | ||
513 | // .build(); | ||
514 | // | ||
515 | // var model = store.createEmptyModel(); | ||
516 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
517 | // var queryEngine = model.getAdapter(ModelQueryAdapter.class); | ||
518 | // | ||
519 | // var modelElementInterpretation = model.getInterpretation(classModel); | ||
520 | // modelElementInterpretation.put(dseAdapter.createObject(), true); | ||
521 | // queryEngine.flushChanges(); | ||
522 | // | ||
523 | // var states = dseAdapter.explore(); | ||
524 | // assertEquals(2047, states.size()); | ||
525 | // } | ||
526 | // | ||
527 | // @Test | ||
528 | // void BeFSSolutionLimitTest() { | ||
529 | // var createClassPrecondition = Query.of("CreateClassPrecondition", | ||
530 | // (builder, model) -> builder.clause( | ||
531 | // classModelView.call(model) | ||
532 | // )); | ||
533 | // | ||
534 | // var createClassRule = new TransformationRule("CreateClass", | ||
535 | // createClassPrecondition, | ||
536 | // (model) -> { | ||
537 | // var classesInterpretation = model.getInterpretation(classes); | ||
538 | // var classElementInterpretation = model.getInterpretation(classElement); | ||
539 | // return ((Tuple activation) -> { | ||
540 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
541 | // var modelElement = activation.get(0); | ||
542 | // | ||
543 | // var newClassElement = dseAdapter.createObject(); | ||
544 | // var newClassElementId = newClassElement.get(0); | ||
545 | // | ||
546 | // classesInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
547 | // classElementInterpretation.put(Tuple.of(newClassElementId), true); | ||
548 | // }); | ||
549 | // }); | ||
550 | // | ||
551 | // var createFeaturePrecondition = Query.of("CreateFeaturePrecondition", | ||
552 | // (builder, model) -> builder.clause( | ||
553 | // classModelView.call(model) | ||
554 | // )); | ||
555 | // | ||
556 | // var createFeatureRule = new TransformationRule("CreateFeature", | ||
557 | // createFeaturePrecondition, | ||
558 | // (model) -> { | ||
559 | // var featuresInterpretation = model.getInterpretation(features); | ||
560 | // var featureInterpretation = model.getInterpretation(feature); | ||
561 | // return ((Tuple activation) -> { | ||
562 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
563 | // var modelElement = activation.get(0); | ||
564 | // | ||
565 | // var newClassElement = dseAdapter.createObject(); | ||
566 | // var newClassElementId = newClassElement.get(0); | ||
567 | // | ||
568 | // featuresInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | ||
569 | // featureInterpretation.put(Tuple.of(newClassElementId), true); | ||
570 | // }); | ||
571 | // }); | ||
572 | // | ||
573 | // var store = ModelStore.builder() | ||
574 | // .symbols(classModel, classElement, classes, feature, features, isEncapsulatedBy, encapsulates) | ||
575 | // .with(ViatraModelQueryAdapter.builder() | ||
576 | // .queries(createClassPrecondition, createFeaturePrecondition)) | ||
577 | // .with(DesignSpaceExplorationAdapter.builder() | ||
578 | // .transformations(createClassRule, createFeatureRule) | ||
579 | // .strategy(new BestFirstStrategy().withSolutionLimit(222) | ||
580 | // .continueIfHardObjectivesFulfilled() | ||
581 | // )) | ||
582 | // .build(); | ||
583 | // | ||
584 | // var model = store.createEmptyModel(); | ||
585 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | ||
586 | // var queryEngine = model.getAdapter(ModelQueryAdapter.class); | ||
587 | // | ||
588 | // var modelElementInterpretation = model.getInterpretation(classModel); | ||
589 | // modelElementInterpretation.put(dseAdapter.createObject(), true); | ||
590 | // queryEngine.flushChanges(); | ||
591 | // | ||
592 | // var states = dseAdapter.explore(); | ||
593 | // assertEquals(222, states.size()); | ||
594 | // } | ||
595 | |||
596 | } | ||
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 | } | ||
diff --git a/subprojects/store-dse/src/test/java/tools/refinery/store/dse/tests/QueryAssertions.java b/subprojects/store-dse/src/test/java/tools/refinery/store/dse/tests/QueryAssertions.java index be514eaf..f0a20720 100644 --- a/subprojects/store-dse/src/test/java/tools/refinery/store/dse/tests/QueryAssertions.java +++ b/subprojects/store-dse/src/test/java/tools/refinery/store/dse/tests/QueryAssertions.java | |||
@@ -30,7 +30,7 @@ public final class QueryAssertions { | |||
30 | } | 30 | } |
31 | 31 | ||
32 | public static <T> void assertResults(Map<Tuple, T> expected, ResultSet<T> resultSet) { | 32 | public static <T> void assertResults(Map<Tuple, T> expected, ResultSet<T> resultSet) { |
33 | var defaultValue = resultSet.getQuery().defaultValue(); | 33 | var defaultValue = resultSet.getCanonicalQuery().defaultValue(); |
34 | var filteredExpected = new LinkedHashMap<Tuple, T>(); | 34 | var filteredExpected = new LinkedHashMap<Tuple, T>(); |
35 | var executables = new ArrayList<Executable>(); | 35 | var executables = new ArrayList<Executable>(); |
36 | for (var entry : expected.entrySet()) { | 36 | for (var entry : expected.entrySet()) { |
diff --git a/subprojects/store-dse/src/test/java/tools/refinery/store/dse/transition/TransitionTests.java b/subprojects/store-dse/src/test/java/tools/refinery/store/dse/transition/TransitionTests.java index b89360cb..42a0f89b 100644 --- a/subprojects/store-dse/src/test/java/tools/refinery/store/dse/transition/TransitionTests.java +++ b/subprojects/store-dse/src/test/java/tools/refinery/store/dse/transition/TransitionTests.java | |||
@@ -7,16 +7,14 @@ package tools.refinery.store.dse.transition; | |||
7 | 7 | ||
8 | import org.junit.jupiter.api.Test; | 8 | import org.junit.jupiter.api.Test; |
9 | import tools.refinery.store.dse.modification.ModificationAdapter; | 9 | import tools.refinery.store.dse.modification.ModificationAdapter; |
10 | import tools.refinery.store.dse.transition.objectives.QueryCriteria; | 10 | import tools.refinery.store.dse.transition.objectives.Criteria; |
11 | import tools.refinery.store.dse.transition.objectives.QueryObjective; | 11 | import tools.refinery.store.dse.transition.objectives.Objectives; |
12 | import tools.refinery.store.model.Model; | 12 | import tools.refinery.store.model.Model; |
13 | import tools.refinery.store.model.ModelStore; | 13 | import tools.refinery.store.model.ModelStore; |
14 | import tools.refinery.store.query.ModelQueryAdapter; | 14 | import tools.refinery.store.query.ModelQueryAdapter; |
15 | import tools.refinery.store.query.dnf.FunctionalQuery; | 15 | import tools.refinery.store.query.dnf.FunctionalQuery; |
16 | import tools.refinery.store.query.dnf.Query; | 16 | import tools.refinery.store.query.dnf.Query; |
17 | import tools.refinery.store.query.dnf.RelationalQuery; | 17 | import tools.refinery.store.query.dnf.RelationalQuery; |
18 | import tools.refinery.store.query.literal.CallPolarity; | ||
19 | import tools.refinery.store.query.literal.Literals; | ||
20 | import tools.refinery.store.query.term.Variable; | 18 | import tools.refinery.store.query.term.Variable; |
21 | import tools.refinery.store.query.term.int_.IntTerms; | 19 | import tools.refinery.store.query.term.int_.IntTerms; |
22 | import tools.refinery.store.query.viatra.ViatraModelQueryAdapter; | 20 | import tools.refinery.store.query.viatra.ViatraModelQueryAdapter; |
@@ -29,33 +27,33 @@ import tools.refinery.store.tuple.Tuple; | |||
29 | import java.util.List; | 27 | import java.util.List; |
30 | 28 | ||
31 | import static org.junit.jupiter.api.Assertions.*; | 29 | import static org.junit.jupiter.api.Assertions.*; |
30 | import static tools.refinery.store.query.literal.Literals.check; | ||
31 | import static tools.refinery.store.query.literal.Literals.not; | ||
32 | 32 | ||
33 | class TransitionBuildTests { | 33 | class TransitionBuildTests { |
34 | Symbol<Boolean> person = new Symbol<>("Person", 1, Boolean.class, false); | 34 | Symbol<Boolean> person = new Symbol<>("Person", 1, Boolean.class, false); |
35 | Symbol<Boolean> friend = new Symbol<>("friend", 2, Boolean.class, false); | 35 | Symbol<Boolean> friend = new Symbol<>("friend", 2, Boolean.class, false); |
36 | |||
36 | AnySymbolView personView = new KeyOnlyView<>(person); | 37 | AnySymbolView personView = new KeyOnlyView<>(person); |
37 | AnySymbolView friendView = new KeyOnlyView<>(friend); | 38 | AnySymbolView friendView = new KeyOnlyView<>(friend); |
38 | 39 | ||
39 | /*RelationalQuery areNotFriends = Query.of("areNotFriends", | 40 | RelationalQuery moreThan3Friends = Query.of("moreThan3Friends", (builder, tooMuchFriends) -> builder |
40 | (builder, p1, p2) -> builder.clause( | 41 | .clause(Integer.class, (numberOfFriends) -> List.of( |
41 | personView.call(p1), | ||
42 | personView.call(p2), | ||
43 | not(friendView.call(p1, p2))))*/ | ||
44 | |||
45 | RelationalQuery moreThan3Friends = Query.of("moreThan3Friends", | ||
46 | (builder, tooMuchFriends) -> builder.clause(Integer.class, (numberOfFriends) -> List.of( | ||
47 | numberOfFriends.assign(friendView.count(tooMuchFriends, Variable.of())), | 42 | numberOfFriends.assign(friendView.count(tooMuchFriends, Variable.of())), |
48 | Literals.assume(IntTerms.less(IntTerms.constant(3), numberOfFriends)), | 43 | check(IntTerms.less(IntTerms.constant(3), numberOfFriends)), |
49 | personView.call(tooMuchFriends) | 44 | personView.call(tooMuchFriends) |
50 | ))); | 45 | ))); |
51 | 46 | ||
52 | RelationalQuery somebodyHasNoFriend = Query.of("somebodyHasNoFriend", | 47 | RelationalQuery somebodyHasNoFriend = Query.of("somebodyHasNoFriend", (builder, lonely) -> builder |
53 | (builder, lonely) -> builder.clause( | 48 | .clause( |
54 | personView.call(lonely), | 49 | personView.call(lonely), |
55 | friendView.call(CallPolarity.NEGATIVE, lonely, Variable.of()) | 50 | not(friendView.call(lonely, Variable.of())) |
51 | )); | ||
52 | |||
53 | FunctionalQuery<Integer> numberOfFriends = Query.of(Integer.class, (builder, output) -> builder | ||
54 | .clause( | ||
55 | output.assign(friendView.count(Variable.of(), Variable.of())) | ||
56 | )); | 56 | )); |
57 | FunctionalQuery<Integer> numberOfFriends = FunctionalQuery.of(Integer.class, | ||
58 | (builder, output) -> builder.clause(output.assign(friendView.count(Variable.of(), Variable.of())))); | ||
59 | 57 | ||
60 | @Test | 58 | @Test |
61 | void acceptTest() { | 59 | void acceptTest() { |
@@ -141,9 +139,9 @@ class TransitionBuildTests { | |||
141 | .with(StateCoderAdapter.builder()) | 139 | .with(StateCoderAdapter.builder()) |
142 | .with(ModificationAdapter.builder()) | 140 | .with(ModificationAdapter.builder()) |
143 | .with(DesignSpaceExplorationAdapter.builder() | 141 | .with(DesignSpaceExplorationAdapter.builder() |
144 | .objective(new QueryObjective(numberOfFriends)) | 142 | .objective(Objectives.value(numberOfFriends)) |
145 | .exclude(new QueryCriteria(moreThan3Friends, true)) | 143 | .exclude(Criteria.whenHasMatch(moreThan3Friends)) |
146 | .accept(new QueryCriteria(somebodyHasNoFriend, false))) | 144 | .accept(Criteria.whenNoMatch(somebodyHasNoFriend))) |
147 | .build(); | 145 | .build(); |
148 | 146 | ||
149 | return store.createEmptyModel(); | 147 | return store.createEmptyModel(); |