diff options
Diffstat (limited to 'subprojects/store-dse/src/test/java/tools')
3 files changed, 184 insertions, 129 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 36517709..f4c38b18 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 | |||
@@ -5,13 +5,28 @@ | |||
5 | */ | 5 | */ |
6 | package tools.refinery.store.dse; | 6 | package tools.refinery.store.dse; |
7 | 7 | ||
8 | import tools.refinery.store.dse.transition.TransformationRule; | 8 | import org.junit.jupiter.api.Disabled; |
9 | import org.junit.jupiter.api.Test; | ||
10 | import tools.refinery.store.dse.modification.ModificationAdapter; | ||
11 | import tools.refinery.store.dse.strategy.BestFirstStoreManager; | ||
12 | import tools.refinery.store.dse.transition.DesignSpaceExplorationAdapter; | ||
13 | import tools.refinery.store.dse.tests.DummyCriterion; | ||
14 | import tools.refinery.store.dse.tests.DummyObjective; | ||
15 | import tools.refinery.store.model.ModelStore; | ||
16 | import tools.refinery.store.query.ModelQueryAdapter; | ||
17 | import tools.refinery.store.query.dnf.FunctionalQuery; | ||
9 | import tools.refinery.store.query.dnf.Query; | 18 | import tools.refinery.store.query.dnf.Query; |
10 | import tools.refinery.store.query.dnf.RelationalQuery; | 19 | import tools.refinery.store.query.dnf.RelationalQuery; |
20 | import tools.refinery.store.dse.transition.TransformationRule; | ||
21 | import tools.refinery.store.query.term.Variable; | ||
22 | import tools.refinery.store.query.viatra.ViatraModelQueryAdapter; | ||
11 | import tools.refinery.store.query.view.AnySymbolView; | 23 | import tools.refinery.store.query.view.AnySymbolView; |
12 | import tools.refinery.store.query.view.KeyOnlyView; | 24 | import tools.refinery.store.query.view.KeyOnlyView; |
13 | import tools.refinery.store.representation.Symbol; | 25 | import tools.refinery.store.representation.Symbol; |
26 | import tools.refinery.store.statecoding.StateCoderAdapter; | ||
14 | import tools.refinery.store.tuple.Tuple; | 27 | import tools.refinery.store.tuple.Tuple; |
28 | import tools.refinery.visualization.ModelVisualizerAdapter; | ||
29 | import tools.refinery.visualization.internal.FileFormat; | ||
15 | 30 | ||
16 | import java.util.List; | 31 | import java.util.List; |
17 | 32 | ||
@@ -121,42 +136,42 @@ class CRAExamplesTest { | |||
121 | }); | 136 | }); |
122 | }); | 137 | }); |
123 | 138 | ||
124 | // private static final TransformationRule deleteEmptyClassRule = new TransformationRule("DeleteEmptyClass", | 139 | private static final TransformationRule deleteEmptyClassRule = new TransformationRule("DeleteEmptyClass", |
125 | // deleteEmptyClassPrecondition, | 140 | deleteEmptyClassPrecondition, |
126 | // (model) -> { | 141 | (model) -> { |
127 | //// var classesInterpretation = model.getInterpretation(classes); | 142 | // var classesInterpretation = model.getInterpretation(classes); |
128 | // var classElementInterpretation = model.getInterpretation(classElement); | 143 | var classElementInterpretation = model.getInterpretation(classElement); |
129 | // return ((Tuple activation) -> { | 144 | return ((Tuple activation) -> { |
130 | // // TODO: can we move dseAdapter outside? | 145 | // TODO: can we move modificationAdapter outside? |
131 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | 146 | var modificationAdapter = model.getAdapter(ModificationAdapter.class); |
132 | //// var modelElement = activation.get(0); | 147 | // var modelElement = activation.get(0); |
133 | // var classElement = activation.get(0); | 148 | var classElement = activation.get(0); |
134 | // | 149 | |
135 | //// classesInterpretation.put(Tuple.of(modelElement, classElement), false); | 150 | // classesInterpretation.put(Tuple.of(modelElement, classElement), false); |
136 | // classElementInterpretation.put(Tuple.of(classElement), false); | 151 | classElementInterpretation.put(Tuple.of(classElement), false); |
137 | // dseAdapter.deleteObject(Tuple.of(classElement)); | 152 | modificationAdapter.deleteObject(Tuple.of(classElement)); |
138 | // }); | 153 | }); |
139 | // }); | 154 | }); |
140 | 155 | ||
141 | // private static final TransformationRule createClassRule = new TransformationRule("CreateClass", | 156 | private static final TransformationRule createClassRule = new TransformationRule("CreateClass", |
142 | // createClassPrecondition, | 157 | createClassPrecondition, |
143 | // (model) -> { | 158 | (model) -> { |
144 | // var classElementInterpretation = model.getInterpretation(classElement); | 159 | var classElementInterpretation = model.getInterpretation(classElement); |
145 | //// var classesInterpretation = model.getInterpretation(classes); | 160 | // var classesInterpretation = model.getInterpretation(classes); |
146 | // var encapsulatesInterpretation = model.getInterpretation(encapsulates); | 161 | var encapsulatesInterpretation = model.getInterpretation(encapsulates); |
147 | // return ((Tuple activation) -> { | 162 | return ((Tuple activation) -> { |
148 | // // TODO: can we move dseAdapter outside? | 163 | // TODO: can we move modificationAdapter outside? |
149 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | 164 | var modificationAdapter = model.getAdapter(ModificationAdapter.class); |
150 | //// var modelElement = activation.get(0); | 165 | // var modelElement = activation.get(0); |
151 | // var feature = activation.get(0); | 166 | var feature = activation.get(0); |
152 | // | 167 | |
153 | // var newClassElement = dseAdapter.createObject(); | 168 | var newClassElement = modificationAdapter.createObject(); |
154 | // var newClassElementId = newClassElement.get(0); | 169 | var newClassElementId = newClassElement.get(0); |
155 | // classElementInterpretation.put(newClassElement, true); | 170 | classElementInterpretation.put(newClassElement, true); |
156 | //// classesInterpretation.put(Tuple.of(modelElement, newClassElementId), true); | 171 | // classesInterpretation.put(Tuple.of(modelElement, newClassElementId), true); |
157 | // encapsulatesInterpretation.put(Tuple.of(newClassElementId, feature), true); | 172 | encapsulatesInterpretation.put(Tuple.of(newClassElementId, feature), true); |
158 | // }); | 173 | }); |
159 | // }); | 174 | }); |
160 | 175 | ||
161 | private static final TransformationRule moveFeatureRule = new TransformationRule("MoveFeature", | 176 | private static final TransformationRule moveFeatureRule = new TransformationRule("MoveFeature", |
162 | moveFeaturePrecondition, | 177 | moveFeaturePrecondition, |
@@ -172,16 +187,16 @@ class CRAExamplesTest { | |||
172 | }); | 187 | }); |
173 | }); | 188 | }); |
174 | 189 | ||
175 | // @Test | 190 | @Test |
176 | // @Disabled("This test is only for debugging purposes") | 191 | // @Disabled("This test is only for debugging purposes") |
177 | // void craTest() { | 192 | void craTest() { |
178 | // var store = ModelStore.builder() | 193 | var store = ModelStore.builder() |
179 | // .symbols(classElement, encapsulates, classes, features, attribute, method, dataDependency, | 194 | .symbols(classElement, encapsulates, classes, features, attribute, method, dataDependency, |
180 | // functionalDependency, name) | 195 | functionalDependency, name) |
181 | // .with(ViatraModelQueryAdapter.builder() | 196 | .with(ViatraModelQueryAdapter.builder() |
182 | // .queries(feature, assignFeaturePreconditionHelper, assignFeaturePrecondition, | 197 | .queries(feature, assignFeaturePreconditionHelper, assignFeaturePrecondition, |
183 | // deleteEmptyClassPrecondition, createClassPreconditionHelper, createClassPrecondition, | 198 | deleteEmptyClassPrecondition, createClassPreconditionHelper, createClassPrecondition, |
184 | // moveFeaturePrecondition)) | 199 | moveFeaturePrecondition)) |
185 | // .with(ModelVisualizerAdapter.builder() | 200 | // .with(ModelVisualizerAdapter.builder() |
186 | // .withOutputpath("test_output") | 201 | // .withOutputpath("test_output") |
187 | // .withFormat(FileFormat.DOT) | 202 | // .withFormat(FileFormat.DOT) |
@@ -189,89 +204,99 @@ class CRAExamplesTest { | |||
189 | // .saveStates() | 204 | // .saveStates() |
190 | // .saveDesignSpace() | 205 | // .saveDesignSpace() |
191 | // ) | 206 | // ) |
192 | // .with(DesignSpaceExplorationAdapter.builder() | 207 | .with(StateCoderAdapter.builder()) |
193 | // .transformations(assignFeatureRule, deleteEmptyClassRule, createClassRule, moveFeatureRule) | 208 | .with(ModificationAdapter.builder()) |
209 | .with(DesignSpaceExplorationAdapter.builder() | ||
210 | .transformations(assignFeatureRule, deleteEmptyClassRule, createClassRule, moveFeatureRule) | ||
211 | .objectives(new DummyObjective()) | ||
212 | .accept(new DummyCriterion(true)) | ||
213 | .exclude(new DummyCriterion(false)) | ||
194 | // .objectives(new AlwaysSatisfiedRandomHardObjective()) | 214 | // .objectives(new AlwaysSatisfiedRandomHardObjective()) |
195 | //// .strategy(new DepthFirstStrategy().withDepthLimit(3).continueIfHardObjectivesFulfilled() | 215 | // .strategy(new DepthFirstStrategy().withDepthLimit(3).continueIfHardObjectivesFulfilled() |
196 | // .strategy(new BestFirstStrategy().withDepthLimit(6).continueIfHardObjectivesFulfilled() | 216 | // .strategy(new BestFirstStrategy().withDepthLimit(6).continueIfHardObjectivesFulfilled() |
197 | //// .goOnOnlyIfFitnessIsBetter() | 217 | // .goOnOnlyIfFitnessIsBetter()) |
198 | // )) | 218 | ) |
199 | // .build(); | 219 | .build(); |
200 | // | 220 | |
201 | // var model = store.createEmptyModel(); | 221 | var model = store.createEmptyModel(); |
202 | // var dseAdapter = model.getAdapter(DesignSpaceExplorationAdapter.class); | 222 | // modificationAdapter.setRandom(1); |
203 | //// dseAdapter.setRandom(1); | 223 | var queryEngine = model.getAdapter(ModelQueryAdapter.class); |
204 | // var queryEngine = model.getAdapter(ModelQueryAdapter.class); | 224 | |
205 | // | 225 | // var modelInterpretation = model.getInterpretation(classModel); |
206 | //// var modelInterpretation = model.getInterpretation(classModel); | 226 | var nameInterpretation = model.getInterpretation(name); |
207 | // var nameInterpretation = model.getInterpretation(name); | 227 | var methodInterpretation = model.getInterpretation(method); |
208 | // var methodInterpretation = model.getInterpretation(method); | 228 | var attributeInterpretation = model.getInterpretation(attribute); |
209 | // var attributeInterpretation = model.getInterpretation(attribute); | 229 | var dataDependencyInterpretation = model.getInterpretation(dataDependency); |
210 | // var dataDependencyInterpretation = model.getInterpretation(dataDependency); | 230 | var functionalDependencyInterpretation = model.getInterpretation(functionalDependency); |
211 | // var functionalDependencyInterpretation = model.getInterpretation(functionalDependency); | 231 | |
212 | // | 232 | var modificationAdapter = model.getAdapter(ModificationAdapter.class); |
213 | //// var modelElement = dseAdapter.createObject(); | 233 | |
214 | // var method1 = dseAdapter.createObject(); | 234 | // var modelElement = modificationAdapter.createObject(); |
215 | // var method1Id = method1.get(0); | 235 | var method1 = modificationAdapter.createObject(); |
216 | // var method2 = dseAdapter.createObject(); | 236 | var method1Id = method1.get(0); |
217 | // var method2Id = method2.get(0); | 237 | var method2 = modificationAdapter.createObject(); |
218 | // var method3 = dseAdapter.createObject(); | 238 | var method2Id = method2.get(0); |
219 | // var method3Id = method3.get(0); | 239 | var method3 = modificationAdapter.createObject(); |
220 | // var method4 = dseAdapter.createObject(); | 240 | var method3Id = method3.get(0); |
221 | // var method4Id = method4.get(0); | 241 | var method4 = modificationAdapter.createObject(); |
222 | // var attribute1 = dseAdapter.createObject(); | 242 | var method4Id = method4.get(0); |
223 | // var attribute1Id = attribute1.get(0); | 243 | var attribute1 = modificationAdapter.createObject(); |
224 | // var attribute2 = dseAdapter.createObject(); | 244 | var attribute1Id = attribute1.get(0); |
225 | // var attribute2Id = attribute2.get(0); | 245 | var attribute2 = modificationAdapter.createObject(); |
226 | // var attribute3 = dseAdapter.createObject(); | 246 | var attribute2Id = attribute2.get(0); |
227 | // var attribute3Id = attribute3.get(0); | 247 | var attribute3 = modificationAdapter.createObject(); |
228 | // var attribute4 = dseAdapter.createObject(); | 248 | var attribute3Id = attribute3.get(0); |
229 | // var attribute4Id = attribute4.get(0); | 249 | var attribute4 = modificationAdapter.createObject(); |
230 | // var attribute5 = dseAdapter.createObject(); | 250 | var attribute4Id = attribute4.get(0); |
231 | // var attribute5Id = attribute5.get(0); | 251 | var attribute5 = modificationAdapter.createObject(); |
232 | // | 252 | var attribute5Id = attribute5.get(0); |
233 | // nameInterpretation.put(method1, "M1"); | 253 | |
234 | // nameInterpretation.put(method2, "M2"); | 254 | nameInterpretation.put(method1, "M1"); |
235 | // nameInterpretation.put(method3, "M3"); | 255 | nameInterpretation.put(method2, "M2"); |
236 | // nameInterpretation.put(method4, "M4"); | 256 | nameInterpretation.put(method3, "M3"); |
237 | // nameInterpretation.put(attribute1, "A1"); | 257 | nameInterpretation.put(method4, "M4"); |
238 | // nameInterpretation.put(attribute2, "A2"); | 258 | nameInterpretation.put(attribute1, "A1"); |
239 | // nameInterpretation.put(attribute3, "A3"); | 259 | nameInterpretation.put(attribute2, "A2"); |
240 | // nameInterpretation.put(attribute4, "A4"); | 260 | nameInterpretation.put(attribute3, "A3"); |
241 | // nameInterpretation.put(attribute5, "A5"); | 261 | nameInterpretation.put(attribute4, "A4"); |
242 | // | 262 | nameInterpretation.put(attribute5, "A5"); |
243 | // | 263 | |
244 | // | 264 | |
245 | //// modelInterpretation.put(modelElement, true); | 265 | |
246 | // methodInterpretation.put(method1, true); | 266 | // modelInterpretation.put(modelElement, true); |
247 | // methodInterpretation.put(method2, true); | 267 | methodInterpretation.put(method1, true); |
248 | // methodInterpretation.put(method3, true); | 268 | methodInterpretation.put(method2, true); |
249 | // methodInterpretation.put(method4, true); | 269 | methodInterpretation.put(method3, true); |
250 | // attributeInterpretation.put(attribute1, true); | 270 | methodInterpretation.put(method4, true); |
251 | // attributeInterpretation.put(attribute2, true); | 271 | attributeInterpretation.put(attribute1, true); |
252 | // attributeInterpretation.put(attribute3, true); | 272 | attributeInterpretation.put(attribute2, true); |
253 | // attributeInterpretation.put(attribute4, true); | 273 | attributeInterpretation.put(attribute3, true); |
254 | // attributeInterpretation.put(attribute5, true); | 274 | attributeInterpretation.put(attribute4, true); |
255 | // | 275 | attributeInterpretation.put(attribute5, true); |
256 | // dataDependencyInterpretation.put(Tuple.of(method1Id, attribute1Id), true); | 276 | |
257 | // dataDependencyInterpretation.put(Tuple.of(method1Id, attribute3Id), true); | 277 | dataDependencyInterpretation.put(Tuple.of(method1Id, attribute1Id), true); |
258 | // dataDependencyInterpretation.put(Tuple.of(method2Id, attribute2Id), true); | 278 | dataDependencyInterpretation.put(Tuple.of(method1Id, attribute3Id), true); |
259 | // dataDependencyInterpretation.put(Tuple.of(method3Id, attribute3Id), true); | 279 | dataDependencyInterpretation.put(Tuple.of(method2Id, attribute2Id), true); |
260 | // dataDependencyInterpretation.put(Tuple.of(method3Id, attribute4Id), true); | 280 | dataDependencyInterpretation.put(Tuple.of(method3Id, attribute3Id), true); |
261 | // dataDependencyInterpretation.put(Tuple.of(method4Id, attribute3Id), true); | 281 | dataDependencyInterpretation.put(Tuple.of(method3Id, attribute4Id), true); |
262 | // dataDependencyInterpretation.put(Tuple.of(method4Id, attribute5Id), true); | 282 | dataDependencyInterpretation.put(Tuple.of(method4Id, attribute3Id), true); |
263 | // | 283 | dataDependencyInterpretation.put(Tuple.of(method4Id, attribute5Id), true); |
264 | // functionalDependencyInterpretation.put(Tuple.of(method1Id, attribute3Id), true); | 284 | |
265 | // functionalDependencyInterpretation.put(Tuple.of(method1Id, attribute4Id), true); | 285 | functionalDependencyInterpretation.put(Tuple.of(method1Id, attribute3Id), true); |
266 | // functionalDependencyInterpretation.put(Tuple.of(method2Id, attribute1Id), true); | 286 | functionalDependencyInterpretation.put(Tuple.of(method1Id, attribute4Id), true); |
267 | // functionalDependencyInterpretation.put(Tuple.of(method3Id, attribute1Id), true); | 287 | functionalDependencyInterpretation.put(Tuple.of(method2Id, attribute1Id), true); |
268 | // functionalDependencyInterpretation.put(Tuple.of(method3Id, attribute4Id), true); | 288 | functionalDependencyInterpretation.put(Tuple.of(method3Id, attribute1Id), true); |
269 | // functionalDependencyInterpretation.put(Tuple.of(method4Id, attribute2Id), true); | 289 | functionalDependencyInterpretation.put(Tuple.of(method3Id, attribute4Id), true); |
270 | // | 290 | functionalDependencyInterpretation.put(Tuple.of(method4Id, attribute2Id), true); |
271 | // queryEngine.flushChanges(); | 291 | |
272 | // | 292 | var initialVersion = model.commit(); |
273 | // var states = dseAdapter.explore(); | 293 | queryEngine.flushChanges(); |
274 | // System.out.println("states size: " + states.size()); | 294 | |
275 | // } | 295 | var bestFirst = new BestFirstStoreManager(store); |
276 | //*/ | 296 | bestFirst.startExploration(initialVersion); |
297 | var resultStore = bestFirst.getSolutionStore(); | ||
298 | System.out.println("states size: " + resultStore.getSolutions().size()); | ||
299 | var modelVisualizerAdapter = model.getAdapter(ModelVisualizerAdapter.class); | ||
300 | modelVisualizerAdapter.visualize(); | ||
301 | } | ||
277 | } | 302 | } |
diff --git a/subprojects/store-dse/src/test/java/tools/refinery/store/dse/tests/DummyCriterion.java b/subprojects/store-dse/src/test/java/tools/refinery/store/dse/tests/DummyCriterion.java new file mode 100644 index 00000000..6bcbd1c3 --- /dev/null +++ b/subprojects/store-dse/src/test/java/tools/refinery/store/dse/tests/DummyCriterion.java | |||
@@ -0,0 +1,17 @@ | |||
1 | package tools.refinery.store.dse.tests; | ||
2 | |||
3 | import tools.refinery.store.dse.transition.objectives.Criterion; | ||
4 | import tools.refinery.store.dse.transition.objectives.CriterionCalculator; | ||
5 | import tools.refinery.store.model.Model; | ||
6 | |||
7 | public class DummyCriterion implements Criterion { | ||
8 | protected final boolean returnValue; | ||
9 | public DummyCriterion(boolean returnValue) { | ||
10 | this.returnValue = returnValue; | ||
11 | } | ||
12 | |||
13 | @Override | ||
14 | public CriterionCalculator createCalculator(Model model) { | ||
15 | return () -> returnValue; | ||
16 | } | ||
17 | } | ||
diff --git a/subprojects/store-dse/src/test/java/tools/refinery/store/dse/tests/DummyObjective.java b/subprojects/store-dse/src/test/java/tools/refinery/store/dse/tests/DummyObjective.java new file mode 100644 index 00000000..77a23d62 --- /dev/null +++ b/subprojects/store-dse/src/test/java/tools/refinery/store/dse/tests/DummyObjective.java | |||
@@ -0,0 +1,13 @@ | |||
1 | package tools.refinery.store.dse.tests; | ||
2 | |||
3 | import tools.refinery.store.dse.transition.objectives.Objective; | ||
4 | import tools.refinery.store.dse.transition.objectives.ObjectiveCalculator; | ||
5 | import tools.refinery.store.model.Model; | ||
6 | |||
7 | public class DummyObjective implements Objective { | ||
8 | |||
9 | @Override | ||
10 | public ObjectiveCalculator createCalculator(Model model) { | ||
11 | return () -> {return 0d;}; | ||
12 | } | ||
13 | } | ||