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/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 2ac21d77..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
@@ -51,6 +51,9 @@ public class GreedySchrimpfFactory {
}
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");
@@ -61,10 +64,10 @@ public class GreedySchrimpfFactory {
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(0.3));
- builder.setProperty(Jsprit.Parameter.RADIAL_MAX_SHARE, String.valueOf(0.3));
- builder.setProperty(Jsprit.Parameter.RANDOM_BEST_MIN_SHARE, String.valueOf(0.5));
- builder.setProperty(Jsprit.Parameter.RANDOM_BEST_MAX_SHARE, String.valueOf(0.5));
+ 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/SchrimpfFactory.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/SchrimpfFactory.java
index 08a143c0..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
@@ -49,6 +49,8 @@ public class SchrimpfFactory {
public VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vrp) {
//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");
@@ -59,10 +61,10 @@ public class SchrimpfFactory {
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(0.3));
- builder.setProperty(Jsprit.Parameter.RADIAL_MAX_SHARE, String.valueOf(0.3));
- builder.setProperty(Jsprit.Parameter.RANDOM_BEST_MIN_SHARE, String.valueOf(0.5));
- builder.setProperty(Jsprit.Parameter.RANDOM_BEST_MAX_SHARE, String.valueOf(0.5));
+ 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 8f352405..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;
@@ -28,59 +29,28 @@ 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.VehicleImpl;
import com.graphhopper.jsprit.core.util.Solutions;
-import com.graphhopper.jsprit.io.algorithm.VehicleRoutingAlgorithmBuilder;
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();
@@ -90,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/InitialRoutesTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/InitialRoutesTest.java
index ef109806..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
@@ -40,7 +40,6 @@ 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;
@@ -61,7 +60,7 @@ public class InitialRoutesTest {
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("s1").setLocation(Location.newInstance(1000,1000)).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);
@@ -77,26 +76,6 @@ public class InitialRoutesTest {
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() {
VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
@@ -105,30 +84,12 @@ public class InitialRoutesTest {
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() {
VehicleRoutingAlgorithm vra = new SchrimpfFactory().createAlgorithm(vrp);
Collection solutions = vra.searchSolutions();
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
- Job job = getInitialJob("1", vrp);
+ Job job = getInitialJob("s1", vrp);
assertTrue(hasActivityIn(solution, "veh1", job));
}
@@ -141,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) {
@@ -239,7 +143,7 @@ public class InitialRoutesTest {
Collection solutions = vra.searchSolutions();
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
- assertTrue(hasActivityIn(solution.getRoutes().iterator().next(), "2"));
+ assertTrue(hasActivityIn(solution.getRoutes().iterator().next(), "s2"));
}
@Test
@@ -276,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/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 e4e0e497..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
@@ -47,7 +47,7 @@ public class SolomonSkills_IT {
@Category(IntegrationTest.class)
public void itShouldMakeCorrectAssignmentAccordingToSkills() {
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
- new SolomonReader(vrpBuilder).read("src/test/resources/C101.txt");
+ new SolomonReader(vrpBuilder).read(getClass().getResourceAsStream("C101.txt"));
VehicleRoutingProblem vrp = vrpBuilder.build();
//y >= 50 skill1 otherwise skill2
@@ -78,7 +78,7 @@ public class SolomonSkills_IT {
skillProblemBuilder.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE);
VehicleRoutingProblem skillProblem = skillProblemBuilder.build();
- VehicleRoutingAlgorithm vra = Jsprit.createAlgorithm(skillProblem);
+ VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(skillProblem).setProperty(Jsprit.Parameter.FAST_REGRET,"true").buildAlgorithm();
Collection solutions = vra.searchSolutions();
VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions);
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.
+ *