19package denoptim.fragspace;
21import java.util.ArrayList;
22import java.util.HashSet;
23import java.util.LinkedHashMap;
27import denoptim.graph.APClass;
28import denoptim.graph.APMapping;
29import denoptim.graph.AttachmentPoint;
30import denoptim.graph.DGraph;
31import denoptim.graph.Vertex;
32import denoptim.graph.Vertex.BBType;
97 this(
fragSpace, vA, vB,
null, screenAll,
false,
true);
127 APMapping fixedRootAPs,
boolean screenAll,
128 boolean onlyCompleteMappings,
boolean compatibleIfFree)
131 List<AttachmentPoint> needyAPsA =
new ArrayList<AttachmentPoint>();
134 List<Vertex> subgraph =
new ArrayList<Vertex>();
138 List<AttachmentPoint> needyAPsB =
139 new ArrayList<AttachmentPoint>();
142 List<Vertex> subgraph =
new ArrayList<Vertex>();
148 fixedRootAPs, screenAll, onlyCompleteMappings, compatibleIfFree);
175 List<AttachmentPoint> lstA,
176 List<AttachmentPoint> needyAPsA,
177 List<AttachmentPoint> lstB,
178 List<AttachmentPoint> needyAPsB,
179 APMapping fixedRootAPs,
boolean screenAll,
180 boolean onlyCompleteMappings,
boolean compatibleIfFree)
184 fixedRootAPs, screenAll, onlyCompleteMappings, compatibleIfFree);
207 List<AttachmentPoint> needyAPsA,
208 List<AttachmentPoint> lstB,
209 List<AttachmentPoint> needyAPsB,
210 APMapping fixedRootAPs,
boolean screenAll,
211 boolean onlyCompleteMappings,
boolean compatibleIfFree)
214 List<AttachmentPoint> purgedLstA =
new ArrayList<AttachmentPoint>(lstA);
215 if (fixedRootAPs!=
null)
217 purgedLstA.removeAll(fixedRootAPs.keySet());
219 List<AttachmentPoint> purgedLstB =
new ArrayList<AttachmentPoint>(lstB);
220 if (fixedRootAPs!=
null)
222 purgedLstB.removeAll(fixedRootAPs.values());
226 LinkedHashMap<AttachmentPoint,List<AttachmentPoint>> apCompatilities =
232 List<AttachmentPoint> keys =
new ArrayList<AttachmentPoint>(
233 apCompatilities.keySet());
234 if (fixedRootAPs!=
null)
238 keys.removeAll(fixedRootAPs.keySet());
242 Set<AttachmentPoint> doableAPsA =
new HashSet<AttachmentPoint>(keys);
243 if (fixedRootAPs!=
null)
244 doableAPsA.addAll(fixedRootAPs.keySet());
245 Set<AttachmentPoint> doableAPsB =
new HashSet<AttachmentPoint>();
246 apCompatilities.values().stream().forEach(l -> doableAPsB.addAll(l));
247 if (onlyCompleteMappings)
251 if (!needyAPsA.contains(oldAp))
252 needyAPsA.add(oldAp);
256 if (!needyAPsB.contains(oldAp))
257 needyAPsB.add(oldAp);
260 Set<AttachmentPoint> mustBeDoableA =
new HashSet<AttachmentPoint>(
262 Set<AttachmentPoint> mustBeDoableB =
new HashSet<AttachmentPoint>(
264 if (fixedRootAPs!=
null)
266 mustBeDoableA.removeAll(fixedRootAPs.keySet());
267 mustBeDoableB.removeAll(fixedRootAPs.values());
269 if (!doableAPsA.containsAll(mustBeDoableA)
270 || !doableAPsB.containsAll(mustBeDoableB))
275 if (!onlyCompleteMappings)
279 if (oldAp.isAvailableThroughout())
284 if (apCompatilities.containsKey(oldAp))
286 apCompatilities.get(oldAp).add(
null);
295 if (fixedRootAPs!=
null)
297 currentMapping = fixedRootAPs.
clone();
302 Boolean stopped =
false;
314 List<APMapping> toRemove =
new ArrayList<APMapping>();
317 if (!c.containsAllKeys(needyAPsA))
321 if (!c.containsAllValues(needyAPsB))
333 for (
int iTry = 0; iTry <
maxCombs; iTry++)
336 List<AttachmentPoint> used =
337 new ArrayList<AttachmentPoint>();
338 List<AttachmentPoint> availKeys =
339 new ArrayList<AttachmentPoint>();
340 availKeys.addAll(needyAPsA);
341 boolean abandon =
false;
342 for (
int jj=0; jj<needyAPsA.size(); jj++)
347 availKeys.remove(ap);
348 List<AttachmentPoint> availPartners =
349 new ArrayList<AttachmentPoint>();
350 availPartners.addAll(apCompatilities.get(ap));
351 boolean done =
false;
352 for (
int j=0; j<apCompatilities.get(ap).size(); j++)
357 availPartners.remove(chosenAvail);
358 if (used.contains(chosenAvail))
362 used.add(chosenAvail);
363 apMap.put(ap,chosenAvail);
403 public static LinkedHashMap<AttachmentPoint,List<AttachmentPoint>>
405 List<AttachmentPoint> lstB,
boolean compatibleIfFree,
408 LinkedHashMap<AttachmentPoint,List<AttachmentPoint>>
410 List<AttachmentPoint>>();
416 boolean compatible =
false;
423 boolean oAPIsSrc = oAP.isSrcInUserThroughout();
424 boolean oAPIsTrg = oAPInUse && !oAP.isSrcInUserThroughout();
426 boolean cAPInUse = !cAP.isAvailableThroughout();
427 boolean cAPIsSrc = cAP.isSrcInUserThroughout();
428 boolean cAPIsTrg = cAPInUse && !cAP.isSrcInUserThroughout();
434 APClass oAPcl = oAP.getAPClass();
435 APClass cAPcl = cAP.getAPClass();
446 if (oAP.getAPClass().equals(cAP.getAPClass()))
450 if (!oAPInUse && !cAPInUse && compatibleIfFree)
453 }
else if (!oAPInUse && cAPInUse && compatibleIfFree)
464 }
else if (oAPInUse && !cAPInUse && compatibleIfFree)
475 }
else if (oAPInUse && cAPInUse)
477 if (oAPIsSrc && cAPIsSrc)
487 }
else if ((!oAPIsSrc && cAPIsSrc)
488 || (oAPIsSrc && !cAPIsSrc))
521 if (apCompatilities.containsKey(oAP))
523 apCompatilities.get(oAP).add(cAP);
525 List<AttachmentPoint> lst =
526 new ArrayList<AttachmentPoint>();
528 apCompatilities.put(oAP,lst);
533 return apCompatilities;
An utility class to encapsulate the search for an AttachmentPoint-AttachmentPoint mapping.
APMapping getChosenAPMapping()
Returns the AttachmentPoint-AttachmentPoint mapping chosen among the possible mappings.
APMapping chosenAPMap
The chosen AttachmentPoint-AttachmentPoint mapping.
List< APMapping > allAPMappings
The collection of all AttachmentPoint-AttachmentPoint mappings that have been found.
APMapFinder(FragmentSpace fragSpace, List< AttachmentPoint > lstA, List< AttachmentPoint > needyAPsA, List< AttachmentPoint > lstB, List< AttachmentPoint > needyAPsB, APMapping fixedRootAPs, boolean screenAll, boolean onlyCompleteMappings, boolean compatibleIfFree)
Constructor that launches the search for a mapping between the AttachmentPoints on two lists.
static LinkedHashMap< AttachmentPoint, List< AttachmentPoint > > findMappingCompatibileAPs(List< AttachmentPoint > lstA, List< AttachmentPoint > lstB, boolean compatibleIfFree, FragmentSpace fragSpace)
Compares the AttachmentPoint of two lists searching for all the APs of the second list that are "comp...
boolean foundMapping()
Returns true if any mapping has been found.
List< APMapping > getAllAPMappings()
Returns all AttachmentPoint-AttachmentPoint mapping found.
static int maxCombs
Maximum number of combinations.
FragmentSpace fragSpace
Program-specific fragment space.
APMapFinder(FragmentSpace fragSpace, Vertex vA, Vertex vB, APMapping fixedRootAPs, boolean screenAll, boolean onlyCompleteMappings, boolean compatibleIfFree)
Constructor that launches the search for a mapping between the AttachmentPoints on the first vertex t...
void findAllMappings(List< AttachmentPoint > lstA, List< AttachmentPoint > needyAPsA, List< AttachmentPoint > lstB, List< AttachmentPoint > needyAPsB, APMapping fixedRootAPs, boolean screenAll, boolean onlyCompleteMappings, boolean compatibleIfFree)
Searches for mappings between the AttachmentPoints on the two lists.
APMapFinder(FragmentSpace fragSpace, Vertex vA, Vertex vB, boolean screenAll)
Constructor that launches the search for a mapping between the AttachmentPoints on the first vertex t...
Class defining a space of building blocks.
Randomizer getRandomizer()
Returns the program-specific randomizer that is associated with this program-specific fragment space.
boolean useAPclassBasedApproach()
Check usage of APClass-based approach, i.e., uses attachment points with annotated data (i....
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.
boolean isCPMapCompatibleWith(APClass other, FragmentSpace fragSpace)
Check compatibility as defined in the compatibility matrix considering this AP as source and the othe...
Class representing a mapping between attachment points (APs).
APMapping clone()
Shallow cloning.
An attachment point (AP) is a possibility to attach a Vertex onto the vertex holding the AP (i....
APClass getAPClass()
Returns the Attachment Point class.
boolean isAvailableThroughout()
Check availability of this attachment point throughout the graph level, i.e., check also across the i...
AttachmentPoint getLinkedAPThroughout()
Gets the attachment point (AP) that is connected to this AP via the edge user or in any edge user tha...
List< AttachmentPoint > getInterfaceAPs(List< Vertex > subGraphB)
Searches for all AttachmentPoints that represent the interface between a subgraph,...
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
DGraph getGraphOwner()
Returns the graph this vertex belongs to or null.
abstract List< AttachmentPoint > getAttachmentPoints()
public< T > T randomlyChooseOne(Collection< T > c)
Chooses one member among the given collection.