mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
added SkillConstraint
This commit is contained in:
parent
9b3ca34cfe
commit
0637bdb4b6
2 changed files with 143 additions and 0 deletions
|
|
@ -0,0 +1,36 @@
|
|||
package jsprit.core.problem.constraint;
|
||||
|
||||
import jsprit.core.problem.Skills;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
|
||||
/**
|
||||
* SkillConstraint that ensures that only vehicles with according skills can serve route and job to be inserted.
|
||||
*
|
||||
*/
|
||||
public class SkillConstraint implements HardRouteStateLevelConstraint{
|
||||
|
||||
private RouteAndActivityStateGetter states;
|
||||
|
||||
public SkillConstraint(RouteAndActivityStateGetter states) {
|
||||
this.states = states;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean fulfilled(JobInsertionContext insertionContext) {
|
||||
for(String skill : insertionContext.getJob().getRequiredSkills().values()){
|
||||
if(!insertionContext.getRoute().getVehicle().getSkills().containsSkill(skill)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Skills requiredSkillsForRoute = states.getRouteState(insertionContext.getRoute(), StateFactory.SKILLS, Skills.class);
|
||||
for(String skill : requiredSkillsForRoute.values()){
|
||||
if(!insertionContext.getRoute().getVehicle().getSkills().containsSkill(skill)){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue