diff --git a/jsprit-analysis/src/main/java/com/graphhopper/jsprit/analysis/toolbox/ConcurrentBenchmarker.java b/jsprit-analysis/src/main/java/com/graphhopper/jsprit/analysis/toolbox/ConcurrentBenchmarker.java
deleted file mode 100644
index f3020c7b..00000000
--- a/jsprit-analysis/src/main/java/com/graphhopper/jsprit/analysis/toolbox/ConcurrentBenchmarker.java
+++ /dev/null
@@ -1,219 +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 com.graphhopper.jsprit.analysis.toolbox;
-
-import com.graphhopper.jsprit.analysis.util.BenchmarkWriter;
-import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm;
-import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithmFactory;
-import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
-import com.graphhopper.jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners.Priority;
-import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
-import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
-import com.graphhopper.jsprit.core.util.BenchmarkInstance;
-import com.graphhopper.jsprit.core.util.BenchmarkResult;
-import com.graphhopper.jsprit.core.util.Solutions;
-import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-import java.util.concurrent.*;
-
-
-public class ConcurrentBenchmarker {
-
- public static interface Cost {
- public double getCost(VehicleRoutingProblemSolution sol);
- }
-
-
- private String algorithmConfig = null;
-
- private List benchmarkInstances = new ArrayList();
-
- private int runs = 1;
-
- private Collection writers = new ArrayList();
-
- private Collection results = new ArrayList();
-
- private Cost cost = new Cost() {
-
- @Override
- public double getCost(VehicleRoutingProblemSolution sol) {
- return sol.getCost();
- }
-
- };
-
- private VehicleRoutingAlgorithmFactory algorithmFactory;
-
- public void setCost(Cost cost) {
- this.cost = cost;
- }
-
- public ConcurrentBenchmarker(String algorithmConfig) {
- super();
- this.algorithmConfig = algorithmConfig;
-// LoggerFactory.getRootLogger().setLevel(Level.ERROR);
- }
-
- public ConcurrentBenchmarker(VehicleRoutingAlgorithmFactory algorithmFactory) {
- this.algorithmFactory = algorithmFactory;
- }
-
- public void addBenchmarkWriter(BenchmarkWriter writer) {
- writers.add(writer);
- }
-
- public void addInstance(String name, VehicleRoutingProblem problem) {
- benchmarkInstances.add(new BenchmarkInstance(name, problem, null, null));
- }
-
- public void addInstane(BenchmarkInstance instance) {
- benchmarkInstances.add(instance);
- }
-
- public void addAllInstances(Collection instances) {
- benchmarkInstances.addAll(instances);
- }
-
- public void addInstance(String name, VehicleRoutingProblem problem, Double bestKnownResult, Double bestKnownVehicles) {
- benchmarkInstances.add(new BenchmarkInstance(name, problem, bestKnownResult, bestKnownVehicles));
- }
-
- /**
- * Sets nuOfRuns with same algorithm on same instance.
- *
Default is 1
- *
- * @param runs
- */
- public void setNuOfRuns(int runs) {
- this.runs = runs;
- }
-
- public void run() {
- System.out.println("start benchmarking [nuOfInstances=" + benchmarkInstances.size() + "][runsPerInstance=" + runs + "]");
- double startTime = System.currentTimeMillis();
- ExecutorService executor = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors() + 1);
- List> futures = new ArrayList>();
- for (final BenchmarkInstance p : benchmarkInstances) {
-
- Future futureResult = executor.submit(new Callable() {
-
- @Override
- public BenchmarkResult call() throws Exception {
- return runAlgoAndGetResult(p);
- }
-
- });
- futures.add(futureResult);
-
- }
- try {
- int count = 1;
- for (Future f : futures) {
- BenchmarkResult r = f.get();
- print(r, count);
- results.add(f.get());
- count++;
- }
- } catch (InterruptedException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } catch (ExecutionException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- executor.shutdown();
- print(results);
- System.out.println("done [time=" + (System.currentTimeMillis() - startTime) / 1000 + "sec]");
- }
-
- private BenchmarkResult runAlgoAndGetResult(BenchmarkInstance p) {
- double[] vehicles = new double[runs];
- double[] results = new double[runs];
- double[] times = new double[runs];
-
- for (int run = 0; run < runs; run++) {
- VehicleRoutingAlgorithm vra = createAlgorithm(p);
- StopWatch stopwatch = new StopWatch();
- vra.getAlgorithmListeners().addListener(stopwatch, Priority.HIGH);
- Collection solutions = vra.searchSolutions();
- VehicleRoutingProblemSolution best = Solutions.bestOf(solutions);
- vehicles[run] = best.getRoutes().size();
- results[run] = cost.getCost(best);
- times[run] = stopwatch.getCompTimeInSeconds();
- }
-
- return new BenchmarkResult(p, runs, results, times, vehicles);
- }
-
- private VehicleRoutingAlgorithm createAlgorithm(BenchmarkInstance p) {
- if (algorithmConfig != null) {
- return VehicleRoutingAlgorithms.readAndCreateAlgorithm(p.vrp, algorithmConfig);
- } else {
- return algorithmFactory.createAlgorithm(p.vrp);
- }
-
- }
-
- private void print(Collection results) {
- double sumTime = 0.0;
- double sumResult = 0.0;
- for (BenchmarkResult r : results) {
- sumTime += r.getTimesStats().getMean();
- sumResult += r.getResultStats().getMean();
-// print(r);
- }
- System.out.println("[avgTime=" + round(sumTime / (double) results.size(), 2) + "][avgResult=" + round(sumResult / (double) results.size(), 2) + "]");
- for (BenchmarkWriter writer : writers) {
- writer.write(results);
- }
- }
-
- private void print(BenchmarkResult r, int count) {
- Double avgDelta = null;
- Double bestDelta = null;
- Double worstDelta = null;
- if (r.instance.bestKnownResult != null) {
- avgDelta = (r.getResultStats().getMean() / r.instance.bestKnownResult - 1) * 100;
- bestDelta = (r.getResultStats().getMin() / r.instance.bestKnownResult - 1) * 100;
- worstDelta = (r.getResultStats().getMax() / r.instance.bestKnownResult - 1) * 100;
- }
- System.out.println("(" + count + "/" + benchmarkInstances.size() + ")" + "\t[instance=" + r.instance.name +
- "][avgTime=" + round(r.getTimesStats().getMean(), 2) + "]" +
- "[Result=" + getString(r.getResultStats()) + "]" +
- "[Vehicles=" + getString(r.getVehicleStats()) + "]" +
- "[Delta[%]=" + getString(bestDelta, avgDelta, worstDelta) + "]");
- }
-
- private String getString(Double bestDelta, Double avgDelta, Double worstDelta) {
- return "[best=" + round(bestDelta, 2) + "][avg=" + round(avgDelta, 2) + "][worst=" + round(worstDelta, 2) + "]";
- }
-
- private String getString(DescriptiveStatistics stats) {
- return "[best=" + round(stats.getMin(), 2) + "][avg=" + round(stats.getMean(), 2) + "][worst=" + round(stats.getMax(), 2) + "][stdDev=" + round(stats.getStandardDeviation(), 2) + "]";
- }
-
- private Double round(Double value, int i) {
- if (value == null) return null;
- long roundedVal = Math.round(value * Math.pow(10, i));
- return (double) roundedVal / (double) (Math.pow(10, i));
- }
-
-}
diff --git a/jsprit-core/pom.xml b/jsprit-core/pom.xml
index 54096f97..b427f92e 100644
--- a/jsprit-core/pom.xml
+++ b/jsprit-core/pom.xml
@@ -55,60 +55,25 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
- commons-configuration
- commons-configuration
- 1.9
- jar
- compile
-
-
-
- xerces
- xercesImpl
- 2.11.0
- compile
-
-
org.apache.commonscommons-math33.4
+
+ org.slf4j
+ slf4j-api
+ ${logger.version}
+
+
diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/VehicleRoutingAlgorithmBuilder.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/VehicleRoutingAlgorithmBuilder.java
deleted file mode 100644
index 80af621b..00000000
--- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/VehicleRoutingAlgorithmBuilder.java
+++ /dev/null
@@ -1,177 +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 com.graphhopper.jsprit.core.algorithm;
-
-import com.graphhopper.jsprit.core.algorithm.io.AlgorithmConfig;
-import com.graphhopper.jsprit.core.algorithm.io.AlgorithmConfigXmlReader;
-import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
-import com.graphhopper.jsprit.core.algorithm.state.StateManager;
-import com.graphhopper.jsprit.core.algorithm.state.UpdateEndLocationIfRouteIsOpen;
-import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
-import com.graphhopper.jsprit.core.problem.constraint.ConstraintManager;
-import com.graphhopper.jsprit.core.problem.solution.SolutionCostCalculator;
-
-/**
- * Builder that builds a {@link VehicleRoutingAlgorithm}.
- *
- * @author schroeder
- */
-public class VehicleRoutingAlgorithmBuilder {
-
- private String algorithmConfigFile;
-
- private AlgorithmConfig algorithmConfig;
-
- private final VehicleRoutingProblem vrp;
-
- private SolutionCostCalculator solutionCostCalculator;
-
- private StateManager stateManager;
-
- private boolean addCoreConstraints = false;
-
- private boolean addDefaultCostCalculators = false;
-
- private ConstraintManager constraintManager;
-
- private int nuOfThreads = 0;
-
- /**
- * Constructs the builder with the problem and an algorithmConfigFile. Latter is to configure and specify the ruin-and-recreate meta-heuristic.
- *
- * @param problem to solve
- * @param algorithmConfig config file of VehicleRoutingAlgorithm
- */
- public VehicleRoutingAlgorithmBuilder(VehicleRoutingProblem problem, String algorithmConfig) {
- this.vrp = problem;
- this.algorithmConfigFile = algorithmConfig;
- this.algorithmConfig = null;
- }
-
- /**
- * Constructs the builder with the problem and an algorithmConfig. Latter is to configure and specify the ruin-and-recreate meta-heuristic.
- *
- * @param problem to solve
- * @param algorithmConfig config file of VehicleRoutingAlgorithm
- */
- public VehicleRoutingAlgorithmBuilder(VehicleRoutingProblem problem, AlgorithmConfig algorithmConfig) {
- this.vrp = problem;
- this.algorithmConfigFile = null;
- this.algorithmConfig = algorithmConfig;
- }
-
- /**
- * Sets custom objective function.
- *
- *
If objective function is not set, a default function is applied (which basically minimizes
- * fixed and variable transportation costs ({@link VariablePlusFixedSolutionCostCalculatorFactory}).
- *
- * @param objectiveFunction to be minimized
- * @see VariablePlusFixedSolutionCostCalculatorFactory
- */
- public void setObjectiveFunction(SolutionCostCalculator objectiveFunction) {
- this.solutionCostCalculator = objectiveFunction;
- }
-
- /**
- * Sets stateManager to memorize states.
- *
- * @param stateManager that memorizes your states
- * @see StateManager
- */
- public void setStateManager(StateManager stateManager) {
- this.stateManager = stateManager;
- }
-
- /**
- * Adds core constraints.
- *
- *
Thus, it adds vehicle-capacity, time-window and skills constraints and their
- * required stateUpdater.
- */
- public void addCoreConstraints() {
- addCoreConstraints = true;
- }
-
- /**
- * Adds default cost calculators used by the insertion heuristic,
- * to calculate activity insertion costs.
- * By default, marginal transportation costs are calculated. Thus when inserting
- * act_k between act_i and act_j, marginal (additional) transportation costs
- * are basically c(act_i,act_k)+c(act_k,act_j)-c(act_i,act_j).
- *
- *
Do not use this method, if you plan to control the insertion heuristic
- * entirely via hard- and soft-constraints.
- */
- public void addDefaultCostCalculators() {
- addDefaultCostCalculators = true;
- }
-
- /**
- * Sets state- and constraintManager.
- *
- * @param stateManager that memorizes your states
- * @param constraintManager that manages your constraints
- * @see StateManager
- * @see ConstraintManager
- */
- public void setStateAndConstraintManager(StateManager stateManager, ConstraintManager constraintManager) {
- this.stateManager = stateManager;
- this.constraintManager = constraintManager;
- }
-
- /**
- * Sets nuOfThreads.
- *
- * @param nuOfThreads to be operated
- */
- public void setNuOfThreads(int nuOfThreads) {
- this.nuOfThreads = nuOfThreads;
- }
-
- /**
- * Builds and returns the algorithm.
- *
- *
If algorithmConfigFile is set, it reads the configuration.
- *
- * @return the algorithm
- */
- public VehicleRoutingAlgorithm build() {
- if (stateManager == null) stateManager = new StateManager(vrp);
- if (constraintManager == null) constraintManager = new ConstraintManager(vrp, stateManager);
- //add core updater
- stateManager.addStateUpdater(new UpdateEndLocationIfRouteIsOpen());
-// stateManager.addStateUpdater(new OpenRouteStateVerifier());
-
- if (addCoreConstraints) {
- constraintManager.addLoadConstraint();
- constraintManager.addTimeWindowConstraint();
- constraintManager.addSkillsConstraint();
- stateManager.updateLoadStates();
- stateManager.updateTimeWindowStates();
- stateManager.updateSkillStates();
- }
- if (algorithmConfig == null) {
- algorithmConfig = new AlgorithmConfig();
- AlgorithmConfigXmlReader xmlReader = new AlgorithmConfigXmlReader(algorithmConfig);
- xmlReader.read(algorithmConfigFile);
- }
- return VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, algorithmConfig, nuOfThreads, solutionCostCalculator, stateManager, constraintManager, addDefaultCostCalculators);
- }
-
-
-}
diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/acceptor/ExperimentalSchrimpfAcceptance.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/acceptor/ExperimentalSchrimpfAcceptance.java
index 64ca65f5..d42ff4d2 100644
--- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/acceptor/ExperimentalSchrimpfAcceptance.java
+++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/acceptor/ExperimentalSchrimpfAcceptance.java
@@ -17,21 +17,18 @@
package com.graphhopper.jsprit.core.algorithm.acceptor;
import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm;
-import com.graphhopper.jsprit.core.algorithm.io.AlgorithmConfig;
-import com.graphhopper.jsprit.core.algorithm.io.AlgorithmConfigXmlReader;
-import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
+import com.graphhopper.jsprit.core.algorithm.box.GreedySchrimpfFactory;
+import com.graphhopper.jsprit.core.algorithm.box.Jsprit;
import com.graphhopper.jsprit.core.algorithm.listener.AlgorithmStartsListener;
import com.graphhopper.jsprit.core.algorithm.listener.IterationEndsListener;
import com.graphhopper.jsprit.core.algorithm.listener.IterationStartsListener;
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
-import com.graphhopper.jsprit.core.util.Resource;
import com.graphhopper.jsprit.core.util.Solutions;
import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.net.URL;
import java.util.Collection;
@@ -114,10 +111,9 @@ public class ExperimentalSchrimpfAcceptance implements SolutionAcceptor, Iterati
*/
final double[] results = new double[nOfRandomWalks];
- URL resource = Resource.getAsURL("randomWalk.xml");
- AlgorithmConfig algorithmConfig = new AlgorithmConfig();
- new AlgorithmConfigXmlReader(algorithmConfig).read(resource);
- VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.createAlgorithm(problem, algorithmConfig);
+ Jsprit.Builder builder = new GreedySchrimpfFactory().createGreedyAlgorithmBuilder(problem);
+ builder.setCustomAcceptor(new AcceptNewRemoveFirst(1));
+ VehicleRoutingAlgorithm vra = builder.buildAlgorithm();
vra.setMaxIterations(nOfRandomWalks);
vra.getAlgorithmListeners().addListener(new IterationEndsListener() {
diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/acceptor/SchrimpfInitialThresholdGenerator.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/acceptor/SchrimpfInitialThresholdGenerator.java
index 3905142c..09f90237 100644
--- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/acceptor/SchrimpfInitialThresholdGenerator.java
+++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/acceptor/SchrimpfInitialThresholdGenerator.java
@@ -17,20 +17,17 @@
package com.graphhopper.jsprit.core.algorithm.acceptor;
import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm;
-import com.graphhopper.jsprit.core.algorithm.io.AlgorithmConfig;
-import com.graphhopper.jsprit.core.algorithm.io.AlgorithmConfigXmlReader;
-import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
+import com.graphhopper.jsprit.core.algorithm.box.GreedySchrimpfFactory;
+import com.graphhopper.jsprit.core.algorithm.box.Jsprit;
import com.graphhopper.jsprit.core.algorithm.listener.AlgorithmStartsListener;
import com.graphhopper.jsprit.core.algorithm.listener.IterationEndsListener;
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
-import com.graphhopper.jsprit.core.util.Resource;
import com.graphhopper.jsprit.core.util.Solutions;
import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.net.URL;
import java.util.Collection;
public class SchrimpfInitialThresholdGenerator implements AlgorithmStartsListener {
@@ -57,10 +54,9 @@ public class SchrimpfInitialThresholdGenerator implements AlgorithmStartsListene
*/
final double[] results = new double[nOfRandomWalks];
- URL resource = Resource.getAsURL("randomWalk.xml");
- AlgorithmConfig algorithmConfig = new AlgorithmConfig();
- new AlgorithmConfigXmlReader(algorithmConfig).read(resource);
- VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.createAlgorithm(problem, algorithmConfig);
+ Jsprit.Builder builder = new GreedySchrimpfFactory().createGreedyAlgorithmBuilder(problem);
+ builder.setCustomAcceptor(new AcceptNewRemoveFirst(1));
+ VehicleRoutingAlgorithm vra = builder.buildAlgorithm();
vra.setMaxIterations(nOfRandomWalks);
vra.getAlgorithmListeners().addListener(new IterationEndsListener() {
diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/GreedySchrimpfFactory.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/GreedySchrimpfFactory.java
index 195fcdf9..bd8c05d8 100644
--- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/GreedySchrimpfFactory.java
+++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/GreedySchrimpfFactory.java
@@ -17,13 +17,7 @@
package com.graphhopper.jsprit.core.algorithm.box;
import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm;
-import com.graphhopper.jsprit.core.algorithm.io.AlgorithmConfig;
-import com.graphhopper.jsprit.core.algorithm.io.AlgorithmConfigXmlReader;
-import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
-import com.graphhopper.jsprit.core.util.Resource;
-
-import java.net.URL;
/**
@@ -53,11 +47,28 @@ public class GreedySchrimpfFactory {
* @return algorithm
*/
public VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vrp) {
- AlgorithmConfig algorithmConfig = new AlgorithmConfig();
- URL resource = Resource.getAsURL("greedySchrimpf.xml");
- new AlgorithmConfigXmlReader(algorithmConfig).read(resource);
- return VehicleRoutingAlgorithms.createAlgorithm(vrp, algorithmConfig);
+ return createGreedyAlgorithmBuilder(vrp).buildAlgorithm();
}
+ public Jsprit.Builder createGreedyAlgorithmBuilder(VehicleRoutingProblem vrp) {
+ int radialShare = (int) (vrp.getJobs().size() * 0.3);
+ int randomShare = (int) (vrp.getJobs().size() * 0.5);
+
+ Jsprit.Builder builder = Jsprit.Builder.newInstance(vrp);
+ builder.setProperty(Jsprit.Parameter.THRESHOLD_ALPHA,"0.0");
+ builder.setProperty(Jsprit.Strategy.RADIAL_BEST, "0.5");
+ builder.setProperty(Jsprit.Strategy.RADIAL_REGRET, "0.0");
+ builder.setProperty(Jsprit.Strategy.RANDOM_BEST, "0.5");
+ builder.setProperty(Jsprit.Strategy.RANDOM_REGRET, "0.0");
+ builder.setProperty(Jsprit.Strategy.WORST_BEST, "0.0");
+ builder.setProperty(Jsprit.Strategy.WORST_REGRET, "0.0");
+ builder.setProperty(Jsprit.Strategy.CLUSTER_BEST, "0.0");
+ builder.setProperty(Jsprit.Strategy.CLUSTER_REGRET, "0.0");
+ builder.setProperty(Jsprit.Parameter.RADIAL_MIN_SHARE, String.valueOf(radialShare));
+ builder.setProperty(Jsprit.Parameter.RADIAL_MAX_SHARE, String.valueOf(radialShare));
+ builder.setProperty(Jsprit.Parameter.RANDOM_BEST_MIN_SHARE, String.valueOf(randomShare));
+ builder.setProperty(Jsprit.Parameter.RANDOM_BEST_MAX_SHARE, String.valueOf(randomShare));
+ return builder;
+ }
}
diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/Jsprit.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/Jsprit.java
index 2f49d5c9..1e881fea 100644
--- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/Jsprit.java
+++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/Jsprit.java
@@ -4,6 +4,7 @@ import com.graphhopper.jsprit.core.algorithm.PrettyAlgorithmBuilder;
import com.graphhopper.jsprit.core.algorithm.SearchStrategy;
import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm;
import com.graphhopper.jsprit.core.algorithm.acceptor.SchrimpfAcceptance;
+import com.graphhopper.jsprit.core.algorithm.acceptor.SolutionAcceptor;
import com.graphhopper.jsprit.core.algorithm.listener.AlgorithmEndsListener;
import com.graphhopper.jsprit.core.algorithm.listener.IterationStartsListener;
import com.graphhopper.jsprit.core.algorithm.module.RuinAndRecreateModule;
@@ -140,6 +141,8 @@ public class Jsprit {
private ActivityInsertionCostsCalculator activityInsertionCalculator;
+ private SolutionAcceptor solutionAcceptor;
+
public static Builder newInstance(VehicleRoutingProblem vrp) {
return new Builder(vrp);
}
@@ -199,6 +202,11 @@ public class Jsprit {
return this;
}
+ public Builder setCustomAcceptor(SolutionAcceptor acceptor){
+ this.solutionAcceptor = acceptor;
+ return this;
+ }
+
public Builder setRandom(Random random) {
this.random = random;
return this;
@@ -300,6 +308,8 @@ public class Jsprit {
private Random random;
+ private SolutionAcceptor acceptor;
+
private Jsprit(Builder builder) {
this.stateManager = builder.stateManager;
this.constraintManager = builder.constraintManager;
@@ -310,6 +320,7 @@ public class Jsprit {
this.objectiveFunction = builder.objectiveFunction;
this.random = builder.random;
this.activityInsertion = builder.activityInsertionCalculator;
+ this.acceptor = builder.solutionAcceptor;
}
private VehicleRoutingAlgorithm create(final VehicleRoutingProblem vrp) {
@@ -500,40 +511,44 @@ public class Jsprit {
}
best.setRandom(random);
- final SchrimpfAcceptance schrimpfAcceptance = new SchrimpfAcceptance(1, toDouble(getProperty(Parameter.THRESHOLD_ALPHA.toString())));
- IterationStartsListener schrimpfThreshold = new IterationStartsListener() {
- @Override
- public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection solutions) {
- if (i == 1) {
- double initialThreshold = Solutions.bestOf(solutions).getCost() * toDouble(getProperty(Parameter.THRESHOLD_INI.toString()));
- schrimpfAcceptance.setInitialThreshold(initialThreshold);
+ IterationStartsListener schrimpfThreshold = null;
+ if(acceptor == null) {
+ final SchrimpfAcceptance schrimpfAcceptance = new SchrimpfAcceptance(1, toDouble(getProperty(Parameter.THRESHOLD_ALPHA.toString())));
+ schrimpfThreshold = new IterationStartsListener() {
+ @Override
+ public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection solutions) {
+ if (i == 1) {
+ double initialThreshold = Solutions.bestOf(solutions).getCost() * toDouble(getProperty(Parameter.THRESHOLD_INI.toString()));
+ schrimpfAcceptance.setInitialThreshold(initialThreshold);
+ }
}
- }
- };
+ };
+ acceptor = schrimpfAcceptance;
+ }
SolutionCostCalculator objectiveFunction = getObjectiveFunction(vrp, maxCosts);
- SearchStrategy radial_regret = new SearchStrategy(Strategy.RADIAL_REGRET.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction);
+ SearchStrategy radial_regret = new SearchStrategy(Strategy.RADIAL_REGRET.toString(), new SelectBest(), acceptor, objectiveFunction);
radial_regret.addModule(new RuinAndRecreateModule(Strategy.RADIAL_REGRET.toString(), regret, radial));
- SearchStrategy radial_best = new SearchStrategy(Strategy.RADIAL_BEST.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction);
+ SearchStrategy radial_best = new SearchStrategy(Strategy.RADIAL_BEST.toString(), new SelectBest(), acceptor, objectiveFunction);
radial_best.addModule(new RuinAndRecreateModule(Strategy.RADIAL_BEST.toString(), best, radial));
- SearchStrategy random_best = new SearchStrategy(Strategy.RANDOM_BEST.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction);
+ SearchStrategy random_best = new SearchStrategy(Strategy.RANDOM_BEST.toString(), new SelectBest(), acceptor, objectiveFunction);
random_best.addModule(new RuinAndRecreateModule(Strategy.RANDOM_BEST.toString(), best, random_for_best));
- SearchStrategy random_regret = new SearchStrategy(Strategy.RANDOM_REGRET.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction);
+ SearchStrategy random_regret = new SearchStrategy(Strategy.RANDOM_REGRET.toString(), new SelectBest(), acceptor, objectiveFunction);
random_regret.addModule(new RuinAndRecreateModule(Strategy.RANDOM_REGRET.toString(), regret, random_for_regret));
- SearchStrategy worst_regret = new SearchStrategy(Strategy.WORST_REGRET.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction);
+ SearchStrategy worst_regret = new SearchStrategy(Strategy.WORST_REGRET.toString(), new SelectBest(), acceptor, objectiveFunction);
worst_regret.addModule(new RuinAndRecreateModule(Strategy.WORST_REGRET.toString(), regret, worst));
- SearchStrategy worst_best = new SearchStrategy(Strategy.WORST_BEST.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction);
+ SearchStrategy worst_best = new SearchStrategy(Strategy.WORST_BEST.toString(), new SelectBest(), acceptor, objectiveFunction);
worst_best.addModule(new RuinAndRecreateModule(Strategy.WORST_BEST.toString(), best, worst));
- final SearchStrategy clusters_regret = new SearchStrategy(Strategy.CLUSTER_REGRET.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction);
+ final SearchStrategy clusters_regret = new SearchStrategy(Strategy.CLUSTER_REGRET.toString(), new SelectBest(), acceptor, objectiveFunction);
clusters_regret.addModule(new RuinAndRecreateModule(Strategy.CLUSTER_REGRET.toString(), regret, clusters));
- final SearchStrategy clusters_best = new SearchStrategy(Strategy.CLUSTER_BEST.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction);
+ final SearchStrategy clusters_best = new SearchStrategy(Strategy.CLUSTER_BEST.toString(), new SelectBest(), acceptor, objectiveFunction);
clusters_best.addModule(new RuinAndRecreateModule(Strategy.CLUSTER_BEST.toString(), best, clusters));
@@ -558,7 +573,9 @@ public class Jsprit {
VehicleRoutingAlgorithm vra = prettyBuilder.build();
- vra.addListener(schrimpfThreshold);
+ if(schrimpfThreshold != null) {
+ vra.addListener(schrimpfThreshold);
+ }
vra.addListener(noiseConfigurator);
vra.addListener(noise);
vra.addListener(clusters);
diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/SchrimpfFactory.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/SchrimpfFactory.java
index 069af7b6..50eefb0d 100644
--- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/SchrimpfFactory.java
+++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/SchrimpfFactory.java
@@ -17,13 +17,7 @@
package com.graphhopper.jsprit.core.algorithm.box;
import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm;
-import com.graphhopper.jsprit.core.algorithm.io.AlgorithmConfig;
-import com.graphhopper.jsprit.core.algorithm.io.AlgorithmConfigXmlReader;
-import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
-import com.graphhopper.jsprit.core.util.Resource;
-
-import java.net.URL;
/**
@@ -53,10 +47,25 @@ public class SchrimpfFactory {
* @return algorithm
*/
public VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vrp) {
- AlgorithmConfig algorithmConfig = new AlgorithmConfig();
- URL resource = Resource.getAsURL("schrimpf.xml");
- new AlgorithmConfigXmlReader(algorithmConfig).read(resource);
- return VehicleRoutingAlgorithms.createAlgorithm(vrp, algorithmConfig);
+ //TODO determine alpha threshold
+
+ int radialShare = (int) (vrp.getJobs().size() * 0.3);
+ int randomShare = (int) (vrp.getJobs().size() * 0.5);
+ Jsprit.Builder builder = Jsprit.Builder.newInstance(vrp);
+ builder.setProperty(Jsprit.Parameter.THRESHOLD_ALPHA,"0.0");
+ builder.setProperty(Jsprit.Strategy.RADIAL_BEST, "0.5");
+ builder.setProperty(Jsprit.Strategy.RADIAL_REGRET, "0.0");
+ builder.setProperty(Jsprit.Strategy.RANDOM_BEST, "0.5");
+ builder.setProperty(Jsprit.Strategy.RANDOM_REGRET, "0.0");
+ builder.setProperty(Jsprit.Strategy.WORST_BEST, "0.0");
+ builder.setProperty(Jsprit.Strategy.WORST_REGRET, "0.0");
+ builder.setProperty(Jsprit.Strategy.CLUSTER_BEST, "0.0");
+ builder.setProperty(Jsprit.Strategy.CLUSTER_REGRET, "0.0");
+ builder.setProperty(Jsprit.Parameter.RADIAL_MIN_SHARE, String.valueOf(radialShare));
+ builder.setProperty(Jsprit.Parameter.RADIAL_MAX_SHARE, String.valueOf(radialShare));
+ builder.setProperty(Jsprit.Parameter.RANDOM_BEST_MIN_SHARE, String.valueOf(randomShare));
+ builder.setProperty(Jsprit.Parameter.RANDOM_BEST_MAX_SHARE, String.valueOf(randomShare));
+ return builder.buildAlgorithm();
}
diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/BuildCVRPAlgoFromScratch_IT.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/BuildCVRPAlgoFromScratch_IT.java
index 579166ff..bf110c35 100644
--- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/BuildCVRPAlgoFromScratch_IT.java
+++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/BuildCVRPAlgoFromScratch_IT.java
@@ -30,12 +30,12 @@ import com.graphhopper.jsprit.core.algorithm.state.InternalStates;
import com.graphhopper.jsprit.core.algorithm.state.StateManager;
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
import com.graphhopper.jsprit.core.problem.constraint.ConstraintManager;
-import com.graphhopper.jsprit.core.problem.io.VrpXMLReader;
import com.graphhopper.jsprit.core.problem.solution.SolutionCostCalculator;
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
import com.graphhopper.jsprit.core.problem.vehicle.InfiniteFleetManagerFactory;
import com.graphhopper.jsprit.core.problem.vehicle.VehicleFleetManager;
+import com.graphhopper.jsprit.core.util.ChristofidesReader;
import com.graphhopper.jsprit.core.util.Solutions;
import org.junit.Before;
import org.junit.Test;
@@ -55,7 +55,7 @@ public class BuildCVRPAlgoFromScratch_IT {
@Before
public void setup() {
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(builder).read("src/test/resources/vrpnc1-jsprit.xml");
+ new ChristofidesReader(builder).read(getClass().getResourceAsStream("vrpnc1.txt"));
vrp = builder.build();
final StateManager stateManager = new StateManager(vrp);
diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/BuildPDVRPAlgoFromScratch_IT.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/BuildPDVRPAlgoFromScratch_IT.java
deleted file mode 100644
index bc64e653..00000000
--- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/BuildPDVRPAlgoFromScratch_IT.java
+++ /dev/null
@@ -1,118 +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 com.graphhopper.jsprit.core.algorithm;
-
-import com.graphhopper.jsprit.core.IntegrationTest;
-import com.graphhopper.jsprit.core.algorithm.acceptor.GreedyAcceptance;
-import com.graphhopper.jsprit.core.algorithm.module.RuinAndRecreateModule;
-import com.graphhopper.jsprit.core.algorithm.recreate.BestInsertionBuilder;
-import com.graphhopper.jsprit.core.algorithm.recreate.InsertionStrategy;
-import com.graphhopper.jsprit.core.algorithm.ruin.RadialRuinStrategyFactory;
-import com.graphhopper.jsprit.core.algorithm.ruin.RandomRuinStrategyFactory;
-import com.graphhopper.jsprit.core.algorithm.ruin.RuinStrategy;
-import com.graphhopper.jsprit.core.algorithm.ruin.distance.AvgServiceDistance;
-import com.graphhopper.jsprit.core.algorithm.selector.SelectBest;
-import com.graphhopper.jsprit.core.algorithm.state.InternalStates;
-import com.graphhopper.jsprit.core.algorithm.state.StateManager;
-import com.graphhopper.jsprit.core.algorithm.termination.IterationWithoutImprovementTermination;
-import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
-import com.graphhopper.jsprit.core.problem.constraint.ConstraintManager;
-import com.graphhopper.jsprit.core.problem.io.VrpXMLReader;
-import com.graphhopper.jsprit.core.problem.solution.SolutionCostCalculator;
-import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
-import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
-import com.graphhopper.jsprit.core.problem.vehicle.InfiniteFleetManagerFactory;
-import com.graphhopper.jsprit.core.problem.vehicle.VehicleFleetManager;
-import junit.framework.Assert;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.util.Collection;
-
-
-public class BuildPDVRPAlgoFromScratch_IT {
-
- VehicleRoutingProblem vrp;
-
- VehicleRoutingAlgorithm vra;
-
- static Logger log = LoggerFactory.getLogger(BuildPDVRPAlgoFromScratch_IT.class);
-
- @Before
- public void setup() {
-
- VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(builder).read("src/test/resources/pd_solomon_r101.xml");
- vrp = builder.build();
-
- final StateManager stateManager = new StateManager(vrp);
-
- ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager);
-
- VehicleFleetManager fleetManager = new InfiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager();
-
- InsertionStrategy bestInsertion = new BestInsertionBuilder(vrp, fleetManager, stateManager, constraintManager).build();
-
- RuinStrategy radial = new RadialRuinStrategyFactory(0.15, new AvgServiceDistance(vrp.getTransportCosts())).createStrategy(vrp);
- RuinStrategy random = new RandomRuinStrategyFactory(0.25).createStrategy(vrp);
-
- SolutionCostCalculator solutionCostCalculator = new SolutionCostCalculator() {
-
- @Override
- public double getCosts(VehicleRoutingProblemSolution solution) {
- double costs = 0.0;
- for (VehicleRoute route : solution.getRoutes()) {
- Double cost_of_route = stateManager.getRouteState(route, InternalStates.COSTS, Double.class);
- if (cost_of_route == null) cost_of_route = 0.;
- costs += cost_of_route;
- }
- return costs;
- }
- };
-
- SearchStrategy randomStrategy = new SearchStrategy("random", new SelectBest(), new GreedyAcceptance(1), solutionCostCalculator);
- RuinAndRecreateModule randomModule = new RuinAndRecreateModule("randomRuin_bestInsertion", bestInsertion, random);
- randomStrategy.addModule(randomModule);
-
- SearchStrategy radialStrategy = new SearchStrategy("radial", new SelectBest(), new GreedyAcceptance(1), solutionCostCalculator);
- RuinAndRecreateModule radialModule = new RuinAndRecreateModule("radialRuin_bestInsertion", bestInsertion, radial);
- radialStrategy.addModule(radialModule);
-
- vra = new PrettyAlgorithmBuilder(vrp, fleetManager, stateManager, constraintManager)
- .addCoreStateAndConstraintStuff().constructInitialSolutionWith(bestInsertion, solutionCostCalculator)
- .withStrategy(radialStrategy, 0.5).withStrategy(randomStrategy, 0.5).build();
-
- vra.setMaxIterations(1000);
- vra.setPrematureAlgorithmTermination(new IterationWithoutImprovementTermination(100));
-
- }
-
- @Test
- @Category(IntegrationTest.class)
- public void test() {
- try {
- Collection solutions = vra.searchSolutions();
- Assert.assertTrue(true);
- } catch (Exception e) {
- Assert.assertTrue(false);
- }
- }
-
-}
diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/BuildPDVRPWithShipmentsAlgoFromScratch_IT.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/BuildPDVRPWithShipmentsAlgoFromScratch_IT.java
deleted file mode 100644
index c55b60e5..00000000
--- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/BuildPDVRPWithShipmentsAlgoFromScratch_IT.java
+++ /dev/null
@@ -1,114 +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 com.graphhopper.jsprit.core.algorithm;
-
-import com.graphhopper.jsprit.core.IntegrationTest;
-import com.graphhopper.jsprit.core.algorithm.acceptor.GreedyAcceptance;
-import com.graphhopper.jsprit.core.algorithm.module.RuinAndRecreateModule;
-import com.graphhopper.jsprit.core.algorithm.recreate.BestInsertionBuilder;
-import com.graphhopper.jsprit.core.algorithm.recreate.InsertionStrategy;
-import com.graphhopper.jsprit.core.algorithm.ruin.RadialRuinStrategyFactory;
-import com.graphhopper.jsprit.core.algorithm.ruin.RandomRuinStrategyFactory;
-import com.graphhopper.jsprit.core.algorithm.ruin.RuinStrategy;
-import com.graphhopper.jsprit.core.algorithm.ruin.distance.AvgServiceAndShipmentDistance;
-import com.graphhopper.jsprit.core.algorithm.selector.SelectBest;
-import com.graphhopper.jsprit.core.algorithm.state.InternalStates;
-import com.graphhopper.jsprit.core.algorithm.state.StateManager;
-import com.graphhopper.jsprit.core.algorithm.state.UpdateVariableCosts;
-import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
-import com.graphhopper.jsprit.core.problem.constraint.ConstraintManager;
-import com.graphhopper.jsprit.core.problem.io.VrpXMLReader;
-import com.graphhopper.jsprit.core.problem.solution.SolutionCostCalculator;
-import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
-import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
-import com.graphhopper.jsprit.core.problem.vehicle.InfiniteFleetManagerFactory;
-import com.graphhopper.jsprit.core.problem.vehicle.VehicleFleetManager;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import java.util.Collection;
-
-import static org.junit.Assert.assertTrue;
-
-
-public class BuildPDVRPWithShipmentsAlgoFromScratch_IT {
-
- @Test
- @Category(IntegrationTest.class)
- public void test() {
- VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(builder).read("src/test/resources/pdp.xml");
-
- VehicleRoutingProblem vrp = builder.build();
-
- final StateManager stateManager = new StateManager(vrp);
- stateManager.updateLoadStates();
-// stateManager.updateTimeWindowStates();
- stateManager.addStateUpdater(new UpdateVariableCosts(vrp.getActivityCosts(), vrp.getTransportCosts(), stateManager));
-
- ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager);
-// constraintManager.addTimeWindowConstraint();
- constraintManager.addLoadConstraint();
-
- VehicleFleetManager fleetManager = new InfiniteFleetManagerFactory(vrp.getVehicles()).createFleetManager();
-
- BestInsertionBuilder bestIBuilder = new BestInsertionBuilder(vrp, fleetManager, stateManager, constraintManager);
- InsertionStrategy bestInsertion = bestIBuilder.build();
-
-
- RuinStrategy radial = new RadialRuinStrategyFactory(0.3, new AvgServiceAndShipmentDistance(vrp.getTransportCosts())).createStrategy(vrp);
- RuinStrategy random = new RandomRuinStrategyFactory(0.5).createStrategy(vrp);
-
-
- SolutionCostCalculator solutionCostCalculator = new SolutionCostCalculator() {
-
- @Override
- public double getCosts(VehicleRoutingProblemSolution solution) {
- double costs = 0.0;
- for (VehicleRoute route : solution.getRoutes()) {
- costs += stateManager.getRouteState(route, InternalStates.COSTS, Double.class);
- }
- return costs;
- }
- };
-
- SearchStrategy randomStrategy = new SearchStrategy("random", new SelectBest(), new GreedyAcceptance(1), solutionCostCalculator);
- RuinAndRecreateModule randomModule = new RuinAndRecreateModule("randomRuin_bestInsertion", bestInsertion, random);
- randomStrategy.addModule(randomModule);
-
- SearchStrategy radialStrategy = new SearchStrategy("radial", new SelectBest(), new GreedyAcceptance(1), solutionCostCalculator);
- RuinAndRecreateModule radialModule = new RuinAndRecreateModule("radialRuin_bestInsertion", bestInsertion, radial);
- radialStrategy.addModule(radialModule);
-
- SearchStrategyManager strategyManager = new SearchStrategyManager();
- strategyManager.addStrategy(radialStrategy, 0.5);
- strategyManager.addStrategy(randomStrategy, 0.5);
-
- VehicleRoutingAlgorithm vra = new VehicleRoutingAlgorithm(vrp, strategyManager);
- vra.addListener(stateManager);
- vra.addListener(new RemoveEmptyVehicles(fleetManager));
-
- VehicleRoutingProblemSolution iniSolution = new InsertionInitialSolutionFactory(bestInsertion, solutionCostCalculator).createSolution(vrp);
- vra.addInitialSolution(iniSolution);
-
- vra.setMaxIterations(3);
- Collection solutions = vra.searchSolutions();
- assertTrue(!solutions.isEmpty());
- }
-
-
-}
diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/CVRPwithDeliveriesAndDifferentInsertionStrategies_IT.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/CVRPwithDeliveriesAndDifferentInsertionStrategies_IT.java
deleted file mode 100644
index 2ea8caf3..00000000
--- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/CVRPwithDeliveriesAndDifferentInsertionStrategies_IT.java
+++ /dev/null
@@ -1,64 +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 com.graphhopper.jsprit.core.algorithm;
-
-import com.graphhopper.jsprit.core.IntegrationTest;
-import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
-import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
-import com.graphhopper.jsprit.core.problem.io.VrpXMLReader;
-import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
-import junit.framework.Assert;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-
-import java.util.Collection;
-
-public class CVRPwithDeliveriesAndDifferentInsertionStrategies_IT {
-
- @Test
- @Category(IntegrationTest.class)
- public void whenWithTwoInsertionStrategiesWhereOnleOneIsInAlgo_itShouldWork() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
- VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig_greedyWithRegret.xml");
- vra.setMaxIterations(10);
- try {
- Collection solutions = vra.searchSolutions();
- Assert.assertTrue(true);
- } catch (Exception e) {
- Assert.assertTrue(false);
- }
- }
-
- @Test
- @Category(IntegrationTest.class)
- public void whenWithTwoInsertionStrategiesWhereBothAreInAlgo_itShouldWork() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
- VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig_greedyWithRegret_v2.xml");
- vra.setMaxIterations(10);
- try {
- Collection solutions = vra.searchSolutions();
- Assert.assertTrue(true);
- } catch (Exception e) {
- Assert.assertTrue(false);
- }
- }
-
-}
diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/CVRPwithDeliveries_IT.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/CVRPwithDeliveries_IT.java
index 11569adf..7695649e 100644
--- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/CVRPwithDeliveries_IT.java
+++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/CVRPwithDeliveries_IT.java
@@ -18,10 +18,10 @@ package com.graphhopper.jsprit.core.algorithm;
import com.graphhopper.jsprit.core.IntegrationTest;
import com.graphhopper.jsprit.core.algorithm.box.Jsprit;
-import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
-import com.graphhopper.jsprit.core.problem.io.VrpXMLReader;
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
+import com.graphhopper.jsprit.core.util.ChristofidesReader;
+import com.graphhopper.jsprit.core.util.JobType;
import com.graphhopper.jsprit.core.util.Solutions;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -32,23 +32,11 @@ import static org.junit.Assert.assertEquals;
public class CVRPwithDeliveries_IT {
- @Test
- @Category(IntegrationTest.class)
- public void whenSolvingVRPNC1withDeliveries_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
- VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml");
- Collection solutions = vra.searchSolutions();
- assertEquals(530.0, Solutions.bestOf(solutions).getCost(), 50.0);
- assertEquals(5, Solutions.bestOf(solutions).getRoutes().size());
- }
-
@Test
@Category(IntegrationTest.class)
public void whenSolvingVRPNC1withDeliveriesWithJsprit_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml");
+ new ChristofidesReader(vrpBuilder).setJobType(JobType.DELIVERY).read(getClass().getResourceAsStream("vrpnc1.txt"));
VehicleRoutingProblem vrp = vrpBuilder.build();
VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
Collection solutions = vra.searchSolutions();
diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/CVRPwithMatrix_IT.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/CVRPwithMatrix_IT.java
index 379bc3f5..8c597a09 100644
--- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/CVRPwithMatrix_IT.java
+++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/CVRPwithMatrix_IT.java
@@ -17,20 +17,17 @@
package com.graphhopper.jsprit.core.algorithm;
import com.graphhopper.jsprit.core.IntegrationTest;
-import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
+import com.graphhopper.jsprit.core.algorithm.box.Jsprit;
import com.graphhopper.jsprit.core.analysis.SolutionAnalyser;
import com.graphhopper.jsprit.core.problem.Location;
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
import com.graphhopper.jsprit.core.problem.cost.TransportDistance;
-import com.graphhopper.jsprit.core.problem.io.VrpXMLReader;
import com.graphhopper.jsprit.core.problem.job.Job;
import com.graphhopper.jsprit.core.problem.job.Service;
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl;
-import com.graphhopper.jsprit.core.util.EuclideanDistanceCalculator;
-import com.graphhopper.jsprit.core.util.FastVehicleRoutingTransportCostsMatrix;
-import com.graphhopper.jsprit.core.util.Solutions;
+import com.graphhopper.jsprit.core.util.*;
import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -50,10 +47,10 @@ public class CVRPwithMatrix_IT {
@Category(IntegrationTest.class)
public void whenReturnToDepot_itShouldWorkWithMatrix() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml");
+ new ChristofidesReader(vrpBuilder).setJobType(JobType.DELIVERY).read(getClass().getResourceAsStream("vrpnc1.txt"));
VehicleRoutingProblem vrp_ = vrpBuilder.build();
VehicleRoutingProblem vrp = createVrpWithLocationIndecesAndMatrix(vrp_, true);
- VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml");
+ VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.FAST_REGRET,"true").buildAlgorithm();
Collection solutions = vra.searchSolutions();
Assert.assertEquals(530.0, Solutions.bestOf(solutions).getCost(), 50.0);
assertEquals(5, Solutions.bestOf(solutions).getRoutes().size());
@@ -63,10 +60,10 @@ public class CVRPwithMatrix_IT {
@Category(IntegrationTest.class)
public void whenNotReturnToDepot_itShouldWorkWithMatrix() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml");
+ new ChristofidesReader(vrpBuilder).setJobType(JobType.DELIVERY).read(getClass().getResourceAsStream("vrpnc1.txt"));
VehicleRoutingProblem vrp_ = vrpBuilder.build();
VehicleRoutingProblem vrp = createVrpWithLocationIndecesAndMatrix(vrp_, false);
- VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml");
+ VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.FAST_REGRET,"true").buildAlgorithm();
try {
Collection solutions = vra.searchSolutions();
assertTrue(true);
@@ -79,10 +76,10 @@ public class CVRPwithMatrix_IT {
@Category(IntegrationTest.class)
public void whenCalcTimeWithSolutionAnalyser_itShouldWork() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml");
+ new ChristofidesReader(vrpBuilder).setJobType(JobType.DELIVERY).read(getClass().getResourceAsStream("vrpnc1.txt"));
VehicleRoutingProblem vrp_ = vrpBuilder.build();
final VehicleRoutingProblem vrp = createVrpWithLocationIndecesAndMatrix(vrp_, false);
- VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml");
+ VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.FAST_REGRET,"true").buildAlgorithm();
Collection solutions = vra.searchSolutions();
SolutionAnalyser sa = new SolutionAnalyser(vrp, Solutions.bestOf(solutions), new TransportDistance() {
@Override
diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/CVRPwithPickups_IT.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/CVRPwithPickups_IT.java
index ccf2a7d9..9b02f7b8 100644
--- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/CVRPwithPickups_IT.java
+++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/CVRPwithPickups_IT.java
@@ -18,10 +18,10 @@ package com.graphhopper.jsprit.core.algorithm;
import com.graphhopper.jsprit.core.IntegrationTest;
import com.graphhopper.jsprit.core.algorithm.box.Jsprit;
-import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
-import com.graphhopper.jsprit.core.problem.io.VrpXMLReader;
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
+import com.graphhopper.jsprit.core.util.ChristofidesReader;
+import com.graphhopper.jsprit.core.util.JobType;
import com.graphhopper.jsprit.core.util.Solutions;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -36,22 +36,9 @@ public class CVRPwithPickups_IT {
@Category(IntegrationTest.class)
public void whenSolvingVRPNC1WithPickups_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-pickups.xml");
+ new ChristofidesReader(vrpBuilder).setJobType(JobType.PICKUP).read(getClass().getResourceAsStream("vrpnc1.txt"));
VehicleRoutingProblem vrp = vrpBuilder.build();
- VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml");
- Collection solutions = vra.searchSolutions();
- assertEquals(530.0, Solutions.bestOf(solutions).getCost(), 50.0);
- assertEquals(5, Solutions.bestOf(solutions).getRoutes().size());
- }
-
- @Test
- @Category(IntegrationTest.class)
- public void whenSolvingVRPNC1WithPickupsWithJsprit_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-pickups.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
- VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
- vra.setMaxIterations(1000);
+ VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.FAST_REGRET,"true").buildAlgorithm();
Collection solutions = vra.searchSolutions();
assertEquals(530.0, Solutions.bestOf(solutions).getCost(), 50.0);
assertEquals(5, Solutions.bestOf(solutions).getRoutes().size());
diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/DeactivateTimeWindowsTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/DeactivateTimeWindowsTest.java
index d3f631e5..d9e56d01 100644
--- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/DeactivateTimeWindowsTest.java
+++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/DeactivateTimeWindowsTest.java
@@ -18,6 +18,7 @@
package com.graphhopper.jsprit.core.algorithm;
+import com.graphhopper.jsprit.core.algorithm.box.Jsprit;
import com.graphhopper.jsprit.core.algorithm.state.StateManager;
import com.graphhopper.jsprit.core.problem.Location;
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
@@ -29,57 +30,27 @@ import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl;
import com.graphhopper.jsprit.core.util.Solutions;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
import java.util.Collection;
public class DeactivateTimeWindowsTest {
- @Test
- public void activityTimesShouldIgnoreTimeWindows() {
+ VehicleRoutingProblem vrp;
+
+ @Before
+ public void doBefore(){
Service service = Service.Builder.newInstance("s").setLocation(Location.newInstance(20, 0))
.setTimeWindow(TimeWindow.newInstance(40, 50)).build();
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build();
- VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(service).addVehicle(vehicle).build();
- VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp, "src/test/resources/algorithmConfig.xml");
- vraBuilder.addDefaultCostCalculators();
- VehicleRoutingAlgorithm vra = vraBuilder.build(); //this should ignore any constraints
- vra.setMaxIterations(10);
- Collection solutions = vra.searchSolutions();
+ vrp = VehicleRoutingProblem.Builder.newInstance().addJob(service).addVehicle(vehicle).build();
- VehicleRoute route = Solutions.bestOf(solutions).getRoutes().iterator().next();
- Assert.assertEquals(20., route.getActivities().get(0).getEndTime(), 0.01);
- }
-
- @Test
- public void whenNotActivatingViaStateManager_activityTimesShouldConsiderTimeWindows() {
- Service service = Service.Builder.newInstance("s").setLocation(Location.newInstance(20, 0))
- .setTimeWindow(TimeWindow.newInstance(40, 50)).build();
- VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build();
- VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(service).addVehicle(vehicle).build();
- VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp, "src/test/resources/algorithmConfig.xml");
- vraBuilder.addDefaultCostCalculators();
- StateManager stateManager = new StateManager(vrp);
- ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager);
- vraBuilder.setStateAndConstraintManager(stateManager, constraintManager);
- VehicleRoutingAlgorithm vra = vraBuilder.build(); //this should ignore any constraints
- vra.setMaxIterations(10);
- Collection solutions = vra.searchSolutions();
-
- VehicleRoute route = Solutions.bestOf(solutions).getRoutes().iterator().next();
- Assert.assertEquals(20., route.getActivities().get(0).getEndTime(), 0.01);
}
@Test
public void activityTimesShouldConsiderTimeWindows() {
- Service service = Service.Builder.newInstance("s").setLocation(Location.newInstance(20, 0))
- .setTimeWindow(TimeWindow.newInstance(40, 50)).build();
- VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build();
- VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(service).addVehicle(vehicle).build();
- VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp, "src/test/resources/algorithmConfig.xml");
- vraBuilder.addCoreConstraints();
- vraBuilder.addDefaultCostCalculators();
- VehicleRoutingAlgorithm vra = vraBuilder.build(); //this should ignore any constraints
+ VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp); //this should ignore any constraints
vra.setMaxIterations(10);
Collection solutions = vra.searchSolutions();
@@ -89,18 +60,13 @@ public class DeactivateTimeWindowsTest {
@Test
public void whenActivatingViaStateManager_activityTimesShouldConsiderTimeWindows() {
- Service service = Service.Builder.newInstance("s").setLocation(Location.newInstance(20, 0))
- .setTimeWindow(TimeWindow.newInstance(40, 50)).build();
- VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build();
- VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(service).addVehicle(vehicle).build();
- VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(vrp, "src/test/resources/algorithmConfig.xml");
- vraBuilder.addDefaultCostCalculators();
StateManager stateManager = new StateManager(vrp);
stateManager.updateTimeWindowStates();
ConstraintManager constraintManager = new ConstraintManager(vrp, stateManager);
constraintManager.addTimeWindowConstraint();
- vraBuilder.setStateAndConstraintManager(stateManager, constraintManager);
- VehicleRoutingAlgorithm vra = vraBuilder.build(); //this should ignore any constraints
+
+ VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).addCoreStateAndConstraintStuff(true)
+ .setStateAndConstraintManager(stateManager,constraintManager).buildAlgorithm();
vra.setMaxIterations(10);
Collection solutions = vra.searchSolutions();
diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/ExternalInitialSolutionIsInValidTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/ExternalInitialSolutionIsInValidTest.java
index 393517c3..a5b0f8c7 100644
--- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/ExternalInitialSolutionIsInValidTest.java
+++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/ExternalInitialSolutionIsInValidTest.java
@@ -1,6 +1,6 @@
package com.graphhopper.jsprit.core.algorithm;
-import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
+import com.graphhopper.jsprit.core.algorithm.box.Jsprit;
import com.graphhopper.jsprit.core.problem.Location;
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
import com.graphhopper.jsprit.core.problem.job.Service;
@@ -27,7 +27,7 @@ public class ExternalInitialSolutionIsInValidTest {
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(s1).addJob(s2).addVehicle(vehicle).build();
- VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithm_without_construction.xml");
+ VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
/*
create ini sol
diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/InitialRoutesTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/InitialRoutesTest.java
index 2c592271..1e864c91 100644
--- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/InitialRoutesTest.java
+++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/InitialRoutesTest.java
@@ -25,13 +25,11 @@ import com.graphhopper.jsprit.core.algorithm.box.SchrimpfFactory;
import com.graphhopper.jsprit.core.algorithm.state.StateManager;
import com.graphhopper.jsprit.core.algorithm.state.UpdateEndLocationIfRouteIsOpen;
import com.graphhopper.jsprit.core.algorithm.state.UpdateVariableCosts;
-import com.graphhopper.jsprit.core.problem.AbstractActivity;
import com.graphhopper.jsprit.core.problem.Location;
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
import com.graphhopper.jsprit.core.problem.constraint.ConstraintManager;
import com.graphhopper.jsprit.core.problem.constraint.ServiceLoadActivityLevelConstraint;
import com.graphhopper.jsprit.core.problem.constraint.ServiceLoadRouteLevelConstraint;
-import com.graphhopper.jsprit.core.problem.io.VrpXMLReader;
import com.graphhopper.jsprit.core.problem.job.Job;
import com.graphhopper.jsprit.core.problem.job.Service;
import com.graphhopper.jsprit.core.problem.job.Shipment;
@@ -42,184 +40,56 @@ import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl;
import com.graphhopper.jsprit.core.problem.vehicle.VehicleType;
import com.graphhopper.jsprit.core.problem.vehicle.VehicleTypeImpl;
-import com.graphhopper.jsprit.core.reporting.SolutionPrinter;
import com.graphhopper.jsprit.core.util.Coordinate;
import com.graphhopper.jsprit.core.util.Solutions;
+import org.junit.Before;
import org.junit.Test;
import java.util.Collection;
-import java.util.List;
import static org.junit.Assert.*;
public class InitialRoutesTest {
- @Test
- public void whenReading_jobMapShouldOnlyContainJob2() {
+ private VehicleRoutingProblem vrp;
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
+ private VehicleRoute initialRoute;
- assertEquals(1, getNuServices(vrp));
- assertTrue(vrp.getJobs().containsKey("2"));
+ @Before
+ public void before(){
+ VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
+ VehicleImpl v = VehicleImpl.Builder.newInstance("veh1").setStartLocation(Location.newInstance(0,0)).setLatestArrival(48600).build();
+ Service s1 = Service.Builder.newInstance("s1").setLocation(Location.newInstance(1000,0)).build();
+ Service s2 = Service.Builder.newInstance("s2").setLocation(Location.newInstance(1000,1000)).build();
+ builder.addVehicle(v).addJob(s1).addJob(s2);
+ initialRoute = VehicleRoute.Builder.newInstance(v).addService(s1).build();
+ builder.addInitialVehicleRoute(initialRoute);
+ vrp = builder.build();
}
- @Test
- public void whenReadingProblem2_jobMapShouldContain_service2() {
-
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- assertEquals(1, getNuServices(vrp));
- assertTrue(vrp.getJobs().containsKey("2"));
- }
-
- @Test
- public void whenReading_jobMapShouldContain_shipment4() {
-
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- assertEquals(1, getNuShipments(vrp));
- assertTrue(vrp.getJobs().containsKey("4"));
- }
-
- private int getNuShipments(VehicleRoutingProblem vrp) {
- int nuShipments = 0;
- for (Job job : vrp.getJobs().values()) {
- if (job instanceof Shipment) nuShipments++;
- }
- return nuShipments;
- }
-
- private int getNuServices(VehicleRoutingProblem vrp) {
- int nuServices = 0;
- for (Job job : vrp.getJobs().values()) {
- if (job instanceof Service) nuServices++;
- }
- return nuServices;
- }
-
- @Test
- public void whenReading_thereShouldBeOnlyOneActAssociatedToJob2() {
-
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- assertEquals(1, vrp.getActivities(vrp.getJobs().get("2")).size());
- }
-
- @Test
- public void whenReading_thereShouldBeOnlyOneActAssociatedToJob2_v2() {
-
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- assertEquals(1, vrp.getActivities(vrp.getJobs().get("2")).size());
- }
-
- @Test
- public void whenReading_thereShouldBeTwoActsAssociatedToShipment4() {
-
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- Job job = vrp.getJobs().get("4");
- List activities = vrp.getActivities(job);
-
- assertEquals(2, activities.size());
- }
@Test
public void whenSolving_nuJobsInSolutionShouldBe2() {
-
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
+ VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
Collection solutions = vra.searchSolutions();
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
-
- SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE);
-
assertEquals(2, solution.getRoutes().iterator().next().getTourActivities().getJobs().size());
}
- @Test
- public void whenSolvingProblem2_nuJobsInSolutionShouldBe4() {
-
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
- Collection solutions = vra.searchSolutions();
- VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
-
- SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE);
-
- int jobsInSolution = 0;
- for (VehicleRoute r : solution.getRoutes()) {
- jobsInSolution += r.getTourActivities().jobSize();
- }
- assertEquals(4, jobsInSolution);
- }
-
@Test
public void whenSolving_nuActsShouldBe2() {
-
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
Collection solutions = vra.searchSolutions();
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
-
- SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE);
-
assertEquals(2, solution.getRoutes().iterator().next().getActivities().size());
}
- @Test
- public void whenSolvingProblem2_nuActsShouldBe6() {
-
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
- Collection solutions = vra.searchSolutions();
- VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
-
- int nuActs = 0;
- for (VehicleRoute r : solution.getRoutes()) {
- nuActs += r.getActivities().size();
- }
- assertEquals(6, nuActs);
- }
-
@Test
public void whenSolving_deliverService1_shouldBeInRoute() {
-
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
Collection solutions = vra.searchSolutions();
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
-
- SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE);
-
- Job job = getInitialJob("1", vrp);
+ Job job = getInitialJob("s1", vrp);
assertTrue(hasActivityIn(solution, "veh1", job));
}
@@ -232,63 +102,6 @@ public class InitialRoutesTest {
return null;
}
- @Test
- public void whenSolvingWithJsprit_deliverService1_shouldBeInRoute() {
-
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes_3.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
- Collection solutions = vra.searchSolutions();
- VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
-
- SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE);
-
- Job job = getInitialJob("1", vrp);
- assertTrue(hasActivityIn(solution, "veh1", job));
- }
-
- @Test
- public void whenSolvingProblem2With_deliverServices_and_allShipmentActs_shouldBeInRoute() {
-
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
- Collection solutions = vra.searchSolutions();
- VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
-
- assertTrue(hasActivityIn(solution.getRoutes(), "1"));
- assertTrue(hasActivityIn(solution.getRoutes(), "2"));
- assertTrue(hasActivityIn(solution.getRoutes(), "3"));
- assertTrue(hasActivityIn(solution.getRoutes(), "4"));
-
- assertTrue(hasActivityIn(solution, "veh1", getInitialJob("1", vrp)));
- assertTrue(hasActivityIn(solution, "veh2", getInitialJob("3", vrp)));
- }
-
- @Test
- public void whenSolvingProblem2WithJsprit_deliverServices_and_allShipmentActs_shouldBeInRoute() {
-
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
- Collection solutions = vra.searchSolutions();
- VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
-
- assertTrue(hasActivityIn(solution.getRoutes(), "1"));
- assertTrue(hasActivityIn(solution.getRoutes(), "2"));
- assertTrue(hasActivityIn(solution.getRoutes(), "3"));
- assertTrue(hasActivityIn(solution.getRoutes(), "4"));
-
- assertTrue(hasActivityIn(solution, "veh1", getInitialJob("1", vrp)));
- assertTrue(hasActivityIn(solution, "veh2", getInitialJob("3", vrp)));
- }
-
private boolean hasActivityIn(Collection routes, String jobId) {
boolean isInRoute = false;
for (VehicleRoute route : routes) {
@@ -326,16 +139,11 @@ public class InitialRoutesTest {
@Test
public void whenSolving_deliverService2_shouldBeInRoute() {
-
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
Collection solutions = vra.searchSolutions();
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
- assertTrue(hasActivityIn(solution.getRoutes().iterator().next(), "2"));
+ assertTrue(hasActivityIn(solution.getRoutes().iterator().next(), "s2"));
}
@Test
@@ -372,19 +180,6 @@ public class InitialRoutesTest {
}
- @Test
- public void whenReadingProblemFromFile_maxCapacityShouldNotBeExceeded() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes_2.xml");
- VehicleRoutingAlgorithm vra = new GreedySchrimpfFactory().createAlgorithm(vrpBuilder.build());
- vra.setMaxIterations(10);
-
- Collection solutions = vra.searchSolutions();
-
- assertFalse(secondActIsPickup(solutions));
-
- }
-
private boolean secondActIsPickup(Collection solutions) {
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
TourActivity secondAct = solution.getRoutes().iterator().next().getActivities().get(1);
diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/MeetTimeWindowConstraint_IT.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/MeetTimeWindowConstraint_IT.java
index 608aedde..5f1519fa 100644
--- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/MeetTimeWindowConstraint_IT.java
+++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/MeetTimeWindowConstraint_IT.java
@@ -18,27 +18,30 @@
******************************************************************************/
package com.graphhopper.jsprit.core.algorithm;
-import com.graphhopper.jsprit.core.algorithm.box.GreedySchrimpfFactory;
import com.graphhopper.jsprit.core.algorithm.box.Jsprit;
-import com.graphhopper.jsprit.core.algorithm.box.SchrimpfFactory;
-import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
import com.graphhopper.jsprit.core.algorithm.recreate.listener.JobInsertedListener;
import com.graphhopper.jsprit.core.algorithm.recreate.listener.VehicleSwitchedListener;
+import com.graphhopper.jsprit.core.problem.Location;
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
-import com.graphhopper.jsprit.core.problem.io.VrpXMLReader;
import com.graphhopper.jsprit.core.problem.job.Job;
+import com.graphhopper.jsprit.core.problem.job.Service;
+import com.graphhopper.jsprit.core.problem.job.Shipment;
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
+import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
+import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl;
+import com.graphhopper.jsprit.core.problem.vehicle.VehicleType;
+import com.graphhopper.jsprit.core.problem.vehicle.VehicleTypeImpl;
import com.graphhopper.jsprit.core.util.FastVehicleRoutingTransportCostsMatrix;
import com.graphhopper.jsprit.core.util.Solutions;
import org.junit.Assert;
+import org.junit.Before;
import org.junit.Test;
import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
import java.io.IOException;
+import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
@@ -48,26 +51,35 @@ import static org.junit.Assert.assertTrue;
public class MeetTimeWindowConstraint_IT {
+ VehicleRoutingProblem vrp;
+
+ @Before
+ public void doBefore(){
+ VehicleType type1 = VehicleTypeImpl.Builder.newInstance("5").build();
+ VehicleType type2 = VehicleTypeImpl.Builder.newInstance("3.5").build();
+ VehicleImpl vehicle1 = VehicleImpl.Builder.newInstance("21").setStartLocation(Location.newInstance(0,0))
+ .setEarliestStart(14400).setLatestArrival(46800).setType(type1).build();
+ VehicleImpl vehicle2 = VehicleImpl.Builder.newInstance("19").setStartLocation(Location.newInstance(0,0))
+ .setEarliestStart(39600).setLatestArrival(64800).setType(type2).build();
+ Service service1 = Service.Builder.newInstance("2").setLocation(Location.newInstance(2000, 0))
+ .setTimeWindow(TimeWindow.newInstance(54000,54000)).build();
+ Service service2 = Service.Builder.newInstance("1").setLocation(Location.newInstance(1000, 1000))
+ .setTimeWindow(TimeWindow.newInstance(19800,21600)).build();
+ vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(vehicle1).addVehicle(vehicle2)
+ .addJob(service1).addJob(service2).setFleetSize(VehicleRoutingProblem.FleetSize.FINITE).build();
+ }
+
@Test
public void whenEmployingVehicleWithDifferentWorkingShifts_nRoutesShouldBeCorrect() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
+ VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
vra.setMaxIterations(100);
Collection solutions = vra.searchSolutions();
-
Assert.assertEquals(2, Solutions.bestOf(solutions).getRoutes().size());
}
@Test
public void whenEmployingVehicleWithDifferentWorkingShifts_certainJobsCanNeverBeAssignedToCertainVehicles() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
+ VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
vra.setMaxIterations(100);
final List testFailed = new ArrayList();
vra.addListener(new JobInsertedListener() {
@@ -89,17 +101,12 @@ public class MeetTimeWindowConstraint_IT {
});
@SuppressWarnings("unused")
Collection solutions = vra.searchSolutions();
-
assertTrue(testFailed.isEmpty());
}
@Test
public void whenEmployingVehicleWithDifferentWorkingShifts_certainVehiclesCanNeverBeAssignedToCertainRoutes() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
+ VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
vra.setMaxIterations(100);
final List testFailed = new ArrayList();
vra.addListener(new VehicleSwitchedListener() {
@@ -133,11 +140,7 @@ public class MeetTimeWindowConstraint_IT {
@Test
public void whenEmployingVehicleWithDifferentWorkingShifts_job2CanNeverBeInVehicle21() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
+ VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
vra.setMaxIterations(100);
Collection solutions = vra.searchSolutions();
@@ -146,40 +149,24 @@ public class MeetTimeWindowConstraint_IT {
@Test
public void whenEmployingVehicleWithDifferentWorkingShifts_job1ShouldBeAssignedCorrectly() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
+ VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
vra.setMaxIterations(100);
Collection solutions = vra.searchSolutions();
-
-// assertEquals(2,Solutions.bestOf(solutions).getRoutes().size());
assertTrue(containsJob(vrp.getJobs().get("1"), getRoute("21", Solutions.bestOf(solutions))));
}
@Test
public void whenEmployingVehicleWithDifferentWorkingShifts_job2ShouldBeAssignedCorrectly() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
+ VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
vra.setMaxIterations(100);
Collection solutions = vra.searchSolutions();
-
-// assertEquals(2,Solutions.bestOf(solutions).getRoutes().size());
assertTrue(containsJob(vrp.getJobs().get("2"), getRoute("19", Solutions.bestOf(solutions))));
}
@Test
public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_nRoutesShouldBeCorrect() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml");
+ VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.VEHICLE_SWITCH,"false").buildAlgorithm();
vra.setMaxIterations(100);
Collection solutions = vra.searchSolutions();
@@ -188,11 +175,7 @@ public class MeetTimeWindowConstraint_IT {
@Test
public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_certainJobsCanNeverBeAssignedToCertainVehicles() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml");
+ VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.VEHICLE_SWITCH,"false").buildAlgorithm();
vra.setMaxIterations(100);
final List testFailed = new ArrayList();
vra.addListener(new JobInsertedListener() {
@@ -220,11 +203,7 @@ public class MeetTimeWindowConstraint_IT {
@Test
public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_certainVehiclesCanNeverBeAssignedToCertainRoutes() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml");
+ VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.VEHICLE_SWITCH,"false").buildAlgorithm();
vra.setMaxIterations(100);
final List testFailed = new ArrayList();
vra.addListener(new VehicleSwitchedListener() {
@@ -258,11 +237,7 @@ public class MeetTimeWindowConstraint_IT {
@Test
public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_job2CanNeverBeInVehicle21() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml");
+ VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.VEHICLE_SWITCH,"false").buildAlgorithm();
vra.setMaxIterations(100);
Collection solutions = vra.searchSolutions();
@@ -271,11 +246,7 @@ public class MeetTimeWindowConstraint_IT {
@Test
public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_job1ShouldBeAssignedCorrectly() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml");
+ VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.VEHICLE_SWITCH,"false").buildAlgorithm();
vra.setMaxIterations(100);
Collection solutions = vra.searchSolutions();
@@ -285,261 +256,7 @@ public class MeetTimeWindowConstraint_IT {
@Test
public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_job2ShouldBeAssignedCorrectly() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/schrimpf_vehicleSwitchNotAllowed.xml");
- vra.setMaxIterations(100);
- Collection solutions = vra.searchSolutions();
-
- assertEquals(2, Solutions.bestOf(solutions).getRoutes().size());
- assertTrue(containsJob(vrp.getJobs().get("2"), getRoute("19", Solutions.bestOf(solutions))));
- }
-
-
- @Test
- public void whenEmployingVehicleWithDifferentWorkingShifts_jsprit_nRoutesShouldBeCorrect() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
- vra.setMaxIterations(100);
- Collection solutions = vra.searchSolutions();
-
- assertEquals(2, Solutions.bestOf(solutions).getRoutes().size());
- }
-
- @Test
- public void whenEmployingVehicleWithDifferentWorkingShifts_jsprit_certainJobsCanNeverBeAssignedToCertainVehicles() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
- vra.setMaxIterations(100);
- final List testFailed = new ArrayList();
- vra.addListener(new JobInsertedListener() {
-
- @Override
- public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) {
- if (job2insert.getId().equals("1")) {
- if (inRoute.getVehicle().getId().equals("19")) {
- testFailed.add(true);
- }
- }
- if (job2insert.getId().equals("2")) {
- if (inRoute.getVehicle().getId().equals("21")) {
- testFailed.add(true);
- }
- }
- }
-
- });
- @SuppressWarnings("unused")
- Collection solutions = vra.searchSolutions();
-
- assertTrue(testFailed.isEmpty());
- }
-
- @Test
- public void whenEmployingVehicleWithDifferentWorkingShifts_jsprit_certainVehiclesCanNeverBeAssignedToCertainRoutes() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
- vra.setMaxIterations(100);
- final List testFailed = new ArrayList();
- vra.addListener(new VehicleSwitchedListener() {
-
- @Override
- public void vehicleSwitched(VehicleRoute vehicleRoute, Vehicle oldVehicle, Vehicle newVehicle) {
- if (oldVehicle == null) return;
- if (oldVehicle.getId().equals("21") && newVehicle.getId().equals("19")) {
- for (Job j : vehicleRoute.getTourActivities().getJobs()) {
- if (j.getId().equals("1")) {
- testFailed.add(true);
- }
- }
- }
- if (oldVehicle.getId().equals("19") && newVehicle.getId().equals("21")) {
- for (Job j : vehicleRoute.getTourActivities().getJobs()) {
- if (j.getId().equals("2")) {
- testFailed.add(true);
- }
- }
- }
- }
-
- });
-
-
- @SuppressWarnings("unused")
- Collection solutions = vra.searchSolutions();
- assertTrue(testFailed.isEmpty());
- }
-
- @Test
- public void whenEmployingVehicleWithDifferentWorkingShifts_jsprit_job2CanNeverBeInVehicle21() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
- vra.setMaxIterations(100);
- Collection solutions = vra.searchSolutions();
-
- assertEquals(2, Solutions.bestOf(solutions).getRoutes().size());
- }
-
- @Test
- public void whenEmployingVehicleWithDifferentWorkingShifts_jsprit_job1ShouldBeAssignedCorrectly() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
- vra.setMaxIterations(100);
- Collection solutions = vra.searchSolutions();
-
-// assertEquals(2,Solutions.bestOf(solutions).getRoutes().size());
- assertTrue(containsJob(vrp.getJobs().get("1"), getRoute("21", Solutions.bestOf(solutions))));
- }
-
- @Test
- public void whenEmployingVehicleWithDifferentWorkingShifts_jsprit_job2ShouldBeAssignedCorrectly() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
- vra.setMaxIterations(100);
- Collection solutions = vra.searchSolutions();
-
-// assertEquals(2,Solutions.bestOf(solutions).getRoutes().size());
- assertTrue(containsJob(vrp.getJobs().get("2"), getRoute("19", Solutions.bestOf(solutions))));
- }
-
-
- @Test
- public void whenEmployingVehicleWithDifferentWorkingShifts_jsprit_and_vehicleSwitchIsNotAllowed_nRoutesShouldBeCorrect() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.VEHICLE_SWITCH, "false").buildAlgorithm();
- vra.setMaxIterations(100);
- Collection solutions = vra.searchSolutions();
-
- assertEquals(2, Solutions.bestOf(solutions).getRoutes().size());
- }
-
- @Test
- public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_jsprit_certainJobsCanNeverBeAssignedToCertainVehicles() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.VEHICLE_SWITCH, "false").buildAlgorithm();
- vra.setMaxIterations(100);
- final List testFailed = new ArrayList();
- vra.addListener(new JobInsertedListener() {
-
- @Override
- public void informJobInserted(Job job2insert, VehicleRoute inRoute, double additionalCosts, double additionalTime) {
- if (job2insert.getId().equals("1")) {
- if (inRoute.getVehicle().getId().equals("19")) {
- testFailed.add(true);
- }
- }
- if (job2insert.getId().equals("2")) {
- if (inRoute.getVehicle().getId().equals("21")) {
- testFailed.add(true);
- }
- }
- }
-
- });
- @SuppressWarnings("unused")
- Collection solutions = vra.searchSolutions();
-
- assertTrue(testFailed.isEmpty());
- }
-
- @Test
- public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_jsprit_certainVehiclesCanNeverBeAssignedToCertainRoutes() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.VEHICLE_SWITCH, "false").buildAlgorithm();
- vra.setMaxIterations(100);
- final List testFailed = new ArrayList();
- vra.addListener(new VehicleSwitchedListener() {
-
- @Override
- public void vehicleSwitched(VehicleRoute vehicleRoute, Vehicle oldVehicle, Vehicle newVehicle) {
- if (oldVehicle == null) return;
- if (oldVehicle.getId().equals("21") && newVehicle.getId().equals("19")) {
- for (Job j : vehicleRoute.getTourActivities().getJobs()) {
- if (j.getId().equals("1")) {
- testFailed.add(true);
- }
- }
- }
- if (oldVehicle.getId().equals("19") && newVehicle.getId().equals("21")) {
- for (Job j : vehicleRoute.getTourActivities().getJobs()) {
- if (j.getId().equals("2")) {
- testFailed.add(true);
- }
- }
- }
- }
-
- });
-
-
- @SuppressWarnings("unused")
- Collection solutions = vra.searchSolutions();
- assertTrue(testFailed.isEmpty());
- }
-
- @Test
- public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_jsprit_job2CanNeverBeInVehicle21() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.VEHICLE_SWITCH, "false").buildAlgorithm();
- vra.setMaxIterations(100);
- Collection solutions = vra.searchSolutions();
-
- assertEquals(2, Solutions.bestOf(solutions).getRoutes().size());
- }
-
- @Test
- public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_jsprit_job1ShouldBeAssignedCorrectly() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.VEHICLE_SWITCH, "false").buildAlgorithm();
- vra.setMaxIterations(100);
- Collection solutions = vra.searchSolutions();
-
- assertEquals(2, Solutions.bestOf(solutions).getRoutes().size());
- assertTrue(containsJob(vrp.getJobs().get("1"), getRoute("21", Solutions.bestOf(solutions))));
- }
-
- @Test
- public void whenEmployingVehicleWithDifferentWorkingShifts_and_vehicleSwitchIsNotAllowed_jsprit_job2ShouldBeAssignedCorrectly() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.VEHICLE_SWITCH, "false").buildAlgorithm();
+ VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.VEHICLE_SWITCH,"false").buildAlgorithm();
vra.setMaxIterations(100);
Collection solutions = vra.searchSolutions();
@@ -549,12 +266,8 @@ public class MeetTimeWindowConstraint_IT {
@Test
public void whenUsingJsprit_driverTimesShouldBeMet() throws IOException {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/twbug.xml");
- final FastVehicleRoutingTransportCostsMatrix matrix = createMatrix();
- vrpBuilder.setRoutingCost(matrix);
- VehicleRoutingProblem vrp = vrpBuilder.build();
- VehicleRoutingAlgorithm algorithm = Jsprit.Builder.newInstance(vrp).buildAlgorithm();
+ VehicleRoutingProblem vrp = createTWBugProblem();
+ VehicleRoutingAlgorithm algorithm = Jsprit.createAlgorithm(vrp);
algorithm.setMaxIterations(1000);
VehicleRoutingProblemSolution solution = Solutions.bestOf(algorithm.searchSolutions());
for (VehicleRoute r : solution.getRoutes()) {
@@ -563,41 +276,8 @@ public class MeetTimeWindowConstraint_IT {
}
}
- @Test
- public void whenUsingSchrimpf_driverTimesShouldBeMet() throws IOException {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/twbug.xml");
- final FastVehicleRoutingTransportCostsMatrix matrix = createMatrix();
- vrpBuilder.setRoutingCost(matrix);
- VehicleRoutingProblem vrp = vrpBuilder.build();
- VehicleRoutingAlgorithm algorithm = new SchrimpfFactory().createAlgorithm(vrp);
- algorithm.setMaxIterations(1000);
- VehicleRoutingProblemSolution solution = Solutions.bestOf(algorithm.searchSolutions());
- for (VehicleRoute r : solution.getRoutes()) {
- assertTrue(r.getVehicle().getEarliestDeparture() <= r.getDepartureTime());
- assertTrue(r.getVehicle().getLatestArrival() >= r.getEnd().getArrTime());
- }
- }
-
- @Test
- public void whenUsingGreedySchrimpf_driverTimesShouldBeMet() throws IOException {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/twbug.xml");
- final FastVehicleRoutingTransportCostsMatrix matrix = createMatrix();
- vrpBuilder.setRoutingCost(matrix);
- VehicleRoutingProblem vrp = vrpBuilder.build();
- VehicleRoutingAlgorithm algorithm = new GreedySchrimpfFactory().createAlgorithm(vrp);
- algorithm.setMaxIterations(1000);
- VehicleRoutingProblemSolution solution = Solutions.bestOf(algorithm.searchSolutions());
- for (VehicleRoute r : solution.getRoutes()) {
- assertTrue(r.getVehicle().getEarliestDeparture() <= r.getDepartureTime());
- assertTrue(r.getVehicle().getLatestArrival() >= r.getEnd().getArrTime());
- }
- }
-
-
private FastVehicleRoutingTransportCostsMatrix createMatrix() throws IOException {
- BufferedReader reader = new BufferedReader(new FileReader(new File("src/test/resources/matrix.txt")));
+ BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("matrix.txt")));
String line;
FastVehicleRoutingTransportCostsMatrix.Builder builder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(11, false);
while ((line = reader.readLine()) != null) {
@@ -628,4 +308,75 @@ public class MeetTimeWindowConstraint_IT {
return null;
}
+ private VehicleRoutingProblem createTWBugProblem() throws IOException {
+ VehicleType type = VehicleTypeImpl.Builder.newInstance("type").addCapacityDimension(0,20)
+ .setCostPerTransportTime(1.).setCostPerDistance(0).build();
+ VehicleImpl v0 = VehicleImpl.Builder.newInstance("vehicle0").setStartLocation(Location.newInstance(0))
+ .setEarliestStart(60).setLatestArrival(18060).setType(type).build();
+ VehicleImpl v1 = VehicleImpl.Builder.newInstance("vehicle1").setStartLocation(Location.newInstance(0))
+ .setEarliestStart(60).setLatestArrival(18060).setType(type).build();
+ VehicleImpl v2 = VehicleImpl.Builder.newInstance("vehicle2").setStartLocation(Location.newInstance(0))
+ .setEarliestStart(7200).setLatestArrival(36060).setType(type).build();
+ VehicleImpl v3 = VehicleImpl.Builder.newInstance("vehicle3").setStartLocation(Location.newInstance(0))
+ .setEarliestStart(36000).setLatestArrival(54060).setType(type).build();
+ VehicleImpl v4 = VehicleImpl.Builder.newInstance("vehicle4").setStartLocation(Location.newInstance(0))
+ .setEarliestStart(36000).setLatestArrival(54060).setType(type).build();
+
+ Service s1 = Service.Builder.newInstance("1").setLocation(Location.Builder.newInstance().setIndex(1).setId("js0").build())
+ .setServiceTime(600).setTimeWindow(TimeWindow.newInstance(0,1800)).addSizeDimension(0,1).build();
+ Service s2 = Service.Builder.newInstance("2").setLocation(Location.Builder.newInstance().setIndex(2).setId("js2").build())
+ .setServiceTime(600).setTimeWindow(TimeWindow.newInstance(5400, 7200)).addSizeDimension(0, 2).build();
+ Service s3 = Service.Builder.newInstance("3").setLocation(Location.Builder.newInstance().setIndex(3).setId("js5").build())
+ .setServiceTime(1800).setTimeWindow(TimeWindow.newInstance(17100, 18000)).addSizeDimension(0, 10).build();
+ Service s4 = Service.Builder.newInstance("4").setLocation(Location.Builder.newInstance().setIndex(4).setId("js4").build())
+ .setServiceTime(900).addSizeDimension(0, 2).build();
+ Service s5 = Service.Builder.newInstance("5").setLocation(Location.Builder.newInstance().setIndex(5).setId("js8").build())
+ .setServiceTime(600).addSizeDimension(0, 4).build();
+ Service s6 = Service.Builder.newInstance("6").setLocation(Location.Builder.newInstance().setIndex(6).setId("js10").build())
+ .setServiceTime(1500).setTimeWindow(TimeWindow.newInstance(29700,32400)).addSizeDimension(0, 10).build();
+ Service s7 = Service.Builder.newInstance("7").setLocation(Location.Builder.newInstance().setIndex(7).setId("jsp3").build())
+ .setServiceTime(5594).build();
+
+ Shipment shipment1 = Shipment.Builder.newInstance("shipment1")
+ .setPickupServiceTime(900)
+ .setPickupLocation(Location.Builder.newInstance().setId("jsp1").setIndex(1).build())
+ .setDeliveryLocation(Location.Builder.newInstance().setId("jsd1").setIndex(8).build())
+ .setDeliveryServiceTime(900).build();
+
+ Shipment shipment2 = Shipment.Builder.newInstance("shipment2")
+ .setPickupLocation(Location.Builder.newInstance().setId("jsp4").setIndex(9).build())
+ .setPickupServiceTime(1200)
+ .addPickupTimeWindow(21600,23400)
+ .setDeliveryLocation(Location.Builder.newInstance().setId("jsd4").setIndex(8).build())
+ .setDeliveryServiceTime(900)
+ .addDeliveryTimeWindow(25200,27000)
+ .build();
+
+ Shipment shipment3 = Shipment.Builder.newInstance("shipment3")
+ .setPickupLocation(Location.Builder.newInstance().setId("jsp7").setIndex(9).build())
+ .setPickupServiceTime(1200)
+ .addPickupTimeWindow(37800,41400)
+ .setDeliveryLocation(Location.Builder.newInstance().setId("jsd7").setIndex(8).build())
+ .setDeliveryServiceTime(1800)
+ .addDeliveryTimeWindow(43200,45900)
+ .build();
+
+ Shipment shipment4 = Shipment.Builder.newInstance("shipment4")
+ .setPickupLocation(Location.Builder.newInstance().setId("jsp9").setIndex(10).build())
+ .setPickupServiceTime(300)
+ .addPickupTimeWindow(45000,48600)
+ .setDeliveryLocation(Location.Builder.newInstance().setId("jsd9").setIndex(8).build())
+ .setDeliveryServiceTime(300)
+ .addDeliveryTimeWindow(50400,52200)
+ .build();
+
+ FastVehicleRoutingTransportCostsMatrix matrix = createMatrix();
+ return VehicleRoutingProblem.Builder.newInstance().setFleetSize(VehicleRoutingProblem.FleetSize.FINITE)
+ .addJob(s1).addJob(s2).addJob(s3).addJob(s4).addJob(s5).addJob(s6).addJob(s7)
+ .addJob(shipment1).addJob(shipment2).addJob(shipment3).addJob(shipment4)
+ .addVehicle(v0).addVehicle(v1).addVehicle(v2).addVehicle(v3).addVehicle(v4)
+ .setRoutingCost(matrix).build();
+
+ }
+
}
diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/PickupsAndDeliveries_IT.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/PickupsAndDeliveries_IT.java
index e8fe1c65..7de4d17f 100644
--- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/PickupsAndDeliveries_IT.java
+++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/PickupsAndDeliveries_IT.java
@@ -20,10 +20,9 @@ package com.graphhopper.jsprit.core.algorithm;
import com.graphhopper.jsprit.core.IntegrationTest;
import com.graphhopper.jsprit.core.algorithm.box.Jsprit;
-import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
-import com.graphhopper.jsprit.core.problem.io.VrpXMLReader;
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
+import com.graphhopper.jsprit.core.util.LiLimReader;
import com.graphhopper.jsprit.core.util.Solutions;
import org.junit.Test;
import org.junit.experimental.categories.Category;
@@ -38,22 +37,9 @@ public class PickupsAndDeliveries_IT {
@Category(IntegrationTest.class)
public void whenSolvingLR101InstanceOfLiLim_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/lilim_lr101.xml");
+ new LiLimReader(vrpBuilder).read(getClass().getResourceAsStream("lr101.txt"));
VehicleRoutingProblem vrp = vrpBuilder.build();
- VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/lilim_algorithmConfig.xml");
- Collection solutions = vra.searchSolutions();
- assertEquals(1650.8, Solutions.bestOf(solutions).getCost(), 80.);
- assertEquals(19, Solutions.bestOf(solutions).getRoutes().size(), 1);
- }
-
- @Test
- @Category(IntegrationTest.class)
- public void whenSolvingLR101InstanceOfLiLim_withJsprit_solutionsMustNoBeWorseThan5PercentOfBestKnownSolution() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/lilim_lr101.xml");
- VehicleRoutingProblem vrp = vrpBuilder.build();
- VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(vrp);
- vra.setMaxIterations(1000);
+ VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.FAST_REGRET,"true").buildAlgorithm();
Collection solutions = vra.searchSolutions();
assertEquals(1650.8, Solutions.bestOf(solutions).getCost(), 80.);
assertEquals(19, Solutions.bestOf(solutions).getRoutes().size(), 1);
diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_IT.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_IT.java
index 4421f674..686de826 100644
--- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_IT.java
+++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_IT.java
@@ -31,7 +31,10 @@ import com.graphhopper.jsprit.core.util.VehicleRoutingTransportCostsMatrix;
import org.junit.Test;
import org.junit.experimental.categories.Category;
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStreamReader;
import java.util.Collection;
import static org.junit.Assert.assertEquals;
@@ -39,65 +42,6 @@ import static org.junit.Assert.assertEquals;
public class RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_IT {
- static class RelationKey {
-
- static RelationKey newKey(String from, String to) {
- int fromInt = Integer.parseInt(from);
- int toInt = Integer.parseInt(to);
- if (fromInt < toInt) {
- return new RelationKey(from, to);
- } else {
- return new RelationKey(to, from);
- }
- }
-
- final String from;
- final String to;
-
- public RelationKey(String from, String to) {
- super();
- this.from = from;
- this.to = to;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((from == null) ? 0 : from.hashCode());
- result = prime * result + ((to == null) ? 0 : to.hashCode());
- return result;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- RelationKey other = (RelationKey) obj;
- if (from == null) {
- if (other.from != null)
- return false;
- } else if (!from.equals(other.from))
- return false;
- if (to == null) {
- if (other.to != null)
- return false;
- } else if (!to.equals(other.to))
- return false;
- return true;
- }
- }
-
@Test
@Category(IntegrationTest.class)
public void testAlgo() {
@@ -152,8 +96,8 @@ public class RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_IT {
}
- private static void readDemandQuantities(VehicleRoutingProblem.Builder vrpBuilder) throws FileNotFoundException, IOException {
- BufferedReader reader = new BufferedReader(new FileReader(new File("src/test/resources/refuseCollectionExample_Quantities")));
+ private void readDemandQuantities(VehicleRoutingProblem.Builder vrpBuilder) throws IOException {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("refuseCollectionExample_Quantities")));
String line = null;
boolean firstLine = true;
while ((line = reader.readLine()) != null) {
@@ -176,8 +120,8 @@ public class RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_IT {
}
- private static void readDistances(VehicleRoutingTransportCostsMatrix.Builder matrixBuilder) throws IOException {
- BufferedReader reader = new BufferedReader(new FileReader(new File("src/test/resources/refuseCollectionExample_Distances")));
+ private void readDistances(VehicleRoutingTransportCostsMatrix.Builder matrixBuilder) throws IOException {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("refuseCollectionExample_Distances")));
String line = null;
boolean firstLine = true;
while ((line = reader.readLine()) != null) {
diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_withTimeAndDistanceCosts_IT.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_withTimeAndDistanceCosts_IT.java
index 4fe337f2..c634e86c 100644
--- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_withTimeAndDistanceCosts_IT.java
+++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_withTimeAndDistanceCosts_IT.java
@@ -33,7 +33,10 @@ import com.graphhopper.jsprit.core.util.VehicleRoutingTransportCostsMatrix;
import org.junit.Test;
import org.junit.experimental.categories.Category;
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStreamReader;
import java.util.Collection;
import static org.junit.Assert.assertEquals;
@@ -41,65 +44,6 @@ import static org.junit.Assert.assertEquals;
public class RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_withTimeAndDistanceCosts_IT {
- static class RelationKey {
-
- static RelationKey newKey(String from, String to) {
- int fromInt = Integer.parseInt(from);
- int toInt = Integer.parseInt(to);
- if (fromInt < toInt) {
- return new RelationKey(from, to);
- } else {
- return new RelationKey(to, from);
- }
- }
-
- final String from;
- final String to;
-
- public RelationKey(String from, String to) {
- super();
- this.from = from;
- this.to = to;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#hashCode()
- */
- @Override
- public int hashCode() {
- final int prime = 31;
- int result = 1;
- result = prime * result + ((from == null) ? 0 : from.hashCode());
- result = prime * result + ((to == null) ? 0 : to.hashCode());
- return result;
- }
-
- /* (non-Javadoc)
- * @see java.lang.Object#equals(java.lang.Object)
- */
- @Override
- public boolean equals(Object obj) {
- if (this == obj)
- return true;
- if (obj == null)
- return false;
- if (getClass() != obj.getClass())
- return false;
- RelationKey other = (RelationKey) obj;
- if (from == null) {
- if (other.from != null)
- return false;
- } else if (!from.equals(other.from))
- return false;
- if (to == null) {
- if (other.to != null)
- return false;
- } else if (!to.equals(other.to))
- return false;
- return true;
- }
- }
-
@Test
@Category(IntegrationTest.class)
public void testAlgo() {
@@ -154,8 +98,8 @@ public class RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_withTimeAndD
}
- private static void readDemandQuantities(VehicleRoutingProblem.Builder vrpBuilder) throws FileNotFoundException, IOException {
- BufferedReader reader = new BufferedReader(new FileReader(new File("src/test/resources/refuseCollectionExample_Quantities")));
+ private void readDemandQuantities(VehicleRoutingProblem.Builder vrpBuilder) throws IOException {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("refuseCollectionExample_Quantities")));
String line = null;
boolean firstLine = true;
while ((line = reader.readLine()) != null) {
@@ -178,8 +122,8 @@ public class RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_withTimeAndD
}
- private static void readDistances(VehicleRoutingTransportCostsMatrix.Builder matrixBuilder) throws IOException {
- BufferedReader reader = new BufferedReader(new FileReader(new File("src/test/resources/refuseCollectionExample_Distances")));
+ private void readDistances(VehicleRoutingTransportCostsMatrix.Builder matrixBuilder) throws IOException {
+ BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream("refuseCollectionExample_Distances")));
String line = null;
boolean firstLine = true;
while ((line = reader.readLine()) != null) {
diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/RefuseCollection_IT.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/RefuseCollection_IT.java
index 44ebe782..c6881044 100644
--- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/RefuseCollection_IT.java
+++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/RefuseCollection_IT.java
@@ -35,7 +35,10 @@ import org.junit.Assert;
import org.junit.Test;
import org.junit.experimental.categories.Category;
-import java.io.*;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.Reader;
import java.util.Collection;
@@ -223,8 +226,8 @@ public class RefuseCollection_IT {
}
- private static void readDemandQuantitiesAsServices(VehicleRoutingProblem.Builder vrpBuilder) {
- BufferedReader reader = getBufferedReader("src/test/resources/refuseCollectionExample_Quantities");
+ private void readDemandQuantitiesAsServices(VehicleRoutingProblem.Builder vrpBuilder) {
+ BufferedReader reader = getBufferedReader("refuseCollectionExample_Quantities");
String line;
boolean firstLine = true;
while ((line = readLine(reader)) != null) {
@@ -246,18 +249,12 @@ public class RefuseCollection_IT {
close(reader);
}
- private static BufferedReader getBufferedReader(String s) {
- BufferedReader reader = null;
- try {
- reader = new BufferedReader(new FileReader(new File(s)));
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- }
- return reader;
+ private BufferedReader getBufferedReader(String s) {
+ return new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(s)));
}
- private static void readDemandQuantitiesAsPickups(VehicleRoutingProblem.Builder vrpBuilder) {
- BufferedReader reader = getBufferedReader("src/test/resources/refuseCollectionExample_Quantities");
+ private void readDemandQuantitiesAsPickups(VehicleRoutingProblem.Builder vrpBuilder) {
+ BufferedReader reader = getBufferedReader("refuseCollectionExample_Quantities");
String line;
boolean firstLine = true;
while ((line = readLine(reader)) != null) {
@@ -279,8 +276,8 @@ public class RefuseCollection_IT {
close(reader);
}
- private static void readDemandQuantitiesAsDeliveries(VehicleRoutingProblem.Builder vrpBuilder) {
- BufferedReader reader = getBufferedReader("src/test/resources/refuseCollectionExample_Quantities");
+ private void readDemandQuantitiesAsDeliveries(VehicleRoutingProblem.Builder vrpBuilder) {
+ BufferedReader reader = getBufferedReader("refuseCollectionExample_Quantities");
String line;
boolean firstLine = true;
while ((line = readLine(reader)) != null) {
@@ -321,8 +318,8 @@ public class RefuseCollection_IT {
}
- private static void readDistances(VehicleRoutingTransportCostsMatrix.Builder matrixBuilder) {
- BufferedReader reader = getBufferedReader("src/test/resources/refuseCollectionExample_Distances");
+ private void readDistances(VehicleRoutingTransportCostsMatrix.Builder matrixBuilder) {
+ BufferedReader reader = getBufferedReader("refuseCollectionExample_Distances");
String line;
boolean firstLine = true;
while ((line = readLine(reader)) != null) {
diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/SelectRandomlyTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/SelectRandomlyTest.java
deleted file mode 100644
index 63281794..00000000
--- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/SelectRandomlyTest.java
+++ /dev/null
@@ -1,24 +0,0 @@
-package com.graphhopper.jsprit.core.algorithm;
-
-import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
-import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
-import com.graphhopper.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/java/com/graphhopper/jsprit/core/algorithm/SolomonSkills_IT.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/SolomonSkills_IT.java
index 5c914f31..e2fad632 100644
--- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/SolomonSkills_IT.java
+++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/SolomonSkills_IT.java
@@ -18,12 +18,9 @@
package com.graphhopper.jsprit.core.algorithm;
import com.graphhopper.jsprit.core.IntegrationTest;
-import com.graphhopper.jsprit.core.algorithm.recreate.NoSolutionFoundException;
-import com.graphhopper.jsprit.core.algorithm.state.StateManager;
+import com.graphhopper.jsprit.core.algorithm.box.Jsprit;
import com.graphhopper.jsprit.core.problem.Skills;
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
-import com.graphhopper.jsprit.core.problem.constraint.ConstraintManager;
-import com.graphhopper.jsprit.core.problem.io.VrpXMLReader;
import com.graphhopper.jsprit.core.problem.job.Job;
import com.graphhopper.jsprit.core.problem.job.Service;
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
@@ -31,6 +28,7 @@ import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl;
import com.graphhopper.jsprit.core.problem.vehicle.VehicleType;
+import com.graphhopper.jsprit.core.util.SolomonReader;
import com.graphhopper.jsprit.core.util.Solutions;
import com.graphhopper.jsprit.core.util.TestUtils;
import org.junit.Test;
@@ -49,7 +47,7 @@ public class SolomonSkills_IT {
@Category(IntegrationTest.class)
public void itShouldMakeCorrectAssignmentAccordingToSkills() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/solomon_c101.xml");
+ new SolomonReader(vrpBuilder).read(getClass().getResourceAsStream("C101.txt"));
VehicleRoutingProblem vrp = vrpBuilder.build();
//y >= 50 skill1 otherwise skill2
@@ -80,36 +78,21 @@ public class SolomonSkills_IT {
skillProblemBuilder.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE);
VehicleRoutingProblem skillProblem = skillProblemBuilder.build();
- VehicleRoutingAlgorithmBuilder vraBuilder = new VehicleRoutingAlgorithmBuilder(skillProblem, "src/test/resources/algorithmConfig.xml");
- vraBuilder.addCoreConstraints();
- vraBuilder.addDefaultCostCalculators();
+ VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(skillProblem).setProperty(Jsprit.Parameter.FAST_REGRET,"true").buildAlgorithm();
- StateManager stateManager = new StateManager(skillProblem);
- stateManager.updateSkillStates();
-
- ConstraintManager constraintManager = new ConstraintManager(skillProblem, stateManager);
- constraintManager.addSkillsConstraint();
-
- VehicleRoutingAlgorithm vra = vraBuilder.build();
- vra.setMaxIterations(2000);
-
- try {
- Collection solutions = vra.searchSolutions();
- VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
- assertEquals(828.94, solution.getCost(), 0.01);
- for (VehicleRoute route : solution.getRoutes()) {
- Skills vehicleSkill = route.getVehicle().getSkills();
- for (Job job : route.getTourActivities().getJobs()) {
- for (String skill : job.getRequiredSkills().values()) {
- if (!vehicleSkill.containsSkill(skill)) {
- assertFalse(true);
- }
+ Collection solutions = vra.searchSolutions();
+ VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
+ assertEquals(828.94, solution.getCost(), 0.01);
+ for (VehicleRoute route : solution.getRoutes()) {
+ Skills vehicleSkill = route.getVehicle().getSkills();
+ for (Job job : route.getTourActivities().getJobs()) {
+ for (String skill : job.getRequiredSkills().values()) {
+ if (!vehicleSkill.containsSkill(skill)) {
+ assertFalse(true);
}
}
}
- assertTrue(true);
- } catch (NoSolutionFoundException e) {
- assertFalse(true);
}
+ assertTrue(true);
}
}
diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/Solomon_IT.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/Solomon_IT.java
index 5a211f7e..205ba807 100644
--- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/Solomon_IT.java
+++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/Solomon_IT.java
@@ -3,8 +3,8 @@ package com.graphhopper.jsprit.core.algorithm;
import com.graphhopper.jsprit.core.IntegrationTest;
import com.graphhopper.jsprit.core.algorithm.box.Jsprit;
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
-import com.graphhopper.jsprit.core.problem.io.VrpXMLReader;
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
+import com.graphhopper.jsprit.core.util.SolomonReader;
import com.graphhopper.jsprit.core.util.Solutions;
import org.junit.Assert;
import org.junit.Test;
@@ -21,14 +21,10 @@ public class Solomon_IT {
@Category(IntegrationTest.class)
public void itShouldFindTheBestKnownSolution() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new VrpXMLReader(vrpBuilder).read("src/test/resources/solomon_c101.xml");
+ new SolomonReader(vrpBuilder).read(getClass().getResourceAsStream("C101.txt"));
VehicleRoutingProblem vrp = vrpBuilder.build();
- VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp)
-// .setProperty(Jsprit.Parameter.THREADS,"3")
-// .setProperty(Jsprit.Parameter.FAST_REGRET,"true")
- .buildAlgorithm();
-// VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml");
+ VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setProperty(Jsprit.Parameter.FAST_REGRET,"true").buildAlgorithm();
vra.setMaxIterations(2000);
Collection solutions = vra.searchSolutions();
Assert.assertEquals(828.94, Solutions.bestOf(solutions).getCost(), 0.01);
diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/recreate/CalcWithTimeSchedulingTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/recreate/CalcWithTimeSchedulingTest.java
deleted file mode 100644
index a6cd8141..00000000
--- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/recreate/CalcWithTimeSchedulingTest.java
+++ /dev/null
@@ -1,95 +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 com.graphhopper.jsprit.core.algorithm.recreate;
-
-import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm;
-import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
-import com.graphhopper.jsprit.core.problem.Location;
-import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
-import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem.FleetSize;
-import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingTransportCosts;
-import com.graphhopper.jsprit.core.problem.driver.Driver;
-import com.graphhopper.jsprit.core.problem.job.Service;
-import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
-import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
-import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
-import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl;
-import com.graphhopper.jsprit.core.problem.vehicle.VehicleTypeImpl;
-import com.graphhopper.jsprit.core.util.Coordinate;
-import com.graphhopper.jsprit.core.util.CrowFlyCosts;
-import com.graphhopper.jsprit.core.util.Solutions;
-import com.graphhopper.jsprit.core.util.TestUtils;
-
-import java.util.Collection;
-
-import static org.junit.Assert.assertEquals;
-
-
-public class CalcWithTimeSchedulingTest {
-
-
- public void timeScheduler() {
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- VehicleImpl vehicle = VehicleImpl.Builder.newInstance("myVehicle").setEarliestStart(0.0).setLatestArrival(100.0).
- setStartLocation(TestUtils.loc("0,0", Coordinate.newInstance(0, 0)))
- .setType(VehicleTypeImpl.Builder.newInstance("myType").addCapacityDimension(0, 20).setCostPerDistance(1.0).build()).build();
- vrpBuilder.addVehicle(vehicle);
- vrpBuilder.addJob(Service.Builder.newInstance("myService").addSizeDimension(0, 2)
- .setLocation(TestUtils.loc("0,20", Coordinate.newInstance(0, 20))).build());
- vrpBuilder.setFleetSize(FleetSize.INFINITE);
- vrpBuilder.setRoutingCost(getTpCosts(new CrowFlyCosts(vrpBuilder.getLocations())));
- VehicleRoutingProblem vrp = vrpBuilder.build();
-
- VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/testConfig.xml");
- Collection solutions = vra.searchSolutions();
-
- VehicleRoutingProblemSolution sol = Solutions.bestOf(solutions);
- assertEquals(40.0, sol.getCost(), 0.01);
- assertEquals(1, sol.getRoutes().size());
- VehicleRoute route = sol.getRoutes().iterator().next();
- assertEquals(50.0, route.getStart().getEndTime(), 0.01);
- }
-
- private VehicleRoutingTransportCosts getTpCosts(final VehicleRoutingTransportCosts baseCosts) {
- return new VehicleRoutingTransportCosts() {
-
- @Override
- public double getBackwardTransportCost(Location from, Location to, double arrivalTime, Driver driver, Vehicle vehicle) {
- return getTransportCost(from, to, arrivalTime, driver, vehicle);
- }
-
- @Override
- public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
- if (departureTime < 50) {
- return baseCosts.getTransportCost(from, to, departureTime, driver, vehicle) * 2.0;
- }
- return baseCosts.getTransportCost(from, to, departureTime, driver, vehicle);
- }
-
- @Override
- public double getBackwardTransportTime(Location from, Location to, double arrivalTime, Driver driver, Vehicle vehicle) {
- return getTransportTime(from, to, arrivalTime, driver, vehicle);
- }
-
- @Override
- public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
- return getTransportCost(from, to, departureTime, driver, vehicle);
- }
- };
- }
-
-}
diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/recreate/TestDepartureTimeOpt.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/recreate/TestDepartureTimeOpt.java
deleted file mode 100644
index 388b77f3..00000000
--- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/recreate/TestDepartureTimeOpt.java
+++ /dev/null
@@ -1,249 +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 com.graphhopper.jsprit.core.algorithm.recreate;
-
-import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm;
-import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
-import com.graphhopper.jsprit.core.problem.Location;
-import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
-import com.graphhopper.jsprit.core.problem.cost.VehicleRoutingActivityCosts;
-import com.graphhopper.jsprit.core.problem.driver.Driver;
-import com.graphhopper.jsprit.core.problem.job.Service;
-import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
-import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
-import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
-import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
-import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl;
-import com.graphhopper.jsprit.core.problem.vehicle.VehicleTypeImpl;
-import com.graphhopper.jsprit.core.util.Coordinate;
-import com.graphhopper.jsprit.core.util.Solutions;
-import com.graphhopper.jsprit.core.util.TestUtils;
-import org.junit.Assert;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import java.util.Collection;
-
-@Ignore
-public class TestDepartureTimeOpt {
-
- @Test
- public void whenSettingOneCustWithTWAnd_NO_DepTimeChoice_totalCostsShouldBe50() {
- TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
- Service service = Service.Builder.newInstance("s").setLocation(TestUtils.loc("servLoc", Coordinate.newInstance(0, 10))).setTimeWindow(timeWindow).build();
- Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(TestUtils.loc("vehLoc", Coordinate.newInstance(0, 0)))
- .setType(VehicleTypeImpl.Builder.newInstance("vType").build()).build();
-
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts() {
-
- @Override
- public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
- double waiting = Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime) * 1;
- double late = Math.max(0, arrivalTime - tourAct.getTheoreticalLatestOperationStartTime()) * 100;
- return waiting + late;
- }
-
- @Override
- public double getActivityDuration(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
- return tourAct.getOperationTime();
- }
-
- });
- VehicleRoutingProblem vrp = vrpBuilder.addJob(service).addVehicle(vehicle).build();
-
- VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml");
- Collection solutions = vra.searchSolutions();
-
- Assert.assertEquals(20.0 + 30.0, Solutions.bestOf(solutions).getCost(), 0.1);
-
- }
-
- @Test
- public void whenSettingOneCustWithTWAnd_NO_DepTimeChoice_depTimeShouldBe0() {
- TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
- Service service = Service.Builder.newInstance("s")
- .setLocation(TestUtils.loc("servLoc", Coordinate.newInstance(0, 10))).setTimeWindow(timeWindow).build();
- Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.Builder.newInstance().setId("vehLoc").setCoordinate(Coordinate.newInstance(0, 0)).build())
- .setType(VehicleTypeImpl.Builder.newInstance("vType").build()).build();
-
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts() {
-
- @Override
- public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
- double waiting = Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime) * 1;
- double late = Math.max(0, arrivalTime - tourAct.getTheoreticalLatestOperationStartTime()) * 100;
- return waiting + late;
- }
-
- @Override
- public double getActivityDuration(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
- return tourAct.getOperationTime();
- }
-
- });
- VehicleRoutingProblem vrp = vrpBuilder.addJob(service).addVehicle(vehicle).build();
-
- VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml");
- Collection solutions = vra.searchSolutions();
-
- Assert.assertEquals(0.0, Solutions.bestOf(solutions).getRoutes().iterator().next().getStart().getEndTime(), 0.1);
-
- }
-
- @Test
- public void whenSettingOneCustWithTWAndDepTimeChoice_totalCostsShouldBe50() {
- TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
- Service service = Service.Builder.newInstance("s").setLocation(TestUtils.loc("servLoc", Coordinate.newInstance(0, 10))).setTimeWindow(timeWindow).build();
- Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(TestUtils.loc("vehLoc", Coordinate.newInstance(0, 0)))
- .setType(VehicleTypeImpl.Builder.newInstance("vType").build()).build();
-
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts() {
-
- @Override
- public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
- double waiting = Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime) * 1;
- double late = Math.max(0, arrivalTime - tourAct.getTheoreticalLatestOperationStartTime()) * 100;
- return waiting + late;
- }
-
- @Override
- public double getActivityDuration(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
- return tourAct.getOperationTime();
- }
-
- });
- VehicleRoutingProblem vrp = vrpBuilder.addJob(service).addVehicle(vehicle).build();
-
-
- VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfigWithDepartureTimeChoice.xml");
- Collection solutions = vra.searchSolutions();
-
- Assert.assertEquals(20.0, Solutions.bestOf(solutions).getCost(), 0.1);
-
- }
-
- @Test
- public void whenSettingOneCustWithTWAndDepTimeChoice_depTimeShouldBe0() {
- TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
- Service service = Service.Builder.newInstance("s").setLocation(TestUtils.loc("servLoc", Coordinate.newInstance(0, 10))).setTimeWindow(timeWindow).build();
- Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(TestUtils.loc("vehLoc", Coordinate.newInstance(0, 0)))
- .setType(VehicleTypeImpl.Builder.newInstance("vType").build()).build();
-
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts() {
-
- @Override
- public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
- double waiting = Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime) * 1;
- double late = Math.max(0, arrivalTime - tourAct.getTheoreticalLatestOperationStartTime()) * 100;
- return waiting + late;
- }
-
- @Override
- public double getActivityDuration(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
- return tourAct.getOperationTime();
- }
-
- });
- VehicleRoutingProblem vrp = vrpBuilder.addJob(service).addVehicle(vehicle).build();
-
-
- VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfigWithDepartureTimeChoice.xml");
- Collection solutions = vra.searchSolutions();
-
- Assert.assertEquals(30.0, Solutions.bestOf(solutions).getRoutes().iterator().next().getStart().getEndTime(), 0.1);
-
- }
-
- @Test
- public void whenSettingTwoCustWithTWAndDepTimeChoice_totalCostsShouldBe50() {
- TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
- Service service = Service.Builder.newInstance("s").setLocation(TestUtils.loc("servLoc", Coordinate.newInstance(0, 10))).setTimeWindow(timeWindow).build();
-
- Service service2 = Service.Builder.newInstance("s2").setLocation(TestUtils.loc("servLoc2", Coordinate.newInstance(0, 20))).
- setTimeWindow(TimeWindow.newInstance(30, 40)).build();
-
- Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(TestUtils.loc("vehLoc", Coordinate.newInstance(0, 0)))
- .setType(VehicleTypeImpl.Builder.newInstance("vType").build()).build();
-
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts() {
-
- @Override
- public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
- double waiting = Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime) * 1;
- double late = Math.max(0, arrivalTime - tourAct.getTheoreticalLatestOperationStartTime()) * 100;
- return waiting + late;
- }
-
- @Override
- public double getActivityDuration(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
- return tourAct.getOperationTime();
- }
-
- });
- VehicleRoutingProblem vrp = vrpBuilder.addJob(service).addJob(service2).addVehicle(vehicle).build();
-
-
- VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfigWithDepartureTimeChoice.xml");
- Collection solutions = vra.searchSolutions();
-
- Assert.assertEquals(40.0, Solutions.bestOf(solutions).getCost(), 0.1);
-
- }
-
- @Test
- public void whenSettingTwoCustWithTWAndDepTimeChoice_depTimeShouldBe10() {
- TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
- Service service = Service.Builder.newInstance("s").setLocation(TestUtils.loc("servLoc", Coordinate.newInstance(0, 10))).setTimeWindow(timeWindow).build();
-
- Service service2 = Service.Builder.newInstance("s2").setLocation(TestUtils.loc("servLoc2", Coordinate.newInstance(0, 20))).
- setTimeWindow(TimeWindow.newInstance(30, 40)).build();
-
- Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(TestUtils.loc("vehLoc", Coordinate.newInstance(0, 0)))
- .setType(VehicleTypeImpl.Builder.newInstance("vType").build()).build();
-
- VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- vrpBuilder.setActivityCosts(new VehicleRoutingActivityCosts() {
-
- @Override
- public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
- double waiting = Math.max(0, tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime) * 1;
- double late = Math.max(0, arrivalTime - tourAct.getTheoreticalLatestOperationStartTime()) * 100;
- return waiting + late;
- }
-
- @Override
- public double getActivityDuration(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
- return tourAct.getOperationTime();
- }
-
- });
- VehicleRoutingProblem vrp = vrpBuilder.addJob(service).addJob(service2).addVehicle(vehicle).build();
-
-
- VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfigWithDepartureTimeChoice.xml");
- Collection solutions = vra.searchSolutions();
-
- Assert.assertEquals(10.0, Solutions.bestOf(solutions).getRoutes().iterator().next().getStart().getEndTime(), 0.1);
-
- }
-
-}
diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/util/ChristofidesReader.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/util/ChristofidesReader.java
new file mode 100644
index 00000000..7451f9ef
--- /dev/null
+++ b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/util/ChristofidesReader.java
@@ -0,0 +1,149 @@
+/*******************************************************************************
+ * 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 com.graphhopper.jsprit.core.util;
+
+
+import com.graphhopper.jsprit.core.problem.Location;
+import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
+import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem.FleetSize;
+import com.graphhopper.jsprit.core.problem.job.Delivery;
+import com.graphhopper.jsprit.core.problem.job.Pickup;
+import com.graphhopper.jsprit.core.problem.job.Service;
+import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl;
+import com.graphhopper.jsprit.core.problem.vehicle.VehicleTypeImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+
+
+/**
+ * Reader that reads Christophides, Mingozzi and Toth instances.
+ *