Re: [eclipse-clp-users] Excuse me. I want to ask a question.

From: Joachim Schimpf <jschimpf_at_coninfer.com>
Date: Fri, 13 Apr 2012 13:30:18 +0200
Chen Tommy wrote:
> Hi 
> 
>    I want to ask a question. That's I want to use ECLiPSe in JAVA(eclipse). 
> 
>    But when I use the instruction  "rpc(remote predicate call)" 
> in ECLiPSe that just return "null".
> 
>     It's can work in integer number but can't work in real number.Can I 
> ask why? Thanks for your help.

Working with real number is tricky because in general we cannot represent
them precisely.

In an integer problem, when you reach the end of the search procedure,
all integer variables are instantiated to integer numbers.  You can then
pass these numbers back to your Java program, and there is no problem.

But in a problem with real variables, when you reach the end of the search
(the calls to locate/2 in your example), the variables are still variables,
only their domains have become very small.  That means, unlike in the integer
case, the variables are NOT automatically instantiated to numbers!
You are probably trying to pass these variables back to Java, and this is
not possible, because the Java/Eclipse interface only understands floats.

For your purpose it might be enough to pick an approximate value from
the middle of the resulting variable interval, and return this to Java
as a floating point number.  You could use get_median/2
http://www.eclipseclp.org/doc/bips/lib/ic/get_median-2.html
after the search as follows:

     ...
     locate([NSa], 0.01),
     get_median(NSa, NSaFloat),
     ....

Cheers,
Joachim



> 
>    If I want to solve the answer in  real number domain as follow
> 
> 
> 
>   :- lib(ic), lib(listut).
> 
> testTriangleTriangle(Path, OState, Arg, Result, NState) :-
> Path > 0,
> % Domains
> [Sa] :: -127.5 .. 128.5,
> [NSa] :: -127.5 .. 128.5,
> [Sb] :: -127.5 .. 128.5,
> [NSb] :: -127.5 .. 128.5,
> [Sc] :: -127.5 .. 128.5,
> [NSc] :: -127.5 .. 128.5,
> % Constraints
> Arg = [Sa, Sb, Sc],
> NState = [NSa, NSb, NSc],
> triangleTriangle(Path, OState, Arg, Result, NState),
> % Solving
> locate([Sa],0.01),
> locate([NSa],0.01),
> locate([Sb],0.01),
> locate([NSb],0.01),
> locate([Sc],0.01),
> locate([NSc],0.01).
Received on Fri Apr 13 2012 - 11:30:04 CEST

This archive was generated by hypermail 2.2.0 : Tue Apr 24 2012 - 06:15:45 CEST