[PDDL人工智能] 02.PDDL规划领域定义语言之语法理解和示例详解

智能规划来源于人工智能对理性行为研究,针对一个具体行为的实施目的,开展动作规划以模拟或指导行为的实施,是AI开展研究的关键问题。本文主要介绍PDDL规划领域定义语言的基础语法知识和示例详解,希望文章对您有所帮助。

该系列文章主要介绍PDDL人工智能知识,由于自己也是初学者,所以欢迎大家批评指正,一起加油喔~

前文赏析:


一.PDDL简介

PDDL:Planning Domain Definition Language
规划领域定义语言,是一种解决人工智能规划问题的比较前沿的方法。PDDL常用于解决智能规划问题,例如机器人将一个屋子的球搬运到另一间屋子里,通过合理的组织流程建造一间房子等。PDDL的规划任务(planning task)由五部分组成。

  • Objects(对象)
    Things in the world that interest us.
  • Predicates(谓词)
    Properties of objects that we are interested in; can be true or false.
  • Initial state(初始状态)
    The state of the world that we start in.
  • Goal specification(目标规范)
    Things that we want to be true.
  • Actions/Operators(操作/运算符)
    Ways of changing the state of the world.

定义规划任务的三要素:

  • 状态
  • 动作:动作是规划问题的一个关键部分
  • 目标

PDDL指定的规划任务分为两个文件,domain 文件和 problem 文件。

  1. A domain file(域文件) for predicates and actions.
  2. A problem file(问题文件) for objects, initial state and goal specification.

在这里插入图片描述

Domain Files
域文件定义如下:

在这里插入图片描述

(define (domain <domain name>)
	<PDDL code for predicates>
	<PDDL code for first action>
	[...]
	<PDDL code for last action>
)
  • <域名>:domain name,是标识规划域的字符串,例如gripper,后续gripper.pddl会详细介绍。

Problem Files
问题文件定义如下:

在这里插入图片描述

(define (problem <problem name>)
	(:domain <domain name>)
	<PDDL code for objects>
	<PDDL code for initial state>
	<PDDL code for goal specification>
)
  • <问题名称>:problem name,是一个标识计划任务的字符串,例如gripper-four-balls。
  • <域名>:domain name,必须与对应域名文件中的域名匹配,详见gripper-four.pddl文件。

推荐下列参考资料:


二.PDDL基础语法知识

四个球移动的任务(Gripper task with four balls):假设有一个机器人可以在两个房间之间移动,并用两条手臂中的任何一条捡起或扔掉球。 最初,所有球和机器人都在第一个房间,我们希望移动球到第二个房间中。

  • 对象: 两个房间、四个球和两个机械臂。
    Objects:The two rooms, four balls and two robot arms.
  • 谓词:x是一个房间? x是球? 球x在房间y内?机械臂x是空的吗?
    Predicates:Is x a room? Is x a ball? Is ball x inside room y? Is robot arm x empty? […]
  • 初始状态:所有球和机器人都在第一个房间, 所有机器人手臂都是空的。
    Initial state:All balls and the robot are in the first room. All robot arms are empty. […]
  • 目标说明:所有球必须在第二个房间。
    Goal specification:All balls must be in the second room.
  • 动作/操作:机器人可以在房间之间移动、捡球或丢球。
    Actions/Operators:The robot can move between rooms, pick up a ball or drop a ball.

接下来简单给出基本定义,由于其英语直译非常明确,这里仅给出描述,下一篇文章再进行详细的语法介绍。

Gripper task: Objects

在这里插入图片描述

Gripper task: Predicates

在这里插入图片描述

Gripper task: Initial state

  • 初始状态四个球都在房间rooma中

在这里插入图片描述

Gripper task: Goal specification

  • 目标:将四个球移动到roomb中

在这里插入图片描述

Gripper task: Movement operator

  • 移动操作:机器人从x移动到y

在这里插入图片描述

Gripper task: Pick-up operator

  • pick-up操作:机器人使用z从y中捡起x

在这里插入图片描述

Gripper task: Drop operator

  • drop操作:机器人使用z从y中丢掉x

在这里插入图片描述

A Note on Action Effects

在这里插入图片描述


