diff options
3 files changed, 29 insertions, 13 deletions
diff --git a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/ModelInitializer.java b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/ModelInitializer.java index 486eb89b..c2243f08 100644 --- a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/ModelInitializer.java +++ b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/ModelInitializer.java | |||
@@ -52,7 +52,9 @@ import tools.refinery.store.reasoning.translator.multiplicity.ConstrainedMultipl | |||
52 | import tools.refinery.store.reasoning.translator.multiplicity.Multiplicity; | 52 | import tools.refinery.store.reasoning.translator.multiplicity.Multiplicity; |
53 | import tools.refinery.store.reasoning.translator.multiplicity.UnconstrainedMultiplicity; | 53 | import tools.refinery.store.reasoning.translator.multiplicity.UnconstrainedMultiplicity; |
54 | import tools.refinery.store.reasoning.translator.predicate.PredicateTranslator; | 54 | import tools.refinery.store.reasoning.translator.predicate.PredicateTranslator; |
55 | import tools.refinery.store.statecoding.StateCoderBuilder; | ||
55 | import tools.refinery.store.tuple.Tuple; | 56 | import tools.refinery.store.tuple.Tuple; |
57 | import tools.refinery.store.tuple.Tuple1; | ||
56 | 58 | ||
57 | import java.util.*; | 59 | import java.util.*; |
58 | 60 | ||
@@ -78,6 +80,8 @@ public class ModelInitializer { | |||
78 | 80 | ||
79 | private BuiltinSymbols builtinSymbols; | 81 | private BuiltinSymbols builtinSymbols; |
80 | 82 | ||
83 | private final List<Tuple1> individuals = new ArrayList<>(); | ||
84 | |||
81 | private PartialRelation nodeRelation; | 85 | private PartialRelation nodeRelation; |
82 | 86 | ||
83 | private final Map<Relation, RelationInfo> relationInfoMap = new LinkedHashMap<>(); | 87 | private final Map<Relation, RelationInfo> relationInfoMap = new LinkedHashMap<>(); |
@@ -190,6 +194,8 @@ public class ModelInitializer { | |||
190 | } | 194 | } |
191 | collectPredicates(storeBuilder); | 195 | collectPredicates(storeBuilder); |
192 | collectRules(storeBuilder); | 196 | collectRules(storeBuilder); |
197 | storeBuilder.tryGetAdapter(StateCoderBuilder.class) | ||
198 | .ifPresent(stateCoderBuilder -> stateCoderBuilder.individuals(individuals)); | ||
193 | } catch (TranslationException e) { | 199 | } catch (TranslationException e) { |
194 | throw problemTrace.wrapException(e); | 200 | throw problemTrace.wrapException(e); |
195 | } | 201 | } |
@@ -224,29 +230,33 @@ public class ModelInitializer { | |||
224 | } | 230 | } |
225 | } | 231 | } |
226 | for (var node : problem.getNodes()) { | 232 | for (var node : problem.getNodes()) { |
227 | collectNode(node); | 233 | collectNode(node, false); |
228 | } | 234 | } |
229 | } | 235 | } |
230 | 236 | ||
231 | private void collectNodes(Statement statement) { | 237 | private void collectNodes(Statement statement) { |
232 | if (statement instanceof NodeDeclaration nodeDeclaration) { | 238 | if (statement instanceof NodeDeclaration nodeDeclaration) { |
239 | boolean individual = nodeDeclaration.getKind() == NodeKind.ATOM; | ||
233 | for (var node : nodeDeclaration.getNodes()) { | 240 | for (var node : nodeDeclaration.getNodes()) { |
234 | collectNode(node); | 241 | collectNode(node, individual); |
235 | } | 242 | } |
236 | } else if (statement instanceof ClassDeclaration classDeclaration) { | 243 | } else if (statement instanceof ClassDeclaration classDeclaration) { |
237 | var newNode = classDeclaration.getNewNode(); | 244 | var newNode = classDeclaration.getNewNode(); |
238 | if (newNode != null) { | 245 | if (newNode != null) { |
239 | collectNode(newNode); | 246 | collectNode(newNode, false); |
240 | } | 247 | } |
241 | } else if (statement instanceof EnumDeclaration enumDeclaration) { | 248 | } else if (statement instanceof EnumDeclaration enumDeclaration) { |
242 | for (var literal : enumDeclaration.getLiterals()) { | 249 | for (var literal : enumDeclaration.getLiterals()) { |
243 | collectNode(literal); | 250 | collectNode(literal, true); |
244 | } | 251 | } |
245 | } | 252 | } |
246 | } | 253 | } |
247 | 254 | ||
248 | private void collectNode(Node node) { | 255 | private void collectNode(Node node, boolean individual) { |
249 | problemTrace.collectNode(node); | 256 | int nodeId = problemTrace.collectNode(node); |
257 | if (individual) { | ||
258 | individuals.add(Tuple.of(nodeId)); | ||
259 | } | ||
250 | } | 260 | } |
251 | 261 | ||
252 | private void collectPartialSymbols() { | 262 | private void collectPartialSymbols() { |
diff --git a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/ProblemTraceImpl.java b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/ProblemTraceImpl.java index 3a979bf0..4b44339c 100644 --- a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/ProblemTraceImpl.java +++ b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/ProblemTraceImpl.java | |||
@@ -70,8 +70,10 @@ class ProblemTraceImpl implements ProblemTrace { | |||
70 | return nodeTrace; | 70 | return nodeTrace; |
71 | } | 71 | } |
72 | 72 | ||
73 | void collectNode(Node node) { | 73 | int collectNode(Node node) { |
74 | mutableNodeTrace.getIfAbsentPut(node, mutableNodeTrace.size()); | 74 | var nextId = mutableNodeTrace.size(); |
75 | mutableNodeTrace.getIfAbsentPut(node, nextId); | ||
76 | return nextId; | ||
75 | } | 77 | } |
76 | 78 | ||
77 | @Override | 79 | @Override |
diff --git a/subprojects/store/src/main/java/tools/refinery/store/statecoding/StateCoderBuilder.java b/subprojects/store/src/main/java/tools/refinery/store/statecoding/StateCoderBuilder.java index 54650825..868eddfc 100644 --- a/subprojects/store/src/main/java/tools/refinery/store/statecoding/StateCoderBuilder.java +++ b/subprojects/store/src/main/java/tools/refinery/store/statecoding/StateCoderBuilder.java | |||
@@ -10,34 +10,38 @@ import tools.refinery.store.model.ModelStore; | |||
10 | import tools.refinery.store.representation.AnySymbol; | 10 | import tools.refinery.store.representation.AnySymbol; |
11 | import tools.refinery.store.tuple.Tuple1; | 11 | import tools.refinery.store.tuple.Tuple1; |
12 | 12 | ||
13 | import java.util.Arrays; | ||
14 | import java.util.Collection; | 13 | import java.util.Collection; |
15 | import java.util.List; | 14 | import java.util.List; |
16 | 15 | ||
17 | public interface StateCoderBuilder extends ModelAdapterBuilder { | 16 | public interface StateCoderBuilder extends ModelAdapterBuilder { |
18 | StateCoderBuilder exclude(AnySymbol symbol); | 17 | StateCoderBuilder exclude(AnySymbol symbol); |
18 | |||
19 | default StateCoderBuilder excludeAll(Collection<? extends AnySymbol> symbols) { | 19 | default StateCoderBuilder excludeAll(Collection<? extends AnySymbol> symbols) { |
20 | for(var symbol : symbols) { | 20 | for (var symbol : symbols) { |
21 | exclude(symbol); | 21 | exclude(symbol); |
22 | } | 22 | } |
23 | return this; | 23 | return this; |
24 | } | 24 | } |
25 | |||
25 | default StateCoderBuilder excludeAll(AnySymbol... symbols) { | 26 | default StateCoderBuilder excludeAll(AnySymbol... symbols) { |
26 | return excludeAll(List.of(symbols)); | 27 | return excludeAll(List.of(symbols)); |
27 | } | 28 | } |
28 | 29 | ||
29 | StateCoderBuilder individual(Tuple1 tuple); | 30 | StateCoderBuilder individual(Tuple1 tuple); |
30 | default StateCoderBuilder individual(Collection<Tuple1> tuple1s) { | 31 | |
31 | for(Tuple1 tuple : tuple1s){ | 32 | default StateCoderBuilder individuals(Collection<Tuple1> tuple1s) { |
33 | for (Tuple1 tuple : tuple1s) { | ||
32 | individual(tuple); | 34 | individual(tuple); |
33 | } | 35 | } |
34 | return this; | 36 | return this; |
35 | } | 37 | } |
38 | |||
36 | default StateCoderBuilder individuals(Tuple1... tuple1s) { | 39 | default StateCoderBuilder individuals(Tuple1... tuple1s) { |
37 | return individual(Arrays.stream(tuple1s).toList()); | 40 | return individuals(List.of(tuple1s)); |
38 | } | 41 | } |
39 | 42 | ||
40 | StateCoderBuilder stateCodeCalculatorFactory(StateCodeCalculatorFactory codeCalculatorFactory); | 43 | StateCoderBuilder stateCodeCalculatorFactory(StateCodeCalculatorFactory codeCalculatorFactory); |
44 | |||
41 | StateCoderBuilder stateEquivalenceChecker(StateEquivalenceChecker stateEquivalenceChecker); | 45 | StateCoderBuilder stateEquivalenceChecker(StateEquivalenceChecker stateEquivalenceChecker); |
42 | 46 | ||
43 | @Override | 47 | @Override |