diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/io/TestAlgorithmReader.java b/jsprit-core/src/test/java/jsprit/core/algorithm/io/TestAlgorithmReader.java
index b282e69b..262a01f4 100644
--- a/jsprit-core/src/test/java/jsprit/core/algorithm/io/TestAlgorithmReader.java
+++ b/jsprit-core/src/test/java/jsprit/core/algorithm/io/TestAlgorithmReader.java
@@ -16,12 +16,6 @@
******************************************************************************/
package jsprit.core.algorithm.io;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.util.ArrayList;
-import java.util.Collection;
-
import jsprit.core.algorithm.SearchStrategy;
import jsprit.core.algorithm.SearchStrategyModule;
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
@@ -42,11 +36,16 @@ import jsprit.core.problem.io.VrpXMLReader;
import jsprit.core.problem.job.Job;
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import jsprit.core.problem.solution.route.VehicleRoute;
-
import org.apache.commons.configuration.ConfigurationException;
import org.junit.Before;
import org.junit.Test;
+import java.util.ArrayList;
+import java.util.Collection;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
public class TestAlgorithmReader {
@@ -242,5 +241,19 @@ public class TestAlgorithmReader {
}
assertEquals(3, nOfModules);
}
+
+ @Test
+ public void readerTest_whenReadingAlgoWithSchemaValidation_itReadsCorrectly(){
+ AlgorithmConfig algoConfig = new AlgorithmConfig();
+ new AlgorithmConfigXmlReader(algoConfig).read("src/test/resources/algorithmConfig.xml");
+
+ }
+
+ @Test
+ public void readerTest_whenReadingAlgoWithSchemaValidationWithoutIterations_itReadsCorrectly(){
+ AlgorithmConfig algoConfig = new AlgorithmConfig();
+ new AlgorithmConfigXmlReader(algoConfig).read("src/test/resources/algorithmConfig_withoutIterations.xml");
+
+ }
}
diff --git a/jsprit-core/src/test/java/jsprit/core/problem/io/AlgorithmReaderTest.java b/jsprit-core/src/test/java/jsprit/core/problem/io/AlgorithmReaderTest.java
deleted file mode 100644
index 24beca4b..00000000
--- a/jsprit-core/src/test/java/jsprit/core/problem/io/AlgorithmReaderTest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2013 Stefan Schroeder
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3.0 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see .
- ******************************************************************************/
-package jsprit.core.problem.io;
-
-import jsprit.core.algorithm.io.AlgorithmConfig;
-import jsprit.core.algorithm.io.AlgorithmConfigXmlReader;
-
-import org.junit.Test;
-
-public class AlgorithmReaderTest {
-
- @Test
- public void readerTest_whenReadingAlgoWithSchemaValidation_itReadsCorrectly(){
- AlgorithmConfig algoConfig = new AlgorithmConfig();
- new AlgorithmConfigXmlReader(algoConfig).read("src/test/resources/algorithmConfig.xml");
-
- }
-
- @Test
- public void readerTest_whenReadingAlgoWithSchemaValidationWithoutIterations_itReadsCorrectly(){
- AlgorithmConfig algoConfig = new AlgorithmConfig();
- new AlgorithmConfigXmlReader(algoConfig).read("src/test/resources/algorithmConfig_withoutIterations.xml");
-
- }
-
-}
diff --git a/jsprit-core/src/test/java/jsprit/core/problem/io/ReaderTest.java b/jsprit-core/src/test/java/jsprit/core/problem/io/ReaderTest.java
deleted file mode 100644
index a9d1fb06..00000000
--- a/jsprit-core/src/test/java/jsprit/core/problem/io/ReaderTest.java
+++ /dev/null
@@ -1,63 +0,0 @@
-/*******************************************************************************
- * Copyright (C) 2013 Stefan Schroeder
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 3.0 of the License, or (at your option) any later version.
- *
- * This library 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
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library. If not, see .
- ******************************************************************************/
-package jsprit.core.problem.io;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import jsprit.core.problem.VehicleRoutingProblem;
-import jsprit.core.problem.VehicleRoutingProblem.Builder;
-import jsprit.core.problem.io.VrpXMLReader;
-import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
-import jsprit.core.problem.solution.route.activity.DeliverShipment;
-import jsprit.core.problem.solution.route.activity.PickupService;
-import jsprit.core.problem.solution.route.activity.PickupShipment;
-import jsprit.core.problem.solution.route.activity.TourActivity;
-
-import org.junit.Test;
-
-
-public class ReaderTest {
-
-
- @Test
- public void testRead_ifReaderIsCalled_itReadsSuccessfully(){
- new VrpXMLReader(VehicleRoutingProblem.Builder.newInstance(), new ArrayList()).read("src/test/resources/lui-shen-solution.xml");
- }
-
- @Test
- public void testRead_ifReaderIsCalled_itReadsSuccessfullyV2(){
- Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- ArrayList solutions = new ArrayList();
- new VrpXMLReader(vrpBuilder, solutions).read("src/test/resources/finiteVrpWithShipmentsAndSolution.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
- assertEquals(3,vrp.getJobs().size());
- assertEquals(1,solutions.size());
-
- assertEquals(1,solutions.get(0).getRoutes().size());
- List activities = solutions.get(0).getRoutes().iterator().next().getTourActivities().getActivities();
- assertEquals(4,activities.size());
- assertTrue(activities.get(0) instanceof PickupService);
- assertTrue(activities.get(1) instanceof PickupService);
- assertTrue(activities.get(2) instanceof PickupShipment);
- assertTrue(activities.get(3) instanceof DeliverShipment);
- }
-
-}
diff --git a/jsprit-core/src/test/java/jsprit/core/problem/io/VrpXMLReaderTest.java b/jsprit-core/src/test/java/jsprit/core/problem/io/VrpXMLReaderTest.java
index 67bd1266..30854aa9 100644
--- a/jsprit-core/src/test/java/jsprit/core/problem/io/VrpXMLReaderTest.java
+++ b/jsprit-core/src/test/java/jsprit/core/problem/io/VrpXMLReaderTest.java
@@ -21,7 +21,13 @@ import jsprit.core.problem.VehicleRoutingProblem.FleetSize;
import jsprit.core.problem.job.Job;
import jsprit.core.problem.job.Service;
import jsprit.core.problem.job.Shipment;
+import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
+import jsprit.core.problem.solution.route.activity.DeliverShipment;
+import jsprit.core.problem.solution.route.activity.PickupService;
+import jsprit.core.problem.solution.route.activity.PickupShipment;
+import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.problem.vehicle.Vehicle;
+import jsprit.core.util.Solutions;
import org.junit.Before;
import org.junit.Test;
@@ -570,5 +576,47 @@ public class VrpXMLReaderTest {
assertEquals(2,vrp.getInitialVehicleRoutes().iterator().next().getActivities().size());
}
+ @Test
+ public void testRead_ifReaderIsCalled_itReadsSuccessfullyV2(){
+ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
+ ArrayList solutions = new ArrayList();
+ new VrpXMLReader(vrpBuilder, solutions).read("src/test/resources/finiteVrpWithShipmentsAndSolution.xml");
+ VehicleRoutingProblem vrp = vrpBuilder.build();
+ assertEquals(4,vrp.getJobs().size());
+ assertEquals(1,solutions.size());
+ assertEquals(1,solutions.get(0).getRoutes().size());
+ List activities = solutions.get(0).getRoutes().iterator().next().getTourActivities().getActivities();
+ assertEquals(4,activities.size());
+ assertTrue(activities.get(0) instanceof PickupService);
+ assertTrue(activities.get(1) instanceof PickupService);
+ assertTrue(activities.get(2) instanceof PickupShipment);
+ assertTrue(activities.get(3) instanceof DeliverShipment);
+ }
+
+ @Test
+ public void testRead_ifReaderIsCalled_itReadsSuccessfully(){
+ new VrpXMLReader(VehicleRoutingProblem.Builder.newInstance(), new ArrayList()).read("src/test/resources/lui-shen-solution.xml");
+ assertTrue(true);
+ }
+
+
+ @Test
+ public void unassignedJobShouldBeRead(){
+ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
+ ArrayList solutions = new ArrayList();
+ new VrpXMLReader(vrpBuilder, solutions).read("src/test/resources/finiteVrpWithShipmentsAndSolution.xml");
+
+ VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
+ assertEquals(1,solution.getUnassignedJobs().size());
+ assertEquals("4",solution.getUnassignedJobs().iterator().next().getId());
+ }
+
+ @Test
+ public void solutionListShouldBeEmpty(){
+ VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
+ ArrayList solutions = new ArrayList();
+ new VrpXMLReader(vrpBuilder, solutions).read("src/test/resources/finiteVrpforReaderTest.xml");
+ assertTrue(solutions.isEmpty());
+ }
}
diff --git a/jsprit-core/src/test/java/jsprit/core/problem/io/VrpXMLWriterTest.java b/jsprit-core/src/test/java/jsprit/core/problem/io/VrpXMLWriterTest.java
index 7f8be992..e17a5ef1 100644
--- a/jsprit-core/src/test/java/jsprit/core/problem/io/VrpXMLWriterTest.java
+++ b/jsprit-core/src/test/java/jsprit/core/problem/io/VrpXMLWriterTest.java
@@ -21,15 +21,20 @@ import jsprit.core.problem.VehicleRoutingProblem.Builder;
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.TimeWindow;
import jsprit.core.problem.vehicle.Vehicle;
import jsprit.core.problem.vehicle.VehicleImpl;
import jsprit.core.problem.vehicle.VehicleTypeImpl;
import jsprit.core.util.Coordinate;
+import jsprit.core.util.Solutions;
import org.junit.Before;
import org.junit.Test;
+import java.util.ArrayList;
import java.util.Collection;
+import java.util.List;
import static org.junit.Assert.*;
@@ -865,4 +870,68 @@ public class VrpXMLWriterTest {
assertEquals(2,newVrp.getInitialVehicleRoutes().iterator().next().getActivities().size());
}
+ @Test
+ public void solutionWithoutUnassignedJobsShouldBeWrittenCorrectly(){
+ Builder builder = VehicleRoutingProblem.Builder.newInstance();
+
+ VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build();
+ VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("loc").setType(type1).build();
+ builder.addVehicle(v1);
+
+ Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocationId("loc").setServiceTime(2.0).build();
+ Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocationId("loc2").setServiceTime(4.0).build();
+
+ VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build();
+
+ VehicleRoute route = VehicleRoute.Builder.newInstance(v1).addService(s1).addService(s2).build();
+ List routes = new ArrayList();
+ routes.add(route);
+ VehicleRoutingProblemSolution solution = new VehicleRoutingProblemSolution(routes,10.);
+ List solutions = new ArrayList();
+ solutions.add(solution);
+
+ new VrpXMLWriter(vrp, solutions).write(infileName);
+
+ VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
+ List solutionsToRead = new ArrayList();
+ new VrpXMLReader(vrpToReadBuilder, solutionsToRead).read(infileName);
+
+ assertEquals(1, solutionsToRead.size());
+ assertEquals(10., Solutions.bestOf(solutionsToRead).getCost(),0.01);
+ assertTrue(Solutions.bestOf(solutionsToRead).getUnassignedJobs().isEmpty());
+ }
+
+ @Test
+ public void solutionWithUnassignedJobsShouldBeWrittenCorrectly(){
+ Builder builder = VehicleRoutingProblem.Builder.newInstance();
+
+ VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build();
+ VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("loc").setType(type1).build();
+ builder.addVehicle(v1);
+
+ Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocationId("loc").setServiceTime(2.0).build();
+ Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocationId("loc2").setServiceTime(4.0).build();
+
+ VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build();
+
+ VehicleRoute route = VehicleRoute.Builder.newInstance(v1).addService(s1).build();
+ List routes = new ArrayList();
+ routes.add(route);
+ VehicleRoutingProblemSolution solution = new VehicleRoutingProblemSolution(routes,10.);
+ solution.getUnassignedJobs().add(s2);
+ List solutions = new ArrayList();
+ solutions.add(solution);
+
+ new VrpXMLWriter(vrp, solutions).write(infileName);
+
+ VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance();
+ List solutionsToRead = new ArrayList();
+ new VrpXMLReader(vrpToReadBuilder, solutionsToRead).read(infileName);
+
+ assertEquals(1, solutionsToRead.size());
+ assertEquals(10., Solutions.bestOf(solutionsToRead).getCost(),0.01);
+ assertEquals(1, Solutions.bestOf(solutionsToRead).getUnassignedJobs().size());
+ assertEquals("2", Solutions.bestOf(solutionsToRead).getUnassignedJobs().iterator().next().getId());
+ }
+
}
diff --git a/jsprit-core/src/test/resources/finiteVrpWithShipmentsAndSolution.xml b/jsprit-core/src/test/resources/finiteVrpWithShipmentsAndSolution.xml
index 357b5356..1171c3b8 100644
--- a/jsprit-core/src/test/resources/finiteVrpWithShipmentsAndSolution.xml
+++ b/jsprit-core/src/test/resources/finiteVrpWithShipmentsAndSolution.xml
@@ -81,6 +81,19 @@
+
+
+ i(3,9)
+
+ 1
+ 0.0
+
+
+ 0.0
+ 4000.0
+
+
+
@@ -143,6 +156,9 @@
100.0
+
+
+
diff --git a/jsprit-core/src/test/resources/infiniteWriterV2Test.xml b/jsprit-core/src/test/resources/infiniteWriterV2Test.xml
index d5236fe7..a0d9b95f 100644
--- a/jsprit-core/src/test/resources/infiniteWriterV2Test.xml
+++ b/jsprit-core/src/test/resources/infiniteWriterV2Test.xml
@@ -6,15 +6,13 @@
- v
- type
+ v1
+ vehType
- startLoc
-
+ loc
- endLoc
-
+ loc
0.0
@@ -25,19 +23,9 @@
- type
+ vehType
- 100
- 1000
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 0
- 10000
+ 20
0.0
@@ -46,4 +34,53 @@
+
+
+ loc2
+
+ 1
+
+ 4.0
+
+
+ 0.0
+ 1.7976931348623157E308
+
+
+
+
+ loc
+
+ 1
+
+ 2.0
+
+
+ 0.0
+ 1.7976931348623157E308
+
+
+
+
+
+
+ 10.0
+
+
+ noDriver
+ v1
+ 0.0
+
+ 1
+ 0.0
+ 0.0
+
+ 0.0
+
+
+
+
+
+
+