Changeset 4418 for trunk/examples

Show
Ignore:
Timestamp:
08/10/08 08:22:01 (5 months ago)
Author:
pmoura
Message:

Updated the SWI-Prolog and YAP constraint examples with the help of Markus Triska.

Location:
trunk/examples/constraints
Files:
3 added
3 modified

Legend:

Unmodified
Added
Removed
  • trunk/examples/constraints/swipl/sudoku.lgt

    r4415 r4418  
    2222        length(Rows, 9), maplist(length_(9), Rows), 
    2323        append(Rows, Vs), Vs ins 1..9, 
    24         map_all_different(Rows), 
    25         transpose(Rows, Columns), map_all_different(Columns), 
     24        maplist(clpfd:all_different, Rows), 
     25        transpose(Rows, Columns), maplist(clpfd:all_different, Columns), 
    2626        Rows = [A,B,C,D,E,F,G,H,I], 
    2727        blocks(A, B, C), blocks(D, E, F), blocks(G, H, I). 
     
    150150             [_,_,_,_,_,1,_,3,_]]. 
    151151 
    152     map_all_different([]). 
    153     map_all_different([Head| Tail]) :- 
    154         all_different(Head), 
    155         map_all_different(Tail). 
    156  
    157152    %?- show([ff], Rows). 
    158153 
  • trunk/examples/constraints/yap/loader.lgt

    r4415 r4418  
    22:- initialization(( 
    33    use_module(library(clpfd)), 
    4     logtalk_load(puzzle))). 
     4    logtalk_load(library(metapredicates_loader)), 
     5    logtalk_load([hexagon, queens, puzzle, sudoku]))). 
  • trunk/examples/constraints/yap/SCRIPT.txt

    r4415 r4418  
    1616 
    1717 
     18% change the default term writing depth: 
     19 
     20| ?- set_prolog_flag(toplevel_print_options, [quoted(true), portray(true), max_depth(50), priority(699)]). 
     21true. 
     22 
     23 
    1824| ?- puzzle::solve(Sum=Rs), label(Rs), write(Sum=Rs). 
    1925[9, 5, 6, 7]+[1, 0, 8, 5]=[1, 0, 6, 5, 2] 
    2026Sum = [9, 5, 6, 7]+[1, 0, 8, 5], 
    2127Rs = [1, 0, 6, 5, 2] . 
     28 
     29 
     30| ?- hexagon::mhex(Vs). 
     31Vs = [3, 17, 18, 19, 7, 1, 11, 16, 2, 5, 6, 9, 12, 4, 8, 14, 10, 13, 15] ; 
     32Vs = [3, 19, 16, 17, 7, 2, 12, 18, 1, 5, 4, 10, 11, 6, 8, 13, 9, 14, 15] ; 
     33Vs = [9, 11, 18, 14, 6, 1, 17, 15, 8, 5, 7, 3, 13, 4, 2, 19, 10, 12, 16] ; 
     34(etc) 
     35 
     36 
     37| ?- soduku::sudoku(Rows), append(Rows, Vs), label(Vs). 
     38Rows = [[1, 2, 3, 4, 5, 6, 7, 8, 9], [4, 5, 6, 7, 8, 9, 1, 2, 3], [7, 8, 9, 1, 2, 3, 4, 5, 6], [2, 1, 4, 3, 6, 5, 8, 9, 7], [3, 6, 5, 8, 9, 7, 2, 1, 4], [8, 9, 7, 2, 1, 4, 3, 6, 5], [5, 3, 1, 6, 4, 2, 9, 7, 8], [6, 4, 2, 9, 7, 8, 5, 3, 1], [9, 7, 8, 5, 3, 1, 6, 4, 2]], 
     39Vs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9, 1, 2, 3, 7, 8, 9, 1, 2, 3, 4, 5, 6, 2, 1, 4, 3, 6, 5, 8, 9, 7, 3, 6, 5, 8, 9, 7, 2, 1, 4, 8, 9, 7, 2|...] ; 
     40Rows = [[1, 2, 3, 4, 5, 6, 7, 8, 9], [4, 5, 6, 7, 8, 9, 1, 2, 3], [7, 8, 9, 1, 2, 3, 4, 5, 6], [2, 1, 4, 3, 6, 5, 8, 9, 7], [3, 6, 5, 8, 9, 7, 2, 1, 4], [8, 9, 7, 2, 1, 4, 3, 6, 5], [5, 3, 1, 6, 4, 2, 9, 7, 8], [6, 4, 8, 9, 7, 1, 5, 3, 2], [9, 7, 2, 5, 3, 8, 6, 4, 1]], 
     41Vs = [1, 2, 3, 4, 5, 6, 7, 8, 9, 4, 5, 6, 7, 8, 9, 1, 2, 3, 7, 8, 9, 1, 2, 3, 4, 5, 6, 2, 1, 4, 3, 6, 5, 8, 9, 7, 3, 6, 5, 8, 9, 7, 2, 1, 4, 8, 9, 7, 2|...] ; 
     42(etc) 
     43 
     44 
     45| ?- soduku::(problem(1, Rows), sudoku(Rows)), append(Rows, Vs), label(Vs). 
     46Rows = [[1, 5, 6, 8, 9, 4, 3, 2, 7], [9, 2, 8, 7, 3, 1, 4, 5, 6], [4, 7, 3, 2, 6, 5, 9, 1, 8], [3, 6, 2, 4, 1, 7, 8, 9, 5], [7, 8, 9, 3, 5, 2, 6, 4, 1], [5, 1, 4, 9, 8, 6, 2, 7, 3], [8, 3, 1, 5, 4, 9, 7, 6, 2], [6, 9, 7, 1, 2, 3, 5, 8, 4], [2, 4, 5, 6, 7, 8, 1, 3, 9]], 
     47Vs = [1, 5, 6, 8, 9, 4, 3, 2, 7, 9, 2, 8, 7, 3, 1, 4, 5, 6, 4, 7, 3, 2, 6, 5, 9, 1, 8, 3, 6, 2, 4, 1, 7, 8, 9, 5, 7, 8, 9, 3, 5, 2, 6, 4, 1, 5, 1, 4, 9|...] . 
     48 
     49 
     50% the following two queries implies that Ghostscript is available from the command-line: 
     51 
     52| ?- soduku::(problem(1, Rows), show([ff], Rows)). 
     53Rows = [[1, 5, 6, 8, 9, 4, 3, 2, 7], [9, 2, 8, 7, 3, 1, 4, 5, 6], [4, 7, 3, 2, 6, 5, 9, 1, 8], [3, 6, 2, 4, 1, 7, 8, 9, 5], [7, 8, 9, 3, 5, 2, 6, 4, 1], [5, 1, 4, 9, 8, 6, 2, 7, 3], [8, 3, 1, 5, 4, 9, 7, 6, 2], [6, 9, 7, 1, 2, 3, 5, 8, 4], [2, 4, 5, 6, 7, 8, 1, 3, 9]] . 
     54 
     55 
     56| ?- soduku::show([ff], Rows). 
     57Rows = [[1, 2, 3, 4, 5, 6, 7, 8, 9], [4, 5, 6, 7, 8, 9, 1, 2, 3], [7, 8, 9, 1, 2, 3, 4, 5, 6], [2, 3, 1, 6, 7, 4, 8, 9, 5], [8, 7, 5, 9, 1, 2, 3, 6, 4], [6, 9, 4, 5, 3, 8, 2, 1, 7], [3, 1, 7, 2, 6, 5, 9, 4, 8], [5, 4, 2, 8, 9, 7, 6, 3, 1], [9, 6, 8, 3, 4, 1, 5, 7, 2]] ; 
     58Rows = [[1, 2, 3, 4, 5, 6, 7, 8, 9], [4, 5, 6, 7, 8, 9, 1, 2, 3], [7, 8, 9, 1, 2, 3, 4, 5, 6], [2, 3, 1, 6, 7, 4, 8, 9, 5], [8, 7, 5, 9, 1, 2, 3, 6, 4], [6, 9, 4, 5, 3, 8, 2, 1, 7], [3, 1, 7, 2, 6, 5, 9, 4, 8], [5, 4, 8, 3, 9, 1, 6, 7, 2], [9, 6, 2, 8, 4, 7, 5, 3, 1]] ; 
     59Rows = [[1, 2, 3, 4, 5, 6, 7, 8, 9], [4, 5, 6, 7, 8, 9, 1, 2, 3], [7, 8, 9, 1, 2, 3, 4, 5, 6], [2, 3, 1, 6, 7, 4, 8, 9, 5], [8, 7, 5, 9, 1, 2, 3, 6, 4], [6, 9, 4, 5, 3, 8, 2, 1, 7], [3, 1, 7, 2, 6, 5, 9, 4, 8], [9, 6, 2, 8, 4, 7, 5, 3, 1], [5, 4, 8, 3, 9, 1, 6, 7, 2]] ; 
     60(etc) 
     61 
     62 
     63| ?- queens::n_queens(8, Qs), labeling([ff], Qs). 
     64Qs = [1, 5, 8, 6, 3, 7, 2, 4] ; 
     65Qs = [1, 6, 8, 3, 7, 4, 2, 5] ; 
     66Qs = [1, 7, 4, 6, 8, 2, 5, 3] ; 
     67(etc) 
     68 
     69 
     70% the following query implies that Ghostscript is available from the command-line: 
     71 
     72| ?- queens::show(8, [ff], Qs). 
     73Qs = [1, 5, 8, 6, 3, 7, 2, 4] ; 
     74Qs = [1, 6, 8, 3, 7, 4, 2, 5] ; 
     75Qs = [1, 7, 4, 6, 8, 2, 5, 3] ; 
     76(etc) 
     77 
     78 
     79| ?- queens::show(N, [ff], Qs). 
     80N = 1, 
     81Qs = [1] ; 
     82N = 4, 
     83Qs = [2, 4, 1, 3] ; 
     84N = 4, 
     85Qs = [3, 1, 4, 2] ; 
     86N = 5, 
     87Qs = [1, 3, 5, 2, 4] ; 
     88(etc)