Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 14a704b

Browse files
nouman-10norvig
authored andcommitted
Added air_cargo to planning.ipynb (#835)
* Added air_cargo to planning.ipynb * Some style issues
1 parent dc16a97 commit 14a704b

File tree

2 files changed

+112
-42
lines changed

2 files changed

+112
-42
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Here is a table of algorithms, the figure, name of the algorithm in the book and
108108
| 9.3 | FOL-FC-Ask | `fol_fc_ask` | [`logic.py`][logic] | Done | |
109109
| 9.6 | FOL-BC-Ask | `fol_bc_ask` | [`logic.py`][logic] | Done | |
110110
| 9.8 | Append | | | | |
111-
| 10.1 | Air-Cargo-problem | `air_cargo` | [`planning.py`][planning] | Done | |
111+
| 10.1 | Air-Cargo-problem | `air_cargo` | [`planning.py`][planning] | Done | Included |
112112
| 10.2 | Spare-Tire-Problem | `spare_tire` | [`planning.py`][planning] | Done | |
113113
| 10.3 | Three-Block-Tower | `three_block_tower` | [`planning.py`][planning] | Done | |
114114
| 10.7 | Cake-Problem | `have_cake_and_eat_cake_too` | [`planning.py`][planning] | Done | |

planning.ipynb

Lines changed: 111 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,7 @@
2323
{
2424
"cell_type": "code",
2525
"execution_count": 1,
26-
"metadata": {
27-
"collapsed": false
28-
},
26+
"metadata": {},
2927
"outputs": [],
3028
"source": [
3129
"from planning import *"
@@ -51,9 +49,7 @@
5149
{
5250
"cell_type": "code",
5351
"execution_count": 2,
54-
"metadata": {
55-
"collapsed": false
56-
},
52+
"metadata": {},
5753
"outputs": [],
5854
"source": [
5955
"%psource Action"
@@ -83,9 +79,7 @@
8379
{
8480
"cell_type": "code",
8581
"execution_count": 3,
86-
"metadata": {
87-
"collapsed": false
88-
},
82+
"metadata": {},
8983
"outputs": [],
9084
"source": [
9185
"%psource PDDL"
@@ -110,9 +104,7 @@
110104
{
111105
"cell_type": "code",
112106
"execution_count": 4,
113-
"metadata": {
114-
"collapsed": false
115-
},
107+
"metadata": {},
116108
"outputs": [],
117109
"source": [
118110
"from utils import *\n",
@@ -141,9 +133,7 @@
141133
{
142134
"cell_type": "code",
143135
"execution_count": 5,
144-
"metadata": {
145-
"collapsed": true
146-
},
136+
"metadata": {},
147137
"outputs": [],
148138
"source": [
149139
"knowledge_base.extend([\n",
@@ -163,9 +153,7 @@
163153
{
164154
"cell_type": "code",
165155
"execution_count": 6,
166-
"metadata": {
167-
"collapsed": false
168-
},
156+
"metadata": {},
169157
"outputs": [
170158
{
171159
"data": {
@@ -203,9 +191,7 @@
203191
{
204192
"cell_type": "code",
205193
"execution_count": 7,
206-
"metadata": {
207-
"collapsed": false
208-
},
194+
"metadata": {},
209195
"outputs": [],
210196
"source": [
211197
"#Sibiu to Bucharest\n",
@@ -261,9 +247,7 @@
261247
{
262248
"cell_type": "code",
263249
"execution_count": 8,
264-
"metadata": {
265-
"collapsed": true
266-
},
250+
"metadata": {},
267251
"outputs": [],
268252
"source": [
269253
"#Drive\n",
@@ -284,9 +268,7 @@
284268
{
285269
"cell_type": "code",
286270
"execution_count": 9,
287-
"metadata": {
288-
"collapsed": true
289-
},
271+
"metadata": {},
290272
"outputs": [],
291273
"source": [
292274
"def goal_test(kb):\n",
@@ -303,31 +285,119 @@
303285
{
304286
"cell_type": "code",
305287
"execution_count": 10,
306-
"metadata": {
307-
"collapsed": false
308-
},
288+
"metadata": {},
309289
"outputs": [],
310290
"source": [
311291
"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)"
312292
]
313293
},
294+
{
295+
"cell_type": "markdown",
296+
"metadata": {},
297+
"source": [
298+
"# Air Cargo Problem:"
299+
]
300+
},
301+
{
302+
"cell_type": "markdown",
303+
"metadata": {},
304+
"source": [
305+
"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:"
306+
]
307+
},
314308
{
315309
"cell_type": "code",
316-
"execution_count": null,
317-
"metadata": {
318-
"collapsed": false
319-
},
310+
"execution_count": 15,
311+
"metadata": {},
320312
"outputs": [],
321-
"source": []
313+
"source": [
314+
"airCargo = air_cargo()"
315+
]
316+
},
317+
{
318+
"cell_type": "markdown",
319+
"metadata": {},
320+
"source": [
321+
"Now, before taking any actions, we will check the `airCargo` if it has completed the goal it is required to do:"
322+
]
323+
},
324+
{
325+
"cell_type": "code",
326+
"execution_count": 16,
327+
"metadata": {},
328+
"outputs": [
329+
{
330+
"name": "stdout",
331+
"output_type": "stream",
332+
"text": [
333+
"False\n"
334+
]
335+
}
336+
],
337+
"source": [
338+
"print(airCargo.goal_test())"
339+
]
340+
},
341+
{
342+
"cell_type": "markdown",
343+
"metadata": {},
344+
"source": [
345+
"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",
346+
"the goal. Then the `airCargo` acts on each of them."
347+
]
348+
},
349+
{
350+
"cell_type": "code",
351+
"execution_count": 17,
352+
"metadata": {},
353+
"outputs": [],
354+
"source": [
355+
"solution = [expr(\"Load(C1 , P1, SFO)\"),\n",
356+
" expr(\"Fly(P1, SFO, JFK)\"),\n",
357+
" expr(\"Unload(C1, P1, JFK)\"),\n",
358+
" expr(\"Load(C2, P2, JFK)\"),\n",
359+
" expr(\"Fly(P2, JFK, SFO)\"),\n",
360+
" expr(\"Unload (C2, P2, SFO)\")] \n",
361+
"\n",
362+
"for action in solution:\n",
363+
" airCargo.act(action)"
364+
]
365+
},
366+
{
367+
"cell_type": "markdown",
368+
"metadata": {},
369+
"source": [
370+
"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:"
371+
]
372+
},
373+
{
374+
"cell_type": "code",
375+
"execution_count": 18,
376+
"metadata": {},
377+
"outputs": [
378+
{
379+
"data": {
380+
"text/plain": [
381+
"True"
382+
]
383+
},
384+
"execution_count": 18,
385+
"metadata": {},
386+
"output_type": "execute_result"
387+
}
388+
],
389+
"source": [
390+
"airCargo.goal_test()"
391+
]
322392
},
323393
{
324394
"cell_type": "code",
325395
"execution_count": null,
326-
"metadata": {
327-
"collapsed": true
328-
},
396+
"metadata": {},
329397
"outputs": [],
330-
"source": []
398+
"source": [
399+
"It has now achieved its goal."
400+
]
331401
}
332402
],
333403
"metadata": {
@@ -346,9 +416,9 @@
346416
"name": "python",
347417
"nbconvert_exporter": "python",
348418
"pygments_lexer": "ipython3",
349-
"version": "3.4.3"
419+
"version": "3.6.4"
350420
}
351421
},
352422
"nbformat": 4,
353-
"nbformat_minor": 0
423+
"nbformat_minor": 1
354424
}

0 commit comments

Comments
 (0)