{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# [6.4 Planning as a CSP](http://artint.info/2e/html/ArtInt2e.Ch6.S4.html)\n", "- [Implementation Details](http://artint.info/AIPython/aipython.pdf#page=92) (page 92)\n", "\n", "## About\n", "\n", "In forward planning, the search is constrained by the initial state and only uses the goal as a stopping criterion and as a source for heuristics. In regression planning, the search is constrained by the goal and only uses the start state as a stopping criterion and as a source for heuristics. By converting the problem to a constraint satisfaction problem (CSP), the initial state can be used to prune what is not reachable and the goal to prune what is not useful. The CSP will be defined for a finite number of steps; the number of steps (also called __horizon__) can be adjusted to find the shortest plan. We can apply any method we learnt before (see [Chapter 4](https://artint.info/2e/html/ArtInt2e.Ch4.html)) in order to solve this CSP and thus find a plan.\n", "\n", "You can run each cell by selecting it and pressing *Ctrl+Enter* in Windows or *Shift+Return* in MacOS. Alternatively, you can click the *Play* button in the toolbar, to the left of the stop button. For more information, check out our AISpace2 [Tutorial](https://aispace2.github.io/AISpace2/tutorial.html).\n", "\n", "Feel free to modify our codes either in this notebook or somewhere outside (e.g. python files in `/aipython/`). If you want to modify our codes outside, you might find [this](https://aispace2.github.io/AISpace2/tutorial.html#tutorial-faq-why-update-aipython-not-reflect) helpful for how your changes can take effect.\n", "\n", "You need to run the following command to import our pre-defined problems. You can also define your own problems ([how?](https://aispace2.github.io/AISpace2/tutorial.html#tutorial-planning-construct-yourself)). " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Run this first to import dependencies\n", "from aipython.stripsProblem import strips_delivery1, strips_delivery2, strips_delivery3, strips_blocks1, strips_blocks2, strips_blocks3, strips_elevator" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "You can click on an inconsistent arc to make it consistent, or click buttons such as \"Step\" to randomly select an arc to make consistent. After all arcs are consistent, you can click on a variable with more than one value in its domain to split it." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "from aipython.cspConsistency import Con_solver\n", "from aipython.stripsCSPPlanner import CSP_from_STRIPS\n", "\n", "cspFromSTRIPS = CSP_from_STRIPS(planning_problem=strips_elevator, horizon=2)\n", "solver = Con_solver(csp=cspFromSTRIPS)\n", "\n", "# Visualization options\n", "# For more explanation please visit: https://aispace2.github.io/AISpace2/tutorial.html#tutorial-common-visualization-options\n", "solver.sleep_time = 0.2 # The time, in seconds, between each step in auto solving\n", "solver.line_width = 2.0 # The thickness of edges\n", "solver.text_size = 13 # The fontsize of the text\n", "solver.detail_level = 2 # 0=no text, 1=truncated text, 2=full text\n", "\n", "# Display the widget\n", "display(solver)\n", "solver.solve_one()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.8" } }, "nbformat": 4, "nbformat_minor": 4 }