Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/translate/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -693,7 +693,7 @@ def main():
timer = timers.Timer()
with timers.timing("Parsing", True):
task = pddl_parser.open(
domain_filename=get_options().domain, task_filename=get_options().task)
domain_filename=get_options().domain, problem_filename=get_options().problem)

with timers.timing("Normalizing task"):
normalize.normalize(task)
Expand Down
6 changes: 3 additions & 3 deletions src/translate/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ def get_arg_parser():
# process (issue1217).
argparser = argparse.ArgumentParser(prog=infer_prog())
argparser.add_argument(
"domain", help="path to domain pddl file")
"domain", metavar="DOMAIN", help="path to domain PDDL file")
argparser.add_argument(
"task", help="path to task pddl file")
"problem", metavar="PROBLEM", help="path to problem PDDL file")
argparser.add_argument(
"--relaxed", dest="generate_relaxed_task", action="store_true",
help="output relaxed task (no delete effects)")
Expand Down Expand Up @@ -96,7 +96,7 @@ def parse_args(args=None):
def get_options():
if options is None:
msg = ("No options provided (via options.set_options(...)). For example"
" 'options.set_options([<domain file>, <problem_file>])'.")
" 'options.set_options([<domain_file>, <problem_file>])'.")
raise RuntimeError(msg)
return options

Expand Down
9 changes: 5 additions & 4 deletions src/translate/pddl/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
from translate.pddl.predicates import Predicate

class Task:
def __init__(self, domain_name: str, task_name: str,
def __init__(self, domain_name: str, problem_name: str,
requirements: "Requirements",
types: List[Type], objects: List[TypedObject], predicates:
List[Predicate], functions: List[Function],
init: List[Union[Atom, Assign]], goal: Condition,
actions: List[Action], axioms: List[Axiom],
use_metric: bool) -> None:
self.domain_name = domain_name
self.task_name = task_name
self.problem_name = problem_name
self.requirements = requirements
self.types = types
self.objects = objects
Expand All @@ -41,8 +41,9 @@ def add_axiom(self, parameters, condition):
return axiom

def dump(self):
print("Problem %s: %s [%s]" % (
self.domain_name, self.task_name, self.requirements))
print("Domain:", self.domain_name)
print("Problem:", self.problem_name)
print("Requirements:", self.requirements)
print("Types:")
for type in self.types:
print(" %s" % type)
Expand Down
44 changes: 22 additions & 22 deletions src/translate/pddl_parser/parsing_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@
SYNTAX_ASSIGNMENT = "({=,increase} EXPRESSION EXPRESSION)"

SYNTAX_DOMAIN_DOMAIN_NAME = "(domain NAME)"
SYNTAX_TASK_PROBLEM_NAME = "(problem NAME)"
SYNTAX_TASK_DOMAIN_NAME = "(:domain NAME)"
SYNTAX_PROBLEM_PROBLEM_NAME = "(problem NAME)"
SYNTAX_PROBLEM_DOMAIN_NAME = "(:domain NAME)"
SYNTAX_METRIC = "(:metric minimize (total-cost))"

CONDITION_TAG_TO_SYNTAX = {
Expand Down Expand Up @@ -619,25 +619,25 @@ def parse_init(context, alist, predicate_dict, term_names):
return initial


def parse_task(domain_pddl, task_pddl):
def parse_task(domain_pddl, problem_pddl):
context = Context()
if not isinstance(domain_pddl, list):
context.error("Invalid definition of a PDDL domain.")
domain_name, domain_requirements, types, type_dict, constants, predicates, \
predicate_dict, functions, actions, axioms = parse_domain_pddl(context, domain_pddl)
if not isinstance(task_pddl, list):
context.error("Invalid definition of a PDDL task.")
task_name, task_domain_name, task_requirements, objects, init, goal, \
use_metric = parse_task_pddl(context, task_pddl, type_dict,
predicate_dict, {c.name for c in constants})

if domain_name != task_domain_name:
context.error(f"The domain name specified by the task "
f"({task_domain_name}) does not match the name specified "
if not isinstance(problem_pddl, list):
context.error("Invalid definition of a PDDL problem.")
problem_name, problem_domain_name, problem_requirements, objects, init, goal, \
use_metric = parse_problem_pddl(context, problem_pddl, type_dict,
predicate_dict, {c.name for c in constants})

if domain_name != problem_domain_name:
context.error(f"The domain name specified by the problem file "
f"({problem_domain_name}) does not match the name specified "
f"by the domain file ({domain_name}).")
requirements = pddl.Requirements(sorted(set(
domain_requirements.requirements +
task_requirements.requirements)))
problem_requirements.requirements)))
objects = constants + objects

