crossover_fixknots: Crossover Operator (Fixed-m) with Feasibility-First Restarts

View source: R/gareg_knots.R

crossover_fixknotsR Documentation

Crossover Operator (Fixed-m) with Feasibility-First Restarts

Description

Produces a child chromosome from two fixed-m parents (same number of knots) by alternately sampling candidate knot locations from the parents and enforcing the spacing constraint diff(child) > minDist. If a conflict is encountered, the routine restarts the construction up to a small cap.

Usage

crossover_fixknots(mom, dad, prange = NULL, minDist, lmax, N)

Arguments

mom, dad

Integer vectors encoding parent chromosomes: first entry m (number of changepoints), followed by m ordered knot locations.

prange

Unused placeholder (kept for compatibility with other GA operators). Default NULL.

minDist

Integer; minimum spacing between adjacent knots in the child.

lmax

Integer; chromosome length (number of rows in the population matrix).

N

Integer; series length. Used to place the sentinel N+1 at position m+2.

Details

Let mom and dad be chromosomes of the form c(m, tau_1, ..., tau_m, ...). This operator:

  1. Initializes an empty child of size m.

  2. Picks the first knot at random from mom or dad.

  3. For each subsequent position i=2,\dots,m, considers the pair (mom[i], dad[i]) and chooses the first value that maintains the spacing constraint relative to the previously chosen knot (> minDist); if both work, one is chosen at random.

  4. If no feasible choice exists at some step, the construction restarts from the first position (up to a small cap governed internally by up_tol).

The result is written back as a full-length chromosome with the sentinel N+1 in position m+2, and zeros elsewhere.

Value

An integer vector of length lmax encoding the child chromosome: c(m, child_knots, N+1, 0, 0, ...).

See Also

crossover_fixknots, mutation_fixknots, selectTau_uniform_exact, Popinitial_fixknots, gareg_knots

Examples


N <- 120
lmax <- 30
minDist <- 5
m <- 3
mom <- c(m, c(20, 50, 90), rep(0, lmax - 1 - m))
mom[m + 2] <- N + 1
dad <- c(m, c(18, 55, 85), rep(0, lmax - 1 - m))
dad[m + 2] <- N + 1
child <- crossover_fixknots(mom, dad, minDist = minDist, lmax = lmax, N = N)
child



GAReg documentation built on March 29, 2026, 5:08 p.m.