[rules-users] Hard constraints to enforce employee seniority

Patrik Dufresne ikus060 at gmail.com
Thu Dec 8 17:35:48 EST 2011


Thanks Geoffrey,

I really like you're suggestion to use intermediate facts to keep the
employee'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 'not' or a 'not
exists' expression. It may be stated as follow :

rule "hard-Seniority"
when
         EmployeeRanking($higherRankedEmployee, $lowerRankedEmployee,
$numberOfEmployeesInRankBetweenThem)
         PlanifEventAssignment(employee == $lowerRankedEmployee)
         not PlanifEventAssignment(employee == $higherRankedEmployee)
then
  insertLogical(new IntConstraintOccurrence("hard-Seniority",
         ConstraintType.NEGATIVE_HARD,
          $numberOfEmployeesInRankBetweenThem,
         $employee, $assignment));
end

Thanks

2011/12/8 Geoffrey De Smet <ge0ffrey.spam at gmail.com>

> **
>
>
> Op 07-12-11 21:41, Patrik Dufresne schreef:
>
> Hi all,
>
>  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.
>
>  I've implement it as a hard constraint :
>  rule "hard-Seniority"
>  when
>  $employee : Employee()
>  $assignment : PlanifEventAssignment( $planifEmployee : employee )
>
> What's does this $planifEmployee do?
>
>   not PlanifEventAssignment( employee == $employee )
>  eval(Helper.compareEmployee($employee, $planifEmployee) < 0)
>  then
>  insertLogical(new IntConstraintOccurrence("hard-Seniority",
>         ConstraintType.NEGATIVE_HARD,
>          1,
>          $employee, $assignment));
> end
>
>  The function Helper.compareEmployee(e1, e2) return -1 if e1 is more
> senior then e2 (mostly based on hire date and other boolean fields).
>
>  On first sight, in Solution.getProblemFact() I would add these cached
> problem facts, for any 2 employees (but just once per combination):
> new EmployeeRanking(higherRankedEmployee, lowerRankedEmployee,
> numberOfEmployeesInRankBetweenThem)
>
> then you can do
>
> rule "hard-Seniority"
>  when
>          EmployeeRanking($higherRankedEmployee, $lowerRankedEmployee,
> $numberOfEmployeesInRankBetweenThem)
>          PlanifEventAssignment(employee == $lowerRankedEmployee)
>          PlanifEventAssignment(employee == $higherRankedEmployee)
>
>  then
>  insertLogical(new IntConstraintOccurrence("hard-Seniority",
>         ConstraintType.NEGATIVE_HARD,
>          $numberOfEmployeesInRankBetweenThem,
>          $employee, $assignment));
>
>
>
>  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:
>
>  PlanifEventAssignment1 = e2
> PlanifEventAssignment2 = e3
> PlanifEventAssignment3 = e4
> PlanifEventAssignment4 = e5
>
>  e1 is not working. Multiple move are require to reach the best solution
> :
>  PlanifEventAssignment1 = e1
> PlanifEventAssignment2 = e2
> PlanifEventAssignment3 = e3
> PlanifEventAssignment4 = e4
>
>  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 ?
>
> 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).
>
>
>  --
> Patrik Dufresne
>
>
> _______________________________________________
> rules-users mailing listrules-users at lists.jboss.orghttps://lists.jboss.org/mailman/listinfo/rules-users
>
>
> --
> With kind regards,
> Geoffrey De Smet
>
>
> _______________________________________________
> rules-users mailing list
> rules-users at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/rules-users
>
>


-- 
Patrik Dufresne
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20111208/b90fc7b7/attachment.html 


More information about the rules-users mailing list