Re: [eclipse-clp-users] Managing lists of real variable

From: simone pascucci <cxjepa_at_...6...>
Date: Wed, 14 Oct 2009 12:04:48 -0500
Dear Kish,

thank very much for your help. The main problem is that one does not even
know what to read when is learning a new framework. I could solve my need
with the following code, I post it for people who may get into the same
problem

:- lib(ic).

    sum_up(Amount, Amount_f, MinAmount, MaxAmount, MantCorr, MantCorrMin,
MantCorrMax, MantPrev, Variables, V_floats, MinValues, MaxValues) :-
        Variables $:: 0.0..inf,
        Amount $:: 0.0..inf,
        MantCorr $:: 0.0..inf,
        MantPrev $:: 0.0..inf,
        ( foreach(V, Variables), foreach(Min, MinValues), foreach(Max,
MaxValues) do
            V $>= Min,
            V $=< Max
        ),
        Amount $=< MaxAmount,
        Amount $>= MinAmount,
        MantCorr $=< MantCorrMax*Amount,
        MantCorr $>= MantCorrMin*Amount,
        MantPrev $= sum(Variables),
        Amount $= MantCorr + MantPrev,
        locate(Variables, 1e-3),
        ( foreach(V, Variables), foreach(F, V_floats) do
                F is get_median(V)
        ),
        Amount_f is get_median(Amount).

I doubt that this is best way to do that, but It worked so far. Also, one
has take care of the fact that after the conversion the sum of the variables
is not exactly as the total amount. The acceptability of this approach
depend on the wanted precision.

2009/10/14 Kish Shen <kisshen_at_...5...>

> simone pascucci wrote:
>
>> conversion if they want to pass the result to java (I suppose I should
>> cast
>> the breals to float), but I'm experiencing a infinite loop (or at least
>> something like that). This happen for example if I add at the very end the
>> following
>>
>>       locate(Variables, 1e-5),
>>       float(Amount).
>>
>>  float(Amount) does not convert a number into a float -- it is a test for
> a float, and I assume in your case, it fails because you have a bounded
> real, so it fails back into the locate/2 labelling.
>
> You should check the documentation when you are using a built-in you are
> not familiar with -- ECLiPSe allows you to do this easily from the
> top-level, you simply have to type help <predicate spec>, in your case,
> help float/1. Als0, since variables in ECLiPSe cannot be destructively
> assigned, there is no way you can perform a conversion with a predicate with
> only one argument.
>
> To convert a number into a float, you need to use float/2 (see the
> documentation).
>
>
> Cheers,
>
> Kish
>
>
> --
> This e-mail may contain confidential and privileged material for the
> sole use of the intended recipient. Any review, use, distribution or
> disclosure by others is strictly prohibited. If you are not the intended
> recipient (or authorized to receive for the recipient), please contact
> the sender by reply e-mail and delete all copies of this message.
> Cisco Systems Limited (Company Number: 02558939), is registered in
> England and Wales with its registered office at 1 Callaghan Square,
> Cardiff, South Glamorgan CF10 5BT.
>
Received on Wed Oct 14 2009 - 17:05:04 CEST

This archive was generated by hypermail 2.3.0 : Tue Apr 16 2024 - 09:13:20 CEST