aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/LowerTypeScopePropagator.java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/LowerTypeScopePropagator.java')
-rw-r--r--subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/LowerTypeScopePropagator.java40
1 files changed, 34 insertions, 6 deletions
diff --git a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/LowerTypeScopePropagator.java b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/LowerTypeScopePropagator.java
index b1c421b7..393c4b72 100644
--- a/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/LowerTypeScopePropagator.java
+++ b/subprojects/store-reasoning-scope/src/main/java/tools/refinery/store/reasoning/scope/internal/LowerTypeScopePropagator.java
@@ -5,43 +5,55 @@
5 */ 5 */
6package tools.refinery.store.reasoning.scope.internal; 6package tools.refinery.store.reasoning.scope.internal;
7 7
8import tools.refinery.store.dse.transition.DesignSpaceExplorationBuilder;
9import tools.refinery.store.dse.transition.objectives.Criteria;
10import tools.refinery.store.dse.transition.objectives.Objectives;
11import tools.refinery.store.model.ModelStoreBuilder;
8import tools.refinery.store.query.dnf.AnyQuery; 12import tools.refinery.store.query.dnf.AnyQuery;
9import tools.refinery.store.query.dnf.Query; 13import tools.refinery.store.query.dnf.Query;
10import tools.refinery.store.query.dnf.RelationalQuery; 14import tools.refinery.store.query.dnf.RelationalQuery;
15import tools.refinery.store.query.term.Variable;
16import tools.refinery.store.reasoning.ReasoningBuilder;
17import tools.refinery.store.reasoning.literal.CountCandidateLowerBoundLiteral;
11import tools.refinery.store.reasoning.representation.PartialRelation; 18import tools.refinery.store.reasoning.representation.PartialRelation;
12 19
13import java.util.Collection; 20import java.util.Collection;
14import java.util.List; 21import java.util.List;
15 22
23import static tools.refinery.store.query.literal.Literals.check;
24import static tools.refinery.store.query.term.int_.IntTerms.*;
16import static tools.refinery.store.reasoning.literal.PartialLiterals.may; 25import static tools.refinery.store.reasoning.literal.PartialLiterals.may;
26import static tools.refinery.store.reasoning.translator.multiobject.MultiObjectTranslator.MULTI_VIEW;
17 27
18class LowerTypeScopePropagator extends TypeScopePropagator { 28class LowerTypeScopePropagator extends TypeScopePropagator {
19 private final int lowerBound; 29 private final int lowerBound;
20 30
21 private LowerTypeScopePropagator(ScopePropagatorAdapterImpl adapter, int lowerBound, RelationalQuery allQuery, 31 private LowerTypeScopePropagator(ScopePropagatorAdapterImpl adapter, int lowerBound, RelationalQuery allQuery,
22 RelationalQuery multiQuery) { 32 RelationalQuery multiQuery) {
23 super(adapter, allQuery, multiQuery); 33 super(adapter, allQuery, multiQuery);
24 this.lowerBound = lowerBound; 34 this.lowerBound = lowerBound;
25 } 35 }
26 36
27 @Override 37 @Override
28 public void updateBounds() { 38 public void updateBounds() {
29 constraint.setLb(lowerBound - getSingleCount()); 39 constraint.setLb((lowerBound - getSingleCount()));
30 } 40 }
31 41
32 public static class Factory implements TypeScopePropagator.Factory { 42 public static class Factory extends TypeScopePropagator.Factory {
43 private final PartialRelation type;
33 private final int lowerBound; 44 private final int lowerBound;
34 private final RelationalQuery allMay; 45 private final RelationalQuery allMay;
35 private final RelationalQuery multiMay; 46 private final RelationalQuery multiMay;
36 47
37 public Factory(RelationalQuery multi, PartialRelation type, int lowerBound) { 48 public Factory(PartialRelation type, int lowerBound) {
49 this.type = type;
38 this.lowerBound = lowerBound; 50 this.lowerBound = lowerBound;
39 allMay = Query.of(type.name() + "#may", (builder, instance) -> builder.clause( 51 allMay = Query.of(type.name() + "#may", (builder, instance) -> builder.clause(
40 may(type.call(instance)) 52 may(type.call(instance))
41 )); 53 ));
42 multiMay = Query.of(type.name() + "#multiMay", (builder, instance) -> builder.clause( 54 multiMay = Query.of(type.name() + "#multiMay", (builder, instance) -> builder.clause(
43 may(type.call(instance)), 55 may(type.call(instance)),
44 multi.call(instance) 56 MULTI_VIEW.call(instance)
45 )); 57 ));
46 } 58 }
47 59
@@ -51,8 +63,24 @@ class LowerTypeScopePropagator extends TypeScopePropagator {
51 } 63 }
52 64
53 @Override 65 @Override
54 public Collection<AnyQuery> getQueries() { 66 protected Collection<AnyQuery> getQueries() {
55 return List.of(allMay, multiMay); 67 return List.of(allMay, multiMay);
56 } 68 }
69
70 @Override
71 public void configure(ModelStoreBuilder storeBuilder) {
72 super.configure(storeBuilder);
73
74 var requiredObjects = Query.of(type.name() + "#required", Integer.class, (builder, output) -> builder
75 .clause(Integer.class, currentCount -> List.of(
76 new CountCandidateLowerBoundLiteral(currentCount, type, List.of(Variable.of())),
77 output.assign(sub(currentCount, constant(lowerBound))),
78 check(greater(currentCount, constant(0)))
79 )));
80
81 storeBuilder.getAdapter(ReasoningBuilder.class).objective(Objectives.value(requiredObjects));
82 storeBuilder.tryGetAdapter(DesignSpaceExplorationBuilder.class).ifPresent(dseBuilder ->
83 dseBuilder.accept(Criteria.whenNoMatch(requiredObjects)));
84 }
57 } 85 }
58} 86}