Skip to content

Add Tower of Hanoi domain#12

Open
j-vaught wants to merge 4 commits into
forestagostinelli:mainfrom
j-vaught:add-hanoi-domain
Open

Add Tower of Hanoi domain#12
j-vaught wants to merge 4 commits into
forestagostinelli:mainfrom
j-vaught:add-hanoi-domain

Conversation

@j-vaught
Copy link
Copy Markdown

@j-vaught j-vaught commented Apr 1, 2026

Add Tower of Hanoi domain

Adds a fully parameterized Tower of Hanoi domain supporting arbitrary disk and peg counts via hanoi.<num_disks>.<num_pegs>.

Design

State: uint8 array of length num_disks where state[i] = peg of disk i (disk 0 = largest, disk N-1 = smallest).

Actions: K*(K-1) directed peg-to-peg moves. get_state_actions overrides the ActsEnumFixed default to filter to only valid moves per state (source peg non-empty, destination either empty or topped by a larger disk).

Mixins:

  • ActsEnumFixed with get_state_actions override for validity filtering
  • GoalStartRevWalkableActsRev for reverse-walk problem instance generation
  • GoalFixed for GoalSampleable interface
  • HasFlatSGIn with one-hot depth K (input size = num_disks * num_pegs)
  • StateGoalVizable with peg-stack rendering
  • StringToAct for interactive CLI solving ('F T' or 'FT')

Implementation details:

  • _validity_batch vectorizes the move-legality check across batches using (on_peg * [1..N]).max() - 1 to find the top disk per peg
  • next_state groups states by action and applies valid moves via numpy fancy indexing
  • rev_action swaps source/destination pegs (algebraically guaranteed valid after a forward move)

Usage

# Information
deepxube domain_info

# Visualization (interactive)
deepxube viz --domain hanoi.4.3 --steps 10

# Train
deepxube train --domain hanoi.4.3 --heur resnet_fc.300H_4B_bn --heur_type V \
  --pathfind graph_v --step_max 15 --up_itrs 50 --search_itrs 100 \
  --backup -1 --procs 1 --batch_size 1000 --max_itrs 20000 --dir hanoi_trained/

# Solve
deepxube solve --domain hanoi.4.3 --heur resnet_fc.300H_4B_bn \
  --heur_file hanoi_trained/heur.pt --heur_type V \
  --pathfind graph_v.1B_1.0W --file hanoi_test.pkl --results hanoi_results/ --redo

# Visualize solution (prints each move as "peg F -> peg T")
deepxube viz --domain hanoi.4.3 --file hanoi_results/results.pkl --idx 0 --soln

Scale to more disks or pegs by changing the domain argument (e.g. hanoi.8.3, hanoi.4.4, hanoi.20.7).

Experimental results

Trained and evaluated on three configurations. All worst-case instances (all disks on peg 0, goal on last peg) solved optimally.

Config State space Optimal (worst case) Model found Nodes generated
6 disks, 3 pegs 729 63 moves 63 moves (1.00x) 1,318
4 disks, 4 pegs 256 9 moves (Frame-Stewart) 9 moves (1.00x) 212
8 disks, 3 pegs 6,561 255 moves 255 moves (1.00x) 16,273

The 4-peg model independently discovered the Frame-Stewart optimal strategy.

Adds a fully parameterized Tower of Hanoi domain (hanoi.<num_disks>.<num_pegs>)
supporting arbitrary disk and peg counts.
@j-vaught j-vaught marked this pull request as ready for review April 1, 2026 17:03
Equation Simplification: polynomial expressions with combine/swap/remove.
Word Ladder: 4-letter word transformations via single-char substitution.
Circuit Minimization: boolean SOP expression simplification via QM.
Removed three domains that were either trivially solvable (equation)
or less compelling for demonstrating learned heuristics. Added a
simplified retrosynthesis domain where molecules (6-position carbon
chains with 8 functional groups and single/double bonds) must be
transformed through valid chemical reactions. Multi-step reaction
dependencies create genuine search complexity that cannot be solved
by greedy approaches.
Reactions now target the most reactive eligible position instead of
a player-chosen one, creating tight coupling between positions.
Added protecting groups, global reagent incompatibilities, and
reactivity-based site selection. Positions are no longer independently
solvable -- the optimal sequence depends on the entire molecular state.
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