diff options
author | 2023-08-02 13:08:10 +0200 | |
---|---|---|
committer | 2023-08-02 13:08:10 +0200 | |
commit | 2c303ec940651895ad76a92c0080c707058167ef (patch) | |
tree | 7ba94f9d94593ff3fa7d6a814dc5896d823719e7 /subprojects/visualization/src | |
parent | Update CRA test case (diff) | |
parent | Merge pull request #31 from OszkarSemerath/datastructure (diff) | |
download | refinery-2c303ec940651895ad76a92c0080c707058167ef.tar.gz refinery-2c303ec940651895ad76a92c0080c707058167ef.tar.zst refinery-2c303ec940651895ad76a92c0080c707058167ef.zip |
Merge remote-tracking branch 'origin/main' into design-space-exploration
Diffstat (limited to 'subprojects/visualization/src')
2 files changed, 31 insertions, 20 deletions
diff --git a/subprojects/visualization/src/main/java/tools/refinery/visualization/ModelVisualizerAdapter.java b/subprojects/visualization/src/main/java/tools/refinery/visualization/ModelVisualizerAdapter.java index 2f71d4f3..b3f833ef 100644 --- a/subprojects/visualization/src/main/java/tools/refinery/visualization/ModelVisualizerAdapter.java +++ b/subprojects/visualization/src/main/java/tools/refinery/visualization/ModelVisualizerAdapter.java | |||
@@ -1,6 +1,7 @@ | |||
1 | package tools.refinery.visualization; | 1 | package tools.refinery.visualization; |
2 | 2 | ||
3 | import tools.refinery.store.adapter.ModelAdapter; | 3 | import tools.refinery.store.adapter.ModelAdapter; |
4 | import tools.refinery.store.map.Version; | ||
4 | import tools.refinery.store.tuple.Tuple; | 5 | import tools.refinery.store.tuple.Tuple; |
5 | import tools.refinery.visualization.internal.FileFormat; | 6 | import tools.refinery.visualization.internal.FileFormat; |
6 | import tools.refinery.visualization.internal.ModelVisualizerBuilderImpl; | 7 | import tools.refinery.visualization.internal.ModelVisualizerBuilderImpl; |
@@ -14,7 +15,7 @@ public interface ModelVisualizerAdapter extends ModelAdapter { | |||
14 | 15 | ||
15 | public String createDotForCurrentModelState(); | 16 | public String createDotForCurrentModelState(); |
16 | 17 | ||
17 | public String createDotForModelState(Long version); | 18 | public String createDotForModelState(Version version); |
18 | 19 | ||
19 | public boolean saveDot(String dot, String filePath); | 20 | public boolean saveDot(String dot, String filePath); |
20 | 21 | ||
@@ -22,15 +23,17 @@ public interface ModelVisualizerAdapter extends ModelAdapter { | |||
22 | 23 | ||
23 | public boolean renderDot(String dot, FileFormat format, String filePath); | 24 | public boolean renderDot(String dot, FileFormat format, String filePath); |
24 | 25 | ||
25 | public void addTransition(Long from, Long to, String action); | 26 | public void addTransition(Version from, Version to, String action); |
26 | 27 | ||
27 | 28 | ||
28 | public void addTransition(Long from, Long to, String action, Tuple activation); | 29 | public void addTransition(Version from, Version to, String action, Tuple activation); |
29 | public void addSolution(Long state); | 30 | public void addState(Version state); |
31 | public void addSolution(Version state); | ||
30 | 32 | ||
31 | public boolean saveDesignSpace(String path); | 33 | public boolean saveDesignSpace(String path); |
32 | 34 | ||
33 | public boolean renderDesignSpace(String path); | 35 | public boolean renderDesignSpace(String path); |
34 | 36 | ||
35 | public boolean renderDesignSpace(String path, FileFormat format); | 37 | public boolean renderDesignSpace(String path, FileFormat format); |
38 | |||
36 | } | 39 | } |
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 9a284e24..33c5a43b 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 | |||
@@ -1,5 +1,6 @@ | |||
1 | package tools.refinery.visualization.internal; | 1 | package tools.refinery.visualization.internal; |
2 | 2 | ||
3 | import tools.refinery.store.map.Version; | ||
3 | import tools.refinery.store.model.Interpretation; | 4 | import tools.refinery.store.model.Interpretation; |
4 | import tools.refinery.store.model.Model; | 5 | import tools.refinery.store.model.Model; |
5 | import tools.refinery.store.representation.AnySymbol; | 6 | import tools.refinery.store.representation.AnySymbol; |
@@ -16,7 +17,9 @@ public class ModelVisualizerAdapterImpl implements ModelVisualizerAdapter { | |||
16 | private final ModelVisualizerStoreAdapter storeAdapter; | 17 | private final ModelVisualizerStoreAdapter storeAdapter; |
17 | private final Map<AnySymbol, Interpretation<?>> interpretations; | 18 | private final Map<AnySymbol, Interpretation<?>> interpretations; |
18 | private final StringBuilder designSpaceBuilder = new StringBuilder(); | 19 | private final StringBuilder designSpaceBuilder = new StringBuilder(); |
20 | private final Map<Version, Integer> states = new HashMap<>(); | ||
19 | private int transitionCounter = 0; | 21 | private int transitionCounter = 0; |
22 | private Integer numberOfStates = 0; | ||
20 | 23 | ||
21 | public ModelVisualizerAdapterImpl(Model model, ModelVisualizerStoreAdapter storeAdapter) { | 24 | public ModelVisualizerAdapterImpl(Model model, ModelVisualizerStoreAdapter storeAdapter) { |
22 | this.model = model; | 25 | this.model = model; |
@@ -81,7 +84,7 @@ public class ModelVisualizerAdapterImpl implements ModelVisualizerAdapter { | |||
81 | } | 84 | } |
82 | 85 | ||
83 | @Override | 86 | @Override |
84 | public String createDotForModelState(Long version) { | 87 | public String createDotForModelState(Version version) { |
85 | var currentVersion = model.getState(); | 88 | var currentVersion = model.getState(); |
86 | model.restore(version); | 89 | model.restore(version); |
87 | var graph = createDotForCurrentModelState(); | 90 | var graph = createDotForCurrentModelState(); |
@@ -125,15 +128,15 @@ public class ModelVisualizerAdapterImpl implements ModelVisualizerAdapter { | |||
125 | } | 128 | } |
126 | 129 | ||
127 | @Override | 130 | @Override |
128 | public void addTransition(Long from, Long to, String action) { | 131 | public void addTransition(Version from, Version to, String action) { |
129 | designSpaceBuilder.append(from).append(" -> ").append(to).append(" [label=\"").append(transitionCounter++) | 132 | designSpaceBuilder.append(states.get(from)).append(" -> ").append(states.get(to)).append(" [label=\"") |
130 | .append(": ").append(action).append("\"]\n"); | 133 | .append(transitionCounter++).append(": ").append(action).append("\"]\n"); |
131 | 134 | ||
132 | } | 135 | } |
133 | 136 | ||
134 | @Override | 137 | @Override |
135 | public void addTransition(Long from, Long to, String action, Tuple activation) { | 138 | public void addTransition(Version from, Version to, String action, Tuple activation) { |
136 | designSpaceBuilder.append(from).append(" -> ").append(to).append(" [label=\"").append(transitionCounter++) | 139 | designSpaceBuilder.append(states.get(from)).append(" -> ").append(states.get(to)).append(" [label=\"").append(transitionCounter++) |
137 | .append(": ").append(action).append(" / "); | 140 | .append(": ").append(action).append(" / "); |
138 | 141 | ||
139 | 142 | ||
@@ -147,14 +150,17 @@ public class ModelVisualizerAdapterImpl implements ModelVisualizerAdapter { | |||
147 | } | 150 | } |
148 | 151 | ||
149 | @Override | 152 | @Override |
150 | public void addSolution(Long state) { | 153 | public void addState(Version state) { |
151 | designSpaceBuilder.append(state).append(" [shape = doublecircle]\n"); | 154 | states.put(state, numberOfStates++); |
155 | designSpaceBuilder.append(states.get(state)).append(" [URL=\"./").append(states.get(state)).append(".svg\"]\n"); | ||
156 | } | ||
157 | |||
158 | @Override | ||
159 | public void addSolution(Version state) { | ||
160 | designSpaceBuilder.append(states.get(state)).append(" [shape = doublecircle]\n"); | ||
152 | } | 161 | } |
153 | 162 | ||
154 | private String buildDesignSpaceDot() { | 163 | private String buildDesignSpaceDot() { |
155 | for (var state : storeAdapter.getStore().getStates()) { | ||
156 | designSpaceBuilder.append(state).append(" [URL=\"./").append(state).append(".svg\"]\n"); | ||
157 | } | ||
158 | designSpaceBuilder.append("}"); | 164 | designSpaceBuilder.append("}"); |
159 | return designSpaceBuilder.toString(); | 165 | return designSpaceBuilder.toString(); |
160 | } | 166 | } |
@@ -162,8 +168,8 @@ public class ModelVisualizerAdapterImpl implements ModelVisualizerAdapter { | |||
162 | @Override | 168 | @Override |
163 | public boolean saveDesignSpace(String path) { | 169 | public boolean saveDesignSpace(String path) { |
164 | saveDot(buildDesignSpaceDot(), path + "/designSpace.dot"); | 170 | saveDot(buildDesignSpaceDot(), path + "/designSpace.dot"); |
165 | for (var state : storeAdapter.getStore().getStates()) { | 171 | for (var state : states.keySet()) { |
166 | saveDot(createDotForModelState(state), path + "/" + state + ".dot"); | 172 | saveDot(createDotForModelState(state), path + "/" + states.get(state) + ".dot"); |
167 | } | 173 | } |
168 | return true; | 174 | return true; |
169 | } | 175 | } |
@@ -175,10 +181,12 @@ public class ModelVisualizerAdapterImpl implements ModelVisualizerAdapter { | |||
175 | 181 | ||
176 | @Override | 182 | @Override |
177 | public boolean renderDesignSpace(String path, FileFormat format) { | 183 | public boolean renderDesignSpace(String path, FileFormat format) { |
178 | for (var state : storeAdapter.getStore().getStates()) { | 184 | for (var entry : states.entrySet()) { |
185 | var state = entry.getKey(); | ||
186 | var stateId = entry.getValue(); | ||
179 | var stateDot = createDotForModelState(state); | 187 | var stateDot = createDotForModelState(state); |
180 | saveDot(stateDot, path + "/" + state + ".dot"); | 188 | saveDot(stateDot, path + "/" + stateId + ".dot"); |
181 | renderDot(stateDot, path + "/" + state + "." + format.getFormat()); | 189 | renderDot(stateDot, path + "/" + stateId + "." + format.getFormat()); |
182 | } | 190 | } |
183 | var designSpaceDot = buildDesignSpaceDot(); | 191 | var designSpaceDot = buildDesignSpaceDot(); |
184 | saveDot(designSpaceDot, path + "/designSpace.dot"); | 192 | saveDot(designSpaceDot, path + "/designSpace.dot"); |