planning.ipynb 397 ko
Newer Older
   "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 of a car. \n",
    "The goal is to mount a spare tire onto the car's axle, given that we have a flat tire on the axle and a spare tire in the trunk. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n",
       "   \"http://www.w3.org/TR/html4/strict.dtd\">\n",
       "\n",
       "<html>\n",
       "<head>\n",
       "  <title></title>\n",
       "  <meta http-equiv=\"content-type\" content=\"text/html; charset=None\">\n",
       "  <style type=\"text/css\">\n",
       "td.linenos { background-color: #f0f0f0; padding-right: 10px; }\n",
       "span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }\n",
       "pre { line-height: 125%; }\n",
       "body .hll { background-color: #ffffcc }\n",
       "body  { background: #f8f8f8; }\n",
       "body .c { color: #408080; font-style: italic } /* Comment */\n",
       "body .err { border: 1px solid #FF0000 } /* Error */\n",
       "body .k { color: #008000; font-weight: bold } /* Keyword */\n",
       "body .o { color: #666666 } /* Operator */\n",
       "body .ch { color: #408080; font-style: italic } /* Comment.Hashbang */\n",
       "body .cm { color: #408080; font-style: italic } /* Comment.Multiline */\n",
       "body .cp { color: #BC7A00 } /* Comment.Preproc */\n",
       "body .cpf { color: #408080; font-style: italic } /* Comment.PreprocFile */\n",
       "body .c1 { color: #408080; font-style: italic } /* Comment.Single */\n",
       "body .cs { color: #408080; font-style: italic } /* Comment.Special */\n",
       "body .gd { color: #A00000 } /* Generic.Deleted */\n",
       "body .ge { font-style: italic } /* Generic.Emph */\n",
       "body .gr { color: #FF0000 } /* Generic.Error */\n",
       "body .gh { color: #000080; font-weight: bold } /* Generic.Heading */\n",
       "body .gi { color: #00A000 } /* Generic.Inserted */\n",
       "body .go { color: #888888 } /* Generic.Output */\n",
       "body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */\n",
       "body .gs { font-weight: bold } /* Generic.Strong */\n",
       "body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */\n",
       "body .gt { color: #0044DD } /* Generic.Traceback */\n",
       "body .kc { color: #008000; font-weight: bold } /* Keyword.Constant */\n",
       "body .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */\n",
       "body .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */\n",
       "body .kp { color: #008000 } /* Keyword.Pseudo */\n",
       "body .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */\n",
       "body .kt { color: #B00040 } /* Keyword.Type */\n",
       "body .m { color: #666666 } /* Literal.Number */\n",
       "body .s { color: #BA2121 } /* Literal.String */\n",
       "body .na { color: #7D9029 } /* Name.Attribute */\n",
       "body .nb { color: #008000 } /* Name.Builtin */\n",
       "body .nc { color: #0000FF; font-weight: bold } /* Name.Class */\n",
       "body .no { color: #880000 } /* Name.Constant */\n",
       "body .nd { color: #AA22FF } /* Name.Decorator */\n",
       "body .ni { color: #999999; font-weight: bold } /* Name.Entity */\n",
       "body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */\n",
       "body .nf { color: #0000FF } /* Name.Function */\n",
       "body .nl { color: #A0A000 } /* Name.Label */\n",
       "body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */\n",
       "body .nt { color: #008000; font-weight: bold } /* Name.Tag */\n",
       "body .nv { color: #19177C } /* Name.Variable */\n",
       "body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */\n",
       "body .w { color: #bbbbbb } /* Text.Whitespace */\n",
       "body .mb { color: #666666 } /* Literal.Number.Bin */\n",
       "body .mf { color: #666666 } /* Literal.Number.Float */\n",
       "body .mh { color: #666666 } /* Literal.Number.Hex */\n",
       "body .mi { color: #666666 } /* Literal.Number.Integer */\n",
       "body .mo { color: #666666 } /* Literal.Number.Oct */\n",
       "body .sa { color: #BA2121 } /* Literal.String.Affix */\n",
       "body .sb { color: #BA2121 } /* Literal.String.Backtick */\n",
       "body .sc { color: #BA2121 } /* Literal.String.Char */\n",
       "body .dl { color: #BA2121 } /* Literal.String.Delimiter */\n",
       "body .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */\n",
       "body .s2 { color: #BA2121 } /* Literal.String.Double */\n",
       "body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */\n",
       "body .sh { color: #BA2121 } /* Literal.String.Heredoc */\n",
       "body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */\n",
       "body .sx { color: #008000 } /* Literal.String.Other */\n",
       "body .sr { color: #BB6688 } /* Literal.String.Regex */\n",
       "body .s1 { color: #BA2121 } /* Literal.String.Single */\n",
       "body .ss { color: #19177C } /* Literal.String.Symbol */\n",
       "body .bp { color: #008000 } /* Name.Builtin.Pseudo */\n",
       "body .fm { color: #0000FF } /* Name.Function.Magic */\n",
       "body .vc { color: #19177C } /* Name.Variable.Class */\n",
       "body .vg { color: #19177C } /* Name.Variable.Global */\n",
       "body .vi { color: #19177C } /* Name.Variable.Instance */\n",
       "body .vm { color: #19177C } /* Name.Variable.Magic */\n",
       "body .il { color: #666666 } /* Literal.Number.Integer.Long */\n",
       "\n",
       "  </style>\n",
       "</head>\n",
       "<body>\n",
       "<h2></h2>\n",
       "\n",
       "<div class=\"highlight\"><pre><span></span><span class=\"k\">def</span> <span class=\"nf\">spare_tire</span><span class=\"p\">():</span>\n",
       "    <span class=\"sd\">&quot;&quot;&quot;[Figure 10.2] SPARE-TIRE-PROBLEM</span>\n",
       "\n",
       "<span class=\"sd\">    A problem involving changing the flat tire of a car</span>\n",
       "<span class=\"sd\">    with a spare tire from the trunk.</span>\n",
       "\n",
       "<span class=\"sd\">    Example:</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; from planning import *</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; st = spare_tire()</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; st.goal_test()</span>\n",
       "<span class=\"sd\">    False</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; st.act(expr(&#39;Remove(Spare, Trunk)&#39;))</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; st.act(expr(&#39;Remove(Flat, Axle)&#39;))</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; st.goal_test()</span>\n",
       "<span class=\"sd\">    False</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; st.act(expr(&#39;PutOn(Spare, Axle)&#39;))</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; st.goal_test()</span>\n",
       "<span class=\"sd\">    True</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt;</span>\n",
       "<span class=\"sd\">    &quot;&quot;&quot;</span>\n",
       "    <span class=\"k\">return</span> <span class=\"n\">PlanningProblem</span><span class=\"p\">(</span><span class=\"n\">init</span><span class=\"o\">=</span><span class=\"s1\">&#39;Tire(Flat) &amp; Tire(Spare) &amp; At(Flat, Axle) &amp; At(Spare, Trunk)&#39;</span><span class=\"p\">,</span>\n",
       "                <span class=\"n\">goals</span><span class=\"o\">=</span><span class=\"s1\">&#39;At(Spare, Axle) &amp; At(Flat, Ground)&#39;</span><span class=\"p\">,</span>\n",
       "                <span class=\"n\">actions</span><span class=\"o\">=</span><span class=\"p\">[</span><span class=\"n\">Action</span><span class=\"p\">(</span><span class=\"s1\">&#39;Remove(obj, loc)&#39;</span><span class=\"p\">,</span>\n",
       "                                <span class=\"n\">precond</span><span class=\"o\">=</span><span class=\"s1\">&#39;At(obj, loc)&#39;</span><span class=\"p\">,</span>\n",
       "                                <span class=\"n\">effect</span><span class=\"o\">=</span><span class=\"s1\">&#39;At(obj, Ground) &amp; ~At(obj, loc)&#39;</span><span class=\"p\">),</span>\n",
       "                         <span class=\"n\">Action</span><span class=\"p\">(</span><span class=\"s1\">&#39;PutOn(t, Axle)&#39;</span><span class=\"p\">,</span>\n",
       "                                <span class=\"n\">precond</span><span class=\"o\">=</span><span class=\"s1\">&#39;Tire(t) &amp; At(t, Ground) &amp; ~At(Flat, Axle)&#39;</span><span class=\"p\">,</span>\n",
       "                                <span class=\"n\">effect</span><span class=\"o\">=</span><span class=\"s1\">&#39;At(t, Axle) &amp; ~At(t, Ground)&#39;</span><span class=\"p\">),</span>\n",
       "                         <span class=\"n\">Action</span><span class=\"p\">(</span><span class=\"s1\">&#39;LeaveOvernight&#39;</span><span class=\"p\">,</span>\n",
       "                                <span class=\"n\">precond</span><span class=\"o\">=</span><span class=\"s1\">&#39;&#39;</span><span class=\"p\">,</span>\n",
       "                                <span class=\"n\">effect</span><span class=\"o\">=</span><span class=\"s1\">&#39;~At(Spare, Ground) &amp; ~At(Spare, Axle) &amp; ~At(Spare, Trunk) &amp; </span><span class=\"se\">\\</span>\n",
       "<span class=\"s1\">                                        ~At(Flat, Ground) &amp; ~At(Flat, Axle) &amp; ~At(Flat, Trunk)&#39;</span><span class=\"p\">)])</span>\n",
       "</pre></div>\n",
       "</body>\n",
       "</html>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "psource(spare_tire)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**At(obj, loc):** object **'obj'** is at location **'loc'**.\n",
    "\n",
    "**~At(obj, loc):** object **'obj'** is _not_ at location **'loc'**.\n",
    "\n",
    "**Tire(t):** Declare a tire of type **'t'**.\n",
    "\n",
    "Let us now define an object of `spare_tire` problem:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "spareTire = spare_tire()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Before taking any actions, we will check if `spare_tire` has reached its goal:"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "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. \n",
    "We now define a possible solution that can help us reach the goal of having a spare tire mounted onto the car's axle. \n",
    "The actions are then carried out on the `spareTire` PlanningProblem.\n",
    "\n",
    "The actions available to us are the following: Remove, PutOn\n",
    "\n",
    "**Remove(obj, loc):** Remove the tire **'obj'** from the location **'loc'**.\n",
    "\n",
    "**PutOn(t, Axle):** Attach the tire **'t'** on the Axle.\n",
    "\n",
    "**LeaveOvernight():** We live in a particularly bad neighborhood and all tires, flat or not, are stolen if we leave them overnight.\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": true
   },
   "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": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "print(spareTire.goal_test())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This is a valid solution.\n",
    "<br>\n",
    "Another possible solution is"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {
    "collapsed": true
   },
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
   "outputs": [],
   "source": [
    "spareTire = spare_tire()\n",
    "\n",
    "solution = [expr('Remove(Spare, Trunk)'),\n",
    "            expr('Remove(Flat, Axle)'),\n",
    "            expr('PutOn(Spare, Axle)')]\n",
    "\n",
    "for action in solution:\n",
    "    spareTire.act(action)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
   "source": [
    "print(spareTire.goal_test())"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Notice that both solutions work, which means that the problem can be solved irrespective of the order in which the `Remove` actions take place, as long as both `Remove` actions take place before the `PutOn` action."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "We have successfully mounted a spare tire onto the 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. \n",
    "The blocks can be stacked, but only one block can fit directly on top of another.\n",
    "A robot arm can pick up a block and move it to another position, either on the table or on top of another block. \n",
    "The arm can pick up only one block at a time, so it cannot pick up a block that has another one on it. \n",
    "The goal will always be to build one or more stacks of blocks. \n",
    "In our case, we consider only three blocks.\n",
    "The particular configuration we will use is called the Sussman anomaly after Prof. Gerry Sussman."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Let's take a look at the definition of `three_block_tower()` in the module."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n",
       "   \"http://www.w3.org/TR/html4/strict.dtd\">\n",
       "\n",
       "<html>\n",
       "<head>\n",
       "  <title></title>\n",
       "  <meta http-equiv=\"content-type\" content=\"text/html; charset=None\">\n",
       "  <style type=\"text/css\">\n",
       "td.linenos { background-color: #f0f0f0; padding-right: 10px; }\n",
       "span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }\n",
       "pre { line-height: 125%; }\n",
       "body .hll { background-color: #ffffcc }\n",
       "body  { background: #f8f8f8; }\n",
       "body .c { color: #408080; font-style: italic } /* Comment */\n",
       "body .err { border: 1px solid #FF0000 } /* Error */\n",
       "body .k { color: #008000; font-weight: bold } /* Keyword */\n",
       "body .o { color: #666666 } /* Operator */\n",
       "body .ch { color: #408080; font-style: italic } /* Comment.Hashbang */\n",
       "body .cm { color: #408080; font-style: italic } /* Comment.Multiline */\n",
       "body .cp { color: #BC7A00 } /* Comment.Preproc */\n",
       "body .cpf { color: #408080; font-style: italic } /* Comment.PreprocFile */\n",
       "body .c1 { color: #408080; font-style: italic } /* Comment.Single */\n",
       "body .cs { color: #408080; font-style: italic } /* Comment.Special */\n",
       "body .gd { color: #A00000 } /* Generic.Deleted */\n",
       "body .ge { font-style: italic } /* Generic.Emph */\n",
       "body .gr { color: #FF0000 } /* Generic.Error */\n",
       "body .gh { color: #000080; font-weight: bold } /* Generic.Heading */\n",
       "body .gi { color: #00A000 } /* Generic.Inserted */\n",
       "body .go { color: #888888 } /* Generic.Output */\n",
       "body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */\n",
       "body .gs { font-weight: bold } /* Generic.Strong */\n",
       "body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */\n",
       "body .gt { color: #0044DD } /* Generic.Traceback */\n",
       "body .kc { color: #008000; font-weight: bold } /* Keyword.Constant */\n",
       "body .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */\n",
       "body .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */\n",
       "body .kp { color: #008000 } /* Keyword.Pseudo */\n",
       "body .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */\n",
       "body .kt { color: #B00040 } /* Keyword.Type */\n",
       "body .m { color: #666666 } /* Literal.Number */\n",
       "body .s { color: #BA2121 } /* Literal.String */\n",
       "body .na { color: #7D9029 } /* Name.Attribute */\n",
       "body .nb { color: #008000 } /* Name.Builtin */\n",
       "body .nc { color: #0000FF; font-weight: bold } /* Name.Class */\n",
       "body .no { color: #880000 } /* Name.Constant */\n",
       "body .nd { color: #AA22FF } /* Name.Decorator */\n",
       "body .ni { color: #999999; font-weight: bold } /* Name.Entity */\n",
       "body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */\n",
       "body .nf { color: #0000FF } /* Name.Function */\n",
       "body .nl { color: #A0A000 } /* Name.Label */\n",
       "body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */\n",
       "body .nt { color: #008000; font-weight: bold } /* Name.Tag */\n",
       "body .nv { color: #19177C } /* Name.Variable */\n",
       "body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */\n",
       "body .w { color: #bbbbbb } /* Text.Whitespace */\n",
       "body .mb { color: #666666 } /* Literal.Number.Bin */\n",
       "body .mf { color: #666666 } /* Literal.Number.Float */\n",
       "body .mh { color: #666666 } /* Literal.Number.Hex */\n",
       "body .mi { color: #666666 } /* Literal.Number.Integer */\n",
       "body .mo { color: #666666 } /* Literal.Number.Oct */\n",
       "body .sa { color: #BA2121 } /* Literal.String.Affix */\n",
       "body .sb { color: #BA2121 } /* Literal.String.Backtick */\n",
       "body .sc { color: #BA2121 } /* Literal.String.Char */\n",
       "body .dl { color: #BA2121 } /* Literal.String.Delimiter */\n",
       "body .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */\n",
       "body .s2 { color: #BA2121 } /* Literal.String.Double */\n",
       "body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */\n",
       "body .sh { color: #BA2121 } /* Literal.String.Heredoc */\n",
       "body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */\n",
       "body .sx { color: #008000 } /* Literal.String.Other */\n",
       "body .sr { color: #BB6688 } /* Literal.String.Regex */\n",
       "body .s1 { color: #BA2121 } /* Literal.String.Single */\n",
       "body .ss { color: #19177C } /* Literal.String.Symbol */\n",
       "body .bp { color: #008000 } /* Name.Builtin.Pseudo */\n",
       "body .fm { color: #0000FF } /* Name.Function.Magic */\n",
       "body .vc { color: #19177C } /* Name.Variable.Class */\n",
       "body .vg { color: #19177C } /* Name.Variable.Global */\n",
       "body .vi { color: #19177C } /* Name.Variable.Instance */\n",
       "body .vm { color: #19177C } /* Name.Variable.Magic */\n",
       "body .il { color: #666666 } /* Literal.Number.Integer.Long */\n",
       "\n",
       "  </style>\n",
       "</head>\n",
       "<body>\n",
       "<h2></h2>\n",
       "\n",
       "<div class=\"highlight\"><pre><span></span><span class=\"k\">def</span> <span class=\"nf\">three_block_tower</span><span class=\"p\">():</span>\n",
       "    <span class=\"sd\">&quot;&quot;&quot;</span>\n",
       "<span class=\"sd\">    [Figure 10.3] THREE-BLOCK-TOWER</span>\n",
       "\n",
       "<span class=\"sd\">    A blocks-world problem of stacking three blocks in a certain configuration,</span>\n",
       "<span class=\"sd\">    also known as the Sussman Anomaly.</span>\n",
       "<span class=\"sd\">    Example:</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; from planning import *</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; tbt = three_block_tower()</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; tbt.goal_test()</span>\n",
       "<span class=\"sd\">    False</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; tbt.act(expr(&#39;MoveToTable(C, A)&#39;))</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; tbt.act(expr(&#39;Move(B, Table, C)&#39;))</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; tbt.goal_test()</span>\n",
       "<span class=\"sd\">    False</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; tbt.act(expr(&#39;Move(A, Table, B)&#39;))</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; tbt.goal_test()</span>\n",
       "<span class=\"sd\">    True</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt;</span>\n",
       "<span class=\"sd\">    &quot;&quot;&quot;</span>\n",
       "\n",
       "    <span class=\"k\">return</span> <span class=\"n\">PlanningProblem</span><span class=\"p\">(</span><span class=\"n\">init</span><span class=\"o\">=</span><span class=\"s1\">&#39;On(A, Table) &amp; On(B, Table) &amp; On(C, A) &amp; Block(A) &amp; Block(B) &amp; Block(C) &amp; Clear(B) &amp; Clear(C)&#39;</span><span class=\"p\">,</span>\n",
       "                <span class=\"n\">goals</span><span class=\"o\">=</span><span class=\"s1\">&#39;On(A, B) &amp; On(B, C)&#39;</span><span class=\"p\">,</span>\n",
       "                <span class=\"n\">actions</span><span class=\"o\">=</span><span class=\"p\">[</span><span class=\"n\">Action</span><span class=\"p\">(</span><span class=\"s1\">&#39;Move(b, x, y)&#39;</span><span class=\"p\">,</span>\n",
       "                                <span class=\"n\">precond</span><span class=\"o\">=</span><span class=\"s1\">&#39;On(b, x) &amp; Clear(b) &amp; Clear(y) &amp; Block(b) &amp; Block(y)&#39;</span><span class=\"p\">,</span>\n",
       "                                <span class=\"n\">effect</span><span class=\"o\">=</span><span class=\"s1\">&#39;On(b, y) &amp; Clear(x) &amp; ~On(b, x) &amp; ~Clear(y)&#39;</span><span class=\"p\">),</span>\n",
       "                         <span class=\"n\">Action</span><span class=\"p\">(</span><span class=\"s1\">&#39;MoveToTable(b, x)&#39;</span><span class=\"p\">,</span>\n",
       "                                <span class=\"n\">precond</span><span class=\"o\">=</span><span class=\"s1\">&#39;On(b, x) &amp; Clear(b) &amp; Block(b)&#39;</span><span class=\"p\">,</span>\n",
       "                                <span class=\"n\">effect</span><span class=\"o\">=</span><span class=\"s1\">&#39;On(b, Table) &amp; Clear(x) &amp; ~On(b, x)&#39;</span><span class=\"p\">)])</span>\n",
       "</pre></div>\n",
       "</body>\n",
       "</html>\n"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "psource(three_block_tower)"
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**On(b, x):** The block **'b'** is on **'x'**. **'x'** can be a table or a block.\n",
    "\n",
    "**~On(b, x):** The block **'b'** is _not_ on **'x'**. **'x'** can be a table or a block.\n",
    "\n",
    "**Block(b):** Declares **'b'** as a block.\n",
    "\n",
    "**Clear(x):** To indicate that there is nothing on **'x'** and it is free to be moved around.\n",
    "\n",
    "**~Clear(x):** To indicate that there is something on **'x'** and it cannot be moved.\n",
    " \n",
    " Let us now define an object of `three_block_tower` problem:"
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
   "source": [
    "threeBlockTower = three_block_tower()"
   "cell_type": "markdown",
   "metadata": {},
jeff3456's avatar
jeff3456 a validé
   "source": [
    "Before taking any actions, we will check if `threeBlockTower` has reached its goal:"
   "cell_type": "code",
   "execution_count": 26,
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "False\n"
     ]
    }
   ],
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
   "source": [
    "print(threeBlockTower.goal_test())"
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As we can see, it hasn't completed the goal. \n",
    "We now define a sequence of actions that can stack three blocks in the required order. \n",
    "The actions are then carried out on the `threeBlockTower` PlanningProblem.\n",
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
    "\n",
    "The actions available to us are the following: MoveToTable, Move\n",
    "\n",
    "**MoveToTable(b, x): ** Move box **'b'** stacked on **'x'** to the table, given that box **'b'** is clear.\n",
    "\n",
    "**Move(b, x, y): ** Move box **'b'** stacked on **'x'** to the top of **'y'**, given that both **'b'** and **'y'** are clear.\n"
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {
    "collapsed": true
   },
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
   "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)"
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
   ]
  },
  {
   "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."
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
    }
   ],
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
   "source": [
    "print(threeBlockTower.goal_test())"
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "It has now successfully achieved its goal i.e, to build a stack of three blocks in the specified order."
   "cell_type": "markdown",
   "metadata": {},
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
   "source": [
    "The `three_block_tower` problem can also be defined in simpler terms using just two actions `ToTable(x, y)` and `FromTable(x, y)`.\n",
    "The underlying problem remains the same however, stacking up three blocks in a certain configuration given a particular starting state.\n",
    "Let's have a look at the alternative definition."
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
   "outputs": [
    {
     "data": {
      "text/html": [
       "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n",
       "   \"http://www.w3.org/TR/html4/strict.dtd\">\n",
       "\n",
       "<html>\n",
       "<head>\n",
       "  <title></title>\n",
       "  <meta http-equiv=\"content-type\" content=\"text/html; charset=None\">\n",
       "  <style type=\"text/css\">\n",
       "td.linenos { background-color: #f0f0f0; padding-right: 10px; }\n",
       "span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }\n",
       "pre { line-height: 125%; }\n",
       "body .hll { background-color: #ffffcc }\n",
       "body  { background: #f8f8f8; }\n",
       "body .c { color: #408080; font-style: italic } /* Comment */\n",
       "body .err { border: 1px solid #FF0000 } /* Error */\n",
       "body .k { color: #008000; font-weight: bold } /* Keyword */\n",
       "body .o { color: #666666 } /* Operator */\n",
       "body .ch { color: #408080; font-style: italic } /* Comment.Hashbang */\n",
       "body .cm { color: #408080; font-style: italic } /* Comment.Multiline */\n",
       "body .cp { color: #BC7A00 } /* Comment.Preproc */\n",
       "body .cpf { color: #408080; font-style: italic } /* Comment.PreprocFile */\n",
       "body .c1 { color: #408080; font-style: italic } /* Comment.Single */\n",
       "body .cs { color: #408080; font-style: italic } /* Comment.Special */\n",
       "body .gd { color: #A00000 } /* Generic.Deleted */\n",
       "body .ge { font-style: italic } /* Generic.Emph */\n",
       "body .gr { color: #FF0000 } /* Generic.Error */\n",
       "body .gh { color: #000080; font-weight: bold } /* Generic.Heading */\n",
       "body .gi { color: #00A000 } /* Generic.Inserted */\n",
       "body .go { color: #888888 } /* Generic.Output */\n",
       "body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */\n",
       "body .gs { font-weight: bold } /* Generic.Strong */\n",
       "body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */\n",
       "body .gt { color: #0044DD } /* Generic.Traceback */\n",
       "body .kc { color: #008000; font-weight: bold } /* Keyword.Constant */\n",
       "body .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */\n",
       "body .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */\n",
       "body .kp { color: #008000 } /* Keyword.Pseudo */\n",
       "body .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */\n",
       "body .kt { color: #B00040 } /* Keyword.Type */\n",
       "body .m { color: #666666 } /* Literal.Number */\n",
       "body .s { color: #BA2121 } /* Literal.String */\n",
       "body .na { color: #7D9029 } /* Name.Attribute */\n",
       "body .nb { color: #008000 } /* Name.Builtin */\n",
       "body .nc { color: #0000FF; font-weight: bold } /* Name.Class */\n",
       "body .no { color: #880000 } /* Name.Constant */\n",
       "body .nd { color: #AA22FF } /* Name.Decorator */\n",
       "body .ni { color: #999999; font-weight: bold } /* Name.Entity */\n",
       "body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */\n",
       "body .nf { color: #0000FF } /* Name.Function */\n",
       "body .nl { color: #A0A000 } /* Name.Label */\n",
       "body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */\n",
       "body .nt { color: #008000; font-weight: bold } /* Name.Tag */\n",
       "body .nv { color: #19177C } /* Name.Variable */\n",
       "body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */\n",
       "body .w { color: #bbbbbb } /* Text.Whitespace */\n",
       "body .mb { color: #666666 } /* Literal.Number.Bin */\n",
       "body .mf { color: #666666 } /* Literal.Number.Float */\n",
       "body .mh { color: #666666 } /* Literal.Number.Hex */\n",
       "body .mi { color: #666666 } /* Literal.Number.Integer */\n",
       "body .mo { color: #666666 } /* Literal.Number.Oct */\n",
       "body .sa { color: #BA2121 } /* Literal.String.Affix */\n",
       "body .sb { color: #BA2121 } /* Literal.String.Backtick */\n",
       "body .sc { color: #BA2121 } /* Literal.String.Char */\n",
       "body .dl { color: #BA2121 } /* Literal.String.Delimiter */\n",
       "body .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */\n",
       "body .s2 { color: #BA2121 } /* Literal.String.Double */\n",
       "body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */\n",
       "body .sh { color: #BA2121 } /* Literal.String.Heredoc */\n",
       "body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */\n",
       "body .sx { color: #008000 } /* Literal.String.Other */\n",
       "body .sr { color: #BB6688 } /* Literal.String.Regex */\n",
       "body .s1 { color: #BA2121 } /* Literal.String.Single */\n",
       "body .ss { color: #19177C } /* Literal.String.Symbol */\n",
       "body .bp { color: #008000 } /* Name.Builtin.Pseudo */\n",
       "body .fm { color: #0000FF } /* Name.Function.Magic */\n",
       "body .vc { color: #19177C } /* Name.Variable.Class */\n",
       "body .vg { color: #19177C } /* Name.Variable.Global */\n",
       "body .vi { color: #19177C } /* Name.Variable.Instance */\n",
       "body .vm { color: #19177C } /* Name.Variable.Magic */\n",
       "body .il { color: #666666 } /* Literal.Number.Integer.Long */\n",
       "\n",
       "  </style>\n",
       "</head>\n",
       "<body>\n",
       "<h2></h2>\n",
       "\n",
       "<div class=\"highlight\"><pre><span></span><span class=\"k\">def</span> <span class=\"nf\">simple_blocks_world</span><span class=\"p\">():</span>\n",
       "    <span class=\"sd\">&quot;&quot;&quot;</span>\n",
       "<span class=\"sd\">    SIMPLE-BLOCKS-WORLD</span>\n",
       "<span class=\"sd\">    A simplified definition of the Sussman Anomaly problem.</span>\n",
       "\n",
       "<span class=\"sd\">    Example:</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; from planning import *</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; sbw = simple_blocks_world()</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; sbw.goal_test()</span>\n",
       "<span class=\"sd\">    False</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; sbw.act(expr(&#39;ToTable(A, B)&#39;))</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; sbw.act(expr(&#39;FromTable(B, A)&#39;))</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; sbw.goal_test()</span>\n",
       "<span class=\"sd\">    False</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; sbw.act(expr(&#39;FromTable(C, B)&#39;))</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; sbw.goal_test()</span>\n",
       "<span class=\"sd\">    True</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt;</span>\n",
       "<span class=\"sd\">    &quot;&quot;&quot;</span>\n",
       "\n",
       "    <span class=\"k\">return</span> <span class=\"n\">PlanningProblem</span><span class=\"p\">(</span><span class=\"n\">init</span><span class=\"o\">=</span><span class=\"s1\">&#39;On(A, B) &amp; Clear(A) &amp; OnTable(B) &amp; OnTable(C) &amp; Clear(C)&#39;</span><span class=\"p\">,</span>\n",
       "                <span class=\"n\">goals</span><span class=\"o\">=</span><span class=\"s1\">&#39;On(B, A) &amp; On(C, B)&#39;</span><span class=\"p\">,</span>\n",
       "                <span class=\"n\">actions</span><span class=\"o\">=</span><span class=\"p\">[</span><span class=\"n\">Action</span><span class=\"p\">(</span><span class=\"s1\">&#39;ToTable(x, y)&#39;</span><span class=\"p\">,</span>\n",
       "                                <span class=\"n\">precond</span><span class=\"o\">=</span><span class=\"s1\">&#39;On(x, y) &amp; Clear(x)&#39;</span><span class=\"p\">,</span>\n",
       "                                <span class=\"n\">effect</span><span class=\"o\">=</span><span class=\"s1\">&#39;~On(x, y) &amp; Clear(y) &amp; OnTable(x)&#39;</span><span class=\"p\">),</span>\n",
       "                         <span class=\"n\">Action</span><span class=\"p\">(</span><span class=\"s1\">&#39;FromTable(y, x)&#39;</span><span class=\"p\">,</span>\n",
       "                                <span class=\"n\">precond</span><span class=\"o\">=</span><span class=\"s1\">&#39;OnTable(y) &amp; Clear(y) &amp; Clear(x)&#39;</span><span class=\"p\">,</span>\n",
       "                                <span class=\"n\">effect</span><span class=\"o\">=</span><span class=\"s1\">&#39;~OnTable(y) &amp; ~Clear(x) &amp; On(y, x)&#39;</span><span class=\"p\">)])</span>\n",
       "</pre></div>\n",
       "</body>\n",
       "</html>\n"
      ],
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
      "text/plain": [
       "<IPython.core.display.HTML object>"
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
      ]
     },
     "metadata": {},
     "output_type": "display_data"
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
    }
   ],
   "source": [
    "psource(simple_blocks_world)"
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "**On(x, y):** The block **'x'** is on **'y'**. Both **'x'** and **'y'** have to be blocks.\n",
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
    "\n",
    "**~On(x, y):** The block **'x'** is _not_ on **'y'**. Both **'x'** and **'y'** have to be blocks.\n",
    "**OnTable(x):** The block **'x'** is on the table.\n",
    "**~OnTable(x):** The block **'x'** is _not_ on the table.\n",
    "\n",
    "**Clear(x):** To indicate that there is nothing on **'x'** and it is free to be moved around.\n",
    "\n",
    "**~Clear(x):** To indicate that there is something on **'x'** and it cannot be moved.\n",
    "\n",
    "Let's now define a `simple_blocks_world` prolem."
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {
    "collapsed": true
   },
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
   "outputs": [],
   "source": [
    "simpleBlocksWorld = simple_blocks_world()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Before taking any actions, we will see if `simple_bw` has reached its goal."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "False"
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    "simpleBlocksWorld.goal_test()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "As we can see, it hasn't completed the goal. \n",
    "We now define a sequence of actions that can stack three blocks in the required order. \n",
    "The actions are then carried out on the `simple_bw` PlanningProblem.\n",
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
    "\n",
    "The actions available to us are the following: MoveToTable, Move\n",
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
    "\n",
    "**ToTable(x, y): ** Move box **'x'** stacked on **'y'** to the table, given that box **'y'** is clear.\n",
    "\n",
    "**FromTable(x, y): ** Move box **'x'** from wherever it is, to the top of **'y'**, given that both **'x'** and **'y'** are clear.\n"
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {
    "collapsed": true
   },
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
   "outputs": [],
   "source": [
    "solution = [expr('ToTable(A, B)'),\n",
    "            expr('FromTable(B, A)'),\n",
    "            expr('FromTable(C, B)')]\n",
    "\n",
    "for action in solution:\n",
    "    simpleBlocksWorld.act(action)"
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
   ]
  },
  {
   "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."
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "metadata": {},
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "True\n"
     ]
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
   "source": [
    "print(simpleBlocksWorld.goal_test())"
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "It has now successfully achieved its goal i.e, to build a stack of three blocks in the specified order."
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Shopping Problem"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "This problem requires us to acquire a carton of milk, a banana and a drill.\n",
    "Initially, we start from home and it is known to us that milk and bananas are available in the supermarket and the hardware store sells drills.\n",
    "Let's take a look at the definition of the `shopping_problem` in the module."
Kaivalya Rawal's avatar
Kaivalya Rawal a validé
  {
   "cell_type": "code",
   "execution_count": 34,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01//EN\"\n",
       "   \"http://www.w3.org/TR/html4/strict.dtd\">\n",
       "\n",
       "<html>\n",
       "<head>\n",
       "  <title></title>\n",
       "  <meta http-equiv=\"content-type\" content=\"text/html; charset=None\">\n",
       "  <style type=\"text/css\">\n",
       "td.linenos { background-color: #f0f0f0; padding-right: 10px; }\n",
       "span.lineno { background-color: #f0f0f0; padding: 0 5px 0 5px; }\n",
       "pre { line-height: 125%; }\n",
       "body .hll { background-color: #ffffcc }\n",
       "body  { background: #f8f8f8; }\n",
       "body .c { color: #408080; font-style: italic } /* Comment */\n",
       "body .err { border: 1px solid #FF0000 } /* Error */\n",
       "body .k { color: #008000; font-weight: bold } /* Keyword */\n",
       "body .o { color: #666666 } /* Operator */\n",
       "body .ch { color: #408080; font-style: italic } /* Comment.Hashbang */\n",
       "body .cm { color: #408080; font-style: italic } /* Comment.Multiline */\n",
       "body .cp { color: #BC7A00 } /* Comment.Preproc */\n",
       "body .cpf { color: #408080; font-style: italic } /* Comment.PreprocFile */\n",
       "body .c1 { color: #408080; font-style: italic } /* Comment.Single */\n",
       "body .cs { color: #408080; font-style: italic } /* Comment.Special */\n",
       "body .gd { color: #A00000 } /* Generic.Deleted */\n",
       "body .ge { font-style: italic } /* Generic.Emph */\n",
       "body .gr { color: #FF0000 } /* Generic.Error */\n",
       "body .gh { color: #000080; font-weight: bold } /* Generic.Heading */\n",
       "body .gi { color: #00A000 } /* Generic.Inserted */\n",
       "body .go { color: #888888 } /* Generic.Output */\n",
       "body .gp { color: #000080; font-weight: bold } /* Generic.Prompt */\n",
       "body .gs { font-weight: bold } /* Generic.Strong */\n",
       "body .gu { color: #800080; font-weight: bold } /* Generic.Subheading */\n",
       "body .gt { color: #0044DD } /* Generic.Traceback */\n",
       "body .kc { color: #008000; font-weight: bold } /* Keyword.Constant */\n",
       "body .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */\n",
       "body .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */\n",
       "body .kp { color: #008000 } /* Keyword.Pseudo */\n",
       "body .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */\n",
       "body .kt { color: #B00040 } /* Keyword.Type */\n",
       "body .m { color: #666666 } /* Literal.Number */\n",
       "body .s { color: #BA2121 } /* Literal.String */\n",
       "body .na { color: #7D9029 } /* Name.Attribute */\n",
       "body .nb { color: #008000 } /* Name.Builtin */\n",
       "body .nc { color: #0000FF; font-weight: bold } /* Name.Class */\n",
       "body .no { color: #880000 } /* Name.Constant */\n",
       "body .nd { color: #AA22FF } /* Name.Decorator */\n",
       "body .ni { color: #999999; font-weight: bold } /* Name.Entity */\n",
       "body .ne { color: #D2413A; font-weight: bold } /* Name.Exception */\n",
       "body .nf { color: #0000FF } /* Name.Function */\n",
       "body .nl { color: #A0A000 } /* Name.Label */\n",
       "body .nn { color: #0000FF; font-weight: bold } /* Name.Namespace */\n",
       "body .nt { color: #008000; font-weight: bold } /* Name.Tag */\n",
       "body .nv { color: #19177C } /* Name.Variable */\n",
       "body .ow { color: #AA22FF; font-weight: bold } /* Operator.Word */\n",
       "body .w { color: #bbbbbb } /* Text.Whitespace */\n",
       "body .mb { color: #666666 } /* Literal.Number.Bin */\n",
       "body .mf { color: #666666 } /* Literal.Number.Float */\n",
       "body .mh { color: #666666 } /* Literal.Number.Hex */\n",
       "body .mi { color: #666666 } /* Literal.Number.Integer */\n",
       "body .mo { color: #666666 } /* Literal.Number.Oct */\n",
       "body .sa { color: #BA2121 } /* Literal.String.Affix */\n",
       "body .sb { color: #BA2121 } /* Literal.String.Backtick */\n",
       "body .sc { color: #BA2121 } /* Literal.String.Char */\n",
       "body .dl { color: #BA2121 } /* Literal.String.Delimiter */\n",
       "body .sd { color: #BA2121; font-style: italic } /* Literal.String.Doc */\n",
       "body .s2 { color: #BA2121 } /* Literal.String.Double */\n",
       "body .se { color: #BB6622; font-weight: bold } /* Literal.String.Escape */\n",
       "body .sh { color: #BA2121 } /* Literal.String.Heredoc */\n",
       "body .si { color: #BB6688; font-weight: bold } /* Literal.String.Interpol */\n",
       "body .sx { color: #008000 } /* Literal.String.Other */\n",
       "body .sr { color: #BB6688 } /* Literal.String.Regex */\n",
       "body .s1 { color: #BA2121 } /* Literal.String.Single */\n",
       "body .ss { color: #19177C } /* Literal.String.Symbol */\n",
       "body .bp { color: #008000 } /* Name.Builtin.Pseudo */\n",
       "body .fm { color: #0000FF } /* Name.Function.Magic */\n",
       "body .vc { color: #19177C } /* Name.Variable.Class */\n",
       "body .vg { color: #19177C } /* Name.Variable.Global */\n",
       "body .vi { color: #19177C } /* Name.Variable.Instance */\n",
       "body .vm { color: #19177C } /* Name.Variable.Magic */\n",
       "body .il { color: #666666 } /* Literal.Number.Integer.Long */\n",
       "\n",
       "  </style>\n",
       "</head>\n",
       "<body>\n",
       "<h2></h2>\n",
       "\n",
       "<div class=\"highlight\"><pre><span></span><span class=\"k\">def</span> <span class=\"nf\">shopping_problem</span><span class=\"p\">():</span>\n",
       "    <span class=\"sd\">&quot;&quot;&quot;</span>\n",
       "<span class=\"sd\">    SHOPPING-PROBLEM</span>\n",
       "<span class=\"sd\">    A problem of acquiring some items given their availability at certain stores.</span>\n",
       "\n",
       "<span class=\"sd\">    Example:</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; from planning import *</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; sp = shopping_problem()</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; sp.goal_test()</span>\n",
       "<span class=\"sd\">    False</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; sp.act(expr(&#39;Go(Home, HW)&#39;))</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; sp.act(expr(&#39;Buy(Drill, HW)&#39;))</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; sp.act(expr(&#39;Go(HW, SM)&#39;))</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; sp.act(expr(&#39;Buy(Banana, SM)&#39;))</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; sp.goal_test()</span>\n",
       "<span class=\"sd\">    False</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; sp.act(expr(&#39;Buy(Milk, SM)&#39;))</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt; sp.goal_test()</span>\n",
       "<span class=\"sd\">    True</span>\n",
       "<span class=\"sd\">    &gt;&gt;&gt;</span>\n",
       "<span class=\"sd\">    &quot;&quot;&quot;</span>\n",
       "\n",