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(a)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)