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 index 30174ae6..f3020c7b 100644 --- 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 @@ -26,7 +26,7 @@ import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolutio 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.math.stat.descriptive.DescriptiveStatistics; +import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; import java.util.ArrayList; import java.util.Collection; diff --git a/jsprit-core/pom.xml b/jsprit-core/pom.xml index 7b538a91..b427f92e 100644 --- a/jsprit-core/pom.xml +++ b/jsprit-core/pom.xml @@ -55,68 +55,25 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - + - - org.apache.commons - commons-math - 2.2 - jar - compile - - - - commons-configuration - commons-configuration - 1.9 - jar - compile - - - - xerces - xercesImpl - 2.11.0 - compile - - org.apache.commons commons-math3 3.4 + + org.slf4j + slf4j-api + ${logger.version} + + diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/VehicleRoutingAlgorithmBuilder.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/VehicleRoutingAlgorithmBuilder.java deleted file mode 100644 index 80af621b..00000000 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/VehicleRoutingAlgorithmBuilder.java +++ /dev/null @@ -1,177 +0,0 @@ -/******************************************************************************* - * Copyright (C) 2014 Stefan Schroeder - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3.0 of the License, or (at your option) any later version. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with this library. If not, see . - ******************************************************************************/ -package com.graphhopper.jsprit.core.algorithm; - -import com.graphhopper.jsprit.core.algorithm.io.AlgorithmConfig; -import com.graphhopper.jsprit.core.algorithm.io.AlgorithmConfigXmlReader; -import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms; -import com.graphhopper.jsprit.core.algorithm.state.StateManager; -import com.graphhopper.jsprit.core.algorithm.state.UpdateEndLocationIfRouteIsOpen; -import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem; -import com.graphhopper.jsprit.core.problem.constraint.ConstraintManager; -import com.graphhopper.jsprit.core.problem.solution.SolutionCostCalculator; - -/** - * Builder that builds a {@link VehicleRoutingAlgorithm}. - * - * @author schroeder - */ -public class VehicleRoutingAlgorithmBuilder { - - private String algorithmConfigFile; - - private AlgorithmConfig algorithmConfig; - - private final VehicleRoutingProblem vrp; - - private SolutionCostCalculator solutionCostCalculator; - - private StateManager stateManager; - - private boolean addCoreConstraints = false; - - private boolean addDefaultCostCalculators = false; - - private ConstraintManager constraintManager; - - private int nuOfThreads = 0; - - /** - * Constructs the builder with the problem and an algorithmConfigFile. Latter is to configure and specify the ruin-and-recreate meta-heuristic. - * - * @param problem to solve - * @param algorithmConfig config file of VehicleRoutingAlgorithm - */ - public VehicleRoutingAlgorithmBuilder(VehicleRoutingProblem problem, String algorithmConfig) { - this.vrp = problem; - this.algorithmConfigFile = algorithmConfig; - this.algorithmConfig = null; - } - - /** - * Constructs the builder with the problem and an algorithmConfig. Latter is to configure and specify the ruin-and-recreate meta-heuristic. - * - * @param problem to solve - * @param algorithmConfig config file of VehicleRoutingAlgorithm - */ - public VehicleRoutingAlgorithmBuilder(VehicleRoutingProblem problem, AlgorithmConfig algorithmConfig) { - this.vrp = problem; - this.algorithmConfigFile = null; - this.algorithmConfig = algorithmConfig; - } - - /** - * Sets custom objective function. - *

- *

If objective function is not set, a default function is applied (which basically minimizes - * fixed and variable transportation costs ({@link VariablePlusFixedSolutionCostCalculatorFactory}). - * - * @param objectiveFunction to be minimized - * @see VariablePlusFixedSolutionCostCalculatorFactory - */ - public void setObjectiveFunction(SolutionCostCalculator objectiveFunction) { - this.solutionCostCalculator = objectiveFunction; - } - - /** - * Sets stateManager to memorize states. - * - * @param stateManager that memorizes your states - * @see StateManager - */ - public void setStateManager(StateManager stateManager) { - this.stateManager = stateManager; - } - - /** - * Adds core constraints. - *

- *

Thus, it adds vehicle-capacity, time-window and skills constraints and their - * required stateUpdater. - */ - public void addCoreConstraints() { - addCoreConstraints = true; - } - - /** - * Adds default cost calculators used by the insertion heuristic, - * to calculate activity insertion costs. - * By default, marginal transportation costs are calculated. Thus when inserting - * act_k between act_i and act_j, marginal (additional) transportation costs - * are basically c(act_i,act_k)+c(act_k,act_j)-c(act_i,act_j). - *

- *

Do not use this method, if you plan to control the insertion heuristic - * entirely via hard- and soft-constraints. - */ - public void addDefaultCostCalculators() { - addDefaultCostCalculators = true; - } - - /** - * Sets state- and constraintManager. - * - * @param stateManager that memorizes your states - * @param constraintManager that manages your constraints - * @see StateManager - * @see ConstraintManager - */ - public void setStateAndConstraintManager(StateManager stateManager, ConstraintManager constraintManager) { - this.stateManager = stateManager; - this.constraintManager = constraintManager; - } - - /** - * Sets nuOfThreads. - * - * @param nuOfThreads to be operated - */ - public void setNuOfThreads(int nuOfThreads) { - this.nuOfThreads = nuOfThreads; - } - - /** - * Builds and returns the algorithm. - *

- *

If algorithmConfigFile is set, it reads the configuration. - * - * @return the algorithm - */ - public VehicleRoutingAlgorithm build() { - if (stateManager == null) stateManager = new StateManager(vrp); - if (constraintManager == null) constraintManager = new ConstraintManager(vrp, stateManager); - //add core updater - stateManager.addStateUpdater(new UpdateEndLocationIfRouteIsOpen()); -// stateManager.addStateUpdater(new OpenRouteStateVerifier()); - - if (addCoreConstraints) { - constraintManager.addLoadConstraint(); - constraintManager.addTimeWindowConstraint(); - constraintManager.addSkillsConstraint(); - stateManager.updateLoadStates(); - stateManager.updateTimeWindowStates(); - stateManager.updateSkillStates(); - } - if (algorithmConfig == null) { - algorithmConfig = new AlgorithmConfig(); - AlgorithmConfigXmlReader xmlReader = new AlgorithmConfigXmlReader(algorithmConfig); - xmlReader.read(algorithmConfigFile); - } - return VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, algorithmConfig, nuOfThreads, solutionCostCalculator, stateManager, constraintManager, addDefaultCostCalculators); - } - - -} diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/acceptor/ExperimentalSchrimpfAcceptance.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/acceptor/ExperimentalSchrimpfAcceptance.java index 7dc067df..d42ff4d2 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/acceptor/ExperimentalSchrimpfAcceptance.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/acceptor/ExperimentalSchrimpfAcceptance.java @@ -17,21 +17,18 @@ package com.graphhopper.jsprit.core.algorithm.acceptor; import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm; -import com.graphhopper.jsprit.core.algorithm.io.AlgorithmConfig; -import com.graphhopper.jsprit.core.algorithm.io.AlgorithmConfigXmlReader; -import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms; +import com.graphhopper.jsprit.core.algorithm.box.GreedySchrimpfFactory; +import com.graphhopper.jsprit.core.algorithm.box.Jsprit; import com.graphhopper.jsprit.core.algorithm.listener.AlgorithmStartsListener; import com.graphhopper.jsprit.core.algorithm.listener.IterationEndsListener; import com.graphhopper.jsprit.core.algorithm.listener.IterationStartsListener; import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem; import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution; -import com.graphhopper.jsprit.core.util.Resource; import com.graphhopper.jsprit.core.util.Solutions; -import org.apache.commons.math.stat.descriptive.moment.StandardDeviation; +import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.net.URL; import java.util.Collection; @@ -114,10 +111,9 @@ public class ExperimentalSchrimpfAcceptance implements SolutionAcceptor, Iterati */ final double[] results = new double[nOfRandomWalks]; - URL resource = Resource.getAsURL("randomWalk.xml"); - AlgorithmConfig algorithmConfig = new AlgorithmConfig(); - new AlgorithmConfigXmlReader(algorithmConfig).read(resource); - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.createAlgorithm(problem, algorithmConfig); + Jsprit.Builder builder = new GreedySchrimpfFactory().createGreedyAlgorithmBuilder(problem); + builder.setCustomAcceptor(new AcceptNewRemoveFirst(1)); + VehicleRoutingAlgorithm vra = builder.buildAlgorithm(); vra.setMaxIterations(nOfRandomWalks); vra.getAlgorithmListeners().addListener(new IterationEndsListener() { diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/acceptor/SchrimpfInitialThresholdGenerator.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/acceptor/SchrimpfInitialThresholdGenerator.java index c5391134..09f90237 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/acceptor/SchrimpfInitialThresholdGenerator.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/acceptor/SchrimpfInitialThresholdGenerator.java @@ -17,20 +17,17 @@ package com.graphhopper.jsprit.core.algorithm.acceptor; import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm; -import com.graphhopper.jsprit.core.algorithm.io.AlgorithmConfig; -import com.graphhopper.jsprit.core.algorithm.io.AlgorithmConfigXmlReader; -import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms; +import com.graphhopper.jsprit.core.algorithm.box.GreedySchrimpfFactory; +import com.graphhopper.jsprit.core.algorithm.box.Jsprit; import com.graphhopper.jsprit.core.algorithm.listener.AlgorithmStartsListener; import com.graphhopper.jsprit.core.algorithm.listener.IterationEndsListener; import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem; import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution; -import com.graphhopper.jsprit.core.util.Resource; import com.graphhopper.jsprit.core.util.Solutions; -import org.apache.commons.math.stat.descriptive.moment.StandardDeviation; +import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import java.net.URL; import java.util.Collection; public class SchrimpfInitialThresholdGenerator implements AlgorithmStartsListener { @@ -57,10 +54,9 @@ public class SchrimpfInitialThresholdGenerator implements AlgorithmStartsListene */ final double[] results = new double[nOfRandomWalks]; - URL resource = Resource.getAsURL("randomWalk.xml"); - AlgorithmConfig algorithmConfig = new AlgorithmConfig(); - new AlgorithmConfigXmlReader(algorithmConfig).read(resource); - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.createAlgorithm(problem, algorithmConfig); + Jsprit.Builder builder = new GreedySchrimpfFactory().createGreedyAlgorithmBuilder(problem); + builder.setCustomAcceptor(new AcceptNewRemoveFirst(1)); + VehicleRoutingAlgorithm vra = builder.buildAlgorithm(); vra.setMaxIterations(nOfRandomWalks); vra.getAlgorithmListeners().addListener(new IterationEndsListener() { diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/GreedySchrimpfFactory.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/GreedySchrimpfFactory.java index 195fcdf9..2ac21d77 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/GreedySchrimpfFactory.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/GreedySchrimpfFactory.java @@ -17,13 +17,7 @@ package com.graphhopper.jsprit.core.algorithm.box; import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm; -import com.graphhopper.jsprit.core.algorithm.io.AlgorithmConfig; -import com.graphhopper.jsprit.core.algorithm.io.AlgorithmConfigXmlReader; -import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms; import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem; -import com.graphhopper.jsprit.core.util.Resource; - -import java.net.URL; /** @@ -53,11 +47,25 @@ public class GreedySchrimpfFactory { * @return algorithm */ public VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vrp) { - AlgorithmConfig algorithmConfig = new AlgorithmConfig(); - URL resource = Resource.getAsURL("greedySchrimpf.xml"); - new AlgorithmConfigXmlReader(algorithmConfig).read(resource); - return VehicleRoutingAlgorithms.createAlgorithm(vrp, algorithmConfig); + return createGreedyAlgorithmBuilder(vrp).buildAlgorithm(); } + public Jsprit.Builder createGreedyAlgorithmBuilder(VehicleRoutingProblem vrp) { + Jsprit.Builder builder = Jsprit.Builder.newInstance(vrp); + builder.setProperty(Jsprit.Parameter.THRESHOLD_ALPHA,"0.0"); + builder.setProperty(Jsprit.Strategy.RADIAL_BEST, "0.5"); + builder.setProperty(Jsprit.Strategy.RADIAL_REGRET, "0.0"); + builder.setProperty(Jsprit.Strategy.RANDOM_BEST, "0.5"); + builder.setProperty(Jsprit.Strategy.RANDOM_REGRET, "0.0"); + builder.setProperty(Jsprit.Strategy.WORST_BEST, "0.0"); + builder.setProperty(Jsprit.Strategy.WORST_REGRET, "0.0"); + builder.setProperty(Jsprit.Strategy.CLUSTER_BEST, "0.0"); + builder.setProperty(Jsprit.Strategy.CLUSTER_REGRET, "0.0"); + builder.setProperty(Jsprit.Parameter.RADIAL_MIN_SHARE, String.valueOf(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)); + return builder; + } } diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/Jsprit.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/Jsprit.java index fce66c3d..821171ba 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/Jsprit.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/Jsprit.java @@ -4,6 +4,7 @@ import com.graphhopper.jsprit.core.algorithm.PrettyAlgorithmBuilder; import com.graphhopper.jsprit.core.algorithm.SearchStrategy; import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm; import com.graphhopper.jsprit.core.algorithm.acceptor.SchrimpfAcceptance; +import com.graphhopper.jsprit.core.algorithm.acceptor.SolutionAcceptor; import com.graphhopper.jsprit.core.algorithm.listener.AlgorithmEndsListener; import com.graphhopper.jsprit.core.algorithm.listener.IterationStartsListener; import com.graphhopper.jsprit.core.algorithm.module.RuinAndRecreateModule; @@ -139,6 +140,8 @@ public class Jsprit { private ActivityInsertionCostsCalculator activityInsertionCalculator; + private SolutionAcceptor solutionAcceptor; + public static Builder newInstance(VehicleRoutingProblem vrp) { return new Builder(vrp); } @@ -197,6 +200,11 @@ public class Jsprit { return this; } + public Builder setCustomAcceptor(SolutionAcceptor acceptor){ + this.solutionAcceptor = acceptor; + return this; + } + public Builder setRandom(Random random) { this.random = random; return this; @@ -298,6 +306,8 @@ public class Jsprit { private Random random; + private SolutionAcceptor acceptor; + private Jsprit(Builder builder) { this.stateManager = builder.stateManager; this.constraintManager = builder.constraintManager; @@ -308,6 +318,7 @@ public class Jsprit { this.objectiveFunction = builder.objectiveFunction; this.random = builder.random; this.activityInsertion = builder.activityInsertionCalculator; + this.acceptor = builder.solutionAcceptor; } private VehicleRoutingAlgorithm create(final VehicleRoutingProblem vrp) { @@ -496,40 +507,44 @@ public class Jsprit { } best.setRandom(random); - final SchrimpfAcceptance schrimpfAcceptance = new SchrimpfAcceptance(1, toDouble(getProperty(Parameter.THRESHOLD_ALPHA.toString()))); - IterationStartsListener schrimpfThreshold = new IterationStartsListener() { - @Override - public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection solutions) { - if (i == 1) { - double initialThreshold = Solutions.bestOf(solutions).getCost() * toDouble(getProperty(Parameter.THRESHOLD_INI.toString())); - schrimpfAcceptance.setInitialThreshold(initialThreshold); + IterationStartsListener schrimpfThreshold = null; + if(acceptor == null) { + final SchrimpfAcceptance schrimpfAcceptance = new SchrimpfAcceptance(1, toDouble(getProperty(Parameter.THRESHOLD_ALPHA.toString()))); + schrimpfThreshold = new IterationStartsListener() { + @Override + public void informIterationStarts(int i, VehicleRoutingProblem problem, Collection solutions) { + if (i == 1) { + double initialThreshold = Solutions.bestOf(solutions).getCost() * toDouble(getProperty(Parameter.THRESHOLD_INI.toString())); + schrimpfAcceptance.setInitialThreshold(initialThreshold); + } } - } - }; + }; + acceptor = schrimpfAcceptance; + } SolutionCostCalculator objectiveFunction = getObjectiveFunction(vrp, maxCosts); - SearchStrategy radial_regret = new SearchStrategy(Strategy.RADIAL_REGRET.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction); + SearchStrategy radial_regret = new SearchStrategy(Strategy.RADIAL_REGRET.toString(), new SelectBest(), acceptor, objectiveFunction); radial_regret.addModule(new RuinAndRecreateModule(Strategy.RADIAL_REGRET.toString(), regret, radial)); - SearchStrategy radial_best = new SearchStrategy(Strategy.RADIAL_BEST.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction); + SearchStrategy radial_best = new SearchStrategy(Strategy.RADIAL_BEST.toString(), new SelectBest(), acceptor, objectiveFunction); radial_best.addModule(new RuinAndRecreateModule(Strategy.RADIAL_BEST.toString(), best, radial)); - SearchStrategy random_best = new SearchStrategy(Strategy.RANDOM_BEST.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction); + SearchStrategy random_best = new SearchStrategy(Strategy.RANDOM_BEST.toString(), new SelectBest(), acceptor, objectiveFunction); random_best.addModule(new RuinAndRecreateModule(Strategy.RANDOM_BEST.toString(), best, random_for_best)); - SearchStrategy random_regret = new SearchStrategy(Strategy.RANDOM_REGRET.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction); + SearchStrategy random_regret = new SearchStrategy(Strategy.RANDOM_REGRET.toString(), new SelectBest(), acceptor, objectiveFunction); random_regret.addModule(new RuinAndRecreateModule(Strategy.RANDOM_REGRET.toString(), regret, random_for_regret)); - SearchStrategy worst_regret = new SearchStrategy(Strategy.WORST_REGRET.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction); + SearchStrategy worst_regret = new SearchStrategy(Strategy.WORST_REGRET.toString(), new SelectBest(), acceptor, objectiveFunction); worst_regret.addModule(new RuinAndRecreateModule(Strategy.WORST_REGRET.toString(), regret, worst)); - SearchStrategy worst_best = new SearchStrategy(Strategy.WORST_BEST.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction); + SearchStrategy worst_best = new SearchStrategy(Strategy.WORST_BEST.toString(), new SelectBest(), acceptor, objectiveFunction); worst_best.addModule(new RuinAndRecreateModule(Strategy.WORST_BEST.toString(), best, worst)); - final SearchStrategy clusters_regret = new SearchStrategy(Strategy.CLUSTER_REGRET.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction); + final SearchStrategy clusters_regret = new SearchStrategy(Strategy.CLUSTER_REGRET.toString(), new SelectBest(), acceptor, objectiveFunction); clusters_regret.addModule(new RuinAndRecreateModule(Strategy.CLUSTER_REGRET.toString(), regret, clusters)); - final SearchStrategy clusters_best = new SearchStrategy(Strategy.CLUSTER_BEST.toString(), new SelectBest(), schrimpfAcceptance, objectiveFunction); + final SearchStrategy clusters_best = new SearchStrategy(Strategy.CLUSTER_BEST.toString(), new SelectBest(), acceptor, objectiveFunction); clusters_best.addModule(new RuinAndRecreateModule(Strategy.CLUSTER_BEST.toString(), best, clusters)); @@ -554,7 +569,9 @@ public class Jsprit { VehicleRoutingAlgorithm vra = prettyBuilder.build(); - vra.addListener(schrimpfThreshold); + if(schrimpfThreshold != null) { + vra.addListener(schrimpfThreshold); + } vra.addListener(noiseConfigurator); vra.addListener(noise); vra.addListener(clusters); diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/SchrimpfFactory.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/SchrimpfFactory.java index 069af7b6..08a143c0 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/SchrimpfFactory.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/box/SchrimpfFactory.java @@ -17,13 +17,7 @@ package com.graphhopper.jsprit.core.algorithm.box; import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm; -import com.graphhopper.jsprit.core.algorithm.io.AlgorithmConfig; -import com.graphhopper.jsprit.core.algorithm.io.AlgorithmConfigXmlReader; -import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms; import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem; -import com.graphhopper.jsprit.core.util.Resource; - -import java.net.URL; /** @@ -53,10 +47,23 @@ public class SchrimpfFactory { * @return algorithm */ public VehicleRoutingAlgorithm createAlgorithm(VehicleRoutingProblem vrp) { - AlgorithmConfig algorithmConfig = new AlgorithmConfig(); - URL resource = Resource.getAsURL("schrimpf.xml"); - new AlgorithmConfigXmlReader(algorithmConfig).read(resource); - return VehicleRoutingAlgorithms.createAlgorithm(vrp, algorithmConfig); + //TODO determine alpha threshold + + Jsprit.Builder builder = Jsprit.Builder.newInstance(vrp); + builder.setProperty(Jsprit.Parameter.THRESHOLD_ALPHA,"0.0"); + builder.setProperty(Jsprit.Strategy.RADIAL_BEST, "0.5"); + builder.setProperty(Jsprit.Strategy.RADIAL_REGRET, "0.0"); + builder.setProperty(Jsprit.Strategy.RANDOM_BEST, "0.5"); + builder.setProperty(Jsprit.Strategy.RANDOM_REGRET, "0.0"); + builder.setProperty(Jsprit.Strategy.WORST_BEST, "0.0"); + builder.setProperty(Jsprit.Strategy.WORST_REGRET, "0.0"); + builder.setProperty(Jsprit.Strategy.CLUSTER_BEST, "0.0"); + builder.setProperty(Jsprit.Strategy.CLUSTER_REGRET, "0.0"); + builder.setProperty(Jsprit.Parameter.RADIAL_MIN_SHARE, String.valueOf(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)); + return builder.buildAlgorithm(); } diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/termination/VariationCoefficientTermination.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/termination/VariationCoefficientTermination.java index e1a11990..485762bc 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/termination/VariationCoefficientTermination.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/termination/VariationCoefficientTermination.java @@ -24,8 +24,8 @@ import com.graphhopper.jsprit.core.algorithm.listener.IterationStartsListener; import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem; import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution; import com.graphhopper.jsprit.core.util.Solutions; -import org.apache.commons.math.stat.StatUtils; -import org.apache.commons.math.stat.descriptive.moment.StandardDeviation; +import org.apache.commons.math3.stat.StatUtils; +import org.apache.commons.math3.stat.descriptive.moment.StandardDeviation; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/util/BenchmarkResult.java b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/util/BenchmarkResult.java index ab3e6620..0a02ff3b 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/util/BenchmarkResult.java +++ b/jsprit-core/src/main/java/com/graphhopper/jsprit/core/util/BenchmarkResult.java @@ -16,7 +16,7 @@ ******************************************************************************/ package com.graphhopper.jsprit.core.util; -import org.apache.commons.math.stat.descriptive.DescriptiveStatistics; +import org.apache.commons.math3.stat.descriptive.DescriptiveStatistics; public class BenchmarkResult { diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/DeactivateTimeWindowsTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/DeactivateTimeWindowsTest.java index d3f631e5..8f352405 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 @@ -28,6 +28,7 @@ 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.Test; diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/SolomonSkills_IT.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/SolomonSkills_IT.java index 5c914f31..ca10eee6 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 @@ -33,6 +33,7 @@ import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl; import com.graphhopper.jsprit.core.problem.vehicle.VehicleType; import com.graphhopper.jsprit.core.util.Solutions; import com.graphhopper.jsprit.core.util.TestUtils; +import com.graphhopper.jsprit.io.algorithm.VehicleRoutingAlgorithmBuilder; import org.junit.Test; import org.junit.experimental.categories.Category; diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/io/TestAlgorithmReader.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/io/TestAlgorithmReader.java deleted file mode 100644 index dfabbb62..00000000 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/algorithm/io/TestAlgorithmReader.java +++ /dev/null @@ -1,285 +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.io; - -import com.graphhopper.jsprit.core.algorithm.SearchStrategy; -import com.graphhopper.jsprit.core.algorithm.SearchStrategyModule; -import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm; -import com.graphhopper.jsprit.core.algorithm.acceptor.GreedyAcceptance; -import com.graphhopper.jsprit.core.algorithm.acceptor.SolutionAcceptor; -import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms.ModKey; -import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap.AcceptorKey; -import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap.RuinStrategyKey; -import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap.SelectorKey; -import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap.StrategyModuleKey; -import com.graphhopper.jsprit.core.algorithm.listener.IterationEndsListener; -import com.graphhopper.jsprit.core.algorithm.listener.SearchStrategyModuleListener; -import com.graphhopper.jsprit.core.algorithm.ruin.RuinStrategy; -import com.graphhopper.jsprit.core.algorithm.ruin.listener.RuinListener; -import com.graphhopper.jsprit.core.algorithm.selector.SelectBest; -import com.graphhopper.jsprit.core.algorithm.selector.SolutionSelector; -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.solution.VehicleRoutingProblemSolution; -import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute; -import junit.framework.Assert; -import org.apache.commons.configuration.ConfigurationException; -import org.junit.Before; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.Collection; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - - -public class TestAlgorithmReader { - - AlgorithmConfig config; - - VehicleRoutingProblem vrp; - - Collection solutions; - - @Before - public void doBefore() throws ConfigurationException { - config = new AlgorithmConfig(); - new AlgorithmConfigXmlReader(config).setSchemaValidation(false).read("src/test/resources/testConfig.xml"); - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - solutions = new ArrayList(); - new VrpXMLReader(vrpBuilder, solutions).read("src/test/resources/finiteVrp.xml"); - vrp = vrpBuilder.build(); - } - - @Test - public void itShouldReadMaxIterations() { - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfigForReaderTest.xml"); - Assert.assertEquals(2000, vra.getMaxIterations()); - } - - static class IterationCounter implements IterationEndsListener { - - int iterations = 0; - - @Override - public void informIterationEnds(int i, VehicleRoutingProblem problem, Collection solutions) { - iterations = i; - } - - } - - @Test - public void whenSettingPrematureBreak_itShouldReadTermination() { - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfigForReaderTest2.xml"); - IterationCounter iCounter = new IterationCounter(); - vra.addListener(iCounter); - vra.searchSolutions(); - Assert.assertEquals(100, iCounter.iterations); - } - - @Test - public void itShouldReadTermination() { - VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfigForReaderTest.xml"); - IterationCounter iCounter = new IterationCounter(); - vra.addListener(iCounter); - vra.searchSolutions(); - Assert.assertEquals(25, iCounter.iterations); - } - - - @Test - public void testTypedMap() { - VehicleRoutingAlgorithms.TypedMap typedMap = new VehicleRoutingAlgorithms.TypedMap(); - - String acceptorName = "acceptor"; - String acceptorId = "acceptorId"; - - ModKey key = new ModKey(acceptorName, acceptorId); - AcceptorKey accKey = new AcceptorKey(key); - - SolutionAcceptor acceptor = new GreedyAcceptance(1); - - typedMap.put(accKey, acceptor); - - assertEquals(acceptor, typedMap.get(accKey)); - - } - - @Test - public void testTypedMap2() { - VehicleRoutingAlgorithms.TypedMap typedMap = new VehicleRoutingAlgorithms.TypedMap(); - - String acceptorName = "acceptor"; - String acceptorId = "acceptorId"; - - String selectorName = "selector"; - String selectorId = "selectorId"; - - ModKey key = new ModKey(acceptorName, acceptorId); - AcceptorKey accKey = new AcceptorKey(key); - SolutionAcceptor acceptor = new GreedyAcceptance(1); - - SelectorKey selKey = new SelectorKey(new ModKey(selectorName, selectorId)); - SolutionSelector selector = new SelectBest(); - - typedMap.put(accKey, acceptor); - typedMap.put(selKey, selector); - - assertEquals(acceptor, typedMap.get(accKey)); - assertEquals(selector, typedMap.get(selKey)); - } - - @Test - public void testTypedMap3() { - VehicleRoutingAlgorithms.TypedMap typedMap = new VehicleRoutingAlgorithms.TypedMap(); - - String acceptorName = "acceptor"; - String acceptorId = "acceptorId"; - - String acceptorName2 = "acceptor2"; - String acceptorId2 = "acceptorId2"; - - String selectorName = "selector"; - String selectorId = "selectorId"; - - ModKey key = new ModKey(acceptorName, acceptorId); - AcceptorKey accKey = new AcceptorKey(key); - SolutionAcceptor acceptor = new GreedyAcceptance(1); - - SelectorKey selKey = new SelectorKey(new ModKey(selectorName, selectorId)); - SolutionSelector selector = new SelectBest(); - - AcceptorKey accKey2 = new AcceptorKey(new ModKey(acceptorName2, acceptorId2)); - SolutionAcceptor acceptor2 = new GreedyAcceptance(1); - - typedMap.put(accKey, acceptor); - typedMap.put(selKey, selector); - typedMap.put(accKey2, acceptor2); - - assertEquals(acceptor, typedMap.get(accKey)); - assertEquals(selector, typedMap.get(selKey)); - assertEquals(acceptor2, typedMap.get(accKey2)); - } - - @Test - public void testTypedMap4() { - VehicleRoutingAlgorithms.TypedMap typedMap = new VehicleRoutingAlgorithms.TypedMap(); - - String acceptorName = "acceptor"; - String acceptorId = "acceptorId"; - - ModKey key = new ModKey(acceptorName, acceptorId); - RuinStrategyKey accKey = new RuinStrategyKey(key); - RuinStrategy acceptor = new RuinStrategy() { - - @Override - public Collection ruin(Collection vehicleRoutes) { - return null; - } - - - @Override - public void addListener(RuinListener ruinListener) { - - } - - @Override - public void removeListener(RuinListener ruinListener) { - - } - - @Override - public Collection getListeners() { - return null; - } - - }; - - StrategyModuleKey moduleKey = new StrategyModuleKey(key); - SearchStrategyModule stratModule = new SearchStrategyModule() { - - @Override - public VehicleRoutingProblemSolution runAndGetSolution(VehicleRoutingProblemSolution vrpSolution) { - return null; - } - - @Override - public String getName() { - return null; - } - - @Override - public void addModuleListener( - SearchStrategyModuleListener moduleListener) { - - } - }; - - typedMap.put(accKey, acceptor); - typedMap.put(moduleKey, stratModule); - typedMap.put(moduleKey, stratModule); - - assertEquals(acceptor, typedMap.get(accKey)); - assertEquals(stratModule, typedMap.get(moduleKey)); - - } - - @Test - public void initialiseConstructionAlgoCorrectly() { - VehicleRoutingAlgorithms.createAlgorithm(vrp, config); - assertTrue(true); - } - - @Test - public void whenCreatingAlgorithm_nOfStrategiesIsCorrect() { - VehicleRoutingAlgorithm algo = VehicleRoutingAlgorithms.createAlgorithm(vrp, config); - assertEquals(3, algo.getSearchStrategyManager().getStrategies().size()); - } - - @Test - public void whenCreatingAlgorithm_nOfIterationsIsReadCorrectly() { - VehicleRoutingAlgorithm algo = VehicleRoutingAlgorithms.createAlgorithm(vrp, config); - assertEquals(10, algo.getMaxIterations()); - } - - @Test - public void whenCreatingAlgorithm_nOfStrategyModulesIsCorrect() { - VehicleRoutingAlgorithm algo = VehicleRoutingAlgorithms.createAlgorithm(vrp, config); - int nOfModules = 0; - for (SearchStrategy strat : algo.getSearchStrategyManager().getStrategies()) { - nOfModules += strat.getSearchStrategyModules().size(); - } - assertEquals(3, nOfModules); - } - - @Test - public void readerTest_whenReadingAlgoWithSchemaValidation_itReadsCorrectly() { - AlgorithmConfig algoConfig = new AlgorithmConfig(); - new AlgorithmConfigXmlReader(algoConfig).read("src/test/resources/algorithmConfig.xml"); - - } - - @Test - public void readerTest_whenReadingAlgoWithSchemaValidationWithoutIterations_itReadsCorrectly() { - AlgorithmConfig algoConfig = new AlgorithmConfig(); - new AlgorithmConfigXmlReader(algoConfig).read("src/test/resources/algorithmConfig_withoutIterations.xml"); - - } - -} diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/io/VrpXMLReaderTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/io/VrpXMLReaderTest.java deleted file mode 100644 index 7595677a..00000000 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/io/VrpXMLReaderTest.java +++ /dev/null @@ -1,644 +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.problem.io; - -import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem; -import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem.FleetSize; -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.activity.DeliverShipment; -import com.graphhopper.jsprit.core.problem.solution.route.activity.PickupService; -import com.graphhopper.jsprit.core.problem.solution.route.activity.PickupShipment; -import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity; -import com.graphhopper.jsprit.core.problem.vehicle.Vehicle; -import com.graphhopper.jsprit.core.util.Solutions; -import org.junit.Before; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; - -import static org.junit.Assert.*; - - -public class VrpXMLReaderTest { - - private String inFileName; - - @Before - public void doBefore() { - inFileName = "src/test/resources/finiteVrpForReaderTest.xml"; - } - - @Test - public void shouldReadNameOfService() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Service s = (Service) vrp.getJobs().get("1"); - assertTrue(s.getName().equals("cleaning")); - } - - @Test - public void shouldReadNameOfShipment() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("3"); - assertTrue(s.getName().equals("deliver-smth")); - } - - @Test - public void whenReadingVrp_problemTypeIsReadCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(FleetSize.FINITE, vrp.getFleetSize()); - } - - @Test - public void whenReadingVrp_vehiclesAreReadCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(5, vrp.getVehicles().size()); - assertTrue(idsInCollection(Arrays.asList("v1", "v2"), vrp.getVehicles())); - } - - @Test - public void whenReadingVrp_vehiclesAreReadCorrectly2() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v1 = getVehicle("v1", vrp.getVehicles()); - assertEquals(20, v1.getType().getCapacityDimensions().get(0)); - assertEquals(100.0, v1.getStartLocation().getCoordinate().getX(), 0.01); - assertEquals(0.0, v1.getEarliestDeparture(), 0.01); - assertEquals("depotLoc2", v1.getStartLocation().getId()); - assertNotNull(v1.getType()); - assertEquals("vehType", v1.getType().getTypeId()); - assertNotNull(v1.getStartLocation()); - assertEquals(1, v1.getStartLocation().getIndex()); - assertEquals(1000.0, v1.getLatestArrival(), 0.01); - } - - @Test - public void whenReadingVehicles_skill1ShouldBeAssigned() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v1 = getVehicle("v1", vrp.getVehicles()); - assertTrue(v1.getSkills().containsSkill("skill1")); - } - - @Test - public void whenReadingVehicles_skill2ShouldBeAssigned() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v1 = getVehicle("v1", vrp.getVehicles()); - assertTrue(v1.getSkills().containsSkill("skill2")); - } - - @Test - public void whenReadingVehicles_nuSkillsShouldBeCorrect() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v1 = getVehicle("v1", vrp.getVehicles()); - assertEquals(2, v1.getSkills().values().size()); - } - - @Test - public void whenReadingVehicles_nuSkillsOfV2ShouldBeCorrect() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v = getVehicle("v2", vrp.getVehicles()); - assertEquals(0, v.getSkills().values().size()); - } - - private Vehicle getVehicle(String string, Collection vehicles) { - for (Vehicle v : vehicles) if (string.equals(v.getId())) return v; - return null; - } - - private boolean idsInCollection(List asList, Collection vehicles) { - List ids = new ArrayList(asList); - for (Vehicle v : vehicles) { - if (ids.contains(v.getId())) ids.remove(v.getId()); - } - return ids.isEmpty(); - } - - @Test - public void whenReadingVrp_vehicleTypesAreReadCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(3, vrp.getTypes().size()); - } - - @Test - public void whenReadingVrpWithInfiniteSize_itReadsCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(FleetSize.FINITE, vrp.getFleetSize()); - } - - @Test - public void whenReadingJobs_nuOfJobsIsReadThemCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(4, vrp.getJobs().size()); - } - - @Test - public void whenReadingServices_itReadsThemCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - int servCounter = 0; - for (Job j : vrp.getJobs().values()) { - if (j instanceof Service) servCounter++; - } - assertEquals(2, servCounter); - } - - @Test - public void whenReadingService1_skill1ShouldBeAssigned() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Service s = (Service) vrp.getJobs().get("1"); - assertTrue(s.getRequiredSkills().containsSkill("skill1")); - } - - @Test - public void whenReadingService1_skill2ShouldBeAssigned() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Service s = (Service) vrp.getJobs().get("1"); - assertTrue(s.getRequiredSkills().containsSkill("skill2")); - } - - @Test - public void whenReadingService1_nuSkillsShouldBeCorrect() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Service s = (Service) vrp.getJobs().get("1"); - assertEquals(2, s.getRequiredSkills().values().size()); - } - - @Test - public void whenReadingService2_nuSkillsOfV2ShouldBeCorrect() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Service s = (Service) vrp.getJobs().get("2"); - assertEquals(0, s.getRequiredSkills().values().size()); - } - - @Test - public void whenReadingShipments_itReadsThemCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - int shipCounter = 0; - for (Job j : vrp.getJobs().values()) { - if (j instanceof Shipment) shipCounter++; - } - assertEquals(2, shipCounter); - } - - @Test - public void whenReadingShipment3_skill1ShouldBeAssigned() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("3"); - assertTrue(s.getRequiredSkills().containsSkill("skill1")); - } - - @Test - public void whenReadingShipment3_skill2ShouldBeAssigned() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("3"); - assertTrue(s.getRequiredSkills().containsSkill("skill2")); - } - - @Test - public void whenReadingShipment3_nuSkillsShouldBeCorrect() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("3"); - assertEquals(2, s.getRequiredSkills().values().size()); - } - - @Test - public void whenReadingShipment4_nuSkillsOfV2ShouldBeCorrect() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("4"); - assertEquals(0, s.getRequiredSkills().values().size()); - } - - @Test - public void whenReadingServices_capOfService1IsReadCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Service s1 = (Service) vrp.getJobs().get("1"); - assertEquals(1, s1.getSize().get(0)); - } - - @Test - public void whenReadingServices_durationOfService1IsReadCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Service s1 = (Service) vrp.getJobs().get("1"); - assertEquals(10.0, s1.getServiceDuration(), 0.01); - } - - @Test - public void whenReadingServices_twOfService1IsReadCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Service s1 = (Service) vrp.getJobs().get("1"); - assertEquals(0.0, s1.getTimeWindow().getStart(), 0.01); - assertEquals(4000.0, s1.getTimeWindow().getEnd(), 0.01); - } - - @Test - public void whenReadingServices_typeOfService1IsReadCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Service s1 = (Service) vrp.getJobs().get("1"); - assertEquals("service", s1.getType()); - } - - @Test - public void whenReadingFile_v2MustNotReturnToDepot() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v = getVehicle("v2", vrp.getVehicles()); - assertFalse(v.isReturnToDepot()); - } - - @Test - public void whenReadingFile_v3HasTheCorrectStartLocation() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v3 = getVehicle("v3", vrp.getVehicles()); - assertEquals("startLoc", v3.getStartLocation().getId()); - assertNotNull(v3.getEndLocation()); - assertEquals(4, v3.getEndLocation().getIndex()); - } - - @Test - public void whenReadingFile_v3HasTheCorrectEndLocation() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v3 = getVehicle("v3", vrp.getVehicles()); - assertEquals("endLoc", v3.getEndLocation().getId()); - } - - @Test - public void whenReadingFile_v3HasTheCorrectEndLocationCoordinate() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v3 = getVehicle("v3", vrp.getVehicles()); - assertEquals(1000.0, v3.getEndLocation().getCoordinate().getX(), 0.01); - assertEquals(2000.0, v3.getEndLocation().getCoordinate().getY(), 0.01); - } - - @Test - public void whenReadingFile_v3HasTheCorrectStartLocationCoordinate() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v3 = getVehicle("v3", vrp.getVehicles()); - assertEquals(10.0, v3.getStartLocation().getCoordinate().getX(), 0.01); - assertEquals(100.0, v3.getStartLocation().getCoordinate().getY(), 0.01); - } - - @Test - public void whenReadingFile_v3HasTheCorrectLocationCoordinate() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v3 = getVehicle("v3", vrp.getVehicles()); - assertEquals(10.0, v3.getStartLocation().getCoordinate().getX(), 0.01); - assertEquals(100.0, v3.getStartLocation().getCoordinate().getY(), 0.01); - } - - @Test - public void whenReadingFile_v3HasTheCorrectLocationId() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v3 = getVehicle("v3", vrp.getVehicles()); - assertEquals("startLoc", v3.getStartLocation().getId()); - } - - @Test - public void whenReadingFile_v4HasTheCorrectStartLocation() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v = getVehicle("v4", vrp.getVehicles()); - assertEquals("startLoc", v.getStartLocation().getId()); - } - - @Test - public void whenReadingFile_v4HasTheCorrectEndLocation() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v = getVehicle("v4", vrp.getVehicles()); - assertEquals("endLoc", v.getEndLocation().getId()); - } - - @Test - public void whenReadingFile_v4HasTheCorrectEndLocationCoordinate() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v = getVehicle("v4", vrp.getVehicles()); - assertEquals(1000.0, v.getEndLocation().getCoordinate().getX(), 0.01); - assertEquals(2000.0, v.getEndLocation().getCoordinate().getY(), 0.01); - } - - @Test - public void whenReadingFile_v4HasTheCorrectStartLocationCoordinate() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v = getVehicle("v4", vrp.getVehicles()); - assertEquals(10.0, v.getStartLocation().getCoordinate().getX(), 0.01); - assertEquals(100.0, v.getStartLocation().getCoordinate().getY(), 0.01); - } - - @Test - public void whenReadingFile_v4HasTheCorrectLocationCoordinate() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v = getVehicle("v4", vrp.getVehicles()); - assertEquals(10.0, v.getStartLocation().getCoordinate().getX(), 0.01); - assertEquals(100.0, v.getStartLocation().getCoordinate().getY(), 0.01); - } - - @Test - public void whenReadingFile_v4HasTheCorrectLocationId() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v = getVehicle("v4", vrp.getVehicles()); - assertEquals("startLoc", v.getStartLocation().getId()); - } - - @Test - public void whenReadingJobs_capOfShipment3IsReadCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("3"); - assertEquals(10, s.getSize().get(0)); - } - - @Test - public void whenReadingJobs_pickupServiceTimeOfShipment3IsReadCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("3"); - assertEquals(10.0, s.getPickupServiceTime(), 0.01); - } - - @Test - public void whenReadingJobs_pickupTimeWindowOfShipment3IsReadCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("3"); - assertEquals(1000.0, s.getPickupTimeWindow().getStart(), 0.01); - assertEquals(4000.0, s.getPickupTimeWindow().getEnd(), 0.01); - } - - @Test - public void whenReadingJobs_deliveryTimeWindowOfShipment3IsReadCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("3"); - assertEquals(6000.0, s.getDeliveryTimeWindow().getStart(), 0.01); - assertEquals(10000.0, s.getDeliveryTimeWindow().getEnd(), 0.01); - } - - @Test - public void whenReadingJobs_deliveryServiceTimeOfShipment3IsReadCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("3"); - assertEquals(100.0, s.getDeliveryServiceTime(), 0.01); - } - - @Test - public void whenReadingJobs_deliveryCoordShipment3IsReadCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("3"); - assertEquals(10.0, s.getDeliveryLocation().getCoordinate().getX(), 0.01); - assertEquals(0.0, s.getDeliveryLocation().getCoordinate().getY(), 0.01); - } - - @Test - public void whenReadingJobs_pickupCoordShipment3IsReadCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("3"); - assertEquals(10.0, s.getPickupLocation().getCoordinate().getX(), 0.01); - assertEquals(10.0, s.getPickupLocation().getCoordinate().getY(), 0.01); - } - - @Test - public void whenReadingJobs_deliveryIdShipment3IsReadCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("3"); - assertEquals("i(9,9)", s.getDeliveryLocation().getId()); - } - - @Test - public void whenReadingJobs_pickupIdShipment3IsReadCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("3"); - assertEquals("i(3,9)", s.getPickupLocation().getId()); - } - - @Test - public void whenReadingJobs_pickupLocationIdShipment4IsReadCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("4"); - assertEquals("[x=10.0][y=10.0]", s.getPickupLocation().getId()); - } - - @Test - public void whenReadingJobs_deliveryLocationIdShipment4IsReadCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("4"); - assertEquals("[x=10.0][y=0.0]", s.getDeliveryLocation().getId()); - } - - @Test - public void whenReadingJobs_pickupServiceTimeOfShipment4IsReadCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("4"); - assertEquals(0.0, s.getPickupServiceTime(), 0.01); - } - - @Test - public void whenReadingJobs_deliveryServiceTimeOfShipment4IsReadCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Shipment s = (Shipment) vrp.getJobs().get("4"); - assertEquals(100.0, s.getDeliveryServiceTime(), 0.01); - } - - @Test - public void whenReadingFile_v5AndItsTypeHasTheCorrectCapacityDimensionValues() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read(inFileName); - VehicleRoutingProblem vrp = builder.build(); - Vehicle v = getVehicle("v5", vrp.getVehicles()); - assertEquals(100, v.getType().getCapacityDimensions().get(0)); - assertEquals(1000, v.getType().getCapacityDimensions().get(1)); - assertEquals(10000, v.getType().getCapacityDimensions().get(2)); - assertEquals(0, v.getType().getCapacityDimensions().get(3)); - assertEquals(0, v.getType().getCapacityDimensions().get(5)); - assertEquals(100000, v.getType().getCapacityDimensions().get(10)); - } - - @Test - public void whenReadingInitialRouteWithShipment4_thisShipmentShouldNotAppearInJobMap() { //since it is not part of the problem anymore - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml"); - VehicleRoutingProblem vrp = builder.build(); - assertFalse(vrp.getJobs().containsKey("4")); - } - - @Test - public void whenReadingInitialRouteWithDepTime10_departureTimeOfRouteShouldBeReadCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml"); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(10., vrp.getInitialVehicleRoutes().iterator().next().getDepartureTime(), 0.01); - } - - @Test - public void whenReadingInitialRoute_nuInitialRoutesShouldBeCorrect() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml"); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(1, vrp.getInitialVehicleRoutes().size()); - } - - @Test - public void whenReadingInitialRoute_nuActivitiesShouldBeCorrect() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml"); - VehicleRoutingProblem vrp = builder.build(); - assertEquals(2, vrp.getInitialVehicleRoutes().iterator().next().getActivities().size()); - } - - @Test - public void testRead_ifReaderIsCalled_itReadsSuccessfullyV2() { - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - ArrayList solutions = new ArrayList(); - new VrpXMLReader(vrpBuilder, solutions).read("src/test/resources/finiteVrpWithShipmentsAndSolution.xml"); - VehicleRoutingProblem vrp = vrpBuilder.build(); - assertEquals(4, vrp.getJobs().size()); - assertEquals(1, solutions.size()); - - assertEquals(1, solutions.get(0).getRoutes().size()); - List activities = solutions.get(0).getRoutes().iterator().next().getTourActivities().getActivities(); - assertEquals(4, activities.size()); - assertTrue(activities.get(0) instanceof PickupService); - assertTrue(activities.get(1) instanceof PickupService); - assertTrue(activities.get(2) instanceof PickupShipment); - assertTrue(activities.get(3) instanceof DeliverShipment); - } - - @Test - public void testRead_ifReaderIsCalled_itReadsSuccessfully() { - new VrpXMLReader(VehicleRoutingProblem.Builder.newInstance(), new ArrayList()).read("src/test/resources/lui-shen-solution.xml"); - assertTrue(true); - } - - - @Test - public void unassignedJobShouldBeRead() { - VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); - ArrayList solutions = new ArrayList(); - new VrpXMLReader(vrpBuilder, solutions).read("src/test/resources/finiteVrpWithShipmentsAndSolution.xml"); - - VehicleRoutingProblemSolution solution = Solutions.bestOf(solutions); - assertEquals(1, solution.getUnassignedJobs().size()); - assertEquals("4", solution.getUnassignedJobs().iterator().next().getId()); - } - -// @Test -// public void solutionListShouldBeEmpty(){ -// VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance(); -// ArrayList solutions = new ArrayList(); -// new VrpXMLReader(vrpBuilder, solutions).read("src/test/resources/finiteVrpforReaderTest.xml"); -// assertTrue(solutions.isEmpty()); -// } -} diff --git a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/io/VrpXMLWriterTest.java b/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/io/VrpXMLWriterTest.java deleted file mode 100644 index 13aad736..00000000 --- a/jsprit-core/src/test/java/com/graphhopper/jsprit/core/problem/io/VrpXMLWriterTest.java +++ /dev/null @@ -1,1024 +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.problem.io; - -import com.graphhopper.jsprit.core.problem.Location; -import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem; -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.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.Before; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; - -import static org.junit.Assert.*; - -public class VrpXMLWriterTest { - - private String infileName; - - @Before - public void doBefore() { - infileName = "src/test/resources/infiniteWriterV2Test.xml"; - } - - @Test - public void whenWritingInfiniteVrp_itWritesCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - builder.setFleetSize(VehicleRoutingProblem.FleetSize.INFINITE); - VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleImpl vehicle = VehicleImpl.Builder.newInstance("myVehicle").setStartLocation(TestUtils.loc("loc")).setType(type).build(); - builder.addVehicle(vehicle); - VehicleRoutingProblem vrp = builder.build(); - new VrpXMLWriter(vrp, null).write(infileName); - } - - @Test - public void whenWritingFiniteVrp_itWritesCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - builder.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE); - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); - builder.addVehicle(v1); - builder.addVehicle(v2); - VehicleRoutingProblem vrp = builder.build(); - new VrpXMLWriter(vrp, null).write(infileName); - } - - @Test - public void t() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - builder.setFleetSize(VehicleRoutingProblem.FleetSize.FINITE); - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); - builder.addVehicle(v1); - builder.addVehicle(v2); - VehicleRoutingProblem vrp = builder.build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - } - - @Test - public void whenWritingServices_itWritesThemCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); - - builder.addVehicle(v1); - builder.addVehicle(v2); - - - Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); - Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc2")).setServiceTime(4.0).build(); - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - assertEquals(2, readVrp.getJobs().size()); - - Service s1_read = (Service) vrp.getJobs().get("1"); - assertEquals("1", s1_read.getId()); - Assert.assertEquals("loc", s1_read.getLocation().getId()); - assertEquals("service", s1_read.getType()); - assertEquals(2.0, s1_read.getServiceDuration(), 0.01); - } - - @Test - public void shouldWriteNameOfService() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - Service s1 = Service.Builder.newInstance("1").setName("cleaning").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); - - VehicleRoutingProblem vrp = builder.addJob(s1).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - Service s1_read = (Service) readVrp.getJobs().get("1"); - assertTrue(s1_read.getName().equals("cleaning")); - } - - @Test - public void shouldWriteNameOfShipment() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - Location pickLocation = Location.Builder.newInstance().setId("pick").setIndex(1).build(); - Shipment s1 = Shipment.Builder.newInstance("1").setName("cleaning") - .setPickupLocation(pickLocation) - .setDeliveryLocation(TestUtils.loc("del")).build(); - - VehicleRoutingProblem vrp = builder.addJob(s1).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - Shipment s1_read = (Shipment) readVrp.getJobs().get("1"); - assertTrue(s1_read.getName().equals("cleaning")); - Assert.assertEquals(1, s1_read.getPickupLocation().getIndex()); - } - - @Test - public void whenWritingServicesWithSeveralCapacityDimensions_itWritesThemCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - Service s1 = Service.Builder.newInstance("1") - .addSizeDimension(0, 20) - .addSizeDimension(1, 200) - .setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); - Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc2")).setServiceTime(4.0).build(); - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - assertEquals(2, readVrp.getJobs().size()); - - Service s1_read = (Service) vrp.getJobs().get("1"); - - Assert.assertEquals(2, s1_read.getSize().getNuOfDimensions()); - Assert.assertEquals(20, s1_read.getSize().get(0)); - Assert.assertEquals(200, s1_read.getSize().get(1)); - - } - - @Test - public void whenWritingShipments_readingThemAgainMustReturnTheWrittenLocationIdsOfS1() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); - - builder.addVehicle(v1); - builder.addVehicle(v2); - - Shipment s1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 10) - .setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()) - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).build(); - Shipment s2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 20) - .setPickupLocation(Location.Builder.newInstance().setId("pickLocation").build()) - .setDeliveryLocation(TestUtils.loc("delLocation")).setPickupTimeWindow(TimeWindow.newInstance(5, 6)) - .setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build(); - - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - assertEquals(2, readVrp.getJobs().size()); - - Assert.assertEquals("pickLoc", ((Shipment) readVrp.getJobs().get("1")).getPickupLocation().getId()); - Assert.assertEquals("delLoc", ((Shipment) readVrp.getJobs().get("1")).getDeliveryLocation().getId()); - - } - - @Test - public void whenWritingShipments_readingThemAgainMustReturnTheWrittenPickupTimeWindowsOfS1() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); - - builder.addVehicle(v1); - builder.addVehicle(v2); - - Shipment s1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 10) - .setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()) - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).build(); - Shipment s2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 20) - .setPickupLocation(Location.Builder.newInstance().setId("pickLocation").build()) - .setDeliveryLocation(TestUtils.loc("delLocation")).setPickupTimeWindow(TimeWindow.newInstance(5, 6)) - .setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build(); - - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - assertEquals(2, readVrp.getJobs().size()); - - Assert.assertEquals(1.0, ((Shipment) readVrp.getJobs().get("1")).getPickupTimeWindow().getStart(), 0.01); - Assert.assertEquals(2.0, ((Shipment) readVrp.getJobs().get("1")).getPickupTimeWindow().getEnd(), 0.01); - - - } - - @Test - public void whenWritingShipments_readingThemAgainMustReturnTheWrittenDeliveryTimeWindowsOfS1() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); - - builder.addVehicle(v1); - builder.addVehicle(v2); - - Shipment s1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 10) - .setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()) - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).build(); - Shipment s2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 20) - .setPickupLocation(Location.Builder.newInstance().setId("pickLocation").build()) - .setDeliveryLocation(TestUtils.loc("delLocation")).setPickupTimeWindow(TimeWindow.newInstance(5, 6)) - .setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build(); - - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - assertEquals(2, readVrp.getJobs().size()); - - Assert.assertEquals(3.0, ((Shipment) readVrp.getJobs().get("1")).getDeliveryTimeWindow().getStart(), 0.01); - Assert.assertEquals(4.0, ((Shipment) readVrp.getJobs().get("1")).getDeliveryTimeWindow().getEnd(), 0.01); - - } - - @Test - public void whenWritingShipments_readingThemAgainMustReturnTheWrittenDeliveryServiceTimeOfS1() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); - - builder.addVehicle(v1); - builder.addVehicle(v2); - - Shipment s1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 10) - .setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()) - .setDeliveryLocation(TestUtils.loc("delLoc")).setPickupTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50).build(); - Shipment s2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 20) - .setPickupLocation(Location.Builder.newInstance().setId("pickLocation").build()) - .setDeliveryLocation(TestUtils.loc("delLocation")).setPickupTimeWindow(TimeWindow.newInstance(5, 6)) - .setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build(); - - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - assertEquals(2, readVrp.getJobs().size()); - - assertEquals(100.0, ((Shipment) readVrp.getJobs().get("1")).getPickupServiceTime(), 0.01); - assertEquals(50.0, ((Shipment) readVrp.getJobs().get("1")).getDeliveryServiceTime(), 0.01); - - } - - @Test - public void whenWritingShipments_readingThemAgainMustReturnTheWrittenLocationIdOfS1() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); - - builder.addVehicle(v1); - builder.addVehicle(v2); - - Shipment s1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 10) - .setPickupLocation(TestUtils.loc(Coordinate.newInstance(1, 2))).setDeliveryLocation(TestUtils.loc("delLoc")).setPickupTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50).build(); - Shipment s2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 20) - .setPickupLocation(Location.Builder.newInstance().setId("pickLocation").build()) - .setDeliveryLocation(TestUtils.loc("delLocation")).setPickupTimeWindow(TimeWindow.newInstance(5, 6)) - .setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build(); - - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - assertEquals(2, readVrp.getJobs().size()); - - Assert.assertEquals("[x=1.0][y=2.0]", ((Shipment) readVrp.getJobs().get("1")).getPickupLocation().getId()); - } - - @Test - public void whenWritingVehicles_vehShouldHave2Skills() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleImpl v = VehicleImpl.Builder.newInstance("v1").addSkill("SKILL5").addSkill("skill1").addSkill("Skill2") - .setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - builder.addVehicle(v); - - VehicleRoutingProblem vrp = builder.build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - Vehicle veh1 = getVehicle("v1", readVrp); - - Assert.assertEquals(3, veh1.getSkills().values().size()); - } - - @Test - public void whenWritingVehicles_vehShouldContain_skill5() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleImpl v = VehicleImpl.Builder.newInstance("v1").addSkill("SKILL5").addSkill("skill1").addSkill("Skill2") - .setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - builder.addVehicle(v); - - VehicleRoutingProblem vrp = builder.build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - Vehicle veh1 = getVehicle("v1", readVrp); - - assertTrue(veh1.getSkills().containsSkill("skill5")); - } - - @Test - public void whenWritingVehicles_vehShouldContain_skill1() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleImpl v = VehicleImpl.Builder.newInstance("v1").addSkill("SKILL5").addSkill("skill1").addSkill("Skill2") - .setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - builder.addVehicle(v); - - VehicleRoutingProblem vrp = builder.build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - Vehicle veh1 = getVehicle("v1", readVrp); - - assertTrue(veh1.getSkills().containsSkill("skill1")); - } - - @Test - public void whenWritingVehicles_vehShouldContain_skill2() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleImpl v = VehicleImpl.Builder.newInstance("v1").addSkill("SKILL5").addSkill("skill1").addSkill("Skill2") - .setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - builder.addVehicle(v); - - VehicleRoutingProblem vrp = builder.build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - Vehicle veh1 = getVehicle("v1", readVrp); - - assertTrue(veh1.getSkills().containsSkill("skill2")); - } - - @Test - public void whenWritingVehicles_vehShouldHave0Skills() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleImpl v = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - builder.addVehicle(v); - - VehicleRoutingProblem vrp = builder.build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - Vehicle veh = getVehicle("v1", readVrp); - - Assert.assertEquals(0, veh.getSkills().values().size()); - } - - private Vehicle getVehicle(String v1, VehicleRoutingProblem readVrp) { - for (Vehicle v : readVrp.getVehicles()) { - if (v.getId().equals(v1)) return v; - } - return null; - } - - @Test - public void whenWritingShipments_shipmentShouldHaveCorrectNuSkills() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - Shipment s = Shipment.Builder.newInstance("1").addRequiredSkill("skill1").addRequiredSkill("skill2").addRequiredSkill("skill3") - .addSizeDimension(0, 10) - .setPickupLocation(TestUtils.loc(Coordinate.newInstance(1, 2))) - .setDeliveryLocation(TestUtils.loc("delLoc", Coordinate.newInstance(5, 6))) - .setPickupTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50).build(); - - VehicleRoutingProblem vrp = builder.addJob(s).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - - Assert.assertEquals(3, readVrp.getJobs().get("1").getRequiredSkills().values().size()); - } - - @Test - public void whenWritingShipments_shipmentShouldContain_skill1() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - Shipment s = Shipment.Builder.newInstance("1").addRequiredSkill("skill1").addRequiredSkill("skill2").addRequiredSkill("skill3") - .addSizeDimension(0, 10) - .setPickupLocation(TestUtils.loc(Coordinate.newInstance(1, 2))) - .setDeliveryLocation(TestUtils.loc("delLoc", Coordinate.newInstance(5, 6))) - .setPickupTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50).build(); - - VehicleRoutingProblem vrp = builder.addJob(s).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - - assertTrue(readVrp.getJobs().get("1").getRequiredSkills().containsSkill("skill1")); - } - - @Test - public void whenWritingShipments_shipmentShouldContain_skill2() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - Shipment s = Shipment.Builder.newInstance("1").addRequiredSkill("skill1").addRequiredSkill("Skill2").addRequiredSkill("skill3") - .addSizeDimension(0, 10) - .setPickupLocation(TestUtils.loc(Coordinate.newInstance(1, 2))) - .setDeliveryLocation(TestUtils.loc("delLoc", Coordinate.newInstance(5, 6))) - .setPickupTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50).build(); - - VehicleRoutingProblem vrp = builder.addJob(s).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - - assertTrue(readVrp.getJobs().get("1").getRequiredSkills().containsSkill("skill2")); - } - - @Test - public void whenWritingShipments_shipmentShouldContain_skill3() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - Shipment s = Shipment.Builder.newInstance("1").addRequiredSkill("skill1").addRequiredSkill("Skill2").addRequiredSkill("skill3") - .addSizeDimension(0, 10) - .setPickupLocation(TestUtils.loc(Coordinate.newInstance(1, 2))) - .setDeliveryLocation(TestUtils.loc("delLoc", Coordinate.newInstance(5, 6))) - .setPickupTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50).build(); - - VehicleRoutingProblem vrp = builder.addJob(s).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - - assertTrue(readVrp.getJobs().get("1").getRequiredSkills().containsSkill("skill3")); - } - - @Test - public void whenWritingShipments_readingThemAgainMustReturnTheWrittenLocationCoordinateOfS1() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); - - builder.addVehicle(v1); - builder.addVehicle(v2); - - Shipment s1 = Shipment.Builder.newInstance("1").addSizeDimension(0, 10).setPickupLocation(TestUtils.loc(Coordinate.newInstance(1, 2))) - .setDeliveryLocation(TestUtils.loc("delLoc", Coordinate.newInstance(5, 6))) - .setPickupTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50).build(); - Shipment s2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 20) - .setPickupLocation(Location.Builder.newInstance().setId("pickLocation").build()) - .setDeliveryLocation(TestUtils.loc("delLocation")) - .setPickupTimeWindow(TimeWindow.newInstance(5, 6)) - .setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build(); - - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - assertEquals(2, readVrp.getJobs().size()); - - Assert.assertEquals(1.0, ((Shipment) readVrp.getJobs().get("1")).getPickupLocation().getCoordinate().getX(), 0.01); - Assert.assertEquals(2.0, ((Shipment) readVrp.getJobs().get("1")).getPickupLocation().getCoordinate().getY(), 0.01); - - Assert.assertEquals(5.0, ((Shipment) readVrp.getJobs().get("1")).getDeliveryLocation().getCoordinate().getX(), 0.01); - Assert.assertEquals(6.0, ((Shipment) readVrp.getJobs().get("1")).getDeliveryLocation().getCoordinate().getY(), 0.01); - } - - @Test - public void whenWritingShipmentWithSeveralCapacityDimension_itShouldWriteAndReadItCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - Shipment s1 = Shipment.Builder.newInstance("1") - .setPickupLocation(TestUtils.loc(Coordinate.newInstance(1, 2))) - .setDeliveryLocation(TestUtils.loc("delLoc", Coordinate.newInstance(5, 6))) - .setPickupTimeWindow(TimeWindow.newInstance(1, 2)) - .setDeliveryTimeWindow(TimeWindow.newInstance(3, 4)).setPickupServiceTime(100).setDeliveryServiceTime(50) - .addSizeDimension(0, 10) - .addSizeDimension(2, 100) - .build(); - - Shipment s2 = Shipment.Builder.newInstance("2").addSizeDimension(0, 20) - .setPickupLocation(Location.Builder.newInstance().setId("pickLocation").build()) - .setDeliveryLocation(TestUtils.loc("delLocation")).setPickupTimeWindow(TimeWindow.newInstance(5, 6)) - .setDeliveryTimeWindow(TimeWindow.newInstance(7, 8)).build(); - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - - Assert.assertEquals(3, (readVrp.getJobs().get("1")).getSize().getNuOfDimensions()); - Assert.assertEquals(10, (readVrp.getJobs().get("1")).getSize().get(0)); - Assert.assertEquals(0, (readVrp.getJobs().get("1")).getSize().get(1)); - Assert.assertEquals(100, (readVrp.getJobs().get("1")).getSize().get(2)); - - Assert.assertEquals(1, (readVrp.getJobs().get("2")).getSize().getNuOfDimensions()); - Assert.assertEquals(20, (readVrp.getJobs().get("2")).getSize().get(0)); - } - - @Test - public void whenWritingVehicleV1_itsStartLocationMustBeWrittenCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); - - builder.addVehicle(v1); - builder.addVehicle(v2); - - Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); - Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc2")).setServiceTime(4.0).build(); - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - - Vehicle v = getVehicle("v1", readVrp.getVehicles()); - Assert.assertEquals("loc", v.getStartLocation().getId()); - Assert.assertEquals("loc", v.getEndLocation().getId()); - - } - - @Test - public void whenWritingService_itShouldHaveTheCorrectNuSkills() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - Service s = Service.Builder.newInstance("1").addRequiredSkill("sKill1").addRequiredSkill("skill2").addSizeDimension(0, 1) - .setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); - - VehicleRoutingProblem vrp = builder.addJob(s).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - - Assert.assertEquals(2, readVrp.getJobs().get("1").getRequiredSkills().values().size()); - } - - @Test - public void whenWritingService_itShouldContain_skill1() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - Service s = Service.Builder.newInstance("1").addRequiredSkill("sKill1").addRequiredSkill("skill2").addSizeDimension(0, 1) - .setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); - - VehicleRoutingProblem vrp = builder.addJob(s).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - - assertTrue(readVrp.getJobs().get("1").getRequiredSkills().containsSkill("skill1")); - } - - @Test - public void whenWritingService_itShouldContain_skill2() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - Service s = Service.Builder.newInstance("1").addRequiredSkill("sKill1").addRequiredSkill("skill2").addSizeDimension(0, 1) - .setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); - - VehicleRoutingProblem vrp = builder.addJob(s).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - - assertTrue(readVrp.getJobs().get("1").getRequiredSkills().containsSkill("skill2")); - } - - @Test - public void whenWritingVehicleV1_itDoesNotReturnToDepotMustBeWrittenCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setReturnToDepot(false).setStartLocation(TestUtils.loc("loc")) - .setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); - - builder.addVehicle(v1); - builder.addVehicle(v2); - - Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); - Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc2")).setServiceTime(4.0).build(); - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - - Vehicle v = getVehicle("v1", readVrp.getVehicles()); - assertFalse(v.isReturnToDepot()); - } - - @Test - public void whenWritingVehicleV1_readingAgainAssignsCorrectType() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setReturnToDepot(false).setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); - - builder.addVehicle(v1); - builder.addVehicle(v2); - - Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); - Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc2")).setServiceTime(4.0).build(); - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - - Vehicle v = getVehicle("v1", readVrp.getVehicles()); - assertEquals("vehType", v.getType().getTypeId()); - } - - @Test - public void whenWritingVehicleV2_readingAgainAssignsCorrectType() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setReturnToDepot(false).setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(TestUtils.loc("loc")).setType(type2).build(); - - builder.addVehicle(v1); - builder.addVehicle(v2); - - Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); - Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc2")).setServiceTime(4.0).build(); - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - - Vehicle v = getVehicle("v2", readVrp.getVehicles()); - assertEquals("vehType2", v.getType().getTypeId()); - Assert.assertEquals(200, v.getType().getCapacityDimensions().get(0)); - - } - - @Test - public void whenWritingVehicleV2_readingItsLocationsAgainReturnsCorrectLocations() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setReturnToDepot(false).setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2") - .setStartLocation(TestUtils.loc("startLoc", Coordinate.newInstance(1, 2))) - .setEndLocation(TestUtils.loc("endLoc", Coordinate.newInstance(4, 5))).setType(type2).build(); - - builder.addVehicle(v1); - builder.addVehicle(v2); - - Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); - Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc2")).setServiceTime(4.0).build(); - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - - Vehicle v = getVehicle("v2", readVrp.getVehicles()); - Assert.assertEquals("startLoc", v.getStartLocation().getId()); - Assert.assertEquals("endLoc", v.getEndLocation().getId()); - } - - @Test - public void whenWritingVehicleV2_readingItsLocationsCoordsAgainReturnsCorrectLocationsCoords() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("vehType2").addCapacityDimension(0, 200).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setReturnToDepot(false) - .setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2") - .setStartLocation(TestUtils.loc("startLoc", Coordinate.newInstance(1, 2))) - .setEndLocation(TestUtils.loc("endLoc", Coordinate.newInstance(4, 5))).setType(type2).build(); - - builder.addVehicle(v1); - builder.addVehicle(v2); - - Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); - Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc2")).setServiceTime(4.0).build(); - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - - Vehicle v = getVehicle("v2", readVrp.getVehicles()); - Assert.assertEquals(1.0, v.getStartLocation().getCoordinate().getX(), 0.01); - Assert.assertEquals(2.0, v.getStartLocation().getCoordinate().getY(), 0.01); - - Assert.assertEquals(4.0, v.getEndLocation().getCoordinate().getX(), 0.01); - Assert.assertEquals(5.0, v.getEndLocation().getCoordinate().getY(), 0.01); - } - - @Test - public void whenWritingVehicleWithSeveralCapacityDimensions_itShouldBeWrittenAndRereadCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("type") - .addCapacityDimension(0, 100) - .addCapacityDimension(1, 1000) - .addCapacityDimension(2, 10000) - .build(); - - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v") - .setStartLocation(TestUtils.loc("startLoc", Coordinate.newInstance(1, 2))) - .setEndLocation(TestUtils.loc("endLoc", Coordinate.newInstance(4, 5))).setType(type2).build(); - builder.addVehicle(v2); - - VehicleRoutingProblem vrp = builder.build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - - Vehicle v = getVehicle("v", readVrp.getVehicles()); - Assert.assertEquals(3, v.getType().getCapacityDimensions().getNuOfDimensions()); - Assert.assertEquals(100, v.getType().getCapacityDimensions().get(0)); - Assert.assertEquals(1000, v.getType().getCapacityDimensions().get(1)); - Assert.assertEquals(10000, v.getType().getCapacityDimensions().get(2)); - } - - @Test - public void whenWritingVehicleWithSeveralCapacityDimensions_itShouldBeWrittenAndRereadCorrectlyV2() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("type") - .addCapacityDimension(0, 100) - .addCapacityDimension(1, 1000) - .addCapacityDimension(10, 10000) - .build(); - - VehicleImpl v2 = VehicleImpl.Builder.newInstance("v") - .setStartLocation(TestUtils.loc("startLoc", Coordinate.newInstance(1, 2))) - .setEndLocation(TestUtils.loc("endLoc", Coordinate.newInstance(4, 5))).setType(type2).build(); - builder.addVehicle(v2); - - VehicleRoutingProblem vrp = builder.build(); - new VrpXMLWriter(vrp, null).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(vrpToReadBuilder, null).read(infileName); - VehicleRoutingProblem readVrp = vrpToReadBuilder.build(); - - Vehicle v = getVehicle("v", readVrp.getVehicles()); - Assert.assertEquals(11, v.getType().getCapacityDimensions().getNuOfDimensions()); - Assert.assertEquals(0, v.getType().getCapacityDimensions().get(9)); - Assert.assertEquals(10000, v.getType().getCapacityDimensions().get(10)); - } - - private Vehicle getVehicle(String string, Collection vehicles) { - for (Vehicle v : vehicles) if (string.equals(v.getId())) return v; - return null; - } - - @Test - public void whenWritingAndReadingInitialRouteWithShipment4_thisShipmentShouldNotAppearInJobMap() { //since it is not part of the problem anymore - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml"); - VehicleRoutingProblem vrp = builder.build(); - - new VrpXMLWriter(vrp).write("src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml"); - - VehicleRoutingProblem.Builder newBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(newBuilder).read("src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml"); - VehicleRoutingProblem newVrp = newBuilder.build(); - - assertFalse(newVrp.getJobs().containsKey("4")); - } - - @Test - public void whenReadingInitialRouteWithDepTime10_departureTimeOfRouteShouldBeReadCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml"); - VehicleRoutingProblem vrp = builder.build(); - - new VrpXMLWriter(vrp).write("src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml"); - - VehicleRoutingProblem.Builder newBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(newBuilder).read("src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml"); - VehicleRoutingProblem newVrp = newBuilder.build(); - - Assert.assertEquals(10., newVrp.getInitialVehicleRoutes().iterator().next().getDepartureTime(), 0.01); - } - - @Test - public void whenReadingInitialRoute_nuInitialRoutesShouldBeCorrect() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml"); - VehicleRoutingProblem vrp = builder.build(); - - new VrpXMLWriter(vrp).write("src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml"); - - VehicleRoutingProblem.Builder newBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(newBuilder).read("src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml"); - VehicleRoutingProblem newVrp = newBuilder.build(); - - - assertEquals(1, newVrp.getInitialVehicleRoutes().size()); - } - - @Test - public void whenReadingInitialRoute_nuActivitiesShouldBeCorrect() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(builder, null).read("src/test/resources/finiteVrpWithInitialSolutionForReaderTest.xml"); - VehicleRoutingProblem vrp = builder.build(); - - new VrpXMLWriter(vrp).write("src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml"); - - VehicleRoutingProblem.Builder newBuilder = VehicleRoutingProblem.Builder.newInstance(); - new VrpXMLReader(newBuilder).read("src/test/resources/finiteVrpWithInitialSolutionForWriterTest.xml"); - VehicleRoutingProblem newVrp = newBuilder.build(); - - - Assert.assertEquals(2, newVrp.getInitialVehicleRoutes().iterator().next().getActivities().size()); - } - - @Test - public void solutionWithoutUnassignedJobsShouldBeWrittenCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - builder.addVehicle(v1); - - Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); - Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc2")).setServiceTime(4.0).build(); - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - - VehicleRoute route = VehicleRoute.Builder.newInstance(v1).addService(s1).addService(s2).build(); - List routes = new ArrayList(); - routes.add(route); - VehicleRoutingProblemSolution solution = new VehicleRoutingProblemSolution(routes, 10.); - List solutions = new ArrayList(); - solutions.add(solution); - - new VrpXMLWriter(vrp, solutions).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - List solutionsToRead = new ArrayList(); - new VrpXMLReader(vrpToReadBuilder, solutionsToRead).read(infileName); - - assertEquals(1, solutionsToRead.size()); - Assert.assertEquals(10., Solutions.bestOf(solutionsToRead).getCost(), 0.01); - assertTrue(Solutions.bestOf(solutionsToRead).getUnassignedJobs().isEmpty()); - } - - @Test - public void solutionWithUnassignedJobsShouldBeWrittenCorrectly() { - VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance(); - - VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("vehType").addCapacityDimension(0, 20).build(); - VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(TestUtils.loc("loc")).setType(type1).build(); - builder.addVehicle(v1); - - Service s1 = Service.Builder.newInstance("1").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc")).setServiceTime(2.0).build(); - Service s2 = Service.Builder.newInstance("2").addSizeDimension(0, 1).setLocation(TestUtils.loc("loc2")).setServiceTime(4.0).build(); - - VehicleRoutingProblem vrp = builder.addJob(s1).addJob(s2).build(); - - VehicleRoute route = VehicleRoute.Builder.newInstance(v1).addService(s1).build(); - List routes = new ArrayList(); - routes.add(route); - VehicleRoutingProblemSolution solution = new VehicleRoutingProblemSolution(routes, 10.); - solution.getUnassignedJobs().add(s2); - List solutions = new ArrayList(); - solutions.add(solution); - - new VrpXMLWriter(vrp, solutions).write(infileName); - - VehicleRoutingProblem.Builder vrpToReadBuilder = VehicleRoutingProblem.Builder.newInstance(); - List solutionsToRead = new ArrayList(); - new VrpXMLReader(vrpToReadBuilder, solutionsToRead).read(infileName); - - assertEquals(1, solutionsToRead.size()); - Assert.assertEquals(10., Solutions.bestOf(solutionsToRead).getCost(), 0.01); - Assert.assertEquals(1, Solutions.bestOf(solutionsToRead).getUnassignedJobs().size()); - Assert.assertEquals("2", Solutions.bestOf(solutionsToRead).getUnassignedJobs().iterator().next().getId()); - } - -} diff --git a/jsprit-core/src/test/resources/infiniteWriterV2Test.xml b/jsprit-core/src/test/resources/infiniteWriterV2Test.xml index b34bf776..c7b5a449 100644 --- a/jsprit-core/src/test/resources/infiniteWriterV2Test.xml +++ b/jsprit-core/src/test/resources/infiniteWriterV2Test.xml @@ -2,7 +2,7 @@ - FINITE + INFINITE @@ -20,21 +20,6 @@ true - - v2 - vehType2 - - loc - - - loc - - - 0.0 - 1.7976931348623157E308 - - true - @@ -50,18 +35,58 @@ 0.0 - - vehType2 - - 200 - - - 0.0 - 1.0 - - 0.0 - 0.0 - - + + + + loc + + + 1 + + 2.0 + + + 0.0 + 1.7976931348623157E308 + + + + + + loc2 + + + 1 + + 4.0 + + + 0.0 + 1.7976931348623157E308 + + + + + + + 10.0 + + + noDriver + v1 + 0.0 + + 1 + 0.0 + 0.0 + + 0.0 + + + + + + + diff --git a/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/AdditionalDistanceConstraintExample.java b/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/AdditionalDistanceConstraintExample.java index 4e051262..b362f793 100644 --- a/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/AdditionalDistanceConstraintExample.java +++ b/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/AdditionalDistanceConstraintExample.java @@ -20,7 +20,6 @@ package com.graphhopper.jsprit.examples; import com.graphhopper.jsprit.analysis.toolbox.Plotter; import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm; -import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder; import com.graphhopper.jsprit.core.algorithm.state.StateId; import com.graphhopper.jsprit.core.algorithm.state.StateManager; import com.graphhopper.jsprit.core.algorithm.state.StateUpdater; @@ -38,6 +37,7 @@ import com.graphhopper.jsprit.core.util.Coordinate; import com.graphhopper.jsprit.core.util.EuclideanDistanceCalculator; import com.graphhopper.jsprit.core.util.Solutions; import com.graphhopper.jsprit.core.util.VehicleRoutingTransportCostsMatrix; +import com.graphhopper.jsprit.io.algorithm.VehicleRoutingAlgorithmBuilder; import java.util.Collection; diff --git a/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/BicycleMessenger.java b/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/BicycleMessenger.java index e7028860..89a9cdc3 100644 --- a/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/BicycleMessenger.java +++ b/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/BicycleMessenger.java @@ -21,7 +21,6 @@ import com.graphhopper.jsprit.analysis.toolbox.GraphStreamViewer; import com.graphhopper.jsprit.analysis.toolbox.GraphStreamViewer.Label; import com.graphhopper.jsprit.analysis.toolbox.Plotter; import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm; -import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder; import com.graphhopper.jsprit.core.algorithm.state.StateId; import com.graphhopper.jsprit.core.algorithm.state.StateManager; import com.graphhopper.jsprit.core.algorithm.state.StateUpdater; @@ -51,6 +50,7 @@ import com.graphhopper.jsprit.core.reporting.SolutionPrinter; 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.io.algorithm.VehicleRoutingAlgorithmBuilder; import com.graphhopper.jsprit.util.Examples; import java.io.BufferedReader; diff --git a/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/JobAndActivityDependenciesExample.java b/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/JobAndActivityDependenciesExample.java index f92a5587..b99e7e1a 100644 --- a/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/JobAndActivityDependenciesExample.java +++ b/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/JobAndActivityDependenciesExample.java @@ -20,7 +20,6 @@ package com.graphhopper.jsprit.examples; import com.graphhopper.jsprit.analysis.toolbox.GraphStreamViewer; import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm; -import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder; import com.graphhopper.jsprit.core.algorithm.state.StateId; import com.graphhopper.jsprit.core.algorithm.state.StateManager; import com.graphhopper.jsprit.core.algorithm.state.StateUpdater; @@ -38,6 +37,7 @@ import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity; import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl; import com.graphhopper.jsprit.core.reporting.SolutionPrinter; import com.graphhopper.jsprit.core.util.Solutions; +import com.graphhopper.jsprit.io.algorithm.VehicleRoutingAlgorithmBuilder; import java.util.Collection; diff --git a/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/SimpleEnRoutePickupAndDeliveryWithDepotBoundedDeliveriesExample.java b/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/SimpleEnRoutePickupAndDeliveryWithDepotBoundedDeliveriesExample.java index 20a0a6ae..25a90dbd 100644 --- a/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/SimpleEnRoutePickupAndDeliveryWithDepotBoundedDeliveriesExample.java +++ b/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/SimpleEnRoutePickupAndDeliveryWithDepotBoundedDeliveriesExample.java @@ -18,7 +18,6 @@ package com.graphhopper.jsprit.examples; import com.graphhopper.jsprit.analysis.toolbox.Plotter; import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm; -import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder; import com.graphhopper.jsprit.core.algorithm.state.StateManager; import com.graphhopper.jsprit.core.problem.Location; import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem; @@ -35,6 +34,7 @@ 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 com.graphhopper.jsprit.io.algorithm.VehicleRoutingAlgorithmBuilder; import com.graphhopper.jsprit.util.Examples; import java.util.Collection; diff --git a/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/SimpleExampleWithSkills.java b/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/SimpleExampleWithSkills.java index 950c2587..1d96e4e2 100644 --- a/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/SimpleExampleWithSkills.java +++ b/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/SimpleExampleWithSkills.java @@ -19,7 +19,6 @@ package com.graphhopper.jsprit.examples; import com.graphhopper.jsprit.analysis.toolbox.GraphStreamViewer; import com.graphhopper.jsprit.analysis.toolbox.GraphStreamViewer.Label; import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm; -import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder; import com.graphhopper.jsprit.core.algorithm.state.StateManager; import com.graphhopper.jsprit.core.problem.Location; import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem; @@ -33,6 +32,7 @@ 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.Solutions; +import com.graphhopper.jsprit.io.algorithm.VehicleRoutingAlgorithmBuilder; import java.io.File; import java.util.Collection; diff --git a/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/SimpleVRPWithBackhaulsExample.java b/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/SimpleVRPWithBackhaulsExample.java index 623ee36b..f075bfbb 100644 --- a/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/SimpleVRPWithBackhaulsExample.java +++ b/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/SimpleVRPWithBackhaulsExample.java @@ -19,7 +19,6 @@ package com.graphhopper.jsprit.examples; import com.graphhopper.jsprit.analysis.toolbox.Plotter; import com.graphhopper.jsprit.analysis.toolbox.Plotter.Label; import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm; -import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder; import com.graphhopper.jsprit.core.algorithm.state.StateManager; import com.graphhopper.jsprit.core.problem.Location; import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem; @@ -35,6 +34,7 @@ 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.Solutions; +import com.graphhopper.jsprit.io.algorithm.VehicleRoutingAlgorithmBuilder; import com.graphhopper.jsprit.util.Examples; import java.util.Collection; diff --git a/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/SolomonWithSkillsExample.java b/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/SolomonWithSkillsExample.java index af8f8dc1..d76d5854 100644 --- a/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/SolomonWithSkillsExample.java +++ b/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/SolomonWithSkillsExample.java @@ -20,7 +20,6 @@ package com.graphhopper.jsprit.examples; import com.graphhopper.jsprit.analysis.toolbox.Plotter; import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm; -import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder; import com.graphhopper.jsprit.core.algorithm.box.Jsprit; import com.graphhopper.jsprit.core.algorithm.state.StateManager; import com.graphhopper.jsprit.core.problem.Location; @@ -36,6 +35,7 @@ import com.graphhopper.jsprit.core.problem.vehicle.VehicleType; import com.graphhopper.jsprit.core.reporting.SolutionPrinter; import com.graphhopper.jsprit.core.util.Solutions; import com.graphhopper.jsprit.instance.reader.SolomonReader; +import com.graphhopper.jsprit.io.algorithm.VehicleRoutingAlgorithmBuilder; import java.util.Collection; diff --git a/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/TransportOfDisabledPeople.java b/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/TransportOfDisabledPeople.java index ce61744d..b812ba9e 100644 --- a/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/TransportOfDisabledPeople.java +++ b/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/TransportOfDisabledPeople.java @@ -20,7 +20,6 @@ import com.graphhopper.jsprit.analysis.toolbox.GraphStreamViewer; import com.graphhopper.jsprit.analysis.toolbox.GraphStreamViewer.Label; import com.graphhopper.jsprit.analysis.toolbox.Plotter; import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm; -import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder; import com.graphhopper.jsprit.core.algorithm.state.StateManager; import com.graphhopper.jsprit.core.algorithm.termination.IterationWithoutImprovementTermination; import com.graphhopper.jsprit.core.problem.Location; @@ -38,6 +37,7 @@ 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 com.graphhopper.jsprit.io.algorithm.VehicleRoutingAlgorithmBuilder; import com.graphhopper.jsprit.util.Examples; import java.util.Collection; diff --git a/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/VRPWithBackhaulsExample.java b/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/VRPWithBackhaulsExample.java index d1708ebb..70852ff3 100644 --- a/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/VRPWithBackhaulsExample.java +++ b/jsprit-examples/src/main/java/com/graphhopper/jsprit/examples/VRPWithBackhaulsExample.java @@ -19,7 +19,6 @@ package com.graphhopper.jsprit.examples; import com.graphhopper.jsprit.analysis.toolbox.AlgorithmSearchProgressChartListener; import com.graphhopper.jsprit.analysis.toolbox.GraphStreamViewer; import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithm; -import com.graphhopper.jsprit.core.algorithm.VehicleRoutingAlgorithmBuilder; import com.graphhopper.jsprit.core.algorithm.selector.SelectBest; import com.graphhopper.jsprit.core.algorithm.state.StateManager; import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem; @@ -28,6 +27,7 @@ import com.graphhopper.jsprit.core.problem.constraint.ServiceDeliveriesFirstCons import com.graphhopper.jsprit.core.problem.io.VrpXMLReader; import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution; import com.graphhopper.jsprit.core.reporting.SolutionPrinter; +import com.graphhopper.jsprit.io.algorithm.VehicleRoutingAlgorithmBuilder; import com.graphhopper.jsprit.util.Examples; import java.util.Collection; diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/io/AlgorithmConfig.java b/jsprit-io/src/main/java/com/graphhopper/jsprit/io/algorithm/AlgorithmConfig.java similarity index 95% rename from jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/io/AlgorithmConfig.java rename to jsprit-io/src/main/java/com/graphhopper/jsprit/io/algorithm/AlgorithmConfig.java index f227c403..14127a2e 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/io/AlgorithmConfig.java +++ b/jsprit-io/src/main/java/com/graphhopper/jsprit/io/algorithm/AlgorithmConfig.java @@ -14,7 +14,7 @@ * 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.io; +package com.graphhopper.jsprit.io.algorithm; import org.apache.commons.configuration.XMLConfiguration; diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/io/AlgorithmConfigXmlReader.java b/jsprit-io/src/main/java/com/graphhopper/jsprit/io/algorithm/AlgorithmConfigXmlReader.java similarity index 98% rename from jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/io/AlgorithmConfigXmlReader.java rename to jsprit-io/src/main/java/com/graphhopper/jsprit/io/algorithm/AlgorithmConfigXmlReader.java index d0b5c06f..59842f5f 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/io/AlgorithmConfigXmlReader.java +++ b/jsprit-io/src/main/java/com/graphhopper/jsprit/io/algorithm/AlgorithmConfigXmlReader.java @@ -14,7 +14,7 @@ * 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.io; +package com.graphhopper.jsprit.io.algorithm; import com.graphhopper.jsprit.core.util.Resource; import org.apache.commons.configuration.ConfigurationException; diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/io/InsertionFactory.java b/jsprit-io/src/main/java/com/graphhopper/jsprit/io/algorithm/InsertionFactory.java similarity index 99% rename from jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/io/InsertionFactory.java rename to jsprit-io/src/main/java/com/graphhopper/jsprit/io/algorithm/InsertionFactory.java index ed390c1d..de7dc87a 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/io/InsertionFactory.java +++ b/jsprit-io/src/main/java/com/graphhopper/jsprit/io/algorithm/InsertionFactory.java @@ -14,7 +14,7 @@ * 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.io; +package com.graphhopper.jsprit.io.algorithm; import com.graphhopper.jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners; import com.graphhopper.jsprit.core.algorithm.recreate.InsertionBuilder; diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/io/VehicleRoutingAlgorithms.java b/jsprit-io/src/main/java/com/graphhopper/jsprit/io/algorithm/VehicleRoutingAlgorithms.java similarity index 99% rename from jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/io/VehicleRoutingAlgorithms.java rename to jsprit-io/src/main/java/com/graphhopper/jsprit/io/algorithm/VehicleRoutingAlgorithms.java index f6d0430d..bb499f90 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/algorithm/io/VehicleRoutingAlgorithms.java +++ b/jsprit-io/src/main/java/com/graphhopper/jsprit/io/algorithm/VehicleRoutingAlgorithms.java @@ -14,12 +14,11 @@ * 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.io; +package com.graphhopper.jsprit.io.algorithm; import com.graphhopper.jsprit.core.algorithm.*; import com.graphhopper.jsprit.core.algorithm.acceptor.*; -import com.graphhopper.jsprit.core.algorithm.io.VehicleRoutingAlgorithms.TypedMap.*; import com.graphhopper.jsprit.core.algorithm.listener.AlgorithmEndsListener; import com.graphhopper.jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners.PrioritizedVRAListener; import com.graphhopper.jsprit.core.algorithm.listener.VehicleRoutingAlgorithmListeners.Priority; @@ -51,6 +50,7 @@ import com.graphhopper.jsprit.core.problem.solution.route.activity.ReverseActivi import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity; import com.graphhopper.jsprit.core.problem.vehicle.*; import com.graphhopper.jsprit.core.util.ActivityTimeTracker; +import com.graphhopper.jsprit.io.algorithm.VehicleRoutingAlgorithms.TypedMap.*; import org.apache.commons.configuration.HierarchicalConfiguration; import org.apache.commons.configuration.XMLConfiguration; import org.slf4j.Logger; diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/io/Schema.java b/jsprit-io/src/main/java/com/graphhopper/jsprit/io/problem/Schema.java similarity index 97% rename from jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/io/Schema.java rename to jsprit-io/src/main/java/com/graphhopper/jsprit/io/problem/Schema.java index 8492eff5..8e9ba0ca 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/io/Schema.java +++ b/jsprit-io/src/main/java/com/graphhopper/jsprit/io/problem/Schema.java @@ -14,7 +14,7 @@ * 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.problem.io; +package com.graphhopper.jsprit.io.problem; final class Schema { diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/io/VrpXMLReader.java b/jsprit-io/src/main/java/com/graphhopper/jsprit/io/problem/VrpXMLReader.java similarity index 99% rename from jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/io/VrpXMLReader.java rename to jsprit-io/src/main/java/com/graphhopper/jsprit/io/problem/VrpXMLReader.java index fb602a76..028bcd9c 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/io/VrpXMLReader.java +++ b/jsprit-io/src/main/java/com/graphhopper/jsprit/io/problem/VrpXMLReader.java @@ -14,7 +14,7 @@ * 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.problem.io; +package com.graphhopper.jsprit.io.problem; import com.graphhopper.jsprit.core.problem.Location; import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem; diff --git a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/io/VrpXMLWriter.java b/jsprit-io/src/main/java/com/graphhopper/jsprit/io/problem/VrpXMLWriter.java similarity index 99% rename from jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/io/VrpXMLWriter.java rename to jsprit-io/src/main/java/com/graphhopper/jsprit/io/problem/VrpXMLWriter.java index cf6b04b5..c6e8f2fc 100644 --- a/jsprit-core/src/main/java/com/graphhopper/jsprit/core/problem/io/VrpXMLWriter.java +++ b/jsprit-io/src/main/java/com/graphhopper/jsprit/io/problem/VrpXMLWriter.java @@ -14,7 +14,7 @@ * 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.problem.io; +package com.graphhopper.jsprit.io.problem; import com.graphhopper.jsprit.core.problem.Location; import com.graphhopper.jsprit.core.problem.Skills; diff --git a/pom.xml b/pom.xml index e32a5622..2b2164fc 100644 --- a/pom.xml +++ b/pom.xml @@ -40,7 +40,7 @@ Stefan Schroeder - stefan.schroeder@jspr.it + stefan.schroeder@graphhopper.com @@ -77,6 +77,7 @@ jsprit-analysis jsprit-examples jsprit-instances + jsprit-io @@ -87,7 +88,7 @@ 1.3 1.7.21 false - + 3.0.4 @@ -272,16 +273,6 @@ test - - - - org.slf4j - slf4j-api - ${logger.version} - - - -