diff options
Diffstat (limited to 'subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/TransformationRule.java')
-rw-r--r-- | subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/TransformationRule.java | 99 |
1 files changed, 0 insertions, 99 deletions
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/TransformationRule.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/TransformationRule.java deleted file mode 100644 index 37117164..00000000 --- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/internal/TransformationRule.java +++ /dev/null | |||
@@ -1,99 +0,0 @@ | |||
1 | /* | ||
2 | * SPDX-FileCopyrightText: 2021-2023 The Refinery Authors <https://refinery.tools/> | ||
3 | * | ||
4 | * SPDX-License-Identifier: EPL-2.0 | ||
5 | */ | ||
6 | package tools.refinery.store.dse.internal; | ||
7 | |||
8 | import org.eclipse.collections.api.block.procedure.Procedure; | ||
9 | import tools.refinery.store.model.Model; | ||
10 | import tools.refinery.store.query.ModelQueryAdapter; | ||
11 | import tools.refinery.store.query.dnf.RelationalQuery; | ||
12 | import tools.refinery.store.dse.ActionFactory; | ||
13 | import tools.refinery.store.query.resultset.OrderedResultSet; | ||
14 | import tools.refinery.store.query.resultset.ResultSet; | ||
15 | import tools.refinery.store.tuple.Tuple; | ||
16 | |||
17 | import java.util.*; | ||
18 | |||
19 | public class TransformationRule { | ||
20 | |||
21 | private final String name; | ||
22 | private final RelationalQuery precondition; | ||
23 | private final ActionFactory actionFactory; | ||
24 | private Procedure<Tuple> action; | ||
25 | private OrderedResultSet<Boolean> activations; | ||
26 | private Random random; | ||
27 | private ModelQueryAdapter queryEngine; | ||
28 | |||
29 | @SuppressWarnings("squid:S2245") | ||
30 | public TransformationRule(String name, RelationalQuery precondition, ActionFactory actionFactory) { | ||
31 | this(name, precondition, actionFactory, new Random()); | ||
32 | } | ||
33 | |||
34 | @SuppressWarnings("squid:S2245") | ||
35 | public TransformationRule(String name, RelationalQuery precondition, ActionFactory actionFactory, long seed) { | ||
36 | this(name, precondition, actionFactory, new Random(seed)); | ||
37 | } | ||
38 | |||
39 | public TransformationRule(String name, RelationalQuery precondition, ActionFactory actionFactory, Random random) { | ||
40 | this.name = name; | ||
41 | this.precondition = precondition; | ||
42 | this.actionFactory = actionFactory; | ||
43 | this.random = random; | ||
44 | } | ||
45 | public boolean prepare(Model model, ModelQueryAdapter queryEngine) { | ||
46 | action = actionFactory.prepare(model); | ||
47 | this.queryEngine = queryEngine; | ||
48 | activations = new OrderedResultSet<>(queryEngine.getResultSet(precondition)); | ||
49 | return true; | ||
50 | } | ||
51 | |||
52 | public boolean fireActivation(Tuple activation) { | ||
53 | action.accept(activation); | ||
54 | queryEngine.flushChanges(); | ||
55 | return true; | ||
56 | } | ||
57 | |||
58 | public boolean fireRandomActivation() { | ||
59 | return getRandomActivation().fire(); | ||
60 | } | ||
61 | |||
62 | public String getName() { | ||
63 | return name; | ||
64 | } | ||
65 | |||
66 | public RelationalQuery getPrecondition() { | ||
67 | return precondition; | ||
68 | } | ||
69 | |||
70 | public ResultSet<Boolean> getAllActivationsAsResultSet() { | ||
71 | return activations; | ||
72 | } | ||
73 | |||
74 | public Set<Activation> getAllActivations() { | ||
75 | var result = new LinkedHashSet<Activation>(); | ||
76 | var cursor = activations.getAll(); | ||
77 | while (cursor.move()) { | ||
78 | result.add(new Activation(this, cursor.getKey())); | ||
79 | } | ||
80 | return result; | ||
81 | } | ||
82 | |||
83 | public List<Activation> getAllActivationsAsList() { | ||
84 | var result = new ArrayList<Activation>(); | ||
85 | var cursor = activations.getAll(); | ||
86 | while (cursor.move()) { | ||
87 | result.add(new Activation(this, cursor.getKey())); | ||
88 | } | ||
89 | return result; | ||
90 | } | ||
91 | |||
92 | public Activation getRandomActivation() { | ||
93 | return new Activation(this, activations.getKey(random.nextInt(activations.size()))); | ||
94 | } | ||
95 | |||
96 | public Activation getActivation(int index) { | ||
97 | return new Activation(this, activations.getKey(index)); | ||
98 | } | ||
99 | } | ||