Newer
Older
"collapsed": true,
"deletable": true,
"editable": true
},
"outputs": [],
"source": [
"backtrack_queen_step = make_plot_board_step_function(backtracking_instru_queen) # Step Function for Widgets"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"Now finally we set some matplotlib parameters to adjust how our plot will look. The font is necessary because the Black Queen Unicode character is not a part of all fonts. You can move the slider to experiment and observe the how queens are assigned. It is also possible to move the slider using arrow keys or to jump to the value by directly editing the number with a double click.The **Visualize Button** will automatically animate the slider for you. The **Extra Delay Box** allows you to set time delay in seconds upto one second for each time step.\n"
"collapsed": false,
"deletable": true,
"editable": true
"source": [
"matplotlib.rcParams['figure.figsize'] = (8.0, 8.0)\n",
"matplotlib.rcParams['font.family'].append(u'Dejavu Sans')\n",
"\n",
"iteration_slider = widgets.IntSlider(min=0, max=len(backtracking_instru_queen.assignment_history)-1, step=0, value=0)\n",
"w=widgets.interactive(backtrack_queen_step,iteration=iteration_slider)\n",
"display(w)\n",
"\n",
"visualize_callback = make_visualize(iteration_slider)\n",
"\n",
"visualize_button = widgets.ToggleButton(desctiption = \"Visualize\", value = False)\n",
"time_select = widgets.ToggleButtons(description='Extra Delay:',options=['0', '0.1', '0.2', '0.5', '0.7', '1.0'])\n",
"\n",
"a = widgets.interactive(visualize_callback, Visualize = visualize_button, time_step=time_select)\n",
"display(a)"
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"Now let us finally repeat the above steps for **min_conflicts** solution."
]
},
{
"cell_type": "code",
"collapsed": true,
"deletable": true,
"editable": true
"conflicts_instru_queen = make_instru(twelve_queens_csp)\n",
"result = min_conflicts(conflicts_instru_queen)"
]
},
{
"cell_type": "code",
"collapsed": true,
"deletable": true,
"editable": true
},
"outputs": [],
"source": [
"conflicts_step = make_plot_board_step_function(conflicts_instru_queen)"
]
},
{
"cell_type": "markdown",
"metadata": {
"deletable": true,
"editable": true
},
"source": [
"The visualization has same features as the above. But here it also highlights the conflicts by labeling the conflicted queens with a red background."
]
},
{
"cell_type": "code",
"collapsed": false,
"deletable": true,
"editable": true
"iteration_slider = widgets.IntSlider(min=0, max=len(conflicts_instru_queen.assignment_history)-1, step=0, value=0)\n",
"w=widgets.interactive(conflicts_step,iteration=iteration_slider)\n",
"display(w)\n",
"\n",
"visualize_callback = make_visualize(iteration_slider)\n",
"\n",
"visualize_button = widgets.ToggleButton(desctiption = \"Visualize\", value = False)\n",
"time_select = widgets.ToggleButtons(description='Extra Delay:',options=['0', '0.1', '0.2', '0.5', '0.7', '1.0'])\n",
"\n",
"a = widgets.interactive(visualize_callback, Visualize = visualize_button, time_step=time_select)\n",
"display(a)"
}
],
"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",