org.cpsolver.ifs.algorithms

## Class NeighbourSelector<V extends Variable<V,T>,T extends Value<V,T>>

- java.lang.Object
- - org.cpsolver.ifs.algorithms.NeighbourSelector<V,T>

- Type Parameters:
    `V` - Variable
    `T` - Value
  All Implemented Interfaces:
    NeighbourSelection<V,T>

      public class NeighbourSelector<V extends Variable<V,T>,T extends Value<V,T>>
      extends Object
      implements NeighbourSelection<V,T>

  A wrapper for `NeighbourSelection` that keeps some stats about the given neighbour selector.
  Version:
    IFS 1.3 (Iterative Forward Search)
    Copyright (C) 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/.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected static DecimalFormat` | `sDF`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `NeighbourSelector(NeighbourSelection<V,T> sel, double bonus, boolean update)` Constructor

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `double` | `getBonus()` Initial bonus
    `double` | `getPoints()` Weight of the selector in the roulette wheel selection of neighbour selectors
    `void` | `init(Solver<V,T> solver)` Initialization
    `int` | `nrCalls()` Number of calls of `NeighbourSelection.selectNeighbour(Solution)`
    `int` | `nrImprovingMoves()` Number of returned improving moves (i.e., `Neighbour.value(Assignment)` < 0)
    `int` | `nrNotNull()` Number of returned not-null moves
    `int` | `nrSideMoves()` Number of returned moves with zero improvement of the solution (i.e., `Neighbour.value(Assignment)` = 0)
    `NeighbourSelection<V,T>` | `selection()` Given neighbour selection
    `Neighbour<V,T>` | `selectNeighbour(Solution<V,T> solution)` Neighbour selection -- use `NeighbourSelection.selectNeighbour(Solution)` update stats if desired.
    `double` | `speed()` Average number of iterations per second (calls of `NeighbourSelection.selectNeighbour(Solution)`)
    `long` | `time()` Total time spend in `NeighbourSelection.selectNeighbour(Solution)` (in milliseconds)
    `String` | `toString()` String representation
    `void` | `update(Assignment<V,T> a, Neighbour<V,T> n, long time)` Update statistics

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

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

- - ### Field Detail

    - #### sDF

          protected static DecimalFormat sDF

  - ### Constructor Detail

    - #### NeighbourSelector

          public NeighbourSelector(NeighbourSelection<V,T> sel,
                                   double bonus,
                                   boolean update)

      Constructor
      Parameters:
        `sel` - neighbour selector
        `bonus` - initial bonus (default is 1, can be changed by @n parameter after the name of the selector in Xxx.Neigbours, e.g., org.cpsolver.itc.tim.neighbours.TimPrecedenceMove@0.1 for initial bonus 0.1
        `update` - update selector bonus after each iteration

  - ### Method Detail

    - #### init

          public void init(Solver<V,T> solver)

      Initialization
      Specified by:
        `init` in interface `NeighbourSelection<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `solver` - current solver

    - #### selectNeighbour

          public Neighbour<V,T> selectNeighbour(Solution<V,T> solution)

      Neighbour selection -- use `NeighbourSelection.selectNeighbour(Solution)` update stats if desired.
      Specified by:
        `selectNeighbour` in interface `NeighbourSelection<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `solution` - given solution
      Returns:
        a neighbour assignment

    - #### update

          public void update(Assignment<V,T> a,
                             Neighbour<V,T> n,
                             long time)

      Update statistics
      Parameters:
        `a` - current assignment
        `n` - generated move
        `time` - time needed to generate the move (in milliseconds)

    - #### getPoints

          public double getPoints()

      Weight of the selector in the roulette wheel selection of neighbour selectors
      Returns:
        weight of this selector

    - #### getBonus

          public double getBonus()

      Initial bonus
      Returns:
        initial bonus

    - #### selection

          public NeighbourSelection<V,T> selection()

      Given neighbour selection
      Returns:
        given neighbour selection

    - #### nrCalls

          public int nrCalls()

      Number of calls of `NeighbourSelection.selectNeighbour(Solution)`
      Returns:
        number of calls

    - #### nrNotNull

          public int nrNotNull()

      Number of returned not-null moves
      Returns:
        number of not-null moves

    - #### nrSideMoves

          public int nrSideMoves()

      Number of returned moves with zero improvement of the solution (i.e., `Neighbour.value(Assignment)` = 0)
      Returns:
        number of side moves (value = 0)

    - #### nrImprovingMoves

          public int nrImprovingMoves()

      Number of returned improving moves (i.e., `Neighbour.value(Assignment)` < 0)
      Returns:
        number of improving moves (value < 0)

    - #### time

          public long time()

      Total time spend in `NeighbourSelection.selectNeighbour(Solution)` (in milliseconds)
      Returns:
        total time spend in theis selector

    - #### speed

          public double speed()

      Average number of iterations per second (calls of `NeighbourSelection.selectNeighbour(Solution)`)
      Returns:
        number of calls per second

    - #### toString

          public String toString()

      String representation
      Overrides:
        `toString` in class `Object`