Skip to content

orderCrossover<T>(first, second, cut): readonly [readonly T[], readonly T[]]

Defined in: packages/evolution/src/permutation.ts:35

Cross two permutations with an inclusive order-crossover cut.

Both parents must have equal length and contain the same unique values under Set SameValueZero equality. Each child keeps one parent’s cut segment and fills the other positions in the opposite parent’s cyclic order. Runs in O(n) expected time and O(n) auxiliary space, returns new readonly arrays, and never mutates either parent.

T

readonly T[]

readonly T[]

readonly [number, number]

readonly [readonly T[], readonly T[]]

With code INVALID_PERMUTATION when a parent is not an array, DUPLICATE_ELEMENT when either parent repeats a value, UNEQUAL_PARENT_DOMAIN when parent domains differ, or INVALID_CUT when the cut is not an ascending safe-integer pair inside both parents.