[rules-users] SimpleScoreCalculator
André Fróes
arfmoraes at gmail.com
Tue Feb 19 13:20:11 EST 2013
I forgot to post the code:
public HardAndSoftScore calculateScore(Distributor distributor) {
int hardScore = 0;
int softScore = 0;
for (Engineer e : distributor.getEngineerList()){
long skill = e.getSkillEngineerList().get(0).getSkill().getId();
int requiredWorktime = 0;
List<Skill> requiredSkillList = new ArrayList<Skill>();
for (WorkOrder o : distributor.getWorkOrderList()){
if (e.equals(o.getEngineer())){
requiredWorktime += o.getRequiredWorktime();
for (SkillWorkOrder swo : o.getRequiredSkills()){
requiredSkillList.add(swo.getSkill());
}
}
}
int engineerAvailableTime = e.getWorktime() - requiredWorktime;
if (engineerAvailableTime < 0 ){
hardScore += engineerAvailableTime;
}
int commonSkillCount = 0;
for (SkillEngineer se : e.getSkillEngineerList()){
for (Skill s : requiredSkillList){
if (se.getSkill().getId() == s.getId()){
commonSkillCount++;
}
}
}
if (commonSkillCount != 0){
hardScore += commonSkillCount;
}
}
return DefaultHardAndSoftScore.valueOf(hardScore, softScore);
}
( but i still want to try to create this in dsl rule after this work :D )
2013/2/19 André Fróes <arfmoraes at gmail.com>
> I managed solving that problem even when there's more than one skill
> involved, but now my hard constraint of worktime breaks if I add more
> worktime than the sum of engineers worktime.
>
> (8) is the worktime, my workorders all have a worktime of 4 hours, so, I
> got 32 available hours and 32 hours of workorders to be assigned right?
> When I stick to this plan, it works:
>
> ----Compilation Result----
> Solved distribution with 8 work orders and 4 engineers:
> ID: 104[Skills: (1002) ABC 2] - Qwert(8)[Skills: (1002) ABC 2]
> ID: 103[Skills: (1003) ABC 3] - Trewq(8)[Skills: (1003) ABC 3]
> ID: 105[Skills: (1004) ABC 4] - Lkjhg(8)[Skills: (1004) ABC 4]
> ID: 102[Skills: (1002) ABC 2] - Qwert(8)[Skills: (1002) ABC 2]
> ID: 101[Skills: (1001) ABC 1] - Poiuy(8)[Skills: (1001) ABC 1]
> ID: 107[Skills: (1004) ABC 4] - Lkjhg(8)[Skills: (1004) ABC 4]
> ID: 106[Skills: (1001) ABC 1] - Poiuy(8)[Skills: (1001) ABC 1]
> ID: 108[Skills: (1003) ABC 3] - Trewq(8)[Skills: (1003) ABC 3]
> ---------------
>
> So, if I add another worktime with 4 hours, it messes everything, this is
> the outcome:
>
> Solved distribution with 9 work orders and 4 engineers:
> ID: 104[Skills: (1002) ABC 2] - Qwert(8)[Skills: (1002) ABC 2]
> ID: 103[Skills: (1003) ABC 3] - Trewq(8)[Skills: (1003) ABC 3]
> ID: 105[Skills: (1004) ABC 4] - Lkjhg(8)[Skills: (1004) ABC 4]
> ID: 102[Skills: (1002) ABC 2] - Qwert(8)[Skills: (1002) ABC 2]
> ID: 101[Skills: (1001) ABC 1] - Poiuy(8)[Skills: (1001) ABC 1]
> ID: 107[Skills: (1004) ABC 4] - Lkjhg(8)[Skills: (1004) ABC 4]
> ID: 106[Skills: (1001) ABC 1] - Poiuy(8)[Skills: (1001) ABC 1]
> ID: 108[Skills: (1003) ABC 3] - Trewq(8)[Skills: (1003) ABC 3]
> ID: 109[Skills: (1003) ABC 3] - Trewq(8)[Skills: (1003) ABC 3]
>
> ------------
>
> to be precise, i don't know if it is because of worktime or skill
>
>
> 2013/2/19 André Fróes <arfmoraes at gmail.com>
>
>> Just one correction, it is sorting correctly when there's one workorder
>> with a skill, if there's another workorder with same skill, it doesn't sort
>> that workorder to that skill.
>>
>> This is what is happening:
>>
>> Workorder skill ABC1 ------------ Engineer skill ABC1
>> Workorder skill ABC2 ------------ Engineer skill ABC2
>> Workorder skill ABC1 ------------ Engineer skill ABC2
>>
>> but if there's only one workorder with one skill it works:
>>
>> Workorder skill ABC1 ------------ Engineer skill ABC1
>> Workorder skill ABC2 ------------ Engineer skill ABC2
>> Workorder skill ABC3 ------------ Engineer skill ABC3
>>
>> so, from the second workorder on, with a repeated required skill, it
>> doesn't sort properly
>>
>>
>> 2013/2/19 André Fróes <arfmoraes at gmail.com>
>>
>>> Hello, since i'm not moving a step from where I am at dsl rule, I'm
>>> trying to do it with SimpleScoreCalculator, but the same is happening.
>>>
>>> ------------
>>> public HardAndSoftScore calculateScore(Distributor distributor) {
>>> int hardScore = 0;
>>> int softScore = 0;
>>> for (Engineer e : distributor.getEngineerList()){
>>> long skill = e.getSkillEngineerList().get(0).getSkill().getId();
>>> int requiredWorktime = 0;
>>> long requiredSkill = 0l;
>>> for (WorkOrder o : distributor.getWorkOrderList()){
>>> if (e.equals(o.getEngineer())){
>>> requiredWorktime += o.getRequiredWorktime();
>>> requiredSkill = o.getRequiredSkills().get(0).getSkill().getId();
>>> }
>>> }
>>> int engineerAvailableTime = e.getWorktime() - requiredWorktime;
>>> if (engineerAvailableTime < 0 ){
>>> hardScore += engineerAvailableTime;
>>> }
>>> if (requiredSkill == skill){
>>> softScore += requiredSkill;
>>> }
>>> }
>>> return DefaultHardAndSoftScore.valueOf(hardScore, softScore);
>>> }
>>> ------------
>>>
>>> wouldn't that have to fit since i'm comparing the 1st attribute of each
>>> skill list from engineers and workorders? And how can I weight which
>>> engineer would be better to a determined workorder if the workorder have
>>> more skills and so does the engineer?
>>>
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/rules-users/attachments/20130219/88f0c85c/attachment-0001.html
More information about the rules-users
mailing list