Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Computing > Constraints > golomb size 13 ...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 493 of 550
Post > Topic >>

golomb size 13 solved by clp(FD)

by nengfazhou@[EMAIL PROTECTED] Nov 20, 2007 at 07:53 AM

c:\george>bp
B-Prolog Version 7.1b1, All rights reserved, (C) Afany Software
1994-2007.
Licensed for educational and nonprofit research uses only.

| ?- cl(golomb)
Compiling::golomb.pl
compiled in 16 milliseconds
loading::golomb.out

yes
| ?- go
[0,2,5,25,37,43,59,70,85,89,98,99,106]
time(-217433257)

A solution to the golomb 13 problem was found over the weekend
(obviously the time integer overflowed) on my PC (Pentium 4, 3GHz,
1GRAM). Is this the largest problem instance that has been solved by
CLP(FD)? In the tutorial, solutions are given to instances up to size
12.

go:-
    cputime(Start),
    golomb(13,Sol),
    cputime(End),
    T is End-Start,
    writeln(Sol),
    writeln(time(T)).

/*
    Taken from PRACTICAL CONSTRAINTS: A TUTORIAL ON MODELLING WITH
CONSTRAINTS,
    by ROMAN BART=81=C1K
*/
golomb(M,Sol):-
    Sol =3D [0|_],
    UpperBound is M*M,
    ruler(M,-1,UpperBound,Sol),
    last(Sol,XM),
    distances(Sol,1,M,XM,Dist),
    all_distinct(Dist),
    (Dist=3D[DF,_|_] ->
     last(Dist,DL), DF#<DL
     ;
     true
     ),
    minimize(labeling([ff],Sol),XM).

ruler(0,_,_,[]).
ruler(K,PrevX,UpperBound,[X|Rest]):-
    K>0,
    PrevX#<X, X#=3D<UpperBound,
    K1 is K-1,!,
    ruler(K1,X,UpperBound,Rest).

distances([],_,_,_,[]).
distances([X|Rest],I,M,XM,Dist):-
    J is I+1,
    distances_from_x(Rest,X,I,J,M,XM,Dist,RestDist),
    I1 is I+1,!,
    distances(Rest,I1,M,XM,RestDist).
    distances_from_x([],_,_,_,_,_,RestDist,RestDist).

distances_from_x([Y|Rest],X,I,J,M,XM,[DXY|Dist],RestDist):-
    DXY #=3D Y-X,
    LowerBound is integer(((J-I)*(J-I+1))/2),
    LowerBound #=3D< DXY,
    UpperBoundP is integer(((M-1-J+I)*(M-J+I))/2),
    DXY #=3D< XM - UpperBoundP,
    J1 is J+1,!,
    distances_from_x(Rest,X,I,J1,M,XM,Dist,RestDist).

last([X],X):-!.
last([_|Xs],X):-last(Xs,X).

minimize(Choice,Exp):-minof(Choice,Exp).
 




 5 Posts in Topic:
golomb size 13 solved by clp(FD)
nengfazhou@[EMAIL PROTECT  2007-11-20 07:53:21 
Re: golomb size 13 solved by clp(FD)
"zayenz@[EMAIL PROTE  2007-11-22 05:03:17 
Re: golomb size 13 solved by clp(FD)
Mikael Zayenz Lagerkvist   2007-11-22 09:24:49 
Re: golomb size 13 solved by clp(FD)
"Christian Schulte&q  2007-11-23 00:54:41 
Re: golomb size 13 solved by clp(FD)
"Neng-Fa Zhou"   2007-11-23 10:33:06 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat Aug 30 2:36:13 CDT 2008.