359 字
1 分钟
PDDL规划语言
概述
(PDDL,Planning Domain Definition Language)
- objects(对象) 世界中我们感兴趣的事物。
- predicates(谓词) 我们感兴趣的对象属性;可以为真或假。
- initial state(初始状态) 我们开始时的世界状态。
- goal specification(目标规范) 我们希望成立的事物(即目标状态)。
- action/operators(操作/运算符) 改变世界状态的方式。
PDDL指定的规划任务分为两个文件,domain 文件和 problem 文件。
A domain file(域文件) for predicates and actions. A problem file(问题文件) for objects, initial state and goal specification.
domain:电视剧的剧本模板(人物设定、可以发生的情节类型)
problem : 具体一集(这一集的初始情况、这一集要达成的目标)
1.Domain文件详解
1.基本框架:
(define (domain 领域名称) (:requirements 需要的特性) (:types 类型定义) (:constants 常量定义) ; 可选 (:predicates 谓词定义) (:functions 函数定义) ; 如果用到数值 (:action 动作定义) ; 可以有多个)2.requirements 需求声明:
(:requirements :strips) ; 基本功能(必须)(:requirements :typing) ; 使用类型系统(:requirements :adl) ; 使用高级条件(如forall, exists)(:requirements :fluents) ; 使用数值变量(:requirements :durative-actions) ; 使用持续动作(:requirements :equality) ; 使用等于/不等于判断
; 可以组合使用:(:requirements :strips :typing :durative-actions)3.Types 类型定义
(:types robot ; 简单类型 location ; 简单类型
; 继承关系 vehicle ; 父类型 car truck - vehicle ; car和truck是vehicle的子类型
; 多级继承 animal ; 动物 dog cat - animal ; 狗和猫是动物 puppy - dog ; 小狗是狗的子类型)4.constants 常量定义
(:constants robot1 robot2 - robot ; 两个机器人常量 charging_station - location ; 充电站位置)5.Predicates(谓词)
(:predicates ; 格式: (谓词名 参数1 - 类型1 参数2 - 类型2 ...)
; 位置相关 (at ?obj - object ?loc - location) ; 物体在某个位置 (connected ?from - location ?to - location) ; 两个位置相连
; 状态相关 (power-on ?device - electronic) ; 设备开机 (battery-low ?robot - robot) ; 机器人电量低
; 关系相关 (carries ?robot - robot ?box - container) ; 机器人携带箱子 (belongs-to ?item - object ?owner - person) ; 物品属于某人)6.Functions(函数)
(:functions (battery-level ?r - robot) ; 机器人电量(数值) (distance ?loc1 ?loc2 - location) ; 两个位置的距离 (total-cost) ; 总成本(用于优化))7.Actions(动作定义)
(:action 动作名称 :parameters (?参数1 - 类型1 ?参数2 - 类型2 ...) ; 动作涉及的对象 :precondition (and ...) ; 前提条件 :effect (and ...) ; 执行效果)7.1 普通动作(瞬时动作)
(:action 动作名称 :parameters (?参数1 - 类型1 ?参数2 - 类型2 ...) ; 动作涉及的对象 :precondition (and ...) ; 前提条件 :effect (and ...) ; 执行效果)条件写法 :
:precondition (and (at ?robot ?loc) ; 简单谓词 (not (carrying ?robot ?box)) ; 否定条件 (forall (?p - person) ; 对所有... (not (in-room ?p ?loc))) ; 条件 (exists (?b - box) ; 存在某个... (on-table ?b)) ; 条件 (> (battery-level ?robot) 20) ; 数值比较(需要fluents) (= (distance ?loc1 ?loc2) 10) ; 等于判断)效果(effect)写法:
:effect (and (at ?robot ?newloc) ; 添加谓词 (not (at ?robot ?oldloc)) ; 删除谓词 (forall (?p - person) ; 对所有... (scared ?p)) ; 添加效果
; 数值变化(需要fluents) (increase (battery-level ?robot) -10) ; 减少电量 (assign (total-cost) (+ (total-cost) 5)) ; 增加成本 (decrease (fuel) 1) ; 减少燃料)7.2 持续动作(带时间)
(:durative-action 动作名称 :parameters (?参数1 - 类型1 ?参数2 - 类型2 ...)
; 持续时间(可以是固定值或变量) :duration (= ?duration 10) ; 固定10秒 :duration (>= ?duration 5) ; 至少5秒 :duration (= ?duration (distance ?loc1 ?loc2)) ; 取决于距离
; 条件(可以指定时间点) :condition (and (at start (at ?robot ?loc1)) ; 开始时 (at end (connected ?loc1 ?loc2)) ; 结束时 (over all (battery-high ?robot)) ; 整个过程中 )
; 效果(可以指定时间点) :effect (and (at start (not (at ?robot ?loc1))) ; 开始时离开 (at end (at ?robot ?loc2)) ; 结束时到达 (at end (decrease (fuel) 5)) ; 结束时减少燃料 ))2.problem文件详解
基本框架
(define (problem 问题名称) (:domain 领域名称) ; 指定使用哪个domain
(:objects ; 定义这个具体问题中的对象 robot1 robot2 - robot room1 room2 room3 - room box1 box2 - container )
(:init ; 定义初始状态 (at robot1 room1) (at robot2 room3) (connected room1 room2) (connected room2 room3) (battery-full robot1) (battery-low robot2) (charging-point-at room1)
; 数值初始值(如果有functions) (= (battery-level robot1) 100) (= (battery-level robot2) 15) (= (total-cost) 0) )
(:goal ; 定义要达成的目标 (and (at robot1 room3) (at robot2 room1) (not (battery-low robot2)) ) )
(:metric minimize (total-cost)) ; 可选:优化目标(最小化总成本))3.完整示例
domain示例:
(define (domain warehouse) (:requirements :strips :typing :durative-actions :fluents)
(:types robot location package - object )
(:predicates (at ?obj - object ?loc - location) (connected ?from ?to - location) (carrying ?r - robot ?p - package) (empty ?r - robot) )
(:functions (battery ?r - robot) (distance ?from ?to - location) )
(:durative-action move :parameters (?r - robot ?from ?to - location) :duration (= ?duration (distance ?from ?to)) :condition (and (at start (at ?r ?from)) (at start (connected ?from ?to)) (over all (> (battery ?r) 0)) ) :effect (and (at start (not (at ?r ?from))) (at end (at ?r ?to)) (at end (decrease (battery ?r) (distance ?from ?to))) ) )
(:action pick :parameters (?r - robot ?p - package ?loc - location) :precondition (and (at ?r ?loc) (at ?p ?loc) (empty ?r) ) :effect (and (not (at ?p ?loc)) (carrying ?r ?p) (not (empty ?r)) ) ))problem示例
(define (problem warehouse-1) (:domain warehouse)
(:objects r1 r2 - robot dock shelf1 shelf2 - location pkg1 pkg2 - package )
(:init (at r1 dock) (at r2 dock) (at pkg1 shelf1) (at pkg2 shelf2) (connected dock shelf1) (connected dock shelf2) (connected shelf1 dock) (connected shelf2 dock) (empty r1) (empty r2) (= (battery r1) 100) (= (battery r2) 100) (= (distance dock shelf1) 10) (= (distance dock shelf2) 15) (= (distance shelf1 dock) 10) (= (distance shelf2 dock) 15) )
(:goal (and (at pkg1 dock) (at pkg2 dock) )))4.常用语法表
| 语法 | 含义 | 示例 |
|---|---|---|
?x | 变量 | ?robot - robot |
- | 类型声明 | ?r - robot |
and | 逻辑与 | (and (at ?r ?loc) (connected ?loc ?loc2)) |
or | 逻辑或 | (or (battery-low) (broken)) |
not | 逻辑非 | (not (at ?r ?loc)) |
forall | 所有对象 | (forall (?p - person) (awake ?p)) |
exists | 存在对象 | (exists (?b - box) (on-table ?b)) |
when | 条件效果 | (when (battery-low) (alarm-on)) |
= | 等于 | (= (battery) 100) |
> < | 比较 | (> (battery) 20) |
increase | 增加值 | (increase (cost) 5) |
decrease | 减少值 | (decrease (fuel) 1) |
assign | 赋值 | (assign (battery) 100) |
分享
如果这篇文章对你有帮助,欢迎分享给更多人!
部分信息可能已经过时
相关文章 智能推荐
1
Langchain学习
AI LangChain 学习笔记,整理模型接口、提示词、输出解析、链式调用、记忆和工具集成。
2
AI编程范式浅了解
AI AI 编程范式笔记,整理 vibe coding、spec coding、工程化协作方式和实践优劣。
3
ollama安装
AI Ollama 安装笔记,整理 Windows 安装、模型目录配置、环境变量和本地模型运行方法。
4
AI学习(五)- HarnessEngineering(未完待续)
AI Harness Engineering 学习笔记,整理 Agent 运行框架、上下文管理、工具调用、验证闭环和工程实践。
5
AI学习(三)- RAG
AI RAG 学习笔记,整理检索增强生成的原理、流程、向量检索、知识库构建和应用实践。