[rules-users] SimpleScoreCalculator

André Fróes arfmoraes at gmail.com
Wed Feb 20 13:22:56 EST 2013


I added another variable to check if it would still show the broken
constraint and break the planner, and it still happens, I added this:

WorkOrder wo33 = new WorkOrder(103l, 8, Priority.P1, Nature.CORRECTIVE);
SkillWorkOrder swo333 = new SkillWorkOrder(20333l, wo33, ABC1);
SkillWorkOrder swo3332 = new SkillWorkOrder(203332l, wo33, ABC2);
SkillWorkOrder swo3333 = new SkillWorkOrder(203333l, wo33, ABC3);
SkillWorkOrder swo3334 = new SkillWorkOrder(203334l, wo33, ABC4);
List<SkillWorkOrder> lswo33 = new ArrayList<SkillWorkOrder>();
lswo33.add(swo333);
lswo33.add(swo3332);
lswo33.add(swo3333);
lswo33.add(swo3334);
wo33.setRequiredSkills(lswo33);

it breaks in worktime and required skill, and even so, it shows there in
the result breaking everything T.T


2013/2/20 André Fróes <arfmoraes at gmail.com>

> Problem solved (still I think so):
>
> It was simpler (if i'm right):
> --------
> List<Skill> tempEngSkillList = new ArrayList<Skill>();
> for (SkillEngineer se : e.getSkillEngineerList()){
> tempEngSkillList.add(se.getSkill());
> }
>  if (tempEngSkillList.containsAll(requiredSkillList)){
> hardScore += 1;
> }
> --------
>
> the result:
>
> Solved distribution with 10 work orders and 4 engineers:
> ID: 104[Skills: ABC 2,]   -   Andre(8)[Skills: ABC 1,ABC 2,] ------
> Feasible(0)
> ID: 103[Skills: ABC 1,ABC 2,ABC 3,ABC 4,]   -   Denny(8)[Skills: ABC 2,ABC
> 1,ABC 3,ABC 4,] ------ Feasible(0)
> ID: 105[Skills: ABC 2,]   -   Andre(8)[Skills: ABC 1,ABC 2,] ------
> Feasible(0)
> ID: 102[Skills: ABC 2,]   -   Andre(8)[Skills: ABC 1,ABC 2,] ------
> Feasible(0)
> ID: 101[Skills: ABC 1,ABC 2,ABC 4,]   -   Richard(8)[Skills: ABC 1,ABC
> 2,ABC 4,] ------ Feasible(0)
> ID: 107[Skills: ABC 1,ABC 3,]   -   Fabio(8)[Skills: ABC 3,ABC 1,] ------
> Feasible(0)
> ID: 106[Skills: ABC 1,]   -   Fabio(8)[Skills: ABC 3,ABC 1,] ------
> Feasible(0)
> ID: 108[Skills: ABC 1,ABC 4,]   -   Richard(8)[Skills: ABC 1,ABC 2,ABC 4,]
> ------ Feasible(0)
> ID: 109[Skills: ABC 3,]   -   Fabio(8)[Skills: ABC 3,ABC 1,] ------
> Feasible(0)
> ID: 110[Skills: ABC 1,]   -   Andre(8)[Skills: ABC 1,ABC 2,] ------
> Feasible(0)
>
>
> 2013/2/20 André Fróes <arfmoraes at gmail.com>
>
>> Not fixed, i threw it on excel and make a comparison with expected
>> results and there are 2 broken there. This is how it would be (feasible
>> solution):
>>
>> ID 101 - Engineer Richard
>> ID 102 - Engineer Andre
>> ID 103 - Engineer Denny
>> ID 104 - Engineer Andre
>> ID 105 - Engineer Andre
>> ID 106 - Engineer Andre
>> ID 107 - Engineer Fabio
>> ID 108 - Engineer Richard
>> ID 109 - Engineer Fabio
>> ID 110 - Engineer Fabio
>>
>> this was the result:
>>
>> Solved distribution with 10 work orders and 4 engineers:
>> ID: 104[Skills: ABC 2,]   -   Richard(8)[Skills: ABC 1,ABC 2,ABC 4,]
>> ------ Feasible(0)
>> ID: 103[Skills: ABC 1,ABC 2,ABC 3,ABC 4,]   -   Denny(8)[Skills: ABC
>> 2,ABC 1,ABC 3,ABC 4,] ------ Feasible(0)
>> ID: 105[Skills: ABC 2,]   -   Fabio(8)[Skills: ABC 3,ABC 1,] ------
>> Broken(1)
>> ID: 102[Skills: ABC 2,]   -   Andre(8)[Skills: ABC 1,ABC 2,] ------
>> Feasible(0)
>> ID: 101[Skills: ABC 1,ABC 2,ABC 4,]   -   Richard(8)[Skills: ABC 1,ABC
>> 2,ABC 4,] ------ Feasible(0)
>> ID: 107[Skills: ABC 1,ABC 3,]   -   Fabio(8)[Skills: ABC 3,ABC 1,] ------
>> Feasible(0)
>> ID: 106[Skills: ABC 1,]   -   Andre(8)[Skills: ABC 1,ABC 2,] ------
>> Feasible(0)
>> ID: 108[Skills: ABC 1,ABC 4,]   -   Andre(8)[Skills: ABC 1,ABC 2,] ------
>> Broken(1)
>> ID: 109[Skills: ABC 3,]   -   Andre(8)[Skills: ABC 1,ABC 2,] ------
>> Broken(1)
>> ID: 110[Skills: ABC 1,]   -   Andre(8)[Skills: ABC 1,ABC 2,] ------
>> Feasible(0)
>>
>> Still working on it, I accept any tips :D
>>
>>
>> 2013/2/20 André Fróes <arfmoraes at gmail.com>
>>
>>> I think I fixed it, but the broken constraint is still showing, i don't
>>> know how to remove it. I did this:
>>>
>>> verified if the engineer skill list had the same size or bigger than the
>>> requiredSkillList, iterate to check skills between both counting the
>>> matches and then, if the match was 100% to other, give the workorder
>>>
>>> if (e.getSkillEngineerList().size() >= requiredSkillList.size()) {
>>> int temp = 0;
>>>  for (SkillEngineer se : e.getSkillEngineerList()) {
>>> for (Skill s : requiredSkillList) {
>>> if (se.getSkill().getId() == s.getId()) {
>>>  temp++;
>>> }
>>> }
>>> }
>>>  if (temp == requiredSkillList.size()) {
>>> hardScore += 1;
>>> }
>>>  }
>>>
>>>
>>> 2013/2/20 André Fróes <arfmoraes at gmail.com>
>>>
>>>> After some workaround I noticed that the workorders are not being 100%
>>>> corretly distributed to, i've changed the scorecalculator to this:
>>>>
>>>> int commonSkillCount = 0;
>>>>  for (Skill s : requiredSkillList){
>>>> for (SkillEngineer se : e.getSkillEngineerList()){
>>>> if (se.getSkill().getId() == s.getId()){
>>>>  commonSkillCount++;
>>>> }
>>>> }
>>>> }
>>>>
>>>> if ((commonSkillCount - e.getSkillEngineerList().size()) <= 0){
>>>> hardScore += commonSkillCount;
>>>>  }
>>>>
>>>> and I got the result
>>>>
>>>> ID: 104[Skills: ABC 2,]   -   Trewq(8)[Skills: ABC 3,ABC 2,] ------
>>>> Feasible(0)
>>>> ID: 103[Skills: ABC 3,]   -   Trewq(8)[Skills: ABC 3,ABC 2,] ------
>>>> Feasible(0)
>>>> ID: 105[Skills: ABC 4,ABC 3,]   -   Poiuy(8)[Skills: ABC 1,ABC 2,ABC
>>>> 3,ABC 4,] ------ Feasible(0)
>>>> ID: 102[Skills: ABC 2,ABC 1,ABC 4,]   -   Qwert(8)[Skills: ABC 2,ABC
>>>> 4,] ------ Broken(1)
>>>> ID: 101[Skills: ABC 1,]   -   Lkjhg(8)[Skills: ABC 4,ABC 1,] ------
>>>> Feasible(0)
>>>> ID: 107[Skills: ABC 4,]   -   Lkjhg(8)[Skills: ABC 4,ABC 1,] ------
>>>> Feasible(0)
>>>> ID: 106[Skills: ABC 1,]   -   Qwert(8)[Skills: ABC 2,ABC 4,] ------
>>>> Broken(1)
>>>> ID: 108[Skills: ABC 3,ABC 2,]   -   Poiuy(8)[Skills: ABC 1,ABC 2,ABC
>>>> 3,ABC 4,] ------ Feasible(0)
>>>>
>>>> there's a workorder that woud be disconsidered because no engineer have
>>>> the required skill to complete it
>>>>
>>>>
>>>> 2013/2/19 André Fróes <arfmoraes at gmail.com>
>>>>
>>>>> 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/20130220/91b4a167/attachment-0001.html 


More information about the rules-users mailing list