pddl_builder.PDDLBuilder

class pddl_builder.PDDLBuilder

Bases: object

Generates PDDL problem files with target predicates for precise placement.

The Target Trick works by adding special predicates for geometrically misaligned blocks that MCTS identified. For each target object: - Initial state gets TargetOn(X, Y) to mark “needs precise placement” - Goal state requires AtTarget(X) to force use of stack-target action

This creates a symbolic gap that forces the planner to correct geometric misalignments, even when symbolic relationships like On(X,Y) are satisfied.

__init__()

Initialize the PDDL problem builder.

Methods

__init__()

Initialize the PDDL problem builder.

build_support_map(on_pairs, ontable_set)

Build a map of what each block is sitting on.

generate_problem(current_state, goal_state, ...)

Generate complete PDDL problem with Target Trick for precise placement.

normalize_name(name)

Normalize block names to single uppercase letters.

parse_relationships(state)

Parse symbolic relationships from state dictionary.

build_support_map(on_pairs, ontable_set)

Build a map of what each block is sitting on.

Args:

on_pairs: List of (upper, lower) tuples from On relationships. ontable_set: Set of blocks on the table.

Returns:

Dictionary mapping block -> what it sits on (‘TABLE’ or another block).

generate_problem(current_state, goal_state, target_objects)

Generate complete PDDL problem with Target Trick for precise placement.

This is where the magic happens: target objects identified by MCTS get special treatment in the PDDL problem to force geometric corrections.

Args:

current_state: Dictionary with current symbolic state and relationships. goal_state: List of goal symbolic predicates (e.g., [“On(A,B)”, “On(B,C)”]). target_objects: List of object IDs that need precise placement (from MCTS).

Returns:

String containing complete PDDL problem definition.

normalize_name(name)

Normalize block names to single uppercase letters.

Handles various naming conventions from JSON files: - ‘Box A’, ‘Block B’ -> ‘A’, ‘B’ - ‘0’, ‘1’, ‘2’, ‘3’, ‘4’ -> ‘A’, ‘B’, ‘C’, ‘D’, ‘TABLE’ - ‘Goal_*’, ‘Table_*’ -> ‘TABLE’

Args:

name: Raw name string from JSON.

Returns:

Normalized name (single uppercase letter or ‘TABLE’).

parse_relationships(state)

Parse symbolic relationships from state dictionary.

Extracts On(X,Y), OnTable(X), and Clear(X) relationships. Automatically computes Clear predicates if not explicitly provided.

Args:

state: Dictionary with ‘relationships’ list (e.g., [“On(A,B)”, “Clear(A)”]).

Returns:
Tuple of (on_pairs, ontable_set, clear_set):
  • on_pairs: List of (upper, lower) tuples for On(upper, lower)

  • ontable_set: Set of blocks on the table

  • clear_set: Set of clear blocks