org.cpsolver.ifs.algorithms

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

- java.lang.Object
- - org.cpsolver.ifs.assignment.context.NeighbourSelectionWithContext<V,T,NeighbourSearch.NeighbourSearchContext>
  - - org.cpsolver.ifs.algorithms.NeighbourSearch<V,T>
    - - org.cpsolver.ifs.algorithms.HillClimber<V,T>

- Type Parameters:
    `V` - Variable
    `T` - Value
  All Implemented Interfaces:
    CanHoldContext, HasAssignmentContext<V,T,NeighbourSearch.NeighbourSearchContext>, NeighbourSelection<V,T>, LazyNeighbour.LazyNeighbourAcceptanceCriterion<V,T>, SolutionListener<V,T>
  Direct Known Subclasses:
    StepCountingHillClimber

      public class HillClimber<V extends Variable<V,T>,T extends Value<V,T>>
      extends NeighbourSearch<V,T>

  Hill climber. In each iteration, one of the given neighbourhoods is selected first, then a neighbour is generated and it is accepted if its value `Neighbour.value(Assignment)` is below or equal to zero. The search is stopped after a given amount of idle iterations ( can be defined by problem property HillClimber.MaxIdle).
  Custom neighbours can be set using HillClimber.Neighbours property that should contain semicolon separated list of `NeighbourSelection`. By default, each neighbour selection is selected with the same probability (each has 1 point in a roulette wheel selection). It can be changed by adding @n at the end of the name of the class, for example:

       HillClimber.Neighbours=org.cpsolver.ifs.algorithms.neighbourhoods.RandomMove;org.cpsolver.ifs.algorithms.neighbourhoods.RandomSwapMove@0.1

  Selector RandomSwapMove is 10× less probable to be selected than other selectors. When HillClimber.Random is true, all selectors are selected with the same probability, ignoring these weights.
  When HillClimber.Update is true, `NeighbourSelector.update(Assignment, Neighbour, long)` is called after each iteration (on the selector that was used) and roulette wheel selection that is using `NeighbourSelector.getPoints()` is used to pick a selector in each iteration. See `NeighbourSelector` for more details.
  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/.
  Author:
    Tomáš Müller

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `HillClimber.HillClimberContext`

    - ### Nested classes/interfaces inherited from class org.cpsolver.ifs.algorithms.NeighbourSearch

      `NeighbourSearch.NeighbourSearchContext`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected int` | `iMaxIdleIters`
    `protected boolean` | `iSetHCMode`
    `protected static double` | `sEPS`

    - ### Fields inherited from class org.cpsolver.ifs.algorithms.NeighbourSearch

      `iDF2, iPhase`

    - ### 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
    `HillClimber(DataProperties properties)` Constructor HillClimber.MaxIdle ... maximum number of idle iterations (default is 200000) HillClimber.Neighbours ... semicolon separated list of classes implementing `NeighbourSelection` HillClimber.AdditionalNeighbours ... semicolon separated list of classes implementing `NeighbourSelection` HillClimber.Random ... when true, a neighbour selector is selected randomly HillClimber.Update ... when true, a neighbour selector is selected using `NeighbourSelector.getPoints()` weights (roulette wheel selection)

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `NeighbourSearch.NeighbourSearchContext` | `createAssignmentContext(Assignment<V,T> assignment)` Create a new assignment context for the given assignment.
    `String` | `getParameterBaseName()` All parameters start with HillClimber base name, e.g., HillClimber.MaxIdle
    `void` | `init(Solver<V,T> solver)` Initialization
    `void` | `setPhase(String phase)` Set progress phase name

    - ### Methods inherited from class org.cpsolver.ifs.algorithms.NeighbourSearch

      `accept, accept, addNeighbourSelection, bestCleared, bestRestored, bestSaved, generateMove, getInfo, getInfo, getNeighbours, info, isMaster, logNeibourStatus, nextNeighbourSelection, selectNeighbour, setHCMode, setProgress, setProgressPhase, solutionUpdated`

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

    - #### iMaxIdleIters

          protected int iMaxIdleIters

    - #### iSetHCMode

          protected boolean iSetHCMode

    - #### sEPS

          protected static double sEPS

  - ### Constructor Detail

    - #### HillClimber

          public HillClimber(DataProperties properties)

      Constructor
      - HillClimber.MaxIdle ... maximum number of idle iterations (default is 200000)
      - HillClimber.Neighbours ... semicolon separated list of classes implementing `NeighbourSelection`
      - HillClimber.AdditionalNeighbours ... semicolon separated list of classes implementing `NeighbourSelection`
      - HillClimber.Random ... when true, a neighbour selector is selected randomly
      - HillClimber.Update ... when true, a neighbour selector is selected using `NeighbourSelector.getPoints()` weights (roulette wheel selection)
      Parameters:
        `properties` - solver configuration

  - ### Method Detail

    - #### setPhase

          public void setPhase(String phase)

      Set progress phase name
      Parameters:
        `phase` - name of the phase in which the hill climber is used (for logging purposes)

    - #### 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>>`
      Overrides:
        `init` in class `NeighbourSearch<V extends Variable<V,T>,T extends Value<V,T>>`
      Parameters:
        `solver` - current solver

    - #### getParameterBaseName

          public String getParameterBaseName()

      All parameters start with HillClimber base name, e.g., HillClimber.MaxIdle
      Specified by:
        `getParameterBaseName` in class `NeighbourSearch<V extends Variable<V,T>,T extends Value<V,T>>`
      Returns:
        solver parameter base name for this search technique

    - #### createAssignmentContext

          public NeighbourSearch.NeighbourSearchContext 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.
      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