1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

separate long running tests - fix #178

This commit is contained in:
oblonski 2015-09-17 16:04:56 +02:00
parent 01bf0d55af
commit 2ce279d5a5
23 changed files with 440 additions and 912 deletions

View file

@ -55,8 +55,37 @@
</plugin> </plugin>
</plugins> </plugins>
</pluginManagement> </pluginManagement>
<plugins>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<excludedGroups>jsprit.core.IntegrationTest</excludedGroups>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<includes>
<include>**/*.java</include>
</includes>
<groups>jsprit.core.IntegrationTest</groups>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build> </build>
<dependencies> <dependencies>
<dependency> <dependency>

View file

@ -0,0 +1,7 @@
package jsprit.core;
/**
* Created by schroeder on 17/09/15.
*/
public interface IntegrationTest {
}

View file

@ -16,6 +16,7 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm; package jsprit.core.algorithm;
import jsprit.core.IntegrationTest;
import jsprit.core.algorithm.acceptor.GreedyAcceptance; import jsprit.core.algorithm.acceptor.GreedyAcceptance;
import jsprit.core.algorithm.module.RuinAndRecreateModule; import jsprit.core.algorithm.module.RuinAndRecreateModule;
import jsprit.core.algorithm.recreate.BestInsertionBuilder; import jsprit.core.algorithm.recreate.BestInsertionBuilder;
@ -38,6 +39,7 @@ import jsprit.core.problem.vehicle.VehicleFleetManager;
import jsprit.core.util.Solutions; import jsprit.core.util.Solutions;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category;
import java.util.Collection; import java.util.Collection;
@ -95,6 +97,7 @@ public class BuildCVRPAlgoFromScratch_IT {
} }
@Test @Test
@Category(IntegrationTest.class)
public void testVRA() { public void testVRA() {
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions(); Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
System.out.println("costs=" + Solutions.bestOf(solutions).getCost() + ";#routes=" + Solutions.bestOf(solutions).getRoutes().size()); System.out.println("costs=" + Solutions.bestOf(solutions).getCost() + ";#routes=" + Solutions.bestOf(solutions).getRoutes().size());

View file

@ -16,6 +16,7 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm; package jsprit.core.algorithm;
import jsprit.core.IntegrationTest;
import jsprit.core.algorithm.acceptor.GreedyAcceptance; import jsprit.core.algorithm.acceptor.GreedyAcceptance;
import jsprit.core.algorithm.module.RuinAndRecreateModule; import jsprit.core.algorithm.module.RuinAndRecreateModule;
import jsprit.core.algorithm.recreate.BestInsertionBuilder; import jsprit.core.algorithm.recreate.BestInsertionBuilder;
@ -42,6 +43,7 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category;
import java.util.Collection; import java.util.Collection;
@ -104,6 +106,7 @@ public class BuildPDVRPAlgoFromScratch_IT {
} }
@Test @Test
@Category(IntegrationTest.class)
public void test() { public void test() {
try { try {
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions(); Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();

View file

@ -16,6 +16,7 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm; package jsprit.core.algorithm;
import jsprit.core.IntegrationTest;
import jsprit.core.algorithm.acceptor.GreedyAcceptance; import jsprit.core.algorithm.acceptor.GreedyAcceptance;
import jsprit.core.algorithm.module.RuinAndRecreateModule; import jsprit.core.algorithm.module.RuinAndRecreateModule;
import jsprit.core.algorithm.recreate.BestInsertionBuilder; import jsprit.core.algorithm.recreate.BestInsertionBuilder;
@ -37,6 +38,7 @@ import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.vehicle.InfiniteFleetManagerFactory; import jsprit.core.problem.vehicle.InfiniteFleetManagerFactory;
import jsprit.core.problem.vehicle.VehicleFleetManager; import jsprit.core.problem.vehicle.VehicleFleetManager;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category;
import java.util.Collection; import java.util.Collection;
@ -46,6 +48,7 @@ import static org.junit.Assert.assertTrue;
public class BuildPDVRPWithShipmentsAlgoFromScratch_IT { public class BuildPDVRPWithShipmentsAlgoFromScratch_IT {
@Test @Test
@Category(IntegrationTest.class)
public void test() { public void test() {
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(builder).read("src/test/resources/pdp.xml"); new VrpXMLReader(builder).read("src/test/resources/pdp.xml");

View file

@ -16,18 +16,21 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm; package jsprit.core.algorithm;
import jsprit.core.IntegrationTest;
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.io.VrpXMLReader; import jsprit.core.problem.io.VrpXMLReader;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import junit.framework.Assert; import junit.framework.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category;
import java.util.Collection; import java.util.Collection;
public class CVRPwithDeliveriesAndDifferentInsertionStrategies_IT { public class CVRPwithDeliveriesAndDifferentInsertionStrategies_IT {
@Test @Test
@Category(IntegrationTest.class)
public void whenWithTwoInsertionStrategiesWhereOnleOneIsInAlgo_itShouldWork() { public void whenWithTwoInsertionStrategiesWhereOnleOneIsInAlgo_itShouldWork() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml"); new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml");
@ -43,6 +46,7 @@ public class CVRPwithDeliveriesAndDifferentInsertionStrategies_IT {
} }
@Test @Test
@Category(IntegrationTest.class)
public void whenWithTwoInsertionStrategiesWhereBothAreInAlgo_itShouldWork() { public void whenWithTwoInsertionStrategiesWhereBothAreInAlgo_itShouldWork() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml"); new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml");

View file

@ -16,6 +16,7 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm; package jsprit.core.algorithm;
import jsprit.core.IntegrationTest;
import jsprit.core.algorithm.box.Jsprit; import jsprit.core.algorithm.box.Jsprit;
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem;
@ -23,6 +24,7 @@ import jsprit.core.problem.io.VrpXMLReader;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import jsprit.core.util.Solutions; import jsprit.core.util.Solutions;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category;
import java.util.Collection; import java.util.Collection;
@ -31,6 +33,7 @@ import static org.junit.Assert.assertEquals;
public class CVRPwithDeliveries_IT { public class CVRPwithDeliveries_IT {
@Test @Test
@Category(IntegrationTest.class)
public void whenSolvingVRPNC1withDeliveries_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution() { public void whenSolvingVRPNC1withDeliveries_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml"); new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml");
@ -42,6 +45,7 @@ public class CVRPwithDeliveries_IT {
} }
@Test @Test
@Category(IntegrationTest.class)
public void whenSolvingVRPNC1withDeliveriesWithJsprit_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution() { public void whenSolvingVRPNC1withDeliveriesWithJsprit_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml"); new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml");

View file

@ -16,6 +16,7 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm; package jsprit.core.algorithm;
import jsprit.core.IntegrationTest;
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
import jsprit.core.analysis.SolutionAnalyser; import jsprit.core.analysis.SolutionAnalyser;
import jsprit.core.problem.Location; import jsprit.core.problem.Location;
@ -31,6 +32,7 @@ import jsprit.core.util.EuclideanDistanceCalculator;
import jsprit.core.util.FastVehicleRoutingTransportCostsMatrix; import jsprit.core.util.FastVehicleRoutingTransportCostsMatrix;
import jsprit.core.util.Solutions; import jsprit.core.util.Solutions;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -44,6 +46,7 @@ public class CVRPwithMatrix_IT {
@Test @Test
@Category(IntegrationTest.class)
public void whenReturnToDepot_itShouldWorkWithMatrix() { public void whenReturnToDepot_itShouldWorkWithMatrix() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml"); new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml");
@ -56,6 +59,7 @@ public class CVRPwithMatrix_IT {
} }
@Test @Test
@Category(IntegrationTest.class)
public void whenNotReturnToDepot_itShouldWorkWithMatrix() { public void whenNotReturnToDepot_itShouldWorkWithMatrix() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml"); new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml");
@ -71,6 +75,7 @@ public class CVRPwithMatrix_IT {
} }
@Test @Test
@Category(IntegrationTest.class)
public void whenCalcTimeWithSolutionAnalyser_itShouldWork() { public void whenCalcTimeWithSolutionAnalyser_itShouldWork() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml"); new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml");

View file

@ -16,6 +16,7 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm; package jsprit.core.algorithm;
import jsprit.core.IntegrationTest;
import jsprit.core.algorithm.box.Jsprit; import jsprit.core.algorithm.box.Jsprit;
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem;
@ -23,6 +24,7 @@ import jsprit.core.problem.io.VrpXMLReader;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import jsprit.core.util.Solutions; import jsprit.core.util.Solutions;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category;
import java.util.Collection; import java.util.Collection;
@ -31,6 +33,7 @@ import static org.junit.Assert.assertEquals;
public class CVRPwithPickups_IT { public class CVRPwithPickups_IT {
@Test @Test
@Category(IntegrationTest.class)
public void whenSolvingVRPNC1WithPickups_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution() { public void whenSolvingVRPNC1WithPickups_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-pickups.xml"); new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-pickups.xml");
@ -42,6 +45,7 @@ public class CVRPwithPickups_IT {
} }
@Test @Test
@Category(IntegrationTest.class)
public void whenSolvingVRPNC1WithPickupsWithJsprit_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution() { public void whenSolvingVRPNC1WithPickupsWithJsprit_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-pickups.xml"); new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-pickups.xml");

View file

@ -18,6 +18,7 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm; package jsprit.core.algorithm;
import jsprit.core.IntegrationTest;
import jsprit.core.algorithm.box.Jsprit; import jsprit.core.algorithm.box.Jsprit;
import jsprit.core.algorithm.box.SchrimpfFactory; import jsprit.core.algorithm.box.SchrimpfFactory;
import jsprit.core.algorithm.recreate.NoSolutionFoundException; import jsprit.core.algorithm.recreate.NoSolutionFoundException;
@ -25,6 +26,7 @@ import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.io.VrpXMLReader; import jsprit.core.problem.io.VrpXMLReader;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
@ -35,6 +37,7 @@ import static org.junit.Assert.assertTrue;
public class FiniteVehicleFleetManagerIdentifiesDistinctVehicle_IT { public class FiniteVehicleFleetManagerIdentifiesDistinctVehicle_IT {
@Test @Test
@Category(IntegrationTest.class)
public void whenEmployingVehicleWhereOnlyOneDistinctVehicleCanServeAParticularJob_algorithmShouldFoundDistinctSolution() { public void whenEmployingVehicleWhereOnlyOneDistinctVehicleCanServeAParticularJob_algorithmShouldFoundDistinctSolution() {
final List<Boolean> testFailed = new ArrayList<Boolean>(); final List<Boolean> testFailed = new ArrayList<Boolean>();
for (int i = 0; i < 10; i++) { for (int i = 0; i < 10; i++) {

View file

@ -1,188 +0,0 @@
package jsprit.core.algorithm;
import jsprit.core.algorithm.box.Jsprit;
import jsprit.core.algorithm.box.SchrimpfFactory;
import jsprit.core.problem.AbstractJob;
import jsprit.core.problem.Location;
import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.VehicleRoutingProblem.FleetSize;
import jsprit.core.problem.job.Service;
import jsprit.core.problem.job.Shipment;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.problem.vehicle.Vehicle;
import jsprit.core.problem.vehicle.VehicleImpl;
import jsprit.core.problem.vehicle.VehicleImpl.Builder;
import jsprit.core.problem.vehicle.VehicleType;
import jsprit.core.problem.vehicle.VehicleTypeImpl;
import jsprit.core.util.Coordinate;
import jsprit.core.util.Solutions;
import org.junit.Test;
import java.util.Collection;
import java.util.Random;
import static org.junit.Assert.assertFalse;
public class PDTW_IT {
int nJobs = 200;
int nVehicles = 40;
Random random = new Random(1623);
int nextShipmentId = 1;
int nextVehicleId = 1;
@Test
public void whenDealingWithShipments_timeWindowsShouldNOTbeBroken() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
for (int i = 0; i < nVehicles; i++) {
vrpBuilder.addVehicle(createVehicle());
}
for (int i = 0; i < nJobs; i++) {
vrpBuilder.addJob(createShipment());
}
vrpBuilder.setFleetSize(FleetSize.FINITE);
VehicleRoutingProblem problem = vrpBuilder.build();
VehicleRoutingAlgorithm algorithm = new SchrimpfFactory().createAlgorithm(problem);
algorithm.setMaxIterations(0);
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions);
for (VehicleRoute route : bestSolution.getRoutes()) {
Vehicle v = route.getVehicle();
for (TourActivity ta : route.getActivities()) {
if (ta.getArrTime() > v.getLatestArrival() * 1.00001) {
assertFalse(true);
}
}
}
}
@Test
public void whenDealingWithServices_timeWindowsShouldNOTbeBroken() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
for (int i = 0; i < nVehicles; i++) {
vrpBuilder.addVehicle(createVehicle());
}
for (int i = 0; i < nJobs; i++) {
vrpBuilder.addJob(createService());
}
vrpBuilder.setFleetSize(FleetSize.FINITE);
VehicleRoutingProblem problem = vrpBuilder.build();
VehicleRoutingAlgorithm algorithm = new SchrimpfFactory().createAlgorithm(problem);
algorithm.setMaxIterations(100);
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions);
for (VehicleRoute route : bestSolution.getRoutes()) {
Vehicle v = route.getVehicle();
for (TourActivity ta : route.getActivities()) {
if (ta.getArrTime() * 1.000001 > v.getLatestArrival()) {
assertFalse(true);
}
}
}
}
@Test
public void whenDealingWithShipments_usingJsprit_timeWindowsShouldNOTbeBroken() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
for (int i = 0; i < nVehicles; i++) {
vrpBuilder.addVehicle(createVehicle());
}
for (int i = 0; i < nJobs; i++) {
vrpBuilder.addJob(createShipment());
}
vrpBuilder.setFleetSize(FleetSize.FINITE);
VehicleRoutingProblem problem = vrpBuilder.build();
VehicleRoutingAlgorithm algorithm = Jsprit.createAlgorithm(problem);
algorithm.setMaxIterations(0);
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions);
for (VehicleRoute route : bestSolution.getRoutes()) {
Vehicle v = route.getVehicle();
for (TourActivity ta : route.getActivities()) {
if (ta.getArrTime() > v.getLatestArrival() * 1.00001) {
assertFalse(true);
}
}
}
}
@Test
public void whenDealingWithServices_usingJsprit_timeWindowsShouldNOTbeBroken() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
for (int i = 0; i < nVehicles; i++) {
vrpBuilder.addVehicle(createVehicle());
}
for (int i = 0; i < nJobs; i++) {
vrpBuilder.addJob(createService());
}
vrpBuilder.setFleetSize(FleetSize.FINITE);
VehicleRoutingProblem problem = vrpBuilder.build();
VehicleRoutingAlgorithm algorithm = Jsprit.createAlgorithm(problem);
algorithm.setMaxIterations(100);
Collection<VehicleRoutingProblemSolution> solutions = algorithm.searchSolutions();
VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions);
for (VehicleRoute route : bestSolution.getRoutes()) {
Vehicle v = route.getVehicle();
for (TourActivity ta : route.getActivities()) {
if (ta.getArrTime() * 1.000001 > v.getLatestArrival()) {
assertFalse(true);
}
}
}
}
private AbstractJob createService() {
Service.Builder b = Service.Builder.newInstance(Integer.toString(nextShipmentId++));
b.addSizeDimension(0, 1);
b.setServiceTime(random.nextDouble() * 5);
b.setLocation(createLocation());
return b.build();
}
private Location createLocation() {
return loc(new Coordinate(50 * random.nextDouble(), 50 * random.nextDouble()));
}
private Shipment createShipment() {
Shipment.Builder b = Shipment.Builder.newInstance(Integer.toString(nextShipmentId++));
b.addSizeDimension(0, 1);
b.setPickupServiceTime(random.nextDouble() * 5);
b.setDeliveryServiceTime(random.nextDouble() * 5);
b.setDeliveryLocation(createLocation());
b.setPickupLocation(createLocation());
return b.build();
}
private VehicleImpl createVehicle() {
VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType" + nextVehicleId).addCapacityDimension(0, 2);
vehicleTypeBuilder.setCostPerDistance(1.0);
vehicleTypeBuilder.setCostPerTime(1);
vehicleTypeBuilder.setFixedCost(1000);
VehicleType vehicleType = vehicleTypeBuilder.build();
Builder v = VehicleImpl.Builder.newInstance("vehicle" + nextVehicleId);
Location l = createLocation();
v.setStartLocation(l);
v.setEndLocation(l);
v.setType(vehicleType);
v.setEarliestStart(50);
v.setLatestArrival(200);
nextVehicleId++;
return v.build();
}
private static Location loc(Coordinate coordinate) {
return Location.Builder.newInstance().setCoordinate(coordinate).build();
}
}

View file

@ -18,6 +18,7 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm; package jsprit.core.algorithm;
import jsprit.core.IntegrationTest;
import jsprit.core.algorithm.box.Jsprit; import jsprit.core.algorithm.box.Jsprit;
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem;
@ -25,6 +26,7 @@ import jsprit.core.problem.io.VrpXMLReader;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import jsprit.core.util.Solutions; import jsprit.core.util.Solutions;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category;
import java.util.Collection; import java.util.Collection;
@ -33,6 +35,7 @@ import static org.junit.Assert.assertEquals;
public class PickupsAndDeliveries_IT { public class PickupsAndDeliveries_IT {
@Test @Test
@Category(IntegrationTest.class)
public void whenSolvingLR101InstanceOfLiLim_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution() { public void whenSolvingLR101InstanceOfLiLim_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpBuilder).read("src/test/resources/lilim_lr101.xml"); new VrpXMLReader(vrpBuilder).read("src/test/resources/lilim_lr101.xml");
@ -44,6 +47,7 @@ public class PickupsAndDeliveries_IT {
} }
@Test @Test
@Category(IntegrationTest.class)
public void whenSolvingLR101InstanceOfLiLim_withJsprit_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution() { public void whenSolvingLR101InstanceOfLiLim_withJsprit_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpBuilder).read("src/test/resources/lilim_lr101.xml"); new VrpXMLReader(vrpBuilder).read("src/test/resources/lilim_lr101.xml");

View file

@ -16,6 +16,7 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm; package jsprit.core.algorithm;
import jsprit.core.IntegrationTest;
import jsprit.core.algorithm.box.GreedySchrimpfFactory; import jsprit.core.algorithm.box.GreedySchrimpfFactory;
import jsprit.core.algorithm.termination.IterationWithoutImprovementTermination; import jsprit.core.algorithm.termination.IterationWithoutImprovementTermination;
import jsprit.core.problem.Location; import jsprit.core.problem.Location;
@ -32,6 +33,7 @@ import jsprit.core.util.Solutions;
import jsprit.core.util.VehicleRoutingTransportCostsMatrix; import jsprit.core.util.VehicleRoutingTransportCostsMatrix;
import jsprit.core.util.VehicleRoutingTransportCostsMatrix.Builder; import jsprit.core.util.VehicleRoutingTransportCostsMatrix.Builder;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category;
import java.io.*; import java.io.*;
import java.util.Collection; import java.util.Collection;
@ -101,6 +103,7 @@ public class RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_IT {
} }
@Test @Test
@Category(IntegrationTest.class)
public void testAlgo() { public void testAlgo() {

View file

@ -16,6 +16,7 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm; package jsprit.core.algorithm;
import jsprit.core.IntegrationTest;
import jsprit.core.algorithm.box.GreedySchrimpfFactory; import jsprit.core.algorithm.box.GreedySchrimpfFactory;
import jsprit.core.algorithm.termination.IterationWithoutImprovementTermination; import jsprit.core.algorithm.termination.IterationWithoutImprovementTermination;
import jsprit.core.problem.Location; import jsprit.core.problem.Location;
@ -32,6 +33,7 @@ import jsprit.core.util.Solutions;
import jsprit.core.util.VehicleRoutingTransportCostsMatrix; import jsprit.core.util.VehicleRoutingTransportCostsMatrix;
import jsprit.core.util.VehicleRoutingTransportCostsMatrix.Builder; import jsprit.core.util.VehicleRoutingTransportCostsMatrix.Builder;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category;
import java.io.*; import java.io.*;
import java.util.Collection; import java.util.Collection;
@ -101,6 +103,7 @@ public class RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_withTimeAndD
} }
@Test @Test
@Category(IntegrationTest.class)
public void testAlgo() { public void testAlgo() {

View file

@ -16,6 +16,7 @@
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm; package jsprit.core.algorithm;
import jsprit.core.IntegrationTest;
import jsprit.core.algorithm.box.Jsprit; import jsprit.core.algorithm.box.Jsprit;
import jsprit.core.algorithm.box.SchrimpfFactory; import jsprit.core.algorithm.box.SchrimpfFactory;
import jsprit.core.algorithm.termination.IterationWithoutImprovementTermination; import jsprit.core.algorithm.termination.IterationWithoutImprovementTermination;
@ -34,6 +35,7 @@ import jsprit.core.util.Solutions;
import jsprit.core.util.VehicleRoutingTransportCostsMatrix; import jsprit.core.util.VehicleRoutingTransportCostsMatrix;
import jsprit.core.util.VehicleRoutingTransportCostsMatrix.Builder; import jsprit.core.util.VehicleRoutingTransportCostsMatrix.Builder;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category;
import java.io.*; import java.io.*;
import java.util.Collection; import java.util.Collection;
@ -45,6 +47,7 @@ public class RefuseCollection_IT {
@Test @Test
@Category(IntegrationTest.class)
public void whenReadingServices_itShouldCalculateCorrectly() { public void whenReadingServices_itShouldCalculateCorrectly() {
/* /*
@ -89,6 +92,7 @@ public class RefuseCollection_IT {
} }
@Test @Test
@Category(IntegrationTest.class)
public void whenReadingServices_usingJsprit_itShouldCalculateCorrectly() { public void whenReadingServices_usingJsprit_itShouldCalculateCorrectly() {
/* /*
@ -133,6 +137,7 @@ public class RefuseCollection_IT {
} }
@Test @Test
@Category(IntegrationTest.class)
public void whenReadingPickups_itShouldCalculateCorrectly() { public void whenReadingPickups_itShouldCalculateCorrectly() {
/* /*
@ -177,6 +182,7 @@ public class RefuseCollection_IT {
} }
@Test @Test
@Category(IntegrationTest.class)
public void whenReadingDeliveries_itShouldCalculateCorrectly() { public void whenReadingDeliveries_itShouldCalculateCorrectly() {
/* /*

View file

@ -15,11 +15,11 @@
* License along with this library. If not, see <http://www.gnu.org/licenses/>. * License along with this library. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/ ******************************************************************************/
package jsprit.core.algorithm.state; package jsprit.core.algorithm;
import jsprit.core.algorithm.VehicleRoutingAlgorithm; import jsprit.core.IntegrationTest;
import jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder;
import jsprit.core.algorithm.recreate.NoSolutionFoundException; import jsprit.core.algorithm.recreate.NoSolutionFoundException;
import jsprit.core.algorithm.state.StateManager;
import jsprit.core.problem.Skills; import jsprit.core.problem.Skills;
import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.constraint.ConstraintManager; import jsprit.core.problem.constraint.ConstraintManager;
@ -34,6 +34,7 @@ import jsprit.core.problem.vehicle.VehicleType;
import jsprit.core.util.Solutions; import jsprit.core.util.Solutions;
import jsprit.core.util.TestUtils; import jsprit.core.util.TestUtils;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category;
import java.util.Collection; import java.util.Collection;
@ -45,6 +46,7 @@ import static org.junit.Assert.*;
public class SolomonSkills_IT { public class SolomonSkills_IT {
@Test @Test
@Category(IntegrationTest.class)
public void itShouldMakeCorrectAssignmentAccordingToSkills() { public void itShouldMakeCorrectAssignmentAccordingToSkills() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpBuilder).read("src/test/resources/solomon_c101.xml"); new VrpXMLReader(vrpBuilder).read("src/test/resources/solomon_c101.xml");

View file

@ -1,12 +1,13 @@
package jsprit.core.algorithm.state; package jsprit.core.algorithm;
import jsprit.core.algorithm.VehicleRoutingAlgorithm; import jsprit.core.IntegrationTest;
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.io.VrpXMLReader; import jsprit.core.problem.io.VrpXMLReader;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import jsprit.core.util.Solutions; import jsprit.core.util.Solutions;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category;
import java.util.Collection; import java.util.Collection;
@ -18,6 +19,7 @@ import static org.junit.Assert.assertEquals;
public class Solomon_IT { public class Solomon_IT {
@Test @Test
@Category(IntegrationTest.class)
public void itShouldFindTheBestKnownSolution() { public void itShouldFindTheBestKnownSolution() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpBuilder).read("src/test/resources/solomon_c101.xml"); new VrpXMLReader(vrpBuilder).read("src/test/resources/solomon_c101.xml");

View file

@ -1,5 +1,6 @@
package jsprit.core.algorithm; package jsprit.core.algorithm;
import jsprit.core.IntegrationTest;
import jsprit.core.algorithm.box.Jsprit; import jsprit.core.algorithm.box.Jsprit;
import jsprit.core.algorithm.state.StateManager; import jsprit.core.algorithm.state.StateManager;
import jsprit.core.analysis.SolutionAnalyser; import jsprit.core.analysis.SolutionAnalyser;
@ -21,6 +22,7 @@ import jsprit.core.util.Solutions;
import junit.framework.Assert; import junit.framework.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category;
/** /**
* Created by schroeder on 22/07/15. * Created by schroeder on 22/07/15.
@ -72,6 +74,7 @@ public class VariableDepartureAndWaitingTime_IT {
} }
@Test @Test
@Category(IntegrationTest.class)
public void plainSetupShouldWork() { public void plainSetupShouldWork() {
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build();
Service s1 = Service.Builder.newInstance("s1").setLocation(Location.newInstance(10, 0)).build(); Service s1 = Service.Builder.newInstance("s1").setLocation(Location.newInstance(10, 0)).build();
@ -88,6 +91,7 @@ public class VariableDepartureAndWaitingTime_IT {
} }
@Test @Test
@Category(IntegrationTest.class)
public void withTimeWindowsShouldWork() { public void withTimeWindowsShouldWork() {
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build();
Service s1 = Service.Builder.newInstance("s1").setTimeWindow(TimeWindow.newInstance(1010, 1100)).setLocation(Location.newInstance(10, 0)).build(); Service s1 = Service.Builder.newInstance("s1").setTimeWindow(TimeWindow.newInstance(1010, 1100)).setLocation(Location.newInstance(10, 0)).build();

View file

@ -3,21 +3,16 @@ package jsprit.core.algorithm.box;
import jsprit.core.algorithm.SearchStrategy; import jsprit.core.algorithm.SearchStrategy;
import jsprit.core.algorithm.VehicleRoutingAlgorithm; import jsprit.core.algorithm.VehicleRoutingAlgorithm;
import jsprit.core.algorithm.listener.StrategySelectedListener; import jsprit.core.algorithm.listener.StrategySelectedListener;
import jsprit.core.algorithm.recreate.InsertionData;
import jsprit.core.algorithm.recreate.listener.BeforeJobInsertionListener;
import jsprit.core.algorithm.recreate.listener.JobInsertedListener; import jsprit.core.algorithm.recreate.listener.JobInsertedListener;
import jsprit.core.algorithm.ruin.listener.RuinListener; import jsprit.core.algorithm.ruin.listener.RuinListener;
import jsprit.core.algorithm.termination.VariationCoefficientTermination;
import jsprit.core.problem.Location; import jsprit.core.problem.Location;
import jsprit.core.problem.VehicleRoutingProblem; import jsprit.core.problem.VehicleRoutingProblem;
import jsprit.core.problem.io.VrpXMLReader;
import jsprit.core.problem.job.Job; import jsprit.core.problem.job.Job;
import jsprit.core.problem.job.Service; import jsprit.core.problem.job.Service;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import jsprit.core.problem.solution.route.VehicleRoute; import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.vehicle.VehicleImpl; import jsprit.core.problem.vehicle.VehicleImpl;
import jsprit.core.util.RandomNumberGeneration; import jsprit.core.util.RandomNumberGeneration;
import jsprit.core.util.Solutions;
import junit.framework.Assert; import junit.framework.Assert;
import org.junit.Test; import org.junit.Test;
@ -35,7 +30,7 @@ public class JspritTest {
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build();
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(s).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(s).build();
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
vra.setMaxIterations(10000); vra.setMaxIterations(10);
final Map<String, Integer> counts = new HashMap<String, Integer>(); final Map<String, Integer> counts = new HashMap<String, Integer>();
vra.addListener(new StrategySelectedListener() { vra.addListener(new StrategySelectedListener() {
@ -59,79 +54,6 @@ public class JspritTest {
} }
// @Test
// public void defaultStrategyProbabilitiesShouldWork_(){
// Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1,1)).build();
// Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(1,2)).build();
// VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0)).build();
// VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(s2).addJob(s).build();
// VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
// vra.setMaxIterations(5000);
// final Map<String,Integer> counts = new HashMap<String,Integer>();
// vra.addListener(new StrategySelectedListener() {
//
// @Override
// public void informSelectedStrategy(SearchStrategy.DiscoveredSolution discoveredSolution, VehicleRoutingProblem vehicleRoutingProblem, Collection<VehicleRoutingProblemSolution> vehicleRoutingProblemSolutions) {
// count(discoveredSolution.getStrategyId());
// }
//
// private void count(String strategyId) {
// if(!counts.containsKey(strategyId)) counts.put(strategyId,1);
// Integer integer = counts.get(strategyId);
// counts.put(strategyId, integer +1);
// }
//
// });
// vra.searchSolutions();
// Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.RADIAL_BEST.toString()));
// Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.WORST_BEST.toString()));
// Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.CLUSTER_BEST.toString()));
// Integer randomBestCounts = counts.get(Jsprit.Strategy.RANDOM_BEST.toString());
// Assert.assertEquals(5000.*0.5/3.5,(double) randomBestCounts,100);
// Assert.assertEquals(5000.*0.5/3.5,(double) counts.get(Jsprit.Strategy.RANDOM_REGRET.toString()),100);
// Assert.assertEquals(5000.*0.5/3.5,(double) counts.get(Jsprit.Strategy.RADIAL_REGRET.toString()),100);
// Assert.assertEquals(5000.*1./3.5,(double) counts.get(Jsprit.Strategy.WORST_REGRET.toString()),100);
// Assert.assertEquals(5000.*1./3.5,(double) counts.get(Jsprit.Strategy.CLUSTER_REGRET.toString()),100);
//
// }
//
// @Test
// public void whenChangingStratProb_itShouldBeReflected(){
// Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1,1)).build();
// Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(1,2)).build();
// VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0)).build();
// VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(s2).addJob(s).build();
// VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp)
// .setProperty(Jsprit.Strategy.RANDOM_BEST,"100.").buildAlgorithm();
// vra.setMaxIterations(5000);
// final Map<String,Integer> counts = new HashMap<String,Integer>();
// vra.addListener(new StrategySelectedListener() {
//
// @Override
// public void informSelectedStrategy(SearchStrategy.DiscoveredSolution discoveredSolution, VehicleRoutingProblem vehicleRoutingProblem, Collection<VehicleRoutingProblemSolution> vehicleRoutingProblemSolutions) {
// count(discoveredSolution.getStrategyId());
// }
//
// private void count(String strategyId) {
// if(!counts.containsKey(strategyId)) counts.put(strategyId,1);
// Integer integer = counts.get(strategyId);
// counts.put(strategyId, integer +1);
// }
//
// });
// vra.searchSolutions();
// Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.RADIAL_BEST.toString()));
// Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.WORST_BEST.toString()));
// Assert.assertTrue(!counts.containsKey(Jsprit.Strategy.CLUSTER_BEST.toString()));
// Integer randomBestCounts = counts.get(Jsprit.Strategy.RANDOM_BEST.toString());
// Assert.assertEquals(5000.*100./103.,(double) randomBestCounts,100);
// Assert.assertEquals(5000.*0.5/103.,(double) counts.get(Jsprit.Strategy.RANDOM_REGRET.toString()),100);
// Assert.assertEquals(5000.*0.5/103.,(double) counts.get(Jsprit.Strategy.RADIAL_REGRET.toString()),100);
// Assert.assertEquals(5000.*1./103.,(double) counts.get(Jsprit.Strategy.WORST_REGRET.toString()),100);
// Assert.assertEquals(5000.*1./103.,(double) counts.get(Jsprit.Strategy.CLUSTER_REGRET.toString()),100);
//
// }
@Test @Test
public void whenActivatingStrat_itShouldBeReflected() { public void whenActivatingStrat_itShouldBeReflected() {
Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1, 1)).build(); Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1, 1)).build();
@ -140,7 +62,7 @@ public class JspritTest {
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(s2).addJob(s).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(v).addJob(s2).addJob(s).build();
VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp) VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp)
.setProperty(Jsprit.Strategy.RADIAL_BEST, "100.").buildAlgorithm(); .setProperty(Jsprit.Strategy.RADIAL_BEST, "100.").buildAlgorithm();
vra.setMaxIterations(5000); vra.setMaxIterations(100);
final Map<String, Integer> counts = new HashMap<String, Integer>(); final Map<String, Integer> counts = new HashMap<String, Integer>();
vra.addListener(new StrategySelectedListener() { vra.addListener(new StrategySelectedListener() {
@ -161,7 +83,7 @@ public class JspritTest {
} }
@Test @Test
public void test_v3() { public void whenActivatingStrat_itShouldBeReflectedV2() {
Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1, 1)).build(); Service s = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1, 1)).build();
Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(1, 2)).build(); Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(1, 2)).build();
Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(1, 2)).build(); Service s3 = Service.Builder.newInstance("s3").setLocation(Location.newInstance(1, 2)).build();
@ -169,7 +91,7 @@ public class JspritTest {
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build();
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s3).addVehicle(v).addJob(s2).addJob(s).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s3).addVehicle(v).addJob(s2).addJob(s).build();
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
vra.setMaxIterations(5000); vra.setMaxIterations(100);
final Map<String, Integer> counts = new HashMap<String, Integer>(); final Map<String, Integer> counts = new HashMap<String, Integer>();
vra.addListener(new StrategySelectedListener() { vra.addListener(new StrategySelectedListener() {
@ -198,7 +120,7 @@ public class JspritTest {
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build();
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s4).addJob(s3).addVehicle(v).addJob(s2).addJob(s).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s4).addJob(s3).addVehicle(v).addJob(s2).addJob(s).build();
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
vra.setMaxIterations(5000); vra.setMaxIterations(100);
final Map<String, Integer> counts = new HashMap<String, Integer>(); final Map<String, Integer> counts = new HashMap<String, Integer>();
vra.addListener(new StrategySelectedListener() { vra.addListener(new StrategySelectedListener() {
@ -228,7 +150,7 @@ public class JspritTest {
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build();
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s4).addJob(s3).addVehicle(v).addJob(s2).addJob(s).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s4).addJob(s3).addVehicle(v).addJob(s2).addJob(s).build();
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
vra.setMaxIterations(1000); vra.setMaxIterations(100);
final List<String> firstRecord = new ArrayList<String>(); final List<String> firstRecord = new ArrayList<String>();
vra.addListener(new StrategySelectedListener() { vra.addListener(new StrategySelectedListener() {
@ -242,7 +164,7 @@ public class JspritTest {
RandomNumberGeneration.reset(); RandomNumberGeneration.reset();
VehicleRoutingAlgorithm second = Jsprit.createAlgorithm(vrp); VehicleRoutingAlgorithm second = Jsprit.createAlgorithm(vrp);
second.setMaxIterations(1000); second.setMaxIterations(100);
final List<String> secondRecord = new ArrayList<String>(); final List<String> secondRecord = new ArrayList<String>();
second.addListener(new StrategySelectedListener() { second.addListener(new StrategySelectedListener() {
@ -254,7 +176,7 @@ public class JspritTest {
}); });
second.searchSolutions(); second.searchSolutions();
for (int i = 0; i < 1000; i++) { for (int i = 0; i < 100; i++) {
if (!firstRecord.get(i).equals(secondRecord.get(i))) { if (!firstRecord.get(i).equals(secondRecord.get(i))) {
org.junit.Assert.assertFalse(true); org.junit.Assert.assertFalse(true);
} }
@ -273,7 +195,7 @@ public class JspritTest {
VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build(); VehicleImpl v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build();
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s4).addJob(s3).addVehicle(v).addJob(s2).addJob(s).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s4).addJob(s3).addVehicle(v).addJob(s2).addJob(s).build();
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
vra.setMaxIterations(1000); vra.setMaxIterations(100);
final List<String> firstRecord = new ArrayList<String>(); final List<String> firstRecord = new ArrayList<String>();
vra.addListener(new RuinListener() { vra.addListener(new RuinListener() {
@Override @Override
@ -294,63 +216,7 @@ public class JspritTest {
vra.searchSolutions(); vra.searchSolutions();
VehicleRoutingAlgorithm second = Jsprit.createAlgorithm(vrp); VehicleRoutingAlgorithm second = Jsprit.createAlgorithm(vrp);
second.setMaxIterations(1000); second.setMaxIterations(100);
final List<String> secondRecord = new ArrayList<String>();
second.addListener(new RuinListener() {
@Override
public void ruinStarts(Collection<VehicleRoute> routes) {
}
@Override
public void ruinEnds(Collection<VehicleRoute> routes, Collection<Job> unassignedJobs) {
}
@Override
public void removed(Job job, VehicleRoute fromRoute) {
secondRecord.add(job.getId());
}
});
second.searchSolutions();
Assert.assertEquals(secondRecord.size(), firstRecord.size());
for (int i = 0; i < firstRecord.size(); i++) {
if (!firstRecord.get(i).equals(secondRecord.get(i))) {
Assert.assertFalse(true);
}
}
Assert.assertTrue(true);
}
@Test
public void whenBiggerProblem_ruinedJobsShouldBeReproducible() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml");
VehicleRoutingProblem vrp = vrpBuilder.build();
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
vra.setMaxIterations(1000);
final List<String> firstRecord = new ArrayList<String>();
vra.addListener(new RuinListener() {
@Override
public void ruinStarts(Collection<VehicleRoute> routes) {
}
@Override
public void ruinEnds(Collection<VehicleRoute> routes, Collection<Job> unassignedJobs) {
}
@Override
public void removed(Job job, VehicleRoute fromRoute) {
firstRecord.add(job.getId());
}
});
vra.searchSolutions();
VehicleRoutingAlgorithm second = Jsprit.createAlgorithm(vrp);
second.setMaxIterations(1000);
final List<String> secondRecord = new ArrayList<String>(); final List<String> secondRecord = new ArrayList<String>();
second.addListener(new RuinListener() { second.addListener(new RuinListener() {
@Override @Override
@ -390,7 +256,7 @@ public class JspritTest {
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s4).addJob(s3).addVehicle(v).addJob(s2).addJob(s).build(); VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s4).addJob(s3).addVehicle(v).addJob(s2).addJob(s).build();
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
vra.setMaxIterations(1000); vra.setMaxIterations(100);
final List<String> firstRecord = new ArrayList<String>(); final List<String> firstRecord = new ArrayList<String>();
vra.addListener(new JobInsertedListener() { vra.addListener(new JobInsertedListener() {
@Override @Override
@ -401,7 +267,7 @@ public class JspritTest {
vra.searchSolutions(); vra.searchSolutions();
VehicleRoutingAlgorithm second = Jsprit.createAlgorithm(vrp); VehicleRoutingAlgorithm second = Jsprit.createAlgorithm(vrp);
second.setMaxIterations(1000); second.setMaxIterations(100);
final List<String> secondRecord = new ArrayList<String>(); final List<String> secondRecord = new ArrayList<String>();
second.addListener(new JobInsertedListener() { second.addListener(new JobInsertedListener() {
@Override @Override
@ -420,221 +286,5 @@ public class JspritTest {
Assert.assertTrue(true); Assert.assertTrue(true);
} }
@Test
public void whenBiggerProblem_insertionShouldBeReproducible() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml");
VehicleRoutingProblem vrp = vrpBuilder.build();
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
vra.setMaxIterations(200);
final List<String> firstRecord = new ArrayList<String>();
vra.addListener(new JobInsertedListener() {
@Override
public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) {
firstRecord.add(job2insert.getId());
}
});
vra.searchSolutions();
VehicleRoutingAlgorithm second = Jsprit.createAlgorithm(vrp);
second.setMaxIterations(200);
final List<String> secondRecord = new ArrayList<String>();
second.addListener(new JobInsertedListener() {
@Override
public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) {
secondRecord.add(job2insert.getId());
}
});
second.searchSolutions();
Assert.assertEquals(secondRecord.size(), firstRecord.size());
for (int i = 0; i < firstRecord.size(); i++) {
if (!firstRecord.get(i).equals(secondRecord.get(i))) {
Assert.assertFalse(true);
}
}
Assert.assertTrue(true);
}
@Test
public void whenBiggerProblem_insertionPositionsShouldBeReproducible() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml");
VehicleRoutingProblem vrp = vrpBuilder.build();
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
vra.setMaxIterations(200);
final List<Integer> firstRecord = new ArrayList<Integer>();
vra.addListener(new BeforeJobInsertionListener() {
@Override
public void informBeforeJobInsertion(Job job, InsertionData data, VehicleRoute route) {
firstRecord.add(data.getDeliveryInsertionIndex());
}
});
Collection<VehicleRoutingProblemSolution> firstSolutions = vra.searchSolutions();
VehicleRoutingAlgorithm second = Jsprit.createAlgorithm(vrp);
second.setMaxIterations(200);
final List<Integer> secondRecord = new ArrayList<Integer>();
second.addListener(new BeforeJobInsertionListener() {
@Override
public void informBeforeJobInsertion(Job job, InsertionData data, VehicleRoute route) {
secondRecord.add(data.getDeliveryInsertionIndex());
}
});
Collection<VehicleRoutingProblemSolution> secondSolutions = second.searchSolutions();
Assert.assertEquals(secondRecord.size(), firstRecord.size());
for (int i = 0; i < firstRecord.size(); i++) {
if (!firstRecord.get(i).equals(secondRecord.get(i))) {
Assert.assertFalse(true);
}
}
Assert.assertTrue(true);
Assert.assertEquals(Solutions.bestOf(firstSolutions).getCost(), Solutions.bestOf(secondSolutions).getCost());
}
@Test
public void whenTerminatingWithVariationCoefficient_terminationShouldBeReproducible() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml");
VehicleRoutingProblem vrp = vrpBuilder.build();
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
vra.setMaxIterations(1000);
VariationCoefficientTermination termination = new VariationCoefficientTermination(50, 0.005);
vra.setPrematureAlgorithmTermination(termination);
vra.addListener(termination);
final List<Integer> firstRecord = new ArrayList<Integer>();
vra.addListener(new BeforeJobInsertionListener() {
@Override
public void informBeforeJobInsertion(Job job, InsertionData data, VehicleRoute route) {
firstRecord.add(data.getDeliveryInsertionIndex());
}
});
Collection<VehicleRoutingProblemSolution> firstSolutions = vra.searchSolutions();
VehicleRoutingAlgorithm second = Jsprit.createAlgorithm(vrp);
VariationCoefficientTermination secondTermination = new VariationCoefficientTermination(50, 0.005);
second.setPrematureAlgorithmTermination(secondTermination);
second.addListener(secondTermination);
second.setMaxIterations(1000);
final List<Integer> secondRecord = new ArrayList<Integer>();
second.addListener(new BeforeJobInsertionListener() {
@Override
public void informBeforeJobInsertion(Job job, InsertionData data, VehicleRoute route) {
secondRecord.add(data.getDeliveryInsertionIndex());
}
});
Collection<VehicleRoutingProblemSolution> secondSolutions = second.searchSolutions();
Assert.assertEquals(secondRecord.size(), firstRecord.size());
for (int i = 0; i < firstRecord.size(); i++) {
if (!firstRecord.get(i).equals(secondRecord.get(i))) {
Assert.assertFalse(true);
}
}
Assert.assertTrue(true);
Assert.assertEquals(Solutions.bestOf(firstSolutions).getCost(), Solutions.bestOf(secondSolutions).getCost());
}
@Test
public void whenBiggerProblem_insertioPositionsShouldBeReproducibleWithoutResetingRNGExplicitly() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml");
VehicleRoutingProblem vrp = vrpBuilder.build();
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
vra.setMaxIterations(200);
final List<Integer> firstRecord = new ArrayList<Integer>();
vra.addListener(new BeforeJobInsertionListener() {
@Override
public void informBeforeJobInsertion(Job job, InsertionData data, VehicleRoute route) {
firstRecord.add(data.getDeliveryInsertionIndex());
}
});
Collection<VehicleRoutingProblemSolution> firstSolutions = vra.searchSolutions();
VehicleRoutingAlgorithm second = Jsprit.createAlgorithm(vrp);
second.setMaxIterations(200);
final List<Integer> secondRecord = new ArrayList<Integer>();
second.addListener(new BeforeJobInsertionListener() {
@Override
public void informBeforeJobInsertion(Job job, InsertionData data, VehicleRoute route) {
secondRecord.add(data.getDeliveryInsertionIndex());
}
});
Collection<VehicleRoutingProblemSolution> secondSolutions = second.searchSolutions();
Assert.assertEquals(secondRecord.size(), firstRecord.size());
for (int i = 0; i < firstRecord.size(); i++) {
if (!firstRecord.get(i).equals(secondRecord.get(i))) {
Assert.assertFalse(true);
}
}
Assert.assertTrue(true);
Assert.assertEquals(Solutions.bestOf(firstSolutions).getCost(), Solutions.bestOf(secondSolutions).getCost());
}
@Test
public void whenBiggerProblem_ruinedJobsShouldBeReproducibleWithoutResetingRNGExplicitly() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml");
VehicleRoutingProblem vrp = vrpBuilder.build();
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
vra.setMaxIterations(200);
final List<String> firstRecord = new ArrayList<String>();
vra.addListener(new RuinListener() {
@Override
public void ruinStarts(Collection<VehicleRoute> routes) {
}
@Override
public void ruinEnds(Collection<VehicleRoute> routes, Collection<Job> unassignedJobs) {
}
@Override
public void removed(Job job, VehicleRoute fromRoute) {
firstRecord.add(job.getId());
}
});
vra.searchSolutions();
VehicleRoutingAlgorithm second = Jsprit.createAlgorithm(vrp);
second.setMaxIterations(200);
final List<String> secondRecord = new ArrayList<String>();
second.addListener(new RuinListener() {
@Override
public void ruinStarts(Collection<VehicleRoute> routes) {
}
@Override
public void ruinEnds(Collection<VehicleRoute> routes, Collection<Job> unassignedJobs) {
}
@Override
public void removed(Job job, VehicleRoute fromRoute) {
secondRecord.add(job.getId());
}
});
second.searchSolutions();
Assert.assertEquals(secondRecord.size(), firstRecord.size());
for (int i = 0; i < firstRecord.size(); i++) {
if (!firstRecord.get(i).equals(secondRecord.get(i))) {
Assert.assertFalse(true);
}
}
Assert.assertTrue(true);
}
} }

View file

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<problem xmlns="http://www.w3schools.com" <problem xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd">
xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd">
<problemType> <problemType>
<fleetSize>FINITE</fleetSize> <fleetSize>FINITE</fleetSize>
</problemType> </problemType>

View file

@ -1,7 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<problem xmlns="http://www.w3schools.com" <problem xmlns="http://www.w3schools.com"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd">
xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd">
<problemType> <problemType>
<fleetSize>INFINITE</fleetSize> <fleetSize>INFINITE</fleetSize>
</problemType> </problemType>

View file

@ -43,6 +43,8 @@
</pluginManagement> </pluginManagement>
</build> </build>
<dependencies> <dependencies>
<dependency> <dependency>
<groupId>${project.groupId}</groupId> <groupId>${project.groupId}</groupId>

25
pom.xml
View file

@ -136,30 +136,7 @@
</plugins> </plugins>
</pluginManagement> </pluginManagement>
<plugins> <plugins>
<!-- <plugin> -->
<!-- <groupId>org.eclipse.m2e</groupId> -->
<!-- <artifactId>lifecycle-mapping</artifactId> -->
<!-- <version>1.0.0</version> -->
<!-- <configuration> -->
<!-- <lifecycleMappingMetadata> -->
<!-- <pluginExecutions> -->
<!-- <pluginExecution> -->
<!-- <pluginExecutionFilter> -->
<!-- <groupId>org.apache.maven.plugins</groupId> -->
<!-- <artifactId>maven-enforcer-plugin</artifactId> -->
<!-- <versionRange>[1.0.0,)</versionRange> -->
<!-- <goals> -->
<!-- <goal>enforce</goal> -->
<!-- </goals> -->
<!-- </pluginExecutionFilter> -->
<!-- <action> -->
<!-- <ignore /> -->
<!-- </action> -->
<!-- </pluginExecution> -->
<!-- </pluginExecutions> -->
<!-- </lifecycleMappingMetadata> -->
<!-- </configuration> -->
<!-- </plugin> -->
<plugin> <plugin>
<artifactId>maven-enforcer-plugin</artifactId> <artifactId>maven-enforcer-plugin</artifactId>
<version>1.1.1</version> <version>1.1.1</version>