users-prolog
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

FD problem: "vector too small"


From: Jesper Eskilson
Subject: FD problem: "vector too small"
Date: Sat, 29 Nov 2008 22:40:14 +0100

Hi,

I'm using the FD solver in GNU prolog to solve a couple of problems
over at http://ProjectEuler.net. The problem I'm currently solving is
this: http://projecteuler.net/index.php?section=problems&id=39:

If p is the perimeter of a right angle triangle with integral length
sides, {a,b,c}, there are exactly three solutions for p = 120.

{20,48,52}, {24,45,51}, {30,40,50}

For which value of p 1000, is the number of solutions maximised?

This sounds like an excellent problem for applying some CLP/FD, I
thought, and wrote this program:

perimeter([P,X,Y,Z]) :-
        X #>= 1,
        Y #>= X,
        Z #>= Y,
        P #= X + Y + Z,
        X ** 2 + Y ** 2 #= Z ** 2,
        fd_all_different([X,Y,Z]),
        fd_labeling([P,X,Y,Z]).

p39(0, Length, Length).
p39(P, MaxLen, Length) :-
        findall([X,Y,Z], perimeter([P,X,Y,Z]), Solutions),
        length(Solutions, NewLen),
        max_list([NewLen, MaxLen], NewMaxLen),
        P0 is P - 1,
        p39(P0, NewMaxLen, Length).

p39(MaxLen) :-
        p39(1000, 0, MaxLen).

but when I run it, I get lots and lots of warnings on the form:

    Warning: Vector too small - maybe lost solutions (FD Var:_54)

What does this warning mean? And how do I avoid getting it?

-- 
/Jesper




reply via email to

[Prev in Thread] Current Thread [Next in Thread]