Learn R Programming

cayleyR (version 0.2.1)

find_path_iterative: Iterative Path Finder Between Permutation States

Description

Finds a path between two permutation states using iterative cycle expansion. Generates random operation sequences, analyzes their cycles, and looks for intersections between forward (from start) and backward (from final) state sets. Uses bridge states to progressively narrow the search space.

Usage

find_path_iterative(
  start_state,
  final_state,
  k,
  moves = c("1", "2", "3"),
  combo_length = 20,
  n_samples = 200,
  n_top = 10,
  max_iterations = 10,
  potc = 1,
  ptr = 10,
  opd = FALSE,
  reuse_combos = FALSE,
  distance_method = "manhattan",
  verbose = TRUE
)

Value

List containing:

path

Character vector of operations, or NULL if not found

found

Logical, whether a path was found

cycles

Number of iterations used

selected_info

Details about the selected intersection

bridge_states_start

List of forward bridge states

bridge_states_final

List of backward bridge states

Arguments

start_state

Integer vector, the starting permutation state

final_state

Integer vector, the target permutation state

k

Integer, parameter for reverse operations

moves

Character vector, allowed operations (default c("1", "2", "3"))

combo_length

Integer, length of random operation sequences (default 20)

n_samples

Integer, number of random sequences to test per iteration (default 200)

n_top

Integer, number of top sequences to analyze fully (default 10)

max_iterations

Integer, maximum number of search iterations (default 10)

potc

Numeric in (0,1], fraction of cycle states to keep (default 1)

ptr

Integer, max intersections to process per iteration (default 10)

opd

Logical, if TRUE filters states to only combos containing bridge state (default FALSE)

reuse_combos

Logical, if TRUE generates random combos only once per side (cycle 1) and reuses them in subsequent cycles. Saves time but reduces diversity (default FALSE)

distance_method

Character, method for comparing states during bridge selection. One of "manhattan" (sum of absolute differences) or "breakpoints" (number of adjacency violations). Default "manhattan".

verbose

Logical, if TRUE prints progress messages (default TRUE)

Examples

Run this code
# Small example
set.seed(42)
start <- 1:6
final <- c(3L, 1L, 2L, 6L, 4L, 5L)
# result <- find_path_iterative(start, final, k = 3, max_iterations = 5)

Run the code above in your browser using DataLab