users-prolog
[Top][All Lists]
Advanced

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

Creating prolog FD terms from C?


From: Sebastian Rasmussen
Subject: Creating prolog FD terms from C?
Date: Thu, 12 Aug 2004 17:36:28 +0200

Hi!

I need some pointers to how to solve a problem of mine. What
I want to achieve is to build program (in C) that can pick a
number of objects, who's sum is below a given threshold. I
managed to solve this in prolog using some fd_* predicates
(where S is the sum, 256 the threshold, F1 to F5 the objects
and 3, 36, 76 and so on, the value of each object):

constraints(S, F1, F2, F3, F4, F5) :-
   fd_domain(F1, [0, 3]),
   fd_domain(F2, [0, 36]),
   fd_domain(F3, [0, 76]),
   fd_domain(F4, [0, 176]),
   fd_domain(F5, [0, 197]),
   S #= F1 + F2 + F3 + F4 + F5,
   S #< 256.

q :-
   fd_set_vector_max(1024),
   fd_maximize(constraints(S, F1, F2, F3, F4, F5), S),
   fd_labeling([S, F1, F2, F3, F4, F5]),
   write(S),
   nl,
   write([F1, F2, F3, F4, F5]),
   nl.

:- initialization(q).

The resulting labeling is of course a list of numbers
beginning with the total sum S followed by a list of numbers
that either is the value of the object or zero if the object
is not included in the sum.

The problem is that (at compile time) I don't know compile
time the number of objects that are available for the finite
domain solver to pick from, nor each objects value or size
(e.g. 197 above). So what I would like to do is to create
the constraints/6 and q/1 terms from my c code and then call
Pl_Query_Call() to retrieve the resulting labeling.

I've been skimming through documentation and manual, but I
haven't found how to call gprolog from c to build a FD term.
Has anyone found themselves in a similar situation and
possibly solved the problem? Thanks in advance.

/ Sebastian Rasmussen

_________________________________________________________________
STOP MORE SPAM with the new MSN 8 and get 2 months FREE* http://join.msn.com/?page=features/junkmail





reply via email to

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