Thanks Geoffrey,<div><br></div><div>I really like you&#39;re suggestion to use intermediate facts to keep the employee&#39;s seniority. After this email, I will try to implement it, but I do have a question about your way to implement it. Since my goal is to make senior employee ($higherRankedEmployee) work before a less senior employee ($lowerRankedEmployee), I think the rule should contain a &#39;not&#39; or a &#39;not exists&#39; expression. It may be stated as follow : </div>
<div><br></div><div><div><div>rule &quot;hard-Seniority&quot;</div><div>when<br>         EmployeeRanking($higherRankedEmployee, $lowerRankedEmployee, $numberOfEmployeesInRankBetweenThem)<br>         PlanifEventAssignment(employee == $lowerRankedEmployee)<br>
         not PlanifEventAssignment(employee == $higherRankedEmployee)<div class="im"><div>then</div><div><span style="white-space: pre-wrap;">         </span>insertLogical(new IntConstraintOccurrence(&quot;hard-Seniority&quot;,</div>
<div>        <span style="white-space: pre-wrap; ">     </span>ConstraintType.NEGATIVE_HARD,</div></div><div>        <span style="white-space: pre-wrap; ">     </span>$numberOfEmployeesInRankBetweenThem,</div><div>        <span style="white-space: pre-wrap; ">     </span>$employee, $assignment));</div>
</div></div><div>end</div></div><div><br></div><div>Thanks</div><div><br><div class="gmail_quote">2011/12/8 Geoffrey De Smet <span dir="ltr">&lt;<a href="mailto:ge0ffrey.spam@gmail.com">ge0ffrey.spam@gmail.com</a>&gt;</span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"><u></u>

  
    
    
  
  <div text="#000000" bgcolor="#ffffff">
    <br>
    <br>
    Op 07-12-11 21:41, Patrik Dufresne schreef:
    <div class="im"><blockquote type="cite">Hi all,
      <div><br>
      </div>
      <div>I&#39;m trying to create rules to model my problem. So far, I
        didn&#39;t manage to create rules to make Drools converge to a
        solution because of score traps. I don&#39;t see any way to avoid it
        (as I&#39;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&#39;ve implement it as a hard constraint :</div>
      <div>
        <div>rule &quot;hard-Seniority&quot;</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></div>
    What&#39;s does this $planifEmployee do?<div class="im"><br>
    <blockquote 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) &lt; 0)</div>
        <div><span style="white-space:pre-wrap"> </span>then</div>
        <div><span style="white-space:pre-wrap"> </span>insertLogical(new
          IntConstraintOccurrence(&quot;hard-Seniority&quot;,</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></div>
    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 &quot;hard-Seniority&quot;</div>
      <div><span style="white-space:pre-wrap"> </span>when<br>
                 EmployeeRanking($higherRankedEmployee,
        $lowerRankedEmployee, $numberOfEmployeesInRankBetweenThem)<br>
                 PlanifEventAssignment(employee == $lowerRankedEmployee)<br>
                 PlanifEventAssignment(employee ==
        $higherRankedEmployee)<div class="im"><br>
        <div><span style="white-space:pre-wrap"> </span>then</div>
        <div><span style="white-space:pre-wrap"> </span>insertLogical(new
          IntConstraintOccurrence(&quot;hard-Seniority&quot;,</div>
        <div>        <span style="white-space:pre-wrap"> </span>ConstraintType.NEGATIVE_HARD,</div>
        </div><div>        <span style="white-space:pre-wrap"> </span>$numberOfEmployeesInRankBetweenThem,</div>
        <div>        <span style="white-space:pre-wrap"> </span>$employee,
          $assignment));</div>
                      </div>
    </div><div class="im">
    <br>
    <br>
    <blockquote type="cite">
      <div>This way, the rule make sure a senior employee is working.
        But it&#39;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&#39;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></div>
    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 type="cite">
      <div>
        <div><br><span class="HOEnZb"><font color="#888888">
        </font></span></div><span class="HOEnZb"><font color="#888888">
        <div>
          <div>-- <br>
            Patrik Dufresne<br>
          </div>
        </div>
      </font></span></div><span class="HOEnZb"><font color="#888888">
      <pre><fieldset></fieldset>
_______________________________________________
rules-users mailing list
<a href="mailto:rules-users@lists.jboss.org" target="_blank">rules-users@lists.jboss.org</a>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a>
</pre>
    </font></span></blockquote><span class="HOEnZb"><font color="#888888">
    <br>
    <pre cols="72">-- 
With kind regards,
Geoffrey De Smet</pre>
  </font></span></div>

<br>_______________________________________________<br>
rules-users mailing list<br>
<a href="mailto:rules-users@lists.jboss.org">rules-users@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/rules-users" target="_blank">https://lists.jboss.org/mailman/listinfo/rules-users</a><br>
<br></blockquote></div><br><br clear="all"><div><br></div>-- <br>Patrik Dufresne<br>
</div>