Skip to content

Commit

Permalink
working in reduced space, removed store and changed domain
Browse files Browse the repository at this point in the history
  • Loading branch information
maxzuo committed Oct 12, 2024
1 parent fa5fa1a commit 9f231e6
Show file tree
Hide file tree
Showing 10 changed files with 306 additions and 763 deletions.
4 changes: 2 additions & 2 deletions planetarium/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

# load domains
for domain in resources.files(domains).iterdir():
with domain.open() as f:
DOMAINS[os.path.basename(domain).split(".")[0]] = f.read()
with domain.open() as f:
DOMAINS[os.path.basename(domain).split(".")[0]] = f.read()

from .evaluate import evaluate
24 changes: 7 additions & 17 deletions planetarium/domains/rover-single.pddl
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
(define (domain rover-single)
(:requirements :strips :typing)
(:types
waypoint store camera mode objective
waypoint camera mode objective
)

(:predicates
(at_rover ?y - waypoint)
(at_lander ?y - waypoint)
(can_traverse ?x - waypoint ?y - waypoint)
(empty ?s - store)
(have_rock_analysis ?w - waypoint)
(have_soil_analysis ?w - waypoint)
(full ?s - store)
(supports ?c - camera ?m - mode)
(available)
(visible ?w - waypoint ?p - waypoint)
Expand All @@ -33,23 +31,15 @@
)

(:action sample_soil
:parameters (?s - store ?p - waypoint)
:precondition (and (at_rover ?p) (at_soil_sample ?p) (empty ?s))
:effect (and (not (empty ?s)) (full ?s) (have_soil_analysis ?p)
(not (at_soil_sample ?p)))
:parameters (?p - waypoint)
:precondition (and (at_rover ?p) (at_soil_sample ?p))
:effect (and (have_soil_analysis ?p))
)

(:action sample_rock
:parameters (?s - store ?p - waypoint)
:precondition (and (at_rover ?p) (at_rock_sample ?p) (empty ?s))
:effect (and (not (empty ?s)) (full ?s) (have_rock_analysis ?p)
(not (at_rock_sample ?p)))
)

(:action drop
:parameters (?y - store)
:precondition (full ?y)
:effect (and (not (full ?y)) (empty ?y))
:parameters (?p - waypoint)
:precondition (and (at_rover ?p) (at_rock_sample ?p))
:effect (and (have_rock_analysis ?p))
)

(:action take_image
Expand Down
1 change: 1 addition & 0 deletions planetarium/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
VALIDATE = os.getenv("VALIDATE", "Validate")
DOWNWARD = os.getenv("DOWNWARD", "downward")


def evaluate(
source_pddl_str: str,
target_pddl_str: str,
Expand Down
51 changes: 51 additions & 0 deletions planetarium/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@
import networkx as nx
import rustworkx as rx

from pddl.core import And, Problem, Domain
from pddl.logic.predicates import Predicate
from pddl.logic.terms import Constant
from pddl.formatter import problem_to_string


class Label(str, enum.Enum):
CONSTANT = "constant"
Expand Down Expand Up @@ -578,3 +583,49 @@ def join(init: SceneGraph, goal: SceneGraph) -> "ProblemGraph":
domain=init.domain,
requirements=init._requirements,
)

def to_pddl_str(self) -> str:
"""
Convert a ProblemGraph object to a PDDL problem description string.
NOTE: REQUIREMENTS ARE NOT SUPPORTED YET.
Parameters:
graph (ProblemGraph): The ProblemGraph object to convert.
Returns:
str: A string containing the PDDL problem description.
"""
constant_objs = [
Constant(name=n.name)
for n in self.nodes
if n.label == Label.CONSTANT
]

init_predicates = []
goal_predicates = []
for n in (n for n in self.nodes if n.label == Label.PREDICATE):
args: list[PlanGraphNode] = [
v for v, _ in sorted(self.out_edges(n), key=lambda e: e[1].position)
]
pddl_args = [
Constant(name=v.name)
for v in args
]

predicate = Predicate(n.typing, *pddl_args)
if n.scene == Scene.INIT:
init_predicates.append(predicate)
elif n.scene == Scene.GOAL:
goal_predicates.append(predicate)

return problem_to_string(
Problem(
name="name",
domain=Domain(name=self.domain, requirements=[]),
objects=constant_objs,
init=sorted(init_predicates),
goal=And(*sorted(goal_predicates)),
requirements=[],
)
)
Loading

0 comments on commit 9f231e6

Please sign in to comment.