org.cpsolver.ifs.heuristics

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

- java.lang.Object
- - org.cpsolver.ifs.assignment.context.NeighbourSelectionWithContext<V,T,MaxIdleNeighbourSelection.MaxIdleContext>
  - - org.cpsolver.ifs.heuristics.MaxIdleNeighbourSelection<V,T>

- Type Parameters:
    `V` - Variable
    `T` - Value
  All Implemented Interfaces:
    CanHoldContext, HasAssignmentContext<V,T,MaxIdleNeighbourSelection.MaxIdleContext>, NeighbourSelection<V,T>, SolutionListener<V,T>

      public class MaxIdleNeighbourSelection<V extends Variable<V,T>,T extends Value<V,T>>
      extends NeighbourSelectionWithContext<V,T,MaxIdleNeighbourSelection.MaxIdleContext>
      implements SolutionListener<V,T>

  Simple extension of a provided `NeighbourSelection` that halts the construction heuristic or the IFS search when the underlying heuristic is unable to improve the number of assigned variables. When a given number of non-improving iterations is reached, the `MaxIdleNeighbourSelection` extension starts returning null. The counter gets automatically reset every time a solution with more variables assigned is stored as best solution.
  Version:
    IFS 1.4 (Iterative Forward Search)
    Copyright (C) 2024 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.
  Author:
    Tomáš Müller
  See Also:
    `NeighbourSelection`

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `MaxIdleNeighbourSelection.MaxIdleContext`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected int` | `iBestAssigned`
    `protected int` | `iMaxIdle`
    `protected NeighbourSelection<V,T>` | `iParent`
    `protected ConflictStatistics<V,T>` | `iStat`
    `protected long` | `iTimeOut`

    - ### Fields inherited from class org.cpsolver.ifs.assignment.context.NeighbourSelectionWithContext

      `iContextOverride`

    - ### Fields inherited from interface org.cpsolver.ifs.assignment.context.CanHoldContext

      `sMaxSize`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `MaxIdleNeighbourSelection(DataProperties properties, NeighbourSelection<V,T> parent, int maxIdle)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `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.
    `MaxIdleNeighbourSelection.MaxIdleContext` | `createAssignmentContext(Assignment<V,T> assignment)` Create a new assignment context for the given assignment.
    `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()`.
    `void` | `init(Solver<V,T> solver)` Criterion initialization
    `Neighbour<V,T>` | `selectNeighbour(Solution<V,T> solution)` select a neighbour of a given solution
    `void` | `solutionUpdated(Solution<V,T> solution)` Called by the solution when it is updated, see `Solution.update(double)`.

    - ### Methods inherited from class org.cpsolver.ifs.assignment.context.NeighbourSelectionWithContext

      `getAssignmentContextReference, getContext, getContext, hasContextOverride, isSingleContextSolver, setAssignmentContextReference`

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

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

- - ### Field Detail

    - #### iParent

          protected NeighbourSelection<V extends Variable<V,T>,T extends Value<V,T>> iParent

    - #### iMaxIdle

          protected int iMaxIdle

    - #### iBestAssigned

          protected int iBestAssigned

    - #### iStat

          protected ConflictStatistics<V extends Variable<V,T>,T extends Value<V,T>> iStat

    - #### iTimeOut

          protected long iTimeOut

  - ### Constructor Detail

    - #### MaxIdleNeighbourSelection

          public MaxIdleNeighbourSelection(DataProperties properties,
                                           NeighbourSelection<V,T> parent,
                                           int maxIdle)

  - ### Method Detail

    - #### init

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

      Description copied from interface: `NeighbourSelection`
      Criterion initialization
      Specified by:
        `init` in interface `NeighbourSelection<V extends Variable<V,T>,T extends Value<V,T>>`
      Overrides:
        `init` in class `NeighbourSelectionWithContext<V extends Variable<V,T>,T extends Value<V,T>,MaxIdleNeighbourSelection.MaxIdleContext>`
      Parameters:
        `solver` - current solver

    - #### 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

    - #### 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

    - #### 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

    - #### selectNeighbour

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

      Description copied from interface: `NeighbourSelection`
      select a neighbour of a given solution
      Specified by:
        `selectNeighbour` in interface `NeighbourSelection<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `solution` - given solution
      Returns:
        a neighbour assignment

    - #### createAssignmentContext

          public MaxIdleNeighbourSelection.MaxIdleContext createAssignmentContext(Assignment<V,T> assignment)

      Description copied from interface: `HasAssignmentContext`
      Create a new assignment context for the given assignment. If there are already some variables assigned in the value, the method should make sure that the context is appropriately initialized.
      Specified by:
        `createAssignmentContext` in interface `HasAssignmentContext<V extends Variable<V,T>,T extends Value<V,T>,MaxIdleNeighbourSelection.MaxIdleContext>`
      Parameters:
        `assignment` - an assignment for which there needs to be an assignment context
      Returns:
        a new instance of the assignment context, filled according to the given assignment