{ "cells": [ { "cell_type": "markdown", "metadata": { "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": { "col": 4, "height": 4, "hidden": false, "row": 0, "width": 4 }, "report_default": { "hidden": false } } } } }, "source": [ "# [4.4 Consistency Algorithms](http://artint.info/2e/html/ArtInt2e.Ch4.S4.html)\n", "- [Implementation Details](http://artint.info/AIPython/aipython.pdf#page=57) (page 57)\n", "\n", "## About\n", "A more advanced technique for solving Constraint Satisfaction Problems (CSPs) is to use __arc consistency__ to prune domains first. In the best case, this will find a unique solution; otherwise, we can perform domain splitting or use search on the simpler problem.\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-csp-construct-yourself)). " ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# Run this to import pre-defined problems\n", "from aipython.cspProblem import csp_simple1, csp_simple2, csp_simple3, csp_extended1, csp_extended2, csp_extended3, csp_crossword1, csp_crossword2, csp_crossword3, csp_crossword2d, csp_five_queens, csp_eight_queens" ] }, { "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": { "extensions": { "jupyter_dashboards": { "version": 1, "views": { "grid_default": { "col": 8, "height": 20, "hidden": false, "row": 0, "width": null }, "report_default": { "hidden": false } } } } }, "outputs": [], "source": [ "from aipython.cspConsistency import Con_solver\n", "\n", "con_solver = Con_solver(csp=csp_simple1)\n", "\n", "# Visualization options\n", "# For more explanation please visit: https://aispace2.github.io/AISpace2/tutorial.html#tutorial-common-visualization-options\n", "con_solver.sleep_time = 0.2 # The time, in seconds, between each step in auto solving\n", "con_solver.line_width = 2.0 # The thickness of edges\n", "con_solver.text_size = 13 # The fontsize of the text\n", "con_solver.detail_level = 2 # 0=no text, 1=truncated text, 2=full text\n", "\n", "# Display the widget\n", "display(con_solver)\n", "con_solver.solve_one()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "celltoolbar": "Raw Cell Format", "extensions": { "jupyter_dashboards": { "activeView": "report_default", "version": 1, "views": { "grid_default": { "cellMargin": 10, "defaultCellHeight": 20, "maxColumns": 12, "name": "grid", "type": "grid" }, "report_default": { "name": "report", "type": "report" } } } }, "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 }