Comments (1)
The BDD is represented with complemented edges. Considering a node labeled by a variable x
, the outgoing solid edge corresponds to the case x = TRUE
, and a dashed outgoing edge to the case x = FALSE
. A dashed edge annotated with -1
is a complemented edge, in the sense that it references the negation of the node it points to. For example, a dashed edge pointing to the node labeled with "True" references TRUE
, whereas a dashed edge annotated with -1
that points to "True" references FALSE
. A more detailed description can be found in Sec. 2.3 of "Binary decision diagrams" by Fabio Somenzi, and in the documentation of plotting.
The variables for the row with index 0 and the column with index 0 appear to be missing from the image. For example, the variables declared include x00
for all problem instances (range
):
These variables are included in the formulas:
For the case of n = 3
, the BDD manager I obtain is:
The problem is solved for an n
-by-n
chessboard, where n
the argument of the function solve_queens
:
Running the script queens.py
solves the problem for the range of sizes `0..n_max:
https://github.com/johnyf/dd/blob/954c7045ae4a62a50ebc2d5ee063e703cc5307a5/examples/queens.py#L139
Adding the statements:
print(bdd.count(u))
print(list(bdd.pick_iter(u)))
after the line:
https://github.com/johnyf/dd/blob/954c7045ae4a62a50ebc2d5ee063e703cc5307a5/examples/queens.py#L120
shows the number of solutions, and the solutions as assignments to the variables xij
. The results I obtain are:
n = 0
: satisfiable (no variables declared, "zero" size chessboard)n = 1
: satisfiable, with a single solution (one queen on a chessboard with one square)n = 2
: unsatisfiable (two queens cannot be placed on a 2-by-2 chessboard without interference)n = 3
: unsatisfiable (three queens cannot be placed on a 3-by-3 chessboard without interference)n = 4
: satisfiable, with two solutions, which are symmetric with respect to the symmetries of the chessboard (rotation around the horizontal and vertical axes at the middle of the chessboard, and the diagonals of the chessboard).
The cases of n = 2
and n = 3
can be confirmed by drawing a 2-by-2 and a 3-by-3 chessboard and trying to place on them 2 and 3 queens, respectively.
The solutions for n = 4
can be read in the output of print(list(bdd.pick_iter(u)))
(from above), namely:
[{'x01': False, 'x31': True, 'x23': True, 'x20': False,
'x12': False, 'x11': False, 'x13': False, 'x32': False,
'x22': False, 'x30': False, 'x21': False, 'x02': True,
'x33': False, 'x00': False, 'x10': True, 'x03': False},
{'x01': True, 'x31': False, 'x23': False, 'x20': True,
'x12': False, 'x11': False, 'x13': True, 'x32': True,
'x22': False, 'x30': False, 'x21': False, 'x02': False,
'x33': False, 'x00': False, 'x10': False, 'x03': False}]
For example, the assignment 'x31': True
means that a queen is present in the square at row 3 and column 1. The assignment 'x01': False
means that there is no queen in the square at row 0 and column 1.
The reference for the N
-queens problem mentioned in the docstring of the script queens.py
is Sec. 6.1 of "An introduction to binary decision diagrams" by Henrik Andersen.
from dd.
Related Issues (20)
- Understanding of BDD generated diagram HOT 2
- Quantifying multi-state reliability with MDDs HOT 1
- Question: Referencing children node in an MDD HOT 3
- Question: Recursive function for MDDs HOT 3
- use memory size prefixes consistently HOT 2
- install cudd using --fetch or using existing cudd build directory not working HOT 1
- Support for pure-Python ZDD implementation. HOT 2
- Question: MDD Method that returns the level of a node? HOT 1
- "bdd.let" does not work with substitutions with overlapping variables HOT 1
- Maximum expression length for autoref.BDD.add_expr() HOT 2
- using dd package properly HOT 1
- `cudd.to_expr` does not produce the correct result after reordering HOT 4
- Python 3.10 HOT 2
- AssertionError when using let HOT 2
- Question: Conversion function returning empty DiGraph
- REL: specify Python version using `Requires-Python`, not Trove classifiers for second numeric component HOT 1
- SetuptoolsDeprecationWarning: The license_file parameter is deprecated, use license_files instead HOT 5
- --install-option does not work anymore in requirements.txt HOT 6
- Fault Tree minimum cut sets using zBDD HOT 8
- NeedsReordering exception HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from dd.