Ops, copy&paste problem. The correct rule is:

rule "get closer object"
when
    $a : Agent( $num1 : num )
    $b : Poste( $num2 : num )
    not Poste( $num3 : num -> ( abs( $num1, $num3 ) < abs( $num1, $num2 ) ) )
then
    // do something
end

   []s
   Edson

2007/5/3, Edson Tirelli <tirelli@post.com>:

    Hi,

    If you are using 4.0.0.M2, I think this will do the job:

function abs( int a, int b ) {
    return Math.abs( b - a );
}

rule "get closer object"
when
    $a : Agent( $num1 : num )
    $b : Poste( $num2 : num )
    not Poste( $num3 : num -> ( abs( $num1, $num3 ) < Math.abs( $num1, $num2 ) ) )
then
    // do something
end

    If you are using 3.0.x, then it would be like:

function abs( Integer a, Integer b ) {
    return Math.abs( b.intValue() - a.intValue() );
}

rule "get closer object"
when
    $a : Agent( $num1 : num )
    $b : Poste( $num2 : num )
    not Poste( $num3 : num -> ( abs( $num1, $num3 ) < Math.abs( $num1, $num2 ) ) )
then
    // do something
end

    Hope it helps. Let us know if it works the way you need.
  
    []s
    Edson


2007/5/3, l'ami molette <l_ami_molette@hotmail.com >:

Hi, I'm a new user of JBossRules, and I have difficulties to solve a problem using jBossRules.

 

I have two classes (AClass.java & Bclass.java). Each one have a number (an "int" value (AClass.getNum() & BClass.getNum())

, and I want to extract a Aclass & a Bclass witch have the closest numbers. In fact I want to minimize the value:

Math.abs(AClass.getNum() - BClass.getNum()).

 

I tried to write a rule like this:

 

rule "My rule"

            when

                        ACl : Agent ($AClNum : num , $AClNom : nom)

                        BCl : Poste ($BClNum : num , $BClNom : nom)

                        BCl2 : Poste ()

                        not Agent($ACl2Num : num -> (Aminor(CalculAbsolue($ACl2Num.intValue(),BCl2.getNum()) , CalculAbsolue($AClNum.intValue(),$BClNum.intValue()) )))

            then

                        System.out.println("Selected : "+ ACl.getName() +" "+BCl.getName()+" diff: "+ CalculAbsolue(ACl.getNum(),BCl.getNum()));

                        retract(ACl);

                        retract(BCl);

end

 

    function int CalculAbsolue(int a, int b){

            return Math.abs(b-a);

    }

   

    function boolean Aminor(int a, int b){

            return a < b;

    }

   

    --> But the rule doesn't work.

    Does anyone have an idea to solve my problem?

    Thank you very much for your help.

    Olivier Lafon

 

PS : (excuse my English, I'm French)



Essayez Live.com, votre nouvelle page d'accueil ! Personnalisez-la en quelques clics pour retrouver tout ce qui vous intéresse au même endroit. au même endroit.

_______________________________________________
rules-users mailing list
rules-users@lists.jboss.org
https://lists.jboss.org/mailman/listinfo/rules-users




--
  Edson Tirelli
  Software Engineer - JBoss Rules Core Developer
  Office: +55 11 3529-6000
  Mobile: +55 11 9287-5646
  JBoss, a division of Red Hat @ www.jboss.com



--
  Edson Tirelli
  Software Engineer - JBoss Rules Core Developer
  Office: +55 11 3529-6000
  Mobile: +55 11 9287-5646
  JBoss, a division of Red Hat @ www.jboss.com