Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove mapping, proposition names *are* PDDL ground fluents. Fix ambiguity in DP names #262

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

marcofavorito
Copy link
Member

Proposed changes

After this commit, to specify the PPLTL formula, there is no need to provide an explicit mapping, since it is assumed that the propositions are the ground fluents.

E.g. if previously the formula was specified as follows:

formula = "on_b_a & O(ontable_c)"

Now we require that the propositions can be interpreted as PDDL predicates, i.e.:

formula = '"on b a" & O("ontable c")'

Pylogics does not allow spaces in the proposition name; therefore, the double quotes are always required.

Only exception is when the predicate is unary:

formula = 'Y(O(made-p4)))'

(as in openstacks).

@LBonassi95 @francescofuggitti I would like to make a thorough discussion with you on this PR since it changes quite a few things.

Fixes

n/a

Types of changes

What types of changes does your code introduce?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist

Put an x in the boxes that apply.

  • I have read the CONTRIBUTING doc
  • I am making a pull request against the develop branch (left side). Also, you should start your branch off our develop.
  • Lint and unit tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works

Further comments

n/a

from plan4past.utils.atoms_visitor import find_atoms
_PDDL_NAME_REGEX = "[A-Za-z][-_A-Za-z0-9]*"
_GROUND_FLUENT_REGEX = re.compile(
rf"(\"({_PDDL_NAME_REGEX})( {_PDDL_NAME_REGEX})*\")|({_PDDL_NAME_REGEX})"
Copy link
Member Author

@marcofavorito marcofavorito Jul 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

either

"predicate_name const1 const2 ..." or predicate_name.

E.g.:

O("on a b") & O(emptyhand)

"s28-0": "O(served_p14 & served_p15 & served_p16 & served_p17 & served_p18 & served_p19 & served_p20 & served_p21 & served_p22 & served_p23 & served_p24 & served_p25 & served_p26 & served_p27) & O(served_p0 & served_p1 & served_p2 & served_p3 & served_p4 & served_p5 & served_p6 & served_p7 & served_p8 & served_p9 & served_p10 & served_p11 & served_p12 & served_p13 & !(Y(O(served_p14 | served_p15 | served_p16 | served_p17 | served_p18 | served_p19 | served_p20 | served_p21 | served_p22 | served_p23 | served_p24 | served_p25 | served_p26 | served_p27)))) & !(O(boarded_p0 & (boarded_p1 | boarded_p2 | boarded_p3 | boarded_p4 | boarded_p5 | boarded_p6 | boarded_p7 | boarded_p8 | boarded_p9))) & !(O(boarded_p1 & (boarded_p2 | boarded_p3 | boarded_p4 | boarded_p5 | boarded_p6 | boarded_p7 | boarded_p8 | boarded_p9 | boarded_p10))) & !(O(boarded_p2 & (boarded_p3 | boarded_p4 | boarded_p5 | boarded_p6 | boarded_p7 | boarded_p8 | boarded_p9 | boarded_p10 | boarded_p11))) & !(O(boarded_p3 & (boarded_p4 | boarded_p5 | boarded_p6 | boarded_p7 | boarded_p8 | boarded_p9 | boarded_p10 | boarded_p11 | boarded_p12))) & !(O(boarded_p4 & (boarded_p5 | boarded_p6 | boarded_p7 | boarded_p8 | boarded_p9 | boarded_p10 | boarded_p11 | boarded_p12 | boarded_p13))) & !(O(boarded_p5 & (boarded_p6 | boarded_p7 | boarded_p8 | boarded_p9 | boarded_p10 | boarded_p11 | boarded_p12 | boarded_p13 | boarded_p14))) & !(O(boarded_p6 & (boarded_p7 | boarded_p8 | boarded_p9 | boarded_p10 | boarded_p11 | boarded_p12 | boarded_p13 | boarded_p14 | boarded_p15))) & !(O(boarded_p7 & (boarded_p8 | boarded_p9 | boarded_p10 | boarded_p11 | boarded_p12 | boarded_p13 | boarded_p14 | boarded_p15 | boarded_p16))) & !(O(boarded_p8 & (boarded_p9 | boarded_p10 | boarded_p11 | boarded_p12 | boarded_p13 | boarded_p14 | boarded_p15 | boarded_p16 | boarded_p17))) & !(O(boarded_p9 & (boarded_p10 | boarded_p11 | boarded_p12 | boarded_p13 | boarded_p14 | boarded_p15 | boarded_p16 | boarded_p17 | boarded_p18))) & !(O(boarded_p10 & (boarded_p11 | boarded_p12 | boarded_p13 | boarded_p14 | boarded_p15 | boarded_p16 | boarded_p17 | boarded_p18 | boarded_p19))) & !(O(boarded_p11 & (boarded_p12 | boarded_p13 | boarded_p14 | boarded_p15 | boarded_p16 | boarded_p17 | boarded_p18 | boarded_p19 | boarded_p20))) & !(O(boarded_p12 & (boarded_p13 | boarded_p14 | boarded_p15 | boarded_p16 | boarded_p17 | boarded_p18 | boarded_p19 | boarded_p20 | boarded_p21))) & !(O(boarded_p13 & (boarded_p14 | boarded_p15 | boarded_p16 | boarded_p17 | boarded_p18 | boarded_p19 | boarded_p20 | boarded_p21 | boarded_p22))) & !(O(boarded_p14 & (boarded_p15 | boarded_p16 | boarded_p17 | boarded_p18 | boarded_p19 | boarded_p20 | boarded_p21 | boarded_p22 | boarded_p23))) & !(O(boarded_p15 & (boarded_p16 | boarded_p17 | boarded_p18 | boarded_p19 | boarded_p20 | boarded_p21 | boarded_p22 | boarded_p23 | boarded_p24))) & !(O(boarded_p16 & (boarded_p17 | boarded_p18 | boarded_p19 | boarded_p20 | boarded_p21 | boarded_p22 | boarded_p23 | boarded_p24 | boarded_p25))) & !(O(boarded_p17 & (boarded_p18 | boarded_p19 | boarded_p20 | boarded_p21 | boarded_p22 | boarded_p23 | boarded_p24 | boarded_p25 | boarded_p26))) & !(O(boarded_p18 & (boarded_p19 | boarded_p20 | boarded_p21 | boarded_p22 | boarded_p23 | boarded_p24 | boarded_p25 | boarded_p26 | boarded_p27))) & !(O(boarded_p19 & (boarded_p20 | boarded_p21 | boarded_p22 | boarded_p23 | boarded_p24 | boarded_p25 | boarded_p26 | boarded_p27 | boarded_p0))) & !(O(boarded_p20 & (boarded_p21 | boarded_p22 | boarded_p23 | boarded_p24 | boarded_p25 | boarded_p26 | boarded_p27 | boarded_p0 | boarded_p1))) & !(O(boarded_p21 & (boarded_p22 | boarded_p23 | boarded_p24 | boarded_p25 | boarded_p26 | boarded_p27 | boarded_p0 | boarded_p1 | boarded_p2))) & !(O(boarded_p22 & (boarded_p23 | boarded_p24 | boarded_p25 | boarded_p26 | boarded_p27 | boarded_p0 | boarded_p1 | boarded_p2 | boarded_p3))) & !(O(boarded_p23 & (boarded_p24 | boarded_p25 | boarded_p26 | boarded_p27 | boarded_p0 | boarded_p1 | boarded_p2 | boarded_p3 | boarded_p4))) & !(O(boarded_p24 & (boarded_p25 | boarded_p26 | boarded_p27 | boarded_p0 | boarded_p1 | boarded_p2 | boarded_p3 | boarded_p4 | boarded_p5))) & !(O(boarded_p25 & (boarded_p26 | boarded_p27 | boarded_p0 | boarded_p1 | boarded_p2 | boarded_p3 | boarded_p4 | boarded_p5 | boarded_p6))) & !(O(boarded_p26 & (boarded_p27 | boarded_p0 | boarded_p1 | boarded_p2 | boarded_p3 | boarded_p4 | boarded_p5 | boarded_p6 | boarded_p7))) & !(O(boarded_p27 & (boarded_p0 | boarded_p1 | boarded_p2 | boarded_p3 | boarded_p4 | boarded_p5 | boarded_p6 | boarded_p7 | boarded_p8)))",
"s29-0": "O(served_p14 & served_p15 & served_p16 & served_p17 & served_p18 & served_p19 & served_p20 & served_p21 & served_p22 & served_p23 & served_p24 & served_p25 & served_p26 & served_p27 & served_p28) & O(served_p0 & served_p1 & served_p2 & served_p3 & served_p4 & served_p5 & served_p6 & served_p7 & served_p8 & served_p9 & served_p10 & served_p11 & served_p12 & served_p13 & !(Y(O(served_p14 | served_p15 | served_p16 | served_p17 | served_p18 | served_p19 | served_p20 | served_p21 | served_p22 | served_p23 | served_p24 | served_p25 | served_p26 | served_p27 | served_p28)))) & !(O(boarded_p0 & (boarded_p1 | boarded_p2 | boarded_p3 | boarded_p4 | boarded_p5 | boarded_p6 | boarded_p7 | boarded_p8 | boarded_p9))) & !(O(boarded_p1 & (boarded_p2 | boarded_p3 | boarded_p4 | boarded_p5 | boarded_p6 | boarded_p7 | boarded_p8 | boarded_p9 | boarded_p10))) & !(O(boarded_p2 & (boarded_p3 | boarded_p4 | boarded_p5 | boarded_p6 | boarded_p7 | boarded_p8 | boarded_p9 | boarded_p10 | boarded_p11))) & !(O(boarded_p3 & (boarded_p4 | boarded_p5 | boarded_p6 | boarded_p7 | boarded_p8 | boarded_p9 | boarded_p10 | boarded_p11 | boarded_p12))) & !(O(boarded_p4 & (boarded_p5 | boarded_p6 | boarded_p7 | boarded_p8 | boarded_p9 | boarded_p10 | boarded_p11 | boarded_p12 | boarded_p13))) & !(O(boarded_p5 & (boarded_p6 | boarded_p7 | boarded_p8 | boarded_p9 | boarded_p10 | boarded_p11 | boarded_p12 | boarded_p13 | boarded_p14))) & !(O(boarded_p6 & (boarded_p7 | boarded_p8 | boarded_p9 | boarded_p10 | boarded_p11 | boarded_p12 | boarded_p13 | boarded_p14 | boarded_p15))) & !(O(boarded_p7 & (boarded_p8 | boarded_p9 | boarded_p10 | boarded_p11 | boarded_p12 | boarded_p13 | boarded_p14 | boarded_p15 | boarded_p16))) & !(O(boarded_p8 & (boarded_p9 | boarded_p10 | boarded_p11 | boarded_p12 | boarded_p13 | boarded_p14 | boarded_p15 | boarded_p16 | boarded_p17))) & !(O(boarded_p9 & (boarded_p10 | boarded_p11 | boarded_p12 | boarded_p13 | boarded_p14 | boarded_p15 | boarded_p16 | boarded_p17 | boarded_p18))) & !(O(boarded_p10 & (boarded_p11 | boarded_p12 | boarded_p13 | boarded_p14 | boarded_p15 | boarded_p16 | boarded_p17 | boarded_p18 | boarded_p19))) & !(O(boarded_p11 & (boarded_p12 | boarded_p13 | boarded_p14 | boarded_p15 | boarded_p16 | boarded_p17 | boarded_p18 | boarded_p19 | boarded_p20))) & !(O(boarded_p12 & (boarded_p13 | boarded_p14 | boarded_p15 | boarded_p16 | boarded_p17 | boarded_p18 | boarded_p19 | boarded_p20 | boarded_p21))) & !(O(boarded_p13 & (boarded_p14 | boarded_p15 | boarded_p16 | boarded_p17 | boarded_p18 | boarded_p19 | boarded_p20 | boarded_p21 | boarded_p22))) & !(O(boarded_p14 & (boarded_p15 | boarded_p16 | boarded_p17 | boarded_p18 | boarded_p19 | boarded_p20 | boarded_p21 | boarded_p22 | boarded_p23))) & !(O(boarded_p15 & (boarded_p16 | boarded_p17 | boarded_p18 | boarded_p19 | boarded_p20 | boarded_p21 | boarded_p22 | boarded_p23 | boarded_p24))) & !(O(boarded_p16 & (boarded_p17 | boarded_p18 | boarded_p19 | boarded_p20 | boarded_p21 | boarded_p22 | boarded_p23 | boarded_p24 | boarded_p25))) & !(O(boarded_p17 & (boarded_p18 | boarded_p19 | boarded_p20 | boarded_p21 | boarded_p22 | boarded_p23 | boarded_p24 | boarded_p25 | boarded_p26))) & !(O(boarded_p18 & (boarded_p19 | boarded_p20 | boarded_p21 | boarded_p22 | boarded_p23 | boarded_p24 | boarded_p25 | boarded_p26 | boarded_p27))) & !(O(boarded_p19 & (boarded_p20 | boarded_p21 | boarded_p22 | boarded_p23 | boarded_p24 | boarded_p25 | boarded_p26 | boarded_p27 | boarded_p28))) & !(O(boarded_p20 & (boarded_p21 | boarded_p22 | boarded_p23 | boarded_p24 | boarded_p25 | boarded_p26 | boarded_p27 | boarded_p28 | boarded_p0))) & !(O(boarded_p21 & (boarded_p22 | boarded_p23 | boarded_p24 | boarded_p25 | boarded_p26 | boarded_p27 | boarded_p28 | boarded_p0 | boarded_p1))) & !(O(boarded_p22 & (boarded_p23 | boarded_p24 | boarded_p25 | boarded_p26 | boarded_p27 | boarded_p28 | boarded_p0 | boarded_p1 | boarded_p2))) & !(O(boarded_p23 & (boarded_p24 | boarded_p25 | boarded_p26 | boarded_p27 | boarded_p28 | boarded_p0 | boarded_p1 | boarded_p2 | boarded_p3))) & !(O(boarded_p24 & (boarded_p25 | boarded_p26 | boarded_p27 | boarded_p28 | boarded_p0 | boarded_p1 | boarded_p2 | boarded_p3 | boarded_p4))) & !(O(boarded_p25 & (boarded_p26 | boarded_p27 | boarded_p28 | boarded_p0 | boarded_p1 | boarded_p2 | boarded_p3 | boarded_p4 | boarded_p5))) & !(O(boarded_p26 & (boarded_p27 | boarded_p28 | boarded_p0 | boarded_p1 | boarded_p2 | boarded_p3 | boarded_p4 | boarded_p5 | boarded_p6))) & !(O(boarded_p27 & (boarded_p28 | boarded_p0 | boarded_p1 | boarded_p2 | boarded_p3 | boarded_p4 | boarded_p5 | boarded_p6 | boarded_p7))) & !(O(boarded_p28 & (boarded_p0 | boarded_p1 | boarded_p2 | boarded_p3 | boarded_p4 | boarded_p5 | boarded_p6 | boarded_p7 | boarded_p8)))",
"s30-0": "O(served_p15 & served_p16 & served_p17 & served_p18 & served_p19 & served_p20 & served_p21 & served_p22 & served_p23 & served_p24 & served_p25 & served_p26 & served_p27 & served_p28 & served_p29) & O(served_p0 & served_p1 & served_p2 & served_p3 & served_p4 & served_p5 & served_p6 & served_p7 & served_p8 & served_p9 & served_p10 & served_p11 & served_p12 & served_p13 & served_p14 & !(Y(O(served_p15 | served_p16 | served_p17 | served_p18 | served_p19 | served_p20 | served_p21 | served_p22 | served_p23 | served_p24 | served_p25 | served_p26 | served_p27 | served_p28 | served_p29)))) & !(O(boarded_p0 & (boarded_p1 | boarded_p2 | boarded_p3 | boarded_p4 | boarded_p5 | boarded_p6 | boarded_p7 | boarded_p8 | boarded_p9 | boarded_p10))) & !(O(boarded_p1 & (boarded_p2 | boarded_p3 | boarded_p4 | boarded_p5 | boarded_p6 | boarded_p7 | boarded_p8 | boarded_p9 | boarded_p10 | boarded_p11))) & !(O(boarded_p2 & (boarded_p3 | boarded_p4 | boarded_p5 | boarded_p6 | boarded_p7 | boarded_p8 | boarded_p9 | boarded_p10 | boarded_p11 | boarded_p12))) & !(O(boarded_p3 & (boarded_p4 | boarded_p5 | boarded_p6 | boarded_p7 | boarded_p8 | boarded_p9 | boarded_p10 | boarded_p11 | boarded_p12 | boarded_p13))) & !(O(boarded_p4 & (boarded_p5 | boarded_p6 | boarded_p7 | boarded_p8 | boarded_p9 | boarded_p10 | boarded_p11 | boarded_p12 | boarded_p13 | boarded_p14))) & !(O(boarded_p5 & (boarded_p6 | boarded_p7 | boarded_p8 | boarded_p9 | boarded_p10 | boarded_p11 | boarded_p12 | boarded_p13 | boarded_p14 | boarded_p15))) & !(O(boarded_p6 & (boarded_p7 | boarded_p8 | boarded_p9 | boarded_p10 | boarded_p11 | boarded_p12 | boarded_p13 | boarded_p14 | boarded_p15 | boarded_p16))) & !(O(boarded_p7 & (boarded_p8 | boarded_p9 | boarded_p10 | boarded_p11 | boarded_p12 | boarded_p13 | boarded_p14 | boarded_p15 | boarded_p16 | boarded_p17))) & !(O(boarded_p8 & (boarded_p9 | boarded_p10 | boarded_p11 | boarded_p12 | boarded_p13 | boarded_p14 | boarded_p15 | boarded_p16 | boarded_p17 | boarded_p18))) & !(O(boarded_p9 & (boarded_p10 | boarded_p11 | boarded_p12 | boarded_p13 | boarded_p14 | boarded_p15 | boarded_p16 | boarded_p17 | boarded_p18 | boarded_p19))) & !(O(boarded_p10 & (boarded_p11 | boarded_p12 | boarded_p13 | boarded_p14 | boarded_p15 | boarded_p16 | boarded_p17 | boarded_p18 | boarded_p19 | boarded_p20))) & !(O(boarded_p11 & (boarded_p12 | boarded_p13 | boarded_p14 | boarded_p15 | boarded_p16 | boarded_p17 | boarded_p18 | boarded_p19 | boarded_p20 | boarded_p21))) & !(O(boarded_p12 & (boarded_p13 | boarded_p14 | boarded_p15 | boarded_p16 | boarded_p17 | boarded_p18 | boarded_p19 | boarded_p20 | boarded_p21 | boarded_p22))) & !(O(boarded_p13 & (boarded_p14 | boarded_p15 | boarded_p16 | boarded_p17 | boarded_p18 | boarded_p19 | boarded_p20 | boarded_p21 | boarded_p22 | boarded_p23))) & !(O(boarded_p14 & (boarded_p15 | boarded_p16 | boarded_p17 | boarded_p18 | boarded_p19 | boarded_p20 | boarded_p21 | boarded_p22 | boarded_p23 | boarded_p24))) & !(O(boarded_p15 & (boarded_p16 | boarded_p17 | boarded_p18 | boarded_p19 | boarded_p20 | boarded_p21 | boarded_p22 | boarded_p23 | boarded_p24 | boarded_p25))) & !(O(boarded_p16 & (boarded_p17 | boarded_p18 | boarded_p19 | boarded_p20 | boarded_p21 | boarded_p22 | boarded_p23 | boarded_p24 | boarded_p25 | boarded_p26))) & !(O(boarded_p17 & (boarded_p18 | boarded_p19 | boarded_p20 | boarded_p21 | boarded_p22 | boarded_p23 | boarded_p24 | boarded_p25 | boarded_p26 | boarded_p27))) & !(O(boarded_p18 & (boarded_p19 | boarded_p20 | boarded_p21 | boarded_p22 | boarded_p23 | boarded_p24 | boarded_p25 | boarded_p26 | boarded_p27 | boarded_p28))) & !(O(boarded_p19 & (boarded_p20 | boarded_p21 | boarded_p22 | boarded_p23 | boarded_p24 | boarded_p25 | boarded_p26 | boarded_p27 | boarded_p28 | boarded_p29))) & !(O(boarded_p20 & (boarded_p21 | boarded_p22 | boarded_p23 | boarded_p24 | boarded_p25 | boarded_p26 | boarded_p27 | boarded_p28 | boarded_p29 | boarded_p0))) & !(O(boarded_p21 & (boarded_p22 | boarded_p23 | boarded_p24 | boarded_p25 | boarded_p26 | boarded_p27 | boarded_p28 | boarded_p29 | boarded_p0 | boarded_p1))) & !(O(boarded_p22 & (boarded_p23 | boarded_p24 | boarded_p25 | boarded_p26 | boarded_p27 | boarded_p28 | boarded_p29 | boarded_p0 | boarded_p1 | boarded_p2))) & !(O(boarded_p23 & (boarded_p24 | boarded_p25 | boarded_p26 | boarded_p27 | boarded_p28 | boarded_p29 | boarded_p0 | boarded_p1 | boarded_p2 | boarded_p3))) & !(O(boarded_p24 & (boarded_p25 | boarded_p26 | boarded_p27 | boarded_p28 | boarded_p29 | boarded_p0 | boarded_p1 | boarded_p2 | boarded_p3 | boarded_p4))) & !(O(boarded_p25 & (boarded_p26 | boarded_p27 | boarded_p28 | boarded_p29 | boarded_p0 | boarded_p1 | boarded_p2 | boarded_p3 | boarded_p4 | boarded_p5))) & !(O(boarded_p26 & (boarded_p27 | boarded_p28 | boarded_p29 | boarded_p0 | boarded_p1 | boarded_p2 | boarded_p3 | boarded_p4 | boarded_p5 | boarded_p6))) & !(O(boarded_p27 & (boarded_p28 | boarded_p29 | boarded_p0 | boarded_p1 | boarded_p2 | boarded_p3 | boarded_p4 | boarded_p5 | boarded_p6 | boarded_p7))) & !(O(boarded_p28 & (boarded_p29 | boarded_p0 | boarded_p1 | boarded_p2 | boarded_p3 | boarded_p4 | boarded_p5 | boarded_p6 | boarded_p7 | boarded_p8))) & !(O(boarded_p29 & (boarded_p0 | boarded_p1 | boarded_p2 | boarded_p3 | boarded_p4 | boarded_p5 | boarded_p6 | boarded_p7 | boarded_p8 | boarded_p9)))"
"s2-0": "O(\"served p1\") & O(\"served p0\" & !(Y(O(\"served p1\"))))",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now formulas look like this...

in JSON we cannot use ' to wrap strings; therefore, escaping " is the only way to specify the temporal goal.

@marcofavorito
Copy link
Member Author

marcofavorito commented Jul 9, 2023

Alternative considered: add parenthesis: "(p a b)"

Pros: more adherence to PDDL format;
Cons: parenthesis might add too much cognitive overload, considering that they can occur also in the formula

@marcofavorito marcofavorito force-pushed the no-mappings branch 2 times, most recently from bac485a to 0d19b23 Compare July 9, 2023 20:27
@codecov
Copy link

codecov bot commented Jul 9, 2023

Codecov Report

Merging #262 (838f43c) into main (dd7b158) will decrease coverage by 0.96%.
The diff coverage is 94.20%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #262      +/-   ##
==========================================
- Coverage   89.79%   88.84%   -0.96%     
==========================================
  Files          12       11       -1     
  Lines         549      484      -65     
==========================================
- Hits          493      430      -63     
+ Misses         56       54       -2     
Flag Coverage Δ
unittests 88.84% <94.20%> (-0.96%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
plan4past/__main__.py 0.00% <0.00%> (ø)
plan4past/helpers/utils.py 97.77% <97.22%> (-2.23%) ⬇️
plan4past/compiler.py 98.18% <100.00%> (-0.24%) ⬇️
plan4past/utils/derived_visitor.py 100.00% <100.00%> (ø)
plan4past/utils/predicates_visitor.py 100.00% <100.00%> (ø)
plan4past/utils/rewrite_formula_visitor.py 100.00% <100.00%> (ø)
plan4past/utils/val_predicates_visitor.py 100.00% <100.00%> (ø)

@marcofavorito
Copy link
Member Author

Consider the formula:

(a S (b & O(c))) 
| 
((a S b) & O(c))

We get the following derived predicates:

(:derived (val__Oc) (or (val__c) (Y-Oc)))
(:derived (val__Oc) (or (val__c) (Y-Oc)))
(:derived (val__a) (a))
(:derived (val__a) (a))
(:derived (val__a-S-b) (or (val__b) (and (val__a) (Y-a-S-b))))
(:derived (val__a-S-b-and-Oc) (and (val__a-S-b) (val__Oc)))
(:derived (val__a-S-b-and-Oc) (or (val__b-and-Oc) (and (val__a) (Y-a-S-b-and-Oc))))
(:derived (val__a-S-b-and-Oc-or-a-S-b-and-Oc) (val__a-S-b-and-Oc))
(:derived (val__b) (b))
(:derived (val__b) (b))
(:derived (val__b-and-Oc) (and (val__b) (val__Oc)))
(:derived (val__c) (c))
(:derived (val__c) (c))

The derived predicate val__a-S-b-and-Oc occurs twice with a different condition on the right. This is because we do not distinguish between open and close parenthesis. This has to be addressed.

Idea: replace ( with LPAR__ and ) with __RPAR. The result would be:

(:derived (val__LPAR__LPAR__a__RPAR-S-LPAR__LPAR__b__RPAR-and-LPAR__OLPAR__c__RPAR__RPAR__RPAR__RPAR-or-LPAR__LPAR__LPAR__a__RPAR-S-LPAR__b__RPAR__RPAR-and-LPAR__OLPAR__c__RPAR__RPAR__RPAR) (or (val__LPAR__a__RPAR-S-LPAR__LPAR__b__RPAR-and-LPAR__OLPAR__c__RPAR__RPAR__RPAR) (val__LPAR__LPAR__a__RPAR-S-LPAR__b__RPAR__RPAR-and-LPAR__OLPAR__c__RPAR__RPAR)))
(:derived (val__LPAR__LPAR__a__RPAR-S-LPAR__b__RPAR__RPAR-and-LPAR__OLPAR__c__RPAR__RPAR) (and (val__LPAR__a__RPAR-S-LPAR__b__RPAR) (val__OLPAR__c__RPAR)))
(:derived (val__LPAR__a__RPAR-S-LPAR__LPAR__b__RPAR-and-LPAR__OLPAR__c__RPAR__RPAR__RPAR) (or (val__LPAR__b__RPAR-and-LPAR__OLPAR__c__RPAR__RPAR) (and (val__a) (Y-LPAR__a__RPAR-S-LPAR__LPAR__b__RPAR-and-LPAR__OLPAR__c__RPAR__RPAR__RPAR))))
(:derived (val__LPAR__a__RPAR-S-LPAR__b__RPAR) (or (val__b) (and (val__a) (Y-LPAR__a__RPAR-S-LPAR__b__RPAR))))
(:derived (val__LPAR__b__RPAR-and-LPAR__OLPAR__c__RPAR__RPAR) (and (val__b) (val__OLPAR__c__RPAR)))
(:derived (val__OLPAR__c__RPAR) (or (val__c) (Y-OLPAR__c__RPAR)))
(:derived (val__OLPAR__c__RPAR) (or (val__c) (Y-OLPAR__c__RPAR)))
(:derived (val__a) (a))
(:derived (val__a) (a))
(:derived (val__b) (b))
(:derived (val__b) (b))
(:derived (val__c) (c))
(:derived (val__c) (c))

Which is quite verbose, but now the two conflicting derived predicates now have distinct names:

(:derived (val__LPAR__LPAR__a__RPAR-S-LPAR__b__RPAR__RPAR-and-LPAR__OLPAR__c__RPAR__RPAR) (and (val__LPAR__a__RPAR-S-LPAR__b__RPAR) (val__OLPAR__c__RPAR)))
(:derived (val__LPAR__a__RPAR-S-LPAR__LPAR__b__RPAR-and-LPAR__OLPAR__c__RPAR__RPAR__RPAR) (or (val__LPAR__b__RPAR-and-LPAR__OLPAR__c__RPAR__RPAR) (and (val__a) (Y-LPAR__a__RPAR-S-LPAR__LPAR__b__RPAR-and-LPAR__OLPAR__c__RPAR__RPAR__RPAR))))

Of course other alternatives than LPAR__ and __RPAR could be considered...

@marcofavorito marcofavorito changed the base branch from add-planner-tests to main July 10, 2023 10:08
After this commit, there is no need to provide an explicit mapping, since it is assumed that the propositions *are* the ground fluents.

E.g. if previously the formula was specified as follows:

formula = "on_b_a & O(ontable_c)"

Now we require that the propositions can be interpreted as PDDL predicates, i.e.:

formula = '"on b a" & O("ontable c")'

Pylogics does not allow spaces in the proposition name; therefore, the double quotes are always required.

Only exception is when the predicate is unary:

formula = 'Y(O(made-p4)))'

(as in openstacks).
We now check if the prefix 'val' is in the atom name. This is because after the compilation there might be conflicts in the val predicate names.

Consider the following example: '"p a b" & val-p-a-b'

The formula is compiled as follows:

"p a b" ->  'val-p-a-b'

(:derived (val-p-a-b)        (p a b))
	      ^                  ^
	      derived-predicate  condition (ground fluent, predicate name 'p', constants 'a' and 'b')

"val-p-a-b" -> 'val-val-p-a-b'

(:derived (val-val-p-a-b)     (val-p-a-b))
	      ^                   ^
	      derived-predicate   condition (ground fluent, predicate name 'p-a-b', no constants

The prefix is changed to `val__` to make the prefix less probable to occur in an atom name.
@marcofavorito
Copy link
Member Author

An even simpler formula is: O(a) & "Oa", which generates:

(:derived (val__Oa) (Oa))
(:derived (val__Oa) (or (val__a) (Y-Oa)))
(:derived (val__Oa-and-Oa) (val__Oa))
(:derived (val__a) (a))

Again, val__Oa is ambiguous: it both resolves to the predicate name Oa, or to the "once a" rule.

@marcofavorito
Copy link
Member Author

marcofavorito commented Jul 10, 2023

Copying from c891195:

with this change, we translate each formula special symbols (operator symbols, parenthesis etc.) into a sequence of characters that can be part of a valid derived predicate name.

This means that, given a name of a derived predicate, one can simply do the inverse replacement and recover the original formula.

This approach has two major drawbacks:

  1. the output of the compiler is much more verbose; e.g. the formula 'Y(a)' gets translated into 'val__YLPAR__a__RPAR'
  2. the new approach imposes restrictions on the allowed symbols in a PPLTL formula. E.g. symbols that start with VAL__ or Y__, or symbols that contain one of the following as substring:
  • LPAR__ (left parenthesis)
  • __RPAR (right parenthesis)
  • NOT__ (not symbol)
  • __AND__ (and symbol)
  • __OR__ (or symbol)
  • __QUOTE__ (quote)
    are forbidden.

This policy might be more conservative than needed, but in this way we should have the guarantee that the encoding is an invertible mapping (such property basically proves non-ambiguity of the encoding, because it means there is a one-to-one relationship between 'string representation of pylogics formulas' and 'string representation encoded as PDDL predicate name').

@marcofavorito marcofavorito changed the title Remove mapping; proposition names *are* PDDL ground fluents Remove mapping, proposition names *are* PDDL ground fluents. Fix ambiguity in DP names Jul 10, 2023
with this change, we translate each formula special symbols (operator symbols, parenthesis etc.) into a sequence of characters that can be part of a valid derived predicate name.

This means that, given a name of a derived predicate, one can simply do the inverse replacement and recover the original formula.

This approach has two major drawbacks:
1) the output of the compiler is much more verbose; e.g. the formula 'Y(a)' gets translated into 'val__YLPAR__a__RPAR'
2) the new approach imposes restrictions on the allowed symbols in a PPLTL formula. E.g. symbols that start with 'VAL__' or 'Y__', or symbols that contain one of the following as substring:
  - "LPAR__" (left parenthesis)
  - "__RPAR" (right parenthesis)
  - "NOT__" (not symbol)
  - "__AND__" (and symbol)
  - "__OR__" (or symbol)
  - "__QUOTE__" (quote)
  are forbidden.

This policy might be more conservative than needed, but in this way we should have the guarantee that the encoding is an invertible mapping (such property basically proves non-ambiguity of the encoding, because it means there is a one-to-one relationship between 'string representation of pylogics formulas' and 'string representation encoded as PDDL predicate name').
@LBonassi95
Copy link
Collaborator

Regarding the collision between "Val" (and "Y") PDDL predicates corresponding to different PPLTL subformulas, I think it is a good idea to use unique identifiers for these atoms.
I propose the following pattern val_id-[PPLTL operator | Atom]_{Ids of Arguments}
Example: for O(O(a)) we generate:
[
val_p0-a
val_p1-Once_p0
val_p2-Once_p1
]

Other examples:
(a S (b & O(c)))
[
val_p3-Since_p5_p2,
val_p2-And_p1_p0,
val_p0-O_p4,
val_p4_c,
val_p5_a,
val_p1_b
]

((a S b) & O(c))
[
val_p3-And_p2_p0,
val_p2-Since_p5_p1,
val_p0-Once_p4,
val_p4_c,
val_p5_a,
val_p1_b
]
Let me know what you think about this approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants