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;
96 this(
fragSpace, vA, vB,
null, screenAll,
false,
true);
126 APMapping fixedRootAPs,
boolean screenAll,
127 boolean onlyCompleteMappings,
boolean compatibleIfFree)
130 List<AttachmentPoint> needyAPsA =
new ArrayList<AttachmentPoint>();
133 List<Vertex> subgraph =
new ArrayList<Vertex>();
137 List<AttachmentPoint> needyAPsB =
138 new ArrayList<AttachmentPoint>();
141 List<Vertex> subgraph =
new ArrayList<Vertex>();
147 fixedRootAPs, screenAll, onlyCompleteMappings, compatibleIfFree);
174 List<AttachmentPoint> lstA,
175 List<AttachmentPoint> needyAPsA,
176 List<AttachmentPoint> lstB,
177 List<AttachmentPoint> needyAPsB,
178 APMapping fixedRootAPs,
boolean screenAll,
179 boolean onlyCompleteMappings,
boolean compatibleIfFree)
183 fixedRootAPs, screenAll, onlyCompleteMappings, compatibleIfFree);
206 List<AttachmentPoint> needyAPsA,
207 List<AttachmentPoint> lstB,
208 List<AttachmentPoint> needyAPsB,
209 APMapping fixedRootAPs,
boolean screenAll,
210 boolean onlyCompleteMappings,
boolean compatibleIfFree)
213 List<AttachmentPoint> purgedLstA =
new ArrayList<AttachmentPoint>(lstA);
214 if (fixedRootAPs!=
null)
216 purgedLstA.removeAll(fixedRootAPs.keySet());
218 List<AttachmentPoint> purgedLstB =
new ArrayList<AttachmentPoint>(lstB);
219 if (fixedRootAPs!=
null)
221 purgedLstB.removeAll(fixedRootAPs.values());
225 LinkedHashMap<AttachmentPoint,List<AttachmentPoint>> apCompatilities =
231 List<AttachmentPoint> keys =
new ArrayList<AttachmentPoint>(
232 apCompatilities.keySet());
233 if (fixedRootAPs!=
null)
237 keys.removeAll(fixedRootAPs.keySet());
241 Set<AttachmentPoint> doableAPsA =
new HashSet<AttachmentPoint>(keys);
242 if (fixedRootAPs!=
null)
243 doableAPsA.addAll(fixedRootAPs.keySet());
244 Set<AttachmentPoint> doableAPsB =
new HashSet<AttachmentPoint>();
245 apCompatilities.values().stream().forEach(l -> doableAPsB.addAll(l));
246 if (onlyCompleteMappings)
250 if (!needyAPsA.contains(oldAp))
251 needyAPsA.add(oldAp);
255 if (!needyAPsB.contains(oldAp))
256 needyAPsB.add(oldAp);
259 Set<AttachmentPoint> mustBeDoableA =
new HashSet<AttachmentPoint>(
261 Set<AttachmentPoint> mustBeDoableB =
new HashSet<AttachmentPoint>(
263 if (fixedRootAPs!=
null)
265 mustBeDoableA.removeAll(fixedRootAPs.keySet());
266 mustBeDoableB.removeAll(fixedRootAPs.values());
268 if (!doableAPsA.containsAll(mustBeDoableA)
269 || !doableAPsB.containsAll(mustBeDoableB))
274 if (!onlyCompleteMappings)
278 if (oldAp.isAvailableThroughout())
283 if (apCompatilities.containsKey(oldAp))
285 apCompatilities.get(oldAp).add(
null);
294 if (fixedRootAPs!=
null)
296 currentMapping = fixedRootAPs.
clone();
301 Boolean stopped =
false;
313 List<APMapping> toRemove =
new ArrayList<APMapping>();
316 if (!c.containsAllKeys(needyAPsA))
320 if (!c.containsAllValues(needyAPsB))
332 for (
int iTry = 0; iTry <
maxCombs; iTry++)
335 List<AttachmentPoint> used =
336 new ArrayList<AttachmentPoint>();
337 List<AttachmentPoint> availKeys =
338 new ArrayList<AttachmentPoint>();
339 availKeys.addAll(needyAPsA);
340 boolean abandon =
false;
341 for (
int jj=0; jj<needyAPsA.size(); jj++)
346 availKeys.remove(ap);
347 List<AttachmentPoint> availPartners =
348 new ArrayList<AttachmentPoint>();
349 availPartners.addAll(apCompatilities.get(ap));
350 boolean done =
false;
351 for (
int j=0; j<apCompatilities.get(ap).size(); j++)
356 availPartners.remove(chosenAvail);
357 if (used.contains(chosenAvail))
361 used.add(chosenAvail);
362 apMap.put(ap,chosenAvail);
402 public static LinkedHashMap<AttachmentPoint,List<AttachmentPoint>>
404 List<AttachmentPoint> lstB,
boolean compatibleIfFree,
407 LinkedHashMap<AttachmentPoint,List<AttachmentPoint>>
409 List<AttachmentPoint>>();
415 boolean compatible =
false;
422 boolean oAPIsSrc = oAP.isSrcInUserThroughout();
423 boolean oAPIsTrg = oAPInUse && !oAP.isSrcInUserThroughout();
425 boolean cAPInUse = !cAP.isAvailableThroughout();
426 boolean cAPIsSrc = cAP.isSrcInUserThroughout();
427 boolean cAPIsTrg = cAPInUse && !cAP.isSrcInUserThroughout();
433 APClass oAPcl = oAP.getAPClass();
434 APClass cAPcl = cAP.getAPClass();
445 if (oAP.getAPClass().equals(cAP.getAPClass()))
449 if (!oAPInUse && !cAPInUse && compatibleIfFree)
452 }
else if (!oAPInUse && cAPInUse && compatibleIfFree)
463 }
else if (oAPInUse && !cAPInUse && compatibleIfFree)
474 }
else if (oAPInUse && cAPInUse)
476 if (oAPIsSrc && cAPIsSrc)
486 }
else if ((!oAPIsSrc && cAPIsSrc)
487 || (oAPIsSrc && !cAPIsSrc))
520 if (apCompatilities.containsKey(oAP))
522 apCompatilities.get(oAP).add(cAP);
524 List<AttachmentPoint> lst =
525 new ArrayList<AttachmentPoint>();
527 apCompatilities.put(oAP,lst);
532 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.