[rules-users] Comparing 2 Lists [Planner]

Welsh, Armand AWelsh at statestreet.com
Tue Feb 19 19:00:55 EST 2013


I would consider using comparable lists, where workorderSkill.compareTo(employeeSkills) can be true for the same skill.

When
                $workorder : WorkOrder( $requiredSkills : skills)
                $workorderSkill : Skill ( ) from $requiredSkills
                $employee : Employee( skills contains $workorderSkill)
then
                // do whatever, for each employee with a matching skill for all work orders, this rule will file.
                // if you need to limit only one employee with matching skill to workorder, then more logic will need to be built

End

In this scenario, you are collecting all the workorder, and required skills.  Then you check each employee to see if their list of skills contains any of the required skills (not all skill are required in this case, just one skill like your example suggested).

From: rules-users-bounces at lists.jboss.org [mailto:rules-users-bounces at lists.jboss.org] On Behalf Of André Fróes
Sent: Monday, February 18, 2013 10:52 AM
To: Rules Users List
Subject: Re: [rules-users] Comparing 2 Lists [Planner]

I found (i guess) a way to iterate over list, but it is not comparing and assigning the workorder now. I tried this way:
-----------------
rule "requiredSkill"
   when
       There is an unassigned workorder
       and the workorder has a requiredSkill other than null

       and there is an engineer
       and the engineer has a skill other than null

       and engineer skill is the same as workorder skill
   then
       assign workorder to engineer
engineer
-----------------
this is how i tried implementing;
-----------------
rule "requiredSkill"
            when
                $workOrder : WorkOrder()
               $woReqSkill : SkillWorkOrder($requiredSkillWO : skill , eval(skill != null)) from $workOrder.requiredSkills

               $engineer : Engineer()
               $engineerSkill : SkillEngineer($engSkill : skill, eval(skill != null)) from $engineer.skillEngineerList

               exists SkillEngineer( $engineerSkill.skill == $woReqSkill.skill )
            then
                        insertLogical(new IntConstraintOccurrence("requiredSkill", ConstraintType.NEGATIVE_HARD,
                                    1, $engineer));
end
-----------------
But all workorders are going to the same one, it is not validating if one is equals to other.

2013/2/18 André Fróes <arfmoraes at gmail.com<mailto:arfmoraes at gmail.com>>
Hello everyone!

How can I compare 2 lists with a rule?
I upgraded my basic model to a more complex one now, but now I hit a wall. My WorkOrder have a List of skills, and my Engineer also have a list of Skills and I have to compare one with another.

Example:

Engineer A have skill ABC 1
Engineer B have skill ABC 2
Engineer C have skill ABC 3

WorkOrder A needs an engineer with skill ABC 3
WorkOrder B needs an engineer with skill ABC 1
WorkOrder C needs an engineer with skill ABC 2

The result should be this:

Engineer A will receive WorkOrder B
Engineer B will receive WorkOrder C
Engineer C will receive WorkOrder A
---------------

I am able to sort it by time, but not by skill, and I don't know how to loop over each list to find if one have the skills needed to fulful the other. These are my classes involved:

WorkOrder attributes:
--------
private int requiredWorktime;
private Priority priority;(enum)
private Severity severity;(enum)
private List<SkillWorkOrder> requiredSkills;
--------
Engineer attributes:
--------
private int worktime;
private String name;
private List<SkillEngineer> skillEngineerList;
--------
Skill attributes:
--------
private String name;
--------

both SkillEngineer and SkillWorkOrder are classes that simple receives the named class and a Skill:
Eg:
private Engineer engineer; //Or WorkOrder
private Skill skill;

Is it possible to iterate over these 2 lists, by drool rule, to check wich engineer have most coincidences with an workorder? (Eg: if and Engineer have skill ABC1, ABC2 and a WorkOrder needs an engineer with skill ABC1, ABC2 and ABC3 he would be choseng among the others because his skills)


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20130220/2ab39d80/attachment.html 


More information about the rules-users mailing list