aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/matcher/integration/LocalSearchHints.java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/matcher/integration/LocalSearchHints.java')
-rw-r--r--subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/matcher/integration/LocalSearchHints.java157
1 files changed, 53 insertions, 104 deletions
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 *******************************************************************************/
9package tools.refinery.viatra.runtime.localsearch.matcher.integration; 9package tools.refinery.viatra.runtime.localsearch.matcher.integration;
10 10
11import static tools.refinery.viatra.runtime.localsearch.matcher.integration.LocalSearchHintOptions.ADORNMENT_PROVIDER;
12import static tools.refinery.viatra.runtime.localsearch.matcher.integration.LocalSearchHintOptions.CALL_DELEGATION_STRATEGY;
13import static tools.refinery.viatra.runtime.localsearch.matcher.integration.LocalSearchHintOptions.FLATTEN_CALL_PREDICATE;
14import static tools.refinery.viatra.runtime.localsearch.matcher.integration.LocalSearchHintOptions.PLANNER_COST_FUNCTION;
15import static tools.refinery.viatra.runtime.localsearch.matcher.integration.LocalSearchHintOptions.PLANNER_TABLE_ROW_COUNT;
16import static tools.refinery.viatra.runtime.localsearch.matcher.integration.LocalSearchHintOptions.USE_BASE_INDEX;
17import static tools.refinery.viatra.runtime.matchers.backend.CommonQueryHintOptions.normalizationTraceCollector;
18
19import java.util.HashMap;
20import java.util.Map;
21import java.util.Objects;
22
23import tools.refinery.viatra.runtime.localsearch.planner.cost.ICostFunction; 11import tools.refinery.viatra.runtime.localsearch.planner.cost.ICostFunction;
24import tools.refinery.viatra.runtime.localsearch.planner.cost.impl.IndexerBasedConstraintCostFunction; 12import tools.refinery.viatra.runtime.localsearch.planner.cost.impl.IndexerBasedConstraintCostFunction;
25import tools.refinery.viatra.runtime.localsearch.planner.cost.impl.StatisticsBasedConstraintCostFunction; 13import tools.refinery.viatra.runtime.localsearch.planner.cost.impl.StatisticsBasedConstraintCostFunction;
26import tools.refinery.viatra.runtime.localsearch.planner.cost.impl.VariableBindingBasedCostFunction; 14import tools.refinery.viatra.runtime.matchers.backend.*;
27import tools.refinery.viatra.runtime.matchers.backend.ICallDelegationStrategy;
28import tools.refinery.viatra.runtime.matchers.backend.IMatcherCapability;
29import tools.refinery.viatra.runtime.matchers.backend.IQueryBackendFactory;
30import tools.refinery.viatra.runtime.matchers.backend.QueryEvaluationHint;
31import tools.refinery.viatra.runtime.matchers.backend.QueryHintOption;
32import tools.refinery.viatra.runtime.matchers.psystem.rewriters.DefaultFlattenCallPredicate;
33import tools.refinery.viatra.runtime.matchers.psystem.rewriters.IFlattenCallPredicate; 15import tools.refinery.viatra.runtime.matchers.psystem.rewriters.IFlattenCallPredicate;
34import tools.refinery.viatra.runtime.matchers.psystem.rewriters.IRewriterTraceCollector; 16import tools.refinery.viatra.runtime.matchers.psystem.rewriters.IRewriterTraceCollector;
35import tools.refinery.viatra.runtime.matchers.psystem.rewriters.NeverFlattenCallPredicate;
36import tools.refinery.viatra.runtime.matchers.psystem.rewriters.NopTraceCollector; 17import tools.refinery.viatra.runtime.matchers.psystem.rewriters.NopTraceCollector;
37 18
19import java.util.HashMap;
20import java.util.Map;
21import java.util.Objects;
22
23import static tools.refinery.viatra.runtime.localsearch.matcher.integration.LocalSearchHintOptions.*;
24import 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 */
45public final class LocalSearchHints implements IMatcherCapability { 33public 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 */