Skip to content

Neighborhoods

ypea.neighborhoods.ProblemNeighborhood

The moves of all variables of a problem, on code vectors.

nb = ypea.neighborhoods.ProblemNeighborhood(problem, moves, real_moves=
"coordinate", step=0.1, inversion_attribute="edges")
moves is empty (every kind, and real_moves for Real variables) or a
struct whose fields are variable names or type names, each with the
move kinds of that variable, for example struct("Permutation",
"inversion") or struct("x", ["swap" "insertion"]). A variable name
comes before a type name. step is the Real step as a fraction of the
range. A random move picks a variable, then a kind, uniformly at
random.

Candidates are returned as a struct: groups (one per variable and
kind: v, kind and the move matrix M), and for each candidate g (its
group) and j (its row in that group's M).

ypea.neighborhoods.for_variable

The neighborhood of a variable, with the given move kinds (default: all of them).

Differs from Python: Named neighborhood in Python. On Windows, file names ignore case, so neighborhood.m would replace Neighborhood.m.

nb = ypea.neighborhoods.for_variable(var, kinds, step=0.1, inversion_attribute="edges")
See ypea.neighborhoods.Neighborhood for the kinds of each type.

ypea.neighborhoods.Neighborhood

Moves of one variable, for the local search methods.

A neighborhood lists the moves of one solution (moves), draws random
ones (sample), builds the neighbors (codes) and gives each move its
tabu attributes (attributes). Each variable type has one subclass:

Type             Kinds (the first is the basic move)
Permutation      swap, insertion, inversion
Integer          step (plus or minus 1), reset (another value)
Binary           flip
Real             coordinate (one component plus or minus step), gaussian
Selection        replace (an item with an unused one), swap (two positions)
BinarySelection  swap (a one and a zero)
Partition, BinaryPartition  move (an item to another group), swap
FixedSum         transfer (part of one element to another with the same sum)

ypea.neighborhoods.for_variable(var, kinds) makes the neighborhood of
a variable. A solution's value is split into rows (one per row of a
variable with count, otherwise one). A move is a row of a matrix: the
row number, then the move's own columns, with 1-based positions and
items. Attribute keys are 0-based numbers as in Python, -1 for none.