org.cpsolver.ifs.heuristics

## Class RouletteWheelSelection<E>

- java.lang.Object
- - org.cpsolver.ifs.heuristics.RouletteWheelSelection<E>

- Type Parameters:
    `E` - Class of objects that are to be selected from.
  All Implemented Interfaces:
    Enumeration<E>

      public class RouletteWheelSelection<E>
      extends Object
      implements Enumeration<E>

  A general roulette wheel selection. An object is selected randomly, proportionaly to the provided weight. This class also supports multiple selections (it implements `Enumeration` interface).
  Version:
    StudentSct 1.3 (Student Sectioning)
    Copyright (C) 2007 - 2014 Tomáš Müller
    muller@unitime.org
    http://muller.unitime.org
    This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
    This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
    You should have received a copy of the GNU Lesser General Public License along with this library; if not see http://www.gnu.org/licenses/.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `RouletteWheelSelection()`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `add(E adept, double points)` Add an adept to the selection
    `void` | `addExisting(E adept, double points)` Add an adept to the selection.
    `double` | `getRemainingPoints()` Total value of objects that are still in the selection.
    `double` | `getTotalPoints()` Total value of objects that were added into the selection.
    `double` | `getUsedPoints()` Total value of objects that were already returned by the selection.
    `boolean` | `hasMoreElements()` Are there still some adepts that have not been yet selected
    `E` | `nextElement()` Perform selection.
    `int` | `size()` Number of objects in the set

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### RouletteWheelSelection

          public RouletteWheelSelection()

  - ### Method Detail

    - #### add

          public void add(E adept,
                          double points)

      Add an adept to the selection
      Parameters:
        `adept` - an object
        `points` - object weight (more points, better chance to be selected)

    - #### addExisting

          public void addExisting(E adept,
                                  double points)

      Add an adept to the selection. Only increase points when the adept already exist in the selection.
      Parameters:
        `adept` - an object
        `points` - object weight (more points, better chance to be selected)

    - #### hasMoreElements

          public boolean hasMoreElements()

      Are there still some adepts that have not been yet selected
      Specified by:
        `hasMoreElements` in interface `Enumeration<E>`

    - #### nextElement

          public E nextElement()

      Perform selection. An object is selected randomly with the probability proportional to the provided weight. Each object can be selected only once.
      Specified by:
        `nextElement` in interface `Enumeration<E>`

    - #### size

          public int size()

      Number of objects in the set
      Returns:
        number of objects in the set

    - #### getUsedPoints

          public double getUsedPoints()

      Total value of objects that were already returned by the selection.
      Returns:
        total value of objects that were already returned by the selection

    - #### getRemainingPoints

          public double getRemainingPoints()

      Total value of objects that are still in the selection.
      Returns:
        total value of objects that are still in the selection

    - #### getTotalPoints

          public double getTotalPoints()

      Total value of objects that were added into the selection.
      Returns:
        total value of objects that were added into the selection