org.cpsolver.ifs.algorithms

## Class NeighbourSearch.NeighbourSearchContext

- java.lang.Object
- - org.cpsolver.ifs.algorithms.NeighbourSearch.NeighbourSearchContext

- All Implemented Interfaces:
    AssignmentContext, SolutionListener<V,T>
  Direct Known Subclasses:
    GreatDeluge.GreatDelugeContext, HillClimber.HillClimberContext, SimulatedAnnealing.SimulatedAnnealingContext
  Enclosing class:
    NeighbourSearch<V extends Variable<V,T>,T extends Value<V,T>>

      public abstract class NeighbourSearch.NeighbourSearchContext
      extends Object
      implements AssignmentContext, SolutionListener<V,T>

  Search context

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected int` | `iIter`
    `protected long` | `iT0`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `NeighbourSearchContext()`

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected abstract boolean` | `accept(Assignment<V,T> assignment, Model<V,T> model, Neighbour<V,T> neighbour, double value, boolean lazy)` Acceptance criterion.
    `protected void` | `activate(Solution<V,T> solution)` Called just before the neighbourhood search is called for the first time.
    `void` | `bestCleared(Solution<V,T> solution)` Called by the solution when method `Solution.clearBest()` is called.
    `void` | `bestRestored(Solution<V,T> solution)` Called by the solution when method `Solution.restoreBest()` is called.
    `void` | `bestSaved(Solution<V,T> solution)` Called by the solution when method `Solution.saveBest()` is called.
    `protected boolean` | `canContinue(Solution<V,T> solution)` Return false if the search is to be stopped.
    `protected void` | `deactivate(Solution<V,T> solution)` Called when the search cannot continue, just before a null neighbour is returned
    `void` | `getInfo(Solution<V,T> solution, Map<String,String> info)` Called by the solution when it is asked to produce info table, see `Solution.getInfo()`.
    `void` | `getInfo(Solution<V,T> solution, Map<String,String> info, Collection<V> variables)` Called by the solution when it is asked to produce info table, see `Solution.getInfo()`.
    `protected long` | `getTimeMillis()` Running time in milliseconds (since the last call of activate)
    `protected void` | `incIteration(Solution<V,T> solution)` Increment iteration counters etc.
    `void` | `solutionUpdated(Solution<V,T> solution)` Called by the solution when it is updated, see `Solution.update(double)`.

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

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

- - ### Field Detail

    - #### iT0

          protected long iT0

    - #### iIter

          protected int iIter

  - ### Constructor Detail

    - #### NeighbourSearchContext

          public NeighbourSearchContext()

  - ### Method Detail

    - #### activate

          protected void activate(Solution<V,T> solution)

      Called just before the neighbourhood search is called for the first time.
      Parameters:
        `solution` - current solution

    - #### deactivate

          protected void deactivate(Solution<V,T> solution)

      Called when the search cannot continue, just before a null neighbour is returned
      Parameters:
        `solution` - current solution

    - #### incIteration

          protected void incIteration(Solution<V,T> solution)

      Increment iteration counters etc.
      Parameters:
        `solution` - current solution

    - #### getTimeMillis

          protected long getTimeMillis()

      Running time in milliseconds (since the last call of activate)
      Returns:
        running time

    - #### canContinue

          protected boolean canContinue(Solution<V,T> solution)

      Return false if the search is to be stopped. Null neighbour is returned when this method returns false.
      Parameters:
        `solution` - current solution
      Returns:
        true if can continue

    - #### accept

          protected abstract boolean accept(Assignment<V,T> assignment,
                                            Model<V,T> model,
                                            Neighbour<V,T> neighbour,
                                            double value,
                                            boolean lazy)

      Acceptance criterion. If lazy, current assignment already contains the given neighbour.
      Parameters:
        `assignment` - current assignment
        `model` - problem model
        `neighbour` - a generated move
        `value` - value of the generated move (i.e., its impact on the solution value)
        `lazy` - true if lazy move
      Returns:
        true if the generated move is to be assigned

    - #### bestSaved

          public void bestSaved(Solution<V,T> solution)

      Description copied from interface: `SolutionListener`
      Called by the solution when method `Solution.saveBest()` is called.
      Specified by:
        `bestSaved` in interface `SolutionListener<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `solution` - source solution

    - #### solutionUpdated

          public void solutionUpdated(Solution<V,T> solution)

      Description copied from interface: `SolutionListener`
      Called by the solution when it is updated, see `Solution.update(double)`.
      Specified by:
        `solutionUpdated` in interface `SolutionListener<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `solution` - source solution

    - #### getInfo

          public void getInfo(Solution<V,T> solution,
                              Map<String,String> info)

      Description copied from interface: `SolutionListener`
      Called by the solution when it is asked to produce info table, see `Solution.getInfo()`. A listener can also add some its info into this table.
      Specified by:
        `getInfo` in interface `SolutionListener<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `solution` - source solution
        `info` - produced info table

    - #### getInfo

          public void getInfo(Solution<V,T> solution,
                              Map<String,String> info,
                              Collection<V> variables)

      Description copied from interface: `SolutionListener`
      Called by the solution when it is asked to produce info table, see `Solution.getInfo()`. A listener can also add some its info into this table.
      Specified by:
        `getInfo` in interface `SolutionListener<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `solution` - source solution
        `info` - produced info table
        `variables` - only variables from this set are included

    - #### bestCleared

          public void bestCleared(Solution<V,T> solution)

      Description copied from interface: `SolutionListener`
      Called by the solution when method `Solution.clearBest()` is called.
      Specified by:
        `bestCleared` in interface `SolutionListener<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `solution` - source solution

    - #### bestRestored

          public void bestRestored(Solution<V,T> solution)

      Description copied from interface: `SolutionListener`
      Called by the solution when method `Solution.restoreBest()` is called.
      Specified by:
        `bestRestored` in interface `SolutionListener<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `solution` - source solution