21import static org.junit.jupiter.api.Assertions.assertEquals;
22import static org.junit.jupiter.api.Assertions.assertFalse;
23import static org.junit.jupiter.api.Assertions.assertTrue;
25import java.util.ArrayList;
26import java.util.Arrays;
27import java.util.HashMap;
28import java.util.HashSet;
32import org.junit.jupiter.api.Test;
34import denoptim.exception.DENOPTIMException;
35import denoptim.fragspace.FragmentSpace;
36import denoptim.fragspace.FragmentSpaceParameters;
37import denoptim.graph.APClass;
38import denoptim.graph.Candidate;
39import denoptim.graph.DGraph;
40import denoptim.graph.Edge;
41import denoptim.graph.Edge.BondType;
42import denoptim.graph.EmptyVertex;
43import denoptim.graph.Template;
44import denoptim.graph.Template.ContractLevel;
45import denoptim.graph.Vertex;
46import denoptim.graph.Vertex.BBType;
47import denoptim.programs.RunTimeParameters.ParametersType;
48import denoptim.programs.denovo.GAParameters;
70 HashMap<APClass,ArrayList<APClass>> cpMap =
71 new HashMap<APClass,ArrayList<APClass>>();
72 ArrayList<APClass> lstA =
new ArrayList<APClass>();
74 cpMap.put(
APCA, lstA);
75 ArrayList<APClass> lstB =
new ArrayList<APClass>();
78 cpMap.put(
APCB, lstB);
79 ArrayList<APClass> lstC =
new ArrayList<APClass>();
82 cpMap.put(
APCC, lstC);
83 ArrayList<APClass> lstD =
new ArrayList<APClass>();
85 cpMap.put(
APCD, lstD);
101 HashMap<APClass,APClass> capMap =
new HashMap<APClass,APClass>();
102 HashSet<APClass> forbEnds =
new HashSet<APClass>();
106 new ArrayList<Vertex>(),
107 new ArrayList<Vertex>(),
108 new ArrayList<Vertex>(),
109 cpMap, capMap, forbEnds, cpMap);
134 String k =
"Uniquefying";
191 new ArrayList<Candidate>(Arrays.asList(c1,c2,c3,c4,c5)), fs);
193 new ArrayList<Candidate>(Arrays.asList(c1,c2,c3,c4,c5)), fs);
195 new ArrayList<Candidate>(Arrays.asList(c1,c2,c3,c4,c5)), fs);
197 new ArrayList<Candidate>(Arrays.asList(c1,c2,c3,c4,c5)), fs);
199 new ArrayList<Candidate>(Arrays.asList(c1,c2,c3,c4,c5)), fs);
201 Map<Candidate,Map<Candidate,Integer>> expected =
202 new HashMap<Candidate,Map<Candidate,Integer>>();
203 Map<Candidate,Integer> expectedForC1 =
new HashMap<Candidate,Integer>();
204 expectedForC1.put(c2, 9);
205 expectedForC1.put(c3, 9);
206 expectedForC1.put(c4, 5);
207 expected.put(c1, expectedForC1);
208 Map<Candidate,Integer> expectedForC2 =
new HashMap<Candidate,Integer>();
209 expectedForC2.put(c1, 9);
211 expectedForC2.put(c4, 2);
212 expected.put(c2, expectedForC2);
213 Map<Candidate,Integer> expectedForC3 =
new HashMap<Candidate,Integer>();
214 expectedForC3.put(c1, 9);
216 expectedForC3.put(c4, 2);
217 expected.put(c3, expectedForC3);
218 Map<Candidate,Integer> expectedForC4 =
new HashMap<Candidate,Integer>();
219 expectedForC4.put(c1, 5);
220 expectedForC4.put(c2, 2);
221 expectedForC4.put(c3, 2);
222 expected.put(c4, expectedForC4);
228 assertEquals(partnersForC5.size(), 0,
"Wrong umber of partners for C5");
252 String k =
"Uniquefying";
259 new ArrayList<Candidate>(Arrays.asList(c1,c2)), fs);
261 new ArrayList<Candidate>(Arrays.asList(c1,c2)), fs);
263 Map<Candidate,Map<Candidate,Integer>> expected =
264 new HashMap<Candidate,Map<Candidate,Integer>>();
265 Map<Candidate,Integer> expectedForC1 =
new HashMap<Candidate,Integer>();
266 expectedForC1.put(c2, 9);
267 expected.put(c1, expectedForC1);
268 Map<Candidate,Integer> expectedForC2 =
new HashMap<Candidate,Integer>();
269 expectedForC2.put(c1, 9);
270 expected.put(c2, expectedForC2);
287 List<XoverSite> listB)
289 for (
int i=0; i<listA.size(); i++)
291 assertTrue(listA.get(i).equals(listB.get(i)));
298 Map<Candidate, Integer> expectedForC1,
299 List<Candidate> partnersForC1,
Population pop)
301 for (
Candidate c : expectedForC1.keySet())
303 assertTrue(partnersForC1.contains(c),
"Missing XOver compatibility "
304 +
"between '" + parentA.
getName() +
"' and '" + c.getName()
306 assertEquals(expectedForC1.get(c).intValue(),
308 "Wrong number of sites between '" + parentA.
getName()
309 +
"' and '" + c.getName() +
"'.");
594 "getting min fitness");
596 "getting max fitness");
653 assertTrue(v1>v0,
"Version change 1");
659 assertTrue(v2>v1,
"Version change 2");
665 assertTrue(v3>v2,
"Version change 3");
669 assertTrue(v4>v3,
"Version change 4");
675 assertTrue(v5>v4,
"Version change 5");
681 assertTrue(v6>v5,
"Version change 6");
1248 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.