三.入门示例详解

1.domain.pddl

规划域描述整个规划世界的基础构成信息,包括实体类型、实体实例化、谓词逻辑状态、实体状态等。

  • 定义:谓词和动作

示例代码如下:

(define (domain gripper-strips)
    (:requirements :negative-preconditions)
    (:predicates (room ?r)
                (ball ?b)
                (at ?b ?r)
                (at-robby ?r)
                (gripper ?g)
                (free ?g)
                (carry ?b ?g))
    (:action pick
        :parameters(?obj ?room ?gripper)
        :precondition 
            (and 
                (ball ?obj) 
                (room ?room) 
                (gripper ?gripper)
                (free ?gripper) 
                (at ?obj ?room) 
                (at-robby ?room)
            )
        :effect 
            (and 
                (not 
                    (free ?gripper)
                ) 
                (carry ?obj ?gripper) 
                (not (at ?obj ?room))
            )
        )
    (:action move
        :parameters (?from ?to)
        :precondition 
            (and 
                (room ?from) 
                (room ?to) 
                (at-robby ?from)
            )
        :effect 
            (and 
                (at-robby ?to)
                (not 
                    (at-robby ?from)
                )
            )
    )
    (:action drop
        :parameters (?room ?ball ?gripper)
        :precondition
            (and 
                (room ?room) 
                (ball ?ball) 
                (at-robby ?room) 
                (gripper ?gripper)
                (not 
                    (free ?gripper)
                )
                (carry ?ball ?gripper)
                (at-robby ?room))
        :effect 
            (and 
                (free ?gripper) 
                (at ?ball ?room) 
                (not
                    (carry ?ball ?gripper)
                )
            )
        )
)

2.question.pddl

问题域描述在这样的规划世界中一个具体问题的条件与目标。

  • 目标:将ball1和ball2两个球从a房间移动到b房间
  • 定义:对象、 初始状态和目标规范

示例代码如下:

(define (problem solve)
    (:domain gripper-strips)
    (:objects 
        rooma roomb 
        ball1 ball2 
        left right
    )
    (:init 
        (room rooma)
        (room roomb) 
        (ball ball1) 
        (ball ball2)
        (gripper left) 
        (gripper right) 
        (free left) 
        (free right)
        (at ball1 rooma) 
        (at ball2 rooma) 
        (at-robby rooma)
    )
    (:goal 
        (and
            (at ball1 roomb)
            (at ball2 roomb)
        )
    )
)

3.运行结果

运行结果如下图所示:

在这里插入图片描述

Planning service: http://solver.planning.domains/solve
Domain: gripper-strips, Problem: solve
 --- OK.
 Match tree built with 18 nodes.

PDDL problem description loaded: 
	Domain: GRIPPER-STRIPS
	Problem: SOLVE
	#Actions: 18
	#Fluents: 14
