Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Here is a table of algorithms, the figure, name of the algorithm in the book and
| 9.3 | FOL-FC-Ask | `fol_fc_ask` | [`logic.py`][logic] | Done | |
| 9.6 | FOL-BC-Ask | `fol_bc_ask` | [`logic.py`][logic] | Done | |
| 9.8 | Append | | | | |
| 10.1 | Air-Cargo-problem | `air_cargo` | [`planning.py`][planning] | Done | |
| 10.1 | Air-Cargo-problem | `air_cargo` | [`planning.py`][planning] | Done | Included |
| 10.2 | Spare-Tire-Problem | `spare_tire` | [`planning.py`][planning] | Done | |
| 10.3 | Three-Block-Tower | `three_block_tower` | [`planning.py`][planning] | Done | |
| 10.7 | Cake-Problem | `have_cake_and_eat_cake_too` | [`planning.py`][planning] | Done | |
Expand Down
152 changes: 111 additions & 41 deletions planning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"from planning import *"
Expand All @@ -51,9 +49,7 @@
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"%psource Action"
Expand Down Expand Up @@ -83,9 +79,7 @@
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"%psource PDDL"
Expand All @@ -110,9 +104,7 @@
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"from utils import *\n",
Expand Down Expand Up @@ -141,9 +133,7 @@
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"knowledge_base.extend([\n",
Expand All @@ -163,9 +153,7 @@
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [
{
"data": {
Expand Down Expand Up @@ -203,9 +191,7 @@
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"#Sibiu to Bucharest\n",
Expand Down Expand Up @@ -261,9 +247,7 @@
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"#Drive\n",
Expand All @@ -284,9 +268,7 @@
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": [
"def goal_test(kb):\n",
Expand All @@ -303,31 +285,119 @@
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"metadata": {},
"outputs": [],
"source": [
"prob = PDDL(knowledge_base, [fly_s_b, fly_b_s, fly_s_c, fly_c_s, fly_b_c, fly_c_b, drive], goal_test)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Air Cargo Problem:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Air Cargo problem involves loading and unloading of cargo and flying it from place to place. The problem can be with defined with three actions: Load, Unload and Fly. Let us now define an object of `air_cargo` problem:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": []
"source": [
"airCargo = air_cargo()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, before taking any actions, we will check the `airCargo` if it has completed the goal it is required to do:"
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n"
]
}
],
"source": [
"print(airCargo.goal_test())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As we can see, it hasn't completed the goal. Now, we define the sequence of actions that it should take in order to achieve\n",
"the goal. Then the `airCargo` acts on each of them."
]
},
{
"cell_type": "code",
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"solution = [expr(\"Load(C1 , P1, SFO)\"),\n",
" expr(\"Fly(P1, SFO, JFK)\"),\n",
" expr(\"Unload(C1, P1, JFK)\"),\n",
" expr(\"Load(C2, P2, JFK)\"),\n",
" expr(\"Fly(P2, JFK, SFO)\"),\n",
" expr(\"Unload (C2, P2, SFO)\")] \n",
"\n",
"for action in solution:\n",
" airCargo.act(action)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"As the `airCargo` has taken all the steps it needed in order to achieve the goal, we can now check if it has acheived its goal:"
]
},
{
"cell_type": "code",
"execution_count": 18,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 18,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"airCargo.goal_test()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": []
"source": [
"It has now achieved its goal."
]
}
],
"metadata": {
Expand All @@ -346,9 +416,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.3"
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}