Skip to content

Added air_cargo to planning.ipynb #835

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 14, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Here is a table of algorithms, the figure, name of the algorithm in the book and
| 9.3 | FOL-FC-Ask | `fol_fc_ask` | [`logic.py`][logic] | Done | |
| 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 | |
| 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.7 | Cake-Problem | `have_cake_and_eat_cake_too` | [`planning.py`][planning] | Done | |
Expand Down
195 changes: 144 additions & 51 deletions planning.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,8 @@
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"collapsed": false
},
"execution_count": 9,
"metadata": {},
"outputs": [],
"source": [
"from planning import *"
Expand All @@ -50,10 +48,8 @@
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"collapsed": false
},
"execution_count": 10,
"metadata": {},
"outputs": [],
"source": [
"%psource Action"
Expand Down Expand Up @@ -82,10 +78,8 @@
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {
"collapsed": false
},
"execution_count": 11,
"metadata": {},
"outputs": [],
"source": [
"%psource PDDL"
Expand All @@ -109,10 +103,8 @@
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"collapsed": false
},
"execution_count": 12,
"metadata": {},
"outputs": [],
"source": [
"from utils import *\n",
Expand Down Expand Up @@ -140,10 +132,8 @@
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {
"collapsed": true
},
"execution_count": 13,
"metadata": {},
"outputs": [],
"source": [
"knowledge_base.extend([\n",
Expand All @@ -162,10 +152,8 @@
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {
"collapsed": false
},
"execution_count": 14,
"metadata": {},
"outputs": [
{
"data": {
Expand All @@ -182,7 +170,7 @@
" At(Sibiu)]"
]
},
"execution_count": 6,
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
Expand All @@ -202,10 +190,8 @@
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"collapsed": false
},
"execution_count": 15,
"metadata": {},
"outputs": [],
"source": [
"#Sibiu to Bucharest\n",
Expand Down Expand Up @@ -260,10 +246,8 @@
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {
"collapsed": true
},
"execution_count": 16,
"metadata": {},
"outputs": [],
"source": [
"#Drive\n",
Expand All @@ -283,10 +267,8 @@
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {
"collapsed": true
},
"execution_count": 17,
"metadata": {},
"outputs": [],
"source": [
"def goal_test(kb):\n",
Expand All @@ -302,30 +284,141 @@
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {
"collapsed": false
},
"execution_count": 18,
"metadata": {},
"outputs": [],
"source": [
"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)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Air Cargo Problem:"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
" 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."
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should remove the extra space before the sentence

]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"execution_count": 2,
"metadata": {},
"outputs": [
{
"ename": "SyntaxError",
"evalue": "can't use starred expression here (<ipython-input-2-a15fe137afb2>, line 1)",
"output_type": "error",
"traceback": [
"\u001b[1;36m File \u001b[1;32m\"<ipython-input-2-a15fe137afb2>\"\u001b[1;36m, line \u001b[1;32m1\u001b[0m\n\u001b[1;33m *psource(air_cargo)\u001b[0m\n\u001b[1;37m ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m can't use starred expression here\n"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct the error in this cell

]
}
],
"source": [
"*psource(air_cargo)"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove the asterisk before psource and execute the cell. This is the cause of the erroneous output.

]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Let us now define an object of `air_cargo` problem:"
]
},
{
"cell_type": "code",
"execution_count": 19,
"metadata": {},
"outputs": [],
"source": []
"source": [
"airCargo = air_cargo()"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Now, before taking any actions, we will check the `airCargo` if it has completed the goal it is required to do:"
]
},
{
"cell_type": "code",
"execution_count": 20,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"False\n"
]
}
],
"source": [
"print(airCargo.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 achieve\n",
"the goal. Then the `airCargo` acts on each of them."
]
},
{
"cell_type": "code",
"execution_count": 21,
"metadata": {},
"outputs": [],
"source": [
"solution = [expr(\"Load(C1 , P1, SFO)\"),\n",
" expr(\"Fly(P1, SFO, JFK)\"),\n",
" expr(\"Unload(C1, P1, JFK)\"),\n",
" expr(\"Load(C2, P2, JFK)\"),\n",
" expr(\"Fly(P2, JFK, SFO)\"),\n",
" expr(\"Unload (C2, P2, SFO)\")] \n",
"\n",
"for action in solution:\n",
" airCargo.act(action)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"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:"
]
},
{
"cell_type": "code",
"execution_count": 22,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"True"
]
},
"execution_count": 22,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"airCargo.goal_test()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"metadata": {},
"outputs": [],
"source": []
}
Expand All @@ -346,9 +439,9 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.4.3"
"version": "3.6.4"
}
},
"nbformat": 4,
"nbformat_minor": 0
"nbformat_minor": 1
}
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy