/** {@inheritDoc} */ @Override public <T extends Entity> T create(T targetEntity, T current, Topology<T> topology) { T bestEntity = Topologies.getBestEntity(topology); List<T> participants = Selection.copyOf(topology) .exclude(targetEntity, bestEntity, current) .orderBy(new RandomArrangement()) .select(Samples.first((int) numberOfDifferenceVectors.getParameter()).unique()); Vector differenceVector = determineDistanceVector(participants); Vector targetVector = ((Vector) targetEntity.getCandidateSolution()) .multiply(1 - greedynessParameter.getParameter()); Vector bestVector = ((Vector) bestEntity.getCandidateSolution()).multiply(greedynessParameter.getParameter()); Vector trialVector = bestVector.plus( targetVector.plus(differenceVector.multiply(scaleParameter.getParameter()))); T trialEntity = (T) current.getClone(); trialEntity.setCandidateSolution(trialVector); return trialEntity; }
/** * Calculate the {@linkplain Vector} that is the resultant of several difference vectors. * * @param participants The {@linkplain Entity} list to create the difference vectors from. It is * very important to note that the {@linkplain Entity} objects within this list should not * contain duplicates. If duplicates are contained, this will severely reduce the diversity of * the population as not all entities will be considered. * @return A {@linkplain Vector} representing the resultant of all calculated difference vectors. */ protected Vector determineDistanceVector(List<Entity> participants) { RandomProvider random = new MersenneTwister(); Vector distanceVector = Vector.fill(0.0, participants.get(0).getCandidateSolution().size()); Iterator<Entity> iterator; int number = Double.valueOf(this.numberOfDifferenceVectors.getParameter()).intValue(); List<Entity> currentParticipants; Vector first, second; double difference; for (int d = 0; d < distanceVector.size(); d++) { // get random participants for this dimension currentParticipants = (List<Entity>) Selection.copyOf(participants) .orderBy(new RandomArrangement(random)) .select(Samples.first(number)); iterator = currentParticipants.iterator(); while (iterator.hasNext()) { first = (Vector) iterator.next().getCandidateSolution(); second = (Vector) iterator.next().getCandidateSolution(); difference = first.doubleValueOf(d) - second.doubleValueOf(d); distanceVector.setReal(d, distanceVector.get(d).doubleValue() + difference); } } return distanceVector; }
/** {@inheritDoc} */ @Override public <T extends Entity> T create(T targetEntity, T current, fj.data.List<T> topology) { int number = Double.valueOf(this.numberOfDifferenceVectors.getParameter()).intValue(); List<T> participants = Selection.copyOf(topology) .exclude(targetEntity, current) .orderBy(new RandomArrangement()) .select(Samples.first(number).unique()); Vector differenceVector = determineDistanceVector(participants); Vector targetVector = (Vector) targetEntity.getCandidateSolution(); Vector trialVector = targetVector.plus( differenceVector.multiply( new P1<Number>() { @Override public Number _1() { return scaleParameter.getParameter(); } })); T trialEntity = (T) current.getClone(); trialEntity.setCandidateSolution(trialVector); return trialEntity; }
/** * Reevaluate a specified percentage of the given entities. * * @param entities a {@link List} of entities that should be considered for * reevaluation * @param reevaluateCount an <code>int<code> specifying how many entities should be * reevaluated */ protected void reevaluate(List<? extends Entity> entities, int reevaluateCount) { RandomSelector selector = new RandomSelector(); List<? extends Entity> subList = selector.on(entities).select(Samples.first(reevaluateCount)); for (Entity entity : subList) { // FIXME: does not reevaluate the _best_ positon. entity.calculateFitness(); } }
/** {@inheritDoc} */ @Override public Entity create(Entity targetEntity, Entity current, Topology<? extends Entity> topology) { List<Entity> participants = (List<Entity>) Selection.copyOf(topology).exclude(targetEntity, current).select(Samples.all()); Vector differenceVector = determineDistanceVector(participants); Vector targetVector = (Vector) targetEntity.getCandidateSolution(); Vector trialVector = targetVector.plus( differenceVector.multiply( new P1<Number>() { @Override public Number _1() { return scaleParameter.getParameter(); } })); Entity trialEntity = current.getClone(); trialEntity.setCandidateSolution(trialVector); return trialEntity; }