diff options
Diffstat (limited to 'subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/CheckConstant.java')
-rw-r--r-- | subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/CheckConstant.java | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/CheckConstant.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/CheckConstant.java new file mode 100644 index 00000000..4ce48af0 --- /dev/null +++ b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/check/CheckConstant.java | |||
@@ -0,0 +1,70 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2014, Marton Bur, Akos Horvath, 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.Collections; | ||
12 | import java.util.List; | ||
13 | import java.util.function.Function; | ||
14 | |||
15 | import tools.refinery.viatra.runtime.localsearch.MatchingFrame; | ||
16 | import tools.refinery.viatra.runtime.localsearch.matcher.ISearchContext; | ||
17 | import tools.refinery.viatra.runtime.localsearch.operations.CheckOperationExecutor; | ||
18 | import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation; | ||
19 | |||
20 | /** | ||
21 | * This operation handles constants in search plans by checking if a variable is bound to a certain constant value. Such | ||
22 | * operations should be executed as early as possible during plan execution. | ||
23 | * | ||
24 | * @author Marton Bur | ||
25 | * @noextend This class is not intended to be subclassed by clients. | ||
26 | */ | ||
27 | public class CheckConstant implements ISearchOperation { | ||
28 | |||
29 | private class Executor extends CheckOperationExecutor { | ||
30 | |||
31 | @Override | ||
32 | protected boolean check(MatchingFrame frame, ISearchContext context) { | ||
33 | return frame.get(position).equals(value); | ||
34 | } | ||
35 | |||
36 | @Override | ||
37 | public ISearchOperation getOperation() { | ||
38 | return CheckConstant.this; | ||
39 | } | ||
40 | } | ||
41 | |||
42 | private int position; | ||
43 | private Object value; | ||
44 | |||
45 | public CheckConstant(int position, Object value) { | ||
46 | this.position = position; | ||
47 | this.value = value; | ||
48 | } | ||
49 | |||
50 | @Override | ||
51 | public ISearchOperationExecutor createExecutor() { | ||
52 | return new Executor(); | ||
53 | } | ||
54 | |||
55 | @Override | ||
56 | public List<Integer> getVariablePositions() { | ||
57 | return Collections.singletonList(position); | ||
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 constant "+variableMapping.apply(position)+"='"+value+"'"; | ||
68 | } | ||
69 | |||
70 | } | ||