Documentation
¶
Overview ¶
Package graphplan implements the Graphplan algorithm for solving STRIPS and ADL planning problems. It constructs a Planning Graph and uses backward-chaining search with memoization to find shortest parallel plans.
ADL support includes a Formula tree representation with And, Or, Imply, Forall, Exists, and When nodes. Disjunctive preconditions, conditional effects, and universally or existentially quantified formulas are grounded and evaluated during graph expansion. Derived predicates (axioms) are computed via fixed-point evaluation at each proposition layer.
Index ¶
- Variables
- func MarshalFormula(formula Formula) ([]byte, error)
- type Action
- type AndFormula
- type AtomFormula
- type Axiom
- type Domain
- type ExistsFormula
- type ForallFormula
- type Formula
- type Graph
- func (g *Graph) ActLevelSize(level int) int
- func (g *Graph) ActionsAreMutex(level int, actA, actB *Action) bool
- func (g *Graph) Extend()
- func (g *Graph) GoalsReachable(goals []Proposition, level int) bool
- func (g *Graph) HasProp(level int, prop Proposition) bool
- func (g *Graph) Leveled() bool
- func (g *Graph) NumPropLevels() int
- func (g *Graph) PropLevelSize(level int) int
- func (g *Graph) PropsAreMutex(level int, prop, other Proposition) bool
- func (g *Graph) Search(goals []Proposition) ([]PlanStep, bool)
- type ImplyFormula
- type Object
- type Operator
- type OrFormula
- type Parameter
- type PlanStep
- type Predicate
- type Problem
- type Proposition
- type Solver
- type SolverConfig
- type Type
- type WhenFormula
Constants ¶
This section is empty.
Variables ¶
var ( // ErrNoValidPlan indicates no valid plan exists for // the given problem. ErrNoValidPlan = errors.New("no valid plan exists") // ErrMaxLevelsExceeded indicates the solver hit the // configured level cap without finding a plan. ErrMaxLevelsExceeded = errors.New( "max levels exceeded", ) )
var ErrNilFormula = errors.New("nil formula")
ErrNilFormula is returned when unmarshaling a JSON null into a Formula.
Functions ¶
func MarshalFormula ¶ added in v0.2.2
MarshalFormula serializes a Formula to JSON using a discriminated-union envelope keyed by "type".
Types ¶
type Action ¶
Action is a grounded operator with all parameters bound to concrete objects.
func GroundActions ¶
GroundActions instantiates all operators with all type-compatible object bindings. It handles :equality constraints (neq) by filtering at grounding time.
type AndFormula ¶ added in v0.2.2
type AndFormula struct {
Children []Formula
}
AndFormula is a conjunction of sub-formulas.
type AtomFormula ¶ added in v0.2.2
AtomFormula is an atomic predicate application.
func CollectAtoms ¶ added in v0.2.2
func CollectAtoms(f Formula) []*AtomFormula
CollectAtoms walks a formula tree depth-first and returns all *AtomFormula leaf nodes.
type Axiom ¶ added in v0.2.2
Axiom defines a derived predicate whose truth is computed from a body formula.
func (Axiom) MarshalJSON ¶ added in v0.2.2
MarshalJSON implements json.Marshaler for Axiom.
func (*Axiom) UnmarshalJSON ¶ added in v0.2.2
UnmarshalJSON implements json.Unmarshaler for Axiom.
type Domain ¶
type Domain struct {
Name string
Types []Type
Predicates []Predicate
Operators []Operator
Constants []Object
Axioms []Axiom
}
Domain holds the complete planning domain definition.
type ExistsFormula ¶ added in v0.2.2
ExistsFormula is an existentially quantified formula.
type ForallFormula ¶ added in v0.2.2
ForallFormula is a universally quantified formula.
type Formula ¶ added in v0.2.2
type Formula interface {
// contains filtered or unexported methods
}
Formula represents a logical formula in preconditions or effects.
func PropsToFormula ¶ added in v0.2.2
func PropsToFormula(props []Proposition) Formula
PropsToFormula converts a flat proposition slice to a formula tree. Returns nil for empty input. A single proposition becomes an *AtomFormula; multiple propositions are wrapped in an *AndFormula.
func UnmarshalFormula ¶ added in v0.2.2
UnmarshalFormula deserializes JSON produced by MarshalFormula back into a Formula value. Returns ErrNilFormula when the input is JSON null.
type Graph ¶
type Graph struct {
// contains filtered or unexported fields
}
Graph is a directed, leveled planning graph alternating between proposition levels and action levels as described by Blum & Furst (1997).
func NewGraph ¶
NewGraph creates a planning graph with proposition level 0 containing the initial state. Negative propositions are seeded via the closed-world assumption for predicates used in negative preconditions.
func (*Graph) ActLevelSize ¶
ActLevelSize returns the number of actions at the given level.
func (*Graph) ActionsAreMutex ¶
ActionsAreMutex returns true if two actions are mutually exclusive at the given action level.
func (*Graph) Extend ¶
func (g *Graph) Extend()
Extend adds one action level and one proposition level to the graph.
func (*Graph) GoalsReachable ¶
func (g *Graph) GoalsReachable( goals []Proposition, level int, ) bool
GoalsReachable returns true if all goals exist at the given proposition level and no pair is mutex.
func (*Graph) HasProp ¶
func (g *Graph) HasProp( level int, prop Proposition, ) bool
HasProp returns true if proposition prop exists at the given proposition level.
func (*Graph) Leveled ¶
Leveled returns true if the last two proposition levels are identical (same props and same mutexes).
func (*Graph) NumPropLevels ¶
NumPropLevels returns the number of proposition levels.
func (*Graph) PropLevelSize ¶
PropLevelSize returns the number of propositions at the given level.
func (*Graph) PropsAreMutex ¶
func (g *Graph) PropsAreMutex( level int, prop, other Proposition, ) bool
PropsAreMutex returns true if two propositions are mutually exclusive at the given proposition level.
type ImplyFormula ¶ added in v0.2.2
ImplyFormula represents (imply A B), equivalent to (or (not A) B).
type Operator ¶
Operator defines an operator template with typed parameters, a precondition formula, and an effect formula.
func (Operator) MarshalJSON ¶ added in v0.2.2
MarshalJSON implements json.Marshaler for Operator.
func (*Operator) UnmarshalJSON ¶ added in v0.2.2
UnmarshalJSON implements json.Unmarshaler for Operator.
type OrFormula ¶ added in v0.2.2
type OrFormula struct {
Children []Formula
}
OrFormula is a disjunction of sub-formulas.
type PlanStep ¶
PlanStep is one time step in the output plan, containing a set of non-interfering parallel actions.
type Problem ¶
type Problem struct {
Name string
Domain *Domain
Objects []Object
InitialState []Proposition
Goals []Proposition
}
Problem defines a planning problem: a domain, objects, initial state, and goal propositions.
type Proposition ¶
Proposition is a grounded predicate — fully instantiated with concrete objects. When Negated is true, it represents the absence of the fact (closed-world assumption).
func FormulaToProps ¶ added in v0.2.2
func FormulaToProps(f Formula) []Proposition
FormulaToProps extracts all atomic propositions from a formula tree by collecting atoms and converting each to a Proposition.
func GroundPredicates ¶ added in v0.2.0
func GroundPredicates( domain *Domain, objects []Object, predicateNames map[string]bool, ) []Proposition
GroundPredicates enumerates all type-compatible ground instances of the given predicates. It reuses buildTypeIndex and enumerateBindings to generate all valid argument combinations for each predicate.
func SplitEffects ¶ added in v0.2.2
func SplitEffects( f Formula, ) (adds, deletes []Proposition)
SplitEffects partitions a formula's atoms into add effects (Negated=false) and delete effects (Negated=true, returned with Negated=false).
func (Proposition) BaseKey ¶ added in v0.2.0
func (p Proposition) BaseKey() string
BaseKey returns the key without negation, useful for interference checks between positive and negative propositions.
func (Proposition) Key ¶
func (p Proposition) Key() string
Key returns a unique string key for map lookups. Negated propositions are prefixed with "NOT-".
func (Proposition) Negate ¶ added in v0.2.0
func (p Proposition) Negate() Proposition
Negate returns a copy with Negated flipped.
func (Proposition) String ¶
func (p Proposition) String() string
String returns the human-readable representation.
type Solver ¶
type Solver struct {
SolverConfig
}
Solver runs the Graphplan extend/search loop to find shortest parallel plans for STRIPS problems.
func NewSolver ¶
func NewSolver( cfg *SolverConfig, ) (*Solver, error)
NewSolver creates a solver. A nil config uses defaults.
type SolverConfig ¶
type SolverConfig struct {
// MaxLevels caps graph expansion. Nil means no limit.
MaxLevels *int `json:"max_levels,omitempty" yaml:"max_levels"`
}
SolverConfig controls solver behavior.
func (*SolverConfig) Validate ¶
func (c *SolverConfig) Validate() error
Validate checks that config values are semantically valid.
type WhenFormula ¶ added in v0.2.2
WhenFormula is a conditional effect. Valid only in effect context.