Neighbourhoods ============== In simulated annealing, a neighbourhood function defines the set of candidate solutions that can be reached from the current state in a single step. The quality and structure of the neighbourhood are crucial for the algorithm's performance, as they determine how the search space is explored. The :class:`~altbacken.core.neighbourhood.Neighbourhood` protocol defines the interface for these functions. A neighbourhood is a callable that takes an :class:`~altbacken.core.state.AnnealingState` and returns a new candidate solution of the same type. .. include:: numeric.rst .. include:: permutation.rst Custom Neighbourhoods --------------------- You can implement your own neighbourhood by creating a class or function that follows the :class:`~altbacken.core.neighbourhood.Neighbourhood` protocol. .. code-block:: python from altbacken.core.state import AnnealingState def my_custom_neighbourhood(state: AnnealingState[float]) -> float: # Generate a new solution based on the current one return state.current_solution + 0.1