Free AI web copilot to create summaries, insights and extended knowledge, download it at here
4786
Abstract
iv id="7555"><pre>for <span class="hljs-keyword">action</span> <span class="hljs-keyword">in</span> actions:
<span class="hljs-keyword">if</span> <span class="hljs-keyword">action</span>.pre(pacman_world):
predicted_pacman_world = <span class="hljs-keyword">action</span>.eff()</pre></div><p id="a8eb">The preconditions of all simple actions that we have are:</p><ol><li>the action is legal (not moving towards the wall)</li><li>will not meet ghost</li></ol><p id="95c9">Another thing worth noting here is we provide the cost incurred to perform the action as well to the search algorithm.</p><h1 id="dbdd">Planning Problem</h1><p id="287a">We’ll look at one example of Planning Problem, start with a simple one.</p><p id="9998">From this initial state with 4 foods in the corner and without ghosts.</p><figure id="067e"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*t4BKH2a_PGT1ZuVU62lboA.png"><figcaption>Simple Planning Problem with 4 foods in the corners</figcaption></figure><p id="3e4d">We want to have this goal state with 0 food, which means our AI agent, Pacman, has to eat all 4 foods intelligently.</p><figure id="203a"><img src="https://cdn-images-1.readmedium.com/v2/resize:fit:800/1*pgmW3pFdY_O-o6XTEeNnIQ.png"><figcaption>Goal State with no food at all in Pacman World</figcaption></figure><h1 id="371b">Algorithms</h1><p id="2890">Let’s look at how deterministic search algorithms solve this problem. In these implementations we are not using heuristics. Heuristics will be discussed in a separate post.</p><h2 id="4ed4">Breadth-first Search</h2><p id="2c05">We implement BFS as an instance of Deterministic search algorithm with node selection and node pruning as follows:</p><ol><li>Node selection
Choose a node with shortest length</li><li>Pruning
Remove from Children and Frontier nodes which are already in Expanded</li></ol>
<figure id="bbcb">
<div>
<div>
<iframe class="gist-iframe" src="/gist/debbynirwan/ceea32a6141af53f2ca10895bf5c5ed4.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
</div>
</div>
</figure></iframe></div></div></figure><p id="cb87">When running this algorithm on our planning problem we will get optimal solution but long planning time. For relative comparisons, I will write each algorithm’s planning time when I ran it.</p><ul><li>Planning time: 185 seconds</li></ul>
<figure id="3757">
<div>
<div>
<img class="ratio" src="http://placehold.it/16x9">
<iframe class="" src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FECDlfYZzwSc%3Ffeature%3Doembed&display_name=YouTube&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DECDlfYZzwSc&image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FECDlfYZzwSc%2Fhqdefault.jpg&key=a19fcc184b9711e1b4764040d3dc5c07&type=text%2Fhtml&schema=youtube" allowfullscreen="" frameborder="0" height="480" width="854">
</div>
</div>
</figure></iframe></div></div></figure><h2 id="e628">Depth-first Search</h2><ol><li>Node Selection
Choose node with longest length</li><li>Pruning
Cycle checking</li></ol>
<figure id="4a3d">
<div>
<div>
<iframe class="gist-iframe" src="/gist/debbynirwan/c8853363db07533924249a95993bbfae.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
</div>
</div>
</figure></iframe></div></div></figure><p id="6602">Running this algorithm on our planning problem gives us non-optimal solution but much shorter planning time.</p><ul><li>Planning time: 37 seconds</li></ul>
<figure id="e1ec">
<div>
<div>
<img class="ratio" src="http://placehold.it/16x9">
<iframe class="" src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F1KG44GW9nZ8%3Ffeature%3Doembed&display_name=YouTube&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D1KG44GW9nZ8&image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F1KG44GW9nZ8%2Fhqdefault.jpg&key=a19fcc184b9711e1b4764040d3dc5c07&type=text%2Fhtml&schema=youtube" allowfullscreen="" frameborder="0" height="480" width="854">
</div>
</div>
</figure></iframe></div></div></figure><h2 id="1c27">Hill Climbing</h2><ol><li>Node Selection
Choose node that minimizes heuristic, for our implementation this is just any nodes because we have not implemented heuristic function</li><li>Pruning
Clear Frontier so that we only follow current path</li></ol><p id="5d71">As we can see in the pruning process
Options
it is not guaranteed that we will have a solution. This algorithm fails to solve our planning problem.</p><h2 id="e6e6">Uniform-cost Search</h2><ol><li>Node Selection
Choose node that minimizes total cost</li><li>Pruning
Remove from Frontier and Children nodes that are already in Expanded</li></ol>
<figure id="01ff">
<div>
<div>
<iframe class="gist-iframe" src="/gist/debbynirwan/7c808ae6e64ce8e3cc34b49733bbb4e8.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
</div>
</div>
</figure></iframe></div></div></figure><p id="ce80">This algorithm gives us optimal solution and shorter planning time compared to BFS.</p><ul><li>Planning time: 106 seconds</li></ul>
<figure id="060b">
<div>
<div>
<img class="ratio" src="http://placehold.it/16x9">
<iframe class="" src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F1Qcgk_CUW7I%3Ffeature%3Doembed&display_name=YouTube&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D1Qcgk_CUW7I&image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F1Qcgk_CUW7I%2Fhqdefault.jpg&key=a19fcc184b9711e1b4764040d3dc5c07&type=text%2Fhtml&schema=youtube" allowfullscreen="" frameborder="0" height="480" width="854">
</div>
</div>
</figure></iframe></div></div></figure><h2 id="9be8">A*</h2><ol><li>Node Selection
Choose node that minimizes f(v) = cost + heuristic. For our current implementation this will be exactly the same as Uniform-cost search because we have not implemented heuristics</li><li>Pruning
Remove duplicated paths with higher cost</li></ol>
<figure id="9cf4">
<div>
<div>
<iframe class="gist-iframe" src="/gist/debbynirwan/a9e6a4df5d2b800fc6a9dbf52d9c7628.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
</div>
</div>
</figure></iframe></div></div></figure><p id="0fb8">Because of the pruning process, the planning time is shorter than Uniform-cost search. The result is optimal.</p><ul><li>Planning time: 24 seconds</li></ul>
<figure id="62e9">
<div>
<div>
<img class="ratio" src="http://placehold.it/16x9">
<iframe class="" src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FVhjbGCHG23A%3Ffeature%3Doembed&display_name=YouTube&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DVhjbGCHG23A&image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FVhjbGCHG23A%2Fhqdefault.jpg&key=a19fcc184b9711e1b4764040d3dc5c07&type=text%2Fhtml&schema=youtube" allowfullscreen="" frameborder="0" height="480" width="854">
</div>
</div>
</figure></iframe></div></div></figure><h2 id="d621">Depth-first Branch and Bound (DFSBB)</h2><p id="47bd">This algorithm evaluates all possible paths in DFS and get the best. However, for our planning problem this algorithm takes too long to run. We’ll skip this algorithm this time.</p><h2 id="0289">Greedy Best-First Search (GBFS)</h2><ol><li>Node Selection
Choose node that minimizes heuristic</li><li>Pruning
Same as A*</li></ol>
<figure id="2277">
<div>
<div>
<iframe class="gist-iframe" src="/gist/debbynirwan/399192c14bb79732b98200e070ec35d9.js" allowfullscreen="" frameborder="0" height="undefined" width="undefined">
</div>
</div>
</figure></iframe></div></div></figure><p id="b9c6">Normally this algorithm runs quicker than A*, however because we haven’t implemented heuristic, the planning time is a little bit longer.</p><ul><li>Planning time: 51 seconds</li></ul>
<figure id="b6a1">
<div>
<div>
<img class="ratio" src="http://placehold.it/16x9">
<iframe class="" src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FLhVUniRS_Vk%3Ffeature%3Doembed&display_name=YouTube&url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DLhVUniRS_Vk&image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FLhVUniRS_Vk%2Fhqdefault.jpg&key=a19fcc184b9711e1b4764040d3dc5c07&type=text%2Fhtml&schema=youtube" allowfullscreen="" frameborder="0" height="480" width="854">
</div>
</div>
</figure></iframe></div></div></figure><p id="fd9e">Now we have looked into different algorithms to solve our first simple planning problem. In the next posts, we’ll solve more difficult planning problems and techniques to solve them.</p></article></body>