check_for_duplicates(context, [o.name for o in objects], "object")
Expand All @@ -646,7 +646,7 @@ def parse_task(domain_pddl, task_pddl):
init += [pddl.Atom("=", (obj.name, obj.name)) for obj in objects]

return pddl.Task(
domain_name, task_name, requirements, types, objects,
domain_name, problem_name, requirements, types, objects,
predicates, functions, init, goal, actions, axioms, use_metric)


Expand Down Expand Up @@ -738,28 +738,28 @@ def parse_domain_pddl(context, domain_pddl):
yield the_axioms


def parse_task_pddl(context, task_pddl, type_dict, predicate_dict, constant_names):
iterator = iter(task_pddl)
with context.layer("Parsing task"):
def parse_problem_pddl(context, problem_pddl, type_dict, predicate_dict, constant_names):
iterator = iter(problem_pddl)
with context.layer("Parsing problem"):
try:
define_tag = next(iterator)
if define_tag != "define":
context.error("Task definition expected to start with '(define ")
context.error("Problem definition expected to start with '(define ")

with context.layer("Parsing problem name"):
problem_line = next(iterator)
check_named_block(context, problem_line, ["problem"], syntax=SYNTAX_TASK_PROBLEM_NAME)
check_named_block(context, problem_line, ["problem"], syntax=SYNTAX_PROBLEM_PROBLEM_NAME)
if len(problem_line) != 2 or not isinstance(problem_line[1], str):
context.error("The definition of the problem name expects exactly one word after 'problem'.",
problem_line[1:], syntax=SYNTAX_TASK_PROBLEM_NAME)
problem_line[1:], syntax=SYNTAX_PROBLEM_PROBLEM_NAME)
yield problem_line[1]

with context.layer("Parsing domain name"):
domain_line = next(iterator)
check_named_block(context, domain_line, [":domain"], syntax=SYNTAX_TASK_DOMAIN_NAME)
check_named_block(context, domain_line, [":domain"], syntax=SYNTAX_PROBLEM_DOMAIN_NAME)
if len(domain_line) != 2 or not isinstance(domain_line[1], str):
context.error("The definition of the domain name expects exactly one word after ':domain'.",
domain_line[1:], syntax=SYNTAX_TASK_DOMAIN_NAME)
domain_line[1:], syntax=SYNTAX_PROBLEM_DOMAIN_NAME)
yield domain_line[1]

requirements_opt = next(iterator)
Expand Down
10 changes: 5 additions & 5 deletions src/translate/pddl_parser/pddl_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ def parse_pddl_file(type, filename):
(type, filename, e))


def open(domain_filename=None, task_filename=None):
if domain_filename is None or task_filename is None:
def open(domain_filename=None, problem_filename=None):
if domain_filename is None or problem_filename is None:
# Importing options triggers parsing the problem and domain file names
# as arguments from the command line. We don't import unconditionally
# at the head of this file because open is exposed in __init__.py
# and as a result importing anything of the pddl_parser package in
# external code would then trigger this arg parse.
from translate.options import get_options
domain_filename = domain_filename or get_options().domain
task_filename = task_filename or get_options().task
problem_filename = problem_filename or get_options().problem

domain_pddl = parse_pddl_file("domain", domain_filename)
task_pddl = parse_pddl_file("task", task_filename)
problem_pddl = parse_pddl_file("problem", problem_filename)

return parsing_functions.parse_task(domain_pddl, task_pddl)
return parsing_functions.parse_task(domain_pddl, problem_pddl)
Loading