Changeset 4416 for trunk/examples
- Timestamp:
- 08/10/08 06:25:36 (5 months ago)
- Location:
- trunk/examples/constraints/swipl
- Files:
-
- 2 modified
-
queens.lgt (modified) (4 diffs)
-
SCRIPT.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
trunk/examples/constraints/swipl/queens.lgt
r4415 r4416 10 10 :- use_module(clpfd, [ins/2, labeling/2, (#=)/2, (#\=)/2, (#<==>)/2]). 11 11 12 :- public( show/3).12 :- public([n_queens/2, show/3]). 13 13 14 14 /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - … … 78 78 79 79 postscript --> 80 "systemdict /.setlanguagelevel known { 2 .setlanguagelevel} if \81 /init { /N exch def 322 N div dup scale -1 -1 translate \80 "systemdict /.setlanguagelevel known { 2 .setlanguagelevel} if \ 81 /init { /N exch def 322 N div dup scale -1 -1 translate \ 82 82 /Palatino-Roman findfont 0.8 scalefont setfont \ 83 83 0 setlinewidth \ 84 84 1 1 N { 1 1 N { 1 index c } for pop } for } bind def \ 85 /showtext { 0.5 0.28 translate dup stringwidth pop -2 div 0 moveto \85 /showtext { 0.5 0.28 translate dup stringwidth pop -2 div 0 moveto \ 86 86 1 setgray show} bind def \ 87 /i { gsave translate .5 setgray 0 0 1 1 4 copy rectfill 0 setgray rectstroke \88 grestore } bind def \89 /q { gsave translate 0 0 1 1 rectfill (Q) showtext grestore } bind def \90 /c { gsave translate 1 setgray 0 0 1 1 4 copy rectfill 0 setgray rectstroke \91 grestore } bind def\n".87 /i { gsave translate .5 setgray 0 0 1 1 4 copy rectfill 0 setgray rectstroke \ 88 grestore } bind def \ 89 /q { gsave translate 0 0 1 1 rectfill (Q) showtext grestore } bind def \ 90 /c { gsave translate 1 setgray 0 0 1 1 4 copy rectfill 0 setgray rectstroke \ 91 grestore } bind def\n". 92 92 93 93 … … 97 97 98 98 show(N, Options, Qs) :- 99 between(1, infinite, N), 99 100 open(pipe('gs -dNOPAUSE -g680x680 -dGraphicsAlphaBits=2 -r151 -q -'), write, 100 Out, [buffer(false),alias(gs)]),101 Out, [buffer(false),alias(gs)]), 101 102 tell(Out), 102 integer(N), N > 0,103 103 phrase(postscript, Ps), 104 104 format(Ps), 105 105 format("~w init\n", [N]), 106 106 n_queens(N, Qs), 107 animate(Qs), 108 labeling(Options, Qs), 109 finish. 110 show(_, _, _) :- finish, close(gs), fail. 107 call_cleanup(((animate(Qs),labeling(Options, Qs),finish)), close(gs)). 111 108 112 109 finish :- … … 114 111 % fill the buffer to make 'gs' process all generated output 115 112 ignore((between(1,500,_), 116 format("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"),117 fail)),113 format("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n"), 114 fail)), 118 115 flush_output. 119 116 120 121 %?- between(0, inf, N), show(N, [ff], Qs). 117 %?- show(N, [ff], Qs). 122 118 123 119 %?- show(8, [ff], Qs). -
trunk/examples/constraints/swipl/SCRIPT.txt
r4415 r4416 61 61 62 62 63 | ?- queens::n_queens(8, Qs), labeling([ff], Qs). 64 Qs = [1, 5, 8, 6, 3, 7, 2, 4] ; 65 Qs = [1, 6, 8, 3, 7, 4, 2, 5] ; 66 Qs = [1, 7, 4, 6, 8, 2, 5, 3] ; 67 (etc) 68 69 63 70 % the following query implies that Ghostscript is available from the command-line: 64 71 65 72 | ?- queens::show(8, [ff], Qs). 66 67 73 Qs = [1, 5, 8, 6, 3, 7, 2, 4] ; 68 74 Qs = [1, 6, 8, 3, 7, 4, 2, 5] ; 69 75 Qs = [1, 7, 4, 6, 8, 2, 5, 3] ; 70 Qs = [1, 7, 5, 8, 2, 4, 6, 3] ;71 76 (etc) 77 78 79 | ?- queens::show(N, [ff], Qs). 80 N = 1, 81 Qs = [1] ; 82 N = 4, 83 Qs = [2, 4, 1, 3] ; 84 N = 4, 85 Qs = [3, 1, 4, 2] ; 86 N = 5, 87 Qs = [1, 3, 5, 2, 4] ; 88 (etc)
