diff options
author | 2023-09-11 19:22:26 +0200 | |
---|---|---|
committer | 2023-09-11 19:22:26 +0200 | |
commit | 4d365b54dad8d066bba2a2b1a05092b4802b9970 (patch) | |
tree | 12e5ae36b0041463ded54e7a69dcdc9f3662794f /subprojects/store-reasoning-scope/src | |
parent | fix: build failures after integrating generation (diff) | |
download | refinery-4d365b54dad8d066bba2a2b1a05092b4802b9970.tar.gz refinery-4d365b54dad8d066bba2a2b1a05092b4802b9970.tar.zst refinery-4d365b54dad8d066bba2a2b1a05092b4802b9970.zip |
feat: cancellation token for ModelStore
Diffstat (limited to 'subprojects/store-reasoning-scope/src')
-rw-r--r-- | subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/BoundScopePropagator.java | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/BoundScopePropagator.java b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/BoundScopePropagator.java index 62aadb4a..3ae4d84b 100644 --- a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/BoundScopePropagator.java +++ b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/BoundScopePropagator.java | |||
@@ -22,6 +22,7 @@ import tools.refinery.store.representation.cardinality.*; | |||
22 | import tools.refinery.store.tuple.Tuple; | 22 | import tools.refinery.store.tuple.Tuple; |
23 | 23 | ||
24 | class BoundScopePropagator implements BoundPropagator { | 24 | class BoundScopePropagator implements BoundPropagator { |
25 | private final Model model; | ||
25 | private final ModelQueryAdapter queryEngine; | 26 | private final ModelQueryAdapter queryEngine; |
26 | private final Interpretation<CardinalityInterval> countInterpretation; | 27 | private final Interpretation<CardinalityInterval> countInterpretation; |
27 | private final MPSolver solver; | 28 | private final MPSolver solver; |
@@ -32,6 +33,7 @@ class BoundScopePropagator implements BoundPropagator { | |||
32 | private boolean changed = true; | 33 | private boolean changed = true; |
33 | 34 | ||
34 | public BoundScopePropagator(Model model, ScopePropagator storeAdapter) { | 35 | public BoundScopePropagator(Model model, ScopePropagator storeAdapter) { |
36 | this.model = model; | ||
35 | queryEngine = model.getAdapter(ModelQueryAdapter.class); | 37 | queryEngine = model.getAdapter(ModelQueryAdapter.class); |
36 | countInterpretation = model.getInterpretation(storeAdapter.getCountSymbol()); | 38 | countInterpretation = model.getInterpretation(storeAdapter.getCountSymbol()); |
37 | solver = MPSolver.createSolver("GLOP"); | 39 | solver = MPSolver.createSolver("GLOP"); |
@@ -41,6 +43,7 @@ class BoundScopePropagator implements BoundPropagator { | |||
41 | var propagatorFactories = storeAdapter.getTypeScopePropagatorFactories(); | 43 | var propagatorFactories = storeAdapter.getTypeScopePropagatorFactories(); |
42 | propagators = new TypeScopePropagator[propagatorFactories.size()]; | 44 | propagators = new TypeScopePropagator[propagatorFactories.size()]; |
43 | for (int i = 0; i < propagators.length; i++) { | 45 | for (int i = 0; i < propagators.length; i++) { |
46 | model.checkCancelled(); | ||
44 | propagators[i] = propagatorFactories.get(i).createPropagator(this); | 47 | propagators[i] = propagatorFactories.get(i).createPropagator(this); |
45 | } | 48 | } |
46 | } | 49 | } |
@@ -145,6 +148,7 @@ class BoundScopePropagator implements BoundPropagator { | |||
145 | } | 148 | } |
146 | changed = false; | 149 | changed = false; |
147 | for (var propagator : propagators) { | 150 | for (var propagator : propagators) { |
151 | model.checkCancelled(); | ||
148 | propagator.updateBounds(); | 152 | propagator.updateBounds(); |
149 | } | 153 | } |
150 | var result = PropagationResult.UNCHANGED; | 154 | var result = PropagationResult.UNCHANGED; |
@@ -167,6 +171,7 @@ class BoundScopePropagator implements BoundPropagator { | |||
167 | } | 171 | } |
168 | 172 | ||
169 | private PropagationResult checkEmptiness() { | 173 | private PropagationResult checkEmptiness() { |
174 | model.checkCancelled(); | ||
170 | var emptinessCheckingResult = solver.solve(); | 175 | var emptinessCheckingResult = solver.solve(); |
171 | return switch (emptinessCheckingResult) { | 176 | return switch (emptinessCheckingResult) { |
172 | case OPTIMAL, UNBOUNDED -> PropagationResult.UNCHANGED; | 177 | case OPTIMAL, UNBOUNDED -> PropagationResult.UNCHANGED; |
@@ -178,6 +183,7 @@ class BoundScopePropagator implements BoundPropagator { | |||
178 | private PropagationResult propagateNode(int nodeId, MPVariable variable) { | 183 | private PropagationResult propagateNode(int nodeId, MPVariable variable) { |
179 | objective.setCoefficient(variable, 1); | 184 | objective.setCoefficient(variable, 1); |
180 | try { | 185 | try { |
186 | model.checkCancelled(); | ||
181 | objective.setMinimization(); | 187 | objective.setMinimization(); |
182 | var minimizationResult = solver.solve(); | 188 | var minimizationResult = solver.solve(); |
183 | int lowerBound; | 189 | int lowerBound; |
@@ -191,6 +197,7 @@ class BoundScopePropagator implements BoundPropagator { | |||
191 | .formatted(variable, minimizationResult)); | 197 | .formatted(variable, minimizationResult)); |
192 | } | 198 | } |
193 | 199 | ||
200 | model.checkCancelled(); | ||
194 | objective.setMaximization(); | 201 | objective.setMaximization(); |
195 | var maximizationResult = solver.solve(); | 202 | var maximizationResult = solver.solve(); |
196 | UpperCardinality upperBound; | 203 | UpperCardinality upperBound; |