mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
added skills
This commit is contained in:
parent
b991793aba
commit
ea7407d936
12 changed files with 1705 additions and 76 deletions
|
|
@ -19,7 +19,10 @@ package jsprit.core.algorithm.recreate;
|
|||
import jsprit.core.algorithm.ExampleActivityCostFunction;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.algorithm.state.UpdateVariableCosts;
|
||||
import jsprit.core.problem.*;
|
||||
import jsprit.core.problem.AbstractActivity;
|
||||
import jsprit.core.problem.AbstractVehicle;
|
||||
import jsprit.core.problem.JobActivityFactory;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.constraint.ConstraintManager;
|
||||
import jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
|
|
@ -33,6 +36,7 @@ import jsprit.core.problem.solution.route.activity.TimeWindow;
|
|||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||
import jsprit.core.util.CostFactory;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
|
@ -44,7 +48,6 @@ import java.util.List;
|
|||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
|
||||
|
|
@ -76,11 +79,8 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
|
||||
|
||||
costs = mock(VehicleRoutingTransportCosts.class);
|
||||
vehicle = mock(AbstractVehicle.class);
|
||||
VehicleType type = mock(VehicleType.class);
|
||||
|
||||
when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1000).build());
|
||||
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0,1000).build();
|
||||
vehicle = VehicleImpl.Builder.newInstance("v1").setType(type).setStartLocationId("0,0").setLatestArrival(100.).build();
|
||||
newVehicle = VehicleImpl.Builder.newInstance("v2").setType(type).setStartLocationId("0,0").setLatestArrival(100.).build();
|
||||
driver = DriverImpl.noDriver();
|
||||
|
|
|
|||
|
|
@ -0,0 +1,98 @@
|
|||
package jsprit.core.algorithm.state;
|
||||
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder;
|
||||
import jsprit.core.algorithm.recreate.NoSolutionFoundException;
|
||||
import jsprit.core.problem.Skills;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.constraint.ConstraintManager;
|
||||
import jsprit.core.problem.io.VrpXMLReader;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
import jsprit.core.util.Solutions;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* to test skills with penalty vehicles
|
||||
*/
|
||||
public class SolomonSkills_IT {
|
||||
|
||||
@Test
|
||||
public void itShouldMakeCorrectAssignmentAccordingToSkills(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(vrpBuilder).read("src/test/resources/solomon_c101.xml");
|
||||
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||
|
||||
//y >= 50 skill1 otherwise skill2
|
||||
//two vehicles: v1 - skill1 #5; v2 - skill2 #6
|
||||
Vehicle solomonVehicle = vrp.getVehicles().iterator().next();
|
||||
VehicleType newType = solomonVehicle.getType();
|
||||
VehicleRoutingProblem.Builder skillProblemBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
for(int i=0;i<6;i++) {
|
||||
VehicleImpl skill1Vehicle = VehicleImpl.Builder.newInstance("skill1_vehicle_"+i).addSkill("skill1")
|
||||
.setStartLocationCoordinate(solomonVehicle.getStartLocationCoordinate()).setStartLocationId(solomonVehicle.getStartLocationId())
|
||||
.setEarliestStart(solomonVehicle.getEarliestDeparture())
|
||||
.setType(newType).build();
|
||||
VehicleImpl skill2Vehicle = VehicleImpl.Builder.newInstance("skill2_vehicle_"+i).addSkill("skill2")
|
||||
.setStartLocationCoordinate(solomonVehicle.getStartLocationCoordinate()).setStartLocationId(solomonVehicle.getStartLocationId())
|
||||
.setEarliestStart(solomonVehicle.getEarliestDeparture())
|
||||
.setType(newType).build();
|
||||
skillProblemBuilder.addVehicle(skill1Vehicle).addVehicle(skill2Vehicle);
|
||||
}
|
||||
for(Job job : vrp.getJobs().values()){
|
||||
Service service = (Service) job;
|
||||
Service.Builder skillServiceBuilder = Service.Builder.newInstance(service.getId()).setServiceTime(service.getServiceDuration())
|
||||
.setCoord(service.getCoord()).setLocationId(service.getLocationId()).setTimeWindow(service.getTimeWindow())
|
||||
.addSizeDimension(0,service.getSize().get(0));
|
||||
if(service.getCoord().getY()<50) skillServiceBuilder.addSkill("skill2");
|
||||
else skillServiceBuilder.addSkill("skill1");
|
||||
skillProblemBuilder.addJob(skillServiceBuilder.build());
|
||||
}
|
||||
skillProblemBuilder.addPenaltyVehicles(3.);
|
||||
skillProblemBuilder.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE);
|
||||
VehicleRoutingProblem skillProblem = skillProblemBuilder.build();
|
||||
|
||||
VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(skillProblem,"src/test/resources/algorithmConfig.xml");
|
||||
vraBuilder.addCoreConstraints();
|
||||
vraBuilder.addDefaultCostCalculators();
|
||||
|
||||
StateManager stateManager = new StateManager(skillProblem);
|
||||
stateManager.updateSkillStates();
|
||||
|
||||
ConstraintManager constraintManager = new ConstraintManager(skillProblem,stateManager);
|
||||
constraintManager.addSkillsConstraint();
|
||||
|
||||
VehicleRoutingAlgorithm vra = vraBuilder.build();
|
||||
vra.setNuOfIterations(500);
|
||||
|
||||
try {
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
|
||||
assertEquals(828.94, solution.getCost(), 0.01);
|
||||
for(VehicleRoute route : solution.getRoutes()){
|
||||
Skills vehicleSkill = route.getVehicle().getSkills();
|
||||
for(Job job : route.getTourActivities().getJobs()){
|
||||
for(String skill : job.getRequiredSkills().values()){
|
||||
if(!vehicleSkill.containsSkill(skill)){
|
||||
assertFalse(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
assertTrue(true);
|
||||
}
|
||||
catch (NoSolutionFoundException e){
|
||||
System.out.println(e.toString());
|
||||
assertFalse(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -94,8 +94,8 @@ public class VehicleRoutingProblemTest {
|
|||
public void whenBuildingWithFourVehiclesAndTwoTypes_vrpShouldContainTheCorrectNuOfTypes(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
||||
VehicleTypeImpl type1 = mock(VehicleTypeImpl.class);
|
||||
VehicleTypeImpl type2 = mock(VehicleTypeImpl.class);
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type1").build();
|
||||
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("type2").build();
|
||||
|
||||
VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("yo").setType(type1).build();
|
||||
VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("yo").setType(type1).build();
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ import org.junit.Test;
|
|||
import java.util.*;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* unit tests to test vehicle dependent time-windows
|
||||
|
|
@ -52,22 +51,23 @@ public class VehicleDependentTimeWindowTest {
|
|||
routingCosts = CostFactory.createEuclideanCosts();
|
||||
vrpBuilder.setRoutingCost(routingCosts);
|
||||
|
||||
vehicle = VehicleImpl.Builder.newInstance("v").setType(mock(VehicleType.class)).setStartLocationId("0,0")
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
vehicle = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocationId("0,0")
|
||||
.setEarliestStart(0.).setLatestArrival(100.).build();
|
||||
|
||||
v2 = VehicleImpl.Builder.newInstance("v2").setType(mock(VehicleType.class)).setStartLocationId("0,0")
|
||||
v2 = VehicleImpl.Builder.newInstance("v2").setType(type).setStartLocationId("0,0")
|
||||
.setEarliestStart(0.).setLatestArrival(60.).build();
|
||||
|
||||
v3 = VehicleImpl.Builder.newInstance("v3").setType(mock(VehicleType.class)).setStartLocationId("0,0")
|
||||
v3 = VehicleImpl.Builder.newInstance("v3").setType(type).setStartLocationId("0,0")
|
||||
.setEarliestStart(0.).setLatestArrival(50.).build();
|
||||
|
||||
v4 = VehicleImpl.Builder.newInstance("v4").setType(mock(VehicleType.class)).setStartLocationId("0,0")
|
||||
v4 = VehicleImpl.Builder.newInstance("v4").setType(type).setStartLocationId("0,0")
|
||||
.setEarliestStart(0.).setLatestArrival(10.).build();
|
||||
|
||||
v5 = VehicleImpl.Builder.newInstance("v5").setType(mock(VehicleType.class)).setStartLocationId("0,0")
|
||||
v5 = VehicleImpl.Builder.newInstance("v5").setType(type).setStartLocationId("0,0")
|
||||
.setEarliestStart(60.).setLatestArrival(100.).build();
|
||||
|
||||
v6 = VehicleImpl.Builder.newInstance("v6").setType(mock(VehicleType.class)).setStartLocationId("0,0")
|
||||
v6 = VehicleImpl.Builder.newInstance("v6").setType(type).setStartLocationId("0,0")
|
||||
.setEndLocationId("40,0").setEarliestStart(0.).setLatestArrival(40.).build();
|
||||
|
||||
vrpBuilder.addVehicle(vehicle).addVehicle(v2).addVehicle(v3).addVehicle(v4).addVehicle(v5).addVehicle(v6);
|
||||
|
|
|
|||
1441
jsprit-core/src/test/resources/solomon_c101.xml
Normal file
1441
jsprit-core/src/test/resources/solomon_c101.xml
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue