diff options
author | 2023-08-07 12:59:35 +0200 | |
---|---|---|
committer | 2023-08-07 15:12:37 +0200 | |
commit | a20fd33c647d8511762f84436dbd8d1632b57fe8 (patch) | |
tree | f28113c37476cca869a3283cd57d81de605b06e7 /subprojects/visualization/src/main/java/tools | |
parent | Update exploration strategies (diff) | |
download | refinery-a20fd33c647d8511762f84436dbd8d1632b57fe8.tar.gz refinery-a20fd33c647d8511762f84436dbd8d1632b57fe8.tar.zst refinery-a20fd33c647d8511762f84436dbd8d1632b57fe8.zip |
Clean up design space exploration
Diffstat (limited to 'subprojects/visualization/src/main/java/tools')
2 files changed, 36 insertions, 22 deletions
diff --git a/subprojects/visualization/src/main/java/tools/refinery/visualization/ModelVisualizerStoreAdapter.java b/subprojects/visualization/src/main/java/tools/refinery/visualization/ModelVisualizerStoreAdapter.java index 6599d4c3..6e6453fd 100644 --- a/subprojects/visualization/src/main/java/tools/refinery/visualization/ModelVisualizerStoreAdapter.java +++ b/subprojects/visualization/src/main/java/tools/refinery/visualization/ModelVisualizerStoreAdapter.java | |||
@@ -6,7 +6,6 @@ | |||
6 | package tools.refinery.visualization; | 6 | package tools.refinery.visualization; |
7 | 7 | ||
8 | import tools.refinery.store.adapter.ModelStoreAdapter; | 8 | import tools.refinery.store.adapter.ModelStoreAdapter; |
9 | import tools.refinery.store.query.ModelQueryStoreAdapter; | ||
10 | 9 | ||
11 | public interface ModelVisualizerStoreAdapter extends ModelStoreAdapter { | 10 | public interface ModelVisualizerStoreAdapter extends ModelStoreAdapter { |
12 | } | 11 | } |
diff --git a/subprojects/visualization/src/main/java/tools/refinery/visualization/internal/ModelVisualizerAdapterImpl.java b/subprojects/visualization/src/main/java/tools/refinery/visualization/internal/ModelVisualizerAdapterImpl.java index 06cc8113..efafe5a2 100644 --- a/subprojects/visualization/src/main/java/tools/refinery/visualization/internal/ModelVisualizerAdapterImpl.java +++ b/subprojects/visualization/src/main/java/tools/refinery/visualization/internal/ModelVisualizerAdapterImpl.java | |||
@@ -21,38 +21,39 @@ import java.util.stream.Collectors; | |||
21 | public class ModelVisualizerAdapterImpl implements ModelVisualizerAdapter { | 21 | public class ModelVisualizerAdapterImpl implements ModelVisualizerAdapter { |
22 | private final Model model; | 22 | private final Model model; |
23 | private final ModelVisualizerStoreAdapter storeAdapter; | 23 | private final ModelVisualizerStoreAdapter storeAdapter; |
24 | private final Map<AnySymbol, Interpretation<?>> interpretations; | 24 | private final Map<AnySymbol, Interpretation<?>> allInterpretations; |
25 | private final StringBuilder designSpaceBuilder = new StringBuilder(); | 25 | private final StringBuilder designSpaceBuilder = new StringBuilder(); |
26 | private final Map<Version, Integer> states = new HashMap<>(); | 26 | private final Map<Version, Integer> states = new HashMap<>(); |
27 | private int transitionCounter = 0; | 27 | private int transitionCounter = 0; |
28 | private Integer numberOfStates = 0; | 28 | private Integer numberOfStates = 0; |
29 | private static final Map<Object, String> truthValueToDot = new HashMap<>() | 29 | private static final Map<Object, String> truthValueToDot = Map.of( |
30 | {{ | 30 | TruthValue.TRUE, "1", |
31 | put(TruthValue.TRUE, "1"); | 31 | TruthValue.FALSE, "0", |
32 | put(TruthValue.FALSE, "0"); | 32 | TruthValue.UNKNOWN, "½", |
33 | put(TruthValue.UNKNOWN, "½"); | 33 | TruthValue.ERROR, "E", |
34 | put(TruthValue.ERROR, "E"); | 34 | true, "1", |
35 | put(true, "1"); | 35 | false, "0" |
36 | put(false, "0"); | 36 | ); |
37 | }}; | ||
38 | 37 | ||
39 | public ModelVisualizerAdapterImpl(Model model, ModelVisualizerStoreAdapter storeAdapter) { | 38 | public ModelVisualizerAdapterImpl(Model model, ModelVisualizerStoreAdapter storeAdapter) { |
40 | this.model = model; | 39 | this.model = model; |
41 | this.storeAdapter = storeAdapter; | 40 | this.storeAdapter = storeAdapter; |
42 | this.interpretations = new HashMap<>(); | 41 | this.allInterpretations = new HashMap<>(); |
43 | for (var symbol : storeAdapter.getStore().getSymbols()) { | 42 | for (var symbol : storeAdapter.getStore().getSymbols()) { |
44 | var arity = symbol.arity(); | 43 | var arity = symbol.arity(); |
45 | if (arity < 1 || arity > 2) { | 44 | if (arity < 1 || arity > 2) { |
46 | continue; | 45 | continue; |
47 | } | 46 | } |
48 | var interpretation = (Interpretation<?>) model.getInterpretation(symbol); | 47 | var interpretation = (Interpretation<?>) model.getInterpretation(symbol); |
49 | interpretations.put(symbol, interpretation); | 48 | allInterpretations.put(symbol, interpretation); |
50 | } | 49 | } |
51 | designSpaceBuilder.append("digraph designSpace {\n"); | 50 | designSpaceBuilder.append("digraph designSpace {\n"); |
52 | designSpaceBuilder.append(""" | 51 | designSpaceBuilder.append(""" |
52 | nodesep=0 | ||
53 | ranksep=5 | ||
53 | node[ | 54 | node[ |
54 | style=filled | 55 | \tstyle=filled |
55 | fillcolor=white | 56 | \tfillcolor=white |
56 | ] | 57 | ] |
57 | """); | 58 | """); |
58 | } | 59 | } |
@@ -90,7 +91,7 @@ public class ModelVisualizerAdapterImpl implements ModelVisualizerAdapter { | |||
90 | ] | 91 | ] |
91 | """); | 92 | """); |
92 | 93 | ||
93 | for (var entry : interpretations.entrySet()) { | 94 | for (var entry : allInterpretations.entrySet()) { |
94 | var key = entry.getKey(); | 95 | var key = entry.getKey(); |
95 | var arity = key.arity(); | 96 | var arity = key.arity(); |
96 | var cursor = entry.getValue().getAll(); | 97 | var cursor = entry.getValue().getAll(); |
@@ -303,6 +304,20 @@ public class ModelVisualizerAdapterImpl implements ModelVisualizerAdapter { | |||
303 | } | 304 | } |
304 | 305 | ||
305 | @Override | 306 | @Override |
307 | public void addState(Version state, Collection<Double> fitness) { | ||
308 | if (states.containsKey(state)) { | ||
309 | return; | ||
310 | } | ||
311 | states.put(state, numberOfStates++); | ||
312 | designSpaceBuilder.append(states.get(state)).append(" [label = \"").append(states.get(state)).append(" ("); | ||
313 | |||
314 | for (var f : fitness) { | ||
315 | designSpaceBuilder.append(f).append(", "); | ||
316 | } | ||
317 | designSpaceBuilder.append(")\"\n").append("URL=\"./").append(states.get(state)).append(".svg\"]\n"); | ||
318 | } | ||
319 | |||
320 | @Override | ||
306 | public void addSolution(Version state) { | 321 | public void addSolution(Version state) { |
307 | addState(state); | 322 | addState(state); |
308 | designSpaceBuilder.append(states.get(state)).append(" [shape = doublecircle]\n"); | 323 | designSpaceBuilder.append(states.get(state)).append(" [shape = doublecircle]\n"); |
@@ -329,12 +344,12 @@ public class ModelVisualizerAdapterImpl implements ModelVisualizerAdapter { | |||
329 | 344 | ||
330 | @Override | 345 | @Override |
331 | public boolean renderDesignSpace(String path, FileFormat format) { | 346 | public boolean renderDesignSpace(String path, FileFormat format) { |
332 | for (var entry : states.entrySet()) { | 347 | // for (var entry : states.entrySet()) { |
333 | var stateId = entry.getValue(); | 348 | // var stateId = entry.getValue(); |
334 | var stateDot = createDotForModelState(entry.getKey()); | 349 | // var stateDot = createDotForModelState(entry.getKey()); |
335 | saveDot(stateDot, path + "/" + stateId + ".dot"); | 350 | // saveDot(stateDot, path + "/" + stateId + ".dot"); |
336 | renderDot(stateDot, format, path + "/" + stateId + "." + format.getFormat()); | 351 | // renderDot(stateDot, format, path + "/" + stateId + "." + format.getFormat()); |
337 | } | 352 | // } |
338 | var designSpaceDot = buildDesignSpaceDot(); | 353 | var designSpaceDot = buildDesignSpaceDot(); |
339 | saveDot(designSpaceDot, path + "/designSpace.dot"); | 354 | saveDot(designSpaceDot, path + "/designSpace.dot"); |
340 | return renderDot(designSpaceDot, format, path + "/designSpace." + format.getFormat()); | 355 | return renderDot(designSpaceDot, format, path + "/designSpace." + format.getFormat()); |