goap

package
v0.16.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 9, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

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.

Index

Examples

Constants

This section is empty.

Variables

View Source
var ErrExpansionLimitReached = errors.New("goap: expansion limit reached")

ErrExpansionLimitReached distinguishes bounded search from an unsatisfiable goal.

Functions

This section is empty.

Types

type Config

type Config struct {
	// MaxExpansions bounds states removed from the frontier. Zero selects a safe
	// default of 10,000 expansions.
	MaxExpansions uint32
}

Config contains the bounded search policy for a GOAP Planner.

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 New

func New(config Config) *Planner

New returns a planner whose search is bounded by configuration, because GOAP's state space grows with the action set and an unbounded search inside a Step would block the Process that owns it.

func (*Planner) Plan

func (p *Planner) Plan(ctx context.Context, problem planning.Problem) (planning.Plan, bool, error)
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.True)
	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)
	}

	fmt.Println(found, len(plan.Actions()), plan.TotalCost())
}
Output:
true 0 0

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL