0

我试图在节点网络中找到最短路径。从x1y1开始,到x9y9结束。从一个节点到另一个节点的每次移动都有一定的成本分配给它。目标是找到总成本最低的路径。问题描述 :init 部分包含有关连接哪些节点以及连接成本是多少的信息:



(:init
    (neighbor x1y1 x1y2)
    (neighbor x1y2 x1y3)
    (neighbor x1y1 x2y1)
    (neighbor x1y3 x9y9)
    (neighbor x2y1 x9y9)
    (on runner x1y1)
    (= (cost-total) 0)
    (= (cost-step x1y1 x1y2) 2)
    (= (cost-step x1y2 x1y3) 2)
    (= (cost-step x1y1 x2y1) 100)
    (= (cost-step x1y3 x9y9) 2)
    (= (cost-step x2y1 x9y9) 2)
)

如您所见,我将 x1y1 和 x2y1 之间的连接成本设置为 100,因此应该避免这种连接。但是规划器总是创建一个包含此连接的解决方案,而不是寻找总成本更低的路径。

规划器输出:
屏幕截图规划器输出

我是 PDDL 的新手,我不知道出了什么问题。因此,我在下面发布了所有代码:

领域:

;Header and description

(define (domain domain_name)

;remove requirements that are not needed
(:requirements :strips :typing :fluents :action-costs)
;(:requirements :strips :fluents :durative-actions :timed-initial-literals :typing :conditional-effects :negative-preconditions :duration-inequalities :equality)

(:types player field
)

; un-comment following line if constants are needed
;(:constants )

(:predicates
    (on ?player - player ?loc - field)
    (neighbor ?start - field ?end - field)
)


(:functions
    (cost-total)
    (cost-step ?from - field ?to - field)
)

(:action move
    :parameters (?player - player ?from - field ?to - field)
    :precondition (and 
        (on ?player ?from)
        (neighbor ?from ?to)
    )
    :effect (and 
        (on ?player ?to)
        (not (on ?player ?from))
        (increase (cost-total) (cost-step ?from ?to))
    )
)

)

问题:

(define (problem problem_name) (:domain domain_name)
(:objects x1y1 x1y2 x2y1 x1y3 x9y9 - field
          runner - player
)

(:init
    (neighbor x1y1 x1y2)
    (neighbor x1y2 x1y3)
    (neighbor x1y1 x2y1)
    (neighbor x1y3 x9y9)
    (neighbor x2y1 x9y9)
    (on runner x1y1)
    (= (cost-total) 0)
    (= (cost-step x1y1 x1y2) 2)
    (= (cost-step x1y2 x1y3) 2)
    (= (cost-step x1y1 x2y1) 100)
    (= (cost-step x1y3 x9y9) 2)
    (= (cost-step x2y1 x9y9) 2)
)

(:goal (and
    (on runner x9y9)
))

;un-comment the following line if metric is needed
(:metric minimize (cost-total))
)
4

2 回答 2

0

通过屏幕截图,您似乎正在使用 vscode 插件,因此很可能是在线求解器。这不是一个最佳求解器,因此无法保证它将使用或不使用哪些操作。

无论哪种方式,第一步是确认你有一个最佳的计划者正在运行。如果仍然存在问题,我们可以深入研究 PDDL。

于 2020-04-26T23:41:35.030 回答
-1

您的代码是正确的,您只需要使用特殊的求解器即可。我建议您使用 Optic-CPL 求解器,这里是下载链接或下载我使用的求解器。

下载已编译的二进制文件

这适用于 Ubuntu 12.10 到 20.04

要使用求解器,您需要以下命令:

$ ./optic-clp -n domain.pddl problem.pddl
于 2021-09-24T21:17:41.667 回答