Hi,
I'm experimenting with the parallel search facility of Oz (with plenty
of success so far I'm pleased to say) but I'm only using a simple
problem at the moment. The program is defined as a functor I can use in
the OPI like so:
(ush is a customised expect script to avoid the ssh password issues!)
%%%%%%%%%%%%%
declare
functor Fractions
import FD
export Script
define
proc {Script Root}
sol(a:A b:B c:C d:D e:E f:F g:G h:H i:I) = Root
BC = {FD.decl}
EF = {FD.decl}
HI = {FD.decl}
in
Root ::: 1#9
{FD.distinct Root}
BC =: 10*B + C
EF =: 10*E + F
HI =: 10*H + I
A*EF*HI + D*BC*HI + G*BC*EF =: BC*EF*HI
{FD.distribute ff Root}
end
end
[M]={Module.apply [Fractions]}
E={New Search.parallel init('outcast':1#ush 'damien.scm':1#ush)}
{Inspect E}
{E trace(true)}
Xs={E all(Fractions $)}
{Browse Xs}
%%%%%%%%%%%%%%%%%%
What I would like to do is try the same thing with the knights tour demo
but I'm having great difficulty getting this to work as a functor within
an OPI style program. Can anyone point in the right direction as to how
to modify the original knights.oz to this functor style?
Regards
Mark
For convenience this is the source for the knights.oz file:
%%%
%%% Authors:
%%% Gert Smolka <[email protected]>
%%%
%%% Copyright:
%%% Gert Smolka, 1998
%%%
%%% Last change:
%%% $Date: 1999-10-15 23:30:30 +0200 (Fri, 15 Oct 1999) $ by $Author: schulte
$
%%% $Revision: 12194 $
%%%
%%% This file is part of Mozart, an implementation
%%% of Oz 3
%%% http://www.mozart-oz.org
%%%
%%% See the file "LICENSE" or
%%% http://www.mozart-oz.org/LICENSE.html
%%% for information on usage and redistribution
%%% of this file, and for a DISCLAIMER OF ALL
%%% WARRANTIES.
%%%
%%
%% Load graphical plugin for Explorer
%%
declare
[Graphics]={Module.link [({Property.get 'oz.home'}#
'/examples/fd/graphics/Knights.ozf')]}
{Graphics.add}
declare
fun {Knights N}
NN = N*N
% The fields of the board are numbered from 1..NN
% according to their lexicographic order, that is,
% (1,1), (1,2), ..., (2,1), (2,2), ..., (N,N)
%
% Field: X x Y --> Field
fun {Field X Y}
(X-1)*N + Y
end
% Neighbours: Field --> List of fields
fun {Neighbours F}
X = (F-1) mod N + 1
Y = (F-1) div N + 1
in
{FoldR [~2#~1 ~2#1 ~1#~2 ~1#2 1#~2 1#2 2#~1 2#1]
fun {$ U#V In}
A = X+U
B = Y+V
in
if A>=1 andthen A=<N andthen B>=1 andthen B=<N then
A + (B-1)*N | In
else In
end
end
nil}
end
in
proc {$ Solution}
Pred = {FD.tuple pred NN 1#NN} % field --> field
Succ = {FD.tuple succ NN 1#NN} % field --> field
Jump = {FD.tuple jump NN 1#NN} % field --> jump
= {FD.distinct}
in
Solution = Jump#Succ#Pred
% there are no solutions for odd N
N mod 2 = 0
% tour starts as follows: (1,1), (2,3), ...
Jump.{Field 1 1} = 1
Jump.{Field 2 3} = 2
% for every field F
{For 1 NN 1
proc {$ F}
Nbs = {Neighbours F}
in
Pred.F :: Nbs
Succ.F :: Nbs
% redundant constraint: avoid trivial cycles
Succ.F \=: Pred.F
% for every neighbour G of F
{ForAll Nbs
proc {$ G}
(Succ.F=:G)
= (F=:Pred.G)
= (Jump.G =: {FD.modI Jump.F NN}+1)
end}
end}
{FD.distribute naive Succ} % better than ff
end
end
{ExploreOne {Knights 8}}
/*
{Search.one.depth {Knights 18} 10 _ _}
{ExploreOne {Knights 16}} % recomputation needed to save memory
{Graphics.delete}
*/
--
Mark Richardson
Final year undergraduate
University of Teesside
_________________________________________________________________________________
mozart-users mailing list
[email protected]
http://www.mozart-oz.org/mailman/listinfo/mozart-users