Git Product home page Git Product logo

goap's Introduction

GOAP

pypi-badge

A Python implementation of the Goal Oriented Action Planner.

pip install -u goap-ai

To be used in combination with existing AI techniques and tools, this planner can help to realise complex, reactive AI without the problems associated with managing large interconnected state transitions.

See http://alumni.media.mit.edu/~jorkin/goap.html for more information, as well as some archived resources at https://github.com/agoose77/goap-resources.

goap's People

Contributors

agoose77 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

goap's Issues

initial world state doesn't satisfy preconditions

from goap.action import Action
from goap.planner import Goal, Planner
from goap.director import Director


class BecomeTwo(Action):
    effects = {"age": 2}
    preconditions = {"age": 1}


class AgeGoal(Goal):
    priority = 1.0
    state = {"age": 2}


if __name__ == "__main__":

    world_state = {"age": 1}

    actions = [BecomeTwo()]
    goals = [AgeGoal()]

    planner = Planner(actions, world_state)
    director = Director(planner, world_state, goals)
    print("Initial State:", world_state)

    plan = director.find_best_plan()

Initial State: {'age': 1}
Traceback (most recent call last):
  File "debug-goap.py", line 27, in <module>
    plan = director.find_best_plan()
  File "/Users/tewhalen/Devel/GOAP-fork/goap/director.py", line 78, in find_best_plan
    raise NoPlanFoundError("Couldn't find suitable plan")
goap.director.NoPlanFoundError: Couldn't find suitable plan

Pre-condition is ignored when multiple actions have the same pre-condition

When multiple actions have the same pre-condition, the primary action has to precede the dependent actions. However, the current behavior seems to be that the primary action is placed arbitrarily in the plan step wherein some actions are placed ahead even if the pre-condition is not met.

In the following example, the expectation is that the action Action1 should be the first action in the plan because every other action has the precondition {"FIRST": True}. However, that is not the result.


from action import Action
from planner import Planner


class Action1(Action):
    effects = {"FIRST": True}
    preconditions = {}


class Action2(Action):
    effects = {"SECOND": True}
    preconditions = {"FIRST": True}


class Action3(Action):
    effects = {"THIRD": True}
    preconditions = {"FIRST": True, "SECOND": True}


class Action4(Action):
    effects = {"FOURTH": True}
    preconditions = {"FIRST": True, "THIRD": True}


if __name__ == "__main__":
    world_state = {"FIRST": False, "SECOND": False, "THIRD": False, "FOURTH": False}
    goal_state = {"FOURTH": True}
    print("Initial State:", world_state)
    print("Goal State:   ", goal_state)

    actions = [Action1(), Action2(), Action3(), Action4()]
    planner = Planner(world_state, actions)

    plan = planner.find_plan(goal_state)
    
    plan_str = 'PLAN:\n'
    for ix, step in enumerate(plan):
        plan_str += "....."*(ix+1) + str(step.action) + '\n'
    print(plan_str)

Output plan steps:

PLAN:
.....Action2
..........Action3
...............Action1
....................Action4

Action2 is the first action; Its pre-condition {"FIRST": True} is being ignored.

Action preconditions sometimes not honored

I just tested a simple setup with the newest changes. It seems that sometimes preconditions of actions are ignored. See the example below. You can switch the effects variable in the Place(Action) class to see the difference.

For some reason the planner skips Carry and directly selects Place if there is another state affected in the effects.

I will check further but didn't find the source of the problem yet.

from goap.action import Action
from goap.planner import RegressivePlanner

# see https://github.com/agoose77/GOAP

TOOL_STATE = "tool"
BLOCK_IN_PLACE_STATE = "block_in_place"
BLOCK_IN_STORAGE_STATE = "block_in_storage"


class Carry(Action):
    effects = {TOOL_STATE: True, BLOCK_IN_STORAGE_STATE: False}
    preconditions = {TOOL_STATE: False, BLOCK_IN_STORAGE_STATE: True}


class Place(Action):
    # effects={BLOCK_IN_PLACE_STATE: True}
    effects = {TOOL_STATE: False, BLOCK_IN_PLACE_STATE: True}
    preconditions = {TOOL_STATE: True, BLOCK_IN_PLACE_STATE: False}


if __name__ == "__main__":
    world_state = {TOOL_STATE: False, BLOCK_IN_PLACE_STATE: False, BLOCK_IN_STORAGE_STATE: True}
    goal_state = {BLOCK_IN_PLACE_STATE: True}
    print("Initial State:", world_state)
    print("Goal State:   ", goal_state)

    actions = [Carry(), Place()]
    planner = RegressivePlanner(actions)

    plan = planner.find_plan(world_state, goal_state)
    for p in plan:
        print(p)

Feature request: Precondition value from list

Is there a way to define not only a singular value per state variable but a list of values as precondition for an action? As far as I can see the ellipsis and reference() function pass the goal value to the precondition without further checking.
If it is not yet implemented, i would like to request this feature, as i think this makes the planner more versatile (and also helps with my problem setting ;) )

btw. I tried something like this for the preconditions of an action but it gets stuck in an infinite loop:

effects = {TOOL_STATE: None, BLOCK_IN_PLACE_STATE: ...}
preconditions = {
        TOOL_STATE: reference(BLOCK_IN_PLACE_STATE) if reference(BLOCK_IN_PLACE_STATE) in CARRY_ABLE else ERROR_VAL,
        BLOCK_IN_PLACE_STATE: None}

Typing issues

When testing the newest changes i was encountering various typing issues throughout the project: "TypeError: 'type' object is not subscriptable"
I fixed this in my install by changing all typing occurrences of list and dict to their typing aliases List and Dict.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.