aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store-reasoning-scope/src/main/java/tools
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2023-11-07 02:20:54 +0100
committerLibravatar Kristóf Marussy <kristof@marussy.com>2023-11-17 12:41:35 +0100
commitcb3fa67e8ae934070f914300d2bbb0b604cb25bb (patch)
tree47176fb021cf1db37235825e55998001acf4cdc5 /subprojects/store-reasoning-scope/src/main/java/tools
parentrefactor(language): opposite content assist (diff)
downloadrefinery-cb3fa67e8ae934070f914300d2bbb0b604cb25bb.tar.gz
refinery-cb3fa67e8ae934070f914300d2bbb0b604cb25bb.tar.zst
refinery-cb3fa67e8ae934070f914300d2bbb0b604cb25bb.zip
fix: scope upper bounds
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/LowerTypeScopePropagator.java2
-rw-r--r--subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/TypeScopePropagator.java2
-rw-r--r--subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/UpperTypeScopePropagator.java26
3 files changed, 27 insertions, 3 deletions
diff --git a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/LowerTypeScopePropagator.java b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/LowerTypeScopePropagator.java
index 2be92464..86401b7e 100644
--- a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/LowerTypeScopePropagator.java
+++ b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/LowerTypeScopePropagator.java
@@ -39,7 +39,7 @@ class LowerTypeScopePropagator extends TypeScopePropagator {
39 constraint.setLb((lowerBound - getSingleCount())); 39 constraint.setLb((lowerBound - getSingleCount()));
40 } 40 }
41 41
42 public static class Factory extends TypeScopePropagator.Factory { 42 static class Factory extends TypeScopePropagator.Factory {
43 private final PartialRelation type; 43 private final PartialRelation type;
44 private final int lowerBound; 44 private final int lowerBound;
45 private final RelationalQuery allMay; 45 private final RelationalQuery allMay;
diff --git a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/TypeScopePropagator.java b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/TypeScopePropagator.java
index bb50656b..193c132c 100644
--- a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/TypeScopePropagator.java
+++ b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/TypeScopePropagator.java
@@ -59,7 +59,7 @@ abstract class TypeScopePropagator {
59 adapter.markAsChanged(); 59 adapter.markAsChanged();
60 } 60 }
61 61
62 public abstract static class Factory { 62 abstract static class Factory {
63 public abstract TypeScopePropagator createPropagator(BoundScopePropagator adapter); 63 public abstract TypeScopePropagator createPropagator(BoundScopePropagator adapter);
64 64
65 protected abstract Collection<AnyQuery> getQueries(); 65 protected abstract Collection<AnyQuery> getQueries();
diff --git a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/UpperTypeScopePropagator.java b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/UpperTypeScopePropagator.java
index 4aba5aac..634e93bc 100644
--- a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/UpperTypeScopePropagator.java
+++ b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/UpperTypeScopePropagator.java
@@ -5,14 +5,22 @@
5 */ 5 */
6package tools.refinery.store.reasoning.scope; 6package tools.refinery.store.reasoning.scope;
7 7
8import tools.refinery.store.dse.transition.DesignSpaceExplorationBuilder;
9import tools.refinery.store.dse.transition.objectives.Criteria;
10import tools.refinery.store.model.ModelStoreBuilder;
8import tools.refinery.store.query.dnf.AnyQuery; 11import tools.refinery.store.query.dnf.AnyQuery;
9import tools.refinery.store.query.dnf.Query; 12import tools.refinery.store.query.dnf.Query;
10import tools.refinery.store.query.dnf.RelationalQuery; 13import tools.refinery.store.query.dnf.RelationalQuery;
14import tools.refinery.store.query.term.Variable;
15import tools.refinery.store.reasoning.literal.CountCandidateUpperBoundLiteral;
11import tools.refinery.store.reasoning.representation.PartialRelation; 16import tools.refinery.store.reasoning.representation.PartialRelation;
12 17
13import java.util.Collection; 18import java.util.Collection;
14import java.util.List; 19import java.util.List;
15 20
21import static tools.refinery.store.query.literal.Literals.check;
22import static tools.refinery.store.query.term.int_.IntTerms.constant;
23import static tools.refinery.store.query.term.int_.IntTerms.greater;
16import static tools.refinery.store.reasoning.literal.PartialLiterals.must; 24import static tools.refinery.store.reasoning.literal.PartialLiterals.must;
17import static tools.refinery.store.reasoning.translator.multiobject.MultiObjectTranslator.MULTI_VIEW; 25import static tools.refinery.store.reasoning.translator.multiobject.MultiObjectTranslator.MULTI_VIEW;
18 26
@@ -30,12 +38,14 @@ class UpperTypeScopePropagator extends TypeScopePropagator {
30 constraint.setUb((upperBound - getSingleCount())); 38 constraint.setUb((upperBound - getSingleCount()));
31 } 39 }
32 40
33 public static class Factory extends TypeScopePropagator.Factory { 41 static class Factory extends TypeScopePropagator.Factory {
42 private final PartialRelation type;
34 private final int upperBound; 43 private final int upperBound;
35 private final RelationalQuery allMust; 44 private final RelationalQuery allMust;
36 private final RelationalQuery multiMust; 45 private final RelationalQuery multiMust;
37 46
38 public Factory(PartialRelation type, int upperBound) { 47 public Factory(PartialRelation type, int upperBound) {
48 this.type = type;
39 this.upperBound = upperBound; 49 this.upperBound = upperBound;
40 allMust = Query.of(type.name() + "#must", (builder, instance) -> builder.clause( 50 allMust = Query.of(type.name() + "#must", (builder, instance) -> builder.clause(
41 must(type.call(instance)) 51 must(type.call(instance))
@@ -55,5 +65,19 @@ class UpperTypeScopePropagator extends TypeScopePropagator {
55 protected Collection<AnyQuery> getQueries() { 65 protected Collection<AnyQuery> getQueries() {
56 return List.of(allMust, multiMust); 66 return List.of(allMust, multiMust);
57 } 67 }
68
69 @Override
70 public void configure(ModelStoreBuilder storeBuilder) {
71 super.configure(storeBuilder);
72
73 var tooManyObjects = Query.of(type.name() + "#tooMany", builder -> builder
74 .clause(Integer.class, candidateUpperBound -> List.of(
75 new CountCandidateUpperBoundLiteral(candidateUpperBound, type, List.of(Variable.of())),
76 check(greater(candidateUpperBound, constant(upperBound)))
77 )));
78
79 storeBuilder.tryGetAdapter(DesignSpaceExplorationBuilder.class).ifPresent(dseBuilder ->
80 dseBuilder.accept(Criteria.whenNoMatch(tooManyObjects)));
81 }
58 } 82 }
59} 83}