PDDL – 山羊、狼和白菜

我被要求为著名的“山羊、狼和白菜”场景编写解决方案。场景如下:

农夫想要将这三者都运过河。然而,如果:

  • 山羊和白菜被单独留下,山羊会吃掉白菜
  • 如果狼和山羊被单独留下,狼会吃掉山羊!

因此,解决这个问题的一种方法如下:

  • 将山羊运过河,并在对岸放下
  • 返回河对岸
  • 拿起白菜或狼中的一个,带到对岸
  • 放下狼,捡起山羊,返回另一边
  • 放下山羊,捡起白菜,返回另一边
  • 捡起山羊,瞧!三者都成功运输了。

然而,我在将其投射到PDDL上遇到了一些困难。我被给出了问题定义:

(define (problem boat1)(:domain boat); only needs two objects, namely representing; either banke side of the river, [w]est and [e]ast(:objects  w e)(:INIT     ; wolf, goat, cabbage, boat are all on     ; the west side to start with    (config w w w w)    ; represent all valid states    ; these two are the special case,    ; representing that wolf and cabbage are    ; safe together even if the boat is away    (valid w e w e)    (valid e w e w)    ; these are all cases where two entities    ; are always safe as long as the boat is     ; with them. In other words, a single entity    ; on the other side is also always safe    ; for west side    (valid w w w w)    (valid w w e w)    (valid w e w w)    (valid e w w w)    ; for east side    (valid e e e e)    (valid e e w e)    (valid e w e e)    (valid w e e e)    ; these are all valid states that are    ; ever allowed)(:goal (AND         ; they all have to move to the east side        (config e e e e)    ))

最后,我们只被给出了一个谓词,并被告知可以用四个动作完成。Move_empty, move_goat, move_wolf, move_cabbage.

谓词是:

(config ?wolf ?goat ?cabbage ?boat)(valid ?wolf ?goat ?cabbage ?boat)

我尝试从move_empty开始:

    (:action move_empty     :parameters (?from ?to)     :precondition (and (valid ?x ?y ?z ?w) (on_left ?from) (on_right ?to))                           :effect (and (valid ?x ?y ?z ?w)))

我并不希望得到答案,只希望得到关于如何解决这个问题的帮助和建议,因为根据我所能找到的,关于PDDL的信息并不多。


回答:

注意: 我不知道pddl语言,这是我通过查看您的代码所取得的成果。


主要思路

在您的问题中,每个实体都被描述为在河的西岸或岸,并且实体通过在谓词configvalid中的相对位置来识别。

每个动作都从一个给定的配置开始,并且必须结束于另一个配置。此外,我们必须要求结束配置有效的。

因此,从岸到西岸的move_empty动作非常简单,如下所示:

  (:action move_empty_ew :parameters (?x ?y ?z)   :precondition (and (config ?x ?y ?z e) (valid ?x ?y ?z w))   :effect (and (not (config ?x ?y ?z e)) (config ?x ?y ?z w))  )

在这里,我们让其他所有实体的位置(狼、山羊和白菜)保持不确定,同时我们要求最初岸,并且让前往西岸而留下动物无人看管是有效的移动。如果所有这些条件都满足,那么我们就移动到所需的配置。


解决方案

请注意,我对动作的名称进行了改进,使它们更能反映实际执行的动作。

boat-domain.pddl

(define (domain boat)  (:requirements :equality)  (:predicates    (config ?wolf ?goat ?cabbage ?boat)    (valid ?wolf ?goat ?cabbage ?boat)  )  (:action move_empty_ew :parameters (?x ?y ?z)   :precondition (and (config ?x ?y ?z e) (valid ?x ?y ?z w))   :effect (and (not (config ?x ?y ?z e)) (config ?x ?y ?z w))  )  (:action move_empty_we :parameters (?x ?y ?z)   :precondition (and (config ?x ?y ?z w) (valid ?x ?y ?z e))   :effect (and (not (config ?x ?y ?z w)) (config ?x ?y ?z e))  )  (:action move_wolf_ew :parameters (?y ?z)   :precondition (and (config e ?y ?z e) (valid w ?y ?z w))   :effect (and (not (config e ?y ?z e)) (config w ?y ?z w))  )  (:action move_wolf_we :parameters (?y ?z)   :precondition (and (config w ?y ?z w) (valid e ?y ?z e))   :effect (and (not (config w ?y ?z w)) (config e ?y ?z e))  )  (:action move_goat_ew :parameters (?x ?z)   :precondition (and (config ?x e ?z e) (valid ?x w ?z w))   :effect (and (not (config ?x e ?z e)) (config ?x w ?z w))  )  (:action move_goat_we :parameters (?x ?z)   :precondition (and (config ?x w ?z w) (valid ?x e ?z e))   :effect (and (not (config ?x w ?z w)) (config ?x e ?z e))  )  (:action move_cabbage_ew :parameters (?x ?y)   :precondition (and (config ?x ?y e e) (valid ?x ?y w w))   :effect (and (not (config ?x ?y e e)) (config ?x ?y w w))  )  (:action move_cabbage_we :parameters (?x ?y)   :precondition (and (config ?x ?y w w) (valid ?x ?y e e))   :effect (and (not (config ?x ?y w w)) (config ?x ?y e e))  ))

boat-prob.pddl

(define (problem boat)  (:domain boat)  (:objects w e)  (:INIT (config w w w w)    (valid w e w e) (valid e w e w)    (valid w w w w) (valid w w e w)    (valid w e w w) (valid e w w w)    (valid e e e e) (valid e e w e)    (valid e w e e) (valid w e e e)  )  (:goal (config e e e e)))

我使用了fast-downward来寻找最短路径的解决方案:

~$ fast-downward.py --alias seq-opt-bjolp boat-domain.pddl boat-prob.pddl

实际的解决方案是:

move_goat_we w w (1)move_empty_ew w e w (1)move_cabbage_we w e (1)move_goat_ew w e (1)move_wolf_we w e (1)move_empty_ew e w e (1)move_goat_we e e (1)Plan length: 7 step(s).Plan cost: 7

Related Posts

使用LSTM在Python中预测未来值

这段代码可以预测指定股票的当前日期之前的值,但不能预测…

如何在gensim的word2vec模型中查找双词组的相似性

我有一个word2vec模型,假设我使用的是googl…

dask_xgboost.predict 可以工作但无法显示 – 数据必须是一维的

我试图使用 XGBoost 创建模型。 看起来我成功地…

ML Tuning – Cross Validation in Spark

我在https://spark.apache.org/…

如何在React JS中使用fetch从REST API获取预测

我正在开发一个应用程序,其中Flask REST AP…

如何分析ML.NET中多类分类预测得分数组?

我在ML.NET中创建了一个多类分类项目。该项目可以对…

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注