aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/generic/GenericTypeExtendSingleValue.java
diff options
context:
space:
mode:
authorLibravatar Kristóf Marussy <marussy@mit.bme.hu>2023-09-14 19:29:36 +0200
committerLibravatar GitHub <noreply@github.com>2023-09-14 19:29:36 +0200
commit98ed3b6db5f4e51961a161050cc31c66015116e8 (patch)
tree8bfd6d9bc8d6ed23b9eb0f889dd40b6c24fe8f92 /subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/generic/GenericTypeExtendSingleValue.java
parentMerge pull request #38 from nagilooh/design-space-exploration (diff)
parentMerge remote-tracking branch 'upstream/main' into partial-interpretation (diff)
downloadrefinery-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-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/generic/GenericTypeExtendSingleValue.java')
-rw-r--r--subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/generic/GenericTypeExtendSingleValue.java114
1 files changed, 114 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/generic/GenericTypeExtendSingleValue.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/generic/GenericTypeExtendSingleValue.java
new file mode 100644
index 00000000..45e4fd0e
--- /dev/null
+++ b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/generic/GenericTypeExtendSingleValue.java
@@ -0,0 +1,114 @@
1/*******************************************************************************
2 * Copyright (c) 2010-2017, Zoltan Ujhelyi, IncQuery Labs Ltd.
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.localsearch.operations.generic;
10
11import java.util.ArrayList;
12import java.util.Collections;
13import java.util.Iterator;
14import java.util.List;
15import java.util.Objects;
16import java.util.function.Function;
17import java.util.stream.Collectors;
18
19import tools.refinery.viatra.runtime.localsearch.MatchingFrame;
20import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext;
21import tools.refinery.viatra.runtime.localsearch.operations.IIteratingSearchOperation;
22import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation;
23import tools.refinery.viatra.runtime.localsearch.operations.extend.SingleValueExtendOperationExecutor;
24import tools.refinery.viatra.runtime.matchers.context.IInputKey;
25import tools.refinery.viatra.runtime.matchers.tuple.TupleMask;
26import tools.refinery.viatra.runtime.matchers.tuple.VolatileMaskedTuple;
27import tools.refinery.viatra.runtime.matchers.util.Preconditions;
28
29/**
30 * @author Zoltan Ujhelyi
31 * @since 1.7
32 * @noextend This class is not intended to be subclassed by clients.
33 */
34public class GenericTypeExtendSingleValue implements IIteratingSearchOperation {
35
36 private class Executor extends SingleValueExtendOperationExecutor<Object> {
37
38 private final VolatileMaskedTuple maskedTuple;
39
40 public Executor(int position) {
41 super(position);
42 this.maskedTuple = new VolatileMaskedTuple(callMask);
43 }
44
45 @Override
46 protected Iterator<? extends Object> getIterator(MatchingFrame frame, ISearchContext context) {
47 maskedTuple.updateTuple(frame);
48 return context.getRuntimeContext().enumerateValues(type, indexerMask, maskedTuple).iterator();
49 }
50
51 @Override
52 public ISearchOperation getOperation() {
53 return GenericTypeExtendSingleValue.this;
54 }
55 }
56
57 private final IInputKey type;
58 private final List<Integer> positionList;
59 private final TupleMask indexerMask;
60 private final TupleMask callMask;
61 private final int unboundVariableIndex;
62
63 /**
64 *
65 * @param type
66 * the type to execute the extend operation on
67 * @param positions
68 * the parameter positions that represent the variables of the input key
69 */
70 public GenericTypeExtendSingleValue(IInputKey type, int[] positions, TupleMask callMask, TupleMask indexerMask, int unboundVariableIndex) {
71 Preconditions.checkArgument(positions.length == type.getArity(),
72 "The type %s requires %d parameters, but %d positions are provided", type.getPrettyPrintableName(),
73 type.getArity(), positions.length);
74 List<Integer> modifiablePositionList = new ArrayList<>();
75 for (int position : positions) {
76 modifiablePositionList.add(position);
77 }
78 this.unboundVariableIndex = unboundVariableIndex;
79 this.positionList = Collections.unmodifiableList(modifiablePositionList);
80 this.type = type;
81
82 this.callMask = callMask;
83 this.indexerMask = indexerMask;
84 }
85
86 @Override
87 public IInputKey getIteratedInputKey() {
88 return type;
89 }
90
91 @Override
92 public ISearchOperationExecutor createExecutor() {
93 return new Executor(unboundVariableIndex);
94 }
95
96 @Override
97 public List<Integer> getVariablePositions() {
98 return positionList;
99 }
100
101 @Override
102 public String toString() {
103 return toString(Object::toString);
104 }
105
106 @Override
107 public String toString(Function<Integer, String> variableMapping) {
108 return "extend " + type.getPrettyPrintableName() + "("
109 + positionList.stream().map(
110 input -> String.format("%s%s", Objects.equals(input, unboundVariableIndex) ? "-" : "+", variableMapping.apply(input)))
111 .collect(Collectors.joining(", "))
112 + ")";
113 }
114}