Implementing skills as "OR" not "And"

Hello,

I am trying to implement the skills as “or” operation not “and”, meaning that if any one of the job’s skills is matched with the vehicle’s skills, then it should be served.

I tried to modify the code in HardSkillConstraint class as follows:

Original code:
for (String skill : insertionContext.getJob().getRequiredSkills().values()) {

        if ( ! insertionContext.getNewVehicle().getSkills().containsSkill(skill)) {
            return false;
        }

}

My modification:
for (String skill : insertionContext.getJob().getRequiredSkills().values()) {

        if ( insertionContext.getNewVehicle().getSkills().containsSkill(skill)) {
            return true;
        }

}

However, this does not work as Intended. Is there anything wrong or should I add anything else?

Thanks!

Hi @kelish09,

I think there are two things that need to be addressed:

  1. the logic:

Since the method returns true at the end, thus, if what you put here is the only change you have made, the logic would be: if the vehicle fulfills any skill of the inserted job OR requiredSkillsForRoute, it will return true.

I think the OR here should be AND, since the vehicle should fulfill the OR skill sets of all jobs in the route, including the inserted one. Therefore, you will need to add a “return false;” if the vehicle does not fulfill any of the skills of the inserted job. Also you should not return true as soon as the vehicle fulfills any of the skills of the inserted job, as you also need to check against requiredSkillsForRoute.

  1. requiredSkillsForRoute:

In the “AND” context, requiredSkillsForRoute will be the union of the “AND” skill sets of all jobs. However, in the “OR” context, the union of the “OR” skill sets is more complicated, e.g., what is requiredSkillsForRoute for a route with 3 jobs with the following skill sets {SkillA OR SkillB} U {Skill A OR SkillC} U {}? And what is requiredSkillsForRoute for a route with N jobs each with 2 skills (assuming the 2N skills are all different)? Perhaps it would be simpler to just go through every job in the route…

Best regards,
He

1 Like

Ah, I see, Thanks for your help!