mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
added skills to jobs
This commit is contained in:
parent
64ed26e12e
commit
2cd2f54b27
6 changed files with 123 additions and 0 deletions
|
|
@ -16,6 +16,10 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.job;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import jsprit.core.util.Coordinate;
|
||||
|
|
@ -67,6 +71,8 @@ public class Service implements Job {
|
|||
|
||||
protected Capacity capacity;
|
||||
|
||||
protected Set<String> skills = new HashSet<String>();
|
||||
|
||||
/**
|
||||
* Constructs the builder.
|
||||
*
|
||||
|
|
@ -180,6 +186,11 @@ public class Service implements Job {
|
|||
return new Service(this);
|
||||
}
|
||||
|
||||
public Builder addSkill(String string) {
|
||||
skills.add(string.toLowerCase());
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -197,6 +208,8 @@ public class Service implements Job {
|
|||
|
||||
private final Capacity size;
|
||||
|
||||
private final Set<String> skills;
|
||||
|
||||
Service(Builder builder){
|
||||
id = builder.id;
|
||||
locationId = builder.locationId;
|
||||
|
|
@ -205,6 +218,7 @@ public class Service implements Job {
|
|||
timeWindow = builder.timeWindow;
|
||||
type = builder.type;
|
||||
size = builder.capacity;
|
||||
skills = builder.skills;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -300,4 +314,23 @@ public class Service implements Job {
|
|||
return size;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns set of required skills. All skills are in lower case.
|
||||
*
|
||||
* @return
|
||||
*/
|
||||
public Set<String> getRequiredSkills() {
|
||||
return Collections.unmodifiableSet(skills);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this contains requiredSkill. Not case sensitive.
|
||||
*
|
||||
* @param requiredSkill
|
||||
* @return
|
||||
*/
|
||||
public boolean requiresSkill(String requiredSkill){
|
||||
return skills.contains(requiredSkill.toLowerCase());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,9 @@
|
|||
package jsprit.core.problem.job;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import jsprit.core.util.Coordinate;
|
||||
|
|
@ -53,6 +57,8 @@ public class Shipment implements Job{
|
|||
|
||||
private Capacity capacity;
|
||||
|
||||
private Set<String> skills = new HashSet<String>();
|
||||
|
||||
/**
|
||||
* Returns new instance of this builder.
|
||||
*
|
||||
|
|
@ -230,6 +236,11 @@ public class Shipment implements Job{
|
|||
return new Shipment(this);
|
||||
}
|
||||
|
||||
public Builder addSkill(String string) {
|
||||
skills.add(string.toLowerCase());
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -253,6 +264,8 @@ public class Shipment implements Job{
|
|||
|
||||
private final Capacity capacity;
|
||||
|
||||
private final Set<String> skills;
|
||||
|
||||
|
||||
/**
|
||||
* Constructs the shipment.
|
||||
|
|
@ -270,6 +283,7 @@ public class Shipment implements Job{
|
|||
this.deliveryServiceTime = builder.deliveryServiceTime;
|
||||
this.deliveryTimeWindow = builder.deliveryTimeWindow;
|
||||
this.capacity = builder.capacity;
|
||||
this.skills = builder.skills;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -386,5 +400,11 @@ public class Shipment implements Job{
|
|||
return capacity;
|
||||
}
|
||||
|
||||
|
||||
public Set<String> getRequiredSkills() {
|
||||
return Collections.unmodifiableSet(skills);
|
||||
}
|
||||
|
||||
public boolean requiresSkill(String requiredSkill){
|
||||
return skills.contains(requiredSkill.toLowerCase());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package jsprit.core.problem.job;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
@ -39,5 +40,22 @@ public class DeliveryTest {
|
|||
assertEquals(1,one.getSize().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingSkills_theyShouldBeAddedCorrectly(){
|
||||
Delivery s = (Delivery) Delivery.Builder.newInstance("s").setLocationId("loc")
|
||||
.addSkill("drill").addSkill("screwdriver").build();
|
||||
assertTrue(s.getRequiredSkills().contains("drill"));
|
||||
assertTrue(s.requiresSkill("drill"));
|
||||
assertTrue(s.requiresSkill("ScrewDriver"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly(){
|
||||
Delivery s = (Delivery) Delivery.Builder.newInstance("s").setLocationId("loc")
|
||||
.addSkill("DriLl").addSkill("screwDriver").build();
|
||||
assertTrue(s.getRequiredSkills().contains("drill"));
|
||||
assertTrue(s.requiresSkill("drilL"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package jsprit.core.problem.job;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
@ -39,5 +40,22 @@ public class PickupTest {
|
|||
assertEquals(1,one.getSize().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingSkills_theyShouldBeAddedCorrectly(){
|
||||
Pickup s = (Pickup) Pickup.Builder.newInstance("s").setLocationId("loc")
|
||||
.addSkill("drill").addSkill("screwdriver").build();
|
||||
assertTrue(s.getRequiredSkills().contains("drill"));
|
||||
assertTrue(s.requiresSkill("drill"));
|
||||
assertTrue(s.requiresSkill("ScrewDriver"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly(){
|
||||
Pickup s = (Pickup) Pickup.Builder.newInstance("s").setLocationId("loc")
|
||||
.addSkill("DriLl").addSkill("screwDriver").build();
|
||||
assertTrue(s.getRequiredSkills().contains("drill"));
|
||||
assertTrue(s.requiresSkill("drilL"));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -147,4 +147,21 @@ public class ServiceTest {
|
|||
assertEquals(2.0,s.getTimeWindow().getEnd(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingSkills_theyShouldBeAddedCorrectly(){
|
||||
Service s = Service.Builder.newInstance("s").setLocationId("loc")
|
||||
.addSkill("drill").addSkill("screwdriver").build();
|
||||
assertTrue(s.getRequiredSkills().contains("drill"));
|
||||
assertTrue(s.requiresSkill("drill"));
|
||||
assertTrue(s.requiresSkill("ScrewDriver"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly(){
|
||||
Service s = Service.Builder.newInstance("s").setLocationId("loc")
|
||||
.addSkill("DriLl").addSkill("screwDriver").build();
|
||||
assertTrue(s.getRequiredSkills().contains("drill"));
|
||||
assertTrue(s.requiresSkill("drilL"));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -231,4 +231,21 @@ public class ShipmentTest {
|
|||
assertEquals(1,one.getSize().getNuOfDimensions());
|
||||
assertEquals(1,one.getSize().get(0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingSkills_theyShouldBeAddedCorrectly(){
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation("loc").setDeliveryLocation("delLoc")
|
||||
.addSkill("drill").addSkill("screwdriver").build();
|
||||
assertTrue(s.getRequiredSkills().contains("drill"));
|
||||
assertTrue(s.requiresSkill("drill"));
|
||||
assertTrue(s.requiresSkill("ScrewDriver"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly(){
|
||||
Delivery s = (Delivery) Delivery.Builder.newInstance("s").setLocationId("loc")
|
||||
.addSkill("DriLl").addSkill("screwDriver").build();
|
||||
assertTrue(s.getRequiredSkills().contains("drill"));
|
||||
assertTrue(s.requiresSkill("drilL"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue