diff options
author | 2023-11-07 02:20:54 +0100 | |
---|---|---|
committer | 2023-11-17 12:41:35 +0100 | |
commit | cb3fa67e8ae934070f914300d2bbb0b604cb25bb (patch) | |
tree | 47176fb021cf1db37235825e55998001acf4cdc5 /subprojects/store-reasoning-scope/src/main/java/tools | |
parent | refactor(language): opposite content assist (diff) | |
download | refinery-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')
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 | */ |
6 | package tools.refinery.store.reasoning.scope; | 6 | package tools.refinery.store.reasoning.scope; |
7 | 7 | ||
8 | import tools.refinery.store.dse.transition.DesignSpaceExplorationBuilder; | ||
9 | import tools.refinery.store.dse.transition.objectives.Criteria; | ||
10 | import tools.refinery.store.model.ModelStoreBuilder; | ||
8 | import tools.refinery.store.query.dnf.AnyQuery; | 11 | import tools.refinery.store.query.dnf.AnyQuery; |
9 | import tools.refinery.store.query.dnf.Query; | 12 | import tools.refinery.store.query.dnf.Query; |
10 | import tools.refinery.store.query.dnf.RelationalQuery; | 13 | import tools.refinery.store.query.dnf.RelationalQuery; |
14 | import tools.refinery.store.query.term.Variable; | ||
15 | import tools.refinery.store.reasoning.literal.CountCandidateUpperBoundLiteral; | ||
11 | import tools.refinery.store.reasoning.representation.PartialRelation; | 16 | import tools.refinery.store.reasoning.representation.PartialRelation; |
12 | 17 | ||
13 | import java.util.Collection; | 18 | import java.util.Collection; |
14 | import java.util.List; | 19 | import java.util.List; |
15 | 20 | ||
21 | import static tools.refinery.store.query.literal.Literals.check; | ||
22 | import static tools.refinery.store.query.term.int_.IntTerms.constant; | ||
23 | import static tools.refinery.store.query.term.int_.IntTerms.greater; | ||
16 | import static tools.refinery.store.reasoning.literal.PartialLiterals.must; | 24 | import static tools.refinery.store.reasoning.literal.PartialLiterals.must; |
17 | import static tools.refinery.store.reasoning.translator.multiobject.MultiObjectTranslator.MULTI_VIEW; | 25 | import 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 | } |