19package denoptim.fragspace;
21import static org.junit.jupiter.api.Assertions.assertEquals;
22import static org.junit.jupiter.api.Assertions.assertTrue;
24import java.util.ArrayList;
25import java.util.HashMap;
26import java.util.HashSet;
27import java.util.LinkedHashMap;
30import org.junit.jupiter.api.Test;
32import denoptim.exception.DENOPTIMException;
33import denoptim.graph.APClass;
34import denoptim.graph.APMapping;
35import denoptim.graph.AttachmentPoint;
36import denoptim.graph.DGraph;
37import denoptim.graph.Edge;
38import denoptim.graph.EmptyVertex;
39import denoptim.graph.Vertex;
40import denoptim.graph.Vertex.BBType;
62 HashMap<APClass,ArrayList<APClass>> cpMap =
63 new HashMap<APClass,ArrayList<APClass>>();
64 ArrayList<APClass> lstA =
new ArrayList<APClass>();
66 cpMap.put(
APCA, lstA);
67 ArrayList<APClass> lstB =
new ArrayList<APClass>();
70 cpMap.put(
APCB, lstB);
71 ArrayList<APClass> lstC =
new ArrayList<APClass>();
74 cpMap.put(
APCC, lstC);
75 ArrayList<APClass> lstD =
new ArrayList<APClass>();
77 cpMap.put(
APCD, lstD);
78 ArrayList<APClass> lstE =
new ArrayList<APClass>();
80 cpMap.put(
APCE, lstE);
102 HashMap<APClass,APClass> capMap =
new HashMap<APClass,APClass>();
103 HashSet<APClass> forbEnds =
new HashSet<APClass>();
107 new ArrayList<Vertex>(),
108 new ArrayList<Vertex>(),
109 new ArrayList<Vertex>(),
110 cpMap, capMap, forbEnds, cpMap);
145 assertTrue(apm.containsKey(vA.
getAP(2)));
146 assertEquals(vB.
getAP(4), apm.get(vA.
getAP(2)));
199 .stream().filter(m -> m.size()==1)
202 .stream().filter(m -> m.size()==2)
206 .filter(m -> m.containsKey(vA.
getAP(0)))
210 .filter(m -> m.size()==2)
211 .filter(m -> m.containsKey(vA.
getAP(0)))
215 apmf =
new APMapFinder(fs, vA, vB,
null,
true,
true,
true);
250 .stream().filter(m -> m.size()==2)
254 .filter(m -> m.containsKey(vA.
getAP(0)))
337 HashMap<APClass,APClass> capMap =
new HashMap<APClass,APClass>();
338 HashSet<APClass> forbEnds =
new HashSet<APClass>();
339 HashMap<APClass,ArrayList<APClass>> cpMap =
340 new HashMap<APClass,ArrayList<APClass>>();
344 new ArrayList<Vertex>(),
345 new ArrayList<Vertex>(),
346 new ArrayList<Vertex>(),
347 cpMap, capMap, forbEnds, cpMap);
349 LinkedHashMap<AttachmentPoint,List<AttachmentPoint>> apCompatilities =
354 assertEquals(2, apCompatilities.size());
355 assertEquals(3, apCompatilities.get(v0.
getAP(0)).size());
356 assertEquals(3, apCompatilities.get(v0.
getAP(1)).size());
361 assertEquals(3, apCompatilities.size());
362 assertEquals(3, apCompatilities.get(f0.
getAP(0)).size());
363 assertEquals(3, apCompatilities.get(f0.
getAP(1)).size());
364 assertEquals(3, apCompatilities.get(f0.
getAP(2)).size());
369 assertEquals(3, apCompatilities.size());
370 assertEquals(3, apCompatilities.get(f0.
getAP(0)).size());
371 assertEquals(3, apCompatilities.get(f0.
getAP(1)).size());
372 assertEquals(3, apCompatilities.get(f0.
getAP(2)).size());
377 assertEquals(3, apCompatilities.size());
378 assertEquals(3, apCompatilities.get(f2.
getAP(0)).size());
379 assertEquals(3, apCompatilities.get(f2.
getAP(1)).size());
380 assertEquals(3, apCompatilities.get(f2.
getAP(2)).size());
385 assertEquals(1, apCompatilities.size());
386 assertEquals(3, apCompatilities.get(v2.
getAP(0)).size());
391 assertEquals(3, apCompatilities.size());
392 assertEquals(3, apCompatilities.get(f0.
getAP(0)).size());
393 assertEquals(3, apCompatilities.get(f0.
getAP(1)).size());
394 assertEquals(3, apCompatilities.get(f0.
getAP(2)).size());
399 assertEquals(3, apCompatilities.size());
400 assertEquals(2, apCompatilities.get(f0.
getAP(0)).size());
401 assertEquals(2, apCompatilities.get(f0.
getAP(1)).size());
402 assertEquals(2, apCompatilities.get(f0.
getAP(2)).size());
415 assertEquals(2, apCompatilities.size());
417 assertEquals(1, apCompatilities.get(v0.
getAP(0)).size());
419 assertEquals(1, apCompatilities.get(v0.
getAP(1)).size());
424 assertEquals(3, apCompatilities.size());
425 assertEquals(1, apCompatilities.get(f0.
getAP(0)).size());
426 assertEquals(1, apCompatilities.get(f0.
getAP(1)).size());
427 assertEquals(1, apCompatilities.get(f0.
getAP(2)).size());
432 assertEquals(3, apCompatilities.size());
433 assertEquals(3, apCompatilities.get(f0.
getAP(0)).size());
434 assertEquals(3, apCompatilities.get(f0.
getAP(1)).size());
435 assertEquals(3, apCompatilities.get(f0.
getAP(2)).size());
440 assertEquals(1, apCompatilities.size());
445 assertEquals(1, apCompatilities.size());
450 assertEquals(3, apCompatilities.size());
451 assertEquals(3, apCompatilities.get(f0.
getAP(0)).size());
452 assertEquals(3, apCompatilities.get(f0.
getAP(1)).size());
453 assertEquals(3, apCompatilities.get(f0.
getAP(2)).size());
458 assertEquals(3, apCompatilities.size());
459 assertEquals(1, apCompatilities.get(f0.
getAP(0)).size());
460 assertEquals(1, apCompatilities.get(f0.
getAP(1)).size());
461 assertEquals(1, apCompatilities.get(f0.
getAP(2)).size());
467 assertEquals(2, apCompatilities.size());
468 assertEquals(1, apCompatilities.get(v0.
getAP(0)).size());
469 assertEquals(f0.
getAP(0), apCompatilities.get(v0.
getAP(0)).get(0));
470 assertEquals(1, apCompatilities.get(v0.
getAP(1)).size());
471 assertEquals(f0.
getAP(1), apCompatilities.get(v0.
getAP(1)).get(0));
476 assertEquals(1, apCompatilities.size());
477 assertEquals(1, apCompatilities.get(v2.
getAP(0)).size());
482 assertEquals(0, apCompatilities.size());
487 cpMap =
new HashMap<APClass,ArrayList<APClass>>();
488 ArrayList<APClass> lstO =
new ArrayList<APClass>();
490 cpMap.put(APCO0, lstO);
491 ArrayList<APClass> lstP =
new ArrayList<APClass>();
493 cpMap.put(APCP0, lstP);
514 new ArrayList<Vertex>(),
515 new ArrayList<Vertex>(),
516 new ArrayList<Vertex>(),
517 cpMap, capMap, forbEnds, cpMap);
523 assertEquals(2, apCompatilities.size());
524 assertEquals(1, apCompatilities.get(v0.
getAP(0)).size());
525 assertEquals(f0.
getAP(0), apCompatilities.get(v0.
getAP(0)).get(0));
526 assertEquals(1, apCompatilities.get(v0.
getAP(1)).size());
527 assertEquals(f0.
getAP(1), apCompatilities.get(v0.
getAP(1)).get(0));
532 assertEquals(3, apCompatilities.size());
533 assertEquals(1, apCompatilities.get(f0.
getAP(0)).size());
534 assertEquals(1, apCompatilities.get(f0.
getAP(1)).size());
535 assertEquals(1, apCompatilities.get(f0.
getAP(2)).size());
540 assertEquals(1, apCompatilities.size());
541 assertEquals(1, apCompatilities.get(v2.
getAP(0)).size());
546 assertEquals(3, apCompatilities.size());
547 assertEquals(1, apCompatilities.get(f0.
getAP(0)).size());
548 assertEquals(1, apCompatilities.get(f0.
getAP(1)).size());
549 assertEquals(1, apCompatilities.get(f0.
getAP(2)).size());
554 assertEquals(0, apCompatilities.size());
559 cpMap =
new HashMap<APClass,ArrayList<APClass>>();
560 lstO =
new ArrayList<APClass>();
563 cpMap.put(APCO0, lstO);
564 lstP =
new ArrayList<APClass>();
567 cpMap.put(APCP0, lstP);
568 ArrayList<APClass> lstQ =
new ArrayList<APClass>();
571 cpMap.put(APCQ0, lstQ);
592 new ArrayList<Vertex>(),
593 new ArrayList<Vertex>(),
594 new ArrayList<Vertex>(),
595 cpMap, capMap, forbEnds, cpMap);
601 assertEquals(2, apCompatilities.size());
602 assertEquals(1, apCompatilities.get(v0.
getAP(0)).size());
603 assertEquals(f0.
getAP(0), apCompatilities.get(v0.
getAP(0)).get(0));
604 assertEquals(1, apCompatilities.get(v0.
getAP(1)).size());
605 assertEquals(f0.
getAP(1), apCompatilities.get(v0.
getAP(1)).get(0));
610 assertEquals(3, apCompatilities.size());
611 assertEquals(1, apCompatilities.get(f0.
getAP(0)).size());
612 assertEquals(1, apCompatilities.get(f0.
getAP(1)).size());
613 assertEquals(1, apCompatilities.get(f0.
getAP(2)).size());
618 assertEquals(1, apCompatilities.size());
619 assertEquals(1, apCompatilities.get(v2.
getAP(0)).size());
624 assertEquals(3, apCompatilities.size());
625 assertEquals(1, apCompatilities.get(f0.
getAP(0)).size());
626 assertEquals(1, apCompatilities.get(f0.
getAP(1)).size());
627 assertEquals(1, apCompatilities.get(f0.
getAP(2)).size());
632 assertEquals(0, apCompatilities.size());
662 cpMap =
new HashMap<APClass,ArrayList<APClass>>();
663 lstO =
new ArrayList<APClass>();
665 cpMap.put(APCO0, lstO);
666 lstP =
new ArrayList<APClass>();
668 cpMap.put(APCP0, lstP);
689 new ArrayList<Vertex>(),
690 new ArrayList<Vertex>(),
691 new ArrayList<Vertex>(),
693 new HashMap<APClass,APClass>(),
694 new HashSet<APClass>(),
695 new HashMap<
APClass,ArrayList<APClass>>());
702 assertEquals(0, apCompatilities.size());
709 assertEquals(0, apCompatilities.size());
716 assertEquals(0, apCompatilities.size());
723 assertEquals(0, apCompatilities.size());
727 cpMap =
new HashMap<APClass,ArrayList<APClass>>();
728 lstO =
new ArrayList<APClass>();
730 cpMap.put(APCO0, lstO);
731 lstP =
new ArrayList<APClass>();
734 cpMap.put(APCP0, lstP);
755 new ArrayList<Vertex>(),
756 new ArrayList<Vertex>(),
757 new ArrayList<Vertex>(),
759 new HashMap<APClass,APClass>(),
760 new HashSet<APClass>(),
761 new HashMap<
APClass,ArrayList<APClass>>());
768 assertEquals(0, apCompatilities.size());
775 assertEquals(0, apCompatilities.size());
782 assertEquals(0, apCompatilities.size());
789 assertEquals(0, apCompatilities.size());
794 cpMap =
new HashMap<APClass,ArrayList<APClass>>();
795 lstO =
new ArrayList<APClass>();
798 cpMap.put(APCO0, lstO);
799 lstP =
new ArrayList<APClass>();
802 cpMap.put(APCP0, lstP);
823 new ArrayList<Vertex>(),
824 new ArrayList<Vertex>(),
825 new ArrayList<Vertex>(),
827 new HashMap<APClass,APClass>(),
828 new HashSet<APClass>(),
829 new HashMap<
APClass,ArrayList<APClass>>());
836 assertEquals(1, apCompatilities.size());
837 assertEquals(1, apCompatilities.get(v0.
getAP(0)).size());
838 assertEquals(v2.
getAP(0), apCompatilities.get(v0.
getAP(0)).get(0));
842 assertEquals(1, apCompatilities.size());
843 assertEquals(1, apCompatilities.get(v2.
getAP(0)).size());
844 assertEquals(v0.
getAP(0), apCompatilities.get(v2.
getAP(0)).get(0));
851 assertEquals(0, apCompatilities.size());
858 assertEquals(0, apCompatilities.size());
865 assertEquals(1, apCompatilities.size());
866 assertEquals(1, apCompatilities.get(v1.
getAP(0)).size());
867 assertEquals(v3.
getAP(0), apCompatilities.get(v1.
getAP(0)).get(0));
871 assertEquals(1, apCompatilities.size());
872 assertEquals(1, apCompatilities.get(v3.
getAP(0)).size());
873 assertEquals(v1.
getAP(0), apCompatilities.get(v3.
getAP(0)).get(0));
878 cpMap =
new HashMap<APClass,ArrayList<APClass>>();
879 ArrayList<APClass> lstO0 =
new ArrayList<APClass>();
884 cpMap.put(APCO0, lstO0);
885 ArrayList<APClass> lstP0 =
new ArrayList<APClass>();
889 cpMap.put(APCP0, lstP0);
890 ArrayList<APClass> lstO1 =
new ArrayList<APClass>();
894 cpMap.put(APCO1, lstO1);
895 ArrayList<APClass> lstP1 =
new ArrayList<APClass>();
899 cpMap.put(APCP1, lstP1);
900 ArrayList<APClass> lstQ1 =
new ArrayList<APClass>();
905 cpMap.put(APCQ1, lstQ1);
926 new ArrayList<Vertex>(),
927 new ArrayList<Vertex>(),
928 new ArrayList<Vertex>(),
930 new HashMap<APClass,APClass>(),
931 new HashSet<APClass>(),
932 new HashMap<
APClass,ArrayList<APClass>>());
939 assertEquals(1, apCompatilities.size());
940 assertEquals(1, apCompatilities.get(v0.
getAP(0)).size());
941 assertEquals(v2.
getAP(0), apCompatilities.get(v0.
getAP(0)).get(0));
945 assertEquals(1, apCompatilities.size());
946 assertEquals(1, apCompatilities.get(v2.
getAP(0)).size());
947 assertEquals(v0.
getAP(0), apCompatilities.get(v2.
getAP(0)).get(0));
954 assertEquals(1, apCompatilities.size());
955 assertEquals(1, apCompatilities.get(v0.
getAP(0)).size());
956 assertEquals(v3.
getAP(0), apCompatilities.get(v0.
getAP(0)).get(0));
960 assertEquals(1, apCompatilities.size());
961 assertEquals(1, apCompatilities.get(v3.
getAP(0)).size());
962 assertEquals(v0.
getAP(0), apCompatilities.get(v3.
getAP(0)).get(0));
969 assertEquals(1, apCompatilities.size());
970 assertEquals(1, apCompatilities.get(v1.
getAP(0)).size());
971 assertEquals(v2.
getAP(0), apCompatilities.get(v1.
getAP(0)).get(0));
975 assertEquals(1, apCompatilities.size());
976 assertEquals(1, apCompatilities.get(v2.
getAP(0)).size());
977 assertEquals(v1.
getAP(0), apCompatilities.get(v2.
getAP(0)).get(0));
984 assertEquals(1, apCompatilities.size());
985 assertEquals(1, apCompatilities.get(v1.
getAP(0)).size());
986 assertEquals(v3.
getAP(0), apCompatilities.get(v1.
getAP(0)).get(0));
990 assertEquals(1, apCompatilities.size());
991 assertEquals(1, apCompatilities.get(v3.
getAP(0)).size());
992 assertEquals(v1.
getAP(0), apCompatilities.get(v3.
getAP(0)).get(0));
998 assertEquals(0, apCompatilities.size());
1002 assertEquals(1, apCompatilities.size());
1003 assertEquals(1, apCompatilities.size());
1004 assertEquals(1, apCompatilities.get(f4.
getAP(0)).size());
1005 assertEquals(v0.
getAP(0), apCompatilities.get(f4.
getAP(0)).get(0));
1009 assertEquals(0, apCompatilities.size());
1013 assertEquals(1, apCompatilities.size());
1014 assertEquals(1, apCompatilities.size());
1015 assertEquals(1, apCompatilities.get(v0.
getAP(0)).size());
1016 assertEquals(f4.
getAP(0), apCompatilities.get(v0.
getAP(0)).get(0));
1022 assertEquals(0, apCompatilities.size());
1026 assertEquals(1, apCompatilities.size());
1027 assertEquals(1, apCompatilities.size());
1028 assertEquals(1, apCompatilities.get(f4.
getAP(0)).size());
1029 assertEquals(v1.
getAP(0), apCompatilities.get(f4.
getAP(0)).get(0));
1033 assertEquals(0, apCompatilities.size());
1037 assertEquals(1, apCompatilities.size());
1038 assertEquals(1, apCompatilities.size());
1039 assertEquals(1, apCompatilities.get(v1.
getAP(0)).size());
1040 assertEquals(f4.
getAP(0), apCompatilities.get(v1.
getAP(0)).get(0));
An utility class to encapsulate the search for an AttachmentPoint-AttachmentPoint mapping.
APMapping getChosenAPMapping()
Returns the AttachmentPoint-AttachmentPoint mapping chosen among the possible mappings.
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.
void testFindMappingCompatibileAPs()
void testAPMapFinder_ConstrainAll()
void testAPMapFinder_Constrained()
Class defining a space of building blocks.
void setAPclassBasedApproach(boolean useAPC)
Set the fragment space to behave according to APClass-based approach.
Parameters defining the fragment space.
static APClass make(String ruleAndSubclass)
Creates an APClass if it does not exist already, or returns the reference to the existing instance.
Class representing a mapping between attachment points (APs).
Container for the list of vertices and the edges that connect them.
void addVertex(Vertex vertex)
Appends a vertex to this graph without creating any edge.
void appendVertexOnAP(AttachmentPoint srcAP, AttachmentPoint trgAP)
Append a vertex to this graph: adds the new vertex to the list of vertices belonging to the graph,...
void addEdge(Edge edge)
Adds the edge to the list of edges belonging to this graph.
This class represents the edge between two vertices.
An empty vertex has the behaviors of a vertex, but has no molecular structure.
List< AttachmentPoint > getAttachmentPoints()
void addAP()
Adds an attachment point with no APClass or other attribute.
void setBuildingBlockType(Vertex.BBType buildingBlockType)
AttachmentPoint getAP(int i)
Get attachment point i on this vertex.
The type of building block.