aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store-dse
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <kristof@marussy.com>2024-05-20 17:29:07 +0200
committerLibravatar Kristóf Marussy <kristof@marussy.com>2024-05-26 17:22:33 +0200
commit42214746edac8bdc992a52ca8624f996871e2842 (patch)
tree2e8cf18ab0a9b12fcba96b2eb7511cd84131cb57 /subprojects/store-dse
parentfeat(dse): detect stuch propagation rules (diff)
downloadrefinery-42214746edac8bdc992a52ca8624f996871e2842.tar.gz
refinery-42214746edac8bdc992a52ca8624f996871e2842.tar.zst
refinery-42214746edac8bdc992a52ca8624f996871e2842.zip
feat(language): node constants in rule actions
Diffstat (limited to 'subprojects/store-dse')
-rw-r--r--subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/actions/Action.java4
-rw-r--r--subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/actions/ActionLiterals.java4
-rw-r--r--subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/actions/ConstantActionLiteral.java45
3 files changed, 51 insertions, 2 deletions
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/actions/Action.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/actions/Action.java
index 0ce0c3a4..edcf9526 100644
--- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/actions/Action.java
+++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/actions/Action.java
@@ -1,5 +1,5 @@
1/* 1/*
2 * SPDX-FileCopyrightText: 2023 The Refinery Authors <https://refinery.tools/> 2 * SPDX-FileCopyrightText: 2023-2024 The Refinery Authors <https://refinery.tools/>
3 * 3 *
4 * SPDX-License-Identifier: EPL-2.0 4 * SPDX-License-Identifier: EPL-2.0
5 */ 5 */
@@ -67,7 +67,7 @@ public class Action {
67 var outputVariables = actionLiteral.getOutputVariables(); 67 var outputVariables = actionLiteral.getOutputVariables();
68 int size = outputVariables.size(); 68 int size = outputVariables.size();
69 if (size == 0) { 69 if (size == 0) {
70 // Identity mappings use a {@code null} allocation to avoid iterating over the output tuple. 70 // Empty mappings use a {@code null} allocation to avoid iterating over the output tuple.
71 return; 71 return;
72 } 72 }
73 if (size >= 2 && new HashSet<>(outputVariables).size() != size) { 73 if (size >= 2 && new HashSet<>(outputVariables).size() != size) {
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/actions/ActionLiterals.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/actions/ActionLiterals.java
index d06e2479..6bd5075b 100644
--- a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/actions/ActionLiterals.java
+++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/actions/ActionLiterals.java
@@ -16,6 +16,10 @@ public final class ActionLiterals {
16 throw new IllegalArgumentException("This is a static utility class and should not be instantiated directly"); 16 throw new IllegalArgumentException("This is a static utility class and should not be instantiated directly");
17 } 17 }
18 18
19 public static ConstantActionLiteral constant(NodeVariable variable, int nodeId) {
20 return new ConstantActionLiteral(variable, nodeId);
21 }
22
19 public static <T> PutActionLiteral<T> put(Symbol<T> symbol, T value, NodeVariable... parameters) { 23 public static <T> PutActionLiteral<T> put(Symbol<T> symbol, T value, NodeVariable... parameters) {
20 return new PutActionLiteral<>(symbol, value, List.of(parameters)); 24 return new PutActionLiteral<>(symbol, value, List.of(parameters));
21 } 25 }
diff --git a/subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/actions/ConstantActionLiteral.java b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/actions/ConstantActionLiteral.java
new file mode 100644
index 00000000..fecb2960
--- /dev/null
+++ b/subprojects/store-dse/src/main/java/tools/refinery/store/dse/transition/actions/ConstantActionLiteral.java
@@ -0,0 +1,45 @@
1/*
2 * SPDX-FileCopyrightText: 2024 The Refinery Authors <https://refinery.tools/>
3 *
4 * SPDX-License-Identifier: EPL-2.0
5 */
6package tools.refinery.store.dse.transition.actions;
7
8import tools.refinery.logic.term.NodeVariable;
9import tools.refinery.store.model.Model;
10import tools.refinery.store.tuple.Tuple;
11
12import java.util.List;
13
14public class ConstantActionLiteral extends AbstractActionLiteral {
15 private final NodeVariable variable;
16 private final int nodeId;
17
18 public ConstantActionLiteral(NodeVariable variable, int nodeId) {
19 this.variable = variable;
20 this.nodeId = nodeId;
21 }
22
23 public NodeVariable getVariable() {
24 return variable;
25 }
26
27 public int getNodeId() {
28 return nodeId;
29 }
30
31 @Override
32 public List<NodeVariable> getInputVariables() {
33 return List.of();
34 }
35
36 @Override
37 public List<NodeVariable> getOutputVariables() {
38 return List.of(variable);
39 }
40
41 @Override
42 public BoundActionLiteral bindToModel(Model model) {
43 return ignoredTuple -> Tuple.of(nodeId);
44 }
45}