From 00838b10dd4e5fff902231dbe777b49a46f657df Mon Sep 17 00:00:00 2001 From: Noumanmufc1 Date: Fri, 16 Mar 2018 00:06:20 +0500 Subject: [PATCH] Added sections in learning.ipynb --- README.md | 4 +- planning.ipynb | 246 +++++++++++++++++++++++++++++++++++++++++++++---- 2 files changed, 230 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 4b8b4528f..91efcde94 100644 --- a/README.md +++ b/README.md @@ -109,8 +109,8 @@ Here is a table of algorithms, the figure, name of the algorithm in the book and | 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 | 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.2 | Spare-Tire-Problem | `spare_tire` | [`planning.py`][planning] | Done | Included | +| 10.3 | Three-Block-Tower | `three_block_tower` | [`planning.py`][planning] | Done | Included | | 10.7 | Cake-Problem | `have_cake_and_eat_cake_too` | [`planning.py`][planning] | Done | | | 10.9 | Graphplan | `GraphPlan` | [`planning.py`][planning] | | | | 10.13 | Partial-Order-Planner | | | | | diff --git a/planning.ipynb b/planning.ipynb index ca648a3a0..6e1940ced 100644 --- a/planning.ipynb +++ b/planning.ipynb @@ -22,7 +22,7 @@ }, { "cell_type": "code", - "execution_count": 1, + "execution_count": 29, "metadata": {}, "outputs": [], "source": [ @@ -48,7 +48,7 @@ }, { "cell_type": "code", - "execution_count": 2, + "execution_count": 30, "metadata": {}, "outputs": [], "source": [ @@ -78,7 +78,7 @@ }, { "cell_type": "code", - "execution_count": 3, + "execution_count": 31, "metadata": {}, "outputs": [], "source": [ @@ -103,7 +103,7 @@ }, { "cell_type": "code", - "execution_count": 4, + "execution_count": 32, "metadata": {}, "outputs": [], "source": [ @@ -132,7 +132,7 @@ }, { "cell_type": "code", - "execution_count": 5, + "execution_count": 33, "metadata": {}, "outputs": [], "source": [ @@ -152,7 +152,7 @@ }, { "cell_type": "code", - "execution_count": 6, + "execution_count": 34, "metadata": {}, "outputs": [ { @@ -170,7 +170,7 @@ " At(Sibiu)]" ] }, - "execution_count": 6, + "execution_count": 34, "metadata": {}, "output_type": "execute_result" } @@ -190,7 +190,7 @@ }, { "cell_type": "code", - "execution_count": 7, + "execution_count": 35, "metadata": {}, "outputs": [], "source": [ @@ -246,7 +246,7 @@ }, { "cell_type": "code", - "execution_count": 8, + "execution_count": 36, "metadata": {}, "outputs": [], "source": [ @@ -267,7 +267,7 @@ }, { "cell_type": "code", - "execution_count": 9, + "execution_count": 37, "metadata": {}, "outputs": [], "source": [ @@ -284,7 +284,7 @@ }, { "cell_type": "code", - "execution_count": 10, + "execution_count": 38, "metadata": {}, "outputs": [], "source": [ @@ -307,7 +307,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 39, "metadata": {}, "outputs": [], "source": [ @@ -323,7 +323,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 40, "metadata": {}, "outputs": [ { @@ -348,7 +348,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 41, "metadata": {}, "outputs": [], "source": [ @@ -372,7 +372,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 42, "metadata": {}, "outputs": [ { @@ -381,7 +381,7 @@ "True" ] }, - "execution_count": 18, + "execution_count": 42, "metadata": {}, "output_type": "execute_result" } @@ -390,14 +390,224 @@ "airCargo.goal_test()" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It has now achieved its goal." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Spare Tire Problem:\n" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It is basically the problem of changing a flat tire. The goal is to have a \n", + "good spare tire properly mounted onto the car's axle, where the initial state \n", + "has a flat tire on the axle and a good spare tire in the trunk. Let us now \n", + "define an object of `spare-tire` problem:" + ] + }, { "cell_type": "code", - "execution_count": null, + "execution_count": 43, "metadata": {}, "outputs": [], "source": [ - "It has now achieved its goal." + "spareTire = spare_tire()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now, before taking any actions, we will check the `spareTire` if it has \n", + "completed the goal it is required to do:" + ] + }, + { + "cell_type": "code", + "execution_count": 44, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n" + ] + } + ], + "source": [ + "print(spareTire.goal_test())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As we can see, it hasn't completed the goal. Now, we define the sequence of\n", + "actions that it should take in order to mount the spare tire onto the car's axle. Then the `spareTire` acts on each of them." + ] + }, + { + "cell_type": "code", + "execution_count": 45, + "metadata": {}, + "outputs": [], + "source": [ + "solution = [expr(\"Remove(Flat, Axle)\"),\n", + " expr(\"Remove(Spare, Trunk)\"),\n", + " expr(\"PutOn(Spare, Axle)\")]\n", + "\n", + "for action in solution:\n", + " spareTire.act(action)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As the `spareTire` 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": 46, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "print(spareTire.goal_test())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It has now successfully achieved its goal i.e, to have a good spare tire mounted onto the car's axle" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## Three Block Tower Problem:" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "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 can't 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, the number of blocks are three. Let's start by defining an object of `three_block_tower` problem:" + ] + }, + { + "cell_type": "code", + "execution_count": 47, + "metadata": {}, + "outputs": [], + "source": [ + "threeBlockTower = three_block_tower()" ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now, before taking any actions, we will check the `threeBlockTower` if it has \n", + "completed the goal it is required to do:" + ] + }, + { + "cell_type": "code", + "execution_count": 48, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n" + ] + } + ], + "source": [ + "print(threeBlockTower.goal_test())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As we can see, it hasn't completed the goal. Now, we define the sequence of\n", + "actions that it should take in order to build a stack of three blocks. Then the `threeBlockTower` acts on each of them." + ] + }, + { + "cell_type": "code", + "execution_count": 49, + "metadata": {}, + "outputs": [], + "source": [ + "solution = [expr(\"MoveToTable(C, A)\"),\n", + " expr(\"Move(B, Table, C)\"),\n", + " expr(\"Move(A, Table, B)\")]\n", + "\n", + "for action in solution:\n", + " threeBlockTower.act(action)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "As the `threeBlockTower` 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": 50, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "print(threeBlockTower.goal_test())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It has now successfully achieved its goal i.e, to build a stack of three blocks." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] } ], "metadata": {