<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<title></title>
</head>
<body text="#000000" bgcolor="#ffffff">
<br>
<br>
Op 07-12-11 21:41, Patrik Dufresne schreef:
<blockquote
cite="mid:CAJ=kj5wS5SMGEBnvJh=1N4BFviYALBPZjKexebLcFn-5_YGnuA@mail.gmail.com"
type="cite">Hi all,
<div><br>
</div>
<div>I'm trying to create rules to model my problem. So far, I
didn't manage to create rules to make Drools converge to a
solution because of score traps. I don't see any way to avoid it
(as I'm not an expert with Drools). I can express the rule as
follow : a senior employee should work before a less senior
employee.</div>
<div><br>
</div>
<div>I've implement it as a hard constraint :</div>
<div>
<div>rule "hard-Seniority"</div>
<div><span style="white-space: pre-wrap;"> </span>when</div>
<div><span style="white-space: pre-wrap;"> </span>$employee :
Employee()</div>
<div><span style="white-space: pre-wrap;"> </span>$assignment :
PlanifEventAssignment( $planifEmployee : employee )</div>
</div>
</blockquote>
What's does this $planifEmployee do?<br>
<blockquote
cite="mid:CAJ=kj5wS5SMGEBnvJh=1N4BFviYALBPZjKexebLcFn-5_YGnuA@mail.gmail.com"
type="cite">
<div>
<div><span style="white-space: pre-wrap;"> </span>not
PlanifEventAssignment( employee == $employee )</div>
<div><span style="white-space: pre-wrap;"> </span>eval(Helper.compareEmployee($employee,
$planifEmployee) < 0)</div>
<div><span style="white-space: pre-wrap;"> </span>then</div>
<div><span style="white-space: pre-wrap;"> </span>insertLogical(new
IntConstraintOccurrence("hard-Seniority",</div>
<div> <span style="white-space: pre-wrap;"> </span>ConstraintType.NEGATIVE_HARD,</div>
<div> <span style="white-space: pre-wrap;"> </span>1,</div>
<div> <span style="white-space: pre-wrap;"> </span>$employee,
$assignment));</div>
<div>end</div>
</div>
<div><br>
</div>
<div>The function Helper.compareEmployee(e1, e2) return -1 if e1
is more senior then e2 (mostly based on hire date and other
boolean fields).</div>
<div><br>
</div>
</blockquote>
On first sight, in Solution.getProblemFact() I would add these
cached problem facts, for any 2 employees (but just once per
combination):<br>
new EmployeeRanking(higherRankedEmployee, lowerRankedEmployee,
numberOfEmployeesInRankBetweenThem)<br>
<br>
then you can do<br>
<div>
<div>rule "hard-Seniority"</div>
<div><span style="white-space: pre-wrap;"> </span>when<br>
EmployeeRanking($higherRankedEmployee,
$lowerRankedEmployee, $numberOfEmployeesInRankBetweenThem)<br>
PlanifEventAssignment(employee == $lowerRankedEmployee)<br>
PlanifEventAssignment(employee ==
$higherRankedEmployee)<br>
<div><span style="white-space: pre-wrap;"> </span>then</div>
<div><span style="white-space: pre-wrap;"> </span>insertLogical(new
IntConstraintOccurrence("hard-Seniority",</div>
<div> <span style="white-space: pre-wrap;"> </span>ConstraintType.NEGATIVE_HARD,</div>
<div> <span style="white-space: pre-wrap;"> </span>$numberOfEmployeesInRankBetweenThem,</div>
<div> <span style="white-space: pre-wrap;"> </span>$employee,
$assignment));</div>
</div>
</div>
<br>
<br>
<blockquote
cite="mid:CAJ=kj5wS5SMGEBnvJh=1N4BFviYALBPZjKexebLcFn-5_YGnuA@mail.gmail.com"
type="cite">
<div>This way, the rule make sure a senior employee is working.
But it's a score trap since, many moves are required to resolve
the constraint. e.g:</div>
<div><br>
</div>
<div>PlanifEventAssignment1 = e2</div>
<div>PlanifEventAssignment2 = e3</div>
<div>PlanifEventAssignment3 = e4</div>
<div>PlanifEventAssignment4 = e5</div>
<div><br>
</div>
<div>e1 is not working. Multiple move are require to reach the
best solution : </div>
<div>
<div>PlanifEventAssignment1 = e1</div>
<div>PlanifEventAssignment2 = e2</div>
<div>PlanifEventAssignment3 = e3</div>
<div>PlanifEventAssignment4 = e4</div>
<div><br>
</div>
<div>So I'm asking you. What is the best way to make Drools
converge ? Do I need to change my rule, or should I create a
BigMove ?</div>
</div>
</blockquote>
course grained moves will work mostly, but solving the score trap
itself is a far better long-term solution (and it still allows you
to add course grained moves later).<br>
<blockquote
cite="mid:CAJ=kj5wS5SMGEBnvJh=1N4BFviYALBPZjKexebLcFn-5_YGnuA@mail.gmail.com"
type="cite">
<div>
<div><br>
</div>
<div>
<div>-- <br>
Patrik Dufresne<br>
</div>
</div>
</div>
<pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
rules-users mailing list
<a class="moz-txt-link-abbreviated" href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a>
<a class="moz-txt-link-freetext" href="https://lists.jboss.org/mailman/listinfo/rules-users">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
</blockquote>
<br>
<pre class="moz-signature" cols="72">--
With kind regards,
Geoffrey De Smet</pre>
</body>
</html>