Warning
This page is located in archive. Go to the latest version of this course pages.

Assignment #1-2 - Grounding

Task Definition

Now that you have Grid-Mario modelled in PDDL, it’s time to work on how to solve it with classical planning. First step is parsing the PDDL to process it further. Thankfully, we have a parser you can use! You can download it here. The comments in the code should contain everything you need to know about the functions and structures. There is one function to parse the domain and one function to parse the problem.

All you have to do next create a grounding for the parsed PDDL that is going to be a base of the STRIPS representation later in the search. Grounding is a process of taking the lifted predicates and actions defined in the PDDL domain definition and instantiating them with objects provided in the problem definition. For more information check out tutorials from week 3.

In this task, we want to create a full naive grounding sorted in alphabetical order.

Full naive grounding means creating all possible instances of all actions and predicates - regardless of how nonsensical they seem.

Task Submission

This task is mandatory and you can recieve maximum of 10 points.

You will implement a grounder for parsed PDDL files in Python that will use the given PDDL parser. You will submit the following files into BRUTE

  • grounder.py - file containing the implementation of your grounder in Python

You should submit the .py file into BRUTE directly, do not put it in an archive.

The grounder will be called in the following way

python3 grounder.py domain.pddl problem.pddl predicates.txt actions.txt

where domain.pddl is the path to the PDDL domain definition and problem.pddl is the path to the PDDL problem definition. File predicates.txt is output file for the alphabetically ordered grounded predicates and actions.txt is output file for the alphabetically ordered grounded actions in the format described below.

Grounding will be provided in two output .txt files in the following format. First file ‘predicates.txt’ will contain all grounded predicates in alphabetical order. Both files will be saved in the same folder as grounder.py file.

predicate1 obj1 obj2
predicate1 obj1 obj3
predicate2 obj1
predicate2 obj2
...

The second file ‘actions.txt’ will contain list of all grounded alphabetically ordered actions’ names and their parameters. This is to shorten the output, of course, the grounding has to include also grounded preconditions and effects of all the actions.

action1 obj1 obj2 obj3
action1 obj1 obj3 obj4
action2 obj2
action2 obj3
...

Please do not add any unnecessary newlines at the end of the file.

Deadline

This task will be assigned during the 3. week of tutorials. You have two weeks to submit it.

Deadline for Monday tutorials: 20.3.2023 - 23:59

Deadline for Wednesday tutorials: 22.3.2023 - 23:59

Automated Evaluation

This assignment has automatic evaluation in BRUTE and you can receive maximum 8 points in BRUTE. The last 2 points (to make it 10 in total) will be assigned by the tutor after checking your code.

The evaluation runs your grounder with 4 different domains and problems and checks your solutions against reference solutions. You will receive output for every domain separately. Either, you will see OK if everything corresponds to the reference solution, or, you will se FAIL next to the file that contains any mistakes. In case of any mistakes in your files, you will see if the number of predicates/actions matches the reference solution and how many lines are mismatched if the number of lines is correct.

Template

Here's a simple template for the file with your grounder implementation. You do not have to stick with this structure, the functions and arguments are just to give you a place to start.

from parser import Parser # do not change this import 
import sys

# We recommend you split your code into these functions but feel free to adjust your implementation however you like 

def ground_all_predicates(domain):
    raise Exception('Predicate grounding not implemented')

def ground_all_actions(domain):
    raise Exception('Action grounding not implemented')

def print_grounded_predicates(predicates, filename):
    raise Exception('Printing grounded predicates into file not implemented')

def print_grounded_actions(actions, filename):
    raise Exception('Printing grounded actions into file not implemented')

if __name__ == '__main__':
    if len(sys.argv) < 5:
        raise Exception('Not enough arguments. Example: python grounder.py domain.pddl problem.pddl')

    domain_file = sys.argv[1]
    problem_file = sys.argv[2]
    predicates_file = sys.argv[3]
    actions_file = sys.argv[4]

    # Import provided PDDL parser 
    PDDL_parser = Parser()

    # Parse PDDL into domain and problem structures  
    domain = PDDL_parser.parse_domain(domain_file)
    problem = PDDL_parser.parse_problem(problem_file, domain)

    # Perform grounding on predicates and actions for this domain + problem 
    grounded_predicates = ground_all_predicates(domain)
    grounded_actions = ground_all_actions(domain)

    # Print alphabetically sorted grounding into these two files 
    print_grounded_predicates(grounded_predicates, predicates_file)
    print_grounded_actions(grounded_actions, actions_file)

Output Example

Here is the possible grounder output for the logistics exampe shown at the tutorials for the logistics domain. You can check out the PDDL files here.

predicates.txt

at a a 
at a b 
at a c 
at p a 
at p b 
at p c 
at t a 
at t b 
at t c 
corridor a a 
corridor a b 
corridor a c 
corridor b a 
corridor b b 
corridor b c 
corridor c a 
corridor c b 
corridor c c 
empty a 
empty t 
in p a 
in p t 
road a a 
road a b 
road a c 
road b a 
road b b 
road b c 
road c a 
road c b 
road c c 

actions.txt

drive t a a 
drive t a b 
drive t a c 
drive t b a 
drive t b b 
drive t b c 
drive t c a 
drive t c b 
drive t c c 
fly a a a 
fly a a b 
fly a a c 
fly a b a 
fly a b b 
fly a b c 
fly a c a 
fly a c b 
fly a c c 
load p a a 
load p a t 
load p b a 
load p b t 
load p c a 
load p c t 
unload p a a 
unload p a t 
unload p b a 
unload p b t 
unload p c a 
unload p c t   

courses/pui/assignments/assignment1-2.txt · Last modified: 2023/03/09 09:50 by urbanm30