Skip to content

Commit

Permalink
Added sections in learning.ipynb
Browse files Browse the repository at this point in the history
  • Loading branch information
nouman-10 committed Mar 15, 2018
1 parent 651cf66 commit 00838b1
Show file tree
Hide file tree
Showing 2 changed files with 230 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -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 | | | | |
Expand Down
246 changes: 228 additions & 18 deletions planning.ipynb
Expand Up @@ -22,7 +22,7 @@
},
{
"cell_type": "code",
"execution_count": 1,
"execution_count": 29,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -48,7 +48,7 @@
},
{
"cell_type": "code",
"execution_count": 2,
"execution_count": 30,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -78,7 +78,7 @@
},
{
"cell_type": "code",
"execution_count": 3,
"execution_count": 31,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -103,7 +103,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 32,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -132,7 +132,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 33,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -152,7 +152,7 @@
},
{
"cell_type": "code",
"execution_count": 6,
"execution_count": 34,
"metadata": {},
"outputs": [
{
Expand All @@ -170,7 +170,7 @@
" At(Sibiu)]"
]
},
"execution_count": 6,
"execution_count": 34,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -190,7 +190,7 @@
},
{
"cell_type": "code",
"execution_count": 7,
"execution_count": 35,
"metadata": {},
"outputs": [],
"source": [
Expand Down Expand Up @@ -246,7 +246,7 @@
},
{
"cell_type": "code",
"execution_count": 8,
"execution_count": 36,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -267,7 +267,7 @@
},
{
"cell_type": "code",
"execution_count": 9,
"execution_count": 37,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -284,7 +284,7 @@
},
{
"cell_type": "code",
"execution_count": 10,
"execution_count": 38,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -307,7 +307,7 @@
},
{
"cell_type": "code",
"execution_count": 15,
"execution_count": 39,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -323,7 +323,7 @@
},
{
"cell_type": "code",
"execution_count": 16,
"execution_count": 40,
"metadata": {},
"outputs": [
{
Expand All @@ -348,7 +348,7 @@
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 41,
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -372,7 +372,7 @@
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 42,
"metadata": {},
"outputs": [
{
Expand All @@ -381,7 +381,7 @@
"True"
]
},
"execution_count": 18,
"execution_count": 42,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -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": {
Expand Down

0 comments on commit 00838b1

Please sign in to comment.