diff options
author | 2023-09-09 12:57:49 +0200 | |
---|---|---|
committer | 2023-09-09 12:57:49 +0200 | |
commit | 0bdb400deef88cb2a7c0b8c90afebf84b29c04d5 (patch) | |
tree | d8cf379d3f1321cb1e3e44e19226c48634ae97f2 /subprojects/store-reasoning-scope/src | |
parent | refactor(store): neighborhood optimization (diff) | |
download | refinery-0bdb400deef88cb2a7c0b8c90afebf84b29c04d5.tar.gz refinery-0bdb400deef88cb2a7c0b8c90afebf84b29c04d5.tar.zst refinery-0bdb400deef88cb2a7c0b8c90afebf84b29c04d5.zip |
feat: integrate DSE with partial interpretation
Diffstat (limited to 'subprojects/store-reasoning-scope/src')
12 files changed, 95 insertions, 218 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 | */ |
6 | package tools.refinery.store.reasoning.scope.internal; | 6 | package tools.refinery.store.reasoning.scope; |
7 | 7 | ||
8 | import com.google.ortools.linearsolver.MPConstraint; | 8 | import com.google.ortools.linearsolver.MPConstraint; |
9 | import com.google.ortools.linearsolver.MPObjective; | 9 | import com.google.ortools.linearsolver.MPObjective; |
@@ -13,18 +13,15 @@ import org.eclipse.collections.api.factory.primitive.IntObjectMaps; | |||
13 | import org.eclipse.collections.api.factory.primitive.IntSets; | 13 | import org.eclipse.collections.api.factory.primitive.IntSets; |
14 | import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; | 14 | import org.eclipse.collections.api.map.primitive.MutableIntObjectMap; |
15 | import org.eclipse.collections.api.set.primitive.MutableIntSet; | 15 | import org.eclipse.collections.api.set.primitive.MutableIntSet; |
16 | import tools.refinery.store.dse.propagation.BoundPropagator; | ||
17 | import tools.refinery.store.dse.propagation.PropagationResult; | ||
16 | import tools.refinery.store.model.Interpretation; | 18 | import tools.refinery.store.model.Interpretation; |
17 | import tools.refinery.store.model.Model; | 19 | import tools.refinery.store.model.Model; |
18 | import tools.refinery.store.query.ModelQueryAdapter; | 20 | import tools.refinery.store.query.ModelQueryAdapter; |
19 | import tools.refinery.store.reasoning.refinement.RefinementResult; | ||
20 | import tools.refinery.store.reasoning.scope.ScopePropagatorAdapter; | ||
21 | import tools.refinery.store.reasoning.scope.ScopePropagatorStoreAdapter; | ||
22 | import tools.refinery.store.representation.cardinality.*; | 21 | import tools.refinery.store.representation.cardinality.*; |
23 | import tools.refinery.store.tuple.Tuple; | 22 | import tools.refinery.store.tuple.Tuple; |
24 | 23 | ||
25 | class ScopePropagatorAdapterImpl implements ScopePropagatorAdapter { | 24 | class 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 | */ |
6 | package tools.refinery.store.reasoning.scope.internal; | 6 | package tools.refinery.store.reasoning.scope; |
7 | 7 | ||
8 | import tools.refinery.store.dse.transition.DesignSpaceExplorationBuilder; | 8 | import tools.refinery.store.dse.transition.DesignSpaceExplorationBuilder; |
9 | import tools.refinery.store.dse.transition.objectives.Criteria; | 9 | import tools.refinery.store.dse.transition.objectives.Criteria; |
@@ -28,7 +28,7 @@ import static tools.refinery.store.reasoning.translator.multiobject.MultiObjectT | |||
28 | class LowerTypeScopePropagator extends TypeScopePropagator { | 28 | class 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 | */ |
6 | package tools.refinery.store.reasoning.scope.internal; | 6 | package tools.refinery.store.reasoning.scope; |
7 | 7 | ||
8 | final class RoundingUtil { | 8 | final 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 | */ |
6 | package tools.refinery.store.reasoning.scope.internal; | 6 | package tools.refinery.store.reasoning.scope; |
7 | 7 | ||
8 | import com.google.ortools.Loader; | 8 | import com.google.ortools.Loader; |
9 | import tools.refinery.store.adapter.AbstractModelAdapterBuilder; | 9 | import tools.refinery.store.dse.propagation.PropagationBuilder; |
10 | import tools.refinery.store.model.ModelStore; | ||
11 | import tools.refinery.store.model.ModelStoreBuilder; | 10 | import tools.refinery.store.model.ModelStoreBuilder; |
11 | import tools.refinery.store.model.ModelStoreConfiguration; | ||
12 | import tools.refinery.store.reasoning.representation.PartialRelation; | 12 | import tools.refinery.store.reasoning.representation.PartialRelation; |
13 | import tools.refinery.store.reasoning.scope.ScopePropagatorBuilder; | ||
14 | import tools.refinery.store.reasoning.scope.ScopePropagatorStoreAdapter; | ||
15 | import tools.refinery.store.reasoning.translator.TranslationException; | 13 | import tools.refinery.store.reasoning.translator.TranslationException; |
16 | import tools.refinery.store.reasoning.translator.multiobject.MultiObjectTranslator; | 14 | import tools.refinery.store.reasoning.translator.multiobject.MultiObjectTranslator; |
17 | import tools.refinery.store.representation.Symbol; | 15 | import tools.refinery.store.representation.Symbol; |
@@ -20,14 +18,16 @@ import tools.refinery.store.representation.cardinality.FiniteUpperCardinality; | |||
20 | 18 | ||
21 | import java.util.*; | 19 | import java.util.*; |
22 | 20 | ||
23 | public class ScopePropagatorBuilderImpl extends AbstractModelAdapterBuilder<ScopePropagatorStoreAdapter> | 21 | public 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 | */ | ||
6 | package tools.refinery.store.reasoning.scope; | ||
7 | |||
8 | import tools.refinery.store.adapter.ModelAdapter; | ||
9 | import tools.refinery.store.reasoning.refinement.RefinementResult; | ||
10 | import tools.refinery.store.reasoning.scope.internal.ScopePropagatorBuilderImpl; | ||
11 | |||
12 | public 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 | */ | ||
6 | package tools.refinery.store.reasoning.scope; | ||
7 | |||
8 | import tools.refinery.store.adapter.ModelAdapterBuilder; | ||
9 | import tools.refinery.store.model.ModelStore; | ||
10 | import tools.refinery.store.reasoning.representation.PartialRelation; | ||
11 | import tools.refinery.store.representation.Symbol; | ||
12 | import tools.refinery.store.representation.cardinality.CardinalityInterval; | ||
13 | |||
14 | public 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 | */ | ||
6 | package tools.refinery.store.reasoning.scope; | ||
7 | |||
8 | import tools.refinery.store.adapter.ModelStoreAdapter; | ||
9 | import tools.refinery.store.reasoning.representation.PartialRelation; | ||
10 | import tools.refinery.store.representation.cardinality.CardinalityInterval; | ||
11 | |||
12 | import java.util.Map; | ||
13 | |||
14 | public 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 | */ |
6 | package tools.refinery.store.reasoning.scope.internal; | 6 | package tools.refinery.store.reasoning.scope; |
7 | 7 | ||
8 | import com.google.ortools.linearsolver.MPConstraint; | 8 | import com.google.ortools.linearsolver.MPConstraint; |
9 | import tools.refinery.store.model.ModelStoreBuilder; | 9 | import tools.refinery.store.model.ModelStoreBuilder; |
10 | import tools.refinery.store.query.ModelQueryAdapter; | ||
11 | import tools.refinery.store.query.ModelQueryBuilder; | 10 | import tools.refinery.store.query.ModelQueryBuilder; |
12 | import tools.refinery.store.query.dnf.AnyQuery; | 11 | import tools.refinery.store.query.dnf.AnyQuery; |
13 | import tools.refinery.store.query.dnf.RelationalQuery; | 12 | import tools.refinery.store.query.dnf.RelationalQuery; |
@@ -17,15 +16,15 @@ import tools.refinery.store.tuple.Tuple; | |||
17 | import java.util.Collection; | 16 | import java.util.Collection; |
18 | 17 | ||
19 | abstract class TypeScopePropagator { | 18 | abstract 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 | */ |
6 | package tools.refinery.store.reasoning.scope.internal; | 6 | package tools.refinery.store.reasoning.scope; |
7 | 7 | ||
8 | import tools.refinery.store.query.dnf.AnyQuery; | 8 | import tools.refinery.store.query.dnf.AnyQuery; |
9 | import tools.refinery.store.query.dnf.Query; | 9 | import tools.refinery.store.query.dnf.Query; |
@@ -19,7 +19,7 @@ import static tools.refinery.store.reasoning.translator.multiobject.MultiObjectT | |||
19 | class UpperTypeScopePropagator extends TypeScopePropagator { | 19 | class 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 | */ | ||
6 | package tools.refinery.store.reasoning.scope.internal; | ||
7 | |||
8 | import tools.refinery.store.adapter.ModelAdapter; | ||
9 | import tools.refinery.store.model.Model; | ||
10 | import tools.refinery.store.model.ModelStore; | ||
11 | import tools.refinery.store.reasoning.representation.PartialRelation; | ||
12 | import tools.refinery.store.reasoning.scope.ScopePropagatorStoreAdapter; | ||
13 | import tools.refinery.store.representation.Symbol; | ||
14 | import tools.refinery.store.representation.cardinality.CardinalityInterval; | ||
15 | |||
16 | import java.util.List; | ||
17 | import java.util.Map; | ||
18 | |||
19 | // Not a record, because we want to control getter visibility. | ||
20 | @SuppressWarnings("ClassCanBeRecord") | ||
21 | class 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 | } | ||
diff --git a/subprojects/store-reasoning-scope/src/test/java/tools/refinery/store/reasoning/scope/MultiObjectTest.java b/subprojects/store-reasoning-scope/src/test/java/tools/refinery/store/reasoning/scope/MultiObjectTest.java index 42ce2f56..5fc70ae1 100644 --- a/subprojects/store-reasoning-scope/src/test/java/tools/refinery/store/reasoning/scope/MultiObjectTest.java +++ b/subprojects/store-reasoning-scope/src/test/java/tools/refinery/store/reasoning/scope/MultiObjectTest.java | |||
@@ -7,13 +7,14 @@ package tools.refinery.store.reasoning.scope; | |||
7 | 7 | ||
8 | import org.junit.jupiter.api.BeforeEach; | 8 | import org.junit.jupiter.api.BeforeEach; |
9 | import org.junit.jupiter.api.Test; | 9 | import org.junit.jupiter.api.Test; |
10 | import tools.refinery.store.dse.propagation.PropagationAdapter; | ||
11 | import tools.refinery.store.dse.propagation.PropagationResult; | ||
10 | import tools.refinery.store.model.Interpretation; | 12 | import tools.refinery.store.model.Interpretation; |
11 | import tools.refinery.store.model.Model; | 13 | import tools.refinery.store.model.Model; |
12 | import tools.refinery.store.model.ModelStore; | 14 | import tools.refinery.store.model.ModelStore; |
13 | import tools.refinery.store.query.viatra.ViatraModelQueryAdapter; | 15 | import tools.refinery.store.query.viatra.ViatraModelQueryAdapter; |
14 | import tools.refinery.store.reasoning.ReasoningAdapter; | 16 | import tools.refinery.store.reasoning.ReasoningAdapter; |
15 | import tools.refinery.store.reasoning.ReasoningStoreAdapter; | 17 | import tools.refinery.store.reasoning.ReasoningStoreAdapter; |
16 | import tools.refinery.store.reasoning.refinement.RefinementResult; | ||
17 | import tools.refinery.store.reasoning.representation.PartialRelation; | 18 | import tools.refinery.store.reasoning.representation.PartialRelation; |
18 | import tools.refinery.store.reasoning.seed.ModelSeed; | 19 | import tools.refinery.store.reasoning.seed.ModelSeed; |
19 | import tools.refinery.store.reasoning.translator.PartialRelationTranslator; | 20 | import tools.refinery.store.reasoning.translator.PartialRelationTranslator; |
@@ -38,11 +39,12 @@ class MultiObjectTest { | |||
38 | void beforeEach() { | 39 | void beforeEach() { |
39 | store = ModelStore.builder() | 40 | store = ModelStore.builder() |
40 | .with(ViatraModelQueryAdapter.builder()) | 41 | .with(ViatraModelQueryAdapter.builder()) |
42 | .with(PropagationAdapter.builder()) | ||
41 | .with(ReasoningAdapter.builder()) | 43 | .with(ReasoningAdapter.builder()) |
42 | .with(new MultiObjectTranslator()) | 44 | .with(new MultiObjectTranslator()) |
43 | .with(PartialRelationTranslator.of(person) | 45 | .with(PartialRelationTranslator.of(person) |
44 | .symbol(Symbol.of("Person", 1, TruthValue.class, TruthValue.FALSE))) | 46 | .symbol(Symbol.of("Person", 1, TruthValue.class, TruthValue.FALSE))) |
45 | .with(ScopePropagatorAdapter.builder() | 47 | .with(new ScopePropagator() |
46 | .scope(person, CardinalityIntervals.between(5, 15))) | 48 | .scope(person, CardinalityIntervals.between(5, 15))) |
47 | .build(); | 49 | .build(); |
48 | model = null; | 50 | model = null; |
@@ -57,7 +59,7 @@ class MultiObjectTest { | |||
57 | .put(Tuple.of(0), CardinalityIntervals.SET)) | 59 | .put(Tuple.of(0), CardinalityIntervals.SET)) |
58 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) | 60 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) |
59 | .build()); | 61 | .build()); |
60 | assertThat(propagate(), is(RefinementResult.REFINED)); | 62 | assertThat(propagate(), is(PropagationResult.PROPAGATED)); |
61 | assertThat(countStorage.get(Tuple.of(0)), is(CardinalityIntervals.between(2, 12))); | 63 | assertThat(countStorage.get(Tuple.of(0)), is(CardinalityIntervals.between(2, 12))); |
62 | } | 64 | } |
63 | 65 | ||
@@ -69,7 +71,7 @@ class MultiObjectTest { | |||
69 | .put(Tuple.of(0), CardinalityIntervals.between(5, 20))) | 71 | .put(Tuple.of(0), CardinalityIntervals.between(5, 20))) |
70 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) | 72 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) |
71 | .build()); | 73 | .build()); |
72 | assertThat(propagate(), is(RefinementResult.REFINED)); | 74 | assertThat(propagate(), is(PropagationResult.PROPAGATED)); |
73 | assertThat(countStorage.get(Tuple.of(0)), is(CardinalityIntervals.between(5, 12))); | 75 | assertThat(countStorage.get(Tuple.of(0)), is(CardinalityIntervals.between(5, 12))); |
74 | } | 76 | } |
75 | 77 | ||
@@ -81,7 +83,7 @@ class MultiObjectTest { | |||
81 | .put(Tuple.of(0), CardinalityIntervals.SET)) | 83 | .put(Tuple.of(0), CardinalityIntervals.SET)) |
82 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) | 84 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) |
83 | .build()); | 85 | .build()); |
84 | assertThat(propagate(), is(RefinementResult.REJECTED)); | 86 | assertThat(propagate(), is(PropagationResult.REJECTED)); |
85 | } | 87 | } |
86 | 88 | ||
87 | @Test | 89 | @Test |
@@ -90,7 +92,7 @@ class MultiObjectTest { | |||
90 | .seed(MultiObjectTranslator.COUNT_SYMBOL, builder -> builder.reducedValue(CardinalityIntervals.ONE)) | 92 | .seed(MultiObjectTranslator.COUNT_SYMBOL, builder -> builder.reducedValue(CardinalityIntervals.ONE)) |
91 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) | 93 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) |
92 | .build()); | 94 | .build()); |
93 | assertThat(propagate(), is(RefinementResult.UNCHANGED)); | 95 | assertThat(propagate(), is(PropagationResult.UNCHANGED)); |
94 | } | 96 | } |
95 | 97 | ||
96 | @Test | 98 | @Test |
@@ -99,7 +101,7 @@ class MultiObjectTest { | |||
99 | .seed(MultiObjectTranslator.COUNT_SYMBOL, builder -> builder.reducedValue(CardinalityIntervals.ONE)) | 101 | .seed(MultiObjectTranslator.COUNT_SYMBOL, builder -> builder.reducedValue(CardinalityIntervals.ONE)) |
100 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) | 102 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) |
101 | .build()); | 103 | .build()); |
102 | assertThat(propagate(), is(RefinementResult.REJECTED)); | 104 | assertThat(propagate(), is(PropagationResult.REJECTED)); |
103 | } | 105 | } |
104 | 106 | ||
105 | @Test | 107 | @Test |
@@ -110,7 +112,7 @@ class MultiObjectTest { | |||
110 | .put(Tuple.of(0), CardinalityIntervals.atLeast(20))) | 112 | .put(Tuple.of(0), CardinalityIntervals.atLeast(20))) |
111 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) | 113 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) |
112 | .build()); | 114 | .build()); |
113 | assertThat(propagate(), is(RefinementResult.REJECTED)); | 115 | assertThat(propagate(), is(PropagationResult.REJECTED)); |
114 | } | 116 | } |
115 | 117 | ||
116 | @Test | 118 | @Test |
@@ -121,7 +123,7 @@ class MultiObjectTest { | |||
121 | .put(Tuple.of(0), CardinalityIntervals.atMost(1))) | 123 | .put(Tuple.of(0), CardinalityIntervals.atMost(1))) |
122 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) | 124 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) |
123 | .build()); | 125 | .build()); |
124 | assertThat(propagate(), is(RefinementResult.REJECTED)); | 126 | assertThat(propagate(), is(PropagationResult.REJECTED)); |
125 | } | 127 | } |
126 | 128 | ||
127 | @Test | 129 | @Test |
@@ -133,7 +135,7 @@ class MultiObjectTest { | |||
133 | .put(Tuple.of(1), CardinalityIntervals.SET)) | 135 | .put(Tuple.of(1), CardinalityIntervals.SET)) |
134 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) | 136 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) |
135 | .build()); | 137 | .build()); |
136 | assertThat(propagate(), is(RefinementResult.REFINED)); | 138 | assertThat(propagate(), is(PropagationResult.PROPAGATED)); |
137 | assertThat(countStorage.get(Tuple.of(0)), is(CardinalityIntervals.atMost(12))); | 139 | assertThat(countStorage.get(Tuple.of(0)), is(CardinalityIntervals.atMost(12))); |
138 | assertThat(countStorage.get(Tuple.of(1)), is(CardinalityIntervals.atMost(12))); | 140 | assertThat(countStorage.get(Tuple.of(1)), is(CardinalityIntervals.atMost(12))); |
139 | } | 141 | } |
@@ -147,7 +149,7 @@ class MultiObjectTest { | |||
147 | .put(Tuple.of(1), CardinalityIntervals.atMost(11))) | 149 | .put(Tuple.of(1), CardinalityIntervals.atMost(11))) |
148 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) | 150 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) |
149 | .build()); | 151 | .build()); |
150 | assertThat(propagate(), is(RefinementResult.REFINED)); | 152 | assertThat(propagate(), is(PropagationResult.PROPAGATED)); |
151 | assertThat(countStorage.get(Tuple.of(0)), is(CardinalityIntervals.between(7, 12))); | 153 | assertThat(countStorage.get(Tuple.of(0)), is(CardinalityIntervals.between(7, 12))); |
152 | assertThat(countStorage.get(Tuple.of(1)), is(CardinalityIntervals.atMost(5))); | 154 | assertThat(countStorage.get(Tuple.of(1)), is(CardinalityIntervals.atMost(5))); |
153 | } | 155 | } |
@@ -161,7 +163,7 @@ class MultiObjectTest { | |||
161 | .put(Tuple.of(1), CardinalityIntervals.exactly(11))) | 163 | .put(Tuple.of(1), CardinalityIntervals.exactly(11))) |
162 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) | 164 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) |
163 | .build()); | 165 | .build()); |
164 | assertThat(propagate(), is(RefinementResult.REJECTED)); | 166 | assertThat(propagate(), is(PropagationResult.REJECTED)); |
165 | } | 167 | } |
166 | 168 | ||
167 | @Test | 169 | @Test |
@@ -173,7 +175,7 @@ class MultiObjectTest { | |||
173 | .put(Tuple.of(1), CardinalityIntervals.atMost(2))) | 175 | .put(Tuple.of(1), CardinalityIntervals.atMost(2))) |
174 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) | 176 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) |
175 | .build()); | 177 | .build()); |
176 | assertThat(propagate(), is(RefinementResult.REJECTED)); | 178 | assertThat(propagate(), is(PropagationResult.REJECTED)); |
177 | } | 179 | } |
178 | 180 | ||
179 | @Test | 181 | @Test |
@@ -185,14 +187,14 @@ class MultiObjectTest { | |||
185 | .put(Tuple.of(1), CardinalityIntervals.SET)) | 187 | .put(Tuple.of(1), CardinalityIntervals.SET)) |
186 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) | 188 | .seed(person, builder -> builder.reducedValue(TruthValue.TRUE)) |
187 | .build()); | 189 | .build()); |
188 | assertThat(propagate(), is(RefinementResult.REFINED)); | 190 | assertThat(propagate(), is(PropagationResult.PROPAGATED)); |
189 | assertThat(countStorage.get(Tuple.of(0)), is(CardinalityIntervals.LONE)); | 191 | assertThat(countStorage.get(Tuple.of(0)), is(CardinalityIntervals.LONE)); |
190 | assertThat(countStorage.get(Tuple.of(1)), is(CardinalityIntervals.between(1, 12))); | 192 | assertThat(countStorage.get(Tuple.of(1)), is(CardinalityIntervals.between(1, 12))); |
191 | countStorage.put(Tuple.of(0), CardinalityIntervals.ONE); | 193 | countStorage.put(Tuple.of(0), CardinalityIntervals.ONE); |
192 | assertThat(propagate(), is(RefinementResult.REFINED)); | 194 | assertThat(propagate(), is(PropagationResult.PROPAGATED)); |
193 | assertThat(countStorage.get(Tuple.of(1)), is(CardinalityIntervals.between(1, 11))); | 195 | assertThat(countStorage.get(Tuple.of(1)), is(CardinalityIntervals.between(1, 11))); |
194 | countStorage.put(Tuple.of(1), CardinalityIntervals.ONE); | 196 | countStorage.put(Tuple.of(1), CardinalityIntervals.ONE); |
195 | assertThat(propagate(), is(RefinementResult.UNCHANGED)); | 197 | assertThat(propagate(), is(PropagationResult.UNCHANGED)); |
196 | } | 198 | } |
197 | 199 | ||
198 | private void createModel(ModelSeed modelSeed) { | 200 | private void createModel(ModelSeed modelSeed) { |
@@ -200,7 +202,7 @@ class MultiObjectTest { | |||
200 | countStorage = model.getInterpretation(MultiObjectTranslator.COUNT_STORAGE); | 202 | countStorage = model.getInterpretation(MultiObjectTranslator.COUNT_STORAGE); |
201 | } | 203 | } |
202 | 204 | ||
203 | private RefinementResult propagate() { | 205 | private PropagationResult propagate() { |
204 | return model.getAdapter(ScopePropagatorAdapter.class).propagate(); | 206 | return model.getAdapter(PropagationAdapter.class).propagate(); |
205 | } | 207 | } |
206 | } | 208 | } |
diff --git a/subprojects/store-reasoning-scope/src/test/java/tools/refinery/store/reasoning/scope/internal/RoundingUtilTest.java b/subprojects/store-reasoning-scope/src/test/java/tools/refinery/store/reasoning/scope/RoundingUtilTest.java index 9daed660..e697298e 100644 --- a/subprojects/store-reasoning-scope/src/test/java/tools/refinery/store/reasoning/scope/internal/RoundingUtilTest.java +++ b/subprojects/store-reasoning-scope/src/test/java/tools/refinery/store/reasoning/scope/RoundingUtilTest.java | |||
@@ -3,7 +3,7 @@ | |||
3 | * | 3 | * |
4 | * SPDX-License-Identifier: EPL-2.0 | 4 | * SPDX-License-Identifier: EPL-2.0 |
5 | */ | 5 | */ |
6 | package tools.refinery.store.reasoning.scope.internal; | 6 | package tools.refinery.store.reasoning.scope; |
7 | 7 | ||
8 | import org.junit.jupiter.params.ParameterizedTest; | 8 | import org.junit.jupiter.params.ParameterizedTest; |
9 | import org.junit.jupiter.params.provider.Arguments; | 9 | import org.junit.jupiter.params.provider.Arguments; |