PDDL demo(转)

http://editor.planning.domains/#

文件 domain

(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


(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)
        )
    )
)

选择 solve-->Plan

http://solver.planning.domains/ 里面例子如下,调用接口处理

可以用python搞:

import urllib2, json, sys

data = {'domain': open(sys.argv[1], 'r').read(),
        'problem': open(sys.argv[2], 'r').read()}

req = urllib2.Request('http://solver.planning.domains/solve')
req.add_header('Content-Type', 'application/json')
resp = json.loads(urllib2.urlopen(req, json.dumps(data)).read())

with open(sys.argv[3], 'w') as f:
    f.write('\n'.join([act['name'] for act in resp['result']['plan']]))

猜你喜欢

转载自blog.csdn.net/lifestxx/article/details/86133452