Hill Climbing (HC)¶
The simplest local search: move to a better neighbor until there is none, then restart. Use it for a quick local search, alone, inside a memetic run or as the last stage of a Sequence.
HillClimbing ¶
HillClimbing(*, improvement='first', batch=10, step_min=1e-08, restart=True, **kwargs)
Hill climbing (local search) with random restarts.
The current solution moves to an improving neighbor: the first one found
(improvement="first", neighbors tried in random order, batch at a time) or the best
of the candidate list ("best"). The candidate list is the whole neighborhood when it
has at most candidate_size moves, otherwise a random sample of that size. With
Real variables, a local optimum halves the step, down to step_min. At a local
optimum the search restarts from a random solution (restart=True) or stops with the
stop reason "local_optimum". The best solution is kept across restarts.
One iteration evaluates one batch of neighbors (the whole candidate list with
improvement="best").
Parameters
improvement: "first" (default) or "best" improvementbatch: neighbors evaluated together with first improvement (default 10). batch=1 gives slightly better results per evaluation and suits expensive objectives, but is several times slower when evaluations are cheapcandidate_size: most neighbors per pass, a random sample when the neighborhood is larger (default 1000)moves: the move kinds of each variable, as a dict of variable name or type to a tuple of kinds, for example{ypea.Permutation: ("inversion",)}. None (default) uses every kind ofypea.neighborhoods.real_moves: "coordinate" (default, one component moves by plus or minus the step) or "gaussian" (all components get Gaussian noise of that size)step: first Real step as a fraction of each range (default 0.1)step_min: smallest Real step (default 1e-8)restart: restart at a local optimum (default True)
References: P. Hansen and N. Mladenović, "Variable neighborhood search", in Handbook of Metaheuristics, 2003, Section 2 (first and best improvement).
ypea.HC is the same class.
The moves of each variable type are listed in Neighborhoods.
Example¶
import ypea
problem = ypea.problems.random_tsp(50, seed=2)
alg = ypea.HillClimbing(max_nfe=50_000)
result = alg.solve(problem, seed=1)
print(result.summary())
HC on random_tsp50
best objective value: 607.033
feasible: True (violation 0)
evaluations: 50000, iterations: 5011, time: 2.1 s, stopped by: max_nfe
Differs from Python: MATLAB draws its own cities and random numbers, so the tour length differs from Python's.
problem = ypea.problems.random_tsp(50, seed=2);
alg = ypea.HillClimbing(max_nfe=50000);
result = alg.solve(problem, seed=1);
disp(result.summary())
HC on random_tsp50
best objective value: 598.723
feasible: true (violation 0)
evaluations: 50000, iterations: 5013, time: 3.15 s, stopped by: max_nfe