我们继续刚刚的话题,请用pddl实现积木世界中的move动作,现在已经实现moveToTable的动作,其中move动作中给出了两个初始参数?x ?y,你可能要用到forall和when,注意,不能增删变量,且不能额外添加函数
时间: 2023-12-14 12:05:57 浏览: 46
好的,假设我们有以下 PDDL 领域和问题描述:
```
(define (domain blocksworld)
(:requirements :strips :typing)
(:types block)
(:predicates
(on ?x - block ?y - block)
(ontable ?x - block)
(clear ?x - block)
(holding ?x - block))
(:action pickup
:parameters (?x - block)
:precondition (and (ontable ?x) (clear ?x))
:effect (and (holding ?x) (not (ontable ?x)) (not (clear ?x))))
(:action putdown
:parameters (?x - block)
:precondition (holding ?x)
:effect (and (ontable ?x) (clear ?x) (not (holding ?x))))
(:action moveToTable
:parameters (?x - block)
:precondition (and (clear ?x) (not (ontable ?x)))
:effect (and (ontable ?x) (not (clear ?x))))
(:action move
:parameters (?x - block ?y - block)
:precondition (and (clear ?x) (not (ontable ?x)) (clear ?y))
:effect (and (on ?x ?y) (clear ?x) (not (clear ?y)) (not (on ?x ?z))))
)
(define (problem blocks-4)
(:domain blocksworld)
(:objects a b c)
(:init
(ontable b)
(ontable c)
(clear a)
(clear b)
(clear c))
(:goal (and (on a b) (on b c) (ontable c))))
```
现在我们需要实现 `move` 动作。在 `move` 动作中,我们需要给出两个积木参数 `?x` 和 `?y`,将 `?x` 放到 `?y` 上面。
我们可以使用 `forall` 关键字来描述 “所有的积木 `?i` 都不在 `?y` 上面” 的条件,然后使用 `when` 关键字来实现 “当所有的积木 `?i` 都不在 `?y` 上面时,才可以执行 `move` 动作”。
具体来说,我们可以这样实现 `move` 动作:
```
(:action move
:parameters (?x - block ?y - block)
:precondition (and (clear ?x) (not (ontable ?x)) (clear ?y) (forall (?i - block) (not (on ?i ?y))))
:effect (and (on ?x ?y) (clear ?x) (not (clear ?y)) (forall (?i - block) (when (on ?i ?x) (not (on ?i ?y)))) (not (on ?x ?z))))
```
其中,`(forall (?i - block) (not (on ?i ?y)))` 表示所有的积木 `?i` 都不在 `?y` 上面,`(forall (?i - block) (when (on ?i ?x) (not (on ?i ?y))))` 表示所有在 `?x` 上面的积木 `?i` 都被移动到了 `?y` 上面。