aboutsummaryrefslogtreecommitdiffstats
path: root/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/ISearchOperation.java
diff options
context:
space:
mode:
Diffstat (limited to 'subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/ISearchOperation.java')
-rw-r--r--subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/ISearchOperation.java88
1 files changed, 88 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/ISearchOperation.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/ISearchOperation.java
new file mode 100644
index 00000000..eb6243ed
--- /dev/null
+++ b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/ISearchOperation.java
@@ -0,0 +1,88 @@
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 *******************************************************************************/
9package tools.refinery.viatra.runtime.localsearch.operations;
10
11import java.util.List;
12import java.util.function.Function;
13
14import tools.refinery.viatra.runtime.localsearch.MatchingFrame;
15import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext;
16import tools.refinery.viatra.runtime.matchers.ViatraQueryRuntimeException;
17
18/**
19 * Represents a search operation executable by the LS engine. It is expected that an operation can be shared among
20 * multiple LS matchers, but the created executors are not.
21 *
22 * @author Zoltan Ujhelyi
23 *
24 */
25public interface ISearchOperation {
26
27 /**
28 * Initializes a new operation executor for the given operation. Repeated calls must return different executor
29 * instances.
30 *
31 * @since 2.0
32 */
33 public ISearchOperationExecutor createExecutor();
34
35 /**
36 *
37 * @since 2.0
38 *
39 */
40 public interface ISearchOperationExecutor {
41
42 /**
43 * Returns the stateless operation this executor was initialized from
44 */
45 ISearchOperation getOperation();
46
47 /**
48 * During the execution of the corresponding plan, the onInitialize callback is evaluated before the execution of
49 * the operation may begin. Operations may use this method to initialize its internal data structures.
50 *
51 * @throws ViatraQueryRuntimeException
52 */
53 void onInitialize(MatchingFrame frame, ISearchContext context);
54
55 /**
56 * After the execution of the operation failed and {@link #execute(MatchingFrame, ISearchContext)} returns false, the onBacktrack
57 * callback is evaluated. Operations may use this method to clean up any temporary structures, and make the
58 * operation ready for a new execution.
59 *
60 * @throws ViatraQueryRuntimeException
61 */
62 void onBacktrack(MatchingFrame frame, ISearchContext context);
63
64 /**
65 *
66 * @param frame
67 * @param context
68 * @return true if successful, or false if backtracking needed
69 * @throws ViatraQueryRuntimeException
70 */
71 boolean execute(MatchingFrame frame, ISearchContext context);
72 }
73 /**
74 *
75 * @return the ordered list of the variable numbers that are affected by the search operation
76 */
77 List<Integer> getVariablePositions();
78
79 /**
80 * Creates a string representation of the search operation by replacing the variable numbers according to the
81 * parameter function. It is expected that the provided function does return a non-null value for each variable
82 * index that is returned by {@link #getVariablePositions()}; otherwise a {@link NullPointerException} will be
83 * thrown during the calculation of the string.
84 *
85 * @since 2.0
86 */
87 String toString(Function<Integer, String> variableMapping);
88}