Search code examples
forallplanningpddl

Forall statement applied for a subset of elements in PDDL Domain?


Case of use

First of all, I want to explain my case of use: I want to divide a field in different sectors and all plants should be analyzed by robots (just one robot per sector). I want to check in :preconditions that all plants for one sector are already analyzed, so that the robot return to the 'home'.

Problem

Here is the domain PDDL. My problem is placed in the preconditions of "tracker-back-home" action. Now I am checking if all the plants have been already analyzed, but I need to know if all the plants of the specific sector ?s are analyzed. It is possible to do using forall statement?

(define (domain killbee)
(:requirements :strips :typing)
(:types 
  bee location - object
  ;Inheritance
  tracker - bee
  hive plant sector - location
)
(:predicates 
  (directly-connected ?l1 - location ?l2 - location)
  (at ?l1 - object ?l2 - object) ;location is hive, plant or sector
  (free-sector ?s - sector)
  (bee-with-sector ?b - tracker)
  (tracker-ready-to-move ?b - tracker)
  (analyzed-plant ?p - plant ?s - sector)
  (sector-tracked ?s - sector)
  (plant-in-sector ?p - plant ?s - sector)
)
...
...
(:action tracker-back-home
:parameters (?b - tracker ?p - plant ?h - hive ?s - sector)
:precondition 
  (and (tracker-ready-to-move ?b)
  (at ?b ?p)
  (not (at ?b ?h))
  (forall (?x - plant) (analyzed-plant ?x ?s)))
  )
:effect 
  (and 
  (not (at ?b ?p))
  (at ?b ?h)
  (sector-tracked ?s)
  (not (bee-with-sector ?b))
  (free-sector ?s))
)...

Solution

  • Did you check out the language feature "imply" as defined by PDDL 2.1? (Maybe it was already defined before 2.1 -- not sure.) With it, you can define:

    (forall (?pPrime - plant)
      (imply (at ?s ?pPrime) (analyzed-plant ?pPrime ?s))
    )
    

    Note: I am not sure whether the order of parameters in (at ?s ?pPrime) is correct. It's supposed to encode that the plant ?pPrime is in sector ?s.

    The condition expands to a large set of implications reading that for all plants p' (no matter where they are) holds: "if plant p' is in s, then it's analyzed in s". This should encode exactly what you are looking for.