[rules-users] Comparing 2 Lists [Planner]
Welsh, Armand
AWelsh at statestreet.com
Tue Feb 19 18:47:43 EST 2013
I assume Engineer().skillEngineerList() is a Collection of SkillEngineer facts for the selected engineer. So there is no need to bind SkillEngineer facts that you extract from the engineer to the engineer, the binding is implicit in the POJO relationship.
But more importantly, why are you binding the workOrder to the engineer? I think what you want is this:
rule "requiredSkill"
when
$engineer : Engineer()
SkillEngineer( $skill : skill ) from $engineer.skillEngineerList
$workOrder : WorkOrder( )
SkillWorkOrder( skill == $skill ) from $workOrder.requiredSkills
then
insertLogical(new IntConstraintOccurrence("requiredSkill", ConstraintType.NEGATIVE_HARD,
1, $engineer));
end
notice, I also removed the binding of the SkillWorkOrder.workorder, as that binding is already implied since you are query against the collection of WorkOrder that you get the list from.
If I have thought this through correctly, what I am doing is collecting all the skills for all the engineers. Then I collect all the workorder, and pull only those workorders that can be matched to an engineer's skill. I am not sure if this will adequately reduce you list of engineers the way you expect. I don't understand the datamodel enough, but I like to take a more focused approach:
rule "requiredSkill"
when
$workOrder : WorkOrder( )
SkillWorkOrder( $skill : skill ) from $workOrder.requiredSkills
$engineer : Engineer( )
SkillEngineer( skill == $skill ) from $engineer.skillEngineerList
then
insertLogical(new IntConstraintOccurrence("requiredSkill", ConstraintType.NEGATIVE_HARD,
1, $engineer));
end
Although all the same details are here, I am first collecting all the work order. For each work order, I extract the skills. Then I get the engineers, but only those where the skill matches the workorder's required skill. It should still be the same result.
The real challenge I see here, is that with all the from clauses you aren't taking advantage of the rete knowledge tree much... and by removing the bindings to the employee you are now looking at all workorders, not just the ones for a specific employee.
From: rules-users-bounces at lists.jboss.org [mailto:rules-users-bounces at lists.jboss.org] On Behalf Of André Fróes
Sent: Tuesday, February 19, 2013 5:02 AM
To: Rules Users List
Subject: Re: [rules-users] Comparing 2 Lists [Planner]
Why's my rule not working properly? I'm pointing my engineer and workorder filling with my list of skills, even so, it is not correctly giving the workorder to engineer.
There is an available engineer with a skill
and there is an unassigned workorder with skill
and workorder skill is equals to engineer skill
then assign workorder to engineer
rule "requiredSkill"
when
$engineer : Engineer()
SkillEngineer( $skill : skill, engineer == $engineer ) from $engineer.skillEngineerList
$workOrder : WorkOrder( engineer == $engineer )
$workOrderRequiredSkill : SkillWorkOrder( skill == $skill, workOrder == $workOrder ) from $workOrder.requiredSkills
then
insertLogical(new IntConstraintOccurrence("requiredSkill", ConstraintType.NEGATIVE_HARD,
1, $engineer));
end
it always set the same engineer to every workorder
2013/2/18 André Fróes <arfmoraes at gmail.com<mailto:arfmoraes at gmail.com>>
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/20130219/10a5101a/attachment-0001.html
More information about the rules-users
mailing list