diff options
Diffstat (limited to 'subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/plan/SearchPlan.java')
-rw-r--r-- | subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/plan/SearchPlan.java | 99 |
1 files changed, 99 insertions, 0 deletions
diff --git a/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/plan/SearchPlan.java b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/plan/SearchPlan.java new file mode 100644 index 00000000..3159f707 --- /dev/null +++ b/subprojects/viatra-runtime-localsearch/src/main/java/tools/refinery/viatra/runtime/localsearch/plan/SearchPlan.java | |||
@@ -0,0 +1,99 @@ | |||
1 | /******************************************************************************* | ||
2 | * Copyright (c) 2010-2014, 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.plan; | ||
10 | |||
11 | import java.util.ArrayList; | ||
12 | import java.util.Collections; | ||
13 | import java.util.List; | ||
14 | import java.util.Map; | ||
15 | import java.util.Map.Entry; | ||
16 | import java.util.stream.Collectors; | ||
17 | |||
18 | import tools.refinery.viatra.runtime.localsearch.operations.ISearchOperation; | ||
19 | import tools.refinery.viatra.runtime.matchers.psystem.PBody; | ||
20 | import tools.refinery.viatra.runtime.matchers.psystem.PVariable; | ||
21 | import tools.refinery.viatra.runtime.matchers.tuple.TupleMask; | ||
22 | |||
23 | /** | ||
24 | * A SearchPlan stores a collection of SearchPlanOperations for a fixed order of variables. | ||
25 | * | ||
26 | * @author Zoltan Ujhelyi | ||
27 | * | ||
28 | */ | ||
29 | public class SearchPlan { | ||
30 | |||
31 | private final List<ISearchOperation> operations; | ||
32 | private final Map<Integer, PVariable> variableMapping; | ||
33 | private final TupleMask parameterMask; | ||
34 | private final PBody body; | ||
35 | |||
36 | /** | ||
37 | * @since 2.0 | ||
38 | */ | ||
39 | public SearchPlan(PBody body, List<ISearchOperation> operations, TupleMask parameterMask, Map<PVariable, Integer> variableMapping) { | ||
40 | this.body = body; | ||
41 | this.operations = Collections.unmodifiableList(new ArrayList<>(operations)); | ||
42 | this.parameterMask = parameterMask; | ||
43 | this.variableMapping = Collections.unmodifiableMap(variableMapping.entrySet().stream() | ||
44 | .collect(Collectors.toMap(Entry::getValue, Entry::getKey))); | ||
45 | } | ||
46 | |||
47 | |||
48 | /** | ||
49 | * Returns an immutable list of operations stored in the plan. | ||
50 | * @return the operations | ||
51 | */ | ||
52 | public List<ISearchOperation> getOperations() { | ||
53 | return operations; | ||
54 | } | ||
55 | |||
56 | /** | ||
57 | * Returns an immutable map of variable mappings for the plan | ||
58 | * @since 2.0 | ||
59 | */ | ||
60 | public Map<Integer, PVariable> getVariableMapping() { | ||
61 | return variableMapping; | ||
62 | } | ||
63 | |||
64 | /** | ||
65 | * Returns the index of a given operation in the plan | ||
66 | * @since 2.0 | ||
67 | */ | ||
68 | public int getOperationIndex(ISearchOperation operation) { | ||
69 | return operations.indexOf(operation); | ||
70 | } | ||
71 | |||
72 | /** | ||
73 | * @since 2.0 | ||
74 | */ | ||
75 | public TupleMask getParameterMask() { | ||
76 | return parameterMask; | ||
77 | } | ||
78 | |||
79 | /** | ||
80 | * @since 2.0 | ||
81 | */ | ||
82 | public PBody getSourceBody() { | ||
83 | return body; | ||
84 | } | ||
85 | |||
86 | @Override | ||
87 | public String toString() { | ||
88 | StringBuilder sb = new StringBuilder(); | ||
89 | |||
90 | sb.append("{\n"); | ||
91 | for(ISearchOperation operation : this.getOperations()){ | ||
92 | sb.append("\t"); | ||
93 | sb.append(operation); | ||
94 | sb.append("\n"); | ||
95 | } | ||
96 | sb.append("}"); | ||
97 | return sb.toString(); | ||
98 | } | ||
99 | } | ||