# River Crossing **Transport N actor-agent pairs across a river with global safety constraints** --- ## Overview River Crossing is a constraint satisfaction planning puzzle that tests multi-agent coordination and safety constraint management. This puzzle is a generalization of classic problems such as the Missionaries and Cannibals problem and the Bridge and Torch problem, which have been widely studied in planning literature. ### Difficulty Rating: ⭐⭐⭐⭐ (Very Hard - Global Constraints) --- ## 📊 Statistics | Metric | Value | |--------|-------| | **Total Puzzles** | 4,208 | | **Total Moves** | 25,396 | | **Training Puzzles (N=1-7)** | 630 | | **Test Puzzles (N=8-10)** | 3,578 | | **Difficulty Parameter** | N (actor-agent pairs) | | **Boat Capacities** | k ∈ {2, 3, 4} | | **Solution Length** | L(N,k) ≥ Ω(N/k) (variable) | | **Transition Locality** | **O(N) global** - must verify all entities | --- ## 🎯 Puzzle Rules ### Objective Transport all 2N individuals (N actors and N agents) from one river bank to the opposite bank using a boat with capacity k. ### Entities - **Actors**: a₁, a₂, ..., aₙ - **Agents**: A₁, A₂, ..., Aₙ - Each actor aᵢ is "protected by" their corresponding agent Aᵢ ### Initial State All 2N individuals start on one bank (typically left bank). ### Goal State All 2N individuals reach the opposite bank. ### Constraints 1. **Boat Capacity Constraint**: The boat can carry at most k individuals at a time 2. **Non-Empty Boat Constraint**: The boat cannot travel empty—must have at least one person aboard 3. **Safety Constraint** (CRITICAL): An actor aᵢ cannot be in the presence of another agent Aⱼ (where j ≠ i) unless their own agent Aᵢ is also present - This applies **on both banks** AND **inside the boat** - Violation at any point renders the solution invalid ### Why River Crossing is Extremely Hard River Crossing is the **second-hardest** puzzle (after Tower of Hanoi): 1. **Global O(N) Constraint Verification**: Every move requires checking safety for all 2N entities - Cannot be verified with local checks - Must scan entire state (both banks + boat) 2. **Combinatorial Action Space**: On the boat-side bank with m entities: ``` Number of candidate loadings = Σ(k, j=1) C(m, j) ``` For k=2 and m=2N: this is O(N²) possible boat configurations 3. **Complex Planning Dependencies**: - Who goes in the boat affects who can safely remain - Return trips are necessary but non-obvious - Requires multi-step lookahead 4. **No Model Achieves >0%**: All tested models (T5, GPT-2, all conditions) achieve **0.00% everywhere** --- ## 📋 State Representation States are represented as **tuples of two sorted lists**: (left_bank, right_bank) Each list contains the entities currently on that bank. ### Format ```python (['a1', 'A1'], ['a2', 'A2', 'a3', 'A3']) ``` This represents: - **Left Bank**: Actor a1 and Agent A1 - **Right Bank**: Actor a2, Agent A2, Actor a3, Agent A3 ### Move Representation ```python ['a1', 'A1'] ``` This represents: **Load actors a1 and Agent A1 onto the boat** (they will travel together) Format: `[entity1, entity2, ...]` (list of entities traveling in this boat trip) An empty move `[]` represents the boat returning empty (when allowed by non-empty constraint). --- ## 🖼️ Example Puzzle ![River Crossing Example](https://github.com/gowravmannem/Recurrent-Reasoning-on-Puzzles/blob/main/assets/river_crossing.png?raw=true) ### Example Trajectory (N=1, k=2) **Initial State**: `(['A1', 'a1'], [])` **Goal State**: `([], ['A1', 'a1'])` **Boat Capacity**: k = 2 **Goal Direction**: Right **Optimal Solution Length**: 1 move **Step-by-step solution:** | Step | Boat Side | Current State | Next State | Move | Description | |------|-----------|--------------|-----------|------|-------------| | 0 | L | `(['A1','a1'],[])` | `([],['A1','a1'])` | `['A1','a1']` | Both cross together | | 1 | R | `([],['A1','a1'])` | `([],['A1','a1'])` | `[]` | Goal reached! | ### More Complex Example (N=2, k=2) **Initial State**: `(['A1','a1','A2','a2'], [])` **Goal State**: `([], ['A1','a1','A2','a2'])` This requires **5 moves** (optimal): 1. Send a1 and A1 across → `(['A2','a2'], ['A1','a1'])` 2. A1 returns alone → `(['A1','A2','a2'], ['a1'])` 3. Send A1 and A2 across → `(['a2'], ['A1','A2','a1'])` 4. A2 returns alone → `(['A2','a2'], ['A1','a1'])` 5. Send A2 and a2 across → `([], ['A1','A2','a1','a2'])` ✓ **Safety verification at each step**: - After step 1: a2 is with A2 on left ✓, a1 is with A1 on right ✓ - After step 2: a2 is with A2 on left ✓, a1 alone on right ✓ - Etc. --- ## 📁 CSV Column Descriptions ### Columns | Column | Type | Description | |--------|------|-------------| | `N` | int | Number of actor-agent pairs (difficulty parameter) | | `boat_capacity` | int | Maximum individuals boat can hold (k ∈ {2,3,4}) | | `start_state` | string | Initial configuration (tuple of two lists) | | `goal_state` | string | Target configuration to achieve | | `goal_direction` | string | Target bank ('Left' or 'Right') | | `boat_side` | string | Current boat location before move ('L' or 'R') | | `current_state` | string | Banks state before this move | | `next_state` | string | Banks state after applying this move | | `move` | string | Entities traveling in boat: `[entity1, entity2, ...]` | | `total_moves` | int | Total moves in the complete optimal solution | ### Data Format Each row represents one **boat crossing** (move). **Example CSV rows:** ```csv N,boat_capacity,start_state,goal_state,goal_direction,boat_side,current_state,next_state,move,total_moves 1,2,"(['A1','a1'],[])","([],['A1','a1'])",Right,L,"(['A1','a1'],[])","([],['A1','a1'])","['A1','a1']",1 1,2,"(['A1','a1'],[])","([],['A1','a1'])",Right,R,"([],['A1','a1'])","([],['A1','a1'])","[]",1 ``` --- ## 💡 Usage Tips ### For Model Training ⚠️ **EXTREME WARNING**: River Crossing is **unsolved** by all current sequence models. Potential approaches (all experimental): 1. **Explicit Constraint Checker**: - Augment model with symbolic safety verifier - Only allow moves that pass safety check - Hybrid neuro-symbolic approach 2. **Constrained Beam Search**: - Generate top-k boat loadings - Filter out unsafe options - Expand only valid candidates 3. **Graph Neural Networks**: - Represent entities and relationships as graph - Use GNN to learn safety constraint - May capture global structure better than sequences 4. **Curriculum with Safety Signals**: - Explicitly annotate which moves violate safety - Train classifier to predict "safe" vs "unsafe" - Use as auxiliary task 5. **Search-Augmented Generation**: - Use model as policy for MCTS or A* - Explicit state-space search with neural heuristic ### For Evaluation ```python from datasets import load_dataset # Load River Crossing dataset = load_dataset("gmannem/RecurrReason", "river_crossing") # WARNING: Expect 0% success rate! def evaluate_river_crossing(model, example): """ Evaluation with strict safety constraint checking. A SINGLE safety violation = immediate failure. """ current_state = example['start_state'] goal_state = example['goal_state'] boat_side = example['boat_side'] boat_capacity = example['boat_capacity'] steps = 0 max_steps = 2 * example['total_moves'] while steps < max_steps: # Model predicts boat loading boat_loading = model.predict(current_state, goal_state, boat_side) # CRITICAL: Verify safety at EVERY step next_state, next_boat_side = apply_move( current_state, boat_loading, boat_side ) # Check safety constraint if violates_safety(next_state): return "SAFETY_VIOLATION", steps # Check capacity constraint if len(boat_loading) > boat_capacity or len(boat_loading) == 0: return "INVALID_CAPACITY", steps if next_state == goal_state: return "SUCCESS", steps current_state = next_state boat_side = next_boat_side steps += 1 return "TIMEOUT", steps def violates_safety(state): """ Check global safety constraint. For each actor a_i on a bank, verify: - No agent A_j (j != i) is present, OR - Agent A_i is also present """ left_bank, right_bank = state for bank in [left_bank, right_bank]: actors = [e for e in bank if e.startswith('a')] agents = [e for e in bank if e.startswith('A')] for actor in actors: actor_id = actor[1:] # Extract numeric ID own_agent = f'A{actor_id}' other_agents = [a for a in agents if a != own_agent] # If other agents present but own agent missing = VIOLATION if other_agents and own_agent not in bank: return True return False ``` --- ## 📚 References **Main Paper:** ```bibtex @inproceedings{mannem2026recurrent, title={Recurrent Reasoning on Symbolic Puzzles with Sequence Models}, author={Gowrav Mannem and Chowdhury Marzia Mahjabin and Jason Chen and Shivank Garg and Kevin Zhu}, booktitle={ICLR 2026 Workshop on Logical Reasoning of Large Language Models}, year={2026} } ``` **Classic River Crossing Problems:** ```bibtex @book{pressman1994puzzles, title={Famous puzzles of great mathematicians}, author={Pressman, Ian and Singmaster, David}, year={2009}, publisher={American Mathematical Society} } ``` --- [← Back to Main README](README.md)