diff options
Diffstat (limited to 'subprojects/store-dse')
4 files changed, 74 insertions, 14 deletions
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/DesignSpaceExplorationAdapterImpl.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/DesignSpaceExplorationAdapterImpl.java index 1329480c..008b2dab 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/DesignSpaceExplorationAdapterImpl.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/DesignSpaceExplorationAdapterImpl.java | |||
@@ -96,6 +96,9 @@ public class DesignSpaceExplorationAdapterImpl implements DesignSpaceExploration | |||
96 | trajectory.add(state); | 96 | trajectory.add(state); |
97 | strategy.initStrategy(this); | 97 | strategy.initStrategy(this); |
98 | strategy.explore(); | 98 | strategy.explore(); |
99 | if (isVisualizationEnabled) { | ||
100 | modelVisualizerAdapter.visualize(); | ||
101 | } | ||
99 | return solutions; | 102 | return solutions; |
100 | } | 103 | } |
101 | 104 | ||
@@ -247,7 +250,7 @@ public class DesignSpaceExplorationAdapterImpl implements DesignSpaceExploration | |||
247 | isNewState = !statesAndTraversedActivations.containsKey(newState); | 250 | isNewState = !statesAndTraversedActivations.containsKey(newState); |
248 | if (isVisualizationEnabled) { | 251 | if (isVisualizationEnabled) { |
249 | if (isNewState) { | 252 | if (isNewState) { |
250 | modelVisualizerAdapter.addState(newState); | 253 | modelVisualizerAdapter.addState(newState, getFitness().values()); |
251 | } | 254 | } |
252 | // TODO: Change to this: | 255 | // TODO: Change to this: |
253 | modelVisualizerAdapter.addTransition(previousState, newState, activation.transformationRule().getName(), | 256 | modelVisualizerAdapter.addTransition(previousState, newState, activation.transformationRule().getName(), |
@@ -272,11 +275,6 @@ public class DesignSpaceExplorationAdapterImpl implements DesignSpaceExploration | |||
272 | fireActivation(activationId); | 275 | fireActivation(activationId); |
273 | } | 276 | } |
274 | 277 | ||
275 | @Override | ||
276 | public boolean isCurrentInTrajectory() { | ||
277 | return trajectory.contains(model.getState()); | ||
278 | } | ||
279 | |||
280 | public List<Activation> getAllActivations() { | 278 | public List<Activation> getAllActivations() { |
281 | List<Activation> result = new LinkedList<>(); | 279 | List<Activation> result = new LinkedList<>(); |
282 | for (var rule : transformationRules) { | 280 | for (var rule : transformationRules) { |
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/objectives/AlwaysSatisfiedRandomHardObjective.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/objectives/AlwaysSatisfiedRandomHardObjective.java new file mode 100644 index 00000000..327d5e2f --- /dev/null +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/objectives/AlwaysSatisfiedRandomHardObjective.java | |||
@@ -0,0 +1,56 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2016, Andras Szabolcs Nagy, Zoltan Ujhelyi and Daniel Varro | ||
3 | * Copyright (c) 2023 The Refinery Authors <https://refinery.tools/> | ||
4 | * This program and the accompanying materials are made available under the | ||
5 | * terms of the Eclipse Public License v. 2.0 which is available at | ||
6 | * http://www.eclipse.org/legal/epl-v20.html. | ||
7 | * | ||
8 | * SPDX-License-Identifier: EPL-2.0 | ||
9 | *******************************************************************************/ | ||
10 | package tools.refinery.store.dse.objectives; | ||
11 | |||
12 | import tools.refinery.store.dse.DesignSpaceExplorationAdapter; | ||
13 | |||
14 | import java.util.Random; | ||
15 | |||
16 | /** | ||
17 | * This hard objective is fulfilled in any circumstances. Use it if all states should be regarded as a valid solution. | ||
18 | * | ||
19 | * @author Andras Szabolcs Nagy | ||
20 | * | ||
21 | */ | ||
22 | public class AlwaysSatisfiedRandomHardObjective extends BaseObjective { | ||
23 | |||
24 | private static final String DEFAULT_NAME = "AlwaysSatisfiedDummyHardObjective"; | ||
25 | private static final Random random = new Random(0); | ||
26 | |||
27 | public AlwaysSatisfiedRandomHardObjective() { | ||
28 | super(DEFAULT_NAME); | ||
29 | } | ||
30 | |||
31 | public AlwaysSatisfiedRandomHardObjective(String name) { | ||
32 | super(name); | ||
33 | } | ||
34 | |||
35 | @Override | ||
36 | public Double getFitness(DesignSpaceExplorationAdapter context) { | ||
37 | // return 0d; | ||
38 | return random.nextDouble(); | ||
39 | } | ||
40 | |||
41 | @Override | ||
42 | public boolean isHardObjective() { | ||
43 | return true; | ||
44 | } | ||
45 | |||
46 | @Override | ||
47 | public boolean satisfiesHardObjective(Double fitness) { | ||
48 | return true; | ||
49 | } | ||
50 | |||
51 | @Override | ||
52 | public Objective createNew() { | ||
53 | return this; | ||
54 | } | ||
55 | |||
56 | } | ||
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 f1e90280..23f0e703 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 | |||
@@ -188,7 +188,13 @@ class CRAExamplesTest { | |||
188 | .queries(feature, assignFeaturePreconditionHelper, assignFeaturePrecondition, | 188 | .queries(feature, assignFeaturePreconditionHelper, assignFeaturePrecondition, |
189 | deleteEmptyClassPrecondition, createClassPreconditionHelper, createClassPrecondition, | 189 | deleteEmptyClassPrecondition, createClassPreconditionHelper, createClassPrecondition, |
190 | moveFeaturePrecondition)) | 190 | moveFeaturePrecondition)) |
191 | .with(ModelVisualizerAdapter.builder()) | 191 | .with(ModelVisualizerAdapter.builder() |
192 | .withOutputpath("test_output") | ||
193 | .withFormat(FileFormat.DOT) | ||
194 | .withFormat(FileFormat.SVG) | ||
195 | .saveStates() | ||
196 | .saveDesignSpace() | ||
197 | ) | ||
192 | .with(DesignSpaceExplorationAdapter.builder() | 198 | .with(DesignSpaceExplorationAdapter.builder() |
193 | .transformations(assignFeatureRule, deleteEmptyClassRule, createClassRule, moveFeatureRule) | 199 | .transformations(assignFeatureRule, deleteEmptyClassRule, createClassRule, moveFeatureRule) |
194 | // .strategy(new DepthFirstStrategy(3).continueIfHardObjectivesFulfilled() | 200 | // .strategy(new DepthFirstStrategy(3).continueIfHardObjectivesFulfilled() |
@@ -271,9 +277,6 @@ class CRAExamplesTest { | |||
271 | 277 | ||
272 | var states = dseAdapter.explore(); | 278 | var states = dseAdapter.explore(); |
273 | System.out.println("states size: " + states.size()); | 279 | System.out.println("states size: " + states.size()); |
274 | System.out.println("states: " + states); | ||
275 | var visualizer = model.getAdapter(ModelVisualizerAdapter.class); | ||
276 | visualizer.renderDesignSpace("test_output", FileFormat.SVG); | ||
277 | } | 280 | } |
278 | 281 | ||
279 | } | 282 | } |
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 553510c8..88c4f152 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 | |||
@@ -90,7 +90,13 @@ class DebugTest { | |||
90 | .symbols(classModel, classElement, feature, isEncapsulatedBy, encapsulates, classes, features) | 90 | .symbols(classModel, classElement, feature, isEncapsulatedBy, encapsulates, classes, features) |
91 | .with(ViatraModelQueryAdapter.builder() | 91 | .with(ViatraModelQueryAdapter.builder() |
92 | .queries(createClassPrecondition, createFeaturePrecondition)) | 92 | .queries(createClassPrecondition, createFeaturePrecondition)) |
93 | .with(ModelVisualizerAdapter.builder()) | 93 | .with(ModelVisualizerAdapter.builder() |
94 | .withOutputpath("test_output") | ||
95 | .withFormat(FileFormat.DOT) | ||
96 | .withFormat(FileFormat.SVG) | ||
97 | .saveStates() | ||
98 | .saveDesignSpace() | ||
99 | ) | ||
94 | .with(DesignSpaceExplorationAdapter.builder() | 100 | .with(DesignSpaceExplorationAdapter.builder() |
95 | .transformations(createClassRule, createFeatureRule) | 101 | .transformations(createClassRule, createFeatureRule) |
96 | .strategy(new DepthFirstStrategy(4).continueIfHardObjectivesFulfilled() | 102 | .strategy(new DepthFirstStrategy(4).continueIfHardObjectivesFulfilled() |
@@ -113,10 +119,7 @@ class DebugTest { | |||
113 | 119 | ||
114 | 120 | ||
115 | var states = dseAdapter.explore(); | 121 | var states = dseAdapter.explore(); |
116 | var visualizer = model.getAdapter(ModelVisualizerAdapter.class); | ||
117 | visualizer.renderDesignSpace("test_output", FileFormat.SVG); | ||
118 | System.out.println("states size: " + states.size()); | 122 | System.out.println("states size: " + states.size()); |
119 | System.out.println("states: " + states); | ||
120 | 123 | ||
121 | } | 124 | } |
122 | } | 125 | } |