$darkmode
DENOPTIM
FragmentSpaceUtils.java
Go to the documentation of this file.
1/*
2 * DENOPTIM
3 * Copyright (C) 2019 Marco Foscato <marco.foscato@uib.no>
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Affero General Public License as published
7 * by the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Affero General Public License for more details.
14 *
15 * You should have received a copy of the GNU Affero General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19package denoptim.fragspace;
20
21import java.util.List;
22import java.util.Map;
23
24import denoptim.graph.APMapping;
25import denoptim.graph.AttachmentPoint;
26
27
34{
35
36//------------------------------------------------------------------------------
37
53 public static boolean recursiveCombiner(List<AttachmentPoint> keys,
54 int currentKey, Map<AttachmentPoint,
55 List<AttachmentPoint>> possibilities,
56 APMapping combination, List<APMapping> completeCombinations,
57 boolean screenAll, int maxCombs)
58 {
59 boolean stopped = false;
60 AttachmentPoint apA = keys.get(currentKey);
61 for (int i=0; i<possibilities.get(apA).size(); i++)
62 {
63 // Prevent combinatorial explosion.
64 if (stopped)
65 break;
66
67 AttachmentPoint apB = possibilities.get(apA).get(i);
68
69 // Move on if apB is already used by another pairing
70 if (combination.containsValue(apB))
71 continue;
72
73 // add this pairing to the growing combinations
74 APMapping priorCombination = combination.clone();
75 if (apA != null && apB != null)
76 {
77 combination.put(apA,apB);
78 }
79 // NB: when one is null it means that the other will not be listed
80 // in the mapping. Therefore, it will be left out of any operation
81 // that uses the mapping. For example, the AP for which the is a
82 // 'null' possibility will be left free.
83
84 // go deeper, to the next key
85 if (currentKey+1 < keys.size())
86 {
87 stopped = recursiveCombiner(keys, currentKey+1, possibilities,
88 combination, completeCombinations, screenAll, maxCombs);
89 }
90
91 // we reached the deepest level: save combination
92 if (currentKey+1 == keys.size() && !combination.isEmpty())
93 {
94 APMapping storable = combination.clone(); //Shallow clone
95 completeCombinations.add(storable);
96 if (!screenAll && completeCombinations.size() >= maxCombs)
97 {
98 stopped = true;
99 }
100 }
101
102 // Restart building a new combination from the previous combination
103 combination = priorCombination;
104 }
105 return stopped;
106 }
107
108//------------------------------------------------------------------------------
109
110}
Utility class for the fragment space.
static boolean recursiveCombiner(List< AttachmentPoint > keys, int currentKey, Map< AttachmentPoint, List< AttachmentPoint > > possibilities, APMapping combination, List< APMapping > completeCombinations, boolean screenAll, int maxCombs)
Search for all possible combinations of compatible APs.
Class representing a mapping between attachment points (APs).
Definition: APMapping.java:42
APMapping clone()
Shallow cloning.
Definition: APMapping.java:140
An attachment point (AP) is a possibility to attach a Vertex onto the vertex holding the AP (i....