aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/RelationalOperationCompiler.java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/RelationalOperationCompiler.java')
-rw-r--r--subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/RelationalOperationCompiler.java65
1 files changed, 65 insertions, 0 deletions
diff --git a/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/RelationalOperationCompiler.java b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/RelationalOperationCompiler.java
new file mode 100644
index 00000000..b6832b39
--- /dev/null
+++ b/subprojects/store-query-viatra/src/main/java/tools/refinery/store/query/viatra/internal/localsearch/RelationalOperationCompiler.java
@@ -0,0 +1,65 @@
1package tools.refinery.store.query.viatra.internal.localsearch;
2
3import org.eclipse.viatra.query.runtime.localsearch.operations.generic.GenericTypeExtendSingleValue;
4import org.eclipse.viatra.query.runtime.localsearch.operations.util.CallInformation;
5import org.eclipse.viatra.query.runtime.localsearch.planner.compiler.GenericOperationCompiler;
6import org.eclipse.viatra.query.runtime.matchers.context.IInputKey;
7import org.eclipse.viatra.query.runtime.matchers.context.IQueryRuntimeContext;
8import org.eclipse.viatra.query.runtime.matchers.psystem.PVariable;
9import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.PositivePatternCall;
10import org.eclipse.viatra.query.runtime.matchers.psystem.basicenumerables.TypeConstraint;
11import org.eclipse.viatra.query.runtime.matchers.tuple.Tuple;
12import org.eclipse.viatra.query.runtime.matchers.tuple.TupleMask;
13
14import java.util.*;
15
16public class RelationalOperationCompiler extends GenericOperationCompiler {
17 public RelationalOperationCompiler(IQueryRuntimeContext runtimeContext) {
18 super(runtimeContext);
19 }
20
21 @Override
22 protected void createExtend(TypeConstraint typeConstraint, Map<PVariable, Integer> variableMapping) {
23 IInputKey inputKey = typeConstraint.getSupplierKey();
24 Tuple tuple = typeConstraint.getVariablesTuple();
25
26 int[] positions = new int[tuple.getSize()];
27 List<Integer> boundVariableIndices = new ArrayList<>();
28 List<Integer> boundVariables = new ArrayList<>();
29 Set<Integer> unboundVariables = new HashSet<>();
30 for (int i = 0; i < tuple.getSize(); i++) {
31 PVariable variable = (PVariable) tuple.get(i);
32 Integer position = variableMapping.get(variable);
33 positions[i] = position;
34 if (variableBindings.get(typeConstraint).contains(position)) {
35 boundVariableIndices.add(i);
36 boundVariables.add(position);
37 } else {
38 unboundVariables.add(position);
39 }
40 }
41 TupleMask indexerMask = TupleMask.fromSelectedIndices(inputKey.getArity(), boundVariableIndices);
42 TupleMask callMask = TupleMask.fromSelectedIndices(variableMapping.size(), boundVariables);
43 // If multiple tuple elements from the indexer should be bound to the same variable, we must use a
44 // {@link GenericTypeExtend} check whether the tuple elements have the same value.
45 if (unboundVariables.size() == 1 && indexerMask.getSize() + 1 == indexerMask.getSourceWidth()) {
46 operations.add(new GenericTypeExtendSingleValue(inputKey, positions, callMask, indexerMask,
47 unboundVariables.iterator().next()));
48 } else {
49 // Use a fixed version of
50 // {@code org.eclipse.viatra.query.runtime.localsearch.operations.generic.GenericTypeExtend} that handles
51 // failed unification of variables correctly.
52 operations.add(new GenericTypeExtend(inputKey, positions, callMask, indexerMask, unboundVariables));
53 }
54 }
55
56 @Override
57 protected void createExtend(PositivePatternCall pCall, Map<PVariable, Integer> variableMapping) {
58 CallInformation information = CallInformation.create(pCall, variableMapping, variableBindings.get(pCall));
59 // Use a fixed version of
60 // {@code org.eclipse.viatra.query.runtime.localsearch.operations.extend.ExtendPositivePatternCall} that handles
61 // failed unification of variables correctly.
62 operations.add(new ExtendPositivePatternCall(information));
63 dependencies.add(information.getCallWithAdornment());
64 }
65}