# Practicum 6: Integrating PDDL and a KB

<div align="center">

**Practicum date: {{prac6_date}}**  
</div>

**Course:** RO47014 Knowledge Representation and Symbolic Reasoning, TU Delft, CoR  
**Instructors:** Juri Morisse, email: J.S.Morisse@tudelft.nl

In this practicum you will practice working with both PDDL and an ontology. First, you will train your understanding of both by answering: What knowledge should be modeled where? Then, you practice their integration. Lastly, we prepare the homework assignment.

We expect the practicum to take 90 minutes: 15 minutes for discussing the last homework, 60 minutes for the exercises, and 30 minutes for preparing the homework.

**You do not need to hand in anything for this practicum.**

---

## Preparation

Before completing this practicum, you should have attended/watched Lecture 6 on the differences between and integration of PDDL and ontogies. It is assumed that you are familiar with:
- PDDL
- Ontologies
- The differences between PDDL & Ontologies
- The kind of problems that require integration of PDDL & Ontologies
- Different approaches for integrating PDDL & Ontologies
- One example for how to translate OWL concepts into PDDL concepts

---

## Exercise 1: Assign Knowledge
A robot uses both PDDL and ontologies to represent its knowledge.
The following are statements the robot needs to know.
Decide where they should be represented: PDDL (problem or domain) or ontology (schema or data)!
1. Picking up an object changes the object's location.
2. The robot can open doors.​
3. A door is connecting two rooms.​
4. Fragile objects should be picked up with less force.​
5. PickUp, Place, and Push are all actions performed by the robot's arm.​
6. D1 is the door between the living room and the kitchen.​
7. There is an apple A1, a mug M1, and a newspaper P1 on the table.​
8. A mug is a container in which liquids can be poured and which usually is fragile.​

---

## Exercise 2: Integrating PDDL & Ontology
Consider the scenario from the lecture: A robot is tasked to "Throw the apple away!". PDDL models all required actions but does not contain the knowledge necessary to decide into which bin the apple belongs. Luckily, the robtos also has ontological knowledge about waste classification.

<details>
<summary>The initial PDDL domain file</summary>

```lisp
(define (domain trash)
   (:predicates
      (at ?o ?l)
      (holding ?o)
      (in ?o ?b)
   )
   (:action pick-up
      :parameters (?o ?l)
      :precondition (at ?o ?l)
      :effect (holding ?o)
   )
   (:action put-in-bin
      :parameters (?o ?b)
      :precondition (holding ?o)
      :effect (in ?o ?b)
   )
)
```

</details>

<details>
<summary>The initial PDDL problem file</summary>

```lisp
(define (problem throw-apple)
   (:domain trash)
   (:objects
      apple
      green_bin blue_bin yellow_bin
      table
   )
   (:init
      (at apple table)
   )
   (:goal
      ;; TODO: complete
   )
)
```

</details>

</details>

<details>
<summary>The ontology</summary>

```
Apple ⊑ Fruit​
Fruit ⊑ OrganicWaste​
OrganicWaste → belongsIn GreenBin​
GreenBin ⊑ WasteBin
```

</details>

### Part 1: Prepare Integration
Decide what exact information should be transferred from the ontology to the PDDL files.

### Part 2: Define Translation
Decide how this information can be translated from the ontology into PDDL.

### Part 3: Reflection
Can you think of a different approach? If so, describe and compare both approaches.

---

## Homework Preparation

#### Cloning the Homework Repository
We recommend cloning the homework repository into a new workspace.
For detailed instructions, see the homework PDF provided via Brightspace.

#### Working on the Homework
To work on the homework, you can simply use the course Singularity image.
Within the root of the homework repository, simply activate the course Singluarity image, e.g. if you pulled the image into `~/Downloads`:

```console
cd ~/krr_week6_hw
singularity shell -p ~/Downloads/ro47014_humble_v3.sif
```

Once you completed `mission_planner.py`, you can test your solution by:
1. Start the TypeDB server and keep it running
```console
cd ~/krr_week6_hw
singularity shell -p ~/Downloads/ro47014_humble_v3.sif
typedb server --storage.data=$PWD/typedb_data
```

2. In a new terminal, setup the TypeDB database and run your mission planner.
```console
cd ~/krr_week6_hw
singularity shell -p ~/Downloads/ro47014_humble_v3.sif
python3 setup_database.py
python3 mission_planner.py
```

#### Submitting the Homework

When you have completed the assignment, prepare your submission as follows:

1. Make sure your `mission_planner.py` is complete and tested
2. Run your code one final time to generate `problem_generated.pddl`
3. Create a ZIP file named: **`StudentID_Surname_Week6.zip`**
   - Example: `1234567_Smith_Week6.zip`
4. Include these two files in the ZIP:
   - `mission_planner.py` (your implementation)
   - `problem_generated.pddl` (generated by your code)
5. Submit your .zip file via Brightspace.