Skip to content

Instantly share code, notes, and snippets.

@primaryobjects
Created July 7, 2024 01:25
Show Gist options
  • Save primaryobjects/ab68c8a6e0b163b4da7220a7f64f524c to your computer and use it in GitHub Desktop.
Save primaryobjects/ab68c8a6e0b163b4da7220a7f64f524c to your computer and use it in GitHub Desktop.
GraphPlan GPT prompt
Write a js implementation of GraphPlan, the planning algorithm based on STRIPS. The input will be a JSON object for domain and problem as provided below in examples.
The algorithm should include the following requirements:
1. The code should find mutexes as part of the process in order to only find a solution that satisfies the goal and with a path that does not contain mutexes among the actions.
2. Make sure that at each new level all available actions are added into the possibilities, as well as all valid combinations of parameters so that every valid action and parameter combination is considered at each level, as long as they do not violate a mutex.
3. Actions can also be 'noop' in which case action.action == 'noop' and action.effect == null.
Work slowly and step-by-step to create a correct and accurate implementation to perform this task. Think through each step in the process and write the code to implement the solution.
Here are examples of domain and problem cases to solve:
Example 1
PDDL
(define (domain blocksworld)
(:requirements :strips)
(:action move
:parameters (?b ?t1 ?t2)
:precondition (and (block ?b) (table ?t1) (table ?t2) (on ?b ?t1) (not (on ?b ?t2))
:effect (and (on ?b ?t2)) (not (on ?b ?t1))))
)
(define (problem move-blocks-from-a-to-b)
(:domain blocksworld)
(:init (and (block a) (block b) (table x) (table y)
(on a x) (on b x)))
(:goal (and (on a y) (on b y)))
)
JSON Representation
Domain
{"domain":"blocksworld","requirements":["strips"],"actions":[{"action":"move","parameters":[{"parameter":"b","type":null},{"parameter":"t1","type":null},{"parameter":"t2","type":null}],"precondition":[{"operation":"and","action":"block","parameters":["b"]},{"operation":"","action":"table","parameters":["t1"]},{"operation":"","action":"table","parameters":["t2"]},{"operation":"","action":"on","parameters":["b","t1"]},{"operation":"not","action":"on","parameters":["b","t2"]}],"effect":[{"operation":"and","action":"on","parameters":["b","t2"]},{"operation":"not","action":"on","parameters":["b","t1"]}],"parameterCombinations":[["a"],["b"],["x"],["y"],["a","b"],["b","a"],["a","x"],["x","a"],["b","x"],["x","b"],["a","y"],["y","a"],["b","y"],["y","b"],["x","y"],["y","x"],["a","b","x"],["a","x","b"],["b","a","x"],["b","x","a"],["x","a","b"],["x","b","a"],["a","b","y"],["a","y","b"],["b","a","y"],["b","y","a"],["y","a","b"],["y","b","a"],["a","x","y"],["a","y","x"],["x","a","y"],["x","y","a"],["y","a","x"],["y","x","a"],["b","x","y"],["b","y","x"],["x","b","y"],["x","y","b"],["y","b","x"],["y","x","b"],["a","b","x","y"],["a","b","y","x"],["a","x","b","y"],["a","x","y","b"],["a","y","b","x"],["a","y","x","b"],["b","a","x","y"],["b","a","y","x"],["b","x","a","y"],["b","x","y","a"],["b","y","a","x"],["b","y","x","a"],["x","a","b","y"],["x","a","y","b"],["x","b","a","y"],["x","b","y","a"],["x","y","a","b"],["x","y","b","a"],["y","a","b","x"],["y","a","x","b"],["y","b","a","x"],["y","b","x","a"],["y","x","a","b"],["y","x","b","a"]]}],"values":{"null":["a","b","x","y"]}}
Problem
{"name":"move-blocks-from-a-to-b","domain":"blocksworld","objects":null,"states":[{"name":"init","actions":[{"operation":"and","action":"block","parameters":["a"]},{"operation":"","action":"block","parameters":["b"]},{"operation":"","action":"table","parameters":["x"]},{"operation":"","action":"table","parameters":["y"]},{"operation":"","action":"on","parameters":["a","x"]},{"operation":"","action":"on","parameters":["b","x"]}]},{"name":"goal","actions":[{"operation":"and","action":"on","parameters":["a","y"]},{"operation":"","action":"on","parameters":["b","y"]}]}],"values":{"null":["a","b","x","y"]}}
Example 2
PDDL
(define (domain blocksworld)
(:requirements :strips :typing)
(:types block table)
(:action move
:parameters (?b - block ?t1 - table ?t2 - table)
:precondition (and (block ?b) (table ?t1) (table ?t2) (on ?b ?t1) not (on ?b ?t2) (clear ?b))
:effect (and (on ?b ?t2)) (not (on ?b ?t1))))
(:action stack
:parameters (?a - block ?b - block ?t1 - table)
:precondition (and (block ?a) (block ?b) (table ?t1) (clear ?a) (clear ?b) (on ?a ?t1) (on ?b ?t1))
:effect (and (on ?a ?b) not (on ?a ?t1) not (clear ?b))
)
(:action unstack
:parameters (?a - block ?b - block ?t1 - table)
:precondition (and (block ?a) (block ?b) (table ?t1) (on ?b ?t1) (clear ?a) (on ?a ?b))
:effect (and (on ?a ?t1) not (on ?a ?b) (clear ?b))
)
)
(define (problem stack-blocks-a-b-from-tablex-to-ab-tabley)
(:domain blocksworld)
(:objects
a b - block
x y - table)
(:init (and (block a) (block b) (table x) (table y)
(on a x) (on b x) (clear a) (clear b)))
(:goal (and (on a b) (on b y) (clear a) ))
)
JSON Representation
domain = {
"domain":"blocksworld","requirements":["strips","typing"],"types":["block","table"],"actions":[{"action":"move","parameters":[{"parameter":"b","type":"block"},{"parameter":"t1","type":"table"},{"parameter":"t2","type":"table"}],"precondition":[{"operation":"and","action":"block","parameters":["b"]},{"operation":"","action":"table","parameters":["t1"]},{"operation":"","action":"table","parameters":["t2"]},{"operation":"","action":"on","parameters":["b","t1"]},{"operation":"not","action":"on","parameters":["b","t2"]},{"operation":"","action":"clear","parameters":["b"]}],"effect":[{"operation":"and","action":"on","parameters":["b","t2"]},{"operation":"not","action":"on","parameters":["b","t1"]}],"parameterCombinations":[["a","x","y"],["a","y","x"],["b","x","y"],["b","y","x"]]},{"action":"stack","parameters":[{"parameter":"a","type":"block"},{"parameter":"b","type":"block"},{"parameter":"t1","type":"table"}],"precondition":[{"operation":"and","action":"block","parameters":["a"]},{"operation":"","action":"block","parameters":["b"]},{"operation":"","action":"table","parameters":["t1"]},{"operation":"","action":"clear","parameters":["a"]},{"operation":"","action":"clear","parameters":["b"]},{"operation":"","action":"on","parameters":["a","t1"]},{"operation":"","action":"on","parameters":["b","t1"]}],"effect":[{"operation":"and","action":"on","parameters":["a","b"]},{"operation":"not","action":"on","parameters":["a","t1"]},{"operation":"not","action":"clear","parameters":["b"]}],"parameterCombinations":[["a","b","x"],["b","a","x"],["a","b","y"],["b","a","y"]]},{"action":"unstack","parameters":[{"parameter":"a","type":"block"},{"parameter":"b","type":"block"},{"parameter":"t1","type":"table"}],"precondition":[{"operation":"and","action":"block","parameters":["a"]},{"operation":"","action":"block","parameters":["b"]},{"operation":"","action":"table","parameters":["t1"]},{"operation":"","action":"on","parameters":["b","t1"]},{"operation":"","action":"clear","parameters":["a"]},{"operation":"","action":"on","parameters":["a","b"]}],"effect":[{"operation":"and","action":"on","parameters":["a","t1"]},{"operation":"not","action":"on","parameters":["a","b"]},{"operation":"","action":"clear","parameters":["b"]}],"parameterCombinations":[["a","b","x"],["b","a","x"],["a","b","y"],["b","a","y"]]}],"values":{"block":["a","b"],"table":["x","y"]}
};
problem = {
"name":"stack-blocks-a-b-from-tablex-to-ab-tabley","domain":"blocksworld","objects":[{"parameters":["a","b"],"type":"block"},{"parameters":["x","y"],"type":"table"}],"states":[{"name":"init","actions":[{"operation":"and","action":"block","parameters":["a"]},{"operation":"","action":"block","parameters":["b"]},{"operation":"","action":"table","parameters":["x"]},{"operation":"","action":"table","parameters":["y"]},{"operation":"","action":"on","parameters":["a","x"]},{"operation":"","action":"on","parameters":["b","x"]},{"operation":"","action":"clear","parameters":["a"]},{"operation":"","action":"clear","parameters":["b"]}]},{"name":"goal","actions":[{"operation":"and","action":"on","parameters":["a","b"]},{"operation":"","action":"on","parameters":["b","y"]},{"operation":"","action":"clear","parameters":["a"]}]}],"values":{"block":["a","b"],"table":["x","y"]}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment