Re: [eclipse-clp-users] How to handle double values in eclipse clp?

From: Joachim Schimpf <jschimpf_at_...311...>
Date: Sun, 19 May 2013 21:21:48 +0100
On 19/05/2013 12:16, Hadeer Diwan wrote:
> Hello,
> I wanted to ask a question regarding data types in eclipse clp. I am using the following code
> and i want to change it so that it handles double values for the cost. I was able to make it
> handle floating point values by adding float(Result, Cost). How can i refine it to handle double
> values?
> search_min(List,Dists,Cost) :-
>          Result $= sum(Dists),
>          float(Result,Cost),
>          minimize(labeling(List),Cost).

Not sure what you are trying to achieve here, you should simply use
the Result variable directly in minimize/2 (you cannot use float/2
here, as it is not a constraint).

There are no issues with float vs double (as Sergii pointed out, floats
are doubles in ECLiPSe).  However, ECLiPSe has a "bounded real" (breal)
data type, which is a double interval.  All constraint reasoning over
continuous variables is carried out using such intervals, in order to
guarantee correctness.

Consider this small example with non-integral cost:

main(Bools, Cost) :-
	Ds = [4.4, 2.2, 1.1, 5.5, 3.3],

	length(Ds, N),
	length(Bools, N),
	Bools #:: 0..1,
	sum(Bools) #= 3,
	Cost $= Bools*Ds,

         minimize(labeling(Bools), Cost).

?- main(Bools, Cost).
Found a solution with cost 9.8999999999999986__9.9000000000000021
Found a solution with cost 6.6__6.6000000000000005
Found no solution with cost 0.0 .. 5.6000000000000005
Bools = [0, 1, 1, 0, 1]
Cost = 6.6__6.6000000000000005
There is 1 delayed goal.
Yes (0.00s cpu)

As you see, the reasoning is carried out using interval arithmetic,
and the resulting Cost is a breal interval.  You may want to round
that result to some intermediate floating point value for further
processing, but you must do that only *after* the solving process.

-- Joachim
Received on Sun May 19 2013 - 20:22:02 CEST

This archive was generated by hypermail 2.2.0 : Mon Jul 09 2018 - 02:05:30 CEST