コード例 #1
0
  /**
   * Returns the new position
   *
   * @param particle The particle to update
   * @return the particle's new position
   */
  @Override
  public Vector get(Particle particle) {
    particle.setPositionProvider(new LinearPositionProvider());

    Vector solution = (Vector) particle.getCandidateSolution();
    Vector pBest = (Vector) particle.getBestPosition();
    Vector nBest = (Vector) particle.getNeighbourhoodBest().getBestPosition();

    Set<Vector> solutions = new HashSet<Vector>(Arrays.asList(solution, pBest, nBest));

    if (solutions.size() == 3) {
      return applyCrossover(particle, Lists.newLinkedList(solutions), mainCrossover);
    }

    Vector prevPos = (Vector) particle.getProperties().get(EntityType.PREVIOUS_SOLUTION);
    solutions.add(prevPos);

    if (solutions.size() == 3) {
      return applyCrossover(particle, Lists.newLinkedList(solutions), mainCrossover);
    }

    if (solutions.size() == 2) {
      return applyCrossover(particle, Lists.newLinkedList(solutions), alternateCrossover);
    }

    particle.setPositionProvider(new StandardPositionProvider());
    return delegate.get(particle);
  }