aiplan4eu / unified-planning

The AIPlan4EU Unified Planning Library
Apache License 2.0
181 stars 39 forks source link

How to use the forall argument in add_effect()? #602

Closed GiugAles closed 4 months ago

GiugAles commented 4 months ago

Hey everyone,

First of all a big thank you! This project has helped me a lot on getting started on the topic.

Secondly, I am not sure if this is the correct place to ask the question, but I have found no other address. Sorry if this is not the place to ask.

I dug through the documentation, the examples and the code, but I was not able to find out how to use forall with add_effect as done in this PDDL example:


(:action
 stop
 :parameters (?f - floor)
 :precondition (and (lift-at ?f)
      ;; omitted
 :effect (and 
      (forall (?p - passenger) 
                  (when (and (boarded ?p) 
                             (destin ?p ?f))
                        (and (not (boarded ?p)) 
                             (served  ?p))))
      (forall (?p - passenger)                
          (when (and (origin ?p ?f) (not (served ?p)))
            (boarded ?p)))))

Obtained from here

The PDDL reader of this project seems to able to transform it correctly into the model.

Any pointer or examples are much appreciated

Cheers, Alessandro

GiugAles commented 4 months ago

Figured it out in the meantime. It is actually quite easy:

passenger = UserType("passenger")
stop = InstantaneousAction("stop", f=floor)
p = Variable("p", passenger) # create a "loop" variable
stop.add_effect(
    # fluent omitted
    # value omitted
    forall=(p,), # make the variable a tuple
    condition=And(
        And(boarded(p), destin(p)),
        And(Not(boarded(p), serverd(p))
    )
)

Second forall can be added with an additional add_effect

GiugAles commented 4 months ago

Closing