Skip to content

Reduce regular graph construction memory and support NFAs - #234

Open
zayenz wants to merge 5 commits into
mainfrom
feature/improved-regular-construction
Open

Reduce regular graph construction memory and support NFAs#234
zayenz wants to merge 5 commits into
mainfrom
feature/improved-regular-construction

Conversation

@zayenz

@zayenz zayenz commented Jul 28, 2026

Copy link
Copy Markdown
Member

The regular propagator builds a layered graph for the sequence and automaton. The old initializer reserves a state slot for every automaton state at every sequence position, requiring (n + 1)k temporary State objects even when few are reachable.

This change constructs sparse forward frontiers, filters them by backward co-reachability, and allocates persistent states after the surviving layer sizes are known. State-related construction memory is O(k + S), where S is the number of states in the final layered graph. For an unfolded DFA, S <= k. A looping automaton can still have S = Theta(nk), but construction no longer adds a second dense state matrix. The persistent Layer, Support, Edge, and State representation is unchanged.

DFA::nfa(start, transitions, finals) explicitly constructs an epsilon-free NFA, retaining nondeterministic transitions without determinization or minimization. Array and initializer-list overloads are available. Ordinary DFA constructors retain their deterministic-transition precondition. Cloning only removes assigned prefix layers with a single edge, preserving branching NFA paths and their edge counts.

Tests cover cyclic frontiers, acyclic reconvergence, position-specific pruning, failed acceptance, Boolean views, terminal merging, state-index boundaries, randomized DFA/NFA differential checks, and assigned NFA prefixes during cloning. The NFA differential and prefix cases are included in both CMake and Autoconf check selections.

Validation:

  • All 39 regular tests pass for five iterations each in a Debug build with GECODE_AUDIT enabled (195 passes).
  • Tidy and whitespace checks pass.

Existing Apple Clang Release measurements for sparse construction, not repeated for the NFA addition:

  • A fresh build of all libraries, tools, and examples succeeded, and the focused regular suite passed.
  • In the unfolded size-5,000 case, the dense construction had 25,010,001 state slots for 5,001 persistent states. Median peak RSS fell from 108,000 KiB to 9,552 KiB, and median root construction time fell from 215.882 ms to 157.038 ms.
  • An all-model campaign completed 1,760 fresh-process runs with no differences in status, solutions, objectives, nodes, or failures. Across 15 real-model timing rows, the geometric-mean candidate/baseline runtime ratio was 1.010.

The Windows vcpkg checkout and manifest baseline are aligned to the same pinned commit, replacing a GMP portfile that requested a removed MSYS2 autoconf archive.

@zayenz zayenz changed the title Reduce regular layered graph construction memory Reduce regular graph construction memory and support NFAs Sep 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant