Skip to content

GRASP

For discrete problems with a good greedy rule (a heuristic). It builds many greedy solutions with some randomness and improves each one with a local search.

GRASP

GRASP(*, heuristic=None, alpha=None, pheromone='successor', tour=False, order='random', improvement='first', batch=10, **kwargs)

Greedy randomized adaptive search procedure (Feo and Resende 1995).

Each iteration builds one solution step by step and improves it with a local search (hill climbing over all move kinds, first or best improvement). A step chooses uniformly among the restricted candidate list: the allowed choices whose greedy value is at least g_max - alpha (g_max - g_min). alpha 0 is greedy, 1 is random. The greedy values come from heuristic, in the format of the ant colony algorithms (see Ant colony optimization), and for sequences they depend on the item placed last. Without a heuristic every choice has the same value, and GRASP becomes a random restart local search. The best solution over all iterations is the result. x0 is improved first, before the first construction.

Like the ant colony algorithms, it builds discrete solutions: Real and FixedSum variables are not supported.

Parameters

  • heuristic: None, a dict of variable name to array, or a function of the problem that returns one (as in the ant colony algorithms, see Ant colony optimization)
  • alpha: None (default, a new alpha drawn uniformly in [0, 1] for each construction, as in later GRASP work) or a fixed value in [0, 1]
  • pheromone, tour, order: the construction tables, as in the ant colony algorithms (the name "pheromone" is kept so both use the same tables)
  • improvement: "first" (default) or "best" improvement in the local search
  • batch, candidate_size, moves, step, real_moves: as in HillClimbing

References: T. A. Feo and M. G. C. Resende, "Greedy randomized adaptive search procedures", Journal of Global Optimization 6, 1995, 109 to 133. M. G. C. Resende and C. C. Ribeiro, "Greedy randomized adaptive search procedures", in Handbook of Metaheuristics, 2003, 219 to 249.

The heuristic and the construction tables are described in Ant colony optimization, and the local search moves in Neighborhoods.

Example

import numpy as np
import ypea

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


def inverse_distance(problem):
    distances = problem.objective.distances
    n = len(distances)
    return {"tour": 1 / (distances + np.eye(n))}  # the diagonal is never used


alg = ypea.GRASP(heuristic=inverse_distance, max_nfe=50_000)
result = alg.solve(problem, seed=1)
print(result.summary())
GRASP on random_tsp50
  best objective value: 588.575
  feasible: True (violation 0)
  evaluations: 50000, iterations: 8, time: 5.29 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 heuristic is a struct keyed by the variable name.

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

alg = ypea.GRASP(heuristic=@inverse_distance, max_nfe=50000);
result = alg.solve(problem, seed=1);
disp(result.summary())

function heuristic = inverse_distance(problem)
distances = problem.info.distances;
n = size(distances, 1);
heuristic = struct("tour", 1 ./ (distances + eye(n)));  % the diagonal is never used
end
GRASP on random_tsp50
  best objective value: 573.962
  feasible: true (violation 0)
  evaluations: 50000, iterations: 8, time: 3.99 s, stopped by: max_nfe