diff options
Diffstat (limited to 'subprojects')
2 files changed, 34 insertions, 1 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 f28505c3..0f1702ea 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 | |||
@@ -13,6 +13,7 @@ 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.ModelQueryAdapter; | 14 | import tools.refinery.store.query.ModelQueryAdapter; |
15 | import tools.refinery.store.statecoding.StateCoderAdapter; | 15 | import tools.refinery.store.statecoding.StateCoderAdapter; |
16 | import tools.refinery.visualization.ModelVisualizerAdapter; | ||
16 | 17 | ||
17 | import java.util.Random; | 18 | import java.util.Random; |
18 | 19 | ||
@@ -23,6 +24,8 @@ public class BestFirstWorker { | |||
23 | final StateCoderAdapter stateCoderAdapter; | 24 | final StateCoderAdapter stateCoderAdapter; |
24 | final DesignSpaceExplorationAdapter explorationAdapter; | 25 | final DesignSpaceExplorationAdapter explorationAdapter; |
25 | final ModelQueryAdapter queryAdapter; | 26 | final ModelQueryAdapter queryAdapter; |
27 | final ModelVisualizerAdapter visualizerAdapter; | ||
28 | final boolean isVisualizationEnabled; | ||
26 | 29 | ||
27 | public BestFirstWorker(BestFirstStoreManager storeManager, Model model) { | 30 | public BestFirstWorker(BestFirstStoreManager storeManager, Model model) { |
28 | this.storeManager = storeManager; | 31 | this.storeManager = storeManager; |
@@ -33,6 +36,9 @@ public class BestFirstWorker { | |||
33 | queryAdapter = model.getAdapter(ModelQueryAdapter.class); | 36 | queryAdapter = model.getAdapter(ModelQueryAdapter.class); |
34 | activationStoreWorker = new ActivationStoreWorker(storeManager.getActivationStore(), | 37 | activationStoreWorker = new ActivationStoreWorker(storeManager.getActivationStore(), |
35 | explorationAdapter.getTransformations()); | 38 | explorationAdapter.getTransformations()); |
39 | visualizerAdapter = model.getAdapter(ModelVisualizerAdapter.class); | ||
40 | System.out.println("visualizerAdapter = " + visualizerAdapter); | ||
41 | isVisualizationEnabled = visualizerAdapter != null; | ||
36 | } | 42 | } |
37 | 43 | ||
38 | private VersionWithObjectiveValue last = null; | 44 | private VersionWithObjectiveValue last = null; |
@@ -46,6 +52,7 @@ public class BestFirstWorker { | |||
46 | } | 52 | } |
47 | 53 | ||
48 | Version version = model.commit(); | 54 | Version version = model.commit(); |
55 | queryAdapter.flushChanges(); | ||
49 | ObjectiveValue objectiveValue = explorationAdapter.getObjectiveValue(); | 56 | ObjectiveValue objectiveValue = explorationAdapter.getObjectiveValue(); |
50 | last = new VersionWithObjectiveValue(version, objectiveValue); | 57 | last = new VersionWithObjectiveValue(version, objectiveValue); |
51 | var code = stateCoderAdapter.calculateStateCode(); | 58 | var code = stateCoderAdapter.calculateStateCode(); |
@@ -57,14 +64,22 @@ public class BestFirstWorker { | |||
57 | 64 | ||
58 | public void restoreToLast() { | 65 | public void restoreToLast() { |
59 | if (explorationAdapter.getModel().hasUncommittedChanges()) { | 66 | if (explorationAdapter.getModel().hasUncommittedChanges()) { |
67 | var oldVersion = model.getState(); | ||
60 | explorationAdapter.getModel().restore(last.version()); | 68 | explorationAdapter.getModel().restore(last.version()); |
69 | if (isVisualizationEnabled) { | ||
70 | visualizerAdapter.addTransition(oldVersion, last.version(), ""); | ||
71 | } | ||
61 | } | 72 | } |
62 | } | 73 | } |
63 | 74 | ||
64 | public VersionWithObjectiveValue restoreToBest() { | 75 | public VersionWithObjectiveValue restoreToBest() { |
65 | var bestVersion = storeManager.getObjectiveStore().getBest(); | 76 | var bestVersion = storeManager.getObjectiveStore().getBest(); |
66 | if (bestVersion != null) { | 77 | if (bestVersion != null) { |
78 | var oldVersion = model.getState(); | ||
67 | this.model.restore(bestVersion.version()); | 79 | this.model.restore(bestVersion.version()); |
80 | if (isVisualizationEnabled) { | ||
81 | visualizerAdapter.addTransition(oldVersion, last.version(), ""); | ||
82 | } | ||
68 | } | 83 | } |
69 | return bestVersion; | 84 | return bestVersion; |
70 | } | 85 | } |
@@ -99,7 +114,22 @@ public class BestFirstWorker { | |||
99 | var visitResult = activationStoreWorker.fireRandomActivation(this.last, random); | 114 | var visitResult = activationStoreWorker.fireRandomActivation(this.last, random); |
100 | 115 | ||
101 | if (visitResult.successfulVisit()) { | 116 | if (visitResult.successfulVisit()) { |
102 | return new RandomVisitResult(submit(), visitResult.mayHaveMore()); | 117 | Version oldVersion = null; |
118 | if (isVisualizationEnabled) { | ||
119 | oldVersion = last.version(); | ||
120 | } | ||
121 | var submitResult = submit(); | ||
122 | if (isVisualizationEnabled) { | ||
123 | |||
124 | Version newVersion = null; | ||
125 | if (submitResult.newVersion() != null) { | ||
126 | newVersion = submitResult.newVersion().version(); | ||
127 | visualizerAdapter.addState(newVersion, submitResult.newVersion().objectiveValue().toString()); | ||
128 | visualizerAdapter.addSolution(newVersion); | ||
129 | } | ||
130 | visualizerAdapter.addTransition(oldVersion, newVersion, ""); | ||
131 | } | ||
132 | return new RandomVisitResult(submitResult, visitResult.mayHaveMore()); | ||
103 | } else { | 133 | } else { |
104 | return new RandomVisitResult(null, visitResult.mayHaveMore()); | 134 | return new RandomVisitResult(null, visitResult.mayHaveMore()); |
105 | } | 135 | } |