mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
migrated from log4j1x to log4j2
This commit is contained in:
parent
64f0829e4a
commit
42570d69ac
47 changed files with 480 additions and 437 deletions
|
|
@ -37,7 +37,8 @@ import jsprit.core.problem.solution.route.state.StateFactory;
|
|||
import jsprit.core.problem.vehicle.InfiniteFleetManagerFactory;
|
||||
import jsprit.core.problem.vehicle.VehicleFleetManager;
|
||||
import jsprit.core.util.Solutions;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.apache.logging.log4j.LogManager;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
@ -50,7 +51,7 @@ public class BuildPDVRPAlgoFromScratch_IT {
|
|||
|
||||
VehicleRoutingAlgorithm vra;
|
||||
|
||||
static Logger log = Logger.getLogger(BuildPDVRPAlgoFromScratch_IT.class);
|
||||
static Logger log = LogManager.getLogger(BuildPDVRPAlgoFromScratch_IT.class);
|
||||
|
||||
@Before
|
||||
public void setup(){
|
||||
|
|
|
|||
|
|
@ -0,0 +1,49 @@
|
|||
package jsprit.core.algorithm;
|
||||
|
||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import jsprit.core.reporting.SolutionPrinter;
|
||||
import jsprit.core.util.Coordinate;
|
||||
import jsprit.core.util.Solutions;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* Created by schroeder on 24.07.14.
|
||||
*/
|
||||
public class ExternalInitialSolutionIsInValidTest {
|
||||
|
||||
@Test
|
||||
public void itShouldSolveProblemWithIniSolutionExternallyCreated(){
|
||||
|
||||
Service s1 = Service.Builder.newInstance("s1").setCoord(Coordinate.newInstance(10,0)).build();
|
||||
Service s2 = Service.Builder.newInstance("s2").setCoord(Coordinate.newInstance(0,10)).build();
|
||||
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v1").setStartLocationCoordinate(Coordinate.newInstance(0,0)).build();
|
||||
|
||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s1).addJob(s2).addVehicle(vehicle).build();
|
||||
|
||||
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithm_without_construction.xml");
|
||||
|
||||
VehicleImpl vehicle2 = VehicleImpl.Builder.newInstance("v1").setStartLocationCoordinate(Coordinate.newInstance(0,0)).build();
|
||||
/*
|
||||
create ini sol
|
||||
*/
|
||||
VehicleRoute route1 = VehicleRoute.Builder.newInstance(vehicle).setJobActivityFactory(vrp.getJobActivityFactory()).addService(s1).build();
|
||||
|
||||
vra.addInitialSolution(new VehicleRoutingProblemSolution(Arrays.asList(route1),20.));
|
||||
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
|
||||
SolutionPrinter.print(vrp, Solutions.bestOf(solutions), SolutionPrinter.Print.VERBOSE);
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -36,8 +36,6 @@ import jsprit.core.problem.job.Pickup;
|
|||
import jsprit.core.problem.job.Shipment;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.DeliverService;
|
||||
import jsprit.core.problem.solution.route.activity.PickupService;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
|
@ -48,13 +46,11 @@ import jsprit.core.util.CostFactory;
|
|||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
public class ServiceInsertionAndLoadConstraintsTest {
|
||||
|
|
@ -117,41 +113,28 @@ public class ServiceInsertionAndLoadConstraintsTest {
|
|||
Pickup pickup = (Pickup) Pickup.Builder.newInstance("pick").addSizeDimension(0, 15).setLocationId("0,10").build();
|
||||
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0, 50).setCostPerDistance(1).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("0,0").setType(type).build();
|
||||
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("0,0").setType(type).build();
|
||||
|
||||
final VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(delivery).addJob(pickup).addVehicle(vehicle).build();
|
||||
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
route.setVehicleAndDepartureTime(vehicle, 0.0);
|
||||
|
||||
Inserter inserter = new Inserter(new InsertionListeners(), vehicleRoutingProblem);
|
||||
{
|
||||
List<AbstractActivity> acts = new ArrayList<AbstractActivity>();
|
||||
acts.add(new DeliverService(delivery));
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(delivery)).thenReturn(acts);
|
||||
}
|
||||
{
|
||||
List<AbstractActivity> acts = new ArrayList<AbstractActivity>();
|
||||
acts.add(new PickupService(pickup));
|
||||
when(vehicleRoutingProblem.copyAndGetActivities(pickup)).thenReturn(acts);
|
||||
}
|
||||
Inserter inserter = new Inserter(new InsertionListeners(), vrp);
|
||||
inserter.insertJob(delivery, new InsertionData(0,0,0,vehicle,null), route);
|
||||
|
||||
JobActivityFactory activityFactory = new JobActivityFactory() {
|
||||
@Override
|
||||
public List<AbstractActivity> createActivities(Job job) {
|
||||
return vehicleRoutingProblem.copyAndGetActivities(job);
|
||||
return vrp.copyAndGetActivities(job);
|
||||
}
|
||||
};
|
||||
|
||||
VehicleRoutingProblem vrp = mock(VehicleRoutingProblem.class);
|
||||
|
||||
StateManager stateManager = new StateManager(vrp);
|
||||
stateManager.updateLoadStates();
|
||||
|
||||
ConstraintManager constraintManager = new ConstraintManager(vrp,stateManager);
|
||||
constraintManager.addLoadConstraint();
|
||||
// constraintManager.addConstraint(new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager),Priority.CRITICAL);
|
||||
// constraintManager.addConstraint(new ShipmentPickupsFirstConstraint(),Priority.CRITICAL);
|
||||
|
||||
stateManager.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
JobCalculatorSwitcher switcher = new JobCalculatorSwitcher();
|
||||
|
|
@ -163,11 +146,9 @@ public class ServiceInsertionAndLoadConstraintsTest {
|
|||
switcher.put(Pickup.class, serviceInsertionCalc);
|
||||
switcher.put(Delivery.class, serviceInsertionCalc);
|
||||
switcher.put(Shipment.class, insertionCalculator);
|
||||
|
||||
// Pickup service = (Pickup)Pickup.Builder.newInstance("pick", 1).setLocationId("5,5").build();
|
||||
|
||||
InsertionData iData = switcher.getInsertionData(route, pickup, vehicle, 0, DriverImpl.noDriver(), Double.MAX_VALUE);
|
||||
// routeActVisitor.visit(route);
|
||||
|
||||
|
||||
assertEquals(1, iData.getDeliveryInsertionIndex());
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -249,7 +249,6 @@ public class ShipmentInsertionCalculatorTest {
|
|||
route.setVehicleAndDepartureTime(vehicle, 0.0);
|
||||
|
||||
Inserter inserter = new Inserter(new InsertionListeners(), vrp);
|
||||
|
||||
inserter.insertJob(shipment, new InsertionData(0,0,0,vehicle,null), route);
|
||||
inserter.insertJob(shipment2, new InsertionData(0,1,2,vehicle,null), route);
|
||||
|
||||
|
|
@ -263,13 +262,7 @@ public class ShipmentInsertionCalculatorTest {
|
|||
|
||||
ShipmentInsertionCalculator insertionCalculator = new ShipmentInsertionCalculator(routingCosts, activityInsertionCostsCalculator,
|
||||
constraintManager);
|
||||
|
||||
JobActivityFactory activityFactory = mock(JobActivityFactory.class);
|
||||
List<AbstractActivity> activities = new ArrayList<AbstractActivity>();
|
||||
activities.add(new PickupShipment(shipment3));
|
||||
activities.add(new DeliverShipment(shipment3));
|
||||
when(activityFactory.createActivities(shipment3)).thenReturn(activities);
|
||||
insertionCalculator.setJobActivityFactory(activityFactory);
|
||||
insertionCalculator.setJobActivityFactory(vrp.getJobActivityFactory());
|
||||
|
||||
InsertionData iData = insertionCalculator.getInsertionData(route, shipment3, vehicle, 0.0, DriverImpl.noDriver(), Double.MAX_VALUE);
|
||||
assertTrue(iData instanceof InsertionData.NoInsertionFound);
|
||||
|
|
|
|||
|
|
@ -40,8 +40,6 @@ import jsprit.core.util.Coordinate;
|
|||
import jsprit.core.util.EuclideanDistanceCalculator;
|
||||
import jsprit.core.util.Locations;
|
||||
import jsprit.core.util.ManhattanDistanceCalculator;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
@ -73,12 +71,11 @@ public class TestCalculatesServiceInsertion {
|
|||
|
||||
private NoDriver driver;
|
||||
|
||||
// private UpdateStates stateUpdater;
|
||||
private VehicleRoutingProblem vrp;
|
||||
|
||||
@Before
|
||||
public void setup(){
|
||||
Logger.getRootLogger().setLevel(Level.DEBUG);
|
||||
|
||||
|
||||
VehicleType t1 = VehicleTypeImpl.Builder.newInstance("t1").addCapacityDimension(0, 1000).setCostPerDistance(1.0).build();
|
||||
vehicle = VehicleImpl.Builder.newInstance("vehicle").setLatestArrival(100.0).setStartLocationId("0,0").setType(t1).build();
|
||||
|
||||
|
|
@ -121,7 +118,7 @@ public class TestCalculatesServiceInsertion {
|
|||
jobs.add(third);
|
||||
jobs.add(second);
|
||||
|
||||
final VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addAllJobs(jobs).addVehicle(vehicle).setRoutingCost(costs).build();
|
||||
vrp = VehicleRoutingProblem.Builder.newInstance().addAllJobs(jobs).addVehicle(vehicle).setRoutingCost(costs).build();
|
||||
|
||||
states = new StateManager(vrp);
|
||||
states.updateLoadStates();
|
||||
|
|
@ -154,7 +151,7 @@ public class TestCalculatesServiceInsertion {
|
|||
|
||||
@Test
|
||||
public void whenInsertingTheSecondJobInAnNonEmptyTourWithVehicle_itCalculatesMarginalCostChanges(){
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).build();
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).build();
|
||||
states.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
InsertionData iData = serviceInsertion.getInsertionData(route, third, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
|
||||
|
|
@ -164,7 +161,7 @@ public class TestCalculatesServiceInsertion {
|
|||
|
||||
@Test
|
||||
public void whenInsertingThirdJobWithVehicle_itCalculatesMarginalCostChanges(){
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).addService(third).build();
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(third).build();
|
||||
states.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
InsertionData iData = serviceInsertion.getInsertionData(route, second, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
|
||||
|
|
@ -174,7 +171,7 @@ public class TestCalculatesServiceInsertion {
|
|||
|
||||
@Test
|
||||
public void whenInsertingThirdJobWithNewVehicle_itCalculatesMarginalCostChanges(){
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).addService(third).build();
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(third).build();
|
||||
states.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
InsertionData iData = serviceInsertion.getInsertionData(route, second, newVehicle, newVehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
|
||||
|
|
@ -184,7 +181,7 @@ public class TestCalculatesServiceInsertion {
|
|||
|
||||
@Test
|
||||
public void whenInsertingASecondJobWithAVehicle_itCalculatesLocalMarginalCostChanges(){
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).addService(second).build();
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(second).build();
|
||||
states.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
InsertionData iData = serviceInsertion.getInsertionData(route, third, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
|
||||
|
|
@ -195,7 +192,7 @@ public class TestCalculatesServiceInsertion {
|
|||
@Test
|
||||
public void whenInsertingASecondJobWithANewVehicle_itCalculatesLocalMarginalCostChanges(){
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).addService(second).build();
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(second).build();
|
||||
|
||||
states.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
|
|
|
|||
|
|
@ -29,15 +29,11 @@ import jsprit.core.problem.driver.DriverImpl.NoDriver;
|
|||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||
import jsprit.core.problem.solution.route.activity.ServiceActivity;
|
||||
import jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import jsprit.core.problem.solution.route.activity.TourActivities;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
import jsprit.core.util.CostFactory;
|
||||
import org.apache.log4j.Level;
|
||||
import org.apache.log4j.Logger;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
@ -72,10 +68,12 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
private StateManager states;
|
||||
|
||||
private NoDriver driver;
|
||||
|
||||
private VehicleRoutingProblem vrp;
|
||||
|
||||
@Before
|
||||
public void setup(){
|
||||
Logger.getRootLogger().setLevel(Level.DEBUG);
|
||||
|
||||
|
||||
costs = mock(VehicleRoutingTransportCosts.class);
|
||||
vehicle = mock(AbstractVehicle.class);
|
||||
|
|
@ -113,7 +111,7 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
jobs.add(second);
|
||||
jobs.add(third);
|
||||
|
||||
final VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addAllJobs(jobs).addVehicle(vehicle).addVehicle(newVehicle).setRoutingCost(costs).build();
|
||||
vrp = VehicleRoutingProblem.Builder.newInstance().addAllJobs(jobs).addVehicle(vehicle).addVehicle(newVehicle).setRoutingCost(costs).build();
|
||||
|
||||
states = new StateManager(vrp);
|
||||
states.updateLoadStates();
|
||||
|
|
@ -152,11 +150,7 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
|
||||
@Test
|
||||
public void whenInsertingThirdJobWithVehicle_itCalculatesMarginalCostChanges(){
|
||||
TourActivities tour = new TourActivities();
|
||||
tour.addActivity(ServiceActivity.newInstance(first));
|
||||
tour.addActivity(ServiceActivity.newInstance(second));
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).addService(second).build();
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(second).build();
|
||||
states.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
InsertionData iData = serviceInsertion.getInsertionData(route, third, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
|
||||
|
|
@ -166,11 +160,7 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
|
||||
@Test
|
||||
public void whenInsertingThirdJobWithNewVehicle_itCalculatesMarginalCostChanges(){
|
||||
TourActivities tour = new TourActivities();
|
||||
tour.addActivity(ServiceActivity.newInstance(first));
|
||||
tour.addActivity(ServiceActivity.newInstance(second));
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).addService(second).build();
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(second).build();
|
||||
states.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
InsertionData iData = serviceInsertion.getInsertionData(route, third, newVehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
|
||||
|
|
@ -180,11 +170,7 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
|
||||
@Test
|
||||
public void whenInsertingASecondJobWithAVehicle_itCalculatesLocalMarginalCostChanges(){
|
||||
TourActivities tour = new TourActivities();
|
||||
tour.addActivity(ServiceActivity.newInstance(first));
|
||||
tour.addActivity(ServiceActivity.newInstance(third));
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).addService(third).build();
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(third).build();
|
||||
states.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
InsertionData iData = serviceInsertion.getInsertionData(route, second, vehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
|
||||
|
|
@ -194,11 +180,7 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
|
||||
@Test
|
||||
public void whenInsertingASecondJobWithANewVehicle_itCalculatesLocalMarginalCostChanges(){
|
||||
TourActivities tour = new TourActivities();
|
||||
tour.addActivity(ServiceActivity.newInstance(first));
|
||||
tour.addActivity(ServiceActivity.newInstance(third));
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).addService(first).addService(third).build();
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle, driver).setJobActivityFactory(vrp.getJobActivityFactory()).addService(first).addService(third).build();
|
||||
states.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
InsertionData iData = serviceInsertion.getInsertionData(route, second, newVehicle, vehicle.getEarliestDeparture(), null, Double.MAX_VALUE);
|
||||
|
|
|
|||
|
|
@ -30,13 +30,13 @@ import jsprit.core.problem.solution.route.activity.PickupService;
|
|||
import jsprit.core.problem.solution.route.activity.PickupShipment;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
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 org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
|
||||
public class HardPickupAndDeliveryShipmentActivityConstraintTest {
|
||||
|
|
@ -46,67 +46,66 @@ public class HardPickupAndDeliveryShipmentActivityConstraintTest {
|
|||
StateManager stateManager;
|
||||
|
||||
Shipment shipment;
|
||||
|
||||
Service s1;
|
||||
|
||||
Service s2;
|
||||
|
||||
PickupAndDeliverShipmentLoadActivityLevelConstraint constraint;
|
||||
|
||||
JobInsertionContext iFacts;
|
||||
|
||||
VehicleRoutingProblem vrp;
|
||||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
vehicle = mock(Vehicle.class);
|
||||
s1 = Service.Builder.newInstance("s1").setLocationId("loc").build();
|
||||
s2 = Service.Builder.newInstance("s2").setLocationId("loc").build();
|
||||
shipment = Shipment.Builder.newInstance("shipment").setPickupLocation("pickLoc").setDeliveryLocation("delLoc").addSizeDimension(0,1).build();
|
||||
|
||||
|
||||
// when(vehicle.getCapacity()).thenReturn(2);
|
||||
VehicleType type = mock(VehicleType.class);
|
||||
when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build());
|
||||
when(vehicle.getType()).thenReturn(type);
|
||||
// when(vehicle.getType().getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build());
|
||||
stateManager = new StateManager(mock(VehicleRoutingProblem.class));
|
||||
shipment = mock(Shipment.class);
|
||||
when(shipment.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 1).build());
|
||||
// when(shipment.getCapacityDemand()).thenReturn(1);
|
||||
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0,2).build();
|
||||
vehicle = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocationId("start").build();
|
||||
|
||||
vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s1).addJob(s2).addJob(shipment).addVehicle(vehicle).build();
|
||||
|
||||
stateManager = new StateManager(vrp);
|
||||
|
||||
iFacts = new JobInsertionContext(null, null, vehicle, null, 0.0);
|
||||
constraint = new PickupAndDeliverShipmentLoadActivityLevelConstraint(stateManager);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPickupActivityIsInsertedAndLoadIsSufficient_returnFullFilled(){
|
||||
PickupService pickupService = new PickupService(mock(Service.class));
|
||||
PickupService anotherService = new PickupService(mock(Service.class));
|
||||
PickupShipment pickupShipment = new PickupShipment(shipment);
|
||||
PickupService pickupService = (PickupService) vrp.getActivities(s1).get(0);
|
||||
PickupService anotherService = (PickupService) vrp.getActivities(s2).get(0);
|
||||
PickupShipment pickupShipment = (PickupShipment) vrp.getActivities(shipment).get(0);
|
||||
|
||||
assertEquals(ConstraintsStatus.FULFILLED,constraint.fulfilled(iFacts, pickupService, pickupShipment, anotherService, 0.0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPickupActivityIsInsertedAndLoadIsNotSufficient_returnNOT_FullFilled(){
|
||||
PickupService pickupService = new PickupService(mock(Service.class));
|
||||
PickupService anotherService = new PickupService(mock(Service.class));
|
||||
PickupShipment pickupShipment = new PickupShipment(shipment);
|
||||
|
||||
stateManager.putInternalTypedActivityState(pickupService, StateFactory.LOAD, Capacity.Builder.newInstance().addDimension(0, 2).build());
|
||||
PickupService pickupService = (PickupService) vrp.getActivities(s1).get(0);
|
||||
PickupService anotherService = (PickupService) vrp.getActivities(s2).get(0);
|
||||
PickupShipment pickupShipment = (PickupShipment) vrp.getActivities(shipment).get(0);
|
||||
|
||||
stateManager.putInternalTypedActivityState(pickupService, StateFactory.LOAD, Capacity.Builder.newInstance().addDimension(0, 2).build());
|
||||
// when(stateManager.getActivityState(pickupService, StateFactory.LOAD)).thenReturn(StateFactory.createState(2.0));
|
||||
assertEquals(ConstraintsStatus.NOT_FULFILLED,constraint.fulfilled(iFacts, pickupService, pickupShipment, anotherService, 0.0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDeliveryActivityIsInsertedAndLoadIsNotSufficient_returnNOT_FullFilled_BREAK(){
|
||||
PickupService pickupService = new PickupService(mock(Service.class));
|
||||
PickupService anotherService = new PickupService(mock(Service.class));
|
||||
DeliverShipment pickupShipment = new DeliverShipment(shipment);
|
||||
|
||||
stateManager.putInternalTypedActivityState(pickupService, StateFactory.LOAD, Capacity.Builder.newInstance().addDimension(0, 2).build());
|
||||
assertEquals(ConstraintsStatus.NOT_FULFILLED_BREAK,constraint.fulfilled(iFacts, pickupService, pickupShipment, anotherService, 0.0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDeliveryActivityIsInsertedAndLoadIsSufficient_returnFullFilled(){
|
||||
PickupService pickupService = new PickupService(mock(Service.class));
|
||||
PickupService anotherService = new PickupService(mock(Service.class));
|
||||
DeliverShipment pickupShipment = new DeliverShipment(shipment);
|
||||
PickupService pickupService = (PickupService) vrp.getActivities(s1).get(0);
|
||||
PickupService anotherService = (PickupService) vrp.getActivities(s2).get(0);
|
||||
|
||||
DeliverShipment deliverShipment = (DeliverShipment) vrp.getActivities(shipment).get(1);
|
||||
|
||||
stateManager.putInternalTypedActivityState(pickupService, StateFactory.LOAD, Capacity.Builder.newInstance().addDimension(0, 1).build());
|
||||
// stateManager.putInternalActivityState(pickupService, StateFactory.LOAD, StateFactory.createState(1));
|
||||
assertEquals(ConstraintsStatus.FULFILLED,constraint.fulfilled(iFacts, pickupService, pickupShipment, anotherService, 0.0));
|
||||
assertEquals(ConstraintsStatus.FULFILLED,constraint.fulfilled(iFacts, pickupService, deliverShipment, anotherService, 0.0));
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -549,8 +549,8 @@ public class VehicleRoutingProblemTest {
|
|||
vrpBuilder.addJob(shipment);
|
||||
vrpBuilder.build();
|
||||
|
||||
assertEquals(0,service.getIndex());
|
||||
assertEquals(1,shipment.getIndex());
|
||||
assertEquals(1,service.getIndex());
|
||||
assertEquals(2,shipment.getIndex());
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -564,8 +564,8 @@ public class VehicleRoutingProblemTest {
|
|||
vrpBuilder.addVehicle(veh2);
|
||||
vrpBuilder.build();
|
||||
|
||||
assertEquals(0,veh1.getIndex());
|
||||
assertEquals(1,veh2.getIndex());
|
||||
assertEquals(1,veh1.getIndex());
|
||||
assertEquals(2,veh2.getIndex());
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -579,8 +579,8 @@ public class VehicleRoutingProblemTest {
|
|||
vrpBuilder.addVehicle(veh2);
|
||||
vrpBuilder.build();
|
||||
|
||||
assertEquals(0, veh1.getVehicleTypeIdentifier().getIndex());
|
||||
assertEquals(0, veh2.getVehicleTypeIdentifier().getIndex());
|
||||
assertEquals(1, veh1.getVehicleTypeIdentifier().getIndex());
|
||||
assertEquals(1, veh2.getVehicleTypeIdentifier().getIndex());
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -594,8 +594,8 @@ public class VehicleRoutingProblemTest {
|
|||
vrpBuilder.addVehicle(veh2);
|
||||
vrpBuilder.build();
|
||||
|
||||
assertEquals(0,veh1.getVehicleTypeIdentifier().getIndex());
|
||||
assertEquals(1,veh2.getVehicleTypeIdentifier().getIndex());
|
||||
assertEquals(1,veh1.getVehicleTypeIdentifier().getIndex());
|
||||
assertEquals(2,veh2.getVehicleTypeIdentifier().getIndex());
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,7 +32,9 @@ import jsprit.core.problem.solution.route.VehicleRoute;
|
|||
import jsprit.core.problem.solution.route.state.RouteAndActivityStateGetter;
|
||||
import jsprit.core.problem.solution.route.state.StateFactory;
|
||||
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 org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
@ -333,26 +335,18 @@ public class ServiceLoadRouteLevelConstraintTest {
|
|||
|
||||
@Test
|
||||
public void whenNewVehicleCapacityIsNotSufficiant1_returnFalse(){
|
||||
Pickup service = mock(Pickup.class);
|
||||
when(service.getSize()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build());
|
||||
|
||||
Service delivery = createDelivery("del1",3);
|
||||
VehicleRoute.Builder routeBuilder = VehicleRoute.Builder.newInstance(vehicle);
|
||||
routeBuilder.addService(delivery);
|
||||
VehicleRoute route = routeBuilder.build();
|
||||
|
||||
final Service pickup = createPickup("pick",2);
|
||||
final Service pickup2 = createPickup("pick2",3);
|
||||
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0,3).build();
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setType(type).setStartLocationId("loc").build();
|
||||
|
||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(vehicle).addJob(pickup).addJob(pickup2).build();
|
||||
|
||||
VehicleRoute route = VehicleRoute.Builder.newInstance(vehicle).setJobActivityFactory(vrp.getJobActivityFactory()).addService(pickup2).build();
|
||||
|
||||
stateManager.informInsertionStarts(Arrays.asList(route), null);
|
||||
|
||||
VehicleType type = mock(VehicleType.class);
|
||||
when(type.getCapacityDimensions()).thenReturn(Capacity.Builder.newInstance().addDimension(0, 2).build());
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.getType()).thenReturn(type);
|
||||
|
||||
JobInsertionContext iContext = mock(JobInsertionContext.class);
|
||||
when(iContext.getJob()).thenReturn(service);
|
||||
when(iContext.getRoute()).thenReturn(route);
|
||||
when(iContext.getNewVehicle()).thenReturn(vehicle);
|
||||
|
||||
JobInsertionContext iContext = new JobInsertionContext(route,pickup,vehicle,null,0.);
|
||||
assertFalse(new ServiceLoadRouteLevelConstraint(stateManager).fulfilled(iContext));
|
||||
}
|
||||
|
||||
|
|
|
|||
63
jsprit-core/src/test/resources/algorithm_without_construction.xml
Executable file
63
jsprit-core/src/test/resources/algorithm_without_construction.xml
Executable file
|
|
@ -0,0 +1,63 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright (C) 2013 Stefan Schroeder
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
Contributors:
|
||||
Stefan Schroeder - initial API and implementation
|
||||
-->
|
||||
<algorithm xmlns="http://www.w3schools.com"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com algorithm_schema.xsd">
|
||||
|
||||
<iterations>2000</iterations>
|
||||
|
||||
<strategy>
|
||||
<memory>1</memory>
|
||||
<searchStrategies>
|
||||
<searchStrategy name="randomRuinAndRecreate">
|
||||
<selector name="selectBest"/>
|
||||
<acceptor name="acceptNewRemoveWorst"/>
|
||||
<modules>
|
||||
<module name="ruin_and_recreate">
|
||||
<ruin name="randomRuin">
|
||||
<share>0.5</share>
|
||||
</ruin>
|
||||
<insertion name="bestInsertion"/>
|
||||
</module>
|
||||
|
||||
</modules>
|
||||
<probability>0.5</probability>
|
||||
</searchStrategy>
|
||||
|
||||
<searchStrategy name="radialRuinAndRecreate">
|
||||
<selector name="selectBest"/>
|
||||
<acceptor name="acceptNewRemoveWorst"/>
|
||||
<modules>
|
||||
<module name="ruin_and_recreate">
|
||||
<ruin name="radialRuin">
|
||||
<share>0.3</share>
|
||||
</ruin>
|
||||
<insertion name="bestInsertion"/>
|
||||
</module>
|
||||
|
||||
</modules>
|
||||
<probability>0.5</probability>
|
||||
</searchStrategy>
|
||||
</searchStrategies>
|
||||
</strategy>
|
||||
|
||||
|
||||
</algorithm>
|
||||
Loading…
Add table
Add a link
Reference in a new issue