/**
   * 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;
  }
Пример #2
0
  /**
   * 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 <T extends Entity> Vector determineDistanceVector(List<T> participants) {
    Vector distanceVector = Vector.fill(0.0, participants.get(0).getCandidateSolution().size());
    Iterator<T> iterator = participants.iterator();

    while (iterator.hasNext()) {
      Vector first = (Vector) iterator.next().getCandidateSolution();
      Vector second = (Vector) iterator.next().getCandidateSolution();

      Vector difference = first.subtract(second);
      distanceVector = distanceVector.plus(difference);
    }

    return distanceVector;
  }