diff options
Diffstat (limited to 'subprojects/store-reasoning-scope/src/main/java/tools')
3 files changed, 51 insertions, 5 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..702e570f 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 | |||
@@ -13,9 +13,12 @@ import tools.refinery.store.query.dnf.AnyQuery; | |||
13 | import tools.refinery.store.query.dnf.Query; | 13 | import tools.refinery.store.query.dnf.Query; |
14 | import tools.refinery.store.query.dnf.RelationalQuery; | 14 | import tools.refinery.store.query.dnf.RelationalQuery; |
15 | import tools.refinery.store.query.term.Variable; | 15 | import tools.refinery.store.query.term.Variable; |
16 | import tools.refinery.store.query.term.uppercardinality.UpperCardinalityTerms; | ||
16 | import tools.refinery.store.reasoning.ReasoningBuilder; | 17 | import tools.refinery.store.reasoning.ReasoningBuilder; |
17 | import tools.refinery.store.reasoning.literal.CountCandidateLowerBoundLiteral; | 18 | import tools.refinery.store.reasoning.literal.CountCandidateLowerBoundLiteral; |
19 | import tools.refinery.store.reasoning.literal.CountUpperBoundLiteral; | ||
18 | import tools.refinery.store.reasoning.representation.PartialRelation; | 20 | import tools.refinery.store.reasoning.representation.PartialRelation; |
21 | import tools.refinery.store.representation.cardinality.UpperCardinality; | ||
19 | 22 | ||
20 | import java.util.Collection; | 23 | import java.util.Collection; |
21 | import java.util.List; | 24 | import java.util.List; |
@@ -39,7 +42,7 @@ class LowerTypeScopePropagator extends TypeScopePropagator { | |||
39 | constraint.setLb((lowerBound - getSingleCount())); | 42 | constraint.setLb((lowerBound - getSingleCount())); |
40 | } | 43 | } |
41 | 44 | ||
42 | public static class Factory extends TypeScopePropagator.Factory { | 45 | static class Factory extends TypeScopePropagator.Factory { |
43 | private final PartialRelation type; | 46 | private final PartialRelation type; |
44 | private final int lowerBound; | 47 | private final int lowerBound; |
45 | private final RelationalQuery allMay; | 48 | private final RelationalQuery allMay; |
@@ -77,10 +80,18 @@ class LowerTypeScopePropagator extends TypeScopePropagator { | |||
77 | output.assign(sub(constant(lowerBound), candidateLowerBound)), | 80 | output.assign(sub(constant(lowerBound), candidateLowerBound)), |
78 | check(greater(output, constant(0))) | 81 | check(greater(output, constant(0))) |
79 | ))); | 82 | ))); |
83 | var tooFewObjects = Query.of(type.name() + "#tooFew", builder -> builder | ||
84 | .clause(UpperCardinality.class, upperBound -> List.of( | ||
85 | new CountUpperBoundLiteral(upperBound, type, List.of(Variable.of())), | ||
86 | check(UpperCardinalityTerms.less(upperBound, | ||
87 | UpperCardinalityTerms.constant(UpperCardinality.of(lowerBound)))) | ||
88 | ))); | ||
80 | 89 | ||
81 | storeBuilder.getAdapter(ReasoningBuilder.class).objective(Objectives.value(requiredObjects)); | 90 | storeBuilder.getAdapter(ReasoningBuilder.class).objective(Objectives.value(requiredObjects)); |
82 | storeBuilder.tryGetAdapter(DesignSpaceExplorationBuilder.class).ifPresent(dseBuilder -> | 91 | storeBuilder.tryGetAdapter(DesignSpaceExplorationBuilder.class).ifPresent(dseBuilder -> { |
83 | dseBuilder.accept(Criteria.whenNoMatch(requiredObjects))); | 92 | dseBuilder.accept(Criteria.whenNoMatch(requiredObjects)); |
93 | dseBuilder.exclude(Criteria.whenHasMatch(tooFewObjects)); | ||
94 | }); | ||
84 | } | 95 | } |
85 | } | 96 | } |
86 | } | 97 | } |
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..b2f8d39b 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,24 @@ | |||
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.dse.transition.objectives.Objectives; | ||
11 | import tools.refinery.store.model.ModelStoreBuilder; | ||
8 | import tools.refinery.store.query.dnf.AnyQuery; | 12 | import tools.refinery.store.query.dnf.AnyQuery; |
9 | import tools.refinery.store.query.dnf.Query; | 13 | import tools.refinery.store.query.dnf.Query; |
10 | import tools.refinery.store.query.dnf.RelationalQuery; | 14 | import tools.refinery.store.query.dnf.RelationalQuery; |
15 | import tools.refinery.store.query.term.Variable; | ||
16 | import tools.refinery.store.reasoning.ReasoningBuilder; | ||
17 | import tools.refinery.store.reasoning.literal.CountCandidateUpperBoundLiteral; | ||
18 | import tools.refinery.store.reasoning.literal.CountLowerBoundLiteral; | ||
11 | import tools.refinery.store.reasoning.representation.PartialRelation; | 19 | import tools.refinery.store.reasoning.representation.PartialRelation; |
12 | 20 | ||
13 | import java.util.Collection; | 21 | import java.util.Collection; |
14 | import java.util.List; | 22 | import java.util.List; |
15 | 23 | ||
24 | import static tools.refinery.store.query.literal.Literals.check; | ||
25 | import static tools.refinery.store.query.term.int_.IntTerms.*; | ||
16 | import static tools.refinery.store.reasoning.literal.PartialLiterals.must; | 26 | import static tools.refinery.store.reasoning.literal.PartialLiterals.must; |
17 | import static tools.refinery.store.reasoning.translator.multiobject.MultiObjectTranslator.MULTI_VIEW; | 27 | import static tools.refinery.store.reasoning.translator.multiobject.MultiObjectTranslator.MULTI_VIEW; |
18 | 28 | ||
@@ -30,12 +40,14 @@ class UpperTypeScopePropagator extends TypeScopePropagator { | |||
30 | constraint.setUb((upperBound - getSingleCount())); | 40 | constraint.setUb((upperBound - getSingleCount())); |
31 | } | 41 | } |
32 | 42 | ||
33 | public static class Factory extends TypeScopePropagator.Factory { | 43 | static class Factory extends TypeScopePropagator.Factory { |
44 | private final PartialRelation type; | ||
34 | private final int upperBound; | 45 | private final int upperBound; |
35 | private final RelationalQuery allMust; | 46 | private final RelationalQuery allMust; |
36 | private final RelationalQuery multiMust; | 47 | private final RelationalQuery multiMust; |
37 | 48 | ||
38 | public Factory(PartialRelation type, int upperBound) { | 49 | public Factory(PartialRelation type, int upperBound) { |
50 | this.type = type; | ||
39 | this.upperBound = upperBound; | 51 | this.upperBound = upperBound; |
40 | allMust = Query.of(type.name() + "#must", (builder, instance) -> builder.clause( | 52 | allMust = Query.of(type.name() + "#must", (builder, instance) -> builder.clause( |
41 | must(type.call(instance)) | 53 | must(type.call(instance)) |
@@ -55,5 +67,28 @@ class UpperTypeScopePropagator extends TypeScopePropagator { | |||
55 | protected Collection<AnyQuery> getQueries() { | 67 | protected Collection<AnyQuery> getQueries() { |
56 | return List.of(allMust, multiMust); | 68 | return List.of(allMust, multiMust); |
57 | } | 69 | } |
70 | |||
71 | @Override | ||
72 | public void configure(ModelStoreBuilder storeBuilder) { | ||
73 | super.configure(storeBuilder); | ||
74 | |||
75 | var excessObjects = Query.of(type.name() + "#excess", Integer.class, (builder, output) -> builder | ||
76 | .clause(Integer.class, candidateUpperBound -> List.of( | ||
77 | new CountCandidateUpperBoundLiteral(candidateUpperBound, type, List.of(Variable.of())), | ||
78 | output.assign(sub(candidateUpperBound, constant(upperBound))), | ||
79 | check(greater(output, constant(0))) | ||
80 | ))); | ||
81 | var tooManyObjects = Query.of(type.name() + "#tooMany", builder -> builder | ||
82 | .clause(Integer.class, lowerBound -> List.of( | ||
83 | new CountLowerBoundLiteral(lowerBound, type, List.of(Variable.of())), | ||
84 | check(greater(lowerBound, constant(upperBound))) | ||
85 | ))); | ||
86 | |||
87 | storeBuilder.getAdapter(ReasoningBuilder.class).objective(Objectives.value(excessObjects)); | ||
88 | storeBuilder.tryGetAdapter(DesignSpaceExplorationBuilder.class).ifPresent(dseBuilder -> { | ||
89 | dseBuilder.accept(Criteria.whenNoMatch(excessObjects)); | ||
90 | dseBuilder.exclude(Criteria.whenHasMatch(tooManyObjects)); | ||
91 | }); | ||
92 | } | ||
58 | } | 93 | } |
59 | } | 94 | } |