Skip to content

Memetic runs

Every population algorithm takes a local search with local_search=. Each newly evaluated solution is improved, with probability local_search_prob (default 0.1), by a short run of that algorithm of at most local_search_nfe evaluations (default 100). A better solution replaces it in the population (Lamarckian). The local search counts its evaluations, including its start, toward the run's budget, and the run's limits stop it too.

Use moves that differ from the population's own variation, or the local search undoes it. On tours, for example, a hill climber with inversion (2-opt) moves suits a GA that uses order crossover.

Example

import ypea

problem = ypea.problems.random_tsp(50, seed=2)

moves = {ypea.Permutation: ("inversion",)}
two_opt = ypea.HillClimbing(moves=moves, restart=False)

alg = ypea.GA(local_search=two_opt, local_search_nfe=500, max_nfe=50_000)
result = alg.solve(problem, seed=1)
print(result.summary())
GA on random_tsp50
  best objective value: 870.115
  feasible: True (violation 0)
  evaluations: 50000, iterations: 11, time: 2.28 s, stopped by: max_nfe

Differs from Python: MATLAB draws its own cities and random numbers, so the tour length differs from Python's. The moves setting is a struct keyed by the type name.

problem = ypea.problems.random_tsp(50, seed=2);

moves = struct("Permutation", "inversion");
two_opt = ypea.HillClimbing(moves=moves, restart=false);

alg = ypea.GA(local_search=two_opt, local_search_nfe=500, max_nfe=50000);
result = alg.solve(problem, seed=1);
disp(result.summary())
GA on random_tsp50
  best objective value: 846.706
  feasible: true (violation 0)
  evaluations: 50000, iterations: 8, time: 2.96 s, stopped by: max_nfe

The same GA without the local search ends near 1450 on this problem.