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
|
/*******************************************************************************
* Copyright (c) 2010-2014, Bergmann Gabor, Istvan Rath and Daniel Varro
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0 which is available at
* http://www.eclipse.org/legal/epl-v20.html.
*
* SPDX-License-Identifier: EPL-2.0
*******************************************************************************/
package tools.refinery.viatra.runtime.rete.traceability;
import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
import tools.refinery.viatra.runtime.matchers.planning.SubPlan;
import tools.refinery.viatra.runtime.matchers.psystem.PVariable;
import tools.refinery.viatra.runtime.matchers.util.Preconditions;
import tools.refinery.viatra.runtime.rete.recipes.ReteNodeRecipe;
/**
* A trace marker associating a Rete recipe with a query SubPlan.
*
* <p> The Rete node represented by the recipe is equivalent to the SubPlan.
* <p> Invariant: each variable has at most one index associated with it in the tuple, i.e. no duplicates.
*/
public class CompiledSubPlan extends PlanningTrace {
public CompiledSubPlan(SubPlan subPlan, List<PVariable> variablesTuple,
ReteNodeRecipe recipe,
Collection<? extends RecipeTraceInfo> parentRecipeTraces) {
super(subPlan, variablesTuple, recipe, parentRecipeTraces);
// Make sure that each variable occurs only once
Set<PVariable> variablesSet = new HashSet<PVariable>(variablesTuple);
Preconditions.checkState(variablesSet.size() == variablesTuple.size(),
() -> String.format(
"Illegal column duplication (%s) while the query plan %s was compiled into a Rete Recipe %s",
variablesTuple.stream().map(PVariable::getName).collect(Collectors.joining(",")),
subPlan.toShortString(), recipe));
}
public CompiledSubPlan(SubPlan subPlan, List<PVariable> variablesTuple,
ReteNodeRecipe recipe,
RecipeTraceInfo... parentRecipeTraces) {
this(subPlan, variablesTuple, recipe, Arrays.asList(parentRecipeTraces));
}
}
|