diff options
Diffstat (limited to 'subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/ExtendConstant.java')
-rw-r--r-- | subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/ExtendConstant.java | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/ExtendConstant.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/ExtendConstant.java new file mode 100644 index 00000000..455236f3 --- /dev/null +++ b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/operations/extend/ExtendConstant.java | |||
@@ -0,0 +1,75 @@ | |||
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.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.function.Function; | ||
16 | |||
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 | |||
21 | /** | ||
22 | * This operation handles constants in search plans by binding a variable to a constant value. Such operations should be | ||
23 | * executed as early as possible during plan execution. | ||
24 | * | ||
25 | * @author Marton Bur | ||
26 | * | ||
27 | */ | ||
28 | public class ExtendConstant implements ISearchOperation { | ||
29 | |||
30 | private class Executor extends SingleValueExtendOperationExecutor<Object> { | ||
31 | |||
32 | public Executor(int position) { | ||
33 | super(position); | ||
34 | } | ||
35 | |||
36 | @Override | ||
37 | public Iterator<?> getIterator(MatchingFrame frame, ISearchContext context) { | ||
38 | return Collections.singletonList(value).iterator(); | ||
39 | } | ||
40 | |||
41 | @Override | ||
42 | public ISearchOperation getOperation() { | ||
43 | return ExtendConstant.this; | ||
44 | } | ||
45 | } | ||
46 | |||
47 | private final Object value; | ||
48 | private final int position; | ||
49 | |||
50 | public ExtendConstant(int position, Object value) { | ||
51 | this.position = position; | ||
52 | this.value = value; | ||
53 | } | ||
54 | |||
55 | @Override | ||
56 | public ISearchOperationExecutor createExecutor() { | ||
57 | return new Executor(position); | ||
58 | } | ||
59 | |||
60 | @Override | ||
61 | public List<Integer> getVariablePositions() { | ||
62 | return Arrays.asList(position); | ||
63 | } | ||
64 | |||
65 | @Override | ||
66 | public String toString() { | ||
67 | return toString(Object::toString); | ||
68 | } | ||
69 | |||
70 | @Override | ||
71 | public String toString(Function<Integer, String> variableMapping) { | ||
72 | return "extend constant -"+variableMapping.apply(position)+"='"+value+"'"; | ||
73 | } | ||
74 | |||
75 | } | ||