aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store-reasoning-scope/src/main/java/tools
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/store-reasoning-scope/src/main/java/tools
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/store-reasoning-scope/src/main/java/tools')
-rw-r--r--subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/BoundScopePropagator.java (renamed from subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/ScopePropagatorAdapterImpl.java)58
-rw-r--r--subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/LowerTypeScopePropagator.java (renamed from subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/LowerTypeScopePropagator.java)14
-rw-r--r--subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/RoundingUtil.java (renamed from subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/RoundingUtil.java)2
-rw-r--r--subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/ScopePropagator.java (renamed from subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/ScopePropagatorBuilderImpl.java)64
-rw-r--r--subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/ScopePropagatorAdapter.java21
-rw-r--r--subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/ScopePropagatorBuilder.java21
-rw-r--r--subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/ScopePropagatorStoreAdapter.java16
-rw-r--r--subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/TypeScopePropagator.java (renamed from subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/TypeScopePropagator.java)13
-rw-r--r--subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/UpperTypeScopePropagator.java (renamed from subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/UpperTypeScopePropagator.java)6
-rw-r--r--subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/ScopePropagatorStoreAdapterImpl.java58
10 files changed, 74 insertions, 199 deletions
diff --git a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/ScopePropagatorAdapterImpl.java b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/BoundScopePropagator.java
index 99c501ce..62aadb4a 100644
--- a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/ScopePropagatorAdapterImpl.java
+++ b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/BoundScopePropagator.java
@@ -3,7 +3,7 @@
3 * 3 *
4 * SPDX-License-Identifier: EPL-2.0 4 * SPDX-License-Identifier: EPL-2.0
5 */ 5 */
6package tools.refinery.store.reasoning.scope.internal; 6package tools.refinery.store.reasoning.scope;
7 7
8import com.google.ortools.linearsolver.MPConstraint; 8import com.google.ortools.linearsolver.MPConstraint;
9import com.google.ortools.linearsolver.MPObjective; 9import com.google.ortools.linearsolver.MPObjective;
@@ -13,18 +13,15 @@ import org.eclipse.collections.api.factory.primitive.IntObjectMaps;
13import org.eclipse.collections.api.factory.primitive.IntSets; 13import org.eclipse.collections.api.factory.primitive.IntSets;
14import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; 14import org.eclipse.collections.api.map.primitive.MutableIntObjectMap;
15import org.eclipse.collections.api.set.primitive.MutableIntSet; 15import org.eclipse.collections.api.set.primitive.MutableIntSet;
16import tools.refinery.store.dse.propagation.BoundPropagator;
17import tools.refinery.store.dse.propagation.PropagationResult;
16import tools.refinery.store.model.Interpretation; 18import tools.refinery.store.model.Interpretation;
17import tools.refinery.store.model.Model; 19import tools.refinery.store.model.Model;
18import tools.refinery.store.query.ModelQueryAdapter; 20import tools.refinery.store.query.ModelQueryAdapter;
19import tools.refinery.store.reasoning.refinement.RefinementResult;
20import tools.refinery.store.reasoning.scope.ScopePropagatorAdapter;
21import tools.refinery.store.reasoning.scope.ScopePropagatorStoreAdapter;
22import tools.refinery.store.representation.cardinality.*; 21import tools.refinery.store.representation.cardinality.*;
23import tools.refinery.store.tuple.Tuple; 22import tools.refinery.store.tuple.Tuple;
24 23
25class ScopePropagatorAdapterImpl implements ScopePropagatorAdapter { 24class BoundScopePropagator implements BoundPropagator {
26 private final Model model;
27 private final ScopePropagatorStoreAdapterImpl storeAdapter;
28 private final ModelQueryAdapter queryEngine; 25 private final ModelQueryAdapter queryEngine;
29 private final Interpretation<CardinalityInterval> countInterpretation; 26 private final Interpretation<CardinalityInterval> countInterpretation;
30 private final MPSolver solver; 27 private final MPSolver solver;
@@ -34,30 +31,22 @@ class ScopePropagatorAdapterImpl implements ScopePropagatorAdapter {
34 private final TypeScopePropagator[] propagators; 31 private final TypeScopePropagator[] propagators;
35 private boolean changed = true; 32 private boolean changed = true;
36 33
37 public ScopePropagatorAdapterImpl(Model model, ScopePropagatorStoreAdapterImpl storeAdapter) { 34 public BoundScopePropagator(Model model, ScopePropagator storeAdapter) {
38 this.model = model;
39 this.storeAdapter = storeAdapter;
40 queryEngine = model.getAdapter(ModelQueryAdapter.class); 35 queryEngine = model.getAdapter(ModelQueryAdapter.class);
41 countInterpretation = model.getInterpretation(storeAdapter.getCountSymbol()); 36 countInterpretation = model.getInterpretation(storeAdapter.getCountSymbol());
42 solver = MPSolver.createSolver("GLOP"); 37 solver = MPSolver.createSolver("GLOP");
43 objective = solver.objective(); 38 objective = solver.objective();
44 initializeVariables(); 39 initializeVariables();
45 countInterpretation.addListener(this::countChanged, true); 40 countInterpretation.addListener(this::countChanged, true);
46 var propagatorFactories = storeAdapter.getPropagatorFactories(); 41 var propagatorFactories = storeAdapter.getTypeScopePropagatorFactories();
47 propagators = new TypeScopePropagator[propagatorFactories.size()]; 42 propagators = new TypeScopePropagator[propagatorFactories.size()];
48 for (int i = 0; i < propagators.length; i++) { 43 for (int i = 0; i < propagators.length; i++) {
49 propagators[i] = propagatorFactories.get(i).createPropagator(this); 44 propagators[i] = propagatorFactories.get(i).createPropagator(this);
50 } 45 }
51 } 46 }
52 47
53 @Override 48 ModelQueryAdapter getQueryEngine() {
54 public Model getModel() { 49 return queryEngine;
55 return model;
56 }
57
58 @Override
59 public ScopePropagatorStoreAdapter getStoreAdapter() {
60 return storeAdapter;
61 } 50 }
62 51
63 private void initializeVariables() { 52 private void initializeVariables() {
@@ -149,29 +138,16 @@ class ScopePropagatorAdapterImpl implements ScopePropagatorAdapter {
149 } 138 }
150 139
151 @Override 140 @Override
152 public RefinementResult propagate() { 141 public PropagationResult propagateOne() {
153 var result = RefinementResult.UNCHANGED;
154 RefinementResult currentRoundResult;
155 do {
156 currentRoundResult = propagateOne();
157 result = result.andThen(currentRoundResult);
158 if (result.isRejected()) {
159 return result;
160 }
161 } while (currentRoundResult != RefinementResult.UNCHANGED);
162 return result;
163 }
164
165 private RefinementResult propagateOne() {
166 queryEngine.flushChanges(); 142 queryEngine.flushChanges();
167 if (!changed) { 143 if (!changed) {
168 return RefinementResult.UNCHANGED; 144 return PropagationResult.UNCHANGED;
169 } 145 }
170 changed = false; 146 changed = false;
171 for (var propagator : propagators) { 147 for (var propagator : propagators) {
172 propagator.updateBounds(); 148 propagator.updateBounds();
173 } 149 }
174 var result = RefinementResult.UNCHANGED; 150 var result = PropagationResult.UNCHANGED;
175 if (activeVariables.isEmpty()) { 151 if (activeVariables.isEmpty()) {
176 return checkEmptiness(); 152 return checkEmptiness();
177 } 153 }
@@ -190,16 +166,16 @@ class ScopePropagatorAdapterImpl implements ScopePropagatorAdapter {
190 return result; 166 return result;
191 } 167 }
192 168
193 private RefinementResult checkEmptiness() { 169 private PropagationResult checkEmptiness() {
194 var emptinessCheckingResult = solver.solve(); 170 var emptinessCheckingResult = solver.solve();
195 return switch (emptinessCheckingResult) { 171 return switch (emptinessCheckingResult) {
196 case OPTIMAL, UNBOUNDED -> RefinementResult.UNCHANGED; 172 case OPTIMAL, UNBOUNDED -> PropagationResult.UNCHANGED;
197 case INFEASIBLE -> RefinementResult.REJECTED; 173 case INFEASIBLE -> PropagationResult.REJECTED;
198 default -> throw new IllegalStateException("Failed to check for consistency: " + emptinessCheckingResult); 174 default -> throw new IllegalStateException("Failed to check for consistency: " + emptinessCheckingResult);
199 }; 175 };
200 } 176 }
201 177
202 private RefinementResult propagateNode(int nodeId, MPVariable variable) { 178 private PropagationResult propagateNode(int nodeId, MPVariable variable) {
203 objective.setCoefficient(variable, 1); 179 objective.setCoefficient(variable, 1);
204 try { 180 try {
205 objective.setMinimization(); 181 objective.setMinimization();
@@ -209,7 +185,7 @@ class ScopePropagatorAdapterImpl implements ScopePropagatorAdapter {
209 case OPTIMAL -> lowerBound = RoundingUtil.roundUp(objective.value()); 185 case OPTIMAL -> lowerBound = RoundingUtil.roundUp(objective.value());
210 case UNBOUNDED -> lowerBound = 0; 186 case UNBOUNDED -> lowerBound = 0;
211 case INFEASIBLE -> { 187 case INFEASIBLE -> {
212 return RefinementResult.REJECTED; 188 return PropagationResult.REJECTED;
213 } 189 }
214 default -> throw new IllegalStateException("Failed to solve for minimum of %s: %s" 190 default -> throw new IllegalStateException("Failed to solve for minimum of %s: %s"
215 .formatted(variable, minimizationResult)); 191 .formatted(variable, minimizationResult));
@@ -234,7 +210,7 @@ class ScopePropagatorAdapterImpl implements ScopePropagatorAdapter {
234 throw new IllegalArgumentException("Failed to refine multiplicity %s of node %d to %s" 210 throw new IllegalArgumentException("Failed to refine multiplicity %s of node %d to %s"
235 .formatted(oldInterval, nodeId, newInterval)); 211 .formatted(oldInterval, nodeId, newInterval));
236 } 212 }
237 return newInterval.equals(oldInterval) ? RefinementResult.UNCHANGED : RefinementResult.REFINED; 213 return newInterval.equals(oldInterval) ? PropagationResult.UNCHANGED : PropagationResult.PROPAGATED;
238 } finally { 214 } finally {
239 objective.setCoefficient(variable, 0); 215 objective.setCoefficient(variable, 0);
240 } 216 }
diff --git a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/LowerTypeScopePropagator.java b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/LowerTypeScopePropagator.java
index 393c4b72..5d903f41 100644
--- a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/LowerTypeScopePropagator.java
+++ b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/LowerTypeScopePropagator.java
@@ -3,7 +3,7 @@
3 * 3 *
4 * SPDX-License-Identifier: EPL-2.0 4 * SPDX-License-Identifier: EPL-2.0
5 */ 5 */
6package tools.refinery.store.reasoning.scope.internal; 6package tools.refinery.store.reasoning.scope;
7 7
8import tools.refinery.store.dse.transition.DesignSpaceExplorationBuilder; 8import tools.refinery.store.dse.transition.DesignSpaceExplorationBuilder;
9import tools.refinery.store.dse.transition.objectives.Criteria; 9import tools.refinery.store.dse.transition.objectives.Criteria;
@@ -28,7 +28,7 @@ import static tools.refinery.store.reasoning.translator.multiobject.MultiObjectT
28class LowerTypeScopePropagator extends TypeScopePropagator { 28class LowerTypeScopePropagator extends TypeScopePropagator {
29 private final int lowerBound; 29 private final int lowerBound;
30 30
31 private LowerTypeScopePropagator(ScopePropagatorAdapterImpl adapter, int lowerBound, RelationalQuery allQuery, 31 private LowerTypeScopePropagator(BoundScopePropagator adapter, int lowerBound, RelationalQuery allQuery,
32 RelationalQuery multiQuery) { 32 RelationalQuery multiQuery) {
33 super(adapter, allQuery, multiQuery); 33 super(adapter, allQuery, multiQuery);
34 this.lowerBound = lowerBound; 34 this.lowerBound = lowerBound;
@@ -58,7 +58,7 @@ class LowerTypeScopePropagator extends TypeScopePropagator {
58 } 58 }
59 59
60 @Override 60 @Override
61 public TypeScopePropagator createPropagator(ScopePropagatorAdapterImpl adapter) { 61 public TypeScopePropagator createPropagator(BoundScopePropagator adapter) {
62 return new LowerTypeScopePropagator(adapter, lowerBound, allMay, multiMay); 62 return new LowerTypeScopePropagator(adapter, lowerBound, allMay, multiMay);
63 } 63 }
64 64
@@ -72,10 +72,10 @@ class LowerTypeScopePropagator extends TypeScopePropagator {
72 super.configure(storeBuilder); 72 super.configure(storeBuilder);
73 73
74 var requiredObjects = Query.of(type.name() + "#required", Integer.class, (builder, output) -> builder 74 var requiredObjects = Query.of(type.name() + "#required", Integer.class, (builder, output) -> builder
75 .clause(Integer.class, currentCount -> List.of( 75 .clause(Integer.class, candidateLowerBound -> List.of(
76 new CountCandidateLowerBoundLiteral(currentCount, type, List.of(Variable.of())), 76 new CountCandidateLowerBoundLiteral(candidateLowerBound, type, List.of(Variable.of())),
77 output.assign(sub(currentCount, constant(lowerBound))), 77 output.assign(sub(constant(lowerBound), candidateLowerBound)),
78 check(greater(currentCount, constant(0))) 78 check(greater(output, constant(0)))
79 ))); 79 )));
80 80
81 storeBuilder.getAdapter(ReasoningBuilder.class).objective(Objectives.value(requiredObjects)); 81 storeBuilder.getAdapter(ReasoningBuilder.class).objective(Objectives.value(requiredObjects));
diff --git a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/RoundingUtil.java b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/RoundingUtil.java
index a6d663ea..986771a1 100644
--- a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/RoundingUtil.java
+++ b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/RoundingUtil.java
@@ -3,7 +3,7 @@
3 * 3 *
4 * SPDX-License-Identifier: EPL-2.0 4 * SPDX-License-Identifier: EPL-2.0
5 */ 5 */
6package tools.refinery.store.reasoning.scope.internal; 6package tools.refinery.store.reasoning.scope;
7 7
8final class RoundingUtil { 8final class RoundingUtil {
9 private static final double TOLERANCE = 0.01; 9 private static final double TOLERANCE = 0.01;
diff --git a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/ScopePropagatorBuilderImpl.java b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/ScopePropagator.java
index 531a7440..25b1966c 100644
--- a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/ScopePropagatorBuilderImpl.java
+++ b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/ScopePropagator.java
@@ -3,15 +3,13 @@
3 * 3 *
4 * SPDX-License-Identifier: EPL-2.0 4 * SPDX-License-Identifier: EPL-2.0
5 */ 5 */
6package tools.refinery.store.reasoning.scope.internal; 6package tools.refinery.store.reasoning.scope;
7 7
8import com.google.ortools.Loader; 8import com.google.ortools.Loader;
9import tools.refinery.store.adapter.AbstractModelAdapterBuilder; 9import tools.refinery.store.dse.propagation.PropagationBuilder;
10import tools.refinery.store.model.ModelStore;
11import tools.refinery.store.model.ModelStoreBuilder; 10import tools.refinery.store.model.ModelStoreBuilder;
11import tools.refinery.store.model.ModelStoreConfiguration;
12import tools.refinery.store.reasoning.representation.PartialRelation; 12import tools.refinery.store.reasoning.representation.PartialRelation;
13import tools.refinery.store.reasoning.scope.ScopePropagatorBuilder;
14import tools.refinery.store.reasoning.scope.ScopePropagatorStoreAdapter;
15import tools.refinery.store.reasoning.translator.TranslationException; 13import tools.refinery.store.reasoning.translator.TranslationException;
16import tools.refinery.store.reasoning.translator.multiobject.MultiObjectTranslator; 14import tools.refinery.store.reasoning.translator.multiobject.MultiObjectTranslator;
17import tools.refinery.store.representation.Symbol; 15import tools.refinery.store.representation.Symbol;
@@ -20,14 +18,16 @@ import tools.refinery.store.representation.cardinality.FiniteUpperCardinality;
20 18
21import java.util.*; 19import java.util.*;
22 20
23public class ScopePropagatorBuilderImpl extends AbstractModelAdapterBuilder<ScopePropagatorStoreAdapter> 21public class ScopePropagator implements ModelStoreConfiguration {
24 implements ScopePropagatorBuilder { 22 private final Symbol<CardinalityInterval> countSymbol;
25 private Symbol<CardinalityInterval> countSymbol = MultiObjectTranslator.COUNT_STORAGE;
26 private final Map<PartialRelation, CardinalityInterval> scopes = new LinkedHashMap<>(); 23 private final Map<PartialRelation, CardinalityInterval> scopes = new LinkedHashMap<>();
27 private List<TypeScopePropagator.Factory> typeScopePropagatorFactories; 24 private final List<TypeScopePropagator.Factory> typeScopePropagatorFactories = new ArrayList<>();
28 25
29 @Override 26 public ScopePropagator() {
30 public ScopePropagatorBuilder countSymbol(Symbol<CardinalityInterval> countSymbol) { 27 this(MultiObjectTranslator.COUNT_STORAGE);
28 }
29
30 public ScopePropagator(Symbol<CardinalityInterval> countSymbol) {
31 if (countSymbol.arity() != 1) { 31 if (countSymbol.arity() != 1) {
32 throw new IllegalArgumentException("Count symbol must have arty 1, got %s with arity %d instead" 32 throw new IllegalArgumentException("Count symbol must have arty 1, got %s with arity %d instead"
33 .formatted(countSymbol, countSymbol.arity())); 33 .formatted(countSymbol, countSymbol.arity()));
@@ -39,11 +39,9 @@ public class ScopePropagatorBuilderImpl extends AbstractModelAdapterBuilder<Scop
39 throw new IllegalArgumentException("Count symbol must default value null"); 39 throw new IllegalArgumentException("Count symbol must default value null");
40 } 40 }
41 this.countSymbol = countSymbol; 41 this.countSymbol = countSymbol;
42 return this;
43 } 42 }
44 43
45 @Override 44 public ScopePropagator scope(PartialRelation type, CardinalityInterval interval) {
46 public ScopePropagatorBuilder scope(PartialRelation type, CardinalityInterval interval) {
47 if (type.arity() != 1) { 45 if (type.arity() != 1) {
48 throw new TranslationException(type, "Only types with arity 1 may have scopes, got %s with arity %d" 46 throw new TranslationException(type, "Only types with arity 1 may have scopes, got %s with arity %d"
49 .formatted(type, type.arity())); 47 .formatted(type, type.arity()));
@@ -56,9 +54,29 @@ public class ScopePropagatorBuilderImpl extends AbstractModelAdapterBuilder<Scop
56 return this; 54 return this;
57 } 55 }
58 56
57 public ScopePropagator scopes(Map<PartialRelation, CardinalityInterval> scopes) {
58 return scopes(scopes.entrySet());
59 }
60
61 public ScopePropagator scopes(Collection<Map.Entry<PartialRelation, CardinalityInterval>> scopes) {
62 for (var entry : scopes) {
63 scope(entry.getKey(), entry.getValue());
64 }
65 return this;
66 }
67
59 @Override 68 @Override
60 protected void doConfigure(ModelStoreBuilder storeBuilder) { 69 public void apply(ModelStoreBuilder storeBuilder) {
61 typeScopePropagatorFactories = new ArrayList<>(scopes.size()); 70 createTypeScopePropagatorFactories();
71 Loader.loadNativeLibraries();
72 for (var factory : typeScopePropagatorFactories) {
73 factory.configure(storeBuilder);
74 }
75 storeBuilder.getAdapter(PropagationBuilder.class)
76 .propagator(model -> new BoundScopePropagator(model, this));
77 }
78
79 private void createTypeScopePropagatorFactories() {
62 for (var entry : scopes.entrySet()) { 80 for (var entry : scopes.entrySet()) {
63 var type = entry.getKey(); 81 var type = entry.getKey();
64 var bounds = entry.getValue(); 82 var bounds = entry.getValue();
@@ -72,15 +90,13 @@ public class ScopePropagatorBuilderImpl extends AbstractModelAdapterBuilder<Scop
72 typeScopePropagatorFactories.add(upperFactory); 90 typeScopePropagatorFactories.add(upperFactory);
73 } 91 }
74 } 92 }
75 for (var factory : typeScopePropagatorFactories) {
76 factory.configure(storeBuilder);
77 }
78 } 93 }
79 94
80 @Override 95 Symbol<CardinalityInterval> getCountSymbol() {
81 protected ScopePropagatorStoreAdapter doBuild(ModelStore store) { 96 return countSymbol;
82 Loader.loadNativeLibraries(); 97 }
83 return new ScopePropagatorStoreAdapterImpl(store, countSymbol, Collections.unmodifiableMap(scopes), 98
84 Collections.unmodifiableList(typeScopePropagatorFactories)); 99 List<TypeScopePropagator.Factory> getTypeScopePropagatorFactories() {
100 return typeScopePropagatorFactories;
85 } 101 }
86} 102}
diff --git a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/ScopePropagatorAdapter.java b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/ScopePropagatorAdapter.java
deleted file mode 100644
index c2d3f59e..00000000
--- a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/ScopePropagatorAdapter.java
+++ /dev/null
@@ -1,21 +0,0 @@
1/*
2 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package tools.refinery.store.reasoning.scope;
7
8import tools.refinery.store.adapter.ModelAdapter;
9import tools.refinery.store.reasoning.refinement.RefinementResult;
10import tools.refinery.store.reasoning.scope.internal.ScopePropagatorBuilderImpl;
11
12public interface ScopePropagatorAdapter extends ModelAdapter {
13 @Override
14 ScopePropagatorStoreAdapter getStoreAdapter();
15
16 RefinementResult propagate();
17
18 static ScopePropagatorBuilder builder() {
19 return new ScopePropagatorBuilderImpl();
20 }
21}
diff --git a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/ScopePropagatorBuilder.java b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/ScopePropagatorBuilder.java
deleted file mode 100644
index a17e04a4..00000000
--- a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/ScopePropagatorBuilder.java
+++ /dev/null
@@ -1,21 +0,0 @@
1/*
2 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package tools.refinery.store.reasoning.scope;
7
8import tools.refinery.store.adapter.ModelAdapterBuilder;
9import tools.refinery.store.model.ModelStore;
10import tools.refinery.store.reasoning.representation.PartialRelation;
11import tools.refinery.store.representation.Symbol;
12import tools.refinery.store.representation.cardinality.CardinalityInterval;
13
14public interface ScopePropagatorBuilder extends ModelAdapterBuilder {
15 ScopePropagatorBuilder countSymbol(Symbol<CardinalityInterval> countSymbol);
16
17 ScopePropagatorBuilder scope(PartialRelation type, CardinalityInterval interval);
18
19 @Override
20 ScopePropagatorStoreAdapter build(ModelStore store);
21}
diff --git a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/ScopePropagatorStoreAdapter.java b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/ScopePropagatorStoreAdapter.java
deleted file mode 100644
index 65d9c38d..00000000
--- a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/ScopePropagatorStoreAdapter.java
+++ /dev/null
@@ -1,16 +0,0 @@
1/*
2 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package tools.refinery.store.reasoning.scope;
7
8import tools.refinery.store.adapter.ModelStoreAdapter;
9import tools.refinery.store.reasoning.representation.PartialRelation;
10import tools.refinery.store.representation.cardinality.CardinalityInterval;
11
12import java.util.Map;
13
14public interface ScopePropagatorStoreAdapter extends ModelStoreAdapter {
15 Map<PartialRelation, CardinalityInterval> getScopes();
16}
diff --git a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/TypeScopePropagator.java b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/TypeScopePropagator.java
index cfb95829..db80be7f 100644
--- a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/TypeScopePropagator.java
+++ b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/TypeScopePropagator.java
@@ -3,11 +3,10 @@
3 * 3 *
4 * SPDX-License-Identifier: EPL-2.0 4 * SPDX-License-Identifier: EPL-2.0
5 */ 5 */
6package tools.refinery.store.reasoning.scope.internal; 6package tools.refinery.store.reasoning.scope;
7 7
8import com.google.ortools.linearsolver.MPConstraint; 8import com.google.ortools.linearsolver.MPConstraint;
9import tools.refinery.store.model.ModelStoreBuilder; 9import tools.refinery.store.model.ModelStoreBuilder;
10import tools.refinery.store.query.ModelQueryAdapter;
11import tools.refinery.store.query.ModelQueryBuilder; 10import tools.refinery.store.query.ModelQueryBuilder;
12import tools.refinery.store.query.dnf.AnyQuery; 11import tools.refinery.store.query.dnf.AnyQuery;
13import tools.refinery.store.query.dnf.RelationalQuery; 12import tools.refinery.store.query.dnf.RelationalQuery;
@@ -17,15 +16,15 @@ import tools.refinery.store.tuple.Tuple;
17import java.util.Collection; 16import java.util.Collection;
18 17
19abstract class TypeScopePropagator { 18abstract class TypeScopePropagator {
20 private final ScopePropagatorAdapterImpl adapter; 19 private final BoundScopePropagator adapter;
21 private final ResultSet<Boolean> allNodes; 20 private final ResultSet<Boolean> allNodes;
22 private final ResultSet<Boolean> multiNodes; 21 private final ResultSet<Boolean> multiNodes;
23 protected final MPConstraint constraint; 22 protected final MPConstraint constraint;
24 23
25 protected TypeScopePropagator(ScopePropagatorAdapterImpl adapter, RelationalQuery allQuery, 24 protected TypeScopePropagator(BoundScopePropagator adapter, RelationalQuery allQuery,
26 RelationalQuery multiQuery) { 25 RelationalQuery multiQuery) {
27 this.adapter = adapter; 26 this.adapter = adapter;
28 var queryEngine = adapter.getModel().getAdapter(ModelQueryAdapter.class); 27 var queryEngine = adapter.getQueryEngine();
29 allNodes = queryEngine.getResultSet(allQuery); 28 allNodes = queryEngine.getResultSet(allQuery);
30 multiNodes = queryEngine.getResultSet(multiQuery); 29 multiNodes = queryEngine.getResultSet(multiQuery);
31 constraint = adapter.makeConstraint(); 30 constraint = adapter.makeConstraint();
@@ -56,7 +55,7 @@ abstract class TypeScopePropagator {
56 } 55 }
57 56
58 public abstract static class Factory { 57 public abstract static class Factory {
59 public abstract TypeScopePropagator createPropagator(ScopePropagatorAdapterImpl adapter); 58 public abstract TypeScopePropagator createPropagator(BoundScopePropagator adapter);
60 59
61 protected abstract Collection<AnyQuery> getQueries(); 60 protected abstract Collection<AnyQuery> getQueries();
62 61
diff --git a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/UpperTypeScopePropagator.java b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/UpperTypeScopePropagator.java
index a0be0fb4..062f976c 100644
--- a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/UpperTypeScopePropagator.java
+++ b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/UpperTypeScopePropagator.java
@@ -3,7 +3,7 @@
3 * 3 *
4 * SPDX-License-Identifier: EPL-2.0 4 * SPDX-License-Identifier: EPL-2.0
5 */ 5 */
6package tools.refinery.store.reasoning.scope.internal; 6package tools.refinery.store.reasoning.scope;
7 7
8import tools.refinery.store.query.dnf.AnyQuery; 8import tools.refinery.store.query.dnf.AnyQuery;
9import tools.refinery.store.query.dnf.Query; 9import tools.refinery.store.query.dnf.Query;
@@ -19,7 +19,7 @@ import static tools.refinery.store.reasoning.translator.multiobject.MultiObjectT
19class UpperTypeScopePropagator extends TypeScopePropagator { 19class UpperTypeScopePropagator extends TypeScopePropagator {
20 private final int upperBound; 20 private final int upperBound;
21 21
22 private UpperTypeScopePropagator(ScopePropagatorAdapterImpl adapter, int upperBound, RelationalQuery allQuery, 22 private UpperTypeScopePropagator(BoundScopePropagator adapter, int upperBound, RelationalQuery allQuery,
23 RelationalQuery multiQuery) { 23 RelationalQuery multiQuery) {
24 super(adapter, allQuery, multiQuery); 24 super(adapter, allQuery, multiQuery);
25 this.upperBound = upperBound; 25 this.upperBound = upperBound;
@@ -47,7 +47,7 @@ class UpperTypeScopePropagator extends TypeScopePropagator {
47 } 47 }
48 48
49 @Override 49 @Override
50 public TypeScopePropagator createPropagator(ScopePropagatorAdapterImpl adapter) { 50 public TypeScopePropagator createPropagator(BoundScopePropagator adapter) {
51 return new UpperTypeScopePropagator(adapter, upperBound, allMust, multiMust); 51 return new UpperTypeScopePropagator(adapter, upperBound, allMust, multiMust);
52 } 52 }
53 53
diff --git a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/ScopePropagatorStoreAdapterImpl.java b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/ScopePropagatorStoreAdapterImpl.java
deleted file mode 100644
index 282ffe6f..00000000
--- a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/ScopePropagatorStoreAdapterImpl.java
+++ /dev/null
@@ -1,58 +0,0 @@
1/*
2 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package tools.refinery.store.reasoning.scope.internal;
7
8import tools.refinery.store.adapter.ModelAdapter;
9import tools.refinery.store.model.Model;
10import tools.refinery.store.model.ModelStore;
11import tools.refinery.store.reasoning.representation.PartialRelation;
12import tools.refinery.store.reasoning.scope.ScopePropagatorStoreAdapter;
13import tools.refinery.store.representation.Symbol;
14import tools.refinery.store.representation.cardinality.CardinalityInterval;
15
16import java.util.List;
17import java.util.Map;
18
19// Not a record, because we want to control getter visibility.
20@SuppressWarnings("ClassCanBeRecord")
21class ScopePropagatorStoreAdapterImpl implements ScopePropagatorStoreAdapter {
22 private final ModelStore store;
23 private final Symbol<CardinalityInterval> countSymbol;
24 private final Map<PartialRelation, CardinalityInterval> scopes;
25 private final List<TypeScopePropagator.Factory> propagatorFactories;
26
27 public ScopePropagatorStoreAdapterImpl(
28 ModelStore store, Symbol<CardinalityInterval> countSymbol,
29 Map<PartialRelation, CardinalityInterval> scopes, List<TypeScopePropagator.Factory> propagatorFactories) {
30 this.store = store;
31 this.countSymbol = countSymbol;
32 this.scopes = scopes;
33 this.propagatorFactories = propagatorFactories;
34 }
35
36 @Override
37 public ModelStore getStore() {
38 return store;
39 }
40
41 Symbol<CardinalityInterval> getCountSymbol() {
42 return countSymbol;
43 }
44
45 @Override
46 public Map<PartialRelation, CardinalityInterval> getScopes() {
47 return scopes;
48 }
49
50 public List<TypeScopePropagator.Factory> getPropagatorFactories() {
51 return propagatorFactories;
52 }
53
54 @Override
55 public ModelAdapter createModelAdapter(Model model) {
56 return new ScopePropagatorAdapterImpl(model, this);
57 }
58}