Introduction to artificial intelligence-a simple example of pddl

As a little white who has just learned artificial intelligence, he expresses a stunned expression on many knowledge. As the course progresses to the planning problem, it is inevitable to meet pddl, and after a period of learning, the following briefly introduces pddl from the perspective of white, and accompanied by a brief example.

Planning Domain Definition Language (referred to as pddl, planning area definition language)

Is a standardized artificial intelligence planning language, mainly related to logic and planning tasks, not elaborated here. You can google by yourself. There is a PDF file about pddl , which contains a brief introduction and the most basic grammar. Before you start learning, you must first understand the basic grammar content yourself. Here is the simplest example. This example simulates the simple process of a robot cleaning two rooms.

domain file:

(define (domain state)          //domain命名,怎么喜欢怎么来
    (:predicates (room ?r)        //谓词,这里应该包括该文件中出现的所有的谓词逻辑,不然会error:Undefined,这里判断是不是room
                (robot ?rob)       //这里则是判断一个抽象对象rob是不是robot
                (at-robot ?r)          //判断robot是不是在room r中
                (dirty ?r)        //判断room r是不是脏的
                (clean ?r)        //判断room r是不是干净的
                (fullPower ?rob))    //判断机器人robot是不是有电
    (:action sweep             //扫地动作
        :parameters(?robot ?r)      //设置参数
        :precondition           //前提条件(前件)
            (and              //and的意思是以下括号内的都必须为真
                (robot ?robot)      //这个对象robot是robot为真
                (room ?r)         //这个对象r是room为真
                (dirty ?r)        //这个r是dirty的
                (at-robot ?r)      //而且robot在r中刚好为真
                (fullPower ?robot)   //机器人有电
            )
        :effect               //满足以上条件,执行扫地动作,效果为如下
            (and                    
                (clean ?r)        //r已经干净了
                (not  
                    (dirty ?r)      //r不脏
                )
                (not
                    (fullPower ?robot) //机器人没电,默认为扫一个房间即耗尽电量
                )
            )
    )

    (:action charging            //充电动作
        :parameters(?robot ?r)           //两个参数为robot跟r,就近充电
        :precondition 
            (and   
                (robot ?robot)        
                (room ?r) 
                (at-robot ?r)
                (clean ?r)
                (not
                    (fullPower ?robot)
                )
            )
        :effect 
            (and 
                (fullPower ?robot)    //充满电,可进行下一动作
            )
    )

    (:action move               //移动动作
        :parameters (?from ?to)      //从from移动到to
        :precondition 
            (and 
                (dirty ?to)          //移动的前提:to还是脏的,from已经扫干净了,而且robot在扫干净的房间里,想移动到脏的房间
                (clean ?from)
                (room ?from) 
                (room ?to) 
                (at-robot ?from)
            )
        :effect 
            (and 
                (at-robot ?to)       //效果:到达脏的房间,离开干净的房间
                (not 
                    (at-robot ?from)
                )
            )
    )
)

problem (test) file:

(define (problem solve)
    (:domain state)
    (:objects 
        rooma roomb robot     //设置对象,这个例子比较简单,只有三个对象,房间a房间b还有机器人
    )
    (:init               //初始化起始状态,有两个房间,都是脏的,机器人在房间a并且满电,注意此处不用(room ?rooma)
        (room rooma)
        (room roomb) 
        (robot robot)
        (dirty rooma)
        (dirty roomb)
        (at-robot rooma)
        (fullPower robot)
    )
    (:goal                        //设定这个规划问题最终要达到的目标状态,两个房间是干净的,并且机器人仍旧是满电待命的
        (and
            (clean rooma)
            (clean roomb)
            (fullPower robot)
        )
    )
)

operation result:



Published 34 original articles · Like 10 · Visitors 10,000+

Guess you like

Origin blog.csdn.net/weixin_41111088/article/details/80213873