blob: 2a02ff140107d94dc027791cc75291127f22f756 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
|
/*
* SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/>
*
* SPDX-License-Identifier: EPL-2.0
*/
package tools.refinery.store.dse.transition.objectives;
import tools.refinery.logic.literal.Reduction;
import tools.refinery.store.model.Model;
import tools.refinery.store.model.ModelStore;
import java.util.ArrayList;
import java.util.Collection;
public final class AndCriterion extends CompositeCriterion {
AndCriterion(Collection<? extends Criterion> criteria) {
super(criteria);
}
@Override
public Reduction getReduction(ModelStore store) {
for (var criterion : getCriteria()) {
var reduction = criterion.getReduction(store);
if (reduction == Reduction.ALWAYS_FALSE) {
return Reduction.ALWAYS_FALSE;
} else if (reduction == Reduction.NOT_REDUCIBLE) {
return Reduction.NOT_REDUCIBLE;
}
}
return Reduction.ALWAYS_TRUE;
}
@Override
public CriterionCalculator createCalculator(Model model) {
var calculators = new ArrayList<CriterionCalculator>();
for (var criterion : getCriteria()) {
var reduction = criterion.getReduction(model.getStore());
if (reduction == Reduction.ALWAYS_FALSE) {
return () -> false;
} else if (reduction == Reduction.NOT_REDUCIBLE) {
calculators.add(criterion.createCalculator(model));
}
}
return () -> {
for (var calculator : calculators) {
if (!calculator.isSatisfied()) {
return false;
}
}
return true;
};
}
}
|