aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/language-semantics/src/main/java
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2023-09-09 12:57:49 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2023-09-09 12:57:49 +0200
commit0bdb400deef88cb2a7c0b8c90afebf84b29c04d5 (patch)
treed8cf379d3f1321cb1e3e44e19226c48634ae97f2 /subprojects/language-semantics/src/main/java
parentrefactor(store): neighborhood optimization (diff)
downloadrefinery-0bdb400deef88cb2a7c0b8c90afebf84b29c04d5.tar.gz
refinery-0bdb400deef88cb2a7c0b8c90afebf84b29c04d5.tar.zst
refinery-0bdb400deef88cb2a7c0b8c90afebf84b29c04d5.zip
feat: integrate DSE with partial interpretation
Diffstat (limited to 'subprojects/language-semantics/src/main/java')
-rw-r--r--subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/ModelInitializer.java23
1 files changed, 16 insertions, 7 deletions
diff --git a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/ModelInitializer.java b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/ModelInitializer.java
index 89c41a8e..a14b40d0 100644
--- a/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/ModelInitializer.java
+++ b/subprojects/language-semantics/src/main/java/tools/refinery/language/semantics/model/ModelInitializer.java
@@ -13,6 +13,7 @@ import tools.refinery.language.semantics.model.internal.MutableSeed;
13import tools.refinery.language.utils.BuiltinSymbols; 13import tools.refinery.language.utils.BuiltinSymbols;
14import tools.refinery.language.utils.ProblemDesugarer; 14import tools.refinery.language.utils.ProblemDesugarer;
15import tools.refinery.language.utils.ProblemUtil; 15import tools.refinery.language.utils.ProblemUtil;
16import tools.refinery.store.dse.propagation.PropagationBuilder;
16import tools.refinery.store.model.ModelStoreBuilder; 17import tools.refinery.store.model.ModelStoreBuilder;
17import tools.refinery.store.query.Constraint; 18import tools.refinery.store.query.Constraint;
18import tools.refinery.store.query.dnf.InvalidClauseException; 19import tools.refinery.store.query.dnf.InvalidClauseException;
@@ -24,7 +25,7 @@ import tools.refinery.store.query.term.Variable;
24import tools.refinery.store.reasoning.ReasoningAdapter; 25import tools.refinery.store.reasoning.ReasoningAdapter;
25import tools.refinery.store.reasoning.representation.AnyPartialSymbol; 26import tools.refinery.store.reasoning.representation.AnyPartialSymbol;
26import tools.refinery.store.reasoning.representation.PartialRelation; 27import tools.refinery.store.reasoning.representation.PartialRelation;
27import tools.refinery.store.reasoning.scope.ScopePropagatorBuilder; 28import tools.refinery.store.reasoning.scope.ScopePropagator;
28import tools.refinery.store.reasoning.seed.ModelSeed; 29import tools.refinery.store.reasoning.seed.ModelSeed;
29import tools.refinery.store.reasoning.seed.Seed; 30import tools.refinery.store.reasoning.seed.Seed;
30import tools.refinery.store.reasoning.translator.containment.ContainmentHierarchyTranslator; 31import tools.refinery.store.reasoning.translator.containment.ContainmentHierarchyTranslator;
@@ -73,7 +74,9 @@ public class ModelInitializer {
73 74
74 private Metamodel metamodel; 75 private Metamodel metamodel;
75 76
76 private Map<Tuple, CardinalityInterval> countSeed = new LinkedHashMap<>(); 77 private final Map<Tuple, CardinalityInterval> countSeed = new LinkedHashMap<>();
78
79 private ScopePropagator scopePropagator;
77 80
78 private ModelSeed modelSeed; 81 private ModelSeed modelSeed;
79 82
@@ -139,6 +142,12 @@ public class ModelInitializer {
139 modelSeedBuilder.seed(partialRelation, info.toSeed(nodeCount)); 142 modelSeedBuilder.seed(partialRelation, info.toSeed(nodeCount));
140 } 143 }
141 collectScopes(); 144 collectScopes();
145 if (scopePropagator != null) {
146 if (storeBuilder.tryGetAdapter(PropagationBuilder.class).isEmpty()) {
147 throw new TracedException(problem, "Type scopes require a PropagationBuilder");
148 }
149 storeBuilder.with(scopePropagator);
150 }
142 modelSeedBuilder.seed(MultiObjectTranslator.COUNT_SYMBOL, builder -> builder 151 modelSeedBuilder.seed(MultiObjectTranslator.COUNT_SYMBOL, builder -> builder
143 .reducedValue(CardinalityIntervals.SET) 152 .reducedValue(CardinalityIntervals.SET)
144 .putAll(countSeed)); 153 .putAll(countSeed));
@@ -534,8 +543,7 @@ public class ModelInitializer {
534 } 543 }
535 } 544 }
536 545
537 private void toLiterals(Expr expr, Map<tools.refinery.language.model.problem.Variable, 546 private void toLiterals(Expr expr, Map<tools.refinery.language.model.problem.Variable, Variable> localScope,
538 Variable> localScope,
539 List<Literal> literals) { 547 List<Literal> literals) {
540 if (expr instanceof LogicConstant logicConstant) { 548 if (expr instanceof LogicConstant logicConstant) {
541 switch (logicConstant.getLogicValue()) { 549 switch (logicConstant.getLogicValue()) {
@@ -645,14 +653,15 @@ public class ModelInitializer {
645 } 653 }
646 654
647 private void collectTypeScope(TypeScope typeScope) { 655 private void collectTypeScope(TypeScope typeScope) {
648 var scopePropagatorBuilder = storeBuilder.tryGetAdapter(ScopePropagatorBuilder.class).orElseThrow(
649 () -> new TracedException(typeScope, "Type scopes require a ScopePropagatorBuilder"));
650 var type = relationTrace.get(typeScope.getTargetType()); 656 var type = relationTrace.get(typeScope.getTargetType());
651 if (type == null) { 657 if (type == null) {
652 throw new TracedException(typeScope, "Unknown target type"); 658 throw new TracedException(typeScope, "Unknown target type");
653 } 659 }
654 var interval = getCardinalityInterval(typeScope.getMultiplicity()); 660 var interval = getCardinalityInterval(typeScope.getMultiplicity());
655 scopePropagatorBuilder.scope(type, interval); 661 if (scopePropagator == null) {
662 scopePropagator = new ScopePropagator();
663 }
664 scopePropagator.scope(type, interval);
656 } 665 }
657 666
658 private record RelationInfo(PartialRelation partialRelation, MutableSeed<TruthValue> assertions, 667 private record RelationInfo(PartialRelation partialRelation, MutableSeed<TruthValue> assertions,