21import java.util.ArrayList;
22import java.util.Collection;
23import java.util.Comparator;
24import java.util.LinkedHashMap;
26import java.util.concurrent.atomic.AtomicInteger;
27import java.util.logging.Level;
29import denoptim.exception.DENOPTIMException;
30import denoptim.fragspace.FragmentSpace;
31import denoptim.fragspace.FragmentSpaceParameters;
32import denoptim.graph.Candidate;
33import denoptim.graph.DGraph;
34import denoptim.programs.RunTimeParameters.ParametersType;
35import denoptim.programs.denovo.GAParameters;
47public class Population extends ArrayList<Candidate> implements Cloneable
89 boolean result = super.add(c);
110 return super.set(index, c);
119 return super.remove(index);
125 public boolean remove(Object c)
127 boolean result = super.remove(c);
138 boolean result = super.removeAll(c);
158 boolean result = super.retainAll(c);
213 LinkedHashMap<Candidate,List<XoverSite>>>
data;
233 List<XoverSite> xoversite)
235 if (
data.containsKey(c1))
237 data.get(c1).put(c2, xoversite);
239 LinkedHashMap<Candidate,List<XoverSite>> toC1 =
240 new LinkedHashMap<Candidate,List<XoverSite>>();
241 toC1.put(c2, xoversite);
245 List<XoverSite> revPairs =
246 new ArrayList<XoverSite>();
250 revPairs.add(revPair);
253 if (
data.containsKey(c2))
255 data.get(c2).put(c1, revPairs);
257 LinkedHashMap<Candidate,List<XoverSite>> toC2 =
258 new LinkedHashMap<Candidate,List<XoverSite>>();
259 toC2.put(c1, revPairs);
272 if (
data.containsKey(c1))
274 return data.get(c1).get(c2);
287 List<Candidate> compatibleMembers =
new ArrayList<Candidate>();
288 if (
data.keySet().contains(cA))
292 if (!
data.get(cA).get(cB).isEmpty())
294 compatibleMembers.add(cB);
298 return compatibleMembers;
314 return data.keySet().contains(memberA) &&
315 data.get(memberA).containsKey(memberB);
325 for (LinkedHashMap<
Candidate, List<XoverSite>> m :
342 LinkedHashMap<Candidate, List<XoverSite>> inner =
343 new LinkedHashMap<Candidate, List<XoverSite>>();
346 List<XoverSite> lst =
new ArrayList<XoverSite>();
349 lst.add(arr.clone());
353 cloned.
data.put(c1, inner);
377 for (
Candidate memberB : eligibleParents)
379 if (memberA == memberB)
389 DGraph gB = memberB.getGraph();
391 if (gA.
sameAs(gB,
new StringBuilder()))
403 +
"crossover sites between " + memberA.
getName()
404 +
" and " + memberB.getName() +
".");
435 public void trim(
int populationSize)
500 double threshold = (1.0 - percentile) * (max-min);
502 if (value > (threshold+min))
518 .filter(candidate -> name.equals(candidate.getName()))
Class defining a space of building blocks.
boolean useAPclassBasedApproach()
Check usage of APClass-based approach, i.e., uses attachment points with annotated data (i....
Parameters defining the fragment space.
FragmentSpace getFragmentSpace()
Collection of operators meant to alter graphs and associated utilities.
static List< XoverSite > locateCompatibleXOverPoints(DGraph graphA, DGraph graphB, FragmentSpace fragSpace, int maxSizeXoverSubGraph)
Identify crossover sites, i.e., subgraphs that can be swapped between two graphs (i....
A data structure collecting crossover-compatible sites.
XoverSitesAmongCandidates()
Initializes an empty data structure.
LinkedHashMap< Candidate, LinkedHashMap< Candidate, List< XoverSite > > > data
boolean contains(Candidate memberA, Candidate memberB)
Check is this data structure contains information about the combination of the given members.
void remove(Candidate c)
removes all references to the specified candidate.
void put(Candidate c1, Candidate c2, List< XoverSite > xoversite)
Creates the entry corresponding to the pair of given candidates.
List< Candidate > getMembersCompatibleWith(Candidate cA)
Returns a list of items that has crossover sites with the given item.
XoverSitesAmongCandidates clone()
Return a somewhat-shallow clone of this object: the map and list are new objects, but the references ...
List< XoverSite > get(Candidate c1, Candidate c2)
Gets the value corresponding to the pair of keys in the given order.
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.
GAParameters settings
Parameters controlling the GA experiment.
List< Candidate > getXoverPartners(Candidate memberA, List< Candidate > eligibleParents, FragmentSpace fragSpace)
Returns a list of population members that can do crossover with the specified member.
XoverSitesAmongCandidates xoverCompatibilities
Crossover compatibility between members.
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.
boolean removeAll(Collection<?> c)
Population(GAParameters settings)
Population clone()
Does not clone the cross-over compatibility relations between each pairs of population members.
boolean retainAll(Collection<?> c)
static final long serialVersionUID
Version UID.
Candidate getMinFitnessMember()
Gets the Candidate with minimum value of the fitness in this population.
Candidate getCandidateNamed(String name)
Returns the candidate with the given name, if present, or null.
AtomicInteger populationUpdate
An integer that changes every time we change the population.
void trim(int populationSize)
Removes all the elements exceeding the given size.
void add(int index, Candidate c)
double getMaxFitness()
Gets the maximum value of the fitness in this population.
This class collects the data identifying the subgraphs that would be swapped by a crossover event.
XoverSite createMirror()
Creates a new XoverSite that considers the opposite order of candidates of this one.
A candidate is the combination of a denoptim graph with molecular representation and may include also...
Container for the list of vertices and the edges that connect them.
boolean sameAs(DGraph other, StringBuilder reason)
Compare this and another graph ignoring the vertex IDs.
RunTimeParameters getParameters(ParametersType type)
Logger getLogger()
Get the name of the program specific logger.
Parameters for genetic algorithm.
int maxXOverableSubGraphSize
Limit to the size of subgraphs that are exchanged during crossover.
Identifier of the type of parameters.
FS_PARAMS
Parameters pertaining the definition of the fragment space.