From 81a7b34b0445bac281f142bcfeb1353affe8fb20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-David=20Be=CC=81langer?= Date: Wed, 30 Jul 2014 22:42:01 -0400 Subject: [PATCH 1/2] A very simple test case to reproduce a bug where one is not able to use the selectRandomly selector --- .../core/algorithm/SelectRandomlyTest.java | 24 +++++++++ .../algorithmConfig_selectRandomly.xml | 54 +++++++++++++++++++ 2 files changed, 78 insertions(+) create mode 100644 jsprit-core/src/test/java/jsprit/core/algorithm/SelectRandomlyTest.java create mode 100755 jsprit-core/src/test/resources/algorithmConfig_selectRandomly.xml diff --git a/jsprit-core/src/test/java/jsprit/core/algorithm/SelectRandomlyTest.java b/jsprit-core/src/test/java/jsprit/core/algorithm/SelectRandomlyTest.java new file mode 100644 index 00000000..38aa54ec --- /dev/null +++ b/jsprit-core/src/test/java/jsprit/core/algorithm/SelectRandomlyTest.java @@ -0,0 +1,24 @@ +package jsprit.core.algorithm; + +import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; +import jsprit.core.problem.VehicleRoutingProblem; +import jsprit.core.problem.io.VrpXMLReader; +import org.junit.Test; + +import static org.junit.Assert.fail; + +public class SelectRandomlyTest { + + @Test + public void loadAnAlgorithmWithSelectRandomly() { + VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); + new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml"); + VehicleRoutingProblem vrp = vrpBuilder.build(); + try { + VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig_selectRandomly.xml"); + } catch (Exception e) { + e.printStackTrace(); + fail("Should be able to load an algorithm that uses : " + e.getMessage()); + } + } +} diff --git a/jsprit-core/src/test/resources/algorithmConfig_selectRandomly.xml b/jsprit-core/src/test/resources/algorithmConfig_selectRandomly.xml new file mode 100755 index 00000000..72fb0349 --- /dev/null +++ b/jsprit-core/src/test/resources/algorithmConfig_selectRandomly.xml @@ -0,0 +1,54 @@ + + + + + 2000 + + + + + + + + 1 + + + + + + + + + 0.5 + + + + + 1 + + + + + + From e1d5f3165ab03967d072acdf656412968df36fc9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre-David=20Be=CC=81langer?= Date: Wed, 30 Jul 2014 22:48:34 -0400 Subject: [PATCH 2/2] Fix a bug where one gets an error message (solutionSelector is not know. Currently, it only knows "selectRandom" and "selectBest") when he uses selectRandomly as a selector. But selectRandom is not a valid enumeration in the selectorType restriction in the algorithm_schema.xsd. --- .../jsprit/core/algorithm/io/VehicleRoutingAlgorithms.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/jsprit-core/src/main/java/jsprit/core/algorithm/io/VehicleRoutingAlgorithms.java b/jsprit-core/src/main/java/jsprit/core/algorithm/io/VehicleRoutingAlgorithms.java index dd17c055..d234b2ea 100644 --- a/jsprit-core/src/main/java/jsprit/core/algorithm/io/VehicleRoutingAlgorithms.java +++ b/jsprit-core/src/main/java/jsprit/core/algorithm/io/VehicleRoutingAlgorithms.java @@ -746,7 +746,7 @@ public class VehicleRoutingAlgorithms { private static SolutionSelector getSelector(HierarchicalConfiguration strategyConfig, VehicleRoutingProblem vrp, Set algorithmListeners, TypedMap definedSelectors) { String selectorName = strategyConfig.getString("selector[@name]"); - if(selectorName == null) throw new IllegalStateException("no solutionSelector defined. define either \"selectRandom\" or \"selectBest\""); + if(selectorName == null) throw new IllegalStateException("no solutionSelector defined. define either \"selectRandomly\" or \"selectBest\""); String selectorId = strategyConfig.getString("selector[@id]"); if(selectorId == null) selectorId="noId"; ModKey modKey = makeKey(selectorName,selectorId); @@ -755,7 +755,7 @@ public class VehicleRoutingAlgorithms { if(definedSelector != null) { return definedSelector; } - if(selectorName.equals("selectRandom")){ + if(selectorName.equals("selectRandomly")){ SelectRandomly selector = SelectRandomly.getInstance(); definedSelectors.put(selectorKey, selector); return selector; @@ -765,7 +765,7 @@ public class VehicleRoutingAlgorithms { definedSelectors.put(selectorKey, selector); return selector; } - throw new IllegalStateException("solutionSelector is not know. Currently, it only knows \"selectRandom\" and \"selectBest\""); + throw new IllegalStateException("solutionSelector is not know. Currently, it only knows \"selectRandomly\" and \"selectBest\""); } private static ModKey makeKey(String name, String id){