FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Changed plotting function for NQueensCSP by ad71 · Pull Request #847 · aimacode/aima-python · GitHub

Repository navigation

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .ipynb  (1) .md  (1) .png  (1) .py  (1) .yml  (1) All 5 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
1 change: 1 addition & 0 deletions .travis.yml
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ install:
- pip install matplotlib
- pip install networkx
- pip install ipywidgets
- pip install Pillow

script:
- py.test
Expand Down
2 changes: 1 addition & 1 deletion README.md
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ Here is a table of algorithms, the figure, name of the algorithm in the book and
| 6 | CSP | `CSP` | [`csp.py`][csp] | Done | Included |
| 6.3 | AC-3 | `AC3` | [`csp.py`][csp] | Done | |
| 6.5 | Backtracking-Search | `backtracking_search` | [`csp.py`][csp] | Done | Included |
| 6.8 | Min-Conflicts | `min_conflicts` | [`csp.py`][csp] | Done | |
| 6.8 | Min-Conflicts | `min_conflicts` | [`csp.py`][csp] | Done | Included |
| 6.11 | Tree-CSP-Solver | `tree_csp_solver` | [`csp.py`][csp] | Done | Included |
| 7 | KB | `KB` | [`logic.py`][logic] | Done | Included |
| 7.1 | KB-Agent | `KB_Agent` | [`logic.py`][logic] | Done | |
Expand Down
61 changes: 14 additions & 47 deletions csp.ipynb

Large diffs are not rendered by default.

Binary file added images/queen_s.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Viewer requires iframe.
30 changes: 29 additions & 1 deletion notebook.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import matplotlib.pyplot as plt
import numpy as np
from PIL import Image

import os, struct
import array
Expand Down Expand Up @@ -1041,4 +1042,31 @@ def visualize_callback(Visualize):

slider = widgets.IntSlider(min=0, max=1, step=1, value=0)
slider_visual = widgets.interactive(slider_callback, iteration=slider)
display(slider_visual)
display(slider_visual)


# Function to plot NQueensCSP in csp.py and NQueensProblem in search.py
def plot_NQueens(solution):
n = len(solution)
board = np.array([2 * int((i + j) % 2) for j in range(n) for i in range(n)]).reshape((n, n))
im = Image.open('images/queen_s.png')
height = im.size[1]
im = np.array(im).astype(np.float) / 255
fig = plt.figure(figsize=(7, 7))
ax = fig.add_subplot(111)
ax.set_title('{} Queens'.format(n))
plt.imshow(board, cmap='binary', interpolation='nearest')
# NQueensCSP gives a solution as a dictionary
if isinstance(solution, dict):
for (k, v) in solution.items():
newax = fig.add_axes([0.064 + (k * 0.112), 0.062 + ((7 - v) * 0.112), 0.1, 0.1], zorder=1)
newax.imshow(im)
newax.axis('off')
# NQueensProblem gives a solution as a list
elif isinstance(solution, list):
for (k, v) in enumerate(solution):
newax = fig.add_axes([0.064 + (k * 0.112), 0.062 + ((7 - v) * 0.112), 0.1, 0.1], zorder=1)
newax.imshow(im)
newax.axis('off')
fig.tight_layout()
plt.show()

Back | FazBrowse Home | New Git URL