Skip to contents

The local search methods of Metaheuristics.jl that OptimizationMetaheuristics exports, ported to R. They search the neighborhoods that the user defines; in R a neighborhood is a function function(x, i) that returns the i-th neighbor of x (NULL after the last one) or a random neighbor when i is NULL, or Metaheuristics$TwoOptNeighborhood().

Usage

GRASP(
  initial = NULL,
  constructor = NULL,
  local_search = .mh_op("BestImproveSearch"),
  options = NULL,
  information = NULL
)

VND(
  initial = NULL,
  neighborhood = NULL,
  local_search = .mh_op("BestImproveSearch"),
  options = NULL,
  information = NULL
)

VNS(
  initial = NULL,
  neighborhood_shaking = NULL,
  neighborhood_local = NULL,
  local_search = .mh_op("FirstImproveSearch"),
  neighborhood_change = .mh_op("SequentialChange"),
  options = NULL,
  information = NULL
)

Arguments

initial

The starting point (random in the bounds when NULL).

constructor

The randomized greedy constructor of GRASP.

Metaheuristics$BestImproveSearch() or Metaheuristics$FirstImproveSearch() (for GRASP with a neighborhood), or for GRASP a function of a point that returns the improved point.

options, information

As for metaheuristics_single.

neighborhood

A list of neighborhoods of VND.

neighborhood_shaking, neighborhood_local

Lists of neighborhoods of VNS.

neighborhood_change

Metaheuristics$SequentialChange() or Metaheuristics$CyclicChange().

Value

An algorithm object for solve().

Details

  • GRASP(): greedy randomized adaptive search: each iteration builds a point with constructor (a function of no arguments, or Metaheuristics$GreedyRandomizedConstructor()) and improves it with local_search.

  • VND(): variable neighborhood descent over the list neighborhood.

  • VNS(): variable neighborhood search: shaking in neighborhood_shaking, then a VND over neighborhood_local.

Examples

f <- function(x, p) sum((x - c(0.3, 0.7))^2)
step <- function(x, i) {
  if (is.null(i)) i <- sample.int(4, 1)
  if (i > 4) return(NULL)
  x[(i + 1) %/% 2] <- x[(i + 1) %/% 2] + c(-0.1, 0.1)[(i - 1) %% 2 + 1]
  x
}
prob <- OptimizationProblem(f, c(0, 0), lb = c(-1, -1), ub = c(1, 1))
sol <- solve(prob, VND(initial = c(0, 0), neighborhood = list(step)))
sol$u
#> [1] 0.3 0.7