网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!
- 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
文件。
- A domain file(域文件) for predicates and actions.
- 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文件。
推荐下列参考资料:
二.VSCode安装教程
第一步,在VSCode中安装PDDL插件。
- 点击扩展按钮
- 搜索PDDL
- 点击安装“Install”按钮即可
安装成功后如下图所示:
第二步,在VSCode中安装VAL语法检查。
在VS Code安装PDDL成功后,打开PDDL Overview进行安装VAL。
- View -> Command Palette -> PDDL: show overview page
安装过程如下图所示,对应“VAL tools”点击“Download”。
第三步,安装成功之后,可以看到详细的配置信息如下:
- planning engine(在线规划引擎)
Planning service: http://solver.planning.domains/solve - PDDL parser(PDDL解析器)
c:\Users\xxx\AppData\Roaming\Code\User\globalStorage\jan-dolejsi.pddl\val\Val-20210215.2-win64\bin\Parser.exe - Plan Validator(规划验证器)
c:\Users\xxx\AppData\Roaming\Code\User\globalStorage\jan-dolejsi.pddl\val\Val-20210215.2-win64\bin\Validate.exe
此时,我们可以进入后续的PDDL代码编写过程。同时,存在部分在线访问的问题,后续尝试解决。
VSCode PDDL
VSCode是建模规划域的良好工具,其扩展将PDDL引入了一流的编程语言家族中,让其与C#、Python、JavaScript等处于同等级别。PDDL旨在通过以下功能帮助新手并为专家赋能。
- 规划领域建模
planning domain modeling - 通过回归或可扩展性测试用例的数量规划域验证
planning domain validation by number of regression or scalability test cases - 通过从模板生成问题文件来规划工业化解决方案
planning solution industrializing by problem file generation from templates - 计划验证
plan validation
当扩展在 .pddl
文件(通常包含域或问题定义)或选定的PDDL命令被激活时,即可配置解释器(parser)或规划器(planner)。
三.PDDL基础案例快速入门
1.Getting started
创建PDDL文件并运行计划程序,下面是官方最简单的入门步骤:
- (1) 点击
File > Open Folder
打开VS Code中一个空白文件夹。 - (2) 点击
File > New File
创建两个名为domain.pddl
和question.pddl
的空白文件,这两个文件将显示在资源管理器窗格中,在编辑器中并排打开它们。 - (3) 打开
domain.pddl
文件并输入domain
。自动模板会插入域文件的整个结构,使用 Tab 和 Enter 键跳过占位符并进行选择。 - (4) 打开
problem.pddl
文件并输入problem
。自动模板会插入问题文件的整个结构,确保此处的(域名)与域文件中选择的名称匹配。 - (5) 当提示安装
VAL
(验证器 Validator)工具时,请按照说明进行操作。这将为您带来一个PDDL解析器和计划验证实用程序。 - (6) 当准备在域和问题文件上运行规划器时,可以通过文件内容或编辑器选项卡的上下文菜单,或通过Alt + P快捷方式调用规划器(planner)。这个
planning.domains
解析器也将被使用,因此不要发送任何敏感的PDDL代码。 - (7) 按照说明配置您自己的 PDDL 规划器。
同时补充一个在线编辑PDD的网站。
2.创建文件
第一步,点击 File > Open Folder
打开VS Code中一个空白文件夹。
第二步,点击 File > New File
创建两个名为 domain.pddl
和 question.pddl
的空白文件,这两个文件将显示在资源管理器窗格中,在编辑器中并排打开它们。
第三步,打开 domain.pddl
文件并输入 domain
。自动模板会插入域文件的整个结构,使用 Tab 和 Enter 键跳过占位符并进行选择。
第四步,打开 problem.pddl
文件并输入 problem
。自动模板会插入问题文件的整个结构,确保此处的(域名)与域文件中选择的名称匹配。
此时的代码如下所示,仅仅是一个PDDL规划问题的框架基础代码。
domain.pddl
;Header and description
(define (domain domain_name)
;remove requirements that are not needed
(:requirements :strips :fluents :durative-actions :timed-initial-literals :typing :conditional-effects :negative-preconditions :duration-inequalities :equality)
(:types ;todo: enumerate types and their hierarchy here, e.g. car truck bus - vehicle
)
; un-comment following line if constants are needed
;(:constants )
(:predicates ;todo: define predicates here
)
(:functions ;todo: define numeric functions here
)
;define actions here
)
problem.pddl
(define (problem problem_name) (:domain domain_name)
(:objects
)
(:init
;todo: put the initial state's facts and numeric values here
)
(:goal (and
;todo: put the goal condition here
))
;un-comment the following line if metric is needed
;(:metric minimize (???))
)
3.调用在线规划器
由于作者不太会安装VAL工具(学习中),所以先介绍在线运行的过程。
当准备在域和问题文件上运行规划器时,可以通过文件内容或编辑器选项卡的上下文菜单,或通过
Alt + P
快捷方式调用规划器(planner)。这个planning.domains
解析器将将被使用,因此不要发送任何敏感的PDDL代码。
第一步,编写一个 domain
示例代码。
- predicates:谓词定义
- action:动作包括pick、move和drop
domain.pddl
(define (domain gripper-strips)
(: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)
)
)
)
)
第二步,编写一个 problem
示例代码。
- objects:两个房间,两个球,左右移动
- init:初始化
question.pddl
(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)
)
)
)
第三步,如果右键选中直接运行或按 alt+P
运行planner,它会提示错误。
第四步,点击如下图所示的“Test”按钮并创建。
生成如下图所示的测试树状图,并且准备调用远程的 planning.domains
服务器
- Planning service: http://solver.planning.domains/solve
- Domain: gripper-strips, Problem: solve
第五步,点击“domain”右边的三角运行按钮,生成如下图所示的测试报告。注意,右边的“Planner output”是一个规划路径的输出方案。
同时,我们可以双栏打开窗口。
注意,其实我们直接在Explorer中选中PDDL文件,右键“PDDL: Run the planner and display the plan”按钮可以生成运行的规划结果。不需要创建Test,如下图所示,但仍然会进行远程连接。
至此,我们线上运行PDDL规划器的方法介绍完毕。该代码具体的含义及基础语法我们将在第四部分详细介绍。
Finished executing tests from VSCode/PDDL-test01/domain.ptest.json.
![img](https://img-blog.csdnimg.cn/img_convert/393f33423af547b5405a8b144267d0d2.png)
![img](https://img-blog.csdnimg.cn/img_convert/c498607bc4e7b32ff341b88abf9cd129.png)
**网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。**
**[需要这份系统化资料的朋友,可以戳这里获取](https://bbs.csdn.net/topics/618545628)**
**一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!**
size_16,color_FFFFFF,t_70#pic_center)
至此,我们线上运行PDDL规划器的方法介绍完毕。该代码具体的含义及基础语法我们将在第四部分详细介绍。
Finished executing tests from VSCode/PDDL-test01/domain.ptest.json.
[外链图片转存中…(img-cwI8huLP-1715797915707)]
[外链图片转存中…(img-6oh9x7lw-1715797915707)]
网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。
一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!