diff options
author | 2023-09-14 19:29:36 +0200 | |
---|---|---|
committer | 2023-09-14 19:29:36 +0200 | |
commit | 98ed3b6db5f4e51961a161050cc31c66015116e8 (patch) | |
tree | 8bfd6d9bc8d6ed23b9eb0f889dd40b6c24fe8f92 /subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/FilterNode.java | |
parent | Merge pull request #38 from nagilooh/design-space-exploration (diff) | |
parent | Merge remote-tracking branch 'upstream/main' into partial-interpretation (diff) | |
download | refinery-98ed3b6db5f4e51961a161050cc31c66015116e8.tar.gz refinery-98ed3b6db5f4e51961a161050cc31c66015116e8.tar.zst refinery-98ed3b6db5f4e51961a161050cc31c66015116e8.zip |
Merge pull request #39 from kris7t/partial-interpretation
Implement partial interpretation based model generation
Diffstat (limited to 'subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/FilterNode.java')
-rw-r--r-- | subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/FilterNode.java | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/FilterNode.java b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/FilterNode.java new file mode 100644 index 00000000..f66f1715 --- /dev/null +++ b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/single/FilterNode.java | |||
@@ -0,0 +1,69 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2004-2008 Gabor Bergmann and Daniel Varro | ||
3 | * This program and the accompanying materials are made available under the | ||
4 | * terms of the Eclipse Public License v. 2.0 which is available at | ||
5 | * http://www.eclipse.org/legal/epl-v20.html. | ||
6 | * | ||
7 | * SPDX-License-Identifier: EPL-2.0 | ||
8 | *******************************************************************************/ | ||
9 | |||
10 | package tools.refinery.viatra.runtime.rete.single; | ||
11 | |||
12 | import java.util.Collection; | ||
13 | import java.util.Map; | ||
14 | import java.util.Map.Entry; | ||
15 | |||
16 | import tools.refinery.viatra.runtime.matchers.tuple.Tuple; | ||
17 | import tools.refinery.viatra.runtime.matchers.util.Direction; | ||
18 | import tools.refinery.viatra.runtime.matchers.util.timeline.Timeline; | ||
19 | import tools.refinery.viatra.runtime.rete.network.ReteContainer; | ||
20 | import tools.refinery.viatra.runtime.rete.network.communication.Timestamp; | ||
21 | |||
22 | /** | ||
23 | * This node implements a simple filter. A stateless abstract check() predicate determines whether a matching is allowed | ||
24 | * to pass. | ||
25 | * | ||
26 | * @author Gabor Bergmann | ||
27 | * | ||
28 | */ | ||
29 | public abstract class FilterNode extends SingleInputNode { | ||
30 | |||
31 | public FilterNode(final ReteContainer reteContainer) { | ||
32 | super(reteContainer); | ||
33 | } | ||
34 | |||
35 | /** | ||
36 | * Abstract filtering predicate. Expected to be stateless. | ||
37 | * | ||
38 | * @param ps | ||
39 | * the matching to be checked. | ||
40 | * @return true if and only if the parameter matching is allowed to pass through this node. | ||
41 | */ | ||
42 | public abstract boolean check(final Tuple ps); | ||
43 | |||
44 | @Override | ||
45 | public void pullInto(final Collection<Tuple> collector, final boolean flush) { | ||
46 | for (final Tuple ps : this.reteContainer.pullPropagatedContents(this, flush)) { | ||
47 | if (check(ps)) { | ||
48 | collector.add(ps); | ||
49 | } | ||
50 | } | ||
51 | } | ||
52 | |||
53 | @Override | ||
54 | public void pullIntoWithTimeline(Map<Tuple, Timeline<Timestamp>> collector, boolean flush) { | ||
55 | for (final Entry<Tuple, Timeline<Timestamp>> entry : this.reteContainer.pullPropagatedContentsWithTimestamp(this, flush).entrySet()) { | ||
56 | if (check(entry.getKey())) { | ||
57 | collector.put(entry.getKey(), entry.getValue()); | ||
58 | } | ||
59 | } | ||
60 | } | ||
61 | |||
62 | @Override | ||
63 | public void update(final Direction direction, final Tuple updateElement, final Timestamp timestamp) { | ||
64 | if (check(updateElement)) { | ||
65 | propagateUpdate(direction, updateElement, timestamp); | ||
66 | } | ||
67 | } | ||
68 | |||
69 | } | ||