Skip to main content

Module permutation

Module permutation 

Source
Expand description

Operators for permutations Vec<usize> of 0..n: swap, insertion, inversion and scramble mutation; partially mapped (PMX), order (OX), cycle (CX) and edge recombination (ERX) crossover. Every operator maps permutations to permutations (property-tested).

Jakob (2021) recommends operators that change gene order, including segment inversion and order-preserving crossover, for combinatorial tasks; these are they.

Structs§

Cx
Cycle crossover (Oliver, Smith and Holland 1987): positions are partitioned into cycles; alternate cycles come from alternate parents, so every element keeps a parent’s absolute position.
EdgeRecombination
Edge recombination crossover (Whitley, Starkweather and Fuquay 1989) for tours: children are built from the union of both parents’ adjacency lists, always continuing with the neighbour that has the fewest remaining neighbours. Preserves edges, which matter more than positions in routing problems.
Insertion
Removes one element and reinserts it at another position. Works for any Vec<T>.
Inversion
Reverses a random segment (2-opt move for tours). Works for any Vec<T>.
Ox
Order crossover OX1 (Davis 1985): each child keeps a segment of one parent and fills the remaining positions, starting after the segment, with the other parent’s elements in their relative order.
Pmx
Partially mapped crossover (Goldberg and Lingle 1985): each child takes a segment of one parent and fills the rest from the other, resolving conflicts through the segment’s mapping.
RandomPermutation
Uniform random permutations of 0..n.
Scramble
Shuffles a random segment. Works for any Vec<T>.
Swap
Swaps two distinct positions. Works for any Vec<T>.

Functions§

is_permutation
Returns true if p is a permutation of 0..p.len().