Unfortunately, when a constraint rule no longer applies, the score
wouldn't decrement.
So this would work in a stateless working memory, where the entire score
is recalculated for every move of every step.
But drools-solver works in a statefull working memory, where only the
part of the score that is dirty is recalculated (="score delta") for
every move of every step.
Now I haven't experimented with the first option yet, though I am pretty
sure it's exponentially slower.
If anyone wants to try it out, it would be nice to confirm or break my
theory :)
PS: please keep this discussion on the mailing list, so others can
benefit from it too.
With kind regards,
Geoffrey De Smet
Greg Barton schreef:
What I'm talking about isn't like what you've got in that
commented out code. Basically, it would use the same rules, matching on an accumulator
object instead of inserting new Constraint objects, and the last rule would match the
accumulator and set the score.
rule "multipleQueensHorizontal"
when
$a : Accumulator();
$q1 : Queen($id : id, $y : y);
$q2 : Queen(id > $id, y == $y);
then
$a.increment();
end
// multipleQueensVertical is obsolete because it is always 0
rule "multipleQueensAscendingDiagonal"
when
$a : Accumulator();
$q1 : Queen($id : id, $ascendingD : ascendingD);
$q2 : Queen(id > $id, ascendingD == $ascendingD);
then
$a.increment();
end
rule "multipleQueensDescendingDiagonal"
when
$a Accumulator();
$q1 : Queen($id : id, $descendingD : descendingD);
$q2 : Queen(id > $id, descendingD == $descendingD);
then
$a.increment();
end
rule "hardConstraintsBroken"
salience -10
when
$a : Accumulator();
then
scoreCalculator.setScore(- $a.intValue());
end
--- On Fri, 2/13/09, Geoffrey De Smet <ge0ffrey.spam(a)gmail.com> wrote:
> From: Geoffrey De Smet <ge0ffrey.spam(a)gmail.com>
> Subject: Re: Drools solver performance question
> To:
> Cc: greg_barton(a)yahoo.com
> Date: Friday, February 13, 2009, 8:42 AM
> Hi Greg,
>
> Yes, I expected that too, but my experiments proved me
> wrong (for now).
> The current implementation of accumulate backwards chains I
> believe.
> Backward chaining doesn't do score delta calculation,
> so it's very bad for scalability.
>
> Try it yourself with the nqueens example.
> Uncomment the code in nqueensScoreRules.drl and see what
> happens if you go from n=8 to n=16 and more.
>
> With kind regards,
> Geoffrey De Smet
>
>
>
> Greg Barton schreef:
>
>> I answered a performance question a user had about
>> drools-solver, but I'm afraid I answered with a
>>
> touch of
>
>> ignorance about the way drools-solver is set up. His
>>
> rules
>
>> had a new object being inserted into the working
>>
> memory each
>
>> time a constraint rule was matched. The constraint
>>
> objects
>
>> were then accumulated by a low priority rule at the
>>
> end. After looking at the drools-solver examples it looks
> like
>
>> they're all that way. It strikes me that having a
>> single accumulator object, and not creating and
>>
> inserting a
>
>> new object in each constraint rule, would be more
>>
> efficient.
>
>> Is it possible to set this up in a solver ruleset?
>> Thanks,
>> GreG
>>
>>
>>
>>
>>