aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store-reasoning/src/main
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2024-05-31 19:22:46 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2024-06-01 20:17:47 +0200
commit8a62e425b77c43a541d58d4615a13cd182d12a81 (patch)
tree2f84b7d5e3f3dbc4dbda7da06ee93732418024ce /subprojects/store-reasoning/src/main
parentfix(reasoning): candidate rounding mode (diff)
downloadrefinery-8a62e425b77c43a541d58d4615a13cd182d12a81.tar.gz
refinery-8a62e425b77c43a541d58d4615a13cd182d12a81.tar.zst
refinery-8a62e425b77c43a541d58d4615a13cd182d12a81.zip
feat: generate multiple solutions
Switch to partial interpretation based neighborhood calculation when multiple models are request to avoid returning isomorphic models.
Diffstat (limited to 'subprojects/store-reasoning/src/main')
-rw-r--r--subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/interpretation/PartialNeighbourhoodCalculator.java63
1 files changed, 63 insertions, 0 deletions
diff --git a/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/interpretation/PartialNeighbourhoodCalculator.java b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/interpretation/PartialNeighbourhoodCalculator.java
new file mode 100644
index 00000000..859cf7c1
--- /dev/null
+++ b/subprojects/store-reasoning/src/main/java/tools/refinery/store/reasoning/interpretation/PartialNeighbourhoodCalculator.java
@@ -0,0 +1,63 @@
1/*
2 * SPDX-FileCopyrightText: 2024 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package tools.refinery.store.reasoning.interpretation;
7
8import org.eclipse.collections.api.set.primitive.IntSet;
9import tools.refinery.store.map.Cursor;
10import tools.refinery.store.model.Model;
11import tools.refinery.store.query.ModelQueryAdapter;
12import tools.refinery.store.reasoning.ReasoningAdapter;
13import tools.refinery.store.reasoning.literal.Concreteness;
14import tools.refinery.store.reasoning.representation.PartialSymbol;
15import tools.refinery.store.statecoding.StateCodeCalculatorFactory;
16import tools.refinery.store.statecoding.StateCoderResult;
17import tools.refinery.store.statecoding.neighbourhood.AbstractNeighbourhoodCalculator;
18import tools.refinery.store.tuple.Tuple;
19
20import java.util.List;
21
22public class PartialNeighbourhoodCalculator extends AbstractNeighbourhoodCalculator<PartialInterpretation<?, ?>> {
23 private final ModelQueryAdapter queryAdapter;
24
25 public static final StateCodeCalculatorFactory FACTORY =
26 (model, ignoredInterpretations, individuals) -> new PartialNeighbourhoodCalculator(model, individuals);
27
28 protected PartialNeighbourhoodCalculator(Model model, IntSet individuals) {
29 super(model, individuals);
30 queryAdapter = model.getAdapter(ModelQueryAdapter.class);
31 }
32
33 @Override
34 public StateCoderResult calculateCodes() {
35 queryAdapter.flushChanges();
36 return super.calculateCodes();
37 }
38
39 @Override
40 protected List<PartialInterpretation<?, ?>> getInterpretations() {
41 var adapter = getModel().getAdapter(ReasoningAdapter.class);
42 var partialSymbols = adapter.getStoreAdapter().getPartialSymbols();
43 return partialSymbols.stream()
44 .<PartialInterpretation<?, ?>>map(partialSymbol ->
45 adapter.getPartialInterpretation(Concreteness.PARTIAL, (PartialSymbol<?, ?>) partialSymbol))
46 .toList();
47 }
48
49 @Override
50 protected int getArity(PartialInterpretation<?, ?> interpretation) {
51 return interpretation.getPartialSymbol().arity();
52 }
53
54 @Override
55 protected Object getNullValue(PartialInterpretation<?, ?> interpretation) {
56 return interpretation.get(Tuple.of());
57 }
58
59 @Override
60 protected Cursor<Tuple, ?> getCursor(PartialInterpretation<?, ?> interpretation) {
61 return interpretation.getAll();
62 }
63}