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;
|
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.Capacity;
|
||||||
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||||
import jsprit.core.util.Coordinate;
|
import jsprit.core.util.Coordinate;
|
||||||
|
|
@ -67,6 +71,8 @@ public class Service implements Job {
|
||||||
|
|
||||||
protected Capacity capacity;
|
protected Capacity capacity;
|
||||||
|
|
||||||
|
protected Set<String> skills = new HashSet<String>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs the builder.
|
* Constructs the builder.
|
||||||
*
|
*
|
||||||
|
|
@ -179,6 +185,11 @@ public class Service implements Job {
|
||||||
capacity = capacityBuilder.build();
|
capacity = capacityBuilder.build();
|
||||||
return new Service(this);
|
return new Service(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder addSkill(String string) {
|
||||||
|
skills.add(string.toLowerCase());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -196,6 +207,8 @@ public class Service implements Job {
|
||||||
private final TimeWindow timeWindow;
|
private final TimeWindow timeWindow;
|
||||||
|
|
||||||
private final Capacity size;
|
private final Capacity size;
|
||||||
|
|
||||||
|
private final Set<String> skills;
|
||||||
|
|
||||||
Service(Builder builder){
|
Service(Builder builder){
|
||||||
id = builder.id;
|
id = builder.id;
|
||||||
|
|
@ -205,6 +218,7 @@ public class Service implements Job {
|
||||||
timeWindow = builder.timeWindow;
|
timeWindow = builder.timeWindow;
|
||||||
type = builder.type;
|
type = builder.type;
|
||||||
size = builder.capacity;
|
size = builder.capacity;
|
||||||
|
skills = builder.skills;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -299,5 +313,24 @@ public class Service implements Job {
|
||||||
public Capacity getSize() {
|
public Capacity getSize() {
|
||||||
return size;
|
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;
|
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.Capacity;
|
||||||
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||||
import jsprit.core.util.Coordinate;
|
import jsprit.core.util.Coordinate;
|
||||||
|
|
@ -53,6 +57,8 @@ public class Shipment implements Job{
|
||||||
|
|
||||||
private Capacity capacity;
|
private Capacity capacity;
|
||||||
|
|
||||||
|
private Set<String> skills = new HashSet<String>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns new instance of this builder.
|
* Returns new instance of this builder.
|
||||||
*
|
*
|
||||||
|
|
@ -230,6 +236,11 @@ public class Shipment implements Job{
|
||||||
return new Shipment(this);
|
return new Shipment(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Builder addSkill(String string) {
|
||||||
|
skills.add(string.toLowerCase());
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -252,6 +263,8 @@ public class Shipment implements Job{
|
||||||
private final TimeWindow pickupTimeWindow;
|
private final TimeWindow pickupTimeWindow;
|
||||||
|
|
||||||
private final Capacity capacity;
|
private final Capacity capacity;
|
||||||
|
|
||||||
|
private final Set<String> skills;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -270,6 +283,7 @@ public class Shipment implements Job{
|
||||||
this.deliveryServiceTime = builder.deliveryServiceTime;
|
this.deliveryServiceTime = builder.deliveryServiceTime;
|
||||||
this.deliveryTimeWindow = builder.deliveryTimeWindow;
|
this.deliveryTimeWindow = builder.deliveryTimeWindow;
|
||||||
this.capacity = builder.capacity;
|
this.capacity = builder.capacity;
|
||||||
|
this.skills = builder.skills;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -386,5 +400,11 @@ public class Shipment implements Job{
|
||||||
return capacity;
|
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;
|
package jsprit.core.problem.job;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
@ -38,6 +39,23 @@ public class DeliveryTest {
|
||||||
assertEquals(1,one.getSize().getNuOfDimensions());
|
assertEquals(1,one.getSize().getNuOfDimensions());
|
||||||
assertEquals(1,one.getSize().get(0));
|
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;
|
package jsprit.core.problem.job;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
|
@ -38,6 +39,23 @@ public class PickupTest {
|
||||||
assertEquals(1,one.getSize().getNuOfDimensions());
|
assertEquals(1,one.getSize().getNuOfDimensions());
|
||||||
assertEquals(1,one.getSize().get(0));
|
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"));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -146,5 +146,22 @@ public class ServiceTest {
|
||||||
assertEquals(1.0,s.getTimeWindow().getStart(),0.01);
|
assertEquals(1.0,s.getTimeWindow().getStart(),0.01);
|
||||||
assertEquals(2.0,s.getTimeWindow().getEnd(),0.01);
|
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().getNuOfDimensions());
|
||||||
assertEquals(1,one.getSize().get(0));
|
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