diff options
author | Kristóf Marussy <kristof@marussy.com> | 2023-08-19 03:00:23 +0200 |
---|---|---|
committer | Kristóf Marussy <kristof@marussy.com> | 2023-08-19 03:00:23 +0200 |
commit | fc7e3dc61a2ac8de32914af331c1144e4fa843e6 (patch) | |
tree | f17f58c9a14700e76c4b54b242c0bca061199e1f /subprojects/viatra-runtime-localsearch/src | |
parent | chore: import VIATRA source (diff) | |
download | refinery-fc7e3dc61a2ac8de32914af331c1144e4fa843e6.tar.gz refinery-fc7e3dc61a2ac8de32914af331c1144e4fa843e6.tar.zst refinery-fc7e3dc61a2ac8de32914af331c1144e4fa843e6.zip |
refactor: remove unused VIATRA code
We don't need Eclipse platform support, table-based scopes, and EMF support.
Diffstat (limited to 'subprojects/viatra-runtime-localsearch/src')
26 files changed, 151 insertions, 2241 deletions
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/ExecutionLoggerAdapter.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/ExecutionLoggerAdapter.java index 0f7c7b01..bfb76d9a 100644 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/ExecutionLoggerAdapter.java +++ b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/ExecutionLoggerAdapter.java | |||
@@ -3,41 +3,40 @@ | |||
3 | * This program and the accompanying materials are made available under the | 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 | 4 | * terms of the Eclipse Public License v. 2.0 which is available at |
5 | * http://www.eclipse.org/legal/epl-v20.html. | 5 | * http://www.eclipse.org/legal/epl-v20.html. |
6 | * | 6 | * |
7 | * SPDX-License-Identifier: EPL-2.0 | 7 | * SPDX-License-Identifier: EPL-2.0 |
8 | *******************************************************************************/ | 8 | *******************************************************************************/ |
9 | package tools.refinery.viatra.runtime.localsearch; | 9 | package tools.refinery.viatra.runtime.localsearch; |
10 | 10 | ||
11 | import java.util.Optional; | ||
12 | import java.util.function.Consumer; | ||
13 | |||
14 | import tools.refinery.viatra.runtime.localsearch.matcher.ILocalSearchAdapter; | 11 | import tools.refinery.viatra.runtime.localsearch.matcher.ILocalSearchAdapter; |
15 | import tools.refinery.viatra.runtime.localsearch.matcher.LocalSearchMatcher; | 12 | import tools.refinery.viatra.runtime.localsearch.matcher.LocalSearchMatcher; |
16 | import tools.refinery.viatra.runtime.localsearch.operations.IPatternMatcherOperation; | 13 | import tools.refinery.viatra.runtime.localsearch.operations.IPatternMatcherOperation; |
17 | import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation; | 14 | import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation; |
18 | import tools.refinery.viatra.runtime.localsearch.operations.check.nobase.ScopeCheck; | ||
19 | import tools.refinery.viatra.runtime.localsearch.plan.SearchPlan; | 15 | import tools.refinery.viatra.runtime.localsearch.plan.SearchPlan; |
20 | 16 | ||
17 | import java.util.Optional; | ||
18 | import java.util.function.Consumer; | ||
19 | |||
21 | /** | 20 | /** |
22 | * @since 2.0 | 21 | * @since 2.0 |
23 | */ | 22 | */ |
24 | public final class ExecutionLoggerAdapter implements ILocalSearchAdapter { | 23 | public final class ExecutionLoggerAdapter implements ILocalSearchAdapter { |
25 | 24 | ||
26 | volatile String indentation = ""; | 25 | volatile String indentation = ""; |
27 | private final Consumer<String> outputConsumer; | 26 | private final Consumer<String> outputConsumer; |
28 | 27 | ||
29 | public ExecutionLoggerAdapter(Consumer<String> outputConsumer) { | 28 | public ExecutionLoggerAdapter(Consumer<String> outputConsumer) { |
30 | this.outputConsumer = outputConsumer; | 29 | this.outputConsumer = outputConsumer; |
31 | } | 30 | } |
32 | 31 | ||
33 | private void logMessage(String message) { | 32 | private void logMessage(String message) { |
34 | outputConsumer.accept(message); | 33 | outputConsumer.accept(message); |
35 | } | 34 | } |
36 | 35 | ||
37 | private void logMessage(String message, Object...args) { | 36 | private void logMessage(String message, Object...args) { |
38 | outputConsumer.accept(String.format(message, args)); | 37 | outputConsumer.accept(String.format(message, args)); |
39 | } | 38 | } |
40 | 39 | ||
41 | @Override | 40 | @Override |
42 | public void patternMatchingStarted(LocalSearchMatcher lsMatcher) { | 41 | public void patternMatchingStarted(LocalSearchMatcher lsMatcher) { |
43 | logMessage(indentation + "[ START] " + lsMatcher.getQuerySpecification().getFullyQualifiedName()); | 42 | logMessage(indentation + "[ START] " + lsMatcher.getQuerySpecification().getFullyQualifiedName()); |
@@ -56,7 +55,7 @@ public final class ExecutionLoggerAdapter implements ILocalSearchAdapter { | |||
56 | 55 | ||
57 | @Override | 56 | @Override |
58 | public void operationSelected(SearchPlan plan, ISearchOperation operation, MatchingFrame frame, boolean isBacktrack) { | 57 | public void operationSelected(SearchPlan plan, ISearchOperation operation, MatchingFrame frame, boolean isBacktrack) { |
59 | String category = isBacktrack ? "[ BACK] " : "[SELECT] "; | 58 | String category = isBacktrack ? "[ BACK] " : "[SELECT] "; |
60 | logMessage(indentation + category + operation.toString()); | 59 | logMessage(indentation + category + operation.toString()); |
61 | if (operation instanceof IPatternMatcherOperation) { | 60 | if (operation instanceof IPatternMatcherOperation) { |
62 | indentation = indentation + "\t"; | 61 | indentation = indentation + "\t"; |
@@ -66,7 +65,6 @@ public final class ExecutionLoggerAdapter implements ILocalSearchAdapter { | |||
66 | @Override | 65 | @Override |
67 | public void operationExecuted(SearchPlan plan, ISearchOperation operation, MatchingFrame frame, | 66 | public void operationExecuted(SearchPlan plan, ISearchOperation operation, MatchingFrame frame, |
68 | boolean isSuccessful) { | 67 | boolean isSuccessful) { |
69 | if (operation instanceof ScopeCheck) return; | ||
70 | if (operation instanceof IPatternMatcherOperation && indentation.length() > 0) { | 68 | if (operation instanceof IPatternMatcherOperation && indentation.length() > 0) { |
71 | indentation = indentation.substring(1); | 69 | indentation = indentation.substring(1); |
72 | } | 70 | } |
@@ -77,9 +75,9 @@ public final class ExecutionLoggerAdapter implements ILocalSearchAdapter { | |||
77 | public void matchFound(SearchPlan plan, MatchingFrame frame) { | 75 | public void matchFound(SearchPlan plan, MatchingFrame frame) { |
78 | logMessage(indentation + "[ MATCH] " + plan.getSourceBody().getPattern().getFullyQualifiedName() + " " + frame.toString()); | 76 | logMessage(indentation + "[ MATCH] " + plan.getSourceBody().getPattern().getFullyQualifiedName() + " " + frame.toString()); |
79 | } | 77 | } |
80 | 78 | ||
81 | @Override | 79 | @Override |
82 | public void duplicateMatchFound(MatchingFrame frame) { | 80 | public void duplicateMatchFound(MatchingFrame frame) { |
83 | logMessage(indentation + "[ DUPL.] " + frame.toString()); | 81 | logMessage(indentation + "[ DUPL.] " + frame.toString()); |
84 | } | 82 | } |
85 | } \ No newline at end of file | 83 | } |
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/MatchingFrame.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/MatchingFrame.java index 9caf32bb..bdbc663c 100644 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/MatchingFrame.java +++ b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/MatchingFrame.java | |||
@@ -3,21 +3,19 @@ | |||
3 | * This program and the accompanying materials are made available under the | 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 | 4 | * terms of the Eclipse Public License v. 2.0 which is available at |
5 | * http://www.eclipse.org/legal/epl-v20.html. | 5 | * http://www.eclipse.org/legal/epl-v20.html. |
6 | * | 6 | * |
7 | * SPDX-License-Identifier: EPL-2.0 | 7 | * SPDX-License-Identifier: EPL-2.0 |
8 | *******************************************************************************/ | 8 | *******************************************************************************/ |
9 | 9 | ||
10 | package tools.refinery.viatra.runtime.localsearch; | 10 | package tools.refinery.viatra.runtime.localsearch; |
11 | 11 | ||
12 | import java.util.Arrays; | ||
13 | import java.util.stream.Collectors; | ||
14 | |||
15 | import org.eclipse.emf.ecore.EObject; | ||
16 | import org.eclipse.emf.ecore.EStructuralFeature; | ||
17 | import tools.refinery.viatra.runtime.matchers.tuple.IModifiableTuple; | 12 | import tools.refinery.viatra.runtime.matchers.tuple.IModifiableTuple; |
18 | import tools.refinery.viatra.runtime.matchers.tuple.VolatileTuple; | 13 | import tools.refinery.viatra.runtime.matchers.tuple.VolatileTuple; |
19 | import tools.refinery.viatra.runtime.matchers.util.Preconditions; | 14 | import tools.refinery.viatra.runtime.matchers.util.Preconditions; |
20 | 15 | ||
16 | import java.util.Arrays; | ||
17 | import java.util.stream.Collectors; | ||
18 | |||
21 | /** | 19 | /** |
22 | * A MatchingFrame is a Volatile Tuple implementation used by the local search engine internally. | 20 | * A MatchingFrame is a Volatile Tuple implementation used by the local search engine internally. |
23 | */ | 21 | */ |
@@ -34,7 +32,7 @@ public class MatchingFrame extends VolatileTuple implements IModifiableTuple { | |||
34 | public MatchingFrame(int frameSize) { | 32 | public MatchingFrame(int frameSize) { |
35 | this.frame = new Object[frameSize]; | 33 | this.frame = new Object[frameSize]; |
36 | } | 34 | } |
37 | 35 | ||
38 | /** | 36 | /** |
39 | * Creates a copy of another matching frame; the two frames can be updated separately | 37 | * Creates a copy of another matching frame; the two frames can be updated separately |
40 | * @param other | 38 | * @param other |
@@ -48,7 +46,7 @@ public class MatchingFrame extends VolatileTuple implements IModifiableTuple { | |||
48 | 46 | ||
49 | /** | 47 | /** |
50 | * Returns the value stored inside the matching frame. | 48 | * Returns the value stored inside the matching frame. |
51 | * | 49 | * |
52 | * @param position | 50 | * @param position |
53 | * @return the element stored in the selected position in the frame, or null if it is not yet set | 51 | * @return the element stored in the selected position in the frame, or null if it is not yet set |
54 | * @throws IndexOutOfBoundsException | 52 | * @throws IndexOutOfBoundsException |
@@ -60,10 +58,10 @@ public class MatchingFrame extends VolatileTuple implements IModifiableTuple { | |||
60 | Preconditions.checkElementIndex(position, frame.length); | 58 | Preconditions.checkElementIndex(position, frame.length); |
61 | return frame[position]; | 59 | return frame[position]; |
62 | } | 60 | } |
63 | 61 | ||
64 | /** | 62 | /** |
65 | * Sets the value of the variable at the given position. For internal use in LS matching only. | 63 | * Sets the value of the variable at the given position. For internal use in LS matching only. |
66 | * | 64 | * |
67 | * @param position the position of the variable within the frame | 65 | * @param position the position of the variable within the frame |
68 | * @param value the value to be set for the variable | 66 | * @param value the value to be set for the variable |
69 | */ | 67 | */ |
@@ -71,7 +69,7 @@ public class MatchingFrame extends VolatileTuple implements IModifiableTuple { | |||
71 | Preconditions.checkElementIndex(position, frame.length); | 69 | Preconditions.checkElementIndex(position, frame.length); |
72 | frame[position] = value; | 70 | frame[position] = value; |
73 | } | 71 | } |
74 | 72 | ||
75 | public boolean testAndSetValue(Integer position, Object value) { | 73 | public boolean testAndSetValue(Integer position, Object value) { |
76 | Preconditions.checkElementIndex(position, frame.length); | 74 | Preconditions.checkElementIndex(position, frame.length); |
77 | if (frame[position] == null) { | 75 | if (frame[position] == null) { |
@@ -86,20 +84,14 @@ public class MatchingFrame extends VolatileTuple implements IModifiableTuple { | |||
86 | public String toString() { | 84 | public String toString() { |
87 | return Arrays.stream(frame).map(this::stringRepresentation).collect(Collectors.joining(", ", "[", "]")); | 85 | return Arrays.stream(frame).map(this::stringRepresentation).collect(Collectors.joining(", ", "[", "]")); |
88 | } | 86 | } |
89 | 87 | ||
90 | private String stringRepresentation(Object obj) { | 88 | private String stringRepresentation(Object obj) { |
91 | if (obj == null) { | 89 | if (obj == null) { |
92 | return "_"; | 90 | return "_"; |
93 | } else if (obj instanceof EObject) { | ||
94 | EObject eObject = (EObject) obj; | ||
95 | final EStructuralFeature feature = eObject.eClass().getEStructuralFeature("identifier"); | ||
96 | if (feature != null) { | ||
97 | return String.format("%s : %s", eObject.eGet(feature), eObject.eClass().getName()); | ||
98 | } | ||
99 | } | 91 | } |
100 | return obj.toString(); | 92 | return obj.toString(); |
101 | } | 93 | } |
102 | 94 | ||
103 | @Override | 95 | @Override |
104 | public int getSize() { | 96 | public int getSize() { |
105 | return frame.length; | 97 | return frame.length; |
@@ -109,7 +101,7 @@ public class MatchingFrame extends VolatileTuple implements IModifiableTuple { | |||
109 | public Object get(int index) { | 101 | public Object get(int index) { |
110 | return getValue(index); | 102 | return getValue(index); |
111 | } | 103 | } |
112 | 104 | ||
113 | @Override | 105 | @Override |
114 | public Object[] getElements() { | 106 | public Object[] getElements() { |
115 | return Arrays.copyOf(frame, frame.length); | 107 | return Arrays.copyOf(frame, frame.length); |
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/matcher/ISearchContext.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/matcher/ISearchContext.java index 380774bb..71aa4aac 100644 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/matcher/ISearchContext.java +++ b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/matcher/ISearchContext.java | |||
@@ -3,20 +3,12 @@ | |||
3 | * This program and the accompanying materials are made available under the | 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 | 4 | * terms of the Eclipse Public License v. 2.0 which is available at |
5 | * http://www.eclipse.org/legal/epl-v20.html. | 5 | * http://www.eclipse.org/legal/epl-v20.html. |
6 | * | 6 | * |
7 | * SPDX-License-Identifier: EPL-2.0 | 7 | * SPDX-License-Identifier: EPL-2.0 |
8 | *******************************************************************************/ | 8 | *******************************************************************************/ |
9 | package tools.refinery.viatra.runtime.localsearch.matcher; | 9 | package tools.refinery.viatra.runtime.localsearch.matcher; |
10 | 10 | ||
11 | import java.util.Collections; | ||
12 | import java.util.Set; | ||
13 | |||
14 | import org.apache.log4j.Logger; | 11 | import org.apache.log4j.Logger; |
15 | import org.eclipse.emf.ecore.EClass; | ||
16 | import org.eclipse.emf.ecore.EDataType; | ||
17 | import org.eclipse.emf.ecore.EStructuralFeature; | ||
18 | import tools.refinery.viatra.runtime.base.api.IndexingLevel; | ||
19 | import tools.refinery.viatra.runtime.base.api.NavigationHelper; | ||
20 | import tools.refinery.viatra.runtime.localsearch.matcher.integration.IAdornmentProvider; | 12 | import tools.refinery.viatra.runtime.localsearch.matcher.integration.IAdornmentProvider; |
21 | import tools.refinery.viatra.runtime.matchers.ViatraQueryRuntimeException; | 13 | import tools.refinery.viatra.runtime.matchers.ViatraQueryRuntimeException; |
22 | import tools.refinery.viatra.runtime.matchers.backend.IQueryResultProvider; | 14 | import tools.refinery.viatra.runtime.matchers.backend.IQueryResultProvider; |
@@ -26,9 +18,11 @@ import tools.refinery.viatra.runtime.matchers.context.IQueryRuntimeContext; | |||
26 | import tools.refinery.viatra.runtime.matchers.util.ICache; | 18 | import tools.refinery.viatra.runtime.matchers.util.ICache; |
27 | import tools.refinery.viatra.runtime.matchers.util.IProvider; | 19 | import tools.refinery.viatra.runtime.matchers.util.IProvider; |
28 | 20 | ||
21 | import java.util.Collections; | ||
22 | |||
29 | /** | 23 | /** |
30 | * The {@link ISearchContext} interface allows search operations to reuse platform services such as the indexer. | 24 | * The {@link ISearchContext} interface allows search operations to reuse platform services such as the indexer. |
31 | * | 25 | * |
32 | * @author Zoltan Ujhelyi | 26 | * @author Zoltan Ujhelyi |
33 | * @noreference This interface is not intended to be referenced by clients. | 27 | * @noreference This interface is not intended to be referenced by clients. |
34 | * @noimplement This interface is not intended to be implemented by clients. | 28 | * @noimplement This interface is not intended to be implemented by clients. |
@@ -36,43 +30,36 @@ import tools.refinery.viatra.runtime.matchers.util.IProvider; | |||
36 | * | 30 | * |
37 | */ | 31 | */ |
38 | public interface ISearchContext { | 32 | public interface ISearchContext { |
39 | 33 | ||
40 | /** | 34 | /** |
41 | * Provides access to the generic query runtime context of the current engine | 35 | * Provides access to the generic query runtime context of the current engine |
42 | * @since 1.7 | 36 | * @since 1.7 |
43 | */ | 37 | */ |
44 | IQueryRuntimeContext getRuntimeContext(); | 38 | IQueryRuntimeContext getRuntimeContext(); |
45 | 39 | ||
46 | /** | ||
47 | * @param classes | ||
48 | * @param dataTypes | ||
49 | * @param features | ||
50 | */ | ||
51 | void registerObservedTypes(Set<EClass> classes, Set<EDataType> dataTypes, Set<EStructuralFeature> features); | ||
52 | |||
53 | /** | 40 | /** |
54 | * Returns a matcher for a selected query specification. | 41 | * Returns a matcher for a selected query specification. |
55 | * | 42 | * |
56 | * @throws ViatraQueryRuntimeException | 43 | * @throws ViatraQueryRuntimeException |
57 | * @since 1.5 | 44 | * @since 1.5 |
58 | */ | 45 | */ |
59 | IQueryResultProvider getMatcher(CallWithAdornment dependency); | 46 | IQueryResultProvider getMatcher(CallWithAdornment dependency); |
60 | 47 | ||
61 | /** | 48 | /** |
62 | * Allows search operations to cache values through the entire lifecycle of the local search backend. The values are | 49 | * Allows search operations to cache values through the entire lifecycle of the local search backend. The values are |
63 | * calculated if not cached before using the given provider, or returned from the cache accordingly. | 50 | * calculated if not cached before using the given provider, or returned from the cache accordingly. |
64 | * | 51 | * |
65 | * @since 1.7 | 52 | * @since 1.7 |
66 | */ | 53 | */ |
67 | <T> T accessBackendLevelCache(Object key, Class<? extends T> clazz, IProvider<T> valueProvider); | 54 | <T> T accessBackendLevelCache(Object key, Class<? extends T> clazz, IProvider<T> valueProvider); |
68 | 55 | ||
69 | /** | 56 | /** |
70 | * Returns the engine-specific logger | 57 | * Returns the engine-specific logger |
71 | * | 58 | * |
72 | * @since 2.0 | 59 | * @since 2.0 |
73 | */ | 60 | */ |
74 | Logger getLogger(); | 61 | Logger getLogger(); |
75 | 62 | ||
76 | /** | 63 | /** |
77 | * @noreference This class is not intended to be referenced by clients. | 64 | * @noreference This class is not intended to be referenced by clients. |
78 | * @noimplement This interface is not intended to be implemented by clients. | 65 | * @noimplement This interface is not intended to be implemented by clients. |
@@ -80,34 +67,24 @@ public interface ISearchContext { | |||
80 | */ | 67 | */ |
81 | public class SearchContext implements ISearchContext { | 68 | public class SearchContext implements ISearchContext { |
82 | 69 | ||
83 | private final NavigationHelper navigationHelper; | ||
84 | private final IQueryRuntimeContext runtimeContext; | 70 | private final IQueryRuntimeContext runtimeContext; |
85 | 71 | ||
86 | private final ICache backendLevelCache; | 72 | private final ICache backendLevelCache; |
87 | private final Logger logger; | 73 | private final Logger logger; |
88 | private final ResultProviderRequestor resultProviderRequestor; | 74 | private final ResultProviderRequestor resultProviderRequestor; |
89 | 75 | ||
90 | /** | 76 | /** |
91 | * Initializes a search context using an arbitrary backend context | 77 | * Initializes a search context using an arbitrary backend context |
92 | */ | 78 | */ |
93 | public SearchContext(IQueryBackendContext backendContext, ICache backendLevelCache, | 79 | public SearchContext(IQueryBackendContext backendContext, ICache backendLevelCache, |
94 | ResultProviderRequestor resultProviderRequestor) { | 80 | ResultProviderRequestor resultProviderRequestor) { |
95 | this.resultProviderRequestor = resultProviderRequestor; | 81 | this.resultProviderRequestor = resultProviderRequestor; |
96 | this.runtimeContext = backendContext.getRuntimeContext(); | 82 | this.runtimeContext = backendContext.getRuntimeContext(); |
97 | this.logger = backendContext.getLogger(); | 83 | this.logger = backendContext.getLogger(); |
98 | this.navigationHelper = null; | 84 | |
99 | |||
100 | this.backendLevelCache = backendLevelCache; | 85 | this.backendLevelCache = backendLevelCache; |
101 | } | 86 | } |
102 | 87 | ||
103 | public void registerObservedTypes(Set<EClass> classes, Set<EDataType> dataTypes, Set<EStructuralFeature> features) { | ||
104 | if (this.navigationHelper.isInWildcardMode()) { | ||
105 | // In wildcard mode, everything is registered (+ register throws an exception) | ||
106 | return; | ||
107 | } | ||
108 | this.navigationHelper.registerObservedTypes(classes, dataTypes, features, IndexingLevel.FULL); | ||
109 | } | ||
110 | |||
111 | /** | 88 | /** |
112 | * @throws ViatraQueryRuntimeException | 89 | * @throws ViatraQueryRuntimeException |
113 | * @since 2.1 | 90 | * @since 2.1 |
@@ -121,7 +98,7 @@ public interface ISearchContext { | |||
121 | } | 98 | } |
122 | return Collections.emptySet(); | 99 | return Collections.emptySet(); |
123 | }; | 100 | }; |
124 | return resultProviderRequestor.requestResultProvider(dependency.getCall(), | 101 | return resultProviderRequestor.requestResultProvider(dependency.getCall(), |
125 | IAdornmentProvider.toHint(adornmentProvider)); | 102 | IAdornmentProvider.toHint(adornmentProvider)); |
126 | } | 103 | } |
127 | 104 | ||
@@ -133,11 +110,11 @@ public interface ISearchContext { | |||
133 | public IQueryRuntimeContext getRuntimeContext() { | 110 | public IQueryRuntimeContext getRuntimeContext() { |
134 | return runtimeContext; | 111 | return runtimeContext; |
135 | } | 112 | } |
136 | 113 | ||
137 | @Override | 114 | @Override |
138 | public Logger getLogger() { | 115 | public Logger getLogger() { |
139 | return logger; | 116 | return logger; |
140 | } | 117 | } |
141 | 118 | ||
142 | } | 119 | } |
143 | } | 120 | } |
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/matcher/integration/LocalSearchBackendFactoryProvider.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/matcher/integration/LocalSearchBackendFactoryProvider.java deleted file mode 100644 index bba381d3..00000000 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/matcher/integration/LocalSearchBackendFactoryProvider.java +++ /dev/null | |||
@@ -1,29 +0,0 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2018, 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 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.localsearch.matcher.integration; | ||
10 | |||
11 | import tools.refinery.viatra.runtime.matchers.backend.IQueryBackendFactory; | ||
12 | import tools.refinery.viatra.runtime.matchers.backend.IQueryBackendFactoryProvider; | ||
13 | |||
14 | /** | ||
15 | * @since 2.0 | ||
16 | */ | ||
17 | public class LocalSearchBackendFactoryProvider implements IQueryBackendFactoryProvider { | ||
18 | |||
19 | @Override | ||
20 | public IQueryBackendFactory getFactory() { | ||
21 | return LocalSearchEMFBackendFactory.INSTANCE; | ||
22 | } | ||
23 | |||
24 | @Override | ||
25 | public boolean isSystemDefaultSearchBackend() { | ||
26 | return true; | ||
27 | } | ||
28 | |||
29 | } \ No newline at end of file | ||
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/matcher/integration/LocalSearchEMFBackendFactory.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/matcher/integration/LocalSearchEMFBackendFactory.java deleted file mode 100644 index 5bffebac..00000000 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/matcher/integration/LocalSearchEMFBackendFactory.java +++ /dev/null | |||
@@ -1,65 +0,0 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2015, Marton Bur, Zoltan Ujhelyi, 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 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.localsearch.matcher.integration; | ||
10 | |||
11 | import tools.refinery.viatra.runtime.matchers.backend.IMatcherCapability; | ||
12 | import tools.refinery.viatra.runtime.matchers.backend.IQueryBackend; | ||
13 | import tools.refinery.viatra.runtime.matchers.backend.IQueryBackendFactory; | ||
14 | import tools.refinery.viatra.runtime.matchers.backend.QueryEvaluationHint; | ||
15 | import tools.refinery.viatra.runtime.matchers.context.IQueryBackendContext; | ||
16 | import tools.refinery.viatra.runtime.matchers.psystem.queries.PQuery; | ||
17 | |||
18 | /** | ||
19 | * @author Marton Bur, Zoltan Ujhelyi | ||
20 | * @since 2.0 | ||
21 | * | ||
22 | */ | ||
23 | public enum LocalSearchEMFBackendFactory implements IQueryBackendFactory { | ||
24 | |||
25 | |||
26 | INSTANCE; | ||
27 | |||
28 | /** | ||
29 | * @since 1.5 | ||
30 | */ | ||
31 | @Override | ||
32 | public IQueryBackend create(IQueryBackendContext context) { | ||
33 | return new LocalSearchBackend(context) { | ||
34 | |||
35 | @Override | ||
36 | protected AbstractLocalSearchResultProvider initializeResultProvider(PQuery query, QueryEvaluationHint hints) { | ||
37 | return new LocalSearchResultProvider(this, context, query, planProvider, hints); | ||
38 | } | ||
39 | |||
40 | @Override | ||
41 | public IQueryBackendFactory getFactory() { | ||
42 | return INSTANCE; | ||
43 | } | ||
44 | }; | ||
45 | } | ||
46 | |||
47 | @Override | ||
48 | public Class<? extends IQueryBackend> getBackendClass() { | ||
49 | return LocalSearchBackend.class; | ||
50 | } | ||
51 | |||
52 | /** | ||
53 | * @since 1.4 | ||
54 | */ | ||
55 | @Override | ||
56 | public IMatcherCapability calculateRequiredCapability(PQuery query, QueryEvaluationHint hint) { | ||
57 | return LocalSearchHints.parse(hint); | ||
58 | } | ||
59 | |||
60 | @Override | ||
61 | public boolean isCaching() { | ||
62 | return false; | ||
63 | } | ||
64 | |||
65 | } | ||
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/matcher/integration/LocalSearchHints.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/matcher/integration/LocalSearchHints.java index 75f338b6..5f3895be 100644 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/matcher/integration/LocalSearchHints.java +++ b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/matcher/integration/LocalSearchHints.java | |||
@@ -3,63 +3,51 @@ | |||
3 | * This program and the accompanying materials are made available under the | 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 | 4 | * terms of the Eclipse Public License v. 2.0 which is available at |
5 | * http://www.eclipse.org/legal/epl-v20.html. | 5 | * http://www.eclipse.org/legal/epl-v20.html. |
6 | * | 6 | * |
7 | * SPDX-License-Identifier: EPL-2.0 | 7 | * SPDX-License-Identifier: EPL-2.0 |
8 | *******************************************************************************/ | 8 | *******************************************************************************/ |
9 | package tools.refinery.viatra.runtime.localsearch.matcher.integration; | 9 | package tools.refinery.viatra.runtime.localsearch.matcher.integration; |
10 | 10 | ||
11 | import static tools.refinery.viatra.runtime.localsearch.matcher.integration.LocalSearchHintOptions.ADORNMENT_PROVIDER; | ||
12 | import static tools.refinery.viatra.runtime.localsearch.matcher.integration.LocalSearchHintOptions.CALL_DELEGATION_STRATEGY; | ||
13 | import static tools.refinery.viatra.runtime.localsearch.matcher.integration.LocalSearchHintOptions.FLATTEN_CALL_PREDICATE; | ||
14 | import static tools.refinery.viatra.runtime.localsearch.matcher.integration.LocalSearchHintOptions.PLANNER_COST_FUNCTION; | ||
15 | import static tools.refinery.viatra.runtime.localsearch.matcher.integration.LocalSearchHintOptions.PLANNER_TABLE_ROW_COUNT; | ||
16 | import static tools.refinery.viatra.runtime.localsearch.matcher.integration.LocalSearchHintOptions.USE_BASE_INDEX; | ||
17 | import static tools.refinery.viatra.runtime.matchers.backend.CommonQueryHintOptions.normalizationTraceCollector; | ||
18 | |||
19 | import java.util.HashMap; | ||
20 | import java.util.Map; | ||
21 | import java.util.Objects; | ||
22 | |||
23 | import tools.refinery.viatra.runtime.localsearch.planner.cost.ICostFunction; | 11 | import tools.refinery.viatra.runtime.localsearch.planner.cost.ICostFunction; |
24 | import tools.refinery.viatra.runtime.localsearch.planner.cost.impl.IndexerBasedConstraintCostFunction; | 12 | import tools.refinery.viatra.runtime.localsearch.planner.cost.impl.IndexerBasedConstraintCostFunction; |
25 | import tools.refinery.viatra.runtime.localsearch.planner.cost.impl.StatisticsBasedConstraintCostFunction; | 13 | import tools.refinery.viatra.runtime.localsearch.planner.cost.impl.StatisticsBasedConstraintCostFunction; |
26 | import tools.refinery.viatra.runtime.localsearch.planner.cost.impl.VariableBindingBasedCostFunction; | 14 | import tools.refinery.viatra.runtime.matchers.backend.*; |
27 | import tools.refinery.viatra.runtime.matchers.backend.ICallDelegationStrategy; | ||
28 | import tools.refinery.viatra.runtime.matchers.backend.IMatcherCapability; | ||
29 | import tools.refinery.viatra.runtime.matchers.backend.IQueryBackendFactory; | ||
30 | import tools.refinery.viatra.runtime.matchers.backend.QueryEvaluationHint; | ||
31 | import tools.refinery.viatra.runtime.matchers.backend.QueryHintOption; | ||
32 | import tools.refinery.viatra.runtime.matchers.psystem.rewriters.DefaultFlattenCallPredicate; | ||
33 | import tools.refinery.viatra.runtime.matchers.psystem.rewriters.IFlattenCallPredicate; | 15 | import tools.refinery.viatra.runtime.matchers.psystem.rewriters.IFlattenCallPredicate; |
34 | import tools.refinery.viatra.runtime.matchers.psystem.rewriters.IRewriterTraceCollector; | 16 | import tools.refinery.viatra.runtime.matchers.psystem.rewriters.IRewriterTraceCollector; |
35 | import tools.refinery.viatra.runtime.matchers.psystem.rewriters.NeverFlattenCallPredicate; | ||
36 | import tools.refinery.viatra.runtime.matchers.psystem.rewriters.NopTraceCollector; | 17 | import tools.refinery.viatra.runtime.matchers.psystem.rewriters.NopTraceCollector; |
37 | 18 | ||
19 | import java.util.HashMap; | ||
20 | import java.util.Map; | ||
21 | import java.util.Objects; | ||
22 | |||
23 | import static tools.refinery.viatra.runtime.localsearch.matcher.integration.LocalSearchHintOptions.*; | ||
24 | import static tools.refinery.viatra.runtime.matchers.backend.CommonQueryHintOptions.normalizationTraceCollector; | ||
25 | |||
38 | /** | 26 | /** |
39 | * Type safe builder and extractor for Local search specific hints | 27 | * Type safe builder and extractor for Local search specific hints |
40 | * | 28 | * |
41 | * @author Grill Balázs | 29 | * @author Grill Balázs |
42 | * @since 1.4 | 30 | * @since 1.4 |
43 | * | 31 | * |
44 | */ | 32 | */ |
45 | public final class LocalSearchHints implements IMatcherCapability { | 33 | public final class LocalSearchHints implements IMatcherCapability { |
46 | 34 | ||
47 | private Boolean useBase = null; | 35 | private Boolean useBase = null; |
48 | 36 | ||
49 | private Integer rowCount = null; | 37 | private Integer rowCount = null; |
50 | 38 | ||
51 | private ICostFunction costFunction = null; | 39 | private ICostFunction costFunction = null; |
52 | 40 | ||
53 | private IFlattenCallPredicate flattenCallPredicate = null; | 41 | private IFlattenCallPredicate flattenCallPredicate = null; |
54 | 42 | ||
55 | private ICallDelegationStrategy callDelegationStrategy = null; | 43 | private ICallDelegationStrategy callDelegationStrategy = null; |
56 | 44 | ||
57 | private IAdornmentProvider adornmentProvider = null; | 45 | private IAdornmentProvider adornmentProvider = null; |
58 | 46 | ||
59 | private IRewriterTraceCollector traceCollector = NopTraceCollector.INSTANCE; | 47 | private IRewriterTraceCollector traceCollector = NopTraceCollector.INSTANCE; |
60 | 48 | ||
61 | private IQueryBackendFactory backendFactory = null; | 49 | private IQueryBackendFactory backendFactory = null; |
62 | 50 | ||
63 | private LocalSearchHints() {} | 51 | private LocalSearchHints() {} |
64 | 52 | ||
65 | /** | 53 | /** |
@@ -68,53 +56,14 @@ public final class LocalSearchHints implements IMatcherCapability { | |||
68 | public static LocalSearchHints getDefaultOverriddenBy(QueryEvaluationHint overridingHint){ | 56 | public static LocalSearchHints getDefaultOverriddenBy(QueryEvaluationHint overridingHint){ |
69 | return parse(getDefault().build(overridingHint)); | 57 | return parse(getDefault().build(overridingHint)); |
70 | } | 58 | } |
71 | 59 | ||
72 | /** | 60 | /** |
73 | * Default settings which are considered the most safe, providing a reasonable performance for most of the cases. Assumes the availability of the base indexer. | 61 | * Default settings which are considered the most safe, providing a reasonable performance for most of the cases. Assumes the availability of the base indexer. |
74 | */ | 62 | */ |
75 | public static LocalSearchHints getDefault(){ | 63 | public static LocalSearchHints getDefault(){ |
76 | LocalSearchHints result = new LocalSearchHints(); | 64 | return getDefaultGeneric(); |
77 | result.useBase = USE_BASE_INDEX.getDefaultValue(); | ||
78 | result.rowCount = PLANNER_TABLE_ROW_COUNT.getDefaultValue(); | ||
79 | result.costFunction = PLANNER_COST_FUNCTION.getDefaultValue(); | ||
80 | result.flattenCallPredicate = FLATTEN_CALL_PREDICATE.getDefaultValue(); | ||
81 | result.callDelegationStrategy = CALL_DELEGATION_STRATEGY.getDefaultValue(); | ||
82 | result.adornmentProvider = ADORNMENT_PROVIDER.getDefaultValue(); | ||
83 | result.backendFactory = LocalSearchEMFBackendFactory.INSTANCE; | ||
84 | return result; | ||
85 | } | 65 | } |
86 | 66 | ||
87 | /** | ||
88 | * With this setting, the patterns are flattened before planning. This may cause performance gain in some cases compared to the {@link #getDefault()} settings, | ||
89 | * However this should be used with care for patterns containing calls with several bodies. | ||
90 | */ | ||
91 | public static LocalSearchHints getDefaultFlatten(){ | ||
92 | LocalSearchHints result = new LocalSearchHints(); | ||
93 | result.useBase = true; | ||
94 | result.rowCount = 4; | ||
95 | result.costFunction = new IndexerBasedConstraintCostFunction(); | ||
96 | result.flattenCallPredicate = new DefaultFlattenCallPredicate(); | ||
97 | result.callDelegationStrategy = CALL_DELEGATION_STRATEGY.getDefaultValue(); | ||
98 | result.adornmentProvider = ADORNMENT_PROVIDER.getDefaultValue(); | ||
99 | result.backendFactory = LocalSearchEMFBackendFactory.INSTANCE; | ||
100 | return result; | ||
101 | } | ||
102 | |||
103 | /** | ||
104 | * Settings to be used when the base index is not available. | ||
105 | */ | ||
106 | public static LocalSearchHints getDefaultNoBase(){ | ||
107 | LocalSearchHints result = new LocalSearchHints(); | ||
108 | result.useBase = false; | ||
109 | result.rowCount = 4; | ||
110 | result.costFunction = new VariableBindingBasedCostFunction(); | ||
111 | result.flattenCallPredicate = new NeverFlattenCallPredicate(); | ||
112 | result.callDelegationStrategy = ICallDelegationStrategy.FULL_BACKEND_ADHESION; | ||
113 | result.adornmentProvider = ADORNMENT_PROVIDER.getDefaultValue(); | ||
114 | result.backendFactory = LocalSearchEMFBackendFactory.INSTANCE; | ||
115 | return result; | ||
116 | } | ||
117 | |||
118 | /** | 67 | /** |
119 | * Initializes the generic (not EMF specific) search backend with the default settings | 68 | * Initializes the generic (not EMF specific) search backend with the default settings |
120 | * @since 1.7 | 69 | * @since 1.7 |
@@ -130,7 +79,7 @@ public final class LocalSearchHints implements IMatcherCapability { | |||
130 | result.backendFactory = LocalSearchGenericBackendFactory.INSTANCE; | 79 | result.backendFactory = LocalSearchGenericBackendFactory.INSTANCE; |
131 | return result; | 80 | return result; |
132 | } | 81 | } |
133 | 82 | ||
134 | /** | 83 | /** |
135 | * Initializes the default search backend with hybrid-enabled settings | 84 | * Initializes the default search backend with hybrid-enabled settings |
136 | * @since 2.1 | 85 | * @since 2.1 |
@@ -142,7 +91,7 @@ public final class LocalSearchHints implements IMatcherCapability { | |||
142 | new DontFlattenIncrementalPredicate(), new DontFlattenDisjunctive()); | 91 | new DontFlattenIncrementalPredicate(), new DontFlattenDisjunctive()); |
143 | return result; | 92 | return result; |
144 | } | 93 | } |
145 | 94 | ||
146 | /** | 95 | /** |
147 | * Initializes the generic (not EMF specific) search backend with hybrid-enabled settings | 96 | * Initializes the generic (not EMF specific) search backend with hybrid-enabled settings |
148 | * @since 2.1 | 97 | * @since 2.1 |
@@ -154,10 +103,10 @@ public final class LocalSearchHints implements IMatcherCapability { | |||
154 | new DontFlattenIncrementalPredicate(), new DontFlattenDisjunctive()); | 103 | new DontFlattenIncrementalPredicate(), new DontFlattenDisjunctive()); |
155 | return result; | 104 | return result; |
156 | } | 105 | } |
157 | 106 | ||
158 | public static LocalSearchHints parse(QueryEvaluationHint hint){ | 107 | public static LocalSearchHints parse(QueryEvaluationHint hint){ |
159 | LocalSearchHints result = new LocalSearchHints(); | 108 | LocalSearchHints result = new LocalSearchHints(); |
160 | 109 | ||
161 | result.useBase = USE_BASE_INDEX.getValueOrNull(hint); | 110 | result.useBase = USE_BASE_INDEX.getValueOrNull(hint); |
162 | result.rowCount = PLANNER_TABLE_ROW_COUNT.getValueOrNull(hint); | 111 | result.rowCount = PLANNER_TABLE_ROW_COUNT.getValueOrNull(hint); |
163 | result.flattenCallPredicate = FLATTEN_CALL_PREDICATE.getValueOrNull(hint); | 112 | result.flattenCallPredicate = FLATTEN_CALL_PREDICATE.getValueOrNull(hint); |
@@ -165,15 +114,15 @@ public final class LocalSearchHints implements IMatcherCapability { | |||
165 | result.costFunction = PLANNER_COST_FUNCTION.getValueOrNull(hint); | 114 | result.costFunction = PLANNER_COST_FUNCTION.getValueOrNull(hint); |
166 | result.adornmentProvider = ADORNMENT_PROVIDER.getValueOrNull(hint); | 115 | result.adornmentProvider = ADORNMENT_PROVIDER.getValueOrNull(hint); |
167 | result.traceCollector = normalizationTraceCollector.getValueOrDefault(hint); | 116 | result.traceCollector = normalizationTraceCollector.getValueOrDefault(hint); |
168 | 117 | ||
169 | return result; | 118 | return result; |
170 | } | 119 | } |
171 | 120 | ||
172 | 121 | ||
173 | private Map<QueryHintOption<?>, Object> calculateHintMap() { | 122 | private Map<QueryHintOption<?>, Object> calculateHintMap() { |
174 | Map<QueryHintOption<?>, Object> map = new HashMap<>(); | 123 | Map<QueryHintOption<?>, Object> map = new HashMap<>(); |
175 | if (useBase != null){ | 124 | if (useBase != null){ |
176 | USE_BASE_INDEX.insertOverridingValue(map, useBase); | 125 | USE_BASE_INDEX.insertOverridingValue(map, useBase); |
177 | } | 126 | } |
178 | if (rowCount != null){ | 127 | if (rowCount != null){ |
179 | PLANNER_TABLE_ROW_COUNT.insertOverridingValue(map, rowCount); | 128 | PLANNER_TABLE_ROW_COUNT.insertOverridingValue(map, rowCount); |
@@ -195,43 +144,43 @@ public final class LocalSearchHints implements IMatcherCapability { | |||
195 | } | 144 | } |
196 | return map; | 145 | return map; |
197 | } | 146 | } |
198 | 147 | ||
199 | public QueryEvaluationHint build(){ | 148 | public QueryEvaluationHint build(){ |
200 | Map<QueryHintOption<?>, Object> map = calculateHintMap(); | 149 | Map<QueryHintOption<?>, Object> map = calculateHintMap(); |
201 | return new QueryEvaluationHint(map, backendFactory); | 150 | return new QueryEvaluationHint(map, backendFactory); |
202 | } | 151 | } |
203 | 152 | ||
204 | /** | 153 | /** |
205 | * @since 1.7 | 154 | * @since 1.7 |
206 | */ | 155 | */ |
207 | public QueryEvaluationHint build(QueryEvaluationHint overridingHint) { | 156 | public QueryEvaluationHint build(QueryEvaluationHint overridingHint) { |
208 | if (overridingHint == null) | 157 | if (overridingHint == null) |
209 | return build(); | 158 | return build(); |
210 | 159 | ||
211 | IQueryBackendFactory factory = (overridingHint.getQueryBackendFactory() == null) | 160 | IQueryBackendFactory factory = (overridingHint.getQueryBackendFactory() == null) |
212 | ? this.backendFactory | 161 | ? this.backendFactory |
213 | : overridingHint.getQueryBackendFactory(); | 162 | : overridingHint.getQueryBackendFactory(); |
214 | 163 | ||
215 | Map<QueryHintOption<?>, Object> hints = calculateHintMap(); | 164 | Map<QueryHintOption<?>, Object> hints = calculateHintMap(); |
216 | if (overridingHint.getBackendHintSettings() != null) { | 165 | if (overridingHint.getBackendHintSettings() != null) { |
217 | hints.putAll(overridingHint.getBackendHintSettings()); | 166 | hints.putAll(overridingHint.getBackendHintSettings()); |
218 | } | 167 | } |
219 | 168 | ||
220 | return new QueryEvaluationHint(hints, factory); | 169 | return new QueryEvaluationHint(hints, factory); |
221 | } | 170 | } |
222 | 171 | ||
223 | public boolean isUseBase() { | 172 | public boolean isUseBase() { |
224 | return useBase; | 173 | return useBase; |
225 | } | 174 | } |
226 | 175 | ||
227 | public ICostFunction getCostFunction() { | 176 | public ICostFunction getCostFunction() { |
228 | return costFunction; | 177 | return costFunction; |
229 | } | 178 | } |
230 | 179 | ||
231 | public IFlattenCallPredicate getFlattenCallPredicate() { | 180 | public IFlattenCallPredicate getFlattenCallPredicate() { |
232 | return flattenCallPredicate; | 181 | return flattenCallPredicate; |
233 | } | 182 | } |
234 | 183 | ||
235 | /** | 184 | /** |
236 | * @since 2.1 | 185 | * @since 2.1 |
237 | */ | 186 | */ |
@@ -242,7 +191,7 @@ public final class LocalSearchHints implements IMatcherCapability { | |||
242 | public Integer getRowCount() { | 191 | public Integer getRowCount() { |
243 | return rowCount; | 192 | return rowCount; |
244 | } | 193 | } |
245 | 194 | ||
246 | /** | 195 | /** |
247 | * @since 1.5 | 196 | * @since 1.5 |
248 | */ | 197 | */ |
@@ -256,28 +205,28 @@ public final class LocalSearchHints implements IMatcherCapability { | |||
256 | public IRewriterTraceCollector getTraceCollector() { | 205 | public IRewriterTraceCollector getTraceCollector() { |
257 | return traceCollector == null ? normalizationTraceCollector.getDefaultValue() : traceCollector; | 206 | return traceCollector == null ? normalizationTraceCollector.getDefaultValue() : traceCollector; |
258 | } | 207 | } |
259 | 208 | ||
260 | public LocalSearchHints setUseBase(boolean useBase) { | 209 | public LocalSearchHints setUseBase(boolean useBase) { |
261 | this.useBase = useBase; | 210 | this.useBase = useBase; |
262 | return this; | 211 | return this; |
263 | } | 212 | } |
264 | 213 | ||
265 | public LocalSearchHints setRowCount(int rowCount) { | 214 | public LocalSearchHints setRowCount(int rowCount) { |
266 | this.rowCount = rowCount; | 215 | this.rowCount = rowCount; |
267 | return this; | 216 | return this; |
268 | } | 217 | } |
269 | 218 | ||
270 | public LocalSearchHints setCostFunction(ICostFunction costFunction) { | 219 | public LocalSearchHints setCostFunction(ICostFunction costFunction) { |
271 | this.costFunction = costFunction; | 220 | this.costFunction = costFunction; |
272 | return this; | 221 | return this; |
273 | } | 222 | } |
274 | 223 | ||
275 | public LocalSearchHints setFlattenCallPredicate(IFlattenCallPredicate flattenCallPredicate) { | 224 | public LocalSearchHints setFlattenCallPredicate(IFlattenCallPredicate flattenCallPredicate) { |
276 | this.flattenCallPredicate = flattenCallPredicate; | 225 | this.flattenCallPredicate = flattenCallPredicate; |
277 | return this; | 226 | return this; |
278 | } | 227 | } |
279 | 228 | ||
280 | 229 | ||
281 | /** | 230 | /** |
282 | * @since 2.1 | 231 | * @since 2.1 |
283 | */ | 232 | */ |
@@ -293,7 +242,7 @@ public final class LocalSearchHints implements IMatcherCapability { | |||
293 | this.traceCollector = traceCollector; | 242 | this.traceCollector = traceCollector; |
294 | return this; | 243 | return this; |
295 | } | 244 | } |
296 | 245 | ||
297 | /** | 246 | /** |
298 | * @since 1.5 | 247 | * @since 1.5 |
299 | */ | 248 | */ |
@@ -301,37 +250,37 @@ public final class LocalSearchHints implements IMatcherCapability { | |||
301 | this.adornmentProvider = adornmentProvider; | 250 | this.adornmentProvider = adornmentProvider; |
302 | return this; | 251 | return this; |
303 | } | 252 | } |
304 | 253 | ||
305 | public static LocalSearchHints customizeUseBase(boolean useBase){ | 254 | public static LocalSearchHints customizeUseBase(boolean useBase){ |
306 | return new LocalSearchHints().setUseBase(useBase); | 255 | return new LocalSearchHints().setUseBase(useBase); |
307 | } | 256 | } |
308 | 257 | ||
309 | public static LocalSearchHints customizeRowCount(int rowCount){ | 258 | public static LocalSearchHints customizeRowCount(int rowCount){ |
310 | return new LocalSearchHints().setRowCount(rowCount); | 259 | return new LocalSearchHints().setRowCount(rowCount); |
311 | } | 260 | } |
312 | 261 | ||
313 | public static LocalSearchHints customizeCostFunction(ICostFunction costFunction){ | 262 | public static LocalSearchHints customizeCostFunction(ICostFunction costFunction){ |
314 | return new LocalSearchHints().setCostFunction(costFunction); | 263 | return new LocalSearchHints().setCostFunction(costFunction); |
315 | } | 264 | } |
316 | 265 | ||
317 | public static LocalSearchHints customizeFlattenCallPredicate(IFlattenCallPredicate predicate){ | 266 | public static LocalSearchHints customizeFlattenCallPredicate(IFlattenCallPredicate predicate){ |
318 | return new LocalSearchHints().setFlattenCallPredicate(predicate); | 267 | return new LocalSearchHints().setFlattenCallPredicate(predicate); |
319 | } | 268 | } |
320 | 269 | ||
321 | /** | 270 | /** |
322 | * @since 2.1 | 271 | * @since 2.1 |
323 | */ | 272 | */ |
324 | public static LocalSearchHints customizeCallDelegationStrategy(ICallDelegationStrategy strategy){ | 273 | public static LocalSearchHints customizeCallDelegationStrategy(ICallDelegationStrategy strategy){ |
325 | return new LocalSearchHints().setCallDelegationStrategy(strategy); | 274 | return new LocalSearchHints().setCallDelegationStrategy(strategy); |
326 | } | 275 | } |
327 | 276 | ||
328 | /** | 277 | /** |
329 | * @since 1.5 | 278 | * @since 1.5 |
330 | */ | 279 | */ |
331 | public static LocalSearchHints customizeAdornmentProvider(IAdornmentProvider adornmentProvider){ | 280 | public static LocalSearchHints customizeAdornmentProvider(IAdornmentProvider adornmentProvider){ |
332 | return new LocalSearchHints().setAdornmentProvider(adornmentProvider); | 281 | return new LocalSearchHints().setAdornmentProvider(adornmentProvider); |
333 | } | 282 | } |
334 | 283 | ||
335 | /** | 284 | /** |
336 | * @since 1.6 | 285 | * @since 1.6 |
337 | */ | 286 | */ |
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/matcher/integration/LocalSearchResultProvider.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/matcher/integration/LocalSearchResultProvider.java deleted file mode 100644 index a3017b18..00000000 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/matcher/integration/LocalSearchResultProvider.java +++ /dev/null | |||
@@ -1,56 +0,0 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2015, Marton Bur, Zoltan Ujhelyi, 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 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.localsearch.matcher.integration; | ||
10 | |||
11 | import tools.refinery.viatra.runtime.localsearch.plan.IPlanProvider; | ||
12 | import tools.refinery.viatra.runtime.localsearch.planner.compiler.EMFOperationCompiler; | ||
13 | import tools.refinery.viatra.runtime.localsearch.planner.compiler.IOperationCompiler; | ||
14 | import tools.refinery.viatra.runtime.matchers.ViatraQueryRuntimeException; | ||
15 | import tools.refinery.viatra.runtime.matchers.backend.QueryEvaluationHint; | ||
16 | import tools.refinery.viatra.runtime.matchers.context.IQueryBackendContext; | ||
17 | import tools.refinery.viatra.runtime.matchers.context.IndexingService; | ||
18 | import tools.refinery.viatra.runtime.matchers.psystem.queries.PQuery; | ||
19 | |||
20 | /** | ||
21 | * @author Marton Bur, Zoltan Ujhelyi | ||
22 | * | ||
23 | */ | ||
24 | public class LocalSearchResultProvider extends AbstractLocalSearchResultProvider { | ||
25 | |||
26 | /** | ||
27 | * @throws ViatraQueryRuntimeException | ||
28 | * @since 1.5 | ||
29 | */ | ||
30 | public LocalSearchResultProvider(LocalSearchBackend backend, IQueryBackendContext context, PQuery query, | ||
31 | IPlanProvider planProvider) { | ||
32 | this(backend, context, query, planProvider, null); | ||
33 | } | ||
34 | |||
35 | /** | ||
36 | * @throws ViatraQueryRuntimeException | ||
37 | * @since 1.5 | ||
38 | */ | ||
39 | public LocalSearchResultProvider(LocalSearchBackend backend, IQueryBackendContext context, PQuery query, | ||
40 | IPlanProvider planProvider, QueryEvaluationHint userHints) { | ||
41 | super(backend, context, query, planProvider, userHints); | ||
42 | } | ||
43 | |||
44 | @Override | ||
45 | protected void indexInitializationBeforePlanning() { | ||
46 | super.indexInitializationBeforePlanning(); | ||
47 | |||
48 | indexReferredTypesOfQuery(query, IndexingService.STATISTICS); | ||
49 | } | ||
50 | |||
51 | @Override | ||
52 | protected IOperationCompiler getOperationCompiler(IQueryBackendContext backendContext, | ||
53 | LocalSearchHints configuration) { | ||
54 | return new EMFOperationCompiler(runtimeContext, configuration.isUseBase()); | ||
55 | } | ||
56 | } | ||
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/ContainmentCheck.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/ContainmentCheck.java deleted file mode 100644 index 9dfb16f5..00000000 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/ContainmentCheck.java +++ /dev/null | |||
@@ -1,85 +0,0 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2013, Zoltan Ujhelyi, 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 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.localsearch.operations.check; | ||
10 | |||
11 | import java.util.Arrays; | ||
12 | import java.util.List; | ||
13 | import java.util.function.Function; | ||
14 | |||
15 | import org.eclipse.emf.ecore.EObject; | ||
16 | import org.eclipse.emf.ecore.EStructuralFeature; | ||
17 | import org.eclipse.emf.ecore.util.EcoreUtil; | ||
18 | import tools.refinery.viatra.runtime.localsearch.MatchingFrame; | ||
19 | import tools.refinery.viatra.runtime.localsearch.exceptions.LocalSearchException; | ||
20 | import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext; | ||
21 | import tools.refinery.viatra.runtime.localsearch.operations.CheckOperationExecutor; | ||
22 | import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation; | ||
23 | |||
24 | /** | ||
25 | * A simple operation that checks whether a {@link EStructuralFeature} connects two selected variables. | ||
26 | * @noextend This class is not intended to be subclassed by clients. | ||
27 | */ | ||
28 | public class ContainmentCheck implements ISearchOperation { | ||
29 | |||
30 | private class Executor extends CheckOperationExecutor { | ||
31 | |||
32 | @Override | ||
33 | protected boolean check(MatchingFrame frame, ISearchContext context) { | ||
34 | try { | ||
35 | EObject child = (EObject) frame.getValue(childPosition); | ||
36 | EObject container = (EObject)frame.getValue(containerPosition); | ||
37 | |||
38 | if (transitive) { | ||
39 | return EcoreUtil.isAncestor(container, child); | ||
40 | } else { | ||
41 | return child.eContainer().equals(container); | ||
42 | } | ||
43 | } catch (ClassCastException e) { | ||
44 | throw new LocalSearchException(LocalSearchException.TYPE_ERROR, e); | ||
45 | } | ||
46 | } | ||
47 | |||
48 | @Override | ||
49 | public ISearchOperation getOperation() { | ||
50 | return ContainmentCheck.this; | ||
51 | } | ||
52 | } | ||
53 | |||
54 | int childPosition; | ||
55 | int containerPosition; | ||
56 | private boolean transitive; | ||
57 | |||
58 | public ContainmentCheck(int childPosition, int containerPosition, boolean transitive) { | ||
59 | super(); | ||
60 | this.childPosition = childPosition; | ||
61 | this.containerPosition = containerPosition; | ||
62 | this.transitive = transitive; | ||
63 | } | ||
64 | |||
65 | @Override | ||
66 | public ISearchOperationExecutor createExecutor() { | ||
67 | return new Executor(); | ||
68 | } | ||
69 | |||
70 | @Override | ||
71 | public String toString() { | ||
72 | return toString(Object::toString); | ||
73 | } | ||
74 | |||
75 | @Override | ||
76 | public String toString(Function<Integer, String> variableMapping) { | ||
77 | return "check containment +"+variableMapping.apply(containerPosition)+" <>--> +"+childPosition+(transitive ? " transitively" : " directly"); | ||
78 | } | ||
79 | |||
80 | @Override | ||
81 | public List<Integer> getVariablePositions() { | ||
82 | return Arrays.asList(childPosition, containerPosition); | ||
83 | } | ||
84 | |||
85 | } | ||
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/InstanceOfClassCheck.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/InstanceOfClassCheck.java deleted file mode 100644 index 68d92040..00000000 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/InstanceOfClassCheck.java +++ /dev/null | |||
@@ -1,75 +0,0 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2013, Zoltan Ujhelyi, 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 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.localsearch.operations.check; | ||
10 | |||
11 | import java.util.Arrays; | ||
12 | import java.util.List; | ||
13 | import java.util.Objects; | ||
14 | import java.util.function.Function; | ||
15 | |||
16 | import org.eclipse.emf.ecore.EClass; | ||
17 | import org.eclipse.emf.ecore.EObject; | ||
18 | import tools.refinery.viatra.runtime.localsearch.MatchingFrame; | ||
19 | import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext; | ||
20 | import tools.refinery.viatra.runtime.localsearch.operations.CheckOperationExecutor; | ||
21 | import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation; | ||
22 | |||
23 | /** | ||
24 | * @author Zoltan Ujhelyi | ||
25 | * @noextend This class is not intended to be subclassed by clients. | ||
26 | */ | ||
27 | public class InstanceOfClassCheck implements ISearchOperation { | ||
28 | |||
29 | private class Executor extends CheckOperationExecutor { | ||
30 | |||
31 | @Override | ||
32 | protected boolean check(MatchingFrame frame, ISearchContext context) { | ||
33 | Objects.requireNonNull(frame.getValue(position), () -> String.format("Invalid plan, variable %s unbound", position)); | ||
34 | if (frame.getValue(position) instanceof EObject) { | ||
35 | return clazz.isSuperTypeOf(((EObject) frame.getValue(position)).eClass()); | ||
36 | } | ||
37 | return false; | ||
38 | } | ||
39 | |||
40 | @Override | ||
41 | public ISearchOperation getOperation() { | ||
42 | return InstanceOfClassCheck.this; | ||
43 | } | ||
44 | } | ||
45 | |||
46 | private int position; | ||
47 | private EClass clazz; | ||
48 | |||
49 | public InstanceOfClassCheck(int position, EClass clazz) { | ||
50 | this.position = position; | ||
51 | this.clazz = clazz; | ||
52 | |||
53 | } | ||
54 | |||
55 | @Override | ||
56 | public ISearchOperationExecutor createExecutor() { | ||
57 | return new Executor(); | ||
58 | } | ||
59 | |||
60 | @Override | ||
61 | public String toString() { | ||
62 | return toString(Object::toString); | ||
63 | } | ||
64 | |||
65 | @Override | ||
66 | public String toString(Function<Integer, String> variableMapping) { | ||
67 | return "check "+clazz.getName()+"(+"+ variableMapping.apply(position)+")"; | ||
68 | } | ||
69 | |||
70 | @Override | ||
71 | public List<Integer> getVariablePositions() { | ||
72 | return Arrays.asList(position); | ||
73 | } | ||
74 | |||
75 | } | ||
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/InstanceOfDataTypeCheck.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/InstanceOfDataTypeCheck.java deleted file mode 100644 index 940104a2..00000000 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/InstanceOfDataTypeCheck.java +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2013, Zoltan Ujhelyi, 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 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.localsearch.operations.check; | ||
10 | |||
11 | import java.util.Arrays; | ||
12 | import java.util.List; | ||
13 | import java.util.Objects; | ||
14 | import java.util.function.Function; | ||
15 | |||
16 | import org.eclipse.emf.ecore.EDataType; | ||
17 | import tools.refinery.viatra.runtime.localsearch.MatchingFrame; | ||
18 | import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext; | ||
19 | import tools.refinery.viatra.runtime.localsearch.operations.CheckOperationExecutor; | ||
20 | import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation; | ||
21 | |||
22 | /** | ||
23 | * @author Zoltan Ujhelyi | ||
24 | * @noextend This class is not intended to be subclassed by clients. | ||
25 | */ | ||
26 | public class InstanceOfDataTypeCheck implements ISearchOperation { | ||
27 | |||
28 | private class Executor extends CheckOperationExecutor { | ||
29 | |||
30 | @Override | ||
31 | protected boolean check(MatchingFrame frame, ISearchContext context) { | ||
32 | Objects.requireNonNull(frame.getValue(position), () -> String.format("Invalid plan, variable %s unbound", position)); | ||
33 | return dataType.isInstance(frame.getValue(position)); | ||
34 | } | ||
35 | |||
36 | @Override | ||
37 | public ISearchOperation getOperation() { | ||
38 | return InstanceOfDataTypeCheck.this; | ||
39 | } | ||
40 | } | ||
41 | |||
42 | private int position; | ||
43 | private EDataType dataType; | ||
44 | |||
45 | public InstanceOfDataTypeCheck(int position, EDataType dataType) { | ||
46 | this.position = position; | ||
47 | this.dataType = dataType; | ||
48 | |||
49 | } | ||
50 | |||
51 | @Override | ||
52 | public ISearchOperationExecutor createExecutor() { | ||
53 | return new Executor(); | ||
54 | } | ||
55 | |||
56 | @Override | ||
57 | public String toString() { | ||
58 | return toString(Object::toString); | ||
59 | } | ||
60 | |||
61 | @Override | ||
62 | public String toString(Function<Integer, String> variableMapping) { | ||
63 | return "check "+dataType.getName()+"(+"+variableMapping.apply(position)+")"; | ||
64 | } | ||
65 | |||
66 | @Override | ||
67 | public List<Integer> getVariablePositions() { | ||
68 | return Arrays.asList(position); | ||
69 | } | ||
70 | |||
71 | } | ||
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/InstanceOfJavaClassCheck.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/InstanceOfJavaClassCheck.java deleted file mode 100644 index 1da312a0..00000000 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/InstanceOfJavaClassCheck.java +++ /dev/null | |||
@@ -1,71 +0,0 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2013, Zoltan Ujhelyi, 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 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.localsearch.operations.check; | ||
10 | |||
11 | import java.util.Arrays; | ||
12 | import java.util.List; | ||
13 | import java.util.Objects; | ||
14 | import java.util.function.Function; | ||
15 | |||
16 | import tools.refinery.viatra.runtime.localsearch.MatchingFrame; | ||
17 | import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext; | ||
18 | import tools.refinery.viatra.runtime.localsearch.operations.CheckOperationExecutor; | ||
19 | import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation; | ||
20 | |||
21 | /** | ||
22 | * @author Zoltan Ujhelyi | ||
23 | * @since 1.4 | ||
24 | * @noextend This class is not intended to be subclassed by clients. | ||
25 | */ | ||
26 | public class InstanceOfJavaClassCheck implements ISearchOperation { | ||
27 | |||
28 | private class Executor extends CheckOperationExecutor { | ||
29 | |||
30 | @Override | ||
31 | protected boolean check(MatchingFrame frame, ISearchContext context) { | ||
32 | Objects.requireNonNull(frame.getValue(position), () -> String.format("Invalid plan, variable %s unbound", position)); | ||
33 | return clazz.isInstance(frame.getValue(position)); | ||
34 | } | ||
35 | |||
36 | @Override | ||
37 | public ISearchOperation getOperation() { | ||
38 | return InstanceOfJavaClassCheck.this; | ||
39 | } | ||
40 | } | ||
41 | |||
42 | private int position; | ||
43 | private Class<?> clazz; | ||
44 | |||
45 | public InstanceOfJavaClassCheck(int position, Class<?> clazz) { | ||
46 | this.position = position; | ||
47 | this.clazz = clazz; | ||
48 | |||
49 | } | ||
50 | |||
51 | @Override | ||
52 | public ISearchOperationExecutor createExecutor() { | ||
53 | return new Executor(); | ||
54 | } | ||
55 | |||
56 | @Override | ||
57 | public String toString() { | ||
58 | return toString(Object::toString); | ||
59 | } | ||
60 | |||
61 | @Override | ||
62 | public String toString(Function<Integer, String> variableMapping) { | ||
63 | return "check java "+clazz.getName()+"(+"+variableMapping.apply(position)+")"; | ||
64 | } | ||
65 | |||
66 | @Override | ||
67 | public List<Integer> getVariablePositions() { | ||
68 | return Arrays.asList(position); | ||
69 | } | ||
70 | |||
71 | } | ||
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/StructuralFeatureCheck.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/StructuralFeatureCheck.java deleted file mode 100644 index a3e5bc40..00000000 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/StructuralFeatureCheck.java +++ /dev/null | |||
@@ -1,91 +0,0 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2013, Zoltan Ujhelyi, 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 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.localsearch.operations.check; | ||
10 | |||
11 | import java.util.Arrays; | ||
12 | import java.util.Collection; | ||
13 | import java.util.List; | ||
14 | import java.util.Objects; | ||
15 | import java.util.function.Function; | ||
16 | |||
17 | import org.eclipse.emf.ecore.EObject; | ||
18 | import org.eclipse.emf.ecore.EStructuralFeature; | ||
19 | import tools.refinery.viatra.runtime.localsearch.MatchingFrame; | ||
20 | import tools.refinery.viatra.runtime.localsearch.exceptions.LocalSearchException; | ||
21 | import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext; | ||
22 | import tools.refinery.viatra.runtime.localsearch.operations.CheckOperationExecutor; | ||
23 | import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation; | ||
24 | |||
25 | /** | ||
26 | * A simple operation that checks whether a {@link EStructuralFeature} connects two selected variables. | ||
27 | * @noextend This class is not intended to be subclassed by clients. | ||
28 | */ | ||
29 | public class StructuralFeatureCheck implements ISearchOperation { | ||
30 | |||
31 | private class Executor extends CheckOperationExecutor { | ||
32 | |||
33 | @Override | ||
34 | protected boolean check(MatchingFrame frame, ISearchContext context) { | ||
35 | Objects.requireNonNull(frame.getValue(sourcePosition), () -> String.format("Invalid plan, variable %s unbound", sourcePosition)); | ||
36 | Objects.requireNonNull(frame.getValue(targetPosition), () -> String.format("Invalid plan, variable %s unbound", targetPosition)); | ||
37 | try { | ||
38 | EObject source = (EObject) frame.getValue(sourcePosition); | ||
39 | if(! feature.getEContainingClass().isSuperTypeOf(source.eClass()) ){ | ||
40 | // TODO planner should ensure the proper supertype relation, see bug 500968 | ||
41 | return false; | ||
42 | } | ||
43 | Object target = frame.getValue(targetPosition); | ||
44 | if (feature.isMany()) { | ||
45 | return ((Collection<?>) source.eGet(feature)).contains(target); | ||
46 | } else { | ||
47 | return target.equals(source.eGet(feature)); | ||
48 | } | ||
49 | } catch (ClassCastException e) { | ||
50 | throw new LocalSearchException(LocalSearchException.TYPE_ERROR, e); | ||
51 | } | ||
52 | } | ||
53 | |||
54 | @Override | ||
55 | public ISearchOperation getOperation() { | ||
56 | return StructuralFeatureCheck.this; | ||
57 | } | ||
58 | } | ||
59 | |||
60 | int sourcePosition; | ||
61 | int targetPosition; | ||
62 | EStructuralFeature feature; | ||
63 | |||
64 | public StructuralFeatureCheck(int sourcePosition, int targetPosition, EStructuralFeature feature) { | ||
65 | super(); | ||
66 | this.sourcePosition = sourcePosition; | ||
67 | this.targetPosition = targetPosition; | ||
68 | this.feature = feature; | ||
69 | } | ||
70 | |||
71 | @Override | ||
72 | public ISearchOperationExecutor createExecutor() { | ||
73 | return new Executor(); | ||
74 | } | ||
75 | |||
76 | @Override | ||
77 | public String toString() { | ||
78 | return toString(Object::toString); | ||
79 | } | ||
80 | |||
81 | @Override | ||
82 | public String toString(Function<Integer, String> variableMapping) { | ||
83 | return "check "+feature.getContainerClass().getSimpleName()+"."+feature.getName()+"(+"+variableMapping.apply(sourcePosition)+", +"+variableMapping.apply(targetPosition)+")"; | ||
84 | } | ||
85 | |||
86 | @Override | ||
87 | public List<Integer> getVariablePositions() { | ||
88 | return Arrays.asList(sourcePosition, targetPosition); | ||
89 | } | ||
90 | |||
91 | } | ||
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/nobase/ScopeCheck.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/nobase/ScopeCheck.java deleted file mode 100644 index 06989fdc..00000000 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/nobase/ScopeCheck.java +++ /dev/null | |||
@@ -1,91 +0,0 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2015, Marton Bur, Zoltan Ujhelyi, Akos Horvath, 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 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.localsearch.operations.check.nobase; | ||
10 | |||
11 | import java.util.Arrays; | ||
12 | import java.util.List; | ||
13 | import java.util.Objects; | ||
14 | import java.util.function.Function; | ||
15 | |||
16 | import org.eclipse.emf.ecore.EObject; | ||
17 | import org.eclipse.emf.ecore.util.EcoreUtil; | ||
18 | import tools.refinery.viatra.runtime.base.api.filters.IBaseIndexObjectFilter; | ||
19 | import tools.refinery.viatra.runtime.emf.EMFScope; | ||
20 | import tools.refinery.viatra.runtime.localsearch.MatchingFrame; | ||
21 | import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext; | ||
22 | import tools.refinery.viatra.runtime.localsearch.operations.CheckOperationExecutor; | ||
23 | import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation; | ||
24 | |||
25 | /** | ||
26 | * This operation simply checks if a model element is part of the Query Scope | ||
27 | * | ||
28 | * @author Marton Bur | ||
29 | * | ||
30 | */ | ||
31 | public class ScopeCheck implements ISearchOperation { | ||
32 | private class Executor extends CheckOperationExecutor { | ||
33 | |||
34 | @Override | ||
35 | protected boolean check(MatchingFrame frame, ISearchContext context) { | ||
36 | Objects.requireNonNull(frame.getValue(position), () -> String.format("Invalid plan, variable %d unbound", position)); | ||
37 | Object value = frame.getValue(position); | ||
38 | if(value instanceof EObject){ | ||
39 | EObject eObject = (EObject) value; | ||
40 | IBaseIndexObjectFilter filterConfiguration = scope.getOptions().getObjectFilterConfiguration(); | ||
41 | boolean filtered = false; | ||
42 | if(filterConfiguration != null){ | ||
43 | filtered = filterConfiguration.isFiltered(eObject); | ||
44 | } | ||
45 | if(filtered){ | ||
46 | return false; | ||
47 | } else { | ||
48 | return EcoreUtil.isAncestor(scope.getScopeRoots(), eObject); | ||
49 | } | ||
50 | } else { | ||
51 | return true; | ||
52 | } | ||
53 | } | ||
54 | |||
55 | @Override | ||
56 | public ISearchOperation getOperation() { | ||
57 | return ScopeCheck.this; | ||
58 | } | ||
59 | |||
60 | } | ||
61 | |||
62 | private int position; | ||
63 | private EMFScope scope; | ||
64 | |||
65 | public ScopeCheck(int position, EMFScope scope) { | ||
66 | this.position = position; | ||
67 | this.scope = scope; | ||
68 | |||
69 | } | ||
70 | |||
71 | @Override | ||
72 | public ISearchOperationExecutor createExecutor() { | ||
73 | return new Executor(); | ||
74 | } | ||
75 | |||
76 | @Override | ||
77 | public String toString() { | ||
78 | return toString(Object::toString); | ||
79 | } | ||
80 | |||
81 | |||
82 | @Override | ||
83 | public String toString(Function<Integer, String> variableMapping) { | ||
84 | return "check +"+variableMapping.apply(position) +" in scope "+scope; | ||
85 | } | ||
86 | |||
87 | @Override | ||
88 | public List<Integer> getVariablePositions() { | ||
89 | return Arrays.asList(position); | ||
90 | } | ||
91 | } | ||
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/ExtendToEStructuralFeatureSource.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/ExtendToEStructuralFeatureSource.java deleted file mode 100644 index 04f0a8de..00000000 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/ExtendToEStructuralFeatureSource.java +++ /dev/null | |||
@@ -1,112 +0,0 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2013, Zoltan Ujhelyi, Akos Horvath, 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 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.localsearch.operations.extend; | ||
10 | |||
11 | import java.util.Arrays; | ||
12 | import java.util.Iterator; | ||
13 | import java.util.List; | ||
14 | import java.util.function.Function; | ||
15 | import java.util.stream.StreamSupport; | ||
16 | |||
17 | import org.eclipse.emf.ecore.EObject; | ||
18 | import org.eclipse.emf.ecore.EStructuralFeature; | ||
19 | import tools.refinery.viatra.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
20 | import tools.refinery.viatra.runtime.localsearch.MatchingFrame; | ||
21 | import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext; | ||
22 | import tools.refinery.viatra.runtime.localsearch.operations.IIteratingSearchOperation; | ||
23 | import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation; | ||
24 | import tools.refinery.viatra.runtime.matchers.context.IInputKey; | ||
25 | import tools.refinery.viatra.runtime.matchers.context.IQueryRuntimeContext; | ||
26 | import tools.refinery.viatra.runtime.matchers.tuple.TupleMask; | ||
27 | import tools.refinery.viatra.runtime.matchers.tuple.VolatileMaskedTuple; | ||
28 | |||
29 | /** | ||
30 | * Iterates over all sources of {@link EStructuralFeature} using an {@link IQueryRuntimeContext VIATRA Base indexer}. | ||
31 | * It is assumed that the indexer is initialized for the selected {@link EStructuralFeature}. | ||
32 | * | ||
33 | */ | ||
34 | public class ExtendToEStructuralFeatureSource implements IIteratingSearchOperation { | ||
35 | |||
36 | private class Executor extends SingleValueExtendOperationExecutor<EObject> { | ||
37 | |||
38 | private VolatileMaskedTuple maskedTuple; | ||
39 | |||
40 | public Executor(int position) { | ||
41 | super(position); | ||
42 | this.maskedTuple = new VolatileMaskedTuple(mask); | ||
43 | } | ||
44 | |||
45 | |||
46 | @Override | ||
47 | public Iterator<EObject> getIterator(MatchingFrame frame, ISearchContext context) { | ||
48 | maskedTuple.updateTuple(frame); | ||
49 | Iterable<? extends Object> values = context.getRuntimeContext().enumerateValues(type, indexerMask, maskedTuple); | ||
50 | return StreamSupport.stream(values.spliterator(), false) | ||
51 | .filter(EObject.class::isInstance) | ||
52 | .map(EObject.class::cast) | ||
53 | .iterator(); | ||
54 | } | ||
55 | |||
56 | @Override | ||
57 | public ISearchOperation getOperation() { | ||
58 | return ExtendToEStructuralFeatureSource.this; | ||
59 | } | ||
60 | } | ||
61 | |||
62 | private final int sourcePosition; | ||
63 | private final int targetPosition; | ||
64 | private final EStructuralFeature feature; | ||
65 | private final IInputKey type; | ||
66 | private static final TupleMask indexerMask = TupleMask.fromSelectedIndices(2, new int[] {1}); | ||
67 | private final TupleMask mask; | ||
68 | |||
69 | /** | ||
70 | * @since 1.7 | ||
71 | */ | ||
72 | public ExtendToEStructuralFeatureSource(int sourcePosition, int targetPosition, EStructuralFeature feature, TupleMask mask) { | ||
73 | this.sourcePosition = sourcePosition; | ||
74 | this.targetPosition = targetPosition; | ||
75 | this.feature = feature; | ||
76 | this.mask = mask; | ||
77 | this.type = new EStructuralFeatureInstancesKey(feature); | ||
78 | } | ||
79 | |||
80 | public EStructuralFeature getFeature() { | ||
81 | return feature; | ||
82 | } | ||
83 | |||
84 | @Override | ||
85 | public ISearchOperationExecutor createExecutor() { | ||
86 | return new Executor(sourcePosition); | ||
87 | } | ||
88 | |||
89 | @Override | ||
90 | public String toString() { | ||
91 | return toString(Object::toString); | ||
92 | } | ||
93 | |||
94 | @Override | ||
95 | public String toString(Function<Integer, String> variableMapping) { | ||
96 | return "extend "+feature.getContainerClass().getSimpleName()+"."+feature.getName()+"(-"+variableMapping.apply(sourcePosition)+", +"+variableMapping.apply(targetPosition)+") indexed"; | ||
97 | } | ||
98 | |||
99 | @Override | ||
100 | public List<Integer> getVariablePositions() { | ||
101 | return Arrays.asList(sourcePosition, targetPosition); | ||
102 | } | ||
103 | |||
104 | /** | ||
105 | * @since 1.4 | ||
106 | */ | ||
107 | @Override | ||
108 | public IInputKey getIteratedInputKey() { | ||
109 | return type; | ||
110 | } | ||
111 | |||
112 | } | ||
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/ExtendToEStructuralFeatureTarget.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/ExtendToEStructuralFeatureTarget.java deleted file mode 100644 index 4304fc8d..00000000 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/ExtendToEStructuralFeatureTarget.java +++ /dev/null | |||
@@ -1,102 +0,0 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2013, Zoltan Ujhelyi, Akos Horvath, 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 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.localsearch.operations.extend; | ||
10 | |||
11 | import java.util.Arrays; | ||
12 | import java.util.Collection; | ||
13 | import java.util.Collections; | ||
14 | import java.util.Iterator; | ||
15 | import java.util.List; | ||
16 | import java.util.function.Function; | ||
17 | |||
18 | import org.eclipse.emf.ecore.EObject; | ||
19 | import org.eclipse.emf.ecore.EStructuralFeature; | ||
20 | import tools.refinery.viatra.runtime.localsearch.MatchingFrame; | ||
21 | import tools.refinery.viatra.runtime.localsearch.exceptions.LocalSearchException; | ||
22 | import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext; | ||
23 | import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation; | ||
24 | |||
25 | /** | ||
26 | * Iterates over all sources of {@link EStructuralFeature} | ||
27 | */ | ||
28 | public class ExtendToEStructuralFeatureTarget implements ISearchOperation { | ||
29 | |||
30 | private class Executor extends SingleValueExtendOperationExecutor<Object> { | ||
31 | |||
32 | public Executor(int position) { | ||
33 | super(position); | ||
34 | } | ||
35 | |||
36 | @SuppressWarnings("unchecked") | ||
37 | @Override | ||
38 | public Iterator<?> getIterator(MatchingFrame frame, ISearchContext context) { | ||
39 | try { | ||
40 | final EObject value = (EObject) frame.getValue(sourcePosition); | ||
41 | if(! feature.getEContainingClass().isSuperTypeOf(value.eClass()) ){ | ||
42 | // TODO planner should ensure the proper supertype relation | ||
43 | return Collections.emptyIterator(); | ||
44 | } | ||
45 | final Object featureValue = value.eGet(feature); | ||
46 | if (feature.isMany()) { | ||
47 | if (featureValue != null) { | ||
48 | final Collection<Object> objectCollection = (Collection<Object>) featureValue; | ||
49 | return objectCollection.iterator(); | ||
50 | } else { | ||
51 | return Collections.emptyIterator(); | ||
52 | } | ||
53 | } else { | ||
54 | if (featureValue != null) { | ||
55 | return Collections.singletonList(featureValue).iterator(); | ||
56 | } else { | ||
57 | return Collections.emptyIterator(); | ||
58 | } | ||
59 | } | ||
60 | } catch (ClassCastException e) { | ||
61 | throw new LocalSearchException("Invalid feature source in parameter" + Integer.toString(sourcePosition), e); | ||
62 | } | ||
63 | } | ||
64 | |||
65 | @Override | ||
66 | public ISearchOperation getOperation() { | ||
67 | return ExtendToEStructuralFeatureTarget.this; | ||
68 | } | ||
69 | } | ||
70 | |||
71 | private final int sourcePosition; | ||
72 | private final int targetPosition; | ||
73 | private final EStructuralFeature feature; | ||
74 | |||
75 | public ExtendToEStructuralFeatureTarget(int sourcePosition, int targetPosition, EStructuralFeature feature) { | ||
76 | this.sourcePosition = sourcePosition; | ||
77 | this.targetPosition = targetPosition; | ||
78 | this.feature = feature; | ||
79 | } | ||
80 | |||
81 | @Override | ||
82 | public String toString() { | ||
83 | return toString(Object::toString); | ||
84 | } | ||
85 | |||
86 | @Override | ||
87 | public String toString(Function<Integer, String> variableMapping) { | ||
88 | return "extend "+feature.getEContainingClass().getName()+"."+feature.getName()+"(+"+variableMapping.apply(sourcePosition)+", -"+ variableMapping.apply(targetPosition) +")"; | ||
89 | } | ||
90 | |||
91 | @Override | ||
92 | public ISearchOperationExecutor createExecutor() { | ||
93 | return new Executor(targetPosition); | ||
94 | } | ||
95 | |||
96 | |||
97 | @Override | ||
98 | public List<Integer> getVariablePositions() { | ||
99 | return Arrays.asList(sourcePosition, targetPosition); | ||
100 | } | ||
101 | |||
102 | } | ||
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/IterateOverChildren.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/IterateOverChildren.java deleted file mode 100644 index 10764aea..00000000 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/IterateOverChildren.java +++ /dev/null | |||
@@ -1,90 +0,0 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2013, Zoltan Ujhelyi, Akos Horvath, 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 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.localsearch.operations.extend; | ||
10 | |||
11 | import java.util.Arrays; | ||
12 | import java.util.Iterator; | ||
13 | import java.util.List; | ||
14 | import java.util.function.Function; | ||
15 | |||
16 | import org.eclipse.emf.ecore.EObject; | ||
17 | import tools.refinery.viatra.runtime.localsearch.MatchingFrame; | ||
18 | import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext; | ||
19 | import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation; | ||
20 | import tools.refinery.viatra.runtime.matchers.util.Preconditions; | ||
21 | |||
22 | /** | ||
23 | * Iterates all child elements of a selected EObjects. | ||
24 | * | ||
25 | * @author Zoltan Ujhelyi | ||
26 | * | ||
27 | */ | ||
28 | public class IterateOverChildren implements ISearchOperation { | ||
29 | |||
30 | private class Executor extends SingleValueExtendOperationExecutor<EObject> { | ||
31 | |||
32 | public Executor(int position) { | ||
33 | super(position); | ||
34 | } | ||
35 | |||
36 | @Override | ||
37 | public Iterator<EObject> getIterator(MatchingFrame frame, ISearchContext context) { | ||
38 | Preconditions.checkState(frame.get(sourcePosition) instanceof EObject, "Only children of EObject elements are supported."); | ||
39 | EObject source = (EObject) frame.get(sourcePosition); | ||
40 | if(transitive) { | ||
41 | return source.eAllContents(); | ||
42 | } else { | ||
43 | return source.eContents().iterator(); | ||
44 | } | ||
45 | } | ||
46 | |||
47 | @Override | ||
48 | public ISearchOperation getOperation() { | ||
49 | return IterateOverChildren.this; | ||
50 | } | ||
51 | } | ||
52 | |||
53 | private final int position; | ||
54 | private int sourcePosition; | ||
55 | private final boolean transitive; | ||
56 | |||
57 | /** | ||
58 | * | ||
59 | * @param position the position of the variable storing the child elements | ||
60 | * @param sourcePosition the position of the variable storing the parent root; must be bound | ||
61 | * @param transitive if true, child elements are iterated over transitively | ||
62 | */ | ||
63 | public IterateOverChildren(int position, int sourcePosition, boolean transitive) { | ||
64 | this.position = position; | ||
65 | this.sourcePosition = sourcePosition; | ||
66 | this.transitive = transitive; | ||
67 | } | ||
68 | |||
69 | @Override | ||
70 | public String toString() { | ||
71 | return toString(Object::toString); | ||
72 | } | ||
73 | |||
74 | @Override | ||
75 | public String toString(Function<Integer, String> variableMapping) { | ||
76 | return "extend containment +"+variableMapping.apply(sourcePosition)+" <>--> -"+variableMapping.apply(position)+(transitive ? " transitively" : " directly"); | ||
77 | } | ||
78 | |||
79 | @Override | ||
80 | public ISearchOperationExecutor createExecutor() { | ||
81 | return new Executor(position); | ||
82 | } | ||
83 | |||
84 | |||
85 | @Override | ||
86 | public List<Integer> getVariablePositions() { | ||
87 | return Arrays.asList(position, sourcePosition); | ||
88 | } | ||
89 | |||
90 | } \ No newline at end of file | ||
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/IterateOverContainers.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/IterateOverContainers.java deleted file mode 100644 index df7e18c9..00000000 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/IterateOverContainers.java +++ /dev/null | |||
@@ -1,126 +0,0 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2013, Zoltan Ujhelyi, Akos Horvath, 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 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.localsearch.operations.extend; | ||
10 | |||
11 | import java.util.Arrays; | ||
12 | import java.util.Collections; | ||
13 | import java.util.Iterator; | ||
14 | import java.util.List; | ||
15 | import java.util.NoSuchElementException; | ||
16 | import java.util.function.Function; | ||
17 | |||
18 | import org.eclipse.emf.ecore.EObject; | ||
19 | import tools.refinery.viatra.runtime.localsearch.MatchingFrame; | ||
20 | import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext; | ||
21 | import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation; | ||
22 | import tools.refinery.viatra.runtime.matchers.util.Preconditions; | ||
23 | |||
24 | /** | ||
25 | * Iterates all child elements of a selected EObjects. | ||
26 | * | ||
27 | * @author Zoltan Ujhelyi | ||
28 | * | ||
29 | */ | ||
30 | public class IterateOverContainers implements ISearchOperation { | ||
31 | |||
32 | /** | ||
33 | * A helper iterator for transitively traversing a parent of an object | ||
34 | */ | ||
35 | private static final class ParentIterator implements Iterator<EObject> { | ||
36 | private EObject current; | ||
37 | |||
38 | public ParentIterator(EObject source) { | ||
39 | this.current = source; | ||
40 | } | ||
41 | |||
42 | @Override | ||
43 | public void remove() { | ||
44 | throw new UnsupportedOperationException(); | ||
45 | } | ||
46 | |||
47 | @Override | ||
48 | public EObject next() { | ||
49 | EObject newObject = current.eContainer(); | ||
50 | if (newObject == null) { | ||
51 | throw new NoSuchElementException(String.format("No more parents available for EObject %s", current)); | ||
52 | } | ||
53 | current = newObject; | ||
54 | return current; | ||
55 | } | ||
56 | |||
57 | @Override | ||
58 | public boolean hasNext() { | ||
59 | return current.eContainer() != null; | ||
60 | } | ||
61 | } | ||
62 | |||
63 | private class Executor extends SingleValueExtendOperationExecutor<EObject> { | ||
64 | |||
65 | public Executor(int position) { | ||
66 | super(position); | ||
67 | } | ||
68 | |||
69 | @Override | ||
70 | public Iterator<EObject> getIterator(MatchingFrame frame, ISearchContext context) { | ||
71 | Preconditions.checkState(frame.get(sourcePosition) instanceof EObject, "Only children of EObject elements are supported."); | ||
72 | EObject source = (EObject) frame.get(sourcePosition); | ||
73 | EObject container = source.eContainer(); | ||
74 | if (container == null) { | ||
75 | return Collections.emptyIterator(); | ||
76 | } else if (transitive) { | ||
77 | return new ParentIterator(source); | ||
78 | } else { | ||
79 | return Collections.singleton(container).iterator(); | ||
80 | } | ||
81 | } | ||
82 | |||
83 | @Override | ||
84 | public ISearchOperation getOperation() { | ||
85 | return IterateOverContainers.this; | ||
86 | } | ||
87 | } | ||
88 | |||
89 | private final int sourcePosition; | ||
90 | private final int containerPosition; | ||
91 | private final boolean transitive; | ||
92 | |||
93 | /** | ||
94 | * | ||
95 | * @param containerPosition the position of the variable storing the found parent elements | ||
96 | * @param sourcePosition the position of the variable storing the selected element; must be bound | ||
97 | * @param transitive if false, only the direct container is returned; otherwise all containers | ||
98 | */ | ||
99 | public IterateOverContainers(int containerPosition, int sourcePosition, boolean transitive) { | ||
100 | this.containerPosition = containerPosition; | ||
101 | this.sourcePosition = sourcePosition; | ||
102 | this.transitive = transitive; | ||
103 | } | ||
104 | |||
105 | |||
106 | @Override | ||
107 | public ISearchOperationExecutor createExecutor() { | ||
108 | return new Executor(containerPosition); | ||
109 | } | ||
110 | |||
111 | @Override | ||
112 | public String toString() { | ||
113 | return toString(Object::toString); | ||
114 | } | ||
115 | |||
116 | @Override | ||
117 | public String toString(Function<Integer, String> variableMapping) { | ||
118 | return "extend containment -"+variableMapping.apply(sourcePosition)+" <>--> +"+variableMapping.apply(containerPosition)+(transitive ? " transitively" : " directly"); | ||
119 | } | ||
120 | |||
121 | @Override | ||
122 | public List<Integer> getVariablePositions() { | ||
123 | return Arrays.asList(containerPosition, sourcePosition); | ||
124 | } | ||
125 | |||
126 | } | ||
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/IterateOverEClassInstances.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/IterateOverEClassInstances.java deleted file mode 100644 index 333ed1db..00000000 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/IterateOverEClassInstances.java +++ /dev/null | |||
@@ -1,97 +0,0 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2013, Zoltan Ujhelyi, Akos Horvath, 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 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.localsearch.operations.extend; | ||
10 | |||
11 | import java.util.Collections; | ||
12 | import java.util.Iterator; | ||
13 | import java.util.List; | ||
14 | import java.util.function.Function; | ||
15 | |||
16 | import org.eclipse.emf.ecore.EClass; | ||
17 | import tools.refinery.viatra.runtime.emf.types.EClassTransitiveInstancesKey; | ||
18 | import tools.refinery.viatra.runtime.localsearch.MatchingFrame; | ||
19 | import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext; | ||
20 | import tools.refinery.viatra.runtime.localsearch.operations.IIteratingSearchOperation; | ||
21 | import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation; | ||
22 | import tools.refinery.viatra.runtime.matchers.context.IInputKey; | ||
23 | import tools.refinery.viatra.runtime.matchers.context.IQueryRuntimeContext; | ||
24 | import tools.refinery.viatra.runtime.matchers.tuple.TupleMask; | ||
25 | import tools.refinery.viatra.runtime.matchers.tuple.Tuples; | ||
26 | |||
27 | /** | ||
28 | * Iterates all available {@link EClass} instances using an {@link IQueryRuntimeContext VIATRA Base indexer}. It is | ||
29 | * assumed that the base indexer has been registered for the selected type. | ||
30 | * | ||
31 | * @author Zoltan Ujhelyi | ||
32 | * | ||
33 | */ | ||
34 | public class IterateOverEClassInstances implements IIteratingSearchOperation { | ||
35 | |||
36 | private class Executor extends SingleValueExtendOperationExecutor<Object> { | ||
37 | |||
38 | public Executor(int position) { | ||
39 | super(position); | ||
40 | } | ||
41 | |||
42 | @Override | ||
43 | public Iterator<? extends Object> getIterator(MatchingFrame frame, ISearchContext context) { | ||
44 | return context.getRuntimeContext().enumerateValues(type, indexerMask, Tuples.staticArityFlatTupleOf()).iterator(); | ||
45 | } | ||
46 | |||
47 | @Override | ||
48 | public ISearchOperation getOperation() { | ||
49 | return IterateOverEClassInstances.this; | ||
50 | } | ||
51 | } | ||
52 | |||
53 | private final EClass clazz; | ||
54 | private final EClassTransitiveInstancesKey type; | ||
55 | private static final TupleMask indexerMask = TupleMask.empty(1); | ||
56 | private final int position; | ||
57 | |||
58 | public IterateOverEClassInstances(int position, EClass clazz) { | ||
59 | this.position = position; | ||
60 | this.clazz = clazz; | ||
61 | type = new EClassTransitiveInstancesKey(clazz); | ||
62 | } | ||
63 | |||
64 | public EClass getClazz() { | ||
65 | return clazz; | ||
66 | } | ||
67 | |||
68 | |||
69 | @Override | ||
70 | public ISearchOperationExecutor createExecutor() { | ||
71 | return new Executor(position); | ||
72 | } | ||
73 | |||
74 | @Override | ||
75 | public String toString() { | ||
76 | return toString(Object::toString); | ||
77 | } | ||
78 | |||
79 | @Override | ||
80 | public String toString(Function<Integer, String> variableMapping) { | ||
81 | return "extend "+clazz.getName()+"(-"+ variableMapping.apply(position)+") indexed"; | ||
82 | } | ||
83 | |||
84 | @Override | ||
85 | public List<Integer> getVariablePositions() { | ||
86 | return Collections.singletonList(position); | ||
87 | } | ||
88 | |||
89 | /** | ||
90 | * @since 1.4 | ||
91 | */ | ||
92 | @Override | ||
93 | public IInputKey getIteratedInputKey() { | ||
94 | return type; | ||
95 | } | ||
96 | |||
97 | } | ||
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/IterateOverEDatatypeInstances.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/IterateOverEDatatypeInstances.java deleted file mode 100644 index 248a3d27..00000000 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/IterateOverEDatatypeInstances.java +++ /dev/null | |||
@@ -1,96 +0,0 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2013, Zoltan Ujhelyi, Akos Horvath, 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 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.localsearch.operations.extend; | ||
10 | |||
11 | import java.util.Collections; | ||
12 | import java.util.Iterator; | ||
13 | import java.util.List; | ||
14 | import java.util.function.Function; | ||
15 | |||
16 | import org.eclipse.emf.ecore.EDataType; | ||
17 | import tools.refinery.viatra.runtime.emf.types.EDataTypeInSlotsKey; | ||
18 | import tools.refinery.viatra.runtime.localsearch.MatchingFrame; | ||
19 | import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext; | ||
20 | import tools.refinery.viatra.runtime.localsearch.operations.IIteratingSearchOperation; | ||
21 | import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation; | ||
22 | import tools.refinery.viatra.runtime.matchers.context.IInputKey; | ||
23 | import tools.refinery.viatra.runtime.matchers.context.IQueryRuntimeContext; | ||
24 | import tools.refinery.viatra.runtime.matchers.tuple.TupleMask; | ||
25 | import tools.refinery.viatra.runtime.matchers.tuple.Tuples; | ||
26 | |||
27 | |||
28 | /** | ||
29 | * Iterates over all {@link EDataType} instances using an {@link IQueryRuntimeContext VIATRA Base indexer}. It is | ||
30 | * assumed that the indexer is initialized for the selected {@link EDataType}. | ||
31 | * | ||
32 | */ | ||
33 | public class IterateOverEDatatypeInstances implements IIteratingSearchOperation { | ||
34 | |||
35 | private class Executor extends SingleValueExtendOperationExecutor<Object> { | ||
36 | |||
37 | public Executor(int position) { | ||
38 | super(position); | ||
39 | } | ||
40 | |||
41 | @Override | ||
42 | public Iterator<? extends Object> getIterator(MatchingFrame frame, ISearchContext context) { | ||
43 | return context.getRuntimeContext().enumerateValues(type, indexerMask, Tuples.staticArityFlatTupleOf()).iterator(); | ||
44 | } | ||
45 | |||
46 | @Override | ||
47 | public ISearchOperation getOperation() { | ||
48 | return IterateOverEDatatypeInstances.this; | ||
49 | } | ||
50 | } | ||
51 | |||
52 | private final EDataType dataType; | ||
53 | private final EDataTypeInSlotsKey type; | ||
54 | private static final TupleMask indexerMask = TupleMask.empty(1); | ||
55 | private final int position; | ||
56 | |||
57 | public IterateOverEDatatypeInstances(int position, EDataType dataType) { | ||
58 | this.position = position; | ||
59 | this.dataType = dataType; | ||
60 | type = new EDataTypeInSlotsKey(dataType); | ||
61 | } | ||
62 | |||
63 | public EDataType getDataType() { | ||
64 | return dataType; | ||
65 | } | ||
66 | |||
67 | @Override | ||
68 | public ISearchOperationExecutor createExecutor() { | ||
69 | return new Executor(position); | ||
70 | } | ||
71 | |||
72 | @Override | ||
73 | public String toString() { | ||
74 | return toString(Object::toString); | ||
75 | } | ||
76 | |||
77 | @Override | ||
78 | public String toString(Function<Integer, String> variableMapping) { | ||
79 | return "extend "+dataType.getName()+"(-"+variableMapping.apply(position)+") indexed"; | ||
80 | } | ||
81 | |||
82 | @Override | ||
83 | public List<Integer> getVariablePositions() { | ||
84 | return Collections.singletonList(position); | ||
85 | } | ||
86 | |||
87 | /** | ||
88 | * @since 1.4 | ||
89 | */ | ||
90 | @Override | ||
91 | public IInputKey getIteratedInputKey() { | ||
92 | return type; | ||
93 | } | ||
94 | |||
95 | |||
96 | } | ||
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/IterateOverEStructuralFeatureInstances.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/IterateOverEStructuralFeatureInstances.java deleted file mode 100644 index 961939fa..00000000 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/IterateOverEStructuralFeatureInstances.java +++ /dev/null | |||
@@ -1,115 +0,0 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2013, Zoltan Ujhelyi, Akos Horvath, 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 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.localsearch.operations.extend; | ||
10 | |||
11 | import java.util.Arrays; | ||
12 | import java.util.Iterator; | ||
13 | import java.util.List; | ||
14 | import java.util.function.Function; | ||
15 | |||
16 | import org.eclipse.emf.ecore.EStructuralFeature; | ||
17 | import tools.refinery.viatra.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
18 | import tools.refinery.viatra.runtime.localsearch.MatchingFrame; | ||
19 | import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext; | ||
20 | import tools.refinery.viatra.runtime.localsearch.operations.IIteratingSearchOperation; | ||
21 | import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation; | ||
22 | import tools.refinery.viatra.runtime.matchers.context.IInputKey; | ||
23 | import tools.refinery.viatra.runtime.matchers.context.IQueryRuntimeContext; | ||
24 | import tools.refinery.viatra.runtime.matchers.tuple.Tuple; | ||
25 | import tools.refinery.viatra.runtime.matchers.tuple.TupleMask; | ||
26 | import tools.refinery.viatra.runtime.matchers.tuple.Tuples; | ||
27 | |||
28 | /** | ||
29 | * Iterates all available {@link EStructuralFeature} elements using an {@link IQueryRuntimeContext VIATRA Base | ||
30 | * indexer}. It is assumed that the base indexer has been registered for the selected reference type. | ||
31 | * | ||
32 | */ | ||
33 | public class IterateOverEStructuralFeatureInstances implements IIteratingSearchOperation{ | ||
34 | |||
35 | private class Executor implements ISearchOperationExecutor { | ||
36 | private Iterator<Tuple> it; | ||
37 | |||
38 | @Override | ||
39 | public void onBacktrack(MatchingFrame frame, ISearchContext context) { | ||
40 | frame.setValue(sourcePosition, null); | ||
41 | frame.setValue(targetPosition, null); | ||
42 | it = null; | ||
43 | } | ||
44 | |||
45 | @Override | ||
46 | public void onInitialize(MatchingFrame frame, ISearchContext context) { | ||
47 | Iterable<Tuple> tuples = context.getRuntimeContext().enumerateTuples(type, indexerMask, Tuples.staticArityFlatTupleOf()); | ||
48 | |||
49 | it = tuples.iterator(); | ||
50 | } | ||
51 | |||
52 | @Override | ||
53 | public boolean execute(MatchingFrame frame, ISearchContext context) { | ||
54 | if (it.hasNext()) { | ||
55 | final Tuple next = it.next(); | ||
56 | frame.setValue(sourcePosition, next.get(0)); | ||
57 | frame.setValue(targetPosition, next.get(1)); | ||
58 | return true; | ||
59 | } else { | ||
60 | return false; | ||
61 | } | ||
62 | } | ||
63 | |||
64 | @Override | ||
65 | public ISearchOperation getOperation() { | ||
66 | return IterateOverEStructuralFeatureInstances.this; | ||
67 | } | ||
68 | } | ||
69 | |||
70 | private final EStructuralFeature feature; | ||
71 | private final int sourcePosition; | ||
72 | private final int targetPosition; | ||
73 | private final EStructuralFeatureInstancesKey type; | ||
74 | private static final TupleMask indexerMask = TupleMask.empty(2); | ||
75 | |||
76 | public IterateOverEStructuralFeatureInstances(int sourcePosition, int targetPosition, EStructuralFeature feature) { | ||
77 | this.sourcePosition = sourcePosition; | ||
78 | this.targetPosition = targetPosition; | ||
79 | this.feature = feature; | ||
80 | type = new EStructuralFeatureInstancesKey(feature); | ||
81 | } | ||
82 | |||
83 | public EStructuralFeature getFeature() { | ||
84 | return feature; | ||
85 | } | ||
86 | |||
87 | @Override | ||
88 | public ISearchOperationExecutor createExecutor() { | ||
89 | return new Executor(); | ||
90 | } | ||
91 | |||
92 | @Override | ||
93 | public String toString() { | ||
94 | return toString(Object::toString); | ||
95 | } | ||
96 | |||
97 | @Override | ||
98 | public String toString(Function<Integer, String> variableMapping) { | ||
99 | return "extend "+feature.getContainerClass().getSimpleName()+"."+feature.getName()+"(-"+variableMapping.apply(sourcePosition)+", -"+variableMapping.apply(targetPosition)+") indexed"; | ||
100 | } | ||
101 | |||
102 | @Override | ||
103 | public List<Integer> getVariablePositions() { | ||
104 | return Arrays.asList(sourcePosition, targetPosition); | ||
105 | } | ||
106 | |||
107 | /** | ||
108 | * @since 1.4 | ||
109 | */ | ||
110 | @Override | ||
111 | public IInputKey getIteratedInputKey() { | ||
112 | return type; | ||
113 | } | ||
114 | |||
115 | } | ||
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/nobase/AbstractIteratingExtendOperationExecutor.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/nobase/AbstractIteratingExtendOperationExecutor.java deleted file mode 100644 index 954d4c88..00000000 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/nobase/AbstractIteratingExtendOperationExecutor.java +++ /dev/null | |||
@@ -1,54 +0,0 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2016, Grill Balázs, 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 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.localsearch.operations.extend.nobase; | ||
10 | |||
11 | import java.util.Collections; | ||
12 | import java.util.Spliterator; | ||
13 | import java.util.Spliterators; | ||
14 | import java.util.stream.Stream; | ||
15 | import java.util.stream.StreamSupport; | ||
16 | |||
17 | import org.eclipse.emf.common.notify.Notifier; | ||
18 | import org.eclipse.emf.ecore.EObject; | ||
19 | import org.eclipse.emf.ecore.resource.Resource; | ||
20 | import org.eclipse.emf.ecore.resource.ResourceSet; | ||
21 | import tools.refinery.viatra.runtime.emf.EMFScope; | ||
22 | import tools.refinery.viatra.runtime.localsearch.operations.extend.SingleValueExtendOperationExecutor; | ||
23 | |||
24 | /** | ||
25 | * This abstract class provides a utility method for extenders to iterate over the given scope. | ||
26 | * | ||
27 | * @author Grill Balázs | ||
28 | * @noextend This class is not intended to be subclassed by clients. | ||
29 | * | ||
30 | */ | ||
31 | abstract class AbstractIteratingExtendOperationExecutor<T> extends SingleValueExtendOperationExecutor<T> { | ||
32 | |||
33 | private final EMFScope scope; | ||
34 | |||
35 | public AbstractIteratingExtendOperationExecutor(int position, EMFScope scope) { | ||
36 | super(position); | ||
37 | this.scope = scope; | ||
38 | } | ||
39 | |||
40 | protected Stream<Notifier> getModelContents() { | ||
41 | return scope.getScopeRoots().stream().map(input -> { | ||
42 | if (input instanceof ResourceSet) { | ||
43 | return ((ResourceSet) input).getAllContents(); | ||
44 | } else if (input instanceof Resource) { | ||
45 | return ((Resource) input).getAllContents(); | ||
46 | } else if (input instanceof EObject) { | ||
47 | return ((EObject) input).eAllContents(); | ||
48 | } | ||
49 | return Collections.<Notifier> emptyIterator(); | ||
50 | }).map(i -> StreamSupport.stream(Spliterators.spliteratorUnknownSize(i, Spliterator.ORDERED), false)) | ||
51 | .flatMap(i -> i); | ||
52 | } | ||
53 | |||
54 | } | ||
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/nobase/ExtendToEStructuralFeatureSource.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/nobase/ExtendToEStructuralFeatureSource.java deleted file mode 100644 index fc79640b..00000000 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/nobase/ExtendToEStructuralFeatureSource.java +++ /dev/null | |||
@@ -1,118 +0,0 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2015, Marton Bur, Zoltan Ujhelyi, Akos Horvath, 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 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.localsearch.operations.extend.nobase; | ||
10 | |||
11 | import java.util.Arrays; | ||
12 | import java.util.Collection; | ||
13 | import java.util.Collections; | ||
14 | import java.util.Iterator; | ||
15 | import java.util.List; | ||
16 | import java.util.function.Function; | ||
17 | |||
18 | import org.eclipse.emf.ecore.EObject; | ||
19 | import org.eclipse.emf.ecore.EReference; | ||
20 | import org.eclipse.emf.ecore.EStructuralFeature; | ||
21 | import tools.refinery.viatra.runtime.base.api.NavigationHelper; | ||
22 | import tools.refinery.viatra.runtime.localsearch.MatchingFrame; | ||
23 | import tools.refinery.viatra.runtime.localsearch.exceptions.LocalSearchException; | ||
24 | import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext; | ||
25 | import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation; | ||
26 | import tools.refinery.viatra.runtime.localsearch.operations.extend.SingleValueExtendOperationExecutor; | ||
27 | |||
28 | /** | ||
29 | * Iterates over all sources of {@link EStructuralFeature} using an {@link NavigationHelper VIATRA Base indexer}. | ||
30 | * It is assumed that the indexer is initialized for the selected {@link EStructuralFeature}. | ||
31 | * | ||
32 | */ | ||
33 | public class ExtendToEStructuralFeatureSource implements ISearchOperation { | ||
34 | |||
35 | private class Executor extends SingleValueExtendOperationExecutor<Object> { | ||
36 | |||
37 | private Executor() { | ||
38 | super(sourcePosition); | ||
39 | } | ||
40 | |||
41 | @SuppressWarnings("unchecked") | ||
42 | @Override | ||
43 | public Iterator<?> getIterator(MatchingFrame frame, ISearchContext context) { | ||
44 | if(!(feature instanceof EReference)){ | ||
45 | throw new LocalSearchException("Without base index, inverse navigation only possible along " | ||
46 | + "EReferences with defined EOpposite."); | ||
47 | } | ||
48 | EReference oppositeFeature = ((EReference)feature).getEOpposite(); | ||
49 | if(oppositeFeature == null){ | ||
50 | throw new LocalSearchException("Feature has no EOpposite, so cannot do inverse navigation " + feature.toString()); | ||
51 | } | ||
52 | try { | ||
53 | final EObject value = (EObject) frame.getValue(targetPosition); | ||
54 | if(! oppositeFeature.getEContainingClass().isSuperTypeOf(value.eClass()) ){ | ||
55 | // TODO planner should ensure the proper supertype relation | ||
56 | return Collections.emptyIterator(); | ||
57 | } | ||
58 | final Object featureValue = value.eGet(oppositeFeature); | ||
59 | if (oppositeFeature.isMany()) { | ||
60 | if (featureValue != null) { | ||
61 | final Collection<Object> objectCollection = (Collection<Object>) featureValue; | ||
62 | return objectCollection.iterator(); | ||
63 | } else { | ||
64 | return Collections.emptyIterator(); | ||
65 | } | ||
66 | } else { | ||
67 | if (featureValue != null) { | ||
68 | return Collections.singleton(featureValue).iterator(); | ||
69 | } else { | ||
70 | return Collections.emptyIterator(); | ||
71 | } | ||
72 | } | ||
73 | } catch (ClassCastException e) { | ||
74 | throw new LocalSearchException("Invalid feature target in parameter" + Integer.toString(targetPosition), e); | ||
75 | } | ||
76 | } | ||
77 | |||
78 | @Override | ||
79 | public ISearchOperation getOperation() { | ||
80 | return ExtendToEStructuralFeatureSource.this; | ||
81 | } | ||
82 | } | ||
83 | |||
84 | private int targetPosition; | ||
85 | private EStructuralFeature feature; | ||
86 | private int sourcePosition; | ||
87 | |||
88 | public ExtendToEStructuralFeatureSource(int sourcePosition, int targetPosition, EStructuralFeature feature) { | ||
89 | this.sourcePosition = sourcePosition; | ||
90 | this.targetPosition = targetPosition; | ||
91 | this.feature = feature; | ||
92 | } | ||
93 | |||
94 | public EStructuralFeature getFeature() { | ||
95 | return feature; | ||
96 | } | ||
97 | |||
98 | @Override | ||
99 | public ISearchOperationExecutor createExecutor() { | ||
100 | return new Executor(); | ||
101 | } | ||
102 | |||
103 | @Override | ||
104 | public String toString() { | ||
105 | return toString(Object::toString); | ||
106 | } | ||
107 | |||
108 | @Override | ||
109 | public String toString(Function<Integer, String> variableMapping) { | ||
110 | return "extend "+feature.getContainerClass().getSimpleName()+"."+feature.getName()+"(-"+variableMapping.apply(sourcePosition)+", +"+variableMapping.apply(targetPosition)+") iterating"; | ||
111 | } | ||
112 | |||
113 | @Override | ||
114 | public List<Integer> getVariablePositions() { | ||
115 | return Arrays.asList(sourcePosition, targetPosition); | ||
116 | } | ||
117 | |||
118 | } | ||
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/nobase/IterateOverEClassInstances.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/nobase/IterateOverEClassInstances.java deleted file mode 100644 index 0a4c46ec..00000000 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/nobase/IterateOverEClassInstances.java +++ /dev/null | |||
@@ -1,93 +0,0 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2015, Marton Bur, Zoltan Ujhelyi, Akos Horvath, 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 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.localsearch.operations.extend.nobase; | ||
10 | |||
11 | import java.util.Collections; | ||
12 | import java.util.Iterator; | ||
13 | import java.util.List; | ||
14 | import java.util.function.Function; | ||
15 | |||
16 | import org.eclipse.emf.common.notify.Notifier; | ||
17 | import org.eclipse.emf.ecore.EClass; | ||
18 | import tools.refinery.viatra.runtime.base.api.NavigationHelper; | ||
19 | import tools.refinery.viatra.runtime.emf.EMFScope; | ||
20 | import tools.refinery.viatra.runtime.emf.types.EClassTransitiveInstancesKey; | ||
21 | import tools.refinery.viatra.runtime.localsearch.MatchingFrame; | ||
22 | import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext; | ||
23 | import tools.refinery.viatra.runtime.localsearch.operations.IIteratingSearchOperation; | ||
24 | import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation; | ||
25 | import tools.refinery.viatra.runtime.matchers.context.IInputKey; | ||
26 | |||
27 | /** | ||
28 | * Iterates all available {@link EClass} instances without using an {@link NavigationHelper VIATRA Base indexer}. | ||
29 | * | ||
30 | * @author Zoltan Ujhelyi | ||
31 | */ | ||
32 | public class IterateOverEClassInstances implements IIteratingSearchOperation { | ||
33 | |||
34 | private class Executor extends AbstractIteratingExtendOperationExecutor<Notifier> { | ||
35 | |||
36 | public Executor(int position, EMFScope scope) { | ||
37 | super(position, scope); | ||
38 | } | ||
39 | |||
40 | @Override | ||
41 | public Iterator<? extends Notifier> getIterator(MatchingFrame frame, ISearchContext context) { | ||
42 | return getModelContents().filter(clazz::isInstance).iterator(); | ||
43 | } | ||
44 | |||
45 | @Override | ||
46 | public ISearchOperation getOperation() { | ||
47 | return IterateOverEClassInstances.this; | ||
48 | } | ||
49 | } | ||
50 | |||
51 | private final int position; | ||
52 | private final EClass clazz; | ||
53 | private final EMFScope scope; | ||
54 | |||
55 | public IterateOverEClassInstances(int position, EClass clazz, EMFScope scope) { | ||
56 | this.position = position; | ||
57 | this.clazz = clazz; | ||
58 | this.scope = scope; | ||
59 | } | ||
60 | |||
61 | public EClass getClazz() { | ||
62 | return clazz; | ||
63 | } | ||
64 | |||
65 | @Override | ||
66 | public ISearchOperationExecutor createExecutor() { | ||
67 | return new Executor(position, scope); | ||
68 | } | ||
69 | |||
70 | @Override | ||
71 | public String toString() { | ||
72 | return toString(Object::toString); | ||
73 | } | ||
74 | |||
75 | @Override | ||
76 | public String toString(Function<Integer, String> variableMapping) { | ||
77 | return "extend "+clazz.getName()+"(-"+ variableMapping.apply(position)+") iterating"; | ||
78 | } | ||
79 | |||
80 | @Override | ||
81 | public List<Integer> getVariablePositions() { | ||
82 | return Collections.singletonList(position); | ||
83 | } | ||
84 | |||
85 | /** | ||
86 | * @since 1.4 | ||
87 | */ | ||
88 | @Override | ||
89 | public IInputKey getIteratedInputKey() { | ||
90 | return new EClassTransitiveInstancesKey(clazz); | ||
91 | } | ||
92 | |||
93 | } | ||
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/nobase/IterateOverEDatatypeInstances.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/nobase/IterateOverEDatatypeInstances.java deleted file mode 100644 index 999e0a48..00000000 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/nobase/IterateOverEDatatypeInstances.java +++ /dev/null | |||
@@ -1,123 +0,0 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2015, Marton Bur, Zoltan Ujhelyi, Akos Horvath, 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 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.localsearch.operations.extend.nobase; | ||
10 | |||
11 | import java.util.Collections; | ||
12 | import java.util.Iterator; | ||
13 | import java.util.List; | ||
14 | import java.util.Map; | ||
15 | import java.util.Objects; | ||
16 | import java.util.Set; | ||
17 | import java.util.function.Function; | ||
18 | import java.util.stream.Collectors; | ||
19 | import java.util.stream.Stream; | ||
20 | |||
21 | import org.eclipse.emf.ecore.EAttribute; | ||
22 | import org.eclipse.emf.ecore.EClass; | ||
23 | import org.eclipse.emf.ecore.EDataType; | ||
24 | import org.eclipse.emf.ecore.EObject; | ||
25 | import tools.refinery.viatra.runtime.base.api.NavigationHelper; | ||
26 | import tools.refinery.viatra.runtime.emf.EMFScope; | ||
27 | import tools.refinery.viatra.runtime.emf.types.EDataTypeInSlotsKey; | ||
28 | import tools.refinery.viatra.runtime.localsearch.MatchingFrame; | ||
29 | import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext; | ||
30 | import tools.refinery.viatra.runtime.localsearch.operations.IIteratingSearchOperation; | ||
31 | import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation; | ||
32 | import tools.refinery.viatra.runtime.matchers.context.IInputKey; | ||
33 | import tools.refinery.viatra.runtime.matchers.tuple.Tuple; | ||
34 | import tools.refinery.viatra.runtime.matchers.tuple.Tuples; | ||
35 | import tools.refinery.viatra.runtime.matchers.util.CollectionsFactory; | ||
36 | |||
37 | /** | ||
38 | * Iterates over all {@link EDataType} instances without using an {@link NavigationHelper VIATRA Base indexer}. | ||
39 | * | ||
40 | */ | ||
41 | public class IterateOverEDatatypeInstances implements IIteratingSearchOperation { | ||
42 | |||
43 | private class Executor extends AbstractIteratingExtendOperationExecutor<Object> { | ||
44 | |||
45 | public Executor(int position, EMFScope scope) { | ||
46 | super(position, scope); | ||
47 | } | ||
48 | |||
49 | @Override | ||
50 | public Iterator<? extends Object> getIterator(MatchingFrame frame, final ISearchContext context) { | ||
51 | return getModelContents().filter(EObject.class::isInstance).map(EObject.class::cast) | ||
52 | .map(input -> doGetEAttributes(input.eClass(), context) | ||
53 | .map(attribute -> { | ||
54 | if (attribute.isMany()) { | ||
55 | return ((List<?>) input.eGet(attribute)).stream(); | ||
56 | } else { | ||
57 | Object o = input.eGet(attribute); | ||
58 | return o == null ? Stream.empty() : Stream.of(o); | ||
59 | } | ||
60 | })) | ||
61 | .flatMap(i -> i) | ||
62 | .<Object>flatMap(i -> i) | ||
63 | .iterator(); | ||
64 | } | ||
65 | |||
66 | @Override | ||
67 | public ISearchOperation getOperation() { | ||
68 | return IterateOverEDatatypeInstances.this; | ||
69 | } | ||
70 | } | ||
71 | |||
72 | private final EDataType dataType; | ||
73 | private final int position; | ||
74 | private final EMFScope scope; | ||
75 | |||
76 | public IterateOverEDatatypeInstances(int position, EDataType dataType, EMFScope scope) { | ||
77 | this.position = position; | ||
78 | this.dataType = dataType; | ||
79 | this.scope = scope; | ||
80 | } | ||
81 | |||
82 | protected Stream<EAttribute> doGetEAttributes(EClass eclass, ISearchContext context){ | ||
83 | @SuppressWarnings({ "unchecked"}) | ||
84 | Map<Tuple, Set<EAttribute>> cache = context.accessBackendLevelCache(getClass(), Map.class, CollectionsFactory::createMap); | ||
85 | Tuple compositeKey = Tuples.staticArityFlatTupleOf(dataType, eclass); | ||
86 | return cache.computeIfAbsent(compositeKey, k -> | ||
87 | eclass.getEAllAttributes().stream().filter(input -> Objects.equals(input.getEType(), dataType)).collect(Collectors.toSet()) | ||
88 | ).stream(); | ||
89 | } | ||
90 | |||
91 | public EDataType getDataType() { | ||
92 | return dataType; | ||
93 | } | ||
94 | |||
95 | @Override | ||
96 | public ISearchOperationExecutor createExecutor() { | ||
97 | return new Executor(position, scope); | ||
98 | } | ||
99 | |||
100 | @Override | ||
101 | public String toString() { | ||
102 | return toString(Object::toString); | ||
103 | } | ||
104 | |||
105 | @Override | ||
106 | public String toString(Function<Integer, String> variableMapping) { | ||
107 | return "extend "+dataType.getName()+"(-"+variableMapping.apply(position)+") iterating"; | ||
108 | } | ||
109 | |||
110 | @Override | ||
111 | public List<Integer> getVariablePositions() { | ||
112 | return Collections.singletonList(position); | ||
113 | } | ||
114 | |||
115 | /** | ||
116 | * @since 1.4 | ||
117 | */ | ||
118 | @Override | ||
119 | public IInputKey getIteratedInputKey() { | ||
120 | return new EDataTypeInSlotsKey(dataType); | ||
121 | } | ||
122 | |||
123 | } | ||
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/planner/PConstraintInfoInferrer.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/planner/PConstraintInfoInferrer.java index 96fda930..eeac07ce 100644 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/planner/PConstraintInfoInferrer.java +++ b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/planner/PConstraintInfoInferrer.java | |||
@@ -3,40 +3,18 @@ | |||
3 | * This program and the accompanying materials are made available under the | 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 | 4 | * terms of the Eclipse Public License v. 2.0 which is available at |
5 | * http://www.eclipse.org/legal/epl-v20.html. | 5 | * http://www.eclipse.org/legal/epl-v20.html. |
6 | * | 6 | * |
7 | * SPDX-License-Identifier: EPL-2.0 | 7 | * SPDX-License-Identifier: EPL-2.0 |
8 | *******************************************************************************/ | 8 | *******************************************************************************/ |
9 | package tools.refinery.viatra.runtime.localsearch.planner; | 9 | package tools.refinery.viatra.runtime.localsearch.planner; |
10 | 10 | ||
11 | import java.util.ArrayList; | ||
12 | import java.util.Arrays; | ||
13 | import java.util.Collections; | ||
14 | import java.util.HashSet; | ||
15 | import java.util.List; | ||
16 | import java.util.Objects; | ||
17 | import java.util.Set; | ||
18 | import java.util.function.Function; | ||
19 | import java.util.function.Predicate; | ||
20 | import java.util.stream.Collectors; | ||
21 | import java.util.stream.Stream; | ||
22 | |||
23 | import org.eclipse.emf.ecore.EReference; | ||
24 | import org.eclipse.emf.ecore.EStructuralFeature; | ||
25 | import tools.refinery.viatra.runtime.base.api.BaseIndexOptions; | ||
26 | import tools.refinery.viatra.runtime.base.comprehension.EMFModelComprehension; | ||
27 | import tools.refinery.viatra.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
28 | import tools.refinery.viatra.runtime.localsearch.planner.cost.IConstraintEvaluationContext; | 11 | import tools.refinery.viatra.runtime.localsearch.planner.cost.IConstraintEvaluationContext; |
29 | import tools.refinery.viatra.runtime.matchers.backend.ResultProviderRequestor; | 12 | import tools.refinery.viatra.runtime.matchers.backend.ResultProviderRequestor; |
30 | import tools.refinery.viatra.runtime.matchers.context.IInputKey; | 13 | import tools.refinery.viatra.runtime.matchers.context.IInputKey; |
31 | import tools.refinery.viatra.runtime.matchers.context.IQueryBackendContext; | 14 | import tools.refinery.viatra.runtime.matchers.context.IQueryBackendContext; |
32 | import tools.refinery.viatra.runtime.matchers.psystem.PConstraint; | 15 | import tools.refinery.viatra.runtime.matchers.psystem.PConstraint; |
33 | import tools.refinery.viatra.runtime.matchers.psystem.PVariable; | 16 | import tools.refinery.viatra.runtime.matchers.psystem.PVariable; |
34 | import tools.refinery.viatra.runtime.matchers.psystem.basicdeferred.AggregatorConstraint; | 17 | import tools.refinery.viatra.runtime.matchers.psystem.basicdeferred.*; |
35 | import tools.refinery.viatra.runtime.matchers.psystem.basicdeferred.ExportedParameter; | ||
36 | import tools.refinery.viatra.runtime.matchers.psystem.basicdeferred.ExpressionEvaluation; | ||
37 | import tools.refinery.viatra.runtime.matchers.psystem.basicdeferred.Inequality; | ||
38 | import tools.refinery.viatra.runtime.matchers.psystem.basicdeferred.PatternMatchCounter; | ||
39 | import tools.refinery.viatra.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint; | ||
40 | import tools.refinery.viatra.runtime.matchers.psystem.basicenumerables.AbstractTransitiveClosure; | 18 | import tools.refinery.viatra.runtime.matchers.psystem.basicenumerables.AbstractTransitiveClosure; |
41 | import tools.refinery.viatra.runtime.matchers.psystem.basicenumerables.ConstantValue; | 19 | import tools.refinery.viatra.runtime.matchers.psystem.basicenumerables.ConstantValue; |
42 | import tools.refinery.viatra.runtime.matchers.psystem.basicenumerables.PositivePatternCall; | 20 | import tools.refinery.viatra.runtime.matchers.psystem.basicenumerables.PositivePatternCall; |
@@ -46,39 +24,42 @@ import tools.refinery.viatra.runtime.matchers.psystem.queries.PParameterDirectio | |||
46 | import tools.refinery.viatra.runtime.matchers.tuple.Tuple; | 24 | import tools.refinery.viatra.runtime.matchers.tuple.Tuple; |
47 | import tools.refinery.viatra.runtime.matchers.util.Sets; | 25 | import tools.refinery.viatra.runtime.matchers.util.Sets; |
48 | 26 | ||
27 | import java.util.*; | ||
28 | import java.util.function.Function; | ||
29 | import java.util.function.Predicate; | ||
30 | import java.util.stream.Collectors; | ||
31 | import java.util.stream.Stream; | ||
32 | |||
49 | 33 | ||
50 | /** | 34 | /** |
51 | * @author Grill Balázs | 35 | * @author Grill Balázs |
52 | * @noreference This class is not intended to be referenced by clients. | 36 | * @noreference This class is not intended to be referenced by clients. |
53 | */ | 37 | */ |
54 | class PConstraintInfoInferrer { | 38 | class PConstraintInfoInferrer { |
55 | 39 | ||
56 | private static final Predicate<PVariable> SINGLE_USE_VARIABLE = input -> input != null && input.getReferringConstraints().size() == 1; | 40 | private static final Predicate<PVariable> SINGLE_USE_VARIABLE = input -> input != null && input.getReferringConstraints().size() == 1; |
57 | 41 | ||
58 | private final boolean useIndex; | 42 | private final boolean useIndex; |
59 | private final Function<IConstraintEvaluationContext, Double> costFunction; | 43 | private final Function<IConstraintEvaluationContext, Double> costFunction; |
60 | private final EMFModelComprehension modelComprehension; | ||
61 | private final IQueryBackendContext context; | 44 | private final IQueryBackendContext context; |
62 | private final ResultProviderRequestor resultRequestor; | 45 | private final ResultProviderRequestor resultRequestor; |
63 | 46 | ||
64 | 47 | ||
65 | public PConstraintInfoInferrer(boolean useIndex, | 48 | public PConstraintInfoInferrer(boolean useIndex, |
66 | IQueryBackendContext backendContext, | 49 | IQueryBackendContext backendContext, |
67 | ResultProviderRequestor resultRequestor, | 50 | ResultProviderRequestor resultRequestor, |
68 | Function<IConstraintEvaluationContext, Double> costFunction) { | 51 | Function<IConstraintEvaluationContext, Double> costFunction) { |
69 | this.useIndex = useIndex; | 52 | this.useIndex = useIndex; |
70 | this.context = backendContext; | 53 | this.context = backendContext; |
71 | this.resultRequestor = resultRequestor; | 54 | this.resultRequestor = resultRequestor; |
72 | this.costFunction = costFunction; | 55 | this.costFunction = costFunction; |
73 | this.modelComprehension = new EMFModelComprehension(new BaseIndexOptions()); | ||
74 | } | 56 | } |
75 | 57 | ||
76 | 58 | ||
77 | /** | 59 | /** |
78 | * Create all possible application condition for all constraint | 60 | * Create all possible application condition for all constraint |
79 | * | 61 | * |
80 | * @param constraintSet the set of constraints | 62 | * @param constraintSet the set of constraints |
81 | * @param runtimeContext the model dependent runtime contest | ||
82 | * @return a collection of the wrapper PConstraintInfo objects with all the allowed application conditions | 63 | * @return a collection of the wrapper PConstraintInfo objects with all the allowed application conditions |
83 | */ | 64 | */ |
84 | public List<PConstraintInfo> createPConstraintInfos(Set<PConstraint> constraintSet) { | 65 | public List<PConstraintInfo> createPConstraintInfos(Set<PConstraint> constraintSet) { |
@@ -106,7 +87,7 @@ class PConstraintInfoInferrer { | |||
106 | } else if (pConstraint instanceof AggregatorConstraint){ | 87 | } else if (pConstraint instanceof AggregatorConstraint){ |
107 | createConstraintInfoAggregatorConstraint(resultList, pConstraint, ((AggregatorConstraint) pConstraint).getResultVariable()); | 88 | createConstraintInfoAggregatorConstraint(resultList, pConstraint, ((AggregatorConstraint) pConstraint).getResultVariable()); |
108 | } else if (pConstraint instanceof PatternMatchCounter){ | 89 | } else if (pConstraint instanceof PatternMatchCounter){ |
109 | createConstraintInfoAggregatorConstraint(resultList, pConstraint, ((PatternMatchCounter) pConstraint).getResultVariable()); | 90 | createConstraintInfoAggregatorConstraint(resultList, pConstraint, ((PatternMatchCounter) pConstraint).getResultVariable()); |
110 | } else if (pConstraint instanceof PositivePatternCall){ | 91 | } else if (pConstraint instanceof PositivePatternCall){ |
111 | createConstraintInfoPositivePatternCall(resultList, (PositivePatternCall) pConstraint); | 92 | createConstraintInfoPositivePatternCall(resultList, (PositivePatternCall) pConstraint); |
112 | } else if (pConstraint instanceof AbstractTransitiveClosure) { | 93 | } else if (pConstraint instanceof AbstractTransitiveClosure) { |
@@ -115,10 +96,10 @@ class PConstraintInfoInferrer { | |||
115 | createConstraintInfoGeneric(resultList, pConstraint); | 96 | createConstraintInfoGeneric(resultList, pConstraint); |
116 | } | 97 | } |
117 | } | 98 | } |
118 | 99 | ||
119 | private void createConstraintInfoConstantValue(List<PConstraintInfo> resultList, | 100 | private void createConstraintInfoConstantValue(List<PConstraintInfo> resultList, |
120 | ConstantValue pConstraint) { | 101 | ConstantValue pConstraint) { |
121 | // A ConstantValue constraint has a single variable, which is allowed to be unbound | 102 | // A ConstantValue constraint has a single variable, which is allowed to be unbound |
122 | // (extending through ConstantValue is considered a cheap operation) | 103 | // (extending through ConstantValue is considered a cheap operation) |
123 | Set<PVariable> affectedVariables = pConstraint.getAffectedVariables(); | 104 | Set<PVariable> affectedVariables = pConstraint.getAffectedVariables(); |
124 | Set<? extends Set<PVariable>> bindings = Sets.powerSet(affectedVariables); | 105 | Set<? extends Set<PVariable>> bindings = Sets.powerSet(affectedVariables); |
@@ -126,7 +107,7 @@ class PConstraintInfoInferrer { | |||
126 | } | 107 | } |
127 | 108 | ||
128 | 109 | ||
129 | private void createConstraintInfoPositivePatternCall(List<PConstraintInfo> resultList, | 110 | private void createConstraintInfoPositivePatternCall(List<PConstraintInfo> resultList, |
130 | PositivePatternCall pCall) { | 111 | PositivePatternCall pCall) { |
131 | // A pattern call can have any of its variables unbound | 112 | // A pattern call can have any of its variables unbound |
132 | Set<PVariable> affectedVariables = pCall.getAffectedVariables(); | 113 | Set<PVariable> affectedVariables = pCall.getAffectedVariables(); |
@@ -147,23 +128,23 @@ class PConstraintInfoInferrer { | |||
147 | case OUT: | 128 | case OUT: |
148 | default: | 129 | default: |
149 | break; | 130 | break; |
150 | 131 | ||
151 | } | 132 | } |
152 | } | 133 | } |
153 | Iterable<Set<PVariable>> bindings = Sets.powerSet(inoutVariables).stream() | 134 | Iterable<Set<PVariable>> bindings = Sets.powerSet(inoutVariables).stream() |
154 | .map(input -> Stream.concat(input.stream(), inVariables.stream()).collect(Collectors.toSet())) | 135 | .map(input -> Stream.concat(input.stream(), inVariables.stream()).collect(Collectors.toSet())) |
155 | .collect(Collectors.toSet()); | 136 | .collect(Collectors.toSet()); |
156 | 137 | ||
157 | doCreateConstraintInfos(resultList, pCall, affectedVariables, bindings); | 138 | doCreateConstraintInfos(resultList, pCall, affectedVariables, bindings); |
158 | } | 139 | } |
159 | 140 | ||
160 | private void createConstraintInfoBinaryTransitiveClosure(List<PConstraintInfo> resultList, | 141 | private void createConstraintInfoBinaryTransitiveClosure(List<PConstraintInfo> resultList, |
161 | AbstractTransitiveClosure closure) { | 142 | AbstractTransitiveClosure closure) { |
162 | // A pattern call can have any of its variables unbound | 143 | // A pattern call can have any of its variables unbound |
163 | 144 | ||
164 | List<PParameter> parameters = closure.getReferredQuery().getParameters(); | 145 | List<PParameter> parameters = closure.getReferredQuery().getParameters(); |
165 | Tuple variables = closure.getVariablesTuple(); | 146 | Tuple variables = closure.getVariablesTuple(); |
166 | 147 | ||
167 | Set<Set<PVariable>> bindings = new HashSet<>(); | 148 | Set<Set<PVariable>> bindings = new HashSet<>(); |
168 | PVariable firstVariable = (PVariable) variables.get(0); | 149 | PVariable firstVariable = (PVariable) variables.get(0); |
169 | PVariable secondVariable = (PVariable) variables.get(1); | 150 | PVariable secondVariable = (PVariable) variables.get(1); |
@@ -177,20 +158,20 @@ class PConstraintInfoInferrer { | |||
177 | if (parameters.get(1).getDirection() != PParameterDirection.IN) { | 158 | if (parameters.get(1).getDirection() != PParameterDirection.IN) { |
178 | bindings.add(Collections.singleton(firstVariable)); | 159 | bindings.add(Collections.singleton(firstVariable)); |
179 | } | 160 | } |
180 | 161 | ||
181 | doCreateConstraintInfos(resultList, closure, closure.getAffectedVariables(), bindings); | 162 | doCreateConstraintInfos(resultList, closure, closure.getAffectedVariables(), bindings); |
182 | } | 163 | } |
183 | |||
184 | |||
185 | 164 | ||
186 | private void createConstraintInfoExportedParameter(List<PConstraintInfo> resultList, | 165 | |
166 | |||
167 | private void createConstraintInfoExportedParameter(List<PConstraintInfo> resultList, | ||
187 | ExportedParameter parameter) { | 168 | ExportedParameter parameter) { |
188 | // In case of an exported parameter constraint, the parameter must be bound in order to execute | 169 | // In case of an exported parameter constraint, the parameter must be bound in order to execute |
189 | Set<PVariable> affectedVariables = parameter.getAffectedVariables(); | 170 | Set<PVariable> affectedVariables = parameter.getAffectedVariables(); |
190 | doCreateConstraintInfos(resultList, parameter, affectedVariables, Collections.singleton(affectedVariables)); | 171 | doCreateConstraintInfos(resultList, parameter, affectedVariables, Collections.singleton(affectedVariables)); |
191 | } | 172 | } |
192 | 173 | ||
193 | private void createConstraintInfoExpressionEvaluation(List<PConstraintInfo> resultList, | 174 | private void createConstraintInfoExpressionEvaluation(List<PConstraintInfo> resultList, |
194 | ExpressionEvaluation expressionEvaluation) { | 175 | ExpressionEvaluation expressionEvaluation) { |
195 | // An expression evaluation can only have its output variable unbound. All other variables shall be bound | 176 | // An expression evaluation can only have its output variable unbound. All other variables shall be bound |
196 | PVariable output = expressionEvaluation.getOutputVariable(); | 177 | PVariable output = expressionEvaluation.getOutputVariable(); |
@@ -203,41 +184,41 @@ class PConstraintInfoInferrer { | |||
203 | doCreateConstraintInfos(resultList, expressionEvaluation, affectedVariables, bindings); | 184 | doCreateConstraintInfos(resultList, expressionEvaluation, affectedVariables, bindings); |
204 | } | 185 | } |
205 | 186 | ||
206 | private void createConstraintInfoTypeFilterConstraint(List<PConstraintInfo> resultList, | 187 | private void createConstraintInfoTypeFilterConstraint(List<PConstraintInfo> resultList, |
207 | TypeFilterConstraint filter){ | 188 | TypeFilterConstraint filter){ |
208 | // In case of type filter, all affected variables must be bound in order to execute | 189 | // In case of type filter, all affected variables must be bound in order to execute |
209 | Set<PVariable> affectedVariables = filter.getAffectedVariables(); | 190 | Set<PVariable> affectedVariables = filter.getAffectedVariables(); |
210 | doCreateConstraintInfos(resultList, filter, affectedVariables, Collections.singleton(affectedVariables)); | 191 | doCreateConstraintInfos(resultList, filter, affectedVariables, Collections.singleton(affectedVariables)); |
211 | } | 192 | } |
212 | 193 | ||
213 | private void createConstraintInfoInequality(List<PConstraintInfo> resultList, | 194 | private void createConstraintInfoInequality(List<PConstraintInfo> resultList, |
214 | Inequality inequality){ | 195 | Inequality inequality){ |
215 | // In case of inequality, all affected variables must be bound in order to execute | 196 | // In case of inequality, all affected variables must be bound in order to execute |
216 | Set<PVariable> affectedVariables = inequality.getAffectedVariables(); | 197 | Set<PVariable> affectedVariables = inequality.getAffectedVariables(); |
217 | doCreateConstraintInfos(resultList, inequality, affectedVariables, Collections.singleton(affectedVariables)); | 198 | doCreateConstraintInfos(resultList, inequality, affectedVariables, Collections.singleton(affectedVariables)); |
218 | } | 199 | } |
219 | 200 | ||
220 | private void createConstraintInfoAggregatorConstraint(List<PConstraintInfo> resultList, | 201 | private void createConstraintInfoAggregatorConstraint(List<PConstraintInfo> resultList, |
221 | PConstraint pConstraint, PVariable resultVariable){ | 202 | PConstraint pConstraint, PVariable resultVariable){ |
222 | Set<PVariable> affectedVariables = pConstraint.getAffectedVariables(); | 203 | Set<PVariable> affectedVariables = pConstraint.getAffectedVariables(); |
223 | 204 | ||
224 | // The only variables which can be unbound are single-use | 205 | // The only variables which can be unbound are single-use |
225 | Set<PVariable> canBeUnboundVariables = | 206 | Set<PVariable> canBeUnboundVariables = |
226 | Stream.concat(Stream.of(resultVariable), affectedVariables.stream().filter(SINGLE_USE_VARIABLE)).collect(Collectors.toSet()); | 207 | Stream.concat(Stream.of(resultVariable), affectedVariables.stream().filter(SINGLE_USE_VARIABLE)).collect(Collectors.toSet()); |
227 | 208 | ||
228 | Set<Set<PVariable>> bindings = calculatePossibleBindings(canBeUnboundVariables, affectedVariables); | 209 | Set<Set<PVariable>> bindings = calculatePossibleBindings(canBeUnboundVariables, affectedVariables); |
229 | 210 | ||
230 | doCreateConstraintInfos(resultList, pConstraint, affectedVariables, bindings); | 211 | doCreateConstraintInfos(resultList, pConstraint, affectedVariables, bindings); |
231 | } | 212 | } |
232 | 213 | ||
233 | /** | 214 | /** |
234 | * | 215 | * |
235 | * @param canBeUnboundVariables Variables which are allowed to be unbound | 216 | * @param canBeUnboundVariables Variables which are allowed to be unbound |
236 | * @param affectedVariables All affected variables | 217 | * @param affectedVariables All affected variables |
237 | * @return The set of possible bound variable sets | 218 | * @return The set of possible bound variable sets |
238 | */ | 219 | */ |
239 | private Set<Set<PVariable>> calculatePossibleBindings(Set<PVariable> canBeUnboundVariables, Set<PVariable> affectedVariables){ | 220 | private Set<Set<PVariable>> calculatePossibleBindings(Set<PVariable> canBeUnboundVariables, Set<PVariable> affectedVariables){ |
240 | final Set<PVariable> mustBindVariables = affectedVariables.stream().filter(input -> !canBeUnboundVariables.contains(input)).collect(Collectors.toSet()); | 221 | final Set<PVariable> mustBindVariables = affectedVariables.stream().filter(input -> !canBeUnboundVariables.contains(input)).collect(Collectors.toSet()); |
241 | return Sets.powerSet(canBeUnboundVariables).stream() | 222 | return Sets.powerSet(canBeUnboundVariables).stream() |
242 | .map(input -> { | 223 | .map(input -> { |
243 | //some variables have to be bound before executing this constraint | 224 | //some variables have to be bound before executing this constraint |
@@ -247,33 +228,23 @@ class PConstraintInfoInferrer { | |||
247 | }) | 228 | }) |
248 | .collect(Collectors.toSet()); | 229 | .collect(Collectors.toSet()); |
249 | } | 230 | } |
250 | 231 | ||
251 | private void createConstraintInfoGeneric(List<PConstraintInfo> resultList, PConstraint pConstraint){ | 232 | private void createConstraintInfoGeneric(List<PConstraintInfo> resultList, PConstraint pConstraint){ |
252 | Set<PVariable> affectedVariables = pConstraint.getAffectedVariables(); | 233 | Set<PVariable> affectedVariables = pConstraint.getAffectedVariables(); |
253 | 234 | ||
254 | // The only variables which can be unbound are single use variables | 235 | // The only variables which can be unbound are single use variables |
255 | Set<PVariable> canBeUnboundVariables = affectedVariables.stream().filter(SINGLE_USE_VARIABLE).collect(Collectors.toSet()); | 236 | Set<PVariable> canBeUnboundVariables = affectedVariables.stream().filter(SINGLE_USE_VARIABLE).collect(Collectors.toSet()); |
256 | 237 | ||
257 | Set<Set<PVariable>> bindings = calculatePossibleBindings(canBeUnboundVariables, affectedVariables); | 238 | Set<Set<PVariable>> bindings = calculatePossibleBindings(canBeUnboundVariables, affectedVariables); |
258 | 239 | ||
259 | doCreateConstraintInfos(resultList, pConstraint, affectedVariables, bindings); | 240 | doCreateConstraintInfos(resultList, pConstraint, affectedVariables, bindings); |
260 | } | 241 | } |
261 | 242 | ||
262 | private boolean canPerformInverseNavigation(EStructuralFeature feature){ | 243 | private void createConstraintInfoTypeConstraint(List<PConstraintInfo> resultList, |
263 | return ( // Feature has opposite (this only possible for references) | ||
264 | hasEOpposite(feature) | ||
265 | || | ||
266 | (feature instanceof EReference) && ((EReference)feature).isContainment() | ||
267 | || ( // Indexing is enabled, and the feature can be indexed (not a non-well-behaving derived feature). | ||
268 | useIndex && modelComprehension.representable(feature) | ||
269 | )); | ||
270 | } | ||
271 | |||
272 | private void createConstraintInfoTypeConstraint(List<PConstraintInfo> resultList, | ||
273 | TypeConstraint typeConstraint) { | 244 | TypeConstraint typeConstraint) { |
274 | Set<PVariable> affectedVariables = typeConstraint.getAffectedVariables(); | 245 | Set<PVariable> affectedVariables = typeConstraint.getAffectedVariables(); |
275 | Set<? extends Set<PVariable>> bindings = null; | 246 | Set<? extends Set<PVariable>> bindings = null; |
276 | 247 | ||
277 | IInputKey inputKey = typeConstraint.getSupplierKey(); | 248 | IInputKey inputKey = typeConstraint.getSupplierKey(); |
278 | if(inputKey.isEnumerable()){ | 249 | if(inputKey.isEnumerable()){ |
279 | bindings = Sets.powerSet(affectedVariables); | 250 | bindings = Sets.powerSet(affectedVariables); |
@@ -281,23 +252,15 @@ class PConstraintInfoInferrer { | |||
281 | // For not enumerable types, this constraint can only be a check | 252 | // For not enumerable types, this constraint can only be a check |
282 | bindings = Collections.singleton(affectedVariables); | 253 | bindings = Collections.singleton(affectedVariables); |
283 | } | 254 | } |
284 | 255 | ||
285 | if(inputKey instanceof EStructuralFeatureInstancesKey){ | ||
286 | final EStructuralFeature feature = ((EStructuralFeatureInstancesKey) inputKey).getEmfKey(); | ||
287 | if(!canPerformInverseNavigation(feature)){ | ||
288 | // When inverse navigation is not allowed or not possible, filter out operation masks, where | ||
289 | // the first variable would be free AND the feature is an EReference and has no EOpposite | ||
290 | bindings = excludeUnnavigableOperationMasks(typeConstraint, bindings); | ||
291 | } | ||
292 | } | ||
293 | doCreateConstraintInfos(resultList, typeConstraint, affectedVariables, bindings); | 256 | doCreateConstraintInfos(resultList, typeConstraint, affectedVariables, bindings); |
294 | } | 257 | } |
295 | 258 | ||
296 | private void doCreateConstraintInfos(List<PConstraintInfo> constraintInfos, | 259 | private void doCreateConstraintInfos(List<PConstraintInfo> constraintInfos, |
297 | PConstraint pConstraint, Set<PVariable> affectedVariables, Iterable<? extends Set<PVariable>> bindings) { | 260 | PConstraint pConstraint, Set<PVariable> affectedVariables, Iterable<? extends Set<PVariable>> bindings) { |
298 | Set<PConstraintInfo> sameWithDifferentBindings = new HashSet<>(); | 261 | Set<PConstraintInfo> sameWithDifferentBindings = new HashSet<>(); |
299 | for (Set<PVariable> boundVariables : bindings) { | 262 | for (Set<PVariable> boundVariables : bindings) { |
300 | 263 | ||
301 | PConstraintInfo info = new PConstraintInfo(pConstraint, boundVariables, | 264 | PConstraintInfo info = new PConstraintInfo(pConstraint, boundVariables, |
302 | affectedVariables.stream().filter(input -> !boundVariables.contains(input)).collect(Collectors.toSet()), | 265 | affectedVariables.stream().filter(input -> !boundVariables.contains(input)).collect(Collectors.toSet()), |
303 | sameWithDifferentBindings, context, resultRequestor, costFunction); | 266 | sameWithDifferentBindings, context, resultRequestor, costFunction); |
@@ -305,22 +268,11 @@ class PConstraintInfoInferrer { | |||
305 | sameWithDifferentBindings.add(info); | 268 | sameWithDifferentBindings.add(info); |
306 | } | 269 | } |
307 | } | 270 | } |
308 | 271 | ||
309 | private Set<Set<PVariable>> excludeUnnavigableOperationMasks(TypeConstraint typeConstraint, Set<? extends Set<PVariable>> bindings) { | 272 | private Set<Set<PVariable>> excludeUnnavigableOperationMasks(TypeConstraint typeConstraint, Set<? extends Set<PVariable>> bindings) { |
310 | PVariable firstVariable = typeConstraint.getVariableInTuple(0); | 273 | PVariable firstVariable = typeConstraint.getVariableInTuple(0); |
311 | return bindings.stream().filter( | 274 | return bindings.stream().filter( |
312 | boundVariablesSet -> (boundVariablesSet.isEmpty() || boundVariablesSet.contains(firstVariable))) | 275 | boundVariablesSet -> (boundVariablesSet.isEmpty() || boundVariablesSet.contains(firstVariable))) |
313 | .collect(Collectors.toSet()); | 276 | .collect(Collectors.toSet()); |
314 | } | 277 | } |
315 | |||
316 | private boolean hasEOpposite(EStructuralFeature feature) { | ||
317 | if(feature instanceof EReference){ | ||
318 | EReference eOpposite = ((EReference) feature).getEOpposite(); | ||
319 | if(eOpposite != null){ | ||
320 | return true; | ||
321 | } | ||
322 | } | ||
323 | return false; | ||
324 | } | ||
325 | |||
326 | } | 278 | } |
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/planner/compiler/EMFOperationCompiler.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/planner/compiler/EMFOperationCompiler.java deleted file mode 100644 index 7fd86f3c..00000000 --- a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/planner/compiler/EMFOperationCompiler.java +++ /dev/null | |||
@@ -1,198 +0,0 @@ | |||
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 | *******************************************************************************/ | ||
9 | package tools.refinery.viatra.runtime.localsearch.planner.compiler; | ||
10 | |||
11 | import java.util.Map; | ||
12 | |||
13 | import org.eclipse.emf.ecore.EReference; | ||
14 | import org.eclipse.emf.ecore.EStructuralFeature; | ||
15 | import tools.refinery.viatra.runtime.emf.EMFQueryRuntimeContext; | ||
16 | import tools.refinery.viatra.runtime.emf.types.EClassTransitiveInstancesKey; | ||
17 | import tools.refinery.viatra.runtime.emf.types.EClassUnscopedTransitiveInstancesKey; | ||
18 | import tools.refinery.viatra.runtime.emf.types.EDataTypeInSlotsKey; | ||
19 | import tools.refinery.viatra.runtime.emf.types.EStructuralFeatureInstancesKey; | ||
20 | import tools.refinery.viatra.runtime.localsearch.operations.check.InstanceOfClassCheck; | ||
21 | import tools.refinery.viatra.runtime.localsearch.operations.check.InstanceOfDataTypeCheck; | ||
22 | import tools.refinery.viatra.runtime.localsearch.operations.check.InstanceOfJavaClassCheck; | ||
23 | import tools.refinery.viatra.runtime.localsearch.operations.check.StructuralFeatureCheck; | ||
24 | import tools.refinery.viatra.runtime.localsearch.operations.check.nobase.ScopeCheck; | ||
25 | import tools.refinery.viatra.runtime.localsearch.operations.extend.ExtendToEStructuralFeatureSource; | ||
26 | import tools.refinery.viatra.runtime.localsearch.operations.extend.ExtendToEStructuralFeatureTarget; | ||
27 | import tools.refinery.viatra.runtime.localsearch.operations.extend.IterateOverContainers; | ||
28 | import tools.refinery.viatra.runtime.localsearch.operations.extend.IterateOverEClassInstances; | ||
29 | import tools.refinery.viatra.runtime.localsearch.operations.extend.IterateOverEDatatypeInstances; | ||
30 | import tools.refinery.viatra.runtime.matchers.context.IInputKey; | ||
31 | import tools.refinery.viatra.runtime.matchers.context.IQueryRuntimeContext; | ||
32 | import tools.refinery.viatra.runtime.matchers.context.common.JavaTransitiveInstancesKey; | ||
33 | import tools.refinery.viatra.runtime.matchers.planning.QueryProcessingException; | ||
34 | import tools.refinery.viatra.runtime.matchers.psystem.PVariable; | ||
35 | import tools.refinery.viatra.runtime.matchers.psystem.basicdeferred.TypeFilterConstraint; | ||
36 | import tools.refinery.viatra.runtime.matchers.psystem.basicenumerables.TypeConstraint; | ||
37 | import tools.refinery.viatra.runtime.matchers.tuple.TupleMask; | ||
38 | |||
39 | /** | ||
40 | * Operation compiler implementation that uses EMF-specific operations. | ||
41 | * | ||
42 | * @author Zoltan Ujhelyi | ||
43 | * @since 1.7 | ||
44 | * | ||
45 | */ | ||
46 | public class EMFOperationCompiler extends AbstractOperationCompiler { | ||
47 | |||
48 | private boolean baseIndexAvailable; | ||
49 | |||
50 | private final EMFQueryRuntimeContext runtimeContext; | ||
51 | |||
52 | public EMFOperationCompiler(IQueryRuntimeContext runtimeContext) { | ||
53 | this(runtimeContext, false); | ||
54 | } | ||
55 | |||
56 | public EMFOperationCompiler(IQueryRuntimeContext runtimeContext, boolean baseIndexAvailable) { | ||
57 | super(runtimeContext); | ||
58 | this.runtimeContext = (EMFQueryRuntimeContext) runtimeContext; | ||
59 | this.baseIndexAvailable = baseIndexAvailable; | ||
60 | } | ||
61 | |||
62 | @Override | ||
63 | protected void createCheck(TypeFilterConstraint typeConstraint, Map<PVariable, Integer> variableMapping) { | ||
64 | final IInputKey inputKey = typeConstraint.getInputKey(); | ||
65 | if (inputKey instanceof JavaTransitiveInstancesKey) { | ||
66 | doCreateInstanceofJavaTypeCheck((JavaTransitiveInstancesKey) inputKey, variableMapping.get(typeConstraint.getVariablesTuple().get(0))); | ||
67 | } else if (inputKey instanceof EDataTypeInSlotsKey) { // TODO probably only occurs as TypeConstraint | ||
68 | doCreateInstanceofDatatypeCheck((EDataTypeInSlotsKey) inputKey, variableMapping.get(typeConstraint.getVariablesTuple().get(0))); | ||
69 | } else if (inputKey instanceof EClassUnscopedTransitiveInstancesKey) { | ||
70 | doCreateInstanceofUnscopedClassCheck((EClassUnscopedTransitiveInstancesKey) inputKey, variableMapping.get(typeConstraint.getVariablesTuple().get(0))); | ||
71 | } else { | ||
72 | String msg = UNSUPPORTED_TYPE_MESSAGE + inputKey; | ||
73 | throw new QueryProcessingException(msg, null, msg, null); | ||
74 | } | ||
75 | } | ||
76 | |||
77 | @Override | ||
78 | protected void createCheck(TypeConstraint typeConstraint, Map<PVariable, Integer> variableMapping) { | ||
79 | final IInputKey inputKey = typeConstraint.getSupplierKey(); | ||
80 | if (inputKey instanceof EClassTransitiveInstancesKey) { | ||
81 | doCreateInstanceofClassCheck((EClassTransitiveInstancesKey)inputKey, variableMapping.get(typeConstraint.getVariablesTuple().get(0))); | ||
82 | } else if (inputKey instanceof EStructuralFeatureInstancesKey) { | ||
83 | int sourcePosition = variableMapping.get(typeConstraint.getVariablesTuple().get(0)); | ||
84 | int targetPosition = variableMapping.get(typeConstraint.getVariablesTuple().get(1)); | ||
85 | operations.add(new StructuralFeatureCheck(sourcePosition, targetPosition, | ||
86 | ((EStructuralFeatureInstancesKey) inputKey).getEmfKey())); | ||
87 | } else if (inputKey instanceof EDataTypeInSlotsKey) { | ||
88 | doCreateInstanceofDatatypeCheck((EDataTypeInSlotsKey) inputKey, variableMapping.get(typeConstraint.getVariablesTuple().get(0))); | ||
89 | } else { | ||
90 | String msg = UNSUPPORTED_TYPE_MESSAGE + inputKey; | ||
91 | throw new QueryProcessingException(msg, null, msg, null); | ||
92 | } | ||
93 | } | ||
94 | |||
95 | @Override | ||
96 | protected void createUnaryTypeCheck(IInputKey inputKey, int position) { | ||
97 | if (inputKey instanceof EClassTransitiveInstancesKey) { | ||
98 | doCreateInstanceofClassCheck((EClassTransitiveInstancesKey)inputKey, position); | ||
99 | } else if (inputKey instanceof EClassUnscopedTransitiveInstancesKey) { | ||
100 | doCreateInstanceofUnscopedClassCheck((EClassUnscopedTransitiveInstancesKey)inputKey, position); | ||
101 | } else if (inputKey instanceof EDataTypeInSlotsKey) { | ||
102 | doCreateInstanceofDatatypeCheck((EDataTypeInSlotsKey) inputKey, position); | ||
103 | } else if (inputKey instanceof JavaTransitiveInstancesKey) { | ||
104 | doCreateInstanceofJavaTypeCheck((JavaTransitiveInstancesKey) inputKey, position); | ||
105 | } else { | ||
106 | String msg = UNSUPPORTED_TYPE_MESSAGE + inputKey; | ||
107 | throw new QueryProcessingException(msg, null, msg, null); | ||
108 | } | ||
109 | } | ||
110 | |||
111 | private void doCreateInstanceofClassCheck(EClassTransitiveInstancesKey inputKey, int position) { | ||
112 | operations.add(new InstanceOfClassCheck(position, inputKey.getEmfKey())); | ||
113 | operations.add(new ScopeCheck(position, runtimeContext.getEmfScope())); | ||
114 | } | ||
115 | |||
116 | private void doCreateInstanceofUnscopedClassCheck(EClassUnscopedTransitiveInstancesKey inputKey, int position) { | ||
117 | operations.add(new InstanceOfClassCheck(position, inputKey.getEmfKey())); | ||
118 | } | ||
119 | |||
120 | private void doCreateInstanceofDatatypeCheck(EDataTypeInSlotsKey inputKey, int position) { | ||
121 | operations.add(new InstanceOfDataTypeCheck(position, inputKey.getEmfKey())); | ||
122 | } | ||
123 | private void doCreateInstanceofJavaTypeCheck(JavaTransitiveInstancesKey inputKey, int position) { | ||
124 | operations.add(new InstanceOfJavaClassCheck(position, inputKey.getInstanceClass())); | ||
125 | } | ||
126 | |||
127 | @Override | ||
128 | public void createExtend(TypeConstraint typeConstraint, Map<PVariable, Integer> variableMapping) { | ||
129 | final IInputKey inputKey = typeConstraint.getSupplierKey(); | ||
130 | if (inputKey instanceof EDataTypeInSlotsKey) { | ||
131 | if(baseIndexAvailable){ | ||
132 | operations.add(new IterateOverEDatatypeInstances(variableMapping.get(typeConstraint.getVariableInTuple(0)), ((EDataTypeInSlotsKey) inputKey).getEmfKey())); | ||
133 | } else { | ||
134 | int position = variableMapping.get(typeConstraint.getVariableInTuple(0)); | ||
135 | operations | ||
136 | .add(new tools.refinery.viatra.runtime.localsearch.operations.extend.nobase.IterateOverEDatatypeInstances(position, | ||
137 | ((EDataTypeInSlotsKey) inputKey).getEmfKey(), runtimeContext.getEmfScope())); | ||
138 | operations.add(new ScopeCheck(position, runtimeContext.getEmfScope())); | ||
139 | } | ||
140 | } else if (inputKey instanceof EClassTransitiveInstancesKey) { | ||
141 | if(baseIndexAvailable){ | ||
142 | operations.add(new IterateOverEClassInstances(variableMapping.get(typeConstraint.getVariableInTuple(0)), | ||
143 | ((EClassTransitiveInstancesKey) inputKey).getEmfKey())); | ||
144 | } else { | ||
145 | int position = variableMapping.get(typeConstraint.getVariableInTuple(0)); | ||
146 | operations | ||
147 | .add(new tools.refinery.viatra.runtime.localsearch.operations.extend.nobase.IterateOverEClassInstances( | ||
148 | position, | ||
149 | ((EClassTransitiveInstancesKey) inputKey).getEmfKey(), runtimeContext.getEmfScope())); | ||
150 | operations.add(new ScopeCheck(position, runtimeContext.getEmfScope())); | ||
151 | } | ||
152 | } else if (inputKey instanceof EStructuralFeatureInstancesKey) { | ||
153 | final EStructuralFeature feature = ((EStructuralFeatureInstancesKey) inputKey).getEmfKey(); | ||
154 | |||
155 | int sourcePosition = variableMapping.get(typeConstraint.getVariablesTuple().get(0)); | ||
156 | int targetPosition = variableMapping.get(typeConstraint.getVariablesTuple().get(1)); | ||
157 | |||
158 | boolean fromBound = variableBindings.get(typeConstraint).contains(sourcePosition); | ||
159 | boolean toBound = variableBindings.get(typeConstraint).contains(targetPosition); | ||
160 | |||
161 | if (fromBound && !toBound) { | ||
162 | operations.add(new ExtendToEStructuralFeatureTarget(sourcePosition, targetPosition, feature)); | ||
163 | operations.add(new ScopeCheck(targetPosition, runtimeContext.getEmfScope())); | ||
164 | } else if(!fromBound && toBound){ | ||
165 | if (feature instanceof EReference && ((EReference)feature).isContainment()) { | ||
166 | // The iterate is also used to traverse a single container (third parameter) | ||
167 | operations.add(new IterateOverContainers(sourcePosition, targetPosition, false)); | ||
168 | operations.add(new ScopeCheck(sourcePosition, runtimeContext.getEmfScope())); | ||
169 | } else if(baseIndexAvailable){ | ||
170 | TupleMask mask = TupleMask.fromSelectedIndices(variableMapping.size(), new int[] {targetPosition}); | ||
171 | operations.add(new ExtendToEStructuralFeatureSource(sourcePosition, targetPosition, feature, mask)); | ||
172 | } else { | ||
173 | operations.add(new tools.refinery.viatra.runtime.localsearch.operations.extend.nobase.ExtendToEStructuralFeatureSource( | ||
174 | sourcePosition, targetPosition, feature)); | ||
175 | operations.add(new ScopeCheck(sourcePosition, runtimeContext.getEmfScope())); | ||
176 | } | ||
177 | } else { | ||
178 | // TODO Elaborate solution based on the navigability of edges | ||
179 | // As of now a static solution is implemented | ||
180 | if (baseIndexAvailable) { | ||
181 | operations.add(new IterateOverEClassInstances(sourcePosition, feature.getEContainingClass())); | ||
182 | operations.add(new ExtendToEStructuralFeatureTarget(sourcePosition, targetPosition, feature)); | ||
183 | } else { | ||
184 | operations | ||
185 | .add(new tools.refinery.viatra.runtime.localsearch.operations.extend.nobase.IterateOverEClassInstances( | ||
186 | sourcePosition, feature.getEContainingClass(), runtimeContext.getEmfScope())); | ||
187 | operations.add(new ScopeCheck(sourcePosition, runtimeContext.getEmfScope())); | ||
188 | operations.add(new ExtendToEStructuralFeatureTarget(sourcePosition, targetPosition, feature)); | ||
189 | operations.add(new ScopeCheck(targetPosition, runtimeContext.getEmfScope())); | ||
190 | } | ||
191 | } | ||
192 | |||
193 | } else { | ||
194 | throw new IllegalArgumentException(UNSUPPORTED_TYPE_MESSAGE + inputKey); | ||
195 | } | ||
196 | } | ||
197 | |||
198 | } | ||