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

Skip to content

Commit d30f77d

Browse files
nouman-10norvig
authored andcommitted
Added sections on learning.ipynb (aimacode#851)
1 parent ccd620d commit d30f77d

File tree

2 files changed

+205
-9
lines changed

2 files changed

+205
-9
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ Here is a table of algorithms, the figure, name of the algorithm in the book and
109109
| 9.6 | FOL-BC-Ask | `fol_bc_ask` | [`logic.py`][logic] | Done | |
110110
| 9.8 | Append | | | | |
111111
| 10.1 | Air-Cargo-problem | `air_cargo` | [`planning.py`][planning] | Done | Included |
112-
| 10.2 | Spare-Tire-Problem | `spare_tire` | [`planning.py`][planning] | Done | |
113-
| 10.3 | Three-Block-Tower | `three_block_tower` | [`planning.py`][planning] | Done | |
112+
| 10.2 | Spare-Tire-Problem | `spare_tire` | [`planning.py`][planning] | Done | Included |
113+
| 10.3 | Three-Block-Tower | `three_block_tower` | [`planning.py`][planning] | Done | Included |
114114
| 10.7 | Cake-Problem | `have_cake_and_eat_cake_too` | [`planning.py`][planning] | Done | |
115115
| 10.9 | Graphplan | `GraphPlan` | [`planning.py`][planning] | | |
116116
| 10.13 | Partial-Order-Planner | | | | |

planning.ipynb

Lines changed: 203 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@
307307
},
308308
{
309309
"cell_type": "code",
310-
"execution_count": 15,
310+
"execution_count": 11,
311311
"metadata": {},
312312
"outputs": [],
313313
"source": [
@@ -323,7 +323,7 @@
323323
},
324324
{
325325
"cell_type": "code",
326-
"execution_count": 16,
326+
"execution_count": 12,
327327
"metadata": {},
328328
"outputs": [
329329
{
@@ -348,7 +348,7 @@
348348
},
349349
{
350350
"cell_type": "code",
351-
"execution_count": 17,
351+
"execution_count": 13,
352352
"metadata": {},
353353
"outputs": [],
354354
"source": [
@@ -372,7 +372,7 @@
372372
},
373373
{
374374
"cell_type": "code",
375-
"execution_count": 18,
375+
"execution_count": 14,
376376
"metadata": {},
377377
"outputs": [
378378
{
@@ -381,7 +381,7 @@
381381
"True"
382382
]
383383
},
384-
"execution_count": 18,
384+
"execution_count": 14,
385385
"metadata": {},
386386
"output_type": "execute_result"
387387
}
@@ -390,13 +390,209 @@
390390
"airCargo.goal_test()"
391391
]
392392
},
393+
{
394+
"cell_type": "markdown",
395+
"metadata": {},
396+
"source": [
397+
"It has now achieved its goal."
398+
]
399+
},
400+
{
401+
"cell_type": "markdown",
402+
"metadata": {},
403+
"source": [
404+
"## The Spare Tire Problem"
405+
]
406+
},
407+
{
408+
"cell_type": "markdown",
409+
"metadata": {},
410+
"source": [
411+
"Let's consider the problem of changing a flat tire. The goal is to have a good spare tire properly mounted onto the car's axle, where the initial state has a flat tire on the axle and a good spare tire in the trunk. Let us now define an object of `spare_tire` problem:"
412+
]
413+
},
393414
{
394415
"cell_type": "code",
395-
"execution_count": null,
416+
"execution_count": 15,
396417
"metadata": {},
397418
"outputs": [],
398419
"source": [
399-
"It has now achieved its goal."
420+
"spare_tire = spare_tire()"
421+
]
422+
},
423+
{
424+
"cell_type": "markdown",
425+
"metadata": {},
426+
"source": [
427+
"Now, before taking any actions, we will check `spare_tire` if it has completed the goal it is required to do"
428+
]
429+
},
430+
{
431+
"cell_type": "code",
432+
"execution_count": 16,
433+
"metadata": {},
434+
"outputs": [
435+
{
436+
"name": "stdout",
437+
"output_type": "stream",
438+
"text": [
439+
"False\n"
440+
]
441+
}
442+
],
443+
"source": [
444+
"print(spare_tire.goal_test())"
445+
]
446+
},
447+
{
448+
"cell_type": "markdown",
449+
"metadata": {},
450+
"source": [
451+
"As we can see, it hasn't completed the goal. Now, we define the sequence of actions that it should take in order to have a good spare tire properly mounted onto the car's axle. Then the `spare_tire` acts on each of them."
452+
]
453+
},
454+
{
455+
"cell_type": "code",
456+
"execution_count": 17,
457+
"metadata": {},
458+
"outputs": [],
459+
"source": [
460+
"solution = [expr(\"Remove(Flat, Axle)\"),\n",
461+
" expr(\"Remove(Spare, Trunk)\"),\n",
462+
" expr(\"PutOn(Spare, Axle)\")]\n",
463+
"\n",
464+
"for action in solution:\n",
465+
" spare_tire.act(action)"
466+
]
467+
},
468+
{
469+
"cell_type": "markdown",
470+
"metadata": {},
471+
"source": [
472+
"As the `spare_tire` has taken all the steps it needed in order to achieve the goal, we can now check if it has acheived its goal"
473+
]
474+
},
475+
{
476+
"cell_type": "code",
477+
"execution_count": 18,
478+
"metadata": {},
479+
"outputs": [
480+
{
481+
"name": "stdout",
482+
"output_type": "stream",
483+
"text": [
484+
"True\n"
485+
]
486+
}
487+
],
488+
"source": [
489+
"print(spare_tire.goal_test())"
490+
]
491+
},
492+
{
493+
"cell_type": "markdown",
494+
"metadata": {},
495+
"source": [
496+
"It has now successfully achieved its goal i.e, to have a good spare tire properly mounted onto the car's axle."
497+
]
498+
},
499+
{
500+
"cell_type": "markdown",
501+
"metadata": {},
502+
"source": [
503+
"## Three Block Tower Problem"
504+
]
505+
},
506+
{
507+
"cell_type": "markdown",
508+
"metadata": {},
509+
"source": [
510+
"This problem's domain consists of a set of cube-shaped blocks sitting on a table. The blocks can be stacked , but only one block can fit directly on top of another. A robot arm can pick up a block and move it to another position, either on the table or on top of another block. The arm can pick up only one block at a time, so it cannot pick up a block that has another one on it. The goal will always be to build one or more stacks of blocks. In our case, we consider only three blocks. Let us now define an object of `three_block_tower` problem:"
511+
]
512+
},
513+
{
514+
"cell_type": "code",
515+
"execution_count": 19,
516+
"metadata": {},
517+
"outputs": [],
518+
"source": [
519+
"three_block_tower = three_block_tower()"
520+
]
521+
},
522+
{
523+
"cell_type": "markdown",
524+
"metadata": {},
525+
"source": [
526+
"Now, before taking any actions, we will check `three_tower_block` if it has completed the goal it is required to do"
527+
]
528+
},
529+
{
530+
"cell_type": "code",
531+
"execution_count": 21,
532+
"metadata": {},
533+
"outputs": [
534+
{
535+
"name": "stdout",
536+
"output_type": "stream",
537+
"text": [
538+
"False\n"
539+
]
540+
}
541+
],
542+
"source": [
543+
"print(three_block_tower.goal_test())"
544+
]
545+
},
546+
{
547+
"cell_type": "markdown",
548+
"metadata": {},
549+
"source": [
550+
"As we can see, it hasn't completed the goal. Now, we define the sequence of actions that it should take in order to build a stack of three blocks. Then the `three_block_tower` acts on each of them."
551+
]
552+
},
553+
{
554+
"cell_type": "code",
555+
"execution_count": 22,
556+
"metadata": {},
557+
"outputs": [],
558+
"source": [
559+
"solution = [expr(\"MoveToTable(C, A)\"),\n",
560+
" expr(\"Move(B, Table, C)\"),\n",
561+
" expr(\"Move(A, Table, B)\")]\n",
562+
"\n",
563+
"for action in solution:\n",
564+
" three_block_tower.act(action)"
565+
]
566+
},
567+
{
568+
"cell_type": "markdown",
569+
"metadata": {},
570+
"source": [
571+
"As the `three_block_tower` has taken all the steps it needed in order to achieve the goal, we can now check if it has acheived its goal"
572+
]
573+
},
574+
{
575+
"cell_type": "code",
576+
"execution_count": 24,
577+
"metadata": {},
578+
"outputs": [
579+
{
580+
"name": "stdout",
581+
"output_type": "stream",
582+
"text": [
583+
"True\n"
584+
]
585+
}
586+
],
587+
"source": [
588+
"print(three_block_tower.goal_test())"
589+
]
590+
},
591+
{
592+
"cell_type": "markdown",
593+
"metadata": {},
594+
"source": [
595+
"It has now successfully achieved its goal i.e, to build a stack of three blocks."
400596
]
401597
}
402598
],

0 commit comments

Comments
 (0)