/** {@inheritDoc} */
  @Override
  public int compare(E o1, E o2) {
    SinglePopulationBasedAlgorithm populationBasedAlgorithm =
        (SinglePopulationBasedAlgorithm) AbstractAlgorithm.getAlgorithmList().index(0);
    MOOptimisationProblem problem =
        ((MOOptimisationProblem) populationBasedAlgorithm.getOptimisationProblem());

    Particle p1 = (Particle) o1;
    Particle p2 = (Particle) o2;
    MOFitness fitness1 = ((MOFitness) problem.getFitness(p1.getBestPosition()));
    MOFitness fitness2 = ((MOFitness) problem.getFitness(p2.getBestPosition()));

    int value = fitness1.compareTo(fitness2);
    if (fitness1.compareTo(fitness2) == 0) {
      int random = Rand.nextInt(20);
      if (random > 10) value *= -1;
    }
    return value;
  }
  /**
   * This is an Synchronous strategy:
   *
   * <ol>
   *   <li>For all particles:
   *       <ol>
   *         <li>Update the particle velocity
   *         <li>Update the particle position
   *       </ol>
   *   <li>For all particles:
   *       <ol>
   *         <li>Calculate the particle fitness
   *         <li>For all particles in the current particle's neighbourhood:
   *             <ol>
   *               <li>Update the neighbourhood best
   *             </ol>
   *       </ol>
   * </ol>
   *
   * @see
   *     net.sourceforge.cilib.PSO.IterationStrategy#performIteration(net.sourceforge.cilib.PSO.PSO)
   * @param pso The {@link PSO} to have an iteration applied.
   */
  @Override
  public void performIteration(PSO pso) {
    Topology<Particle> topology = pso.getTopology();

    for (Particle current : topology) {
      current.updateVelocity();
      current.updatePosition(); // TODO: replace with visitor (will simplify particle interface)

      boundaryConstraint.enforce(current);
    }

    Problem problem = AbstractAlgorithm.getAlgorithmList().get(0).getOptimisationProblem();

    for (Particle current : topology) {
      current.calculateFitness();
      for (Particle other : topology.neighbourhood(current)) {
        Particle p1 = current.getNeighbourhoodBest().getClone();
        Particle p2 = other.getNeighbourhoodBest().getClone();
        OptimisationSolution s1 =
            new OptimisationSolution(
                p1.getCandidateSolution().getClone(),
                problem.getFitness(p1.getCandidateSolution().getClone()));
        OptimisationSolution s2 =
            new OptimisationSolution(
                p2.getCandidateSolution().getClone(),
                problem.getFitness(p2.getCandidateSolution().getClone()));
        MOFitness fitness1 = (MOFitness) s1.getFitness();
        MOFitness fitness2 = (MOFitness) s2.getFitness();
        //                System.out.println("fitness1 = ");
        //                for (int i=0; i < fitness1.getDimension(); i++)
        //                    System.out.println(fitness1.getFitness(i).getValue());
        //
        //                System.out.println("fitness2 = ");
        //                for (int i=0; i < fitness2.getDimension(); i++)
        //                    System.out.println(fitness2.getFitness(i).getValue());
        if (fitness1.compareTo(fitness2) > 0) {
          other.setNeighbourhoodBest(current);
        }
      }
    }
  }