コード例 #1
0
  /**
   * Structure of Dynamic Heterogeneous iteration strategy:
   *
   * <ol>
   *   <li>For each particle:
   *   <li>Check if particle must change its behavior
   *   <li>If particle must change its behavior:
   *       <ol>
   *         <li>Select a new behavior to the particle from the behavior pool
   *       </ol>
   *   <li>Perform normal iteration
   * </ol>
   *
   * @see
   *     net.sourceforge.cilib.pso.iterationstrategies.SynchronousIterationStrategy#performIteration()
   */
  @Override
  public void performIteration(PSO algorithm) {
    checkState(
        behaviorPool.size() > 0, "You must add particle behaviors to the behavior pool first.");

    for (Entity e : algorithm.getTopology()) {
      Particle p = (Particle) e;

      if (detectionStrategy.detect(p)) {
        p.setParticleBehavior(behaviorSelectionRecipe.on(behaviorPool).select());
      }
    }

    iterationStrategy.performIteration(algorithm);
  }