labeling run out of stack

22 views
Skip to first unread message

Jörg

unread,
Feb 20, 2015, 3:34:35 AM2/20/15
to
pruefen([[A,0],[1,1],[B,0],[3,0],[_,1],[6,0],[C,0],[D,0],[E,0]]),labeling([ff],[A,B,C,D,E]).


hi! i got a list with variable. each variable can be a white or black field(st8ts). white field: [X,0] and black field:[X,1] a list could look like this:
[_,0],[_,0],[_,1],[_,1],[4,0],[_,0],[_,0],[7,1],[_,1]


first i set 3 constraints:

 pruefen(L):-
 
%exclude black and undefined lists
  exclude
(isBlackAndEmpty,L,NewList),
 
%Constraint 1 and 2, every list ins 1..9 and all different(list)
  constraintsFestlegen
(NewList),
 
%get list groups and set constraint(every white block cutted by black boxes has to be gapless)
  listGroupConstraints
(L).

i exclude all fields where i cant set the constraints (in my list are black and white fields, were undefined black fields cant get constraints)

the exclude predicate:

  %for the filter (exclude) excluse if field is black and undefined
  isBlackAndEmpty
([Variable|IsBlack]):-
 
IsBlack=:=1,
 
var(Variable).

set constraint 1 and 2 for the filtered list:

 %set constraints for whole list(black and undefined excluded)
  variablenListeErstellen
([],Variablen):-
     
%jede Liste darf nur aus Zahlen von 1..9 bestehen
     
Variablen ins 1..9,
     
%es dürfen in der Liste keine Zahlen doppelt vorkommen
     
%bibliothek von SWI-Prolog Bibliothek clpfd
      all_different
(Variablen),
     
print('\nListenconstraints:'),
     
print(Variablen).

the white fields in a list which are next to each other have to be gapless. so i filter the list for groups of white fields:

%ausstiegspunkt für eine leere liste
  listGroupConstraints
([]).
 
 
%for a list with a black field
  listGroupConstraints
(List):-
  append
(Prefix, [[_,1]|Rest],List),
 
%creates one dimensional list
  createOneDimensional
(Prefix,OneDimensionalList),
 
%rekursiv
  listGroupConstraints
(Rest).


   
%for a list without a black field
  listGroupConstraints
(List):-
 
%convert to one dimensional list
  createOneDimensional
(List,OneDimensionalList),
 
%set constraint for one dimensional list
  setGroupConstraints
(OneDimensionalList).

after that, i set the constraint 3 for each group(setGroupConstraint):

 
 %check if group is gapless,
  listl
(L) :-
   
[Fst,Lst] ins 1..9,
   
Fst #=< Lst,
   
Len #= Lst - Fst + 1,
    length
(L, Len),
    label
([Fst,Lst]),
    L ins
Fst..Lst,
    all_different
(L),
   
print('\n'),
   
print(L).


after i did this, i try to labeling all undefined variables in white fields:

pruefen([[A,0],[B,0],[_,1],[_,1],[4,0],[C,0],[D,0],[7,1],[_,1]]),labeling([ff],[A,B,C,D]).


if i call this. i run out of local stack. any ideas?

but if i call, all works fine.pruefen([[A,0],[1,1],[B,0],[3,0],[_,1],[6,0],[C,0],[D,0],[E,0]]),labeling([ff],[A,B,C,D,E]).

straights.pl

Jan Wielemaker

unread,
Feb 20, 2015, 8:11:07 AM2/20/15
to Jörg, swi-p...@googlegroups.com
There are roughly two reasons for running out of local stack. The most
common is unbound recursion. The other is creating too many
choicepoints. If you run under the (graphical) debugger, you'll
typically recognise unbound recursion as a very deep stack not making
any progress.

For finding whether you have too many choicepoints, you'll either have
to do a little math to make an estimate how many you have or you can see
what happens if you give it more stack. That only works on 64-bit
systems as the it uses its max if 128Mb on 32-bit systems already.
On a 64bit system you can do e.g.:

?- set_prolog_stack(local, limit(1 000 000 000)).

To have 1Gb rather then the default 256Mb. There is no (practical)
limit on 64-bit systems except for the amount of memory you have.

Success --- Jan

On 02/20/2015 09:34 AM, Jörg wrote:
> hi! i got a list with variable. each variable can be a white or black
> field(st8ts <http://www.str8ts.com/weekly_str8ts.asp>). white field:
> [X,0] and black field:[X,1] a list could look like this:
> |
> [_,0],[_,0],[_,1],[_,1],[4,0],[_,0],[_,0],[7,1],[_,1]
> |
>
>
> first i set 3 constraints:
>
> |
> pruefen(L):-
> %exclude black andundefinedlists
> exclude(isBlackAndEmpty,L,NewList),
> %Constraint1and2,every list ins 1..9andall different(list)
> constraintsFestlegen(NewList),
> %getlist groups andsetconstraint(every white block cutted byblack boxes
> has to be gapless)
> listGroupConstraints(L).
> |
>
> i exclude all fields where i cant set the constraints (in my list are
> black and white fields, were undefined black fields cant get constraints)
>
> the exclude predicate:
>
> |
> %forthe filter (exclude)excluse iffield isblack andundefined
> isBlackAndEmpty([Variable|IsBlack]):-
> IsBlack=:=1,
> var(Variable).
> |
>
> set constraint 1 and 2 for the filtered list:
>
> |
> %setconstraints forwhole list(black andundefinedexcluded)
> variablenListeErstellen([],Variablen):-
> %jede Listedarf nur aus Zahlenvon 1..9bestehen
> Variablenins 1..9,
> %es dürfen inder Listekeine Zahlendoppelt vorkommen
> %bibliothek von SWI-PrologBibliothekclpfd
> all_different(Variablen),
> print('\nListenconstraints:'),
> print(Variablen).
> |
>
> the white fields in a list which are next to each other have to be
> gapless. so i filter the list for groups of white fields:
>
> |
> %ausstiegspunkt für eine leere liste
> listGroupConstraints([]).
>
> %fora list witha black field
> listGroupConstraints(List):-
> append(Prefix,[[_,1]|Rest],List),
> %creates one dimensional list
> createOneDimensional(Prefix,OneDimensionalList),
> %rekursiv
> listGroupConstraints(Rest).
>
>
> %fora list without a black field
> listGroupConstraints(List):-
> %convert to one dimensional list
> createOneDimensional(List,OneDimensionalList),
> %setconstraint forone dimensional list
> setGroupConstraints(OneDimensionalList).
> |
>
> after that, i set the constraint 3 for each group(setGroupConstraint):
>
> |
> %check ifgroupisgapless,
> listl(L):-
> [Fst,Lst]ins 1..9,
> Fst#=< Lst,
> Len#= Lst - Fst + 1,
> length(L,Len),
> label([Fst,Lst]),
> L ins Fst..Lst,
> all_different(L),
> print('\n'),
> print(L).
>
> |
>
> after i did this, i try to labeling all undefined variables in white fields:
>
> |
> pruefen([[A,0],[B,0],[_,1],[_,1],[4,0],[C,0],[D,0],[7,1],[_,1]]),labeling([ff],[A,B,C,D]).
> |
>
>
> if i call this. i run out of local stack. any ideas?
>
> --
> You received this message because you are subscribed to the Google
> Groups "SWI-Prolog" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to swi-prolog+...@googlegroups.com
> <mailto:swi-prolog+...@googlegroups.com>.
> Visit this group at http://groups.google.com/group/swi-prolog.
> For more options, visit https://groups.google.com/d/optout.

Jörg

unread,
Feb 20, 2015, 11:36:32 AM2/20/15
to bauer...@googlemail.com
list for constraint 1 and 2: <-- all different, ins 1..9
[_G1610,_G1619,4,_G1655,_G1664,7]


white field group <-- gapless 
[_G1610,_G1619]


white field group 
<--- gapless
[4,_G1655,_G1664]


and then labeling([ff], [_G1610,_G1619,_G1655,_G1664]
after labeling i get following output:
could you tell whats happening here?

[1]
[2]
[3]
[4]
[5]
[6]
[7]
[8]
[9]
[1]
[1]
[2]
[2]
[3]
[3]
[4]
[4]
[5]
[5]
[6]
[6]
[7]
[7]
[8]
[8]
[9]
[9]
[_G9095,_G9101]
[_G9095,_G9101]
[_G9095,_G9101]
[_G9095,_G9101]
[_G9095,_G9101]
[_G9095,_G9101]
[_G9095,_G9101]
[_G9095,_G9101]
[_G9095,_G9101]
[_G9095,_G9101]
[_G1531,_G1534]
[_G1531,_G1534]
[_G1531,_G1534]
[_G1531,_G1534]
[_G1531,_G1534]
[_G1531,_G1534]
[_G1531,_G1534,_G1537]
[_G1531,_G1534,_G1537]
[_G1531,_G1534,_G1537]
[_G1531,_G1534,_G1537]
[_G1531,_G1534,_G1537]
[_G1531,_G1534,_G1537]
[_G1531,_G1534,_G1537]
[_G1531,_G1534,_G1537]
[_G1531,_G1534,_G1537]
[_G1531,_G1534,_G1537]
[_G1531,_G1534,_G1537]
[_G1531,_G1534,_G1537]
[_G1531,_G1534,_G1537]
[_G1531,_G1534,_G1537]
[_G1531,_G1534,_G1537]
[_G1531,_G1534,_G1537]
[_G1531,_G1534,_G1537]
[_G1531,_G1534,_G1537]
[_G1531,_G1534,_G1537]
[_G1531,_G1534,_G1537]
[_G1531,_G1534,_G1537]
[_G1531,_G1534,_G1537]
[_G1531,_G1534,_G1537]
[_G1531,_G1534,_G1537]
[_G1531,_G1534,_G1537]
[_G1531,_G1534,_G1537]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555,_G1561]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555,_G1561]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555,_G1561]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555,_G1561]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555,_G1561]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555,_G1561]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555,_G1561]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555,_G1561]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555,_G1561]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555,_G1561]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555,_G1561]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555,_G1561]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555,_G1561,_G1567]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555,_G1561,_G1567]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555,_G1561,_G1567]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555,_G1561,_G1567]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555,_G1561,_G1567]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555,_G1561,_G1567]
[_G1531,_G1534,_G1537,_G1543,_G1549,_G1555,_G1561,_G1567,_G1573]
Reply all
Reply to author
Forward
0 new messages