diff options
Diffstat (limited to 'subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/objectives/OrCriterion.java')
-rw-r--r-- | subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/objectives/OrCriterion.java | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/objectives/OrCriterion.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/objectives/OrCriterion.java new file mode 100644 index 00000000..7a8d7778 --- /dev/null +++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/objectives/OrCriterion.java | |||
@@ -0,0 +1,53 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.dse.transition.objectives; | ||
7 | |||
8 | import tools.refinery.store.model.Model; | ||
9 | import tools.refinery.store.model.ModelStore; | ||
10 | import tools.refinery.store.query.literal.Reduction; | ||
11 | |||
12 | import java.util.ArrayList; | ||
13 | import java.util.Collection; | ||
14 | |||
15 | public final class OrCriterion extends CompositeCriterion { | ||
16 | OrCriterion(Collection<? extends Criterion> criteria) { | ||
17 | super(criteria); | ||
18 | } | ||
19 | |||
20 | @Override | ||
21 | public Reduction getReduction(ModelStore store) { | ||
22 | for (var criterion : getCriteria()) { | ||
23 | var reduction = criterion.getReduction(store); | ||
24 | if (reduction == Reduction.ALWAYS_TRUE) { | ||
25 | return Reduction.ALWAYS_TRUE; | ||
26 | } else if (reduction == Reduction.NOT_REDUCIBLE) { | ||
27 | return Reduction.NOT_REDUCIBLE; | ||
28 | } | ||
29 | } | ||
30 | return Reduction.ALWAYS_FALSE; | ||
31 | } | ||
32 | |||
33 | @Override | ||
34 | public CriterionCalculator createCalculator(Model model) { | ||
35 | var calculators = new ArrayList<CriterionCalculator>(); | ||
36 | for (var criterion : getCriteria()) { | ||
37 | var reduction = criterion.getReduction(model.getStore()); | ||
38 | if (reduction == Reduction.ALWAYS_TRUE) { | ||
39 | return () -> true; | ||
40 | } else if (reduction == Reduction.NOT_REDUCIBLE) { | ||
41 | calculators.add(criterion.createCalculator(model)); | ||
42 | } | ||
43 | } | ||
44 | return () -> { | ||
45 | for (var calculator : calculators) { | ||
46 | if (calculator.isSatisfied()) { | ||
47 | return true; | ||
48 | } | ||
49 | } | ||
50 | return false; | ||
51 | }; | ||
52 | } | ||
53 | } | ||