21import static org.junit.jupiter.api.Assertions.assertEquals;
22import static org.junit.jupiter.api.Assertions.assertFalse;
23import static org.junit.jupiter.api.Assertions.assertNull;
24import static org.junit.jupiter.api.Assertions.assertTrue;
26import java.util.ArrayList;
27import java.util.Arrays;
28import java.util.HashMap;
29import java.util.HashSet;
33import org.junit.jupiter.api.Test;
35import denoptim.exception.DENOPTIMException;
36import denoptim.fragspace.FragmentSpace;
37import denoptim.fragspace.FragmentSpaceParameters;
38import denoptim.graph.APClass;
39import denoptim.graph.Candidate;
40import denoptim.graph.DGraph;
41import denoptim.graph.Edge;
42import denoptim.graph.Edge.BondType;
43import denoptim.graph.EmptyVertex;
44import denoptim.graph.Template;
45import denoptim.graph.Template.ContractLevel;
46import denoptim.graph.Vertex;
47import denoptim.graph.Vertex.BBType;
48import denoptim.programs.RunTimeParameters.ParametersType;
49import denoptim.programs.denovo.GAParameters;
71 HashMap<APClass,ArrayList<APClass>> cpMap =
72 new HashMap<APClass,ArrayList<APClass>>();
73 ArrayList<APClass> lstA =
new ArrayList<APClass>();
75 cpMap.put(
APCA, lstA);
76 ArrayList<APClass> lstB =
new ArrayList<APClass>();
79 cpMap.put(
APCB, lstB);
80 ArrayList<APClass> lstC =
new ArrayList<APClass>();
83 cpMap.put(
APCC, lstC);
84 ArrayList<APClass> lstD =
new ArrayList<APClass>();
86 cpMap.put(
APCD, lstD);
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);
135 String k =
"Uniquefying";
192 new ArrayList<Candidate>(Arrays.asList(c1,c2,c3,c4,c5)), fs);
194 new ArrayList<Candidate>(Arrays.asList(c1,c2,c3,c4,c5)), fs);
196 new ArrayList<Candidate>(Arrays.asList(c1,c2,c3,c4,c5)), fs);
198 new ArrayList<Candidate>(Arrays.asList(c1,c2,c3,c4,c5)), fs);
200 new ArrayList<Candidate>(Arrays.asList(c1,c2,c3,c4,c5)), fs);
202 Map<Candidate,Map<Candidate,Integer>> expected =
203 new HashMap<Candidate,Map<Candidate,Integer>>();
204 Map<Candidate,Integer> expectedForC1 =
new HashMap<Candidate,Integer>();
205 expectedForC1.put(c2, 9);
206 expectedForC1.put(c3, 9);
207 expectedForC1.put(c4, 5);
208 expected.put(c1, expectedForC1);
209 Map<Candidate,Integer> expectedForC2 =
new HashMap<Candidate,Integer>();
210 expectedForC2.put(c1, 9);
212 expectedForC2.put(c4, 2);
213 expected.put(c2, expectedForC2);
214 Map<Candidate,Integer> expectedForC3 =
new HashMap<Candidate,Integer>();
215 expectedForC3.put(c1, 9);
217 expectedForC3.put(c4, 2);
218 expected.put(c3, expectedForC3);
219 Map<Candidate,Integer> expectedForC4 =
new HashMap<Candidate,Integer>();
220 expectedForC4.put(c1, 5);
221 expectedForC4.put(c2, 2);
222 expectedForC4.put(c3, 2);
223 expected.put(c4, expectedForC4);
229 assertEquals(partnersForC5.size(), 0,
"Wrong umber of partners for C5");
253 String k =
"Uniquefying";
260 new ArrayList<Candidate>(Arrays.asList(c1,c2)), fs);
262 new ArrayList<Candidate>(Arrays.asList(c1,c2)), fs);
264 Map<Candidate,Map<Candidate,Integer>> expected =
265 new HashMap<Candidate,Map<Candidate,Integer>>();
266 Map<Candidate,Integer> expectedForC1 =
new HashMap<Candidate,Integer>();
267 expectedForC1.put(c2, 9);
268 expected.put(c1, expectedForC1);
269 Map<Candidate,Integer> expectedForC2 =
new HashMap<Candidate,Integer>();
270 expectedForC2.put(c1, 9);
271 expected.put(c2, expectedForC2);
288 List<XoverSite> listB)
290 for (
int i=0; i<listA.size(); i++)
292 assertTrue(listA.get(i).equals(listB.get(i)));
299 Map<Candidate, Integer> expectedForC1,
300 List<Candidate> partnersForC1,
Population pop)
302 for (
Candidate c : expectedForC1.keySet())
304 assertTrue(partnersForC1.contains(c),
"Missing XOver compatibility "
305 +
"between '" + parentA.
getName() +
"' and '" + c.getName()
307 assertEquals(expectedForC1.get(c).intValue(),
309 "Wrong number of sites between '" + parentA.
getName()
310 +
"' and '" + c.getName() +
"'.");
595 "getting min fitness");
597 "getting max fitness");
654 assertTrue(v1>v0,
"Version change 1");
660 assertTrue(v2>v1,
"Version change 2");
666 assertTrue(v3>v2,
"Version change 3");
670 assertTrue(v4>v3,
"Version change 4");
676 assertTrue(v5>v4,
"Version change 5");
682 assertTrue(v6>v5,
"Version change 6");
1249 DGraph graphB = initialGraphs[1];
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.
FragmentSpace getFragmentSpace()
A collection of candidates.
double getMinFitness()
Gets the minimum value of the fitness in this population.
List< XoverSite > getXoverSites(Candidate parentA, Candidate parentB)
Returns a list of crossover sites between the two given parents.
List< Candidate > getXoverPartners(Candidate memberA, List< Candidate > eligibleParents, FragmentSpace fragSpace)
Returns a list of population members that can do crossover with the specified member.
int getVersionID()
Returns an integer that represent the current status of the population.
boolean isWithinPercentile(double value, double percentile)
Checks if a given fitness value if within the given percentile of best candidates.
Population clone()
Does not clone the cross-over compatibility relations between each pairs of population members.
Candidate set(int index, Candidate c)
Candidate remove(int index)
double getMaxFitness()
Gets the maximum value of the fitness in this population.
static DGraph makeGraphD()
Produced a graph like this:
static DGraph makeGraphC()
Produced a graph like this:
void testXOverCompatibility()
static GAParameters prepare()
static DGraph makeGraphB()
Produced a graph like this:
static DGraph[] getPairOfTestGraphsBxoxo()
Builds a pair of graphs that contain templates with ContractLevel#FREE contract.
void compareSizeOfSites(Candidate parentA, Map< Candidate, Integer > expectedForC1, List< Candidate > partnersForC1, Population pop)
void compareSitesLists(List< XoverSite > listA, List< XoverSite > listB)
Assumes the two lists have equal size.
void testIsInPercentile()
static DGraph makeGraphE()
Produced a graph like this:
void testPopulationVersion()
static DGraph makeGraphF()
Produced a graph like this:
static DGraph[] getPairOfTestGraphsB()
Builds a pair of graphs that contain templates with ContractLevel#FREE contract.
static DGraph[] getPairOfTestGraphsBxo()
Builds a pair of graphs that contain templates with ContractLevel#FREE contract.
static DGraph makeGraphA()
Produced a graph like this:
static APClass make(String ruleAndSubclass)
Creates an APClass if it does not exist already, or returns the reference to the existing instance.
A candidate is the combination of a denoptim graph with molecular representation and may include also...
void setFitness(double fitness)
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.
Vertex getVertexAtPosition(int pos)
Returns the vertex that is in the given position of the list of vertices belonging to this graph.
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 renumberGraphVertices()
Reassign vertex IDs to all vertices of this 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.
void addAP()
Adds an attachment point with no APClass or other attribute.
void setInnerGraph(DGraph innerGraph)
void setContractLevel(ContractLevel contract)
Imposes the given contract to this template.
A vertex is a data structure that has an identity and holds a list of AttachmentPoints.
void setAsRCV(boolean isRCV)
void setUniquefyingProperty(String key)
Add the given key among the properties that are checked for equality when comparing vertices with the...
void setBuildingBlockType(Vertex.BBType buildingBlockType)
void setProperty(Object key, Object property)
AttachmentPoint getAP(int i)
Get attachment point i on this vertex.
void setParameters(RunTimeParameters otherParams)
void readParameterLine(String line)
Parameters for genetic algorithm.
Possible chemical bond types an edge can represent.
Enum specifying to what extent the template's inner graph can be changed.
FREE
Inner graphs are free to change within the confines of the required AttachmentPoints.
The type of building block.
Identifier of the type of parameters.
FS_PARAMS
Parameters pertaining the definition of the fragment space.
RC_PARAMS
Parameters pertaining to ring closures in graphs.