diff options
Diffstat (limited to 'subprojects')
2 files changed, 37 insertions, 2 deletions
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/strategy/BestFirstExplorer.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/strategy/BestFirstExplorer.java index f82d7c06..9a03b0b8 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/strategy/BestFirstExplorer.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/strategy/BestFirstExplorer.java | |||
@@ -36,6 +36,7 @@ public class BestFirstExplorer extends BestFirstWorker { | |||
36 | if (lastVisited == null) { | 36 | if (lastVisited == null) { |
37 | lastVisited = this.restoreToBest(); | 37 | lastVisited = this.restoreToBest(); |
38 | if(lastVisited == null) { | 38 | if(lastVisited == null) { |
39 | visualizerAdapter.visualize(); | ||
39 | return; | 40 | return; |
40 | } | 41 | } |
41 | } | 42 | } |
@@ -161,5 +162,7 @@ public class BestFirstExplorer extends BestFirstWorker { | |||
161 | */ | 162 | */ |
162 | } | 163 | } |
163 | // Interrupted. | 164 | // Interrupted. |
165 | visualizerAdapter.visualize(); | ||
166 | |||
164 | } | 167 | } |
165 | } | 168 | } |
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/strategy/BestFirstWorker.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/strategy/BestFirstWorker.java index b8662d8d..b1c51506 100644 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/strategy/BestFirstWorker.java +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/strategy/BestFirstWorker.java | |||
@@ -11,7 +11,9 @@ import tools.refinery.store.dse.transition.VersionWithObjectiveValue; | |||
11 | import tools.refinery.store.dse.transition.statespace.internal.ActivationStoreWorker; | 11 | import tools.refinery.store.dse.transition.statespace.internal.ActivationStoreWorker; |
12 | import tools.refinery.store.map.Version; | 12 | import tools.refinery.store.map.Version; |
13 | import tools.refinery.store.model.Model; | 13 | import tools.refinery.store.model.Model; |
14 | import tools.refinery.store.query.viatra.ViatraModelQueryAdapter; | ||
14 | import tools.refinery.store.statecoding.StateCoderAdapter; | 15 | import tools.refinery.store.statecoding.StateCoderAdapter; |
16 | import tools.refinery.visualization.ModelVisualizerAdapter; | ||
15 | 17 | ||
16 | import java.util.Random; | 18 | import java.util.Random; |
17 | 19 | ||
@@ -21,6 +23,9 @@ public class BestFirstWorker { | |||
21 | final ActivationStoreWorker activationStoreWorker; | 23 | final ActivationStoreWorker activationStoreWorker; |
22 | final StateCoderAdapter stateCoderAdapter; | 24 | final StateCoderAdapter stateCoderAdapter; |
23 | final DesignSpaceExplorationAdapter explorationAdapter; | 25 | final DesignSpaceExplorationAdapter explorationAdapter; |
26 | final ViatraModelQueryAdapter queryAdapter; | ||
27 | final ModelVisualizerAdapter visualizerAdapter; | ||
28 | final boolean isVisualizationEnabled; | ||
24 | 29 | ||
25 | public BestFirstWorker(BestFirstStoreManager storeManager, Model model) { | 30 | public BestFirstWorker(BestFirstStoreManager storeManager, Model model) { |
26 | this.storeManager = storeManager; | 31 | this.storeManager = storeManager; |
@@ -30,7 +35,10 @@ public class BestFirstWorker { | |||
30 | stateCoderAdapter = model.getAdapter(StateCoderAdapter.class); | 35 | stateCoderAdapter = model.getAdapter(StateCoderAdapter.class); |
31 | activationStoreWorker = new ActivationStoreWorker(storeManager.getActivationStore(), | 36 | activationStoreWorker = new ActivationStoreWorker(storeManager.getActivationStore(), |
32 | explorationAdapter.getTransformations()); | 37 | explorationAdapter.getTransformations()); |
33 | 38 | visualizerAdapter = model.getAdapter(ModelVisualizerAdapter.class); | |
39 | queryAdapter = model.getAdapter(ViatraModelQueryAdapter.class); | ||
40 | System.out.println("visualizerAdapter = " + visualizerAdapter); | ||
41 | isVisualizationEnabled = visualizerAdapter != null; | ||
34 | } | 42 | } |
35 | 43 | ||
36 | private VersionWithObjectiveValue last = null; | 44 | private VersionWithObjectiveValue last = null; |
@@ -44,6 +52,7 @@ public class BestFirstWorker { | |||
44 | } | 52 | } |
45 | 53 | ||
46 | Version version = model.commit(); | 54 | Version version = model.commit(); |
55 | queryAdapter.flushChanges(); | ||
47 | ObjectiveValue objectiveValue = explorationAdapter.getObjectiveValue(); | 56 | ObjectiveValue objectiveValue = explorationAdapter.getObjectiveValue(); |
48 | last = new VersionWithObjectiveValue(version, objectiveValue); | 57 | last = new VersionWithObjectiveValue(version, objectiveValue); |
49 | var code = stateCoderAdapter.calculateStateCode(); | 58 | var code = stateCoderAdapter.calculateStateCode(); |
@@ -55,14 +64,22 @@ public class BestFirstWorker { | |||
55 | 64 | ||
56 | public void restoreToLast() { | 65 | public void restoreToLast() { |
57 | if (explorationAdapter.getModel().hasUncommittedChanges()) { | 66 | if (explorationAdapter.getModel().hasUncommittedChanges()) { |
67 | var oldVersion = model.getState(); | ||
58 | explorationAdapter.getModel().restore(last.version()); | 68 | explorationAdapter.getModel().restore(last.version()); |
69 | if (isVisualizationEnabled) { | ||
70 | visualizerAdapter.addTransition(oldVersion, last.version(), ""); | ||
71 | } | ||
59 | } | 72 | } |
60 | } | 73 | } |
61 | 74 | ||
62 | public VersionWithObjectiveValue restoreToBest() { | 75 | public VersionWithObjectiveValue restoreToBest() { |
63 | var bestVersion = storeManager.getObjectiveStore().getBest(); | 76 | var bestVersion = storeManager.getObjectiveStore().getBest(); |
64 | if (bestVersion != null) { | 77 | if (bestVersion != null) { |
78 | var oldVersion = model.getState(); | ||
65 | this.model.restore(bestVersion.version()); | 79 | this.model.restore(bestVersion.version()); |
80 | if (isVisualizationEnabled) { | ||
81 | visualizerAdapter.addTransition(oldVersion, last.version(), ""); | ||
82 | } | ||
66 | } | 83 | } |
67 | return bestVersion; | 84 | return bestVersion; |
68 | } | 85 | } |
@@ -95,7 +112,22 @@ public class BestFirstWorker { | |||
95 | if (!model.hasUncommittedChanges()) { | 112 | if (!model.hasUncommittedChanges()) { |
96 | var visitResult = activationStoreWorker.fireRandomActivation(this.last, random); | 113 | var visitResult = activationStoreWorker.fireRandomActivation(this.last, random); |
97 | if (visitResult.successfulVisit()) { | 114 | if (visitResult.successfulVisit()) { |
98 | return new RandomVisitResult(submit(), visitResult.mayHaveMore()); | 115 | Version oldVersion = null; |
116 | if (isVisualizationEnabled) { | ||
117 | oldVersion = last.version(); | ||
118 | } | ||
119 | var submitResult = submit(); | ||
120 | if (isVisualizationEnabled) { | ||
121 | |||
122 | Version newVersion = null; | ||
123 | if (submitResult.newVersion() != null) { | ||
124 | newVersion = submitResult.newVersion().version(); | ||
125 | visualizerAdapter.addState(newVersion, submitResult.newVersion().objectiveValue().toString()); | ||
126 | visualizerAdapter.addSolution(newVersion); | ||
127 | } | ||
128 | visualizerAdapter.addTransition(oldVersion, newVersion, ""); | ||
129 | } | ||
130 | return new RandomVisitResult(submitResult, visitResult.mayHaveMore()); | ||
99 | } else { | 131 | } else { |
100 | return new RandomVisitResult(null, visitResult.mayHaveMore()); | 132 | return new RandomVisitResult(null, visitResult.mayHaveMore()); |
101 | } | 133 | } |