Documentation
¶
Overview ¶
Package goap provides deterministic goal-oriented action planning over immutable planning.WorldState values. Its Planner uses uniform-cost search, which is complete and cost-optimal for the non-negative finite Action costs accepted by the Planning domain when the search completes within its expansion and generated-node budgets. Exhausting either budget returns an error distinct from a completed search that found no plan.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
var ErrExpansionLimitReached = errors.New("goap: expansion limit reached")
ErrExpansionLimitReached distinguishes bounded search from an unsatisfiable goal.
var ErrGenerationLimitReached = errors.New("goap: generated node limit reached")
ErrGenerationLimitReached means the search exhausted its node budget.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// MaxExpansions bounds non-stale nodes removed from the frontier.
// Its zero value is unlimited. A finite zero permits an already satisfied
// Goal but rejects search with ErrExpansionLimitReached.
MaxExpansions run.Quota
// MaxGeneratedNodes bounds cumulative frontier insertions, including the
// initial node and cheaper replacements of discovered states. Its zero value
// is unlimited; a finite zero rejects search with ErrGenerationLimitReached.
// Already satisfied Goals need no search. This bounds entries, not byte size.
MaxGeneratedNodes run.Quota
}
type Planner ¶
type Planner struct {
// contains filtered or unexported fields
}
Planner performs stateless uniform-cost search and is safe for concurrent use after construction.
func (*Planner) Plan ¶
Example ¶
package main
import (
"context"
"fmt"
"github.com/Tangerg/scope/agent/planning"
"github.com/Tangerg/scope/agent/planning/goap"
)
func main() {
ready, err := planning.NewCondition("service.ready", planning.TruthTrue)
if err != nil {
panic(err)
}
state, err := planning.NewWorldState(ready)
if err != nil {
panic(err)
}
goal, err := planning.NewGoal(planning.GoalConfig{
Name: "service.ready", Description: "The service is ready.", Conditions: []planning.Condition{ready},
})
if err != nil {
panic(err)
}
problem, err := planning.NewProblem(state, goal)
if err != nil {
panic(err)
}
plan, found, err := goap.New(goap.Config{}).Plan(context.Background(), problem)
if err != nil {
panic(err)
}
cost, err := problem.EvaluatePlan(context.Background(), plan)
if err != nil {
panic(err)
}
fmt.Println(found, len(plan.Actions()), cost)
}
Output: true 0 0