aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/traceability/PlanningTrace.java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/traceability/PlanningTrace.java')
-rw-r--r--subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/traceability/PlanningTrace.java80
1 files changed, 80 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/traceability/PlanningTrace.java b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/traceability/PlanningTrace.java
new file mode 100644
index 00000000..c1cc3a69
--- /dev/null
+++ b/subprojects/viatra-runtime-rete/src/main/java/tools/refinery/viatra/runtime/rete/traceability/PlanningTrace.java
@@ -0,0 +1,80 @@
1/*******************************************************************************
2 * Copyright (c) 2010-2014, Bergmann Gabor, Istvan Rath 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 *******************************************************************************/
9package tools.refinery.viatra.runtime.rete.traceability;
10
11import java.util.Arrays;
12import java.util.Collection;
13import java.util.HashMap;
14import java.util.List;
15import java.util.Map;
16
17import tools.refinery.viatra.runtime.matchers.planning.SubPlan;
18import tools.refinery.viatra.runtime.matchers.psystem.PVariable;
19import tools.refinery.viatra.runtime.rete.recipes.ReteNodeRecipe;
20
21/**
22 * A trace marker associating a Rete recipe with a query SubPlan.
23 *
24 * <p> The recipe may be an auxiliary node;
25 * see {@link CompiledSubPlan} if it represents the entire SubPlan instead.
26 */
27public class PlanningTrace extends RecipeTraceInfo implements PatternTraceInfo {
28
29 protected SubPlan subPlan;
30 protected List<PVariable> variablesTuple;
31 protected Map<PVariable, Integer> posMapping;
32
33 public PlanningTrace(SubPlan subPlan, List<PVariable> variablesTuple,
34 ReteNodeRecipe recipe,
35 Collection<? extends RecipeTraceInfo> parentRecipeTraces) {
36 super(recipe, parentRecipeTraces);
37 this.subPlan = subPlan;
38 this.variablesTuple = variablesTuple;
39
40 this.posMapping = new HashMap<PVariable, Integer>();
41 for (int i = 0; i < variablesTuple.size(); ++i)
42 posMapping.put(variablesTuple.get(i), i);
43 }
44
45 public PlanningTrace(SubPlan subPlan, List<PVariable> variablesTuple,
46 ReteNodeRecipe recipe,
47 RecipeTraceInfo... parentRecipeTraces) {
48 this(subPlan, variablesTuple, recipe, Arrays.asList(parentRecipeTraces));
49 }
50
51 public SubPlan getSubPlan() {
52 return subPlan;
53 }
54
55 @Override
56 public String getPatternName() {
57 return subPlan.getBody().getPattern().getFullyQualifiedName();
58 }
59
60 public List<PVariable> getVariablesTuple() {
61 return variablesTuple;
62 }
63
64 public Map<PVariable, Integer> getPosMapping() {
65 return posMapping;
66 }
67
68 /**
69 * Returns a new clone that reinterprets the same compiled form
70 * as the compiled form of a (potentially different) subPlan.
71 * Useful e.g. if child plan turns out to be a no-op, or when promoting a {@link PlanningTrace} to {@link CompiledSubPlan}.
72 */
73 public CompiledSubPlan cloneFor(SubPlan newSubPlan) {
74 return new CompiledSubPlan(newSubPlan,
75 getVariablesTuple(),
76 getRecipe(),
77 getParentRecipeTracesForCloning());
78 }
79
80} \ No newline at end of file