constraint solving or >-> version of n-queens slow

Description

Since commit d67f6f8e1ac1038df767c2b655001dafd14d7af1 the following is now
very slow:
q:1..n >-> 1..n & !(i,j).(i:1..n & j:2..n & j>i => q+j-1 /= q(j) & q-j+1 /= q(j)) & n=12
(14 seconds instead of instantaneous)

d67f6f8e1ac1038df767c2b655001dafd14d7af1 is the first bad commit
commit d67f6f8e1ac1038df767c2b655001dafd14d7af1
Author: Michael Leuschel <leuschel@cs.uni-duesseldorf.de>
Date: Thu Nov 27 14:20:39 2014 +0100

SMT style FD labeling now also active in normal mode

all FD variables are kept in one list
we interleave FD labeling with waitflag grounding
we use clpfd_get_next_variable_to_label
requires change to test 1360

Environment

None

Attachments

2

Gliffy Diagrams

Activity

Show:

Michael Leuschel March 5, 2016 at 10:04 AM
Edited

It seems >->> is simply faster because it forces an enumeration from left to right.
:- block tbij(,?,?,?,?,?), tbij(?,?,,?,?,?).
tbij([],_,0,Dom,Ran,WF) :- empty_set_wf(Dom,WF),empty_set_wf(Ran,WF).
tbij([(X,Y)|T],SoFar,s(Card),Dom,Ran,WF) :- % prints(tbij(X,Y,T,s(Card))),
%not_element_of(X,SoFar), necessary ??
remove_element_wf(X,Dom,Dom2,WF), % instead of setup_domain, we could remove first element if X,Y are free
remove_element_wf(Y,Ran,Ran2,WF), % this forces an enumeration from left-to-right, as Ran is only set when previous element was enumerated
add_new_element_wf(Y,SoFar,SoFar2,WF),
not_element_of_wf(Y,SoFar,WF),
%prints(chooseY(Y,forx(X),Ran,Ran2,sofar(SoFar))), portray_waitflags(WF),nl,

Commit d67f6f8e1ac1038df767c2b655001dafd14d7af1 lead to a reverse in the FD variable list and means variables are prioritised backwards from before; meaning that here enumeration starts on column 12.
It is easer to solve the problem going from left to right here, the last column has no additional constraint attached to it; it can be freely chosen if the others are fixed.

Michael Leuschel March 5, 2016 at 9:18 AM

It seems related to enumeration order.
With -p RANDOMISE_ENUMERATION_ORDER TRUE it is generally much much faster.
The same problem with >->> is also much faster.

Michael Leuschel March 5, 2016 at 8:40 AM

This is actually not the n-Queens Problem, but a Variation thereof (generated by a typo).

Won't Fix

Details

Assignee

Reporter

Priority

Created March 4, 2016 at 3:03 PM
Updated April 18, 2016 at 8:44 AM
Resolved April 18, 2016 at 8:44 AM