Skip to content

Commit

Permalink
Merge pull request #16 from LBonassi95/master
Browse files Browse the repository at this point in the history
Fix in parser
  • Loading branch information
francescofuggitti authored Nov 1, 2024
2 parents dc53b78 + 801c139 commit 851539a
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 25 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ Temporary Items
.idea/**/dictionaries
.idea/**/shelf

#VScode
.vscode

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
Expand Down
32 changes: 32 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
FROM ubuntu:18.04

RUN apt-get update && apt-get install --no-install-recommends -y \
ca-certificates \
cmake \
g++ \
git \
libgmp3-dev \
make \
python3 \
wget \
time \
zlib1g-dev

# Set up some environment variables.
ENV CXX g++

RUN apt-get install -y mona && \
apt-get install -y libssl-dev && \
apt-get install -y python3 && \
apt-get install -y python3-pip && \
python3 -m pip install --upgrade pip

RUN git clone https://github.com/whitemech/FOND4LTLf.git && \
cd FOND4LTLf && \
pip install .

ENV DEBIAN_FRONTEND noninteractive
ENV LC_ALL C.UTF-8
ENV LANG C.UTF-8

CMD ["fond4ltlfpltlf"]
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<h1 align="center">
FOND 4 LTL<sub>f</sub> - PLTL<sub>f</sub>
FOND 4 LTL<sub>f</sub>
</h1>

<p align="center">
Expand All @@ -21,7 +21,7 @@
<img alt="docs" src="https://github.com/whitemech/FOND4LTLfPLTLf/workflows/docs/badge.svg">
</a>
<a href="https://codecov.io/gh/whitemech/FOND4LTLfPLTLf">
<img alt="codecov" src="https://codecov.io/gh/whitemech/FOND4LTLfPLTLf/branch/master/graph/badge.svg">
<img src="https://codecov.io/gh/whitemech/FOND4LTLfPLTLf/branch/master/graph/badge.svg?token=KKWRAH29O7"/>
</a>
</p>
<p align="center">
Expand All @@ -44,11 +44,11 @@
<a href="https://doi.org/10.5281/zenodo.4876281"><img src="https://zenodo.org/badge/DOI/10.5281/zenodo.4876281.svg" alt="DOI"></a>
</p>

FOND 4 LTL<sub>f</sub>/PLTL<sub>f</sub> is a tool that compiles Fully Observable Non-Deterministic (FOND) planning
FOND 4 LTL<sub>f</sub> is a tool that compiles Fully Observable Non-Deterministic (FOND) planning
problems with temporally extended goals, specified either in LTL<sub>f</sub> or in PLTL<sub>f</sub>, into classical FOND
planning problems.

It is also available online at [fond4ltlfpltlf.diag.uniroma1.it](https://fond4ltlf.herokuapp.com/).
It is also available online at [https://fond4ltlf.herokuapp.com/](https://fond4ltlf.herokuapp.com/).

## Prerequisites

Expand All @@ -58,20 +58,20 @@ This tool is based on the following libraries:
- [ply](https://pypi.org/project/ply/)
- [click](https://pypi.org/project/click/)

They are automatically added while installing FOND4LTL<sub>f</sub>/PLTL<sub>f</sub>.
They are automatically added while installing FOND4LTL<sub>f</sub>.

## Install

- Intall from source (`master` branch):

```
pip install git+https://github.com/whitemech/FOND4LTLfPLTLf.git
pip install git+https://github.com/whitemech/FOND4LTLf.git
```

- or, clone the repository and install:

```
git clone https://github.com/whitemech/FOND4LTLfPLTLf.git
git clone https://github.com/whitemech/FOND4LTLf.git
cd fond4ltlfpltlf
pip install .
```
Expand Down Expand Up @@ -102,9 +102,9 @@ To run only the code style checks: `tox -e flake8`

## License

FOND4LTL<sub>f</sub>/PLTL<sub>f</sub> is released under the GNU Lesser General Public License v3.0 or later (LGPLv3+).
FOND4LTL<sub>f</sub> is released under the GNU Lesser General Public License v3.0 or later (LGPLv3+).

Copyright 2019-2020 WhiteMech
Copyright 2019-2022 WhiteMech

## Author

Expand Down
34 changes: 21 additions & 13 deletions fond4ltlfpltlf/automa/automaton.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,29 @@ def create_operators_trans(self, domain_predicates, grounded_symbols):
source_action, vars_mapping, my_predicates, my_variables
)
if isinstance(fluents_list_precond, FormulaAnd):
new_precondition = fluents_list_precond
new_preconditions = [fluents_list_precond]
else:
new_precondition = FormulaAnd(
[fluents_list_precond]
+ [Literal.negative(Predicate("turnDomain"))]
)
new_effects = self.compute_effects(destination, my_variables)
new_operators.append(
Action(
"trans-" + str(counter),
parameters,
new_precondition,
new_effects,
# Luigi: this should be an Or
assert isinstance(fluents_list_precond, FormulaOr)
# For each disjunct I create a new precondition
new_preconditions = [
FormulaAnd(pre.andList + [Literal.negative(Predicate("turnDomain"))])
if isinstance(pre, FormulaAnd)
else FormulaAnd([pre] + [Literal.negative(Predicate("turnDomain"))])
for pre in fluents_list_precond.orList
]
subcounter = 0
for newpre in new_preconditions:
new_effects = self.compute_effects(destination, my_variables)
new_operators.append(
Action(
"trans-" + str(counter) + str(subcounter),
parameters,
newpre,
new_effects,
)
)
)
subcounter += 1
counter += 1
else:
pass
Expand Down
7 changes: 5 additions & 2 deletions fond4ltlfpltlf/parser/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,11 @@ def p_typed_constants_lst(self, p):

def p_action_def_lst(self, p):
"""action_def_lst : action_def action_def_lst
| action_def"""
if len(p) == 2:
| action_def
| """
if len(p) == 1:
p[0] = []
elif len(p) == 2:
p[0] = [p[1]]
else:
p[0] = [p[1]] + p[2]
Expand Down
2 changes: 1 addition & 1 deletion fond4ltlfpltlf/pddl/domain.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def __str__(self):
domain_str = "(define (domain {0})\n".format(self.name)
domain_str += "\t(:requirements {0})\n".format(" ".join(self.requirements))
if self.types:
domain_str += "\t(:types {0})\n".format(" ".join(self.types))
domain_str += "\t(:types {0})\n".format(" ".join(map(str, self.types)))
if self.constants:
domain_str += "\t(:constants {0})\n".format(
" ".join(map(str, self.constants))
Expand Down
24 changes: 24 additions & 0 deletions tests/data/pddl-domains/robot-coffee/coffee2.pddl
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
(define (problem coffee1)
(:domain robot_coffee)
(:objects o1 o2 o3 lab - office
c - kitchen)
(:init (robot_at lab)
(connected lab o1)
(connected o1 lab)
(connected o1 o2)
(connected o2 o1)
(connected o1 o3)
(connected o3 o1)
(connected o3 o2)
(connected o2 o3)
(connected c o3)
(connected o3 c))
; (:goal (and
; (until (true) (coffee_at o1))
; (until (true) (coffee_at o2))
; (until (true) (coffee_at o3))
; ))

(:goal (and (connected o3 c)))

)
49 changes: 49 additions & 0 deletions tests/data/pddl-domains/robot-coffee/domain-fond.pddl
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
(define (domain robot_coffee)
(:requirements :strips :non-deterministic)

(:types office - room
kitchen - room)
(:predicates (robot_at ?x - room)
(coffeeat ?x - room)
(connected ?x - room ?y - room)
(has_coffee)
)

(:action move_to
:parameters
(?x - room
?y - room)
:precondition
(and
(robot_at ?x) (connected ?x ?y))
:effect
(and
(robot_at ?y) (not (robot_at ?x)))
)

(:action prepare_coffee
:parameters
(?x - kitchen)
:precondition
(and
(robot_at ?x) (not (has_coffee)))
:effect
(has_coffee)
)

(:action put_coffee
:parameters
(?x - office)
:precondition
(and
(robot_at ?x) (has_coffee))
:effect
(and (not (has_coffee))
(oneof
(and (coffeeat ?x))
(and)
))
)


)
19 changes: 19 additions & 0 deletions tests/test_parsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -669,3 +669,22 @@ def test_problem_init(self):
def test_problem_goal(self):
"""Test that the goal condition is correct."""
assert self.pddl_goal == Predicate("vehicleat", ["l13"])


def test_robot_coffee():
planning_domain = open(str(Path(TEST_ROOT_DIR,
"data",
"pddl-domains",
"robot-coffee",
"domain-fond.pddl",))).read()
planning_problem = open(str(Path(TEST_ROOT_DIR,
"data",
"pddl-domains",
"robot-coffee",
"coffee2.pddl",))).read()
pddl_parser = PDDLParser()
tmp = list(planning_problem[400:])
parsed_domain = pddl_parser(planning_domain)
parsed_problem = pddl_parser(planning_problem)
assert parsed_domain is not None
assert parsed_problem is not None

0 comments on commit 851539a

Please sign in to comment.