Landmarks found: 2
Starting search with IW (time budget is 60 secs)...
rel_plan size: 5
#RP_fluents 7
Caption
{#goals, #UNnachieved,  #Achieved} -> IW(max_w)

{2/2/0}:IW(1) -> [2][3][4]rel_plan size: 4
#RP_fluents 6
{2/1/1}:IW(1) -> [2][3][4][5][6][7];; NOT I-REACHABLE ;;
Total time: 4.47035e-10
Nodes generated during search: 42
Nodes expanded during search: 35
IW search completed
Starting search with BFS(novel,land,h_add)...
--[4294967295 / 8]--
--[1 / 8]--
--[1 / 6]--
--[1 / 5]--
--[1 / 4]--
--[1 / 2]--
--[1 / 1]--
--[1 / 0]--
--[0 / 0]--
Total time: 4.47035e-10
Nodes generated during search: 22
Nodes expanded during search: 7
Plan found with cost: 7
BFS search completed
0.00100: (pick ball2 rooma left)
0.00200: (move rooma roomb)
0.00300: (drop roomb ball2 left)
0.00400: (move roomb rooma)
0.00500: (pick ball1 rooma left)
0.00600: (move rooma roomb)
0.00700: (drop roomb ball1 left)
Planner found 1 plan(s) in 0.689secs.

另一种运行结果如下图所示:

在这里插入图片描述


4.逻辑解释

下面介绍该实例的智能规划逻辑。

前提:假设存在两个房间(Rooma和Roomb)、两个球(Ball1和Ball2)机器人拥有左手和右手,且机器人和球初始位置是Rooma房间。

  • action pick
  • action move
  • action drop

问题:如何将两个球从房间Rooma移动到Roomb?

在这里插入图片描述

第一步:机器人左手提起Ball1。

在这里插入图片描述

第二步:机器人移动至Roomb。

在这里插入图片描述

第三步:机器人释放Ball1。

在这里插入图片描述

第四步:机器人移动至Rooma。

在这里插入图片描述

第五步:机器人右手拿起Ball2。

在这里插入图片描述

第六步:机器人移动至Roomb。

在这里插入图片描述

第七步:机器人右手释放Ball2。

在这里插入图片描述

至此,完成移动任务。PDDL显示的逻辑路线如下图所示:

在这里插入图片描述

另一种方法如下图所示:机器人捡起两个球移动再释放。

在这里插入图片描述


四.总结

写到这里,本文就介绍完毕,希望对您有所帮助。

  • 一.PDDL简介
  • 二.PDDL基础语法知识
  • 三.入门示例详解
    1.domain.pddl
    2.question.pddl
    3.运行结果
    4.逻辑解释
  • 四.总结

大学之道在明明德,
在亲民,在止于至善。
这周又回答了很多博友的问题,有大一学生的困惑,有论文的咨询,也有老乡和考博的疑问,还有无数博友奋斗路上的相互勉励。虽然自己早已忙成狗,但总忍不住去解答别人的问题。最后那一句感谢和祝福,永远是我最大的满足。虽然会花费我一些时间,但也挺好的,无所谓了,跟着心走。不负遇见,感恩同行。莫愁前路无知己,继续加油。晚安娜和珞。

在这里插入图片描述

(By:Eastmount 2023-01-12 夜于贵阳 http://blog.csdn.net/eastmount/ )


参考文献:


  • 5
    点赞
  • 17
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
好的,农夫过河问题可以用PDDL语言进行规划,以下是一个简单的PDDL实现: ``` (define (problem farmer-crossing) (:domain farmer-crossing) (:objects farmer - person wolf - animal goat - animal cabbage - vegetable left - location right - location) (:init (at farmer left) (at wolf left) (at goat left) (at cabbage left) (opposite left right)) (:goal (and (at farmer right) (at wolf right) (at goat right) (at cabbage right))) (:action cross-farmer :parameters () :precondition (at farmer here) :effect (and (at farmer there) (not (at farmer here)))) (:action cross-wolf :parameters () :precondition (and (at farmer here) (at wolf here)) :effect (and (at wolf there) (not (at wolf here)))) (:action cross-goat :parameters () :precondition (and (at farmer here) (at goat here)) :effect (and (at goat there) (not (at goat here)))) (:action cross-cabbage :parameters () :precondition (and (at farmer here) (at cabbage here)) :effect (and (at cabbage there) (not (at cabbage here)))) (:action return-farmer :parameters () :precondition (at farmer there) :effect (and (at farmer here) (not (at farmer there)))) (:action return-wolf :parameters () :precondition (and (at farmer there) (at wolf there)) :effect (and (at wolf here) (not (at wolf there)))) (:action return-goat :parameters () :precondition (and (at farmer there) (at goat there)) :effect (and (at goat here) (not (at goat there)))) (:action return-cabbage :parameters () :precondition (and (at farmer there) (at cabbage there)) :effect (and (at cabbage here) (not (at cabbage there)))) (:predicate opposite :parameters (?x ?y) :precondition () :effect (or (and (eq ?x left) (eq ?y right)) (and (eq ?x right) (eq ?y left))))) ``` 在这个例子中,我们定义了“farmer-crossing”领域,并定义了对象、初始状态和目标状态。我们还定义了动作,如“cross-farmer”、“cross-wolf”等,以及这些动作的前提条件和效果。最后,我们定义了谓词“opposite”,表示两个位置之间的关系。 通过这个PDDL实现,我们可以使用规划器来解决农夫过河问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Eastmount

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值