mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
clean up test resources
This commit is contained in:
parent
65e5b48afc
commit
21aac20c77
5 changed files with 2072 additions and 0 deletions
|
|
@ -0,0 +1,285 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
******************************************************************************/
|
||||||
|
package com.graphhopper.jsprit.io.algorithm;
|
||||||
|
|
||||||
|
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.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.job.Job;
|
||||||
|
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||||
|
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
|
||||||
|
import com.graphhopper.jsprit.io.algorithm.VehicleRoutingAlgorithms.ModKey;
|
||||||
|
import com.graphhopper.jsprit.io.algorithm.VehicleRoutingAlgorithms.TypedMap.AcceptorKey;
|
||||||
|
import com.graphhopper.jsprit.io.algorithm.VehicleRoutingAlgorithms.TypedMap.RuinStrategyKey;
|
||||||
|
import com.graphhopper.jsprit.io.algorithm.VehicleRoutingAlgorithms.TypedMap.SelectorKey;
|
||||||
|
import com.graphhopper.jsprit.io.algorithm.VehicleRoutingAlgorithms.TypedMap.StrategyModuleKey;
|
||||||
|
import com.graphhopper.jsprit.io.problem.VrpXMLReader;
|
||||||
|
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<VehicleRoutingProblemSolution> 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<VehicleRoutingProblemSolution>();
|
||||||
|
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<VehicleRoutingProblemSolution> 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<Job> ruin(Collection<VehicleRoute> vehicleRoutes) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void addListener(RuinListener ruinListener) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removeListener(RuinListener ruinListener) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Collection<RuinListener> 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");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,119 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
******************************************************************************/
|
||||||
|
|
||||||
|
package com.graphhopper.jsprit.io.problem;
|
||||||
|
|
||||||
|
|
||||||
|
import com.graphhopper.jsprit.core.problem.AbstractActivity;
|
||||||
|
import com.graphhopper.jsprit.core.problem.VehicleRoutingProblem;
|
||||||
|
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 org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
|
public class InitialRoutesTest {
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenReading_jobMapShouldOnlyContainJob2() {
|
||||||
|
|
||||||
|
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes.xml");
|
||||||
|
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||||
|
|
||||||
|
assertEquals(1, getNuServices(vrp));
|
||||||
|
assertTrue(vrp.getJobs().containsKey("2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenReadingProblem2_jobMapShouldContain_service2() {
|
||||||
|
|
||||||
|
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml");
|
||||||
|
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||||
|
|
||||||
|
assertEquals(1, getNuServices(vrp));
|
||||||
|
assertTrue(vrp.getJobs().containsKey("2"));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenReading_jobMapShouldContain_shipment4() {
|
||||||
|
|
||||||
|
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml");
|
||||||
|
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||||
|
|
||||||
|
assertEquals(1, getNuShipments(vrp));
|
||||||
|
assertTrue(vrp.getJobs().containsKey("4"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getNuShipments(VehicleRoutingProblem vrp) {
|
||||||
|
int nuShipments = 0;
|
||||||
|
for (Job job : vrp.getJobs().values()) {
|
||||||
|
if (job instanceof Shipment) nuShipments++;
|
||||||
|
}
|
||||||
|
return nuShipments;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getNuServices(VehicleRoutingProblem vrp) {
|
||||||
|
int nuServices = 0;
|
||||||
|
for (Job job : vrp.getJobs().values()) {
|
||||||
|
if (job instanceof Service) nuServices++;
|
||||||
|
}
|
||||||
|
return nuServices;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenReading_thereShouldBeOnlyOneActAssociatedToJob2() {
|
||||||
|
|
||||||
|
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_iniRoutes.xml");
|
||||||
|
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||||
|
|
||||||
|
assertEquals(1, vrp.getActivities(vrp.getJobs().get("2")).size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenReading_thereShouldBeOnlyOneActAssociatedToJob2_v2() {
|
||||||
|
|
||||||
|
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml");
|
||||||
|
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||||
|
|
||||||
|
assertEquals(1, vrp.getActivities(vrp.getJobs().get("2")).size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void whenReading_thereShouldBeTwoActsAssociatedToShipment4() {
|
||||||
|
|
||||||
|
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
new VrpXMLReader(vrpBuilder).read("src/test/resources/simpleProblem_inclShipments_iniRoutes.xml");
|
||||||
|
VehicleRoutingProblem vrp = vrpBuilder.build();
|
||||||
|
|
||||||
|
Job job = vrp.getJobs().get("4");
|
||||||
|
List<AbstractActivity> activities = vrp.getActivities(job);
|
||||||
|
|
||||||
|
assertEquals(2, activities.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,644 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* 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 <http://www.gnu.org/licenses/>.
|
||||||
|
******************************************************************************/
|
||||||
|
package com.graphhopper.jsprit.io.problem;
|
||||||
|
|
||||||
|
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<Vehicle> vehicles) {
|
||||||
|
for (Vehicle v : vehicles) if (string.equals(v.getId())) return v;
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean idsInCollection(List<String> asList, Collection<Vehicle> vehicles) {
|
||||||
|
List<String> ids = new ArrayList<String>(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<VehicleRoutingProblemSolution> solutions = new ArrayList<VehicleRoutingProblemSolution>();
|
||||||
|
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<TourActivity> 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<VehicleRoutingProblemSolution>()).read("src/test/resources/lui-shen-solution.xml");
|
||||||
|
assertTrue(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void unassignedJobShouldBeRead() {
|
||||||
|
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||||
|
ArrayList<VehicleRoutingProblemSolution> solutions = new ArrayList<VehicleRoutingProblemSolution>();
|
||||||
|
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<VehicleRoutingProblemSolution> solutions = new ArrayList<VehicleRoutingProblemSolution>();
|
||||||
|
// new VrpXMLReader(vrpBuilder, solutions).read("src/test/resources/finiteVrpforReaderTest.xml");
|
||||||
|
// assertTrue(solutions.isEmpty());
|
||||||
|
// }
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue