@Test public void testChoose() { final GreedyComponentSelector instance = new GreedyComponentSelector(); instance.setup(state, BASE); final List<Component> components = new ArrayList<Component>(); components.add(new KnapsackComponent(23, 92)); components.add(new KnapsackComponent(31, 57)); components.add(new KnapsackComponent(29, 49)); final Component expResult = new KnapsackComponent(23, 92); final Component result = instance.choose(state, components, null, 0); assertEquals(expResult, result); assertTrue(instance.repOK()); }
@Override public Component choose(final EvolutionState state, final List<Component> components, final PheromoneTable pheromones, final int thread) { assert(components != null); assert(!components.isEmpty()); assert(!Misc.containsNulls(components)); double bestValue = Double.NEGATIVE_INFINITY; Component best = null; for (final Component c : components) { if (c.desirability() >= bestValue) { bestValue = c.desirability(); best = c; } } assert(best != null); return best; }
GreedyComponentSelector implements ComponentSelector { @Override public Component choose(final EvolutionState state, final List<Component> components, final PheromoneTable pheromones, final int thread) { assert(components != null); assert(!components.isEmpty()); assert(!Misc.containsNulls(components)); double bestValue = Double.NEGATIVE_INFINITY; Component best = null; for (final Component c : components) { if (c.desirability() >= bestValue) { bestValue = c.desirability(); best = c; } } assert(best != null); return best; } }
GreedyComponentSelector implements ComponentSelector { @Override public Component choose(final EvolutionState state, final List<Component> components, final PheromoneTable pheromones, final int thread) { assert(components != null); assert(!components.isEmpty()); assert(!Misc.containsNulls(components)); double bestValue = Double.NEGATIVE_INFINITY; Component best = null; for (final Component c : components) { if (c.desirability() >= bestValue) { bestValue = c.desirability(); best = c; } } assert(best != null); return best; } GreedyComponentSelector(); }
GreedyComponentSelector implements ComponentSelector { @Override public Component choose(final EvolutionState state, final List<Component> components, final PheromoneTable pheromones, final int thread) { assert(components != null); assert(!components.isEmpty()); assert(!Misc.containsNulls(components)); double bestValue = Double.NEGATIVE_INFINITY; Component best = null; for (final Component c : components) { if (c.desirability() >= bestValue) { bestValue = c.desirability(); best = c; } } assert(best != null); return best; } GreedyComponentSelector(); void setup(final EvolutionState state, final Parameter base); @Override Component choose(final EvolutionState state, final List<Component> components, final PheromoneTable pheromones, final int thread); final boolean repOK(); }
GreedyComponentSelector implements ComponentSelector { @Override public Component choose(final EvolutionState state, final List<Component> components, final PheromoneTable pheromones, final int thread) { assert(components != null); assert(!components.isEmpty()); assert(!Misc.containsNulls(components)); double bestValue = Double.NEGATIVE_INFINITY; Component best = null; for (final Component c : components) { if (c.desirability() >= bestValue) { bestValue = c.desirability(); best = c; } } assert(best != null); return best; } GreedyComponentSelector(); void setup(final EvolutionState state, final Parameter base); @Override Component choose(final EvolutionState state, final List<Component> components, final PheromoneTable pheromones, final int thread); final boolean repOK();  }