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..5c26e5b5e 100644 --- a/planning.ipynb +++ b/planning.ipynb @@ -307,7 +307,7 @@ }, { "cell_type": "code", - "execution_count": 15, + "execution_count": 11, "metadata": {}, "outputs": [], "source": [ @@ -323,7 +323,7 @@ }, { "cell_type": "code", - "execution_count": 16, + "execution_count": 12, "metadata": {}, "outputs": [ { @@ -348,7 +348,7 @@ }, { "cell_type": "code", - "execution_count": 17, + "execution_count": 13, "metadata": {}, "outputs": [], "source": [ @@ -372,7 +372,7 @@ }, { "cell_type": "code", - "execution_count": 18, + "execution_count": 14, "metadata": {}, "outputs": [ { @@ -381,7 +381,7 @@ "True" ] }, - "execution_count": 18, + "execution_count": 14, "metadata": {}, "output_type": "execute_result" } @@ -390,13 +390,209 @@ "airCargo.goal_test()" ] }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It has now achieved its goal." + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "## The Spare Tire Problem" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "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:" + ] + }, { "cell_type": "code", - "execution_count": null, + "execution_count": 15, "metadata": {}, "outputs": [], "source": [ - "It has now achieved its goal." + "spare_tire = spare_tire()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now, before taking any actions, we will check `spare_tire` 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(spare_tire.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 have a good spare tire properly mounted onto the car's axle. Then the `spare_tire` acts on each of them." + ] + }, + { + "cell_type": "code", + "execution_count": 17, + "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", + " spare_tire.act(action)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "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" + ] + }, + { + "cell_type": "code", + "execution_count": 18, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "print(spare_tire.goal_test())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It has now successfully achieved its goal i.e, to have a good spare tire properly 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 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:" + ] + }, + { + "cell_type": "code", + "execution_count": 19, + "metadata": {}, + "outputs": [], + "source": [ + "three_block_tower = three_block_tower()" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "Now, before taking any actions, we will check `three_tower_block` if it has completed the goal it is required to do" + ] + }, + { + "cell_type": "code", + "execution_count": 21, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "False\n" + ] + } + ], + "source": [ + "print(three_block_tower.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 build a stack of three blocks. Then the `three_block_tower` acts on each of them." + ] + }, + { + "cell_type": "code", + "execution_count": 22, + "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", + " three_block_tower.act(action)" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "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" + ] + }, + { + "cell_type": "code", + "execution_count": 24, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "True\n" + ] + } + ], + "source": [ + "print(three_block_tower.goal_test())" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "It has now successfully achieved its goal i.e, to build a stack of three blocks." ] } ],