Skip to content
Snippets Groups Projects
Commit 88d935a3 authored by Michael Leuschel's avatar Michael Leuschel
Browse files

add goto -1 before setup constants

parent 9bdd050c
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# Peaceable Armies of Queens
Use `:help` to get an overview for the jupyter notebook commands. If you need more insight on how to use this tool, consider reading *ProB Jupyter Notebook Overview*.
The paper [Models and symmetry breaking for 'peaceable armies of queens'](https://link.springer.com/chapter/10.1007/978-3-540-24664-0_19) by Smith, Petrie and Gent describes a challenging constraint programming problem.
A variation of the problem can be found on page 329 of the [Handbook on Constraint Programming](https://www.elsevier.com/books/handbook-of-constraint-programming/rossi/978-0-444-52726-4).
The challenge is to place two equal-sized armies of white and black queens onto a chessboard. We can distinguish between two problems:
* checking whether two armies of n queens can be placed on a dim*dim chessboard,
* for a given board of size dim*dim find the maximal size n of armies that can be placed onto the board, i.e., solving an optimisation problem.
In this notebook, we take a look at both of the problems and visualize them with the `ANIMATION_FUNCTION`.
%% Cell type:markdown id: tags:
## Checking
First we will take a look at the model for the checking problem. This problem is quite straightforward to encode in B. Most of the lines in the DEFINITIONS section are for our visualization with the `ANIMATION_FUNCTION`.
We will load (`::load`), set up the constants (`:constants`), and initialize the machine (`:init`), before we visualize it (`:show`).
%% Cell type:code id: tags:
``` prob
::load
MACHINE JustQueens
DEFINITIONS
SET_PREF_TIME_OUT == 1000000;
SET_PREF_MAX_INITIALISATIONS == 1;
ANIMATION_IMG0 == "images/ChessPieces/Chess_emptyl45.gif";
ANIMATION_IMG1 == "images/ChessPieces/Chess_emptyd45.gif";
ANIMATION_IMG2 == "images/ChessPieces/Chess_qdl45.gif";
ANIMATION_IMG3 == "images/ChessPieces/Chess_qdd45.gif";
ANIMATION_IMG6 == "images/ChessPieces/Chess_qll45.gif";
ANIMATION_IMG7 == "images/ChessPieces/Chess_qld45.gif";
BWOFFSET(xx,yy) == (xx+yy) mod 2;
ANIMATION_FUNCTION_DEFAULT == ( {r,c,i|r:1..dim & c:1..dim & i=(r+c) mod 2 } );
ANIMATION_FUNCTION == ( UNION(k).(k:1..n| {(blackc(k),blackr(k),2+BWOFFSET(blackc(k),blackr(k)))}) \/
UNION(k).(k:1..n| {(whitec(k),whiter(k),6+BWOFFSET(whitec(k),whiter(k)))}) );
ORDERED(c,r) == (!i.(i:1..(n-1) => c(i) <= c(i+1)) &
!i.(i:1..(n-1) => (c(i)=c(i+1) => r(i) < r(i+1))))
CONSTANTS n, dim, blackc, blackr, whitec, whiter
PROPERTIES
n = 8 & dim = 8 &
blackc : 1..n --> 1..dim &
whitec : 1..n --> 1..dim &
blackr : 1..n --> 1..dim &
whiter : 1..n --> 1..dim &
ORDERED(blackc,blackr) & /* ensures proper ordering + that we do not place two queens on same square */
ORDERED(whitec,whiter) &
!(i,j).(i:1..n & j:1..n => blackc(i) /= whitec(j)) &
!(i,j).(i:1..n & j:1..n => blackr(i) /= whiter(j)) &
!(i,j).(i:1..n & j:1..n => blackr(i) /= whiter(j) + (blackc(i)-whitec(j))) &
!(i,j).(i:1..n & j:1..n => blackr(i) /= whiter(j) - (blackc(i)-whitec(j))) &
whitec(1) < blackc(1) /* symmetry breaking */
END
```
%% Output
Loaded machine: JustQueens
%% Cell type:code id: tags:
``` prob
:constants
```
%% Output
Machine constants set up using operation 0: $setup_constants()
%% Cell type:code id: tags:
``` prob
:init
```
%% Output
Machine initialised using operation 1: $initialise_machine()
%% Cell type:code id: tags:
``` prob
:show
```
%% Output
<table style="font-family:monospace"><tbody>
<tr>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="6" src="images/ChessPieces/Chess_qll45.gif"/></td>
<td style="padding:0px"><img alt="7" src="images/ChessPieces/Chess_qld45.gif"/></td>
</tr>
<tr>
<td style="padding:0px"><img alt="3" src="images/ChessPieces/Chess_qdd45.gif"/></td>
<td style="padding:0px"><img alt="2" src="images/ChessPieces/Chess_qdl45.gif"/></td>
<td style="padding:0px"><img alt="3" src="images/ChessPieces/Chess_qdd45.gif"/></td>
<td style="padding:0px"><img alt="2" src="images/ChessPieces/Chess_qdl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
</tr>
<tr>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="3" src="images/ChessPieces/Chess_qdd45.gif"/></td>
<td style="padding:0px"><img alt="2" src="images/ChessPieces/Chess_qdl45.gif"/></td>
<td style="padding:0px"><img alt="3" src="images/ChessPieces/Chess_qdd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
</tr>
<tr>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="7" src="images/ChessPieces/Chess_qld45.gif"/></td>
<td style="padding:0px"><img alt="6" src="images/ChessPieces/Chess_qll45.gif"/></td>
</tr>
<tr>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="7" src="images/ChessPieces/Chess_qld45.gif"/></td>
</tr>
<tr>
<td style="padding:0px"><img alt="3" src="images/ChessPieces/Chess_qdd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
</tr>
<tr>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="6" src="images/ChessPieces/Chess_qll45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
</tr>
<tr>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="7" src="images/ChessPieces/Chess_qld45.gif"/></td>
<td style="padding:0px"><img alt="6" src="images/ChessPieces/Chess_qll45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
</tr>
</tbody></table>
<Animation function visualisation>
%% Cell type:markdown id: tags:
### Setting up constants
This machine is a great one to understand setting up various constants within jupyter notebook.
If you reload the machine (by pressing `SHIFT`+`ENTER` in the code cell with our machine code) you can change the constants for the queens to change their positions on the board.
Try it out! Reload the machine and run the next cell. Then, initialise and visualise as ususal.
You can change the collums of the queens with the constants `blackc`/`whitec` and the rows with the constants `blackr`/`whiter`.
%% Cell type:code id: tags:
``` prob
:goto -1
```
%% Output
Changed to state with index -1
%% Cell type:code id: tags:
``` prob
:constants blackc(2)=2 & blackr(2)=6
```
%% Output
Machine constants set up using operation 0: $setup_constants()
Machine constants set up using operation 2: $setup_constants()
%% Cell type:code id: tags:
``` prob
:goto -1
```
%% Output
Changed to state with index -1
%% Cell type:code id: tags:
``` prob
:constants whitec(2)=4 & whiter(2)=4
```
%% Output
Machine constants set up using operation 0: $setup_constants()
Machine constants set up using operation 4: $setup_constants()
%% Cell type:code id: tags:
``` prob
:init
```
%% Output
Machine initialised using operation 1: $initialise_machine()
Machine initialised using operation 5: $initialise_machine()
%% Cell type:code id: tags:
``` prob
:show
```
%% Output
<table style="font-family:monospace"><tbody>
<tr>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="6" src="images/ChessPieces/Chess_qll45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
</tr>
<tr>
<td style="padding:0px"><img alt="3" src="images/ChessPieces/Chess_qdd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="3" src="images/ChessPieces/Chess_qdd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
</tr>
<tr>
<td style="padding:0px"><img alt="2" src="images/ChessPieces/Chess_qdl45.gif"/></td>
<td style="padding:0px"><img alt="3" src="images/ChessPieces/Chess_qdd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
</tr>
<tr>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="6" src="images/ChessPieces/Chess_qll45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="6" src="images/ChessPieces/Chess_qll45.gif"/></td>
<td style="padding:0px"><img alt="7" src="images/ChessPieces/Chess_qld45.gif"/></td>
<td style="padding:0px"><img alt="6" src="images/ChessPieces/Chess_qll45.gif"/></td>
</tr>
<tr>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="6" src="images/ChessPieces/Chess_qll45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="6" src="images/ChessPieces/Chess_qll45.gif"/></td>
<td style="padding:0px"><img alt="7" src="images/ChessPieces/Chess_qld45.gif"/></td>
</tr>
<tr>
<td style="padding:0px"><img alt="3" src="images/ChessPieces/Chess_qdd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="3" src="images/ChessPieces/Chess_qdd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
</tr>
<tr>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="3" src="images/ChessPieces/Chess_qdd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
</tr>
<tr>
<td style="padding:0px"><img alt="3" src="images/ChessPieces/Chess_qdd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
</tr>
</tbody></table>
<Animation function visualisation>
%% Cell type:markdown id: tags:
## Optimization
One can obviously use the above model to try and manually find a maximal value of n for a given board size dim. Below, we have encoded this process as B constraints, by setting up the problem twice: once for the army size n and a second time for army size n+1. The second encoding is wrapped into a negated existential quantification.
ProB solves this optimisation problem in about 660 seconds for a board size of 8. This is very competitive with the timings reported in the above mentioned constraint solving paper using new symmetry breaking techniques and much more low-level encoding on state of the art constraint solving libraries such as ILOG.
To find out how long our jupyter notebook kernel needs to run this, we can use the command `:time`:
Times and specs:
```
Acer TravelMate X349-G2-M,
8 GB RAM,
Intel(R) Core(TM) i5-7200U CPU @ 2.50GHz 2.70 GHz Prozessor,
Windows 10 OS
dim=5 --> optimum n=4 0.326799900 secs
dim=6 --> optimum n=5 0.954069900 secs
dim=7 --> optimum n=7 19.829867700 secs
dim=8 --> optimum n=9 658.281314000 secs
```
If you want to check out the optimization for dim=5, dim=6, dim=8, you can do so by changing the constant in the `PROPERTIES` section of the machine code cell.
*EDITOR'S NOTE* : 660 seconds are 11 minutes, and that is why we only recomment to work with dim=5, dim=6 and dim=7 for the purposes of this notebook. However, if you really want to try out dim=8... You know how to.
%% Cell type:code id: tags:
``` prob
::load
MACHINE JustQueens_FindOptimal_CBC
DEFINITIONS
SET_PREF_TIME_OUT == 1000000;
SET_PREF_MAX_INITIALISATIONS == 1;
ANIMATION_IMG0 == "images/ChessPieces/Chess_emptyl45.gif";
ANIMATION_IMG1 == "images/ChessPieces/Chess_emptyd45.gif";
ANIMATION_IMG2 == "images/ChessPieces/Chess_qdl45.gif";
ANIMATION_IMG3 == "images/ChessPieces/Chess_qdd45.gif";
ANIMATION_IMG6 == "images/ChessPieces/Chess_qll45.gif";
ANIMATION_IMG7 == "images/ChessPieces/Chess_qld45.gif";
BWOFFSET(xx,yy) == (xx+yy) mod 2;
ANIMATION_FUNCTION_DEFAULT == ( {r,c,i|r:1..dim & c:1..dim & i=(r+c) mod 2 } );
ANIMATION_FUNCTION == ( UNION(k).(k:1..n| {(blackc(k),blackr(k),2+BWOFFSET(blackc(k),blackr(k)))}) \/
UNION(k).(k:1..n| {(whitec(k),whiter(k),6+BWOFFSET(whitec(k),whiter(k)))}) );
ORDERED(c,r,nn) == (!i.(i:1..(nn-1) => c(i) <= c(i+1)) &
!i.(i:1..(nn-1) => (c(i)=c(i+1) => r(i) < r(i+1))));
CHECK_TYPE(bc,br,wc,wr,nn) == (
bc : 1..nn --> 1..dim &
wc : 1..nn --> 1..dim &
br : 1..nn --> 1..dim &
wr : 1..nn --> 1..dim );
CHECK_DIAGONALS(bc,br,wc,wr,nn) == (
!(i,j).(i:1..nn & j:1..nn => bc(i) /= wc(j)) &
!(i,j).(i:1..nn & j:1..nn => br(i) /= wr(j)) &
!(i,j).(i:1..nn & j:1..nn => br(i) /= wr(j) + (bc(i)-wc(j))) &
!(i,j).(i:1..nn & j:1..nn => br(i) /= wr(j) - (bc(i)-wc(j)))
)
CONSTANTS n, dim, blackc, blackr, whitec, whiter
PROPERTIES
n : 1..16 & dim = 7 & // <------------------------------------YOU CAN CHANGE dim HERE
CHECK_TYPE(blackc, blackr, whitec, whiter, n) &
ORDERED(blackc,blackr,n) & /* ensures proper ordering + that we do not place two queens on same square */
ORDERED(whitec,whiter,n) &
CHECK_DIAGONALS(blackc, blackr, whitec, whiter, n) &
whitec(1) < blackc(1) /* symmetry breaking */ &
/* Repeat constraints for n+1 and assert that it cannot be solved */
not( #(n1,blackc1, blackr1, whitec1, whiter1).
(n1=n+1 & /* n1:2..17 & */
CHECK_TYPE(blackc1, blackr1, whitec1, whiter1, n1) &
ORDERED(blackc1,blackr1,n1) & /* ensures proper ordering + that we do not place two queens on same square */
ORDERED(whitec1,whiter1,n1) &
CHECK_DIAGONALS(blackc1, blackr1, whitec1, whiter1, n1) &
whitec1(1) < blackc1(1) /* symmetry breaking */
)
)
END
```
%% Output
Loaded machine: JustQueens_FindOptimal_CBC
%% Cell type:code id: tags:
``` prob
:time :constants
```
%% Output
Execution time: 17.606007400 seconds
Execution time: 10.936093583 seconds
Machine constants set up using operation 0: $setup_constants()
%% Cell type:code id: tags:
``` prob
:init
```
%% Output
Machine initialised using operation 1: $initialise_machine()
%% Cell type:code id: tags:
``` prob
n
```
%% Output
$7$
7
%% Cell type:code id: tags:
``` prob
:show
```
%% Output
<table style="font-family:monospace"><tbody>
<tr>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="7" src="images/ChessPieces/Chess_qld45.gif"/></td>
<td style="padding:0px"><img alt="6" src="images/ChessPieces/Chess_qll45.gif"/></td>
<td style="padding:0px"><img alt="7" src="images/ChessPieces/Chess_qld45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
</tr>
<tr>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="2" src="images/ChessPieces/Chess_qdl45.gif"/></td>
<td style="padding:0px"><img alt="3" src="images/ChessPieces/Chess_qdd45.gif"/></td>
</tr>
<tr>
<td style="padding:0px"><img alt="6" src="images/ChessPieces/Chess_qll45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="7" src="images/ChessPieces/Chess_qld45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
</tr>
<tr>
<td style="padding:0px"><img alt="7" src="images/ChessPieces/Chess_qld45.gif"/></td>
<td style="padding:0px"><img alt="6" src="images/ChessPieces/Chess_qll45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
</tr>
<tr>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="2" src="images/ChessPieces/Chess_qdl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
</tr>
<tr>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="3" src="images/ChessPieces/Chess_qdd45.gif"/></td>
<td style="padding:0px"><img alt="2" src="images/ChessPieces/Chess_qdl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
</tr>
<tr>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="1" src="images/ChessPieces/Chess_emptyd45.gif"/></td>
<td style="padding:0px"><img alt="0" src="images/ChessPieces/Chess_emptyl45.gif"/></td>
<td style="padding:0px"><img alt="3" src="images/ChessPieces/Chess_qdd45.gif"/></td>
<td style="padding:0px"><img alt="2" src="images/ChessPieces/Chess_qdl45.gif"/></td>
</tr>
</tbody></table>
<Animation function visualisation>
%% Cell type:code id: tags:
``` prob
```
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment