Code Monkey home page Code Monkey logo

prolog-graphplan's Introduction

The Prolog GraphPlan Project

The Graphplan algorithm is an automatic planning algorithm that can compute, given a set of rules, a plan of action to go from an initial state to a final state.

The algorithm was described by Blum and Furst in 1997 and published in:

A. Blum and M. Furst (1997). Fast planning through planning graph analysis. Artificial intelligence. 90:281-300.

This project provides an open source (GPL v3) implementation of this planner in Prolog.

How to use it

This implementation has been tested with SWI-Prolog and is quite simple to use.

There is a basic toy example of a planning domain in examples/rocket_graph.pl. This example provides the "rocket payload" scenario where a set or rockets can be used to move cargo between places.

Before all, you need to load the planner and the domain:

load_files('graphplan').
load_files('examples/rocket_graph').

First of all we define the "world" facts that can be used by the planner to do the inferences:

    rocket(rocket1).
    place(london).
    place(paris).
    cargo(a).
    cargo(b).
    cargo(c).
    cargo(d).

The example predicates are very simple atomic predicates, but with our implementation, you can use any kind of prolog predicates and perfom inferences in the word definition predicates.

Note that these "word" predicates do not describe a changeable state but fixed facts that will not be changed during the planning (i.e. in our examples, the initial position of the rocket is not defined with such predicates)

The planner can be called with the plan\4 predicate, for instance:

    plan([at(a, london), at(rocket1, london), has_fuel(rocket1)],
    	     [at(a, paris)], rocket,
    	     P).

This predicate takes three arguments:

  1. the initial state of the world
  2. the final state of the world that should be reached when the plan is completed
  3. a "domain" where the plan should take place (more about that later).

And "returns" the plan in P.

The plan tries to find a set of actions to change the initial state to reach the final state. Thus you have to define these actions before you can find a plan.

Actions are defined with three predicates:

  1. the preconditions required to perform an action: can(Action, StateDefinition, Domain).

    • first you define the action name,
    • second you define the required precondition as a set of state predicates,
    • and you provide a domain (more about that later).
  2. what the action adds to the current state of the world when it's completed: adds(Action, ListOfAddedStatePredicates, _, Domain).

    • first you define the action name,
    • second you define the list of added state predicates,
    • third you ignore this,
    • and you provide a domain.
  3. what the action removes from the current state of the world when it's completed: deletes(Action, ListOfDeletedStatePredicates, Domain).

    • first you define the action name,
    • second you define the list of removed state predicates,
    • and you provide a domain.

And that's it. It seems complicated, but you can see the definition of the actions in the rocket example and you will see it's not that hard. For instance:

unload(Rocket, Place, Cargo). unload a cargo from a rocket:

  1. preconditions: the cargo must be in the right place
    can(unload(Rocket, Place, Cargo),[at(Rocket,Place),in(Cargo,Rocket)], rocket) :-
    	rocket(Rocket),
    	cargo(Cargo),
    	place(Place).
  1. added state: the cargo is now in the new place
    adds(unload(Rocket, Place, Cargo),[at(Cargo,Place)], _, rocket) :-
    	rocket(Rocket),
    	cargo(Cargo),
    	place(Place).
  1. removed state: the cargo is not in the rocket anymore
    deletes(unload(Rocket, _Place, Cargo),[in(Cargo,Rocket)], rocket) :-
    	rocket(Rocket),
    	cargo(Cargo).

When you call the plan predicate, you will get the complete plan (if one is possible). The current implementation also prints out the plan for simple viewing.

    Step 1:
            load(rocket1,london,a)
    
    Step 2:
            move(rocket1,london,paris)
    
    Step 3:
            unload(rocket1,paris,a)
    
    
    P = [[load(rocket1, london, a)], [move(rocket1, london, paris)], [unload(rocket1, paris, a)]] .

Note that the graphplan algorithm can find actions that can be performed in parallel and thus you can have more than one action per step. Try the test2(P) and test3(P) predicates from the example to see how it works.

The Domain

Because you can load multiple "action" definitions in the same prolog environment, the current implementation protects each action definition within a domain and this is why you have to define in which domain each action is specified and in which domain to search for a plan.

Contributors

This implementation is based on the original algorithm described by Blum and Furst.

The initial implementation was provided by Dr. Suresh Manandhar from the University of York Computer Science department and slightly modified by Dr. Pierre Andrews.

The code is distributed under GPL v3. If you use it, please be sure to provide the right attribution and, if you wish, let us know about it.

You are welcome to contribute patches or improvements to this project. Dr. Manandhar and Andrews are providing the code as is and do not have any plans to provide support (new features, bug corrections) for this project, but I will make sure to push contributed patches to improve the code when I receive them.

If you want to contribute more examples, it would be great too.

Applications

Currently, this implementation of the graphplan has successfully been used for:

  • Planning Human-Computer Dialogue by P. Andrews.

if you use this planner for any other application, please let us know.

prolog-graphplan's People

Contributors

mortimerp9 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

prolog-graphplan's Issues

graphplan.pl returns the same plan multiple times

Hello,

I have been downloading and trying your graphplan implementation with the rocket_plan example.
But unfortunately it returns thesame plan so many times. For instance test(P) returns the same plan about 20 times (or more):

?- test(P).
P = [[load(rocket1, london, a)], [move(rocket1, london, paris)], [unload(rocket1, paris, a)]] ;
P = [[load(rocket1, london, a)], [move(rocket1, london, paris)], [unload(rocket1, paris, a)]] ;
P = [[load(rocket1, london, a)], [move(rocket1, london, paris)], [unload(rocket1, paris, a)]] ;
P = [[load(rocket1, london, a)], [move(rocket1, london, paris)], [unload(rocket1, paris, a)]] ;
P = [[load(rocket1, london, a)], [move(rocket1, london, paris)], [unload(rocket1, paris, a)]] ;

I am using swipl Vesrion 7.2.3

Any idea what could cause this?

Thank you for your help

Fabrice

Read current state inside adds

Hello, I'd like to solve a variant of your Rocket problem where:

  • the rockets have a quantifiable amount of fuel (e.g. 1000 units)
  • moving from a city to another one consumes some amount of fuel (e.g. 300 units).

In order to solve this, I thought I might add to the state a predicate: fuel(Rocket, FuelAmount).

But how can I update the state inside the adds predicate? I mean, can I somehow access the current state to read the FuelAmount of a Rocket in order to add fuel(Rocket, RemainingFuel) where RemainingFuel is FuelAmount - 300?

I'm sorry to trouble you but i'm unexperienced in Prolog and I can't tell if there's an obvious way solve this or if it's a limitation of Graphplan.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.