PageRenderTime 49ms CodeModel.GetById 15ms app.highlight 29ms RepoModel.GetById 1ms app.codeStats 0ms

/README.markdown

http://github.com/Mortimerp9/Prolog-Graphplan
Markdown | 157 lines | 104 code | 53 blank | 0 comment | 0 complexity | 319880f07cb14f466687c1cafd367db8 MD5 | raw file
  1The Prolog GraphPlan Project
  2============================
  3
  4The [Graphplan algorithm](http://en.wikipedia.org/wiki/Graphplan) is an [automatic planning](http://en.wikipedia.org/wiki/Automated_planning) algorithm that can compute, given a set of rules, a plan of action to go from an initial state to a final state.
  5
  6The algorithm was described by Blum and Furst in 1997 and published in:
  7
  8> A. Blum and M. Furst (1997). Fast planning through planning graph analysis. Artificial intelligence. 90:281-300.
  9
 10This project provides an open source (GPL v3) implementation of this planner in Prolog.
 11
 12How to use it
 13-------------
 14
 15This implementation has been tested with [SWI-Prolog](http://www.swi-prolog.org/) and is quite simple to use.
 16
 17There 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.
 18
 19Before all, you need to load the planner and the domain:
 20
 21```prolog
 22load_files('graphplan').
 23load_files('examples/rocket_graph').
 24``` 
 25
 26First of all we define the "world" facts that can be used by the planner to do the inferences:
 27
 28```prolog
 29    rocket(rocket1).
 30    place(london).
 31    place(paris).
 32    cargo(a).
 33    cargo(b).
 34    cargo(c).
 35    cargo(d).
 36 ```
 37
 38The 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.
 39
 40> *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)*
 41
 42The planner can be called with the `plan\4` predicate, for instance:
 43```prolog
 44    plan([at(a, london), at(rocket1, london), has_fuel(rocket1)],
 45    	     [at(a, paris)], rocket,
 46    	     P).
 47```
 48
 49This predicate takes three arguments:
 501. the initial state of the world
 512. the final state of the world that should be reached when the plan is completed
 523. a "domain" where the plan should take place (more about that later).
 53
 54And "returns" the plan in `P`.
 55
 56The 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.
 57
 58Actions are defined with three predicates:
 59
 601. the *preconditions* required to perform an action:
 61`can(Action, StateDefinition, Domain).`
 62
 63	* first you define the action name,
 64	* second you define the required precondition as a set of state predicates,
 65	* and you provide a domain (more about that later).
 66
 672. what the action *adds* to the current state of the world when it's completed:
 68`adds(Action, ListOfAddedStatePredicates, _, Domain).`
 69
 70    * first you define the action name,
 71	* second you define the list of added state predicates,
 72	* third you ignore this,
 73	* and you provide a domain.
 74
 753. what the action *removes* from the current state of the world when it's completed:
 76`deletes(Action, ListOfDeletedStatePredicates, Domain).`
 77
 78    * first you define the action name,
 79	* second you define the list of removed state predicates,
 80	* and you provide a domain.
 81
 82And 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:
 83
 84`unload(Rocket, Place, Cargo).` unload a cargo from a rocket:
 85
 861. **preconditions:** the cargo must be in the right place
 87
 88```prolog
 89    can(unload(Rocket, Place, Cargo),[at(Rocket,Place),in(Cargo,Rocket)], rocket) :-
 90    	rocket(Rocket),
 91    	cargo(Cargo),
 92    	place(Place).
 93```
 94
 952. **added state:** the cargo is now in the new place
 96
 97```prolog
 98    adds(unload(Rocket, Place, Cargo),[at(Cargo,Place)], _, rocket) :-
 99    	rocket(Rocket),
100    	cargo(Cargo),
101    	place(Place).
102```
103
1043. **removed state:** the cargo is not in the rocket anymore
105
106
107```prolog
108    deletes(unload(Rocket, _Place, Cargo),[in(Cargo,Rocket)], rocket) :-
109    	rocket(Rocket),
110    	cargo(Cargo).
111```
112
113When 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.
114
115```prolog
116    Step 1:
117            load(rocket1,london,a)
118    
119    Step 2:
120            move(rocket1,london,paris)
121    
122    Step 3:
123            unload(rocket1,paris,a)
124    
125    
126    P = [[load(rocket1, london, a)], [move(rocket1, london, paris)], [unload(rocket1, paris, a)]] .
127``` 
128
129> *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.*
130
131
132The Domain
133----------
134
135Because  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.
136
137Contributors
138============
139
140This implementation is based on the original algorithm described by **Blum and Furst**.
141
142The initial implementation was provided by [**Dr. Suresh Manandhar**](http://www-users.cs.york.ac.uk/~suresh/) from the University of York Computer Science department and slightly modified by [**Dr. Pierre Andrews**](http://disi.unitn.it/~andrews/).
143
144The 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.
145
146You 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.
147
148If you want to contribute more examples, it would be great too.
149
150Applications
151============
152
153Currently, this implementation of the graphplan has successfully been used for:
154
155* Planning Human-Computer Dialogue by P. Andrews.
156
157*if you use this planner for any other application, please let us know.*