diff --git a/README.md b/README.md index a793deb30..78378bdf8 100644 --- a/README.md +++ b/README.md @@ -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 | | diff --git a/planning.ipynb b/planning.ipynb index 1054f1ee8..ca648a3a0 100644 --- a/planning.ipynb +++ b/planning.ipynb @@ -23,9 +23,7 @@ { "cell_type": "code", "execution_count": 1, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "from planning import *" @@ -51,9 +49,7 @@ { "cell_type": "code", "execution_count": 2, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "%psource Action" @@ -83,9 +79,7 @@ { "cell_type": "code", "execution_count": 3, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "%psource PDDL" @@ -110,9 +104,7 @@ { "cell_type": "code", "execution_count": 4, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "from utils import *\n", @@ -141,9 +133,7 @@ { "cell_type": "code", "execution_count": 5, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "knowledge_base.extend([\n", @@ -163,9 +153,7 @@ { "cell_type": "code", "execution_count": 6, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [ { "data": { @@ -203,9 +191,7 @@ { "cell_type": "code", "execution_count": 7, - "metadata": { - "collapsed": false - }, + "metadata": {}, "outputs": [], "source": [ "#Sibiu to Bucharest\n", @@ -261,9 +247,7 @@ { "cell_type": "code", "execution_count": 8, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "#Drive\n", @@ -284,9 +268,7 @@ { "cell_type": "code", "execution_count": 9, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], "source": [ "def goal_test(kb):\n", @@ -303,31 +285,119 @@ { "cell_type": "code", "execution_count": 10, - "metadata": { - "collapsed": false - }, + "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. Let us now define an object of `air_cargo` problem:" + ] + }, { "cell_type": "code", - "execution_count": null, - "metadata": { - "collapsed": false - }, + "execution_count": 15, + "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": 16, + "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": 17, + "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": 18, + "metadata": {}, + "outputs": [ + { + "data": { + "text/plain": [ + "True" + ] + }, + "execution_count": 18, + "metadata": {}, + "output_type": "execute_result" + } + ], + "source": [ + "airCargo.goal_test()" + ] }, { "cell_type": "code", "execution_count": null, - "metadata": { - "collapsed": true - }, + "metadata": {}, "outputs": [], - "source": [] + "source": [ + "It has now achieved its goal." + ] } ], "metadata": { @@ -346,9 +416,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 }
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: