diff --git a/jsprit-examples/src/main/java/jsprit/examples/CompareAlgorithmExample.java b/jsprit-examples/src/main/java/jsprit/examples/CompareAlgorithmExample.java deleted file mode 100644 index 09e8f2a8..00000000 --- a/jsprit-examples/src/main/java/jsprit/examples/CompareAlgorithmExample.java +++ /dev/null @@ -1,82 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2014 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.examples; - -import jsprit.analysis.toolbox.AlgorithmSearchProgressChartListener; -import jsprit.analysis.toolbox.StopWatch; -import jsprit.core.algorithm.VehicleRoutingAlgorithm; -import jsprit.core.algorithm.box.GreedySchrimpfFactory; -import jsprit.core.algorithm.box.SchrimpfFactory; -import jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners.Priority; -import jsprit.core.algorithm.termination.IterationWithoutImprovementTermination; -import jsprit.core.problem.VehicleRoutingProblem; -import jsprit.instance.reader.SolomonReader; -import jsprit.util.Examples; - - -public class CompareAlgorithmExample { - - - public static void main(String[] args) { - /* - * some preparation - create output folder - */ - Examples.createOutputFolder(); - /* - * Build the problem. - * - * But define a problem-builder first. - */ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - - /* - * A solomonReader reads solomon-instance files, and stores the required information in the builder. - */ - new SolomonReader(vrpBuilder).read("input/C101_solomon.txt"); - - /* - * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). - */ - VehicleRoutingProblem vrp = vrpBuilder.build(); - - /* - * Get schrimpf with threshold accepting - * Note that Priority.LOW is a way to priorize AlgorithmListeners - */ - VehicleRoutingAlgorithm vra_withThreshold = new SchrimpfFactory().createAlgorithm(vrp); - vra_withThreshold.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/schrimpfThreshold_progress.png"), Priority.LOW); - vra_withThreshold.getAlgorithmListeners().addListener(new StopWatch(), Priority.HIGH); - /* - * Get greedy schrimpf - */ - VehicleRoutingAlgorithm vra_greedy = new GreedySchrimpfFactory().createAlgorithm(vrp); - vra_greedy.getAlgorithmListeners().addListener(new AlgorithmSearchProgressChartListener("output/schrimpfGreedy_progress.png"), Priority.LOW); - vra_greedy.getAlgorithmListeners().addListener(new StopWatch(), Priority.HIGH); - - /* - * run both - */ - vra_withThreshold.searchSolutions(); - - vra_greedy.searchSolutions(); - vra_greedy.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(40)); - vra_greedy.searchSolutions(); - - - } - -} diff --git a/jsprit-examples/src/main/java/jsprit/examples/ComputationalExperiments_alphaSenstivity.java b/jsprit-examples/src/main/java/jsprit/examples/ComputationalExperiments_alphaSenstivity.java deleted file mode 100644 index 1c921542..00000000 --- a/jsprit-examples/src/main/java/jsprit/examples/ComputationalExperiments_alphaSenstivity.java +++ /dev/null @@ -1,201 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2014 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.examples; - -import jsprit.analysis.toolbox.ComputationalLaboratory; -import jsprit.analysis.toolbox.ComputationalLaboratory.CalculationListener; -import jsprit.analysis.toolbox.ComputationalLaboratory.DataCollector; -import jsprit.analysis.toolbox.Plotter; -import jsprit.analysis.toolbox.XYLineChartBuilder; -import jsprit.core.algorithm.VehicleRoutingAlgorithm; -import jsprit.core.algorithm.VehicleRoutingAlgorithmFactory; -import jsprit.core.algorithm.io.AlgorithmConfig; -import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; -import jsprit.core.algorithm.listener.IterationStartsListener; -import jsprit.core.problem.VehicleRoutingProblem; -import jsprit.core.problem.solution.VehicleRoutingProblemSolution; -import jsprit.core.reporting.SolutionPrinter; -import jsprit.core.reporting.SolutionPrinter.Print; -import jsprit.core.util.BenchmarkInstance; -import jsprit.core.util.Solutions; -import jsprit.instance.reader.SolomonReader; -import jsprit.util.Examples; -import org.apache.commons.configuration.XMLConfiguration; - -import java.util.Collection; - -/** - * Based on Solomon's R101 instance - * - * @author schroeder - * - */ -public class ComputationalExperiments_alphaSenstivity { - - - public static void main(String[] args) { - /* - * some preparation - create output folder - */ - Examples.createOutputFolder(); - - /* - * Build the problem. - * - * But define a problem-builder first. - */ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - - /* - * A solomonReader reads solomon-instance files, and stores the required information in the builder. - */ - new SolomonReader(vrpBuilder,100).read("input/R101.txt"); - - /* - * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). - */ - VehicleRoutingProblem vrp = vrpBuilder.build(); - - /* - * Create ComputationalLaboratory - */ - ComputationalLaboratory computationalLab = new ComputationalLaboratory(); - /* - * add benchmarking instance - */ - computationalLab.addInstance("SolomonR101", vrp); - /* - * add algorithms through factories - * - * - * - */ - for(double alphaVal=0.;alphaVal<.4;alphaVal+=.1){ - - final String alpha = String.valueOf(alphaVal).substring(0, 3); - computationalLab.addAlgorithmFactory("alpha_"+alpha, new VehicleRoutingAlgorithmFactory() { - - @Override - public VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vrp) { - return VehicleRoutingAlgorithms.createAlgorithm(vrp, getAlgorithmConfig(alpha)); - } - - }); - - } - - /* - * plot search progress of different algorithms - */ - final XYLineChartBuilder chartBuilder = XYLineChartBuilder.newInstance("alpha-sensitivity", "iterations", "costs"); - computationalLab.addListener(new CalculationListener() { - - @Override - public void calculationStarts(BenchmarkInstance p, final String algorithmName,VehicleRoutingAlgorithm algorithm, int run) { - algorithm.addListener(new IterationStartsListener() { - - @Override - public void informIterationStarts(int i, VehicleRoutingProblem problem,Collection solutions) { - /* - * plot only distance-costs, i.e. without fixed costs - */ - VehicleRoutingProblemSolution bestOf = Solutions.bestOf(solutions); - chartBuilder.addData(algorithmName, i, bestOf.getCost()-bestOf.getRoutes().size()*100.); - } - - }); - - } - - @Override - public void calculationEnds(BenchmarkInstance p, String algorithmName,VehicleRoutingAlgorithm algorithm, int run,Collection solutions) {} - - }); - /* - * define dataCollector to collect an arbitrary number of indicators as well as solutions - */ - final DataCollector dataCollector = new DataCollector(); - computationalLab.addListener(new CalculationListener() { - - @Override - public void calculationStarts(BenchmarkInstance p, String algorithmName,VehicleRoutingAlgorithm algorithm, int run) {} - - @Override - public void calculationEnds(BenchmarkInstance p, String algorithmName,VehicleRoutingAlgorithm algorithm, int run,Collection solutions) { - //memorize solution - dataCollector.addSolution(p.name, algorithmName, run, Solutions.bestOf(solutions)); - } - - }); - /* - * determine number of threads to be used - */ - computationalLab.setThreads(2); - /* - * run the experiments - */ - computationalLab.run(); - - /* - * plot the lineChart - */ - XYLineChartBuilder.saveChartAsPNG(chartBuilder.build(), "output/computationalStudies_alphaSensitivity.png"); - - /* - * print best solution - */ - SolutionPrinter.print(vrp, Solutions.bestOf(dataCollector.getSolutions()), Print.VERBOSE); - - /* - * plot best - */ - Plotter plotter = new Plotter(vrp,Solutions.bestOf(dataCollector.getSolutions())); - plotter.plot("output/bestOf.png", "bestOfR101"); - - } - - private static AlgorithmConfig getAlgorithmConfig(String alpha) { - AlgorithmConfig config = new AlgorithmConfig(); - XMLConfiguration xmlConfig = config.getXMLConfiguration(); - xmlConfig.setProperty("iterations",10000); - xmlConfig.setProperty("construction.insertion[@name]","bestInsertion"); - - xmlConfig.setProperty("strategy.memory", 1); - String searchStrategy = "strategy.searchStrategies.searchStrategy"; - - xmlConfig.setProperty(searchStrategy + "(0).selector[@name]","selectBest"); - xmlConfig.setProperty(searchStrategy + "(0).acceptor[@name]","schrimpfAcceptance"); - xmlConfig.setProperty(searchStrategy + "(0).acceptor.alpha",alpha); - xmlConfig.setProperty(searchStrategy + "(0).acceptor.warmup","50"); - xmlConfig.setProperty(searchStrategy + "(0).modules.module(0)[@name]","ruin_and_recreate"); - xmlConfig.setProperty(searchStrategy + "(0).modules.module(0).ruin[@name]","randomRuin"); - xmlConfig.setProperty(searchStrategy + "(0).modules.module(0).ruin.share","0.3"); - xmlConfig.setProperty(searchStrategy + "(0).modules.module(0).insertion[@name]","bestInsertion"); - xmlConfig.setProperty(searchStrategy + "(0).probability",".5"); - - xmlConfig.setProperty(searchStrategy + "(1).selector[@name]","selectBest"); - xmlConfig.setProperty(searchStrategy + "(1).acceptor[@name]","schrimpfAcceptance"); - xmlConfig.setProperty(searchStrategy + "(1).modules.module(0)[@name]","ruin_and_recreate"); - xmlConfig.setProperty(searchStrategy + "(1).modules.module(0).ruin[@name]","radialRuin"); - xmlConfig.setProperty(searchStrategy + "(1).modules.module(0).ruin.share","0.1"); - xmlConfig.setProperty(searchStrategy + "(1).modules.module(0).insertion[@name]","bestInsertion"); - xmlConfig.setProperty(searchStrategy + "(1).probability","0.5"); - - return config; - } - -} diff --git a/jsprit-examples/src/main/java/jsprit/examples/ComputationalExperiments_randomVariations.java b/jsprit-examples/src/main/java/jsprit/examples/ComputationalExperiments_randomVariations.java deleted file mode 100644 index 01a5b5a0..00000000 --- a/jsprit-examples/src/main/java/jsprit/examples/ComputationalExperiments_randomVariations.java +++ /dev/null @@ -1,136 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2014 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.examples; - -import jsprit.analysis.toolbox.ComputationalLaboratory; -import jsprit.analysis.toolbox.ComputationalLaboratory.CalculationListener; -import jsprit.analysis.toolbox.XYLineChartBuilder; -import jsprit.core.algorithm.VehicleRoutingAlgorithm; -import jsprit.core.algorithm.VehicleRoutingAlgorithmFactory; -import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; -import jsprit.core.algorithm.listener.IterationStartsListener; -import jsprit.core.problem.VehicleRoutingProblem; -import jsprit.core.problem.solution.VehicleRoutingProblemSolution; -import jsprit.core.util.BenchmarkInstance; -import jsprit.core.util.Solutions; -import jsprit.instance.reader.SolomonReader; -import jsprit.util.Examples; - -import java.util.Collection; - -/** - * Based on Solomon's R101 instance - * - * @author schroeder - * - */ -public class ComputationalExperiments_randomVariations { - - - public static void main(String[] args) { - /* - * some preparation - create output folder - */ - Examples.createOutputFolder(); - - /* - * Build the problem. - * - * But define a problem-builder first. - */ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - - /* - * A solomonReader reads solomon-instance files, and stores the required information in the builder. - */ - new SolomonReader(vrpBuilder).read("input/R101.txt"); - - /* - * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). - */ - VehicleRoutingProblem vrp = vrpBuilder.build(); - - /* - * Create ComputationalLaboratory - */ - ComputationalLaboratory computationalLab = new ComputationalLaboratory(); - /* - * add benchmarking instance - */ - computationalLab.addInstance("SolomonR101", vrp); - /* - * add algorithms through factories - * - * - * - */ - computationalLab.addAlgorithmFactory("schrimpfAcceptance", new VehicleRoutingAlgorithmFactory() { - - @Override - public VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vrp) { - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfigWithSchrimpfAcceptance.xml"); - vra.setMaxIterations(4000); - return vra; - } - }); - /* - * run schrimpfAcceptance 5 times (and thus each with another seed of random number generator) - */ - computationalLab.setNuOfRuns(5); - - /* - * plot search progress of different algorithms - */ - final XYLineChartBuilder chartBuilder = XYLineChartBuilder.newInstance("random variations", "iterations", "costs"); - computationalLab.addListener(new CalculationListener() { - - @Override - public void calculationStarts(BenchmarkInstance p, final String algorithmName,VehicleRoutingAlgorithm algorithm, final int run) { - algorithm.addListener(new IterationStartsListener() { - - @Override - public void informIterationStarts(int i, VehicleRoutingProblem problem,Collection solutions) { - /* - * since there will be more than 1 run and we want to plot each run, we need to specify an apropriate - * XYSeries-name. Thus we add run to algorithmName. - */ - chartBuilder.addData(algorithmName+"_"+run, i, Solutions.bestOf(solutions).getCost()); - } - - }); - - } - - @Override - public void calculationEnds(BenchmarkInstance p, String algorithmName,VehicleRoutingAlgorithm algorithm, int run,Collection solutions) {} - - }); - - computationalLab.setThreads(2); - /* - * run the experiments - */ - computationalLab.run(); - - /* - * plot the lineChart - */ - XYLineChartBuilder.saveChartAsPNG(chartBuilder.build(), "output/computationalStudies_randomVariations.png"); - - } - -} diff --git a/jsprit-examples/src/main/java/jsprit/examples/ComputationalExperiments_randomVariations_and_nuOfIterations.java b/jsprit-examples/src/main/java/jsprit/examples/ComputationalExperiments_randomVariations_and_nuOfIterations.java deleted file mode 100644 index c1b7f1e4..00000000 --- a/jsprit-examples/src/main/java/jsprit/examples/ComputationalExperiments_randomVariations_and_nuOfIterations.java +++ /dev/null @@ -1,173 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2014 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.examples; - -import jsprit.analysis.toolbox.ComputationalLaboratory; -import jsprit.analysis.toolbox.ComputationalLaboratory.CalculationListener; -import jsprit.analysis.toolbox.ComputationalLaboratory.DataCollector; -import jsprit.analysis.toolbox.XYLineChartBuilder; -import jsprit.core.algorithm.VehicleRoutingAlgorithm; -import jsprit.core.algorithm.VehicleRoutingAlgorithmFactory; -import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; -import jsprit.core.problem.VehicleRoutingProblem; -import jsprit.core.problem.solution.VehicleRoutingProblemSolution; -import jsprit.core.util.BenchmarkInstance; -import jsprit.core.util.Solutions; -import jsprit.instance.reader.SolomonReader; -import jsprit.util.Examples; - -import java.util.Collection; - -/** - * Based on Solomon's R101 instance - * - * @author schroeder - * - */ -public class ComputationalExperiments_randomVariations_and_nuOfIterations { - - - public static void main(String[] args) { - /* - * some preparation - create output folder - */ - Examples.createOutputFolder(); - - /* - * Build the problem. - * - * But define a problem-builder first. - */ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - - /* - * A solomonReader reads solomon-instance files, and stores the required information in the builder. - */ - new SolomonReader(vrpBuilder).read("input/R101.txt"); - - /* - * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). - */ - VehicleRoutingProblem vrp = vrpBuilder.build(); - - /* - * Create ComputationalLaboratory - */ - ComputationalLaboratory computationalLab = new ComputationalLaboratory(); - /* - * add benchmarking instance - */ - computationalLab.addInstance("SolomonR101", vrp); - /* - * add algorithms through factories - * - * - * - */ - computationalLab.addAlgorithmFactory("schrimpfAcceptance_1", getAlgorithmFactory(1)); - computationalLab.addAlgorithmFactory("schrimpfAcceptance_100", getAlgorithmFactory(100)); - computationalLab.addAlgorithmFactory("schrimpfAcceptance_500", getAlgorithmFactory(500)); - computationalLab.addAlgorithmFactory("schrimpfAcceptance_1000", getAlgorithmFactory(1000)); - computationalLab.addAlgorithmFactory("schrimpfAcceptance_2000", getAlgorithmFactory(2000)); - computationalLab.addAlgorithmFactory("schrimpfAcceptance_4000", getAlgorithmFactory(4000)); - computationalLab.addAlgorithmFactory("schrimpfAcceptance_8000", getAlgorithmFactory(8000)); - computationalLab.addAlgorithmFactory("schrimpfAcceptance_12000", getAlgorithmFactory(12000)); - - - /* - * run schrimpfAcceptance 5 times (and thus each with another seed of random number generator) - */ - computationalLab.setNuOfRuns(5); - - /* - * plot search progress of different algorithms - */ - final DataCollector dataCollector = new DataCollector(); - computationalLab.addListener(new CalculationListener() { - - @Override - public void calculationStarts(BenchmarkInstance p, final String algorithmName,VehicleRoutingAlgorithm algorithm, final int run) {} - - @Override - public void calculationEnds(BenchmarkInstance p, String algorithmName,VehicleRoutingAlgorithm algorithm, int run,Collection solutions) { - dataCollector.addDate("R101", algorithmName, run, "costs", Solutions.bestOf(solutions).getCost()); - } - - }); - - computationalLab.setThreads(2); - /* - * run the experiments - */ - computationalLab.run(); - - /* - * plot min, avg and max - */ - XYLineChartBuilder chartBuilder = XYLineChartBuilder.newInstance("variations with iterations", "iterations", "costs"); - for(String algorithmName : computationalLab.getAlgorithmNames()){ - String[] nameTokens = algorithmName.split("_"); - int iteration = Integer.parseInt(nameTokens[1]); - chartBuilder.addData("min", iteration, min(dataCollector.getData("R101", algorithmName, "costs"))); - chartBuilder.addData("max", iteration, max(dataCollector.getData("R101", algorithmName, "costs"))); - chartBuilder.addData("avg", iteration, avg(dataCollector.getData("R101", algorithmName, "costs"))); - } - - XYLineChartBuilder.saveChartAsPNG(chartBuilder.build(), "output/computationalStudies_min_max_avg.png"); - - - } - - public static double min(Collection doubles){ - double min = Double.MAX_VALUE; - for(Double d : doubles){ - if(d doubles){ - double max = 0.; - for(Double d : doubles){ - if(d>max) max=d; - } - return max; - } - - public static double avg(Collection doubles){ - if(doubles.isEmpty()) return 0.; - double sum = 0.; - for(Double d : doubles){ - sum+=d; - } - return sum/(double)doubles.size(); - } - - - private static VehicleRoutingAlgorithmFactory getAlgorithmFactory(final int iterations) { - return new VehicleRoutingAlgorithmFactory() { - - @Override - public VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vrp) { - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfigWithSchrimpfAcceptance.xml"); - vra.setMaxIterations(iterations); - return vra; - } - }; - } - -} diff --git a/jsprit-examples/src/main/java/jsprit/examples/ComputationalExperiments_schrimpf_vs_greedy.java b/jsprit-examples/src/main/java/jsprit/examples/ComputationalExperiments_schrimpf_vs_greedy.java deleted file mode 100644 index b506048a..00000000 --- a/jsprit-examples/src/main/java/jsprit/examples/ComputationalExperiments_schrimpf_vs_greedy.java +++ /dev/null @@ -1,140 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2014 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.examples; - -import jsprit.analysis.toolbox.ComputationalLaboratory; -import jsprit.analysis.toolbox.ComputationalLaboratory.CalculationListener; -import jsprit.analysis.toolbox.XYLineChartBuilder; -import jsprit.core.algorithm.VehicleRoutingAlgorithm; -import jsprit.core.algorithm.VehicleRoutingAlgorithmFactory; -import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; -import jsprit.core.algorithm.listener.IterationStartsListener; -import jsprit.core.problem.VehicleRoutingProblem; -import jsprit.core.problem.solution.VehicleRoutingProblemSolution; -import jsprit.core.util.BenchmarkInstance; -import jsprit.core.util.Solutions; -import jsprit.instance.reader.SolomonReader; -import jsprit.util.Examples; - -import java.util.Collection; - -/** - * Based on Solomon's R101 instance - * - * @author schroeder - * - */ -public class ComputationalExperiments_schrimpf_vs_greedy { - - - public static void main(String[] args) { - /* - * some preparation - create output folder - */ - Examples.createOutputFolder(); - - /* - * Build the problem. - * - * But define a problem-builder first. - */ - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - - /* - * A solomonReader reads solomon-instance files, and stores the required information in the builder. - */ - new SolomonReader(vrpBuilder).read("input/R101.txt"); - - /* - * Finally, the problem can be built. By default, transportCosts are crowFlyDistances (as usually used for vrp-instances). - */ - VehicleRoutingProblem vrp = vrpBuilder.build(); - - /* - * Create ComputationalLaboratory - */ - ComputationalLaboratory computationalLab = new ComputationalLaboratory(); - /* - * add benchmarking instance - */ - computationalLab.addInstance("SolomonR101", vrp); - /* - * add algorithms through factories - * - * - * Define 2 algorithms - * - algorithmsConfigWithSchrimpfAcceptance (4000 iterations) - * - algorithmsConfigWithGreedyAcceptance (4000 iterations) - * - */ - computationalLab.addAlgorithmFactory("schrimpfAcceptance", new VehicleRoutingAlgorithmFactory() { - - @Override - public VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vrp) { - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfigWithSchrimpfAcceptance.xml"); - vra.setMaxIterations(4000); - return vra; - } - }); - computationalLab.addAlgorithmFactory("greedyAcceptance", new VehicleRoutingAlgorithmFactory() { - - @Override - public VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vrp) { - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_solomon.xml"); - vra.setMaxIterations(4000); - return vra; - } - }); - - /* - * plot search progress of different algorithms - */ - final XYLineChartBuilder chartBuilder = XYLineChartBuilder.newInstance("schrimpf vs greedy", "iterations", "costs"); - computationalLab.addListener(new CalculationListener() { - - @Override - public void calculationStarts(BenchmarkInstance p, final String algorithmName,VehicleRoutingAlgorithm algorithm, int run) { - algorithm.addListener(new IterationStartsListener() { - - @Override - public void informIterationStarts(int i, VehicleRoutingProblem problem,Collection solutions) { - chartBuilder.addData(algorithmName, i, Solutions.bestOf(solutions).getCost()); - } - - }); - - } - - @Override - public void calculationEnds(BenchmarkInstance p, String algorithmName,VehicleRoutingAlgorithm algorithm, int run,Collection solutions) {} - - }); - - computationalLab.setThreads(2); - /* - * run the experiments - */ - computationalLab.run(); - - /* - * plot the lineChart - */ - XYLineChartBuilder.saveChartAsPNG(chartBuilder.build(), "output/computationalStudies_schrimpf_vs_greedy.png"); - - } - -} diff --git a/jsprit-examples/src/main/java/jsprit/examples/EnRoutePickupAndDeliveryWithMultipleDepotsAndVehicleAccessConstraintAndSpecifiedVehicleEndLocationsExample.java b/jsprit-examples/src/main/java/jsprit/examples/EnRoutePickupAndDeliveryWithMultipleDepotsAndVehicleAccessConstraintAndSpecifiedVehicleEndLocationsExample.java deleted file mode 100644 index 8c5b9bbc..00000000 --- a/jsprit-examples/src/main/java/jsprit/examples/EnRoutePickupAndDeliveryWithMultipleDepotsAndVehicleAccessConstraintAndSpecifiedVehicleEndLocationsExample.java +++ /dev/null @@ -1,220 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2014 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.examples; - -import jsprit.analysis.toolbox.GraphStreamViewer; -import jsprit.analysis.toolbox.GraphStreamViewer.Label; -import jsprit.core.algorithm.VehicleRoutingAlgorithm; -import jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder; -import jsprit.core.algorithm.state.StateManager; -import jsprit.core.algorithm.termination.IterationWithoutImprovementTermination; -import jsprit.core.problem.Location; -import jsprit.core.problem.VehicleRoutingProblem; -import jsprit.core.problem.VehicleRoutingProblem.FleetSize; -import jsprit.core.problem.constraint.ConstraintManager; -import jsprit.core.problem.constraint.HardRouteConstraint; -import jsprit.core.problem.job.Shipment; -import jsprit.core.problem.misc.JobInsertionContext; -import jsprit.core.problem.solution.VehicleRoutingProblemSolution; -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.reporting.SolutionPrinter; -import jsprit.core.util.Coordinate; -import jsprit.core.util.Solutions; -import jsprit.util.Examples; - -import java.util.Collection; - - -public class EnRoutePickupAndDeliveryWithMultipleDepotsAndVehicleAccessConstraintAndSpecifiedVehicleEndLocationsExample { - - public static void main(String[] args) { - /* - * some preparation - create output folder - */ - Examples.createOutputFolder(); - - /* - * get a vehicle type-builder and build a type with the typeId "vehicleType" and a capacity of 2 - */ - VehicleTypeImpl.Builder vehicleTypeBuilder = VehicleTypeImpl.Builder.newInstance("vehicleType").addCapacityDimension(0, 2); - vehicleTypeBuilder.setCostPerDistance(1.0); - VehicleType vehicleType = vehicleTypeBuilder.build(); - - /* - * define two vehicles and their locations. - * - * this example employs two vehicles. one that has to return to its start-location (vehicle1) and one that has a different - * end-location. - * - * play with these location to see which impact they have on customer-sequences. - */ - Builder vehicleBuilder1 = VehicleImpl.Builder.newInstance("v1"); - vehicleBuilder1.setStartLocation(loc(Coordinate.newInstance(10, 10))); - vehicleBuilder1.setType(vehicleType); - VehicleImpl vehicle1 = vehicleBuilder1.build(); - - Builder vehicleBuilder2 = VehicleImpl.Builder.newInstance("v2"); - vehicleBuilder2.setStartLocation(loc(Coordinate.newInstance(30, 30))).setEndLocation(loc(Coordinate.newInstance(30, 19))); - vehicleBuilder2.setType(vehicleType); - VehicleImpl vehicle2 = vehicleBuilder2.build(); - - - /* - * build shipments at the required locations, each with a capacity-demand of 1. - * - */ - Shipment shipment1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(5, 7))).setDeliveryLocation(loc(Coordinate.newInstance(6, 9))).build(); - Shipment shipment2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(5, 13))).setDeliveryLocation(loc(Coordinate.newInstance(6, 11))).build(); - - Shipment shipment3 = Shipment.Builder.newInstance("3").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(15, 7))).setDeliveryLocation(loc(Coordinate.newInstance(14, 9))).build(); - Shipment shipment4 = Shipment.Builder.newInstance("4").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(15, 13))).setDeliveryLocation(loc(Coordinate.newInstance(14, 11))).build(); - - Shipment shipment5 = Shipment.Builder.newInstance("5").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(25, 27))).setDeliveryLocation(loc(Coordinate.newInstance(26, 29))).build(); - Shipment shipment6 = Shipment.Builder.newInstance("6").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(25, 33))).setDeliveryLocation(loc(Coordinate.newInstance(26, 31))).build(); - - Shipment shipment7 = Shipment.Builder.newInstance("7").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(35, 27))).setDeliveryLocation(loc(Coordinate.newInstance(34, 29))).build(); - Shipment shipment8 = Shipment.Builder.newInstance("8").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(35, 33))).setDeliveryLocation(loc(Coordinate.newInstance(34, 31))).build(); - - Shipment shipment9 = Shipment.Builder.newInstance("9").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(5, 27))).setDeliveryLocation(loc(Coordinate.newInstance(6, 29))).build(); - Shipment shipment10 = Shipment.Builder.newInstance("10").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(5, 33))).setDeliveryLocation(loc(Coordinate.newInstance(6, 31))).build(); - - Shipment shipment11 = Shipment.Builder.newInstance("11").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(15, 27))).setDeliveryLocation(loc(Coordinate.newInstance(14, 29))).build(); - Shipment shipment12 = Shipment.Builder.newInstance("12").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(15, 33))).setDeliveryLocation(loc(Coordinate.newInstance(14, 31))).build(); - - Shipment shipment13 = Shipment.Builder.newInstance("13").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(25, 7))).setDeliveryLocation(loc(Coordinate.newInstance(26, 9))).build(); - Shipment shipment14 = Shipment.Builder.newInstance("14").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(25, 13))).setDeliveryLocation(loc(Coordinate.newInstance(26, 11))).build(); - - Shipment shipment15 = Shipment.Builder.newInstance("15").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(35, 7))).setDeliveryLocation(loc(Coordinate.newInstance(34, 9))).build(); - Shipment shipment16 = Shipment.Builder.newInstance("16").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(35, 13))).setDeliveryLocation(loc(Coordinate.newInstance(34, 11))).build(); - - Shipment shipment17 = Shipment.Builder.newInstance("17").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(5, 14))).setDeliveryLocation(loc(Coordinate.newInstance(6, 16))).build(); - Shipment shipment18 = Shipment.Builder.newInstance("18").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(5, 20))).setDeliveryLocation(loc(Coordinate.newInstance(6, 18))).build(); - - Shipment shipment19 = Shipment.Builder.newInstance("19").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(15, 14))).setDeliveryLocation(loc(Coordinate.newInstance(14, 16))).build(); - Shipment shipment20 = Shipment.Builder.newInstance("20").addSizeDimension(0, 1).setPickupLocation(loc(Coordinate.newInstance(15, 20))).setDeliveryLocation(loc(Coordinate.newInstance(14, 18))).build(); - - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - vrpBuilder.addVehicle(vehicle1).addVehicle(vehicle2); - vrpBuilder.addJob(shipment1).addJob(shipment2).addJob(shipment3).addJob(shipment4); - vrpBuilder.addJob(shipment5).addJob(shipment6).addJob(shipment7).addJob(shipment8); - vrpBuilder.addJob(shipment9).addJob(shipment10).addJob(shipment11).addJob(shipment12); - vrpBuilder.addJob(shipment13).addJob(shipment14).addJob(shipment15).addJob(shipment16); - vrpBuilder.addJob(shipment17).addJob(shipment18).addJob(shipment19).addJob(shipment20); - - //you only have two vehicles - vrpBuilder.setFleetSize(FleetSize.FINITE); - - - - //build the problem - VehicleRoutingProblem problem = vrpBuilder.build(); - - /* - * add a geographic constraint determining that vehicle1 cannot go to x>15 and vehicle2 cannot go to x<15 - * - * switch off the geoConstraints to see the impact of this constraint on routes, or just exchange v1 and v2 to reverse the geo-constraint. - */ - HardRouteConstraint geoClusterConstraint = new HardRouteConstraint() { - - @Override - public boolean fulfilled(JobInsertionContext insertionContext) { - Shipment shipment2insert = ((Shipment)insertionContext.getJob()); - if(insertionContext.getNewVehicle().getId().equals("v1")){ - if(shipment2insert.getPickupLocation().getCoordinate().getX() > 15. || shipment2insert.getDeliveryLocation().getCoordinate().getX() > 15.){ - return false; - } - } - if(insertionContext.getNewVehicle().getId().equals("v2")){ - if(shipment2insert.getPickupLocation().getCoordinate().getX() < 15. || shipment2insert.getDeliveryLocation().getCoordinate().getX() < 15.){ - return false; - } - } - return true; - } - }; - - /* - * get a sample algorithm. - * - * Note that you need to make sure to prohibit vehicle-switching by adding the insertion-tag false. - * This way you make sure that no vehicle can take over a route that is employed by another. Allowing this might make sense when dealing with - * a heterogeneous fleet and you want to employ a bigger vehicle on a still existing route. However, allowing it makes constraint-checking - * bit more complicated and you cannot just add the above hard-constraint. Latter will be covered in another example. - * - */ - VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(problem,"input/algorithmConfig_noVehicleSwitch.xml"); - vraBuilder.addCoreConstraints(); - vraBuilder.addDefaultCostCalculators(); - - StateManager stateManager = new StateManager(problem); - ConstraintManager constraintManager = new ConstraintManager(problem,stateManager); - constraintManager.addConstraint(geoClusterConstraint); - - vraBuilder.setStateAndConstraintManager(stateManager,constraintManager); - VehicleRoutingAlgorithm algorithm = vraBuilder.build(); - - algorithm.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(100)); -// algorithm.setMaxIterations(30000); - /* - * and search a solution - */ - Collection solutions = algorithm.searchSolutions(); - - /* - * get the best - */ - VehicleRoutingProblemSolution bestSolution = Solutions.bestOf(solutions); - - /* - * write out problem and solution to xml-file - */ -// new VrpXMLWriter(problem, solutions).write("output/shipment-problem-with-solution.xml"); - - /* - * print nRoutes and totalCosts of bestSolution - */ - SolutionPrinter.print(bestSolution); - - /* - * plot problem without solution - */ -// Plotter problemPlotter = new Plotter(problem); -// problemPlotter.plotShipments(true); -// problemPlotter.plot("output/enRoutePickupAndDeliveryWithMultipleLocationsExample_problem.png", "en-route pickup and delivery"); -// -// /* -// * plot problem with solution -// */ -// Plotter solutionPlotter = new Plotter(problem,Arrays.asList(Solutions.bestOf(solutions).getRoutes().iterator().next())); -// solutionPlotter.plotShipments(true); -// solutionPlotter.plot("output/enRoutePickupAndDeliveryWithMultipleLocationsExample_solution.png", "en-route pickup and delivery"); - - new GraphStreamViewer(problem).labelWith(Label.ID).setRenderDelay(100).setRenderShipments(true).display(); - - new GraphStreamViewer(problem,Solutions.bestOf(solutions)).labelWith(Label.ACTIVITY).setRenderDelay(100).setRenderShipments(true).display(); - - } - - private static Location loc(Coordinate coordinate) { - return Location.Builder.newInstance().setCoordinate(coordinate).build(); - } - -} - diff --git a/jsprit-examples/src/main/java/jsprit/examples/HVRPBenchmarkExample.java b/jsprit-examples/src/main/java/jsprit/examples/HVRPBenchmarkExample.java deleted file mode 100644 index 03dff1cd..00000000 --- a/jsprit-examples/src/main/java/jsprit/examples/HVRPBenchmarkExample.java +++ /dev/null @@ -1,80 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2014 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.examples; - -import jsprit.analysis.toolbox.AlgorithmSearchProgressChartListener; -import jsprit.analysis.toolbox.GraphStreamViewer; -import jsprit.analysis.toolbox.Plotter; -import jsprit.core.algorithm.VehicleRoutingAlgorithm; -import jsprit.core.algorithm.io.VehicleRoutingAlgorithms; -import jsprit.core.problem.VehicleRoutingProblem; -import jsprit.core.problem.solution.VehicleRoutingProblemSolution; -import jsprit.core.reporting.SolutionPrinter; -import jsprit.core.util.Solutions; -import jsprit.instance.reader.VrphGoldenReader; -import jsprit.instance.reader.VrphGoldenReader.VrphType; -import jsprit.util.Examples; - -import java.util.Collection; - -/** - * Shows how to benchmark the algorithm on different classical HVRP and FSM instances. - * - *

These instances are from Golden and Taillard and copied from - * . - * - *

You can find best results of different problems, instances and authors here: - *
http://link.springer.com/article/10.1007%2Fs10732-011-9186-y - *
http://www2.ic.uff.br/~satoru/conteudo/artigos/PAPER%20PUCA-JHeuristics-2011.pdf - *
http://citeseerx.ist.psu.edu/viewdoc/download?doi=10.1.1.100.2331&rep=rep1&type=pdf - * - * @author schroeder - * - */ -public class HVRPBenchmarkExample { - - public static void main(String[] args) { - Examples.createOutputFolder(); - - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - //read modified Golden-instance, you can find all relevant instances in jsprit-instances/instances/vrph - //you can build various problems, see VrphType doc for more details - new VrphGoldenReader(vrpBuilder, VrphType.HVRPFD).read("input/cn_14mix.txt"); -// vrpBuilder.addPenaltyVehicles(10.0); - VehicleRoutingProblem vrp = vrpBuilder.build(); - - //try also input//jsprit-examples/input/algorithmConfig_considerFixedCosts_routeLevel.xml - //results might even be a bit better, but it is slower, since it checks insertion on routeLevel - //rather than on local level - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "input/algorithmConfig_considerFixedCosts.xml"); - vra.setMaxIterations(10000); -// vra.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(500)); - vra.addListener(new AlgorithmSearchProgressChartListener("output/progress.png")); - Collection solutions = vra.searchSolutions(); - - VehicleRoutingProblemSolution best = Solutions.bestOf(solutions); - - SolutionPrinter.print(vrp, best, SolutionPrinter.Print.VERBOSE); - - - Plotter plotter = new Plotter(vrp,best); - plotter.plot("output/cn14.png", "cn14"); - - new GraphStreamViewer(vrp, best).setRenderDelay(100).display(); - } - -}