[rules-users] programmatic manipulation of 4.0 salience?

Yuri de Wit ydewit at gmail.com
Fri Aug 17 06:41:54 EDT 2007


Scott,

not sure if it fits your problem, but you may also consider using
dynamic saliences. Yesterday I was able to convert 3.x rules to use it
worked very well.

In my case, I have facts of different sizes (some are collections of
other facts, some are individual facts) and in some rules I need to
find first MxN pairs (collection facts on both sides), then Mx1 or 1xN
pairs, and only then 1x1 pairs. In other rules I need to find first
1x1 pairs, then Mx1 or 1xN pairs and only then MxN.

Instead of writting a custom ConflictResolver, what I did was to use
one dynamic salience:

salience (1000 / (c.size * t.size))

for finding smallest pairs first, and

salience (-1000 / (c.size * t.size)

for finding the largest pairs first.

The 1000 is to get around the fact that saliences are integers and not
float/double (afaik)

Hope it helps,

-- yuri


On 8/17/07, Manjax23 <manjunatha.n at coreobjects.com> wrote:
>
> Salience salience = new SalienceInteger( Integer.parseInt( salienceText ) );
> rule.setSalience( salience );
>
> Cheers,
> manjax23
>
>
> Scott Reed-4 wrote:
> >
> > My 3.1 app has a mechanism that allowed the user to change the salience of
> > some rules before running
> > them, before loading up WorkingMemory. This was quite simple,
> > rule.getSalience() returned a rule's
> > int salience value and rule.setSalience(int) set it. Now in 4.0 I see
> > salience is no longer just an
> > int, but a Salience object with a simple constructor and complicated
> > getValue(Tuple,WorkingMemory)
> > method to access the int value.
> >
> > It appears to be still easy to set the salience of a rule:
> > rule.setSalience( new
> > SalienceInteger(int)) but getting the int salience from a Salience object
> > seems to have been removed
> > from joe-blow coder's reach.
> >
> > I would be very grateful if someone would provide me with an example that
> > gets the int salience
> > associated with a rule. I have no idea where or why I need to get the
> > Tuple and WorkingMemory. Can I
> > just pass nulls in for those two arguments?
> >
> > Thanks,
> >    Scott
> > _______________________________________________
> > rules-users mailing list
> > rules-users at lists.jboss.org
> > https://lists.jboss.org/mailman/listinfo/rules-users
> >
> >
>
> --
> View this message in context: http://www.nabble.com/programmatic-manipulation-of-4.0-salience--tf4283735.html#a12194345
> Sent from the drools - user mailing list archive at Nabble.com.
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>



More information about the rules-users mailing list