networkx 2.8.2 Pypi GitHub Homepage
Other Docs

This module gives a generator for n-Sudoku graphs. It can be used to develop algorithms for solving or generating Sudoku puzzles.

A completed Sudoku grid is a 9x9 array of integers between 1 and 9, with no number appearing twice in the same row, column, or 3x3 box.

+---------+---------+---------+ | | 8 6 4 | | 3 7 1 | | 2 5 9 | | | 3 2 5 | | 8 4 9 | | 7 6 1 | | | 9 7 1 | | 2 6 5 | | 8 4 3 | +---------+---------+---------+ | | 4 3 6 | | 1 9 2 | | 5 8 7 | | | 1 9 8 | | 6 5 7 | | 4 3 2 | | | 2 5 7 | | 4 8 3 | | 9 1 6 | +---------+---------+---------+ | | 6 8 9 | | 7 3 4 | | 1 2 5 | | | 7 1 3 | | 5 2 8 | | 6 9 4 | | | 5 4 2 | | 9 1 6 | | 3 7 8 | +---------+---------+---------+

The Sudoku graph is an undirected graph with 81 vertices, corresponding to the cells of a Sudoku grid. It is a regular graph of degree 20. Two distinct vertices are adjacent if and only if the corresponding cells belong to the same row, column, or box. A completed Sudoku grid corresponds to a vertex coloring of the Sudoku graph with nine colors.

More generally, the n-Sudoku graph is a graph with n^4 vertices, corresponding to the cells of an n^2 by n^2 grid. Two distinct vertices are adjacent if and only if they belong to the same row, column, or n by n box.

Generator for Sudoku graphs

Generator for Sudoku graphs

This module gives a generator for n-Sudoku graphs. It can be used to develop algorithms for solving or generating Sudoku puzzles.

A completed Sudoku grid is a 9x9 array of integers between 1 and 9, with no number appearing twice in the same row, column, or 3x3 box.

+---------+---------+---------+ | | 8 6 4 | | 3 7 1 | | 2 5 9 | | | 3 2 5 | | 8 4 9 | | 7 6 1 | | | 9 7 1 | | 2 6 5 | | 8 4 3 | +---------+---------+---------+ | | 4 3 6 | | 1 9 2 | | 5 8 7 | | | 1 9 8 | | 6 5 7 | | 4 3 2 | | | 2 5 7 | | 4 8 3 | | 9 1 6 | +---------+---------+---------+ | | 6 8 9 | | 7 3 4 | | 1 2 5 | | | 7 1 3 | | 5 2 8 | | 6 9 4 | | | 5 4 2 | | 9 1 6 | | 3 7 8 | +---------+---------+---------+

The Sudoku graph is an undirected graph with 81 vertices, corresponding to the cells of a Sudoku grid. It is a regular graph of degree 20. Two distinct vertices are adjacent if and only if the corresponding cells belong to the same row, column, or box. A completed Sudoku grid corresponds to a vertex coloring of the Sudoku graph with nine colors.

More generally, the n-Sudoku graph is a graph with n^4 vertices, corresponding to the cells of an n^2 by n^2 grid. Two distinct vertices are adjacent if and only if they belong to the same row, column, or n by n box.

References

            <Unimplemented 'footnote' '.. [1] Herzberg, A. M., & Murty, M. R. (2007). Sudoku squares and chromatic\n    polynomials. Notices of the AMS, 54(6), 708-717.'>
           
            <Unimplemented 'footnote' '.. [2] Sander, Torsten (2009), "Sudoku graphs are integral",\n    Electronic Journal of Combinatorics, 16 (1): Note 25, 7pp, MR 2529816'>
           
            <Unimplemented 'footnote' '.. [3] Wikipedia contributors. "Glossary of Sudoku." Wikipedia, The Free\n    Encyclopedia, 3 Dec. 2019. Web. 22 Dec. 2019.'>
           

Examples

See :

Local connectivity graph

Hover to see nodes names; edges to Self not shown, Caped at 50 nodes.

Using a canvas is more power efficient and can get hundred of nodes ; but does not allow hyperlinks; , arrows or text (beyond on hover)

SVG is more flexible but power hungry; and does not scale well to 50 + nodes.

All aboves nodes referred to, (or are referred from) current nodes; Edges from Self to other have been omitted (or all nodes would be connected to the central node "self" which is not useful). Nodes are colored by the library they belong to, and scaled with the number of references pointing them


GitHub : /networkx/generators/sudoku.py#0
type: <class 'module'>
Commit: