MaxMinUpdateRule implements UpdateRule { @Override public void updatePheromones(final EvolutionState state, final PheromoneTable pheromones, final List individuals) { assert(pheromones != null); assert(individuals != null); assert(!individuals.isEmpty()); decayPheromones(state, pheromones); updateBest(individuals); assert(best.size() > 0); final double delta_pheromone = best.fitness.fitness(); for (final Object oo : best) { assert(oo instanceof Component); final Component c = (Component) oo; final double oldPheromone = pheromones.get(state, c, 0); pheromones.set(c, (1-rho)*oldPheromone + rho*delta_pheromone); } assert(repOK()); }  BestStrategy getBestStrategy(); double getRho(); @Override void setup(final EvolutionState state, final Parameter base); @Override void updatePheromones(final EvolutionState state, final PheromoneTable pheromones, final List individuals); double getDecayRate(); final boolean repOK(); final static String P_RHO; final static String P_BEST_STRATEGY; final static String P_MAX; final static String P_MIN; final static String P_DECAY_RATE; }
@Test public void testUpdatePheromones() { MaxMinUpdateRule instance = new MaxMinUpdateRule(); instance.setup(state, BASE); final Subpopulation subpop = new Subpopulation(); subpop.individuals = new ArrayList<Individual>() {{ add(createKnapsackInd(new int[] { 1, 2, 3, 4 }, 500.0)); add(createKnapsackInd(new int[] { 1, 2, 3, 4 }, 1000.0)); add(createKnapsackInd(new int[] { 0, 3, 6, 8 }, 700.0)); add(createKnapsackInd(new int[] { 9, 3, 1, 1}, 800.0)); }}; instance.updatePheromones(state, pheromones, subpop.individuals); final List<Component> pComponents = problem.getAllComponents(); assertEquals(50.0, pheromones.get(state, pComponents.get(0), 0), 0.00000001); assertEquals(335.0, pheromones.get(state, pComponents.get(1), 0), 0.00000001); assertEquals(335.0, pheromones.get(state, pComponents.get(2), 0), 0.00000001); assertEquals(335.0, pheromones.get(state, pComponents.get(3), 0), 0.00000001); assertEquals(335.0, pheromones.get(state, pComponents.get(4), 0), 0.00000001); assertEquals(50.0, pheromones.get(state, pComponents.get(5), 0), 0.00000001); assertEquals(50.0, pheromones.get(state, pComponents.get(6), 0), 0.00000001); assertEquals(50.0, pheromones.get(state, pComponents.get(7), 0), 0.00000001); assertEquals(50.0, pheromones.get(state, pComponents.get(8), 0), 0.00000001); assertEquals(50.0, pheromones.get(state, pComponents.get(9), 0), 0.00000001); }