All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sourceforge.cilib.util.selection.recipes.RouletteWheelSelector Maven / Gradle / Ivy

Go to download

A library of composable components enabling simpler Computational Intelligence

There is a newer version: 0.8
Show newest version
/**           __  __
 *    _____ _/ /_/ /_    Computational Intelligence Library (CIlib)
 *   / ___/ / / / __ \   (c) CIRG @ UP
 *  / /__/ / / / /_/ /   http://cilib.net
 *  \___/_/_/_/_.___/
 */
package net.sourceforge.cilib.util.selection.recipes;

import net.sourceforge.cilib.util.selection.PartialSelection;
import net.sourceforge.cilib.util.selection.Selection;
import net.sourceforge.cilib.util.selection.arrangement.ProportionalArrangement;
import net.sourceforge.cilib.util.selection.arrangement.ReverseArrangement;
import net.sourceforge.cilib.util.selection.arrangement.SortedArrangement;
import net.sourceforge.cilib.util.selection.weighting.LinearWeighting;
import net.sourceforge.cilib.util.selection.weighting.Weighting;

/**
 * A recipe for Roulette wheel selection.
 * 

* Roulette wheel selection is performed by: *

    *
  1. Weighing the elements of a selection.
  2. *
  3. Performing a proportional ordering of the weighed elements.
  4. *
  5. Returning the best result.
  6. *
* @param The selection type. */ public class RouletteWheelSelector implements Selector { private static final long serialVersionUID = 4194450350205390514L; private Weighting weighting; /** * Create a new instance. */ public RouletteWheelSelector() { this.weighting = new LinearWeighting(); } /** * Create a new instance with the provided weighing strategy. * @param weighing The weighing strategy to set. */ public RouletteWheelSelector(Weighting weighing) { this.weighting = weighing; } /** * Create a copy of the provided instance. * @param copy The instance to copy. */ public RouletteWheelSelector(RouletteWheelSelector copy) { this.weighting = copy.weighting; } /** * Set the weighing strategy * @param weighing The strategy to set. */ public void setWeighing(Weighting weighing) { this.weighting = weighing; } /** * Get the current weighing strategy. * @return The current weighing strategy. */ public Weighting getWeighing() { return this.weighting; } /** * {@inheritDoc} */ @Override public PartialSelection on(Iterable iterable) { return Selection.copyOf(iterable).weigh(weighting) .orderBy(new SortedArrangement()) .orderBy(new ProportionalArrangement()) .orderBy(new ReverseArrangement()); } }




© 2015 - 2025 Weber Informatics LLC | Privacy Policy