mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
remove deprecated methods dealing with old location concept
This commit is contained in:
parent
917d5d3d2c
commit
b3af33ccf9
22 changed files with 201 additions and 551 deletions
|
|
@ -0,0 +1,135 @@
|
|||
/*******************************************************************************
|
||||
* 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 jsprit.core.algorithm;
|
||||
|
||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
|
||||
import jsprit.core.analysis.SolutionAnalyser;
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.cost.TransportDistance;
|
||||
import jsprit.core.problem.io.VrpXMLReader;
|
||||
import jsprit.core.problem.job.Job;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import jsprit.core.util.EuclideanDistanceCalculator;
|
||||
import jsprit.core.util.FastVehicleRoutingTransportCostsMatrix;
|
||||
import jsprit.core.util.Solutions;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class CVRPwithMatrix_IT {
|
||||
|
||||
private int index = 0;
|
||||
|
||||
|
||||
@Test
|
||||
public void whenReturnToDepot_itShouldWorkWithMatrix(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml");
|
||||
VehicleRoutingProblem vrp_ = vrpBuilder.build();
|
||||
VehicleRoutingProblem vrp = createVrpWithLocationIndecesAndMatrix(vrp_, true);
|
||||
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml");
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
assertEquals(530.0, Solutions.bestOf(solutions).getCost(),50.0);
|
||||
assertEquals(5, Solutions.bestOf(solutions).getRoutes().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenNotReturnToDepot_itShouldWorkWithMatrix(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml");
|
||||
VehicleRoutingProblem vrp_ = vrpBuilder.build();
|
||||
VehicleRoutingProblem vrp = createVrpWithLocationIndecesAndMatrix(vrp_,false);
|
||||
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml");
|
||||
try {
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
assertTrue(true);
|
||||
}
|
||||
catch (Exception e){
|
||||
assertFalse(true);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCalcTimeWithSolutionAnalyser_itShouldWork(){
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
new VrpXMLReader(vrpBuilder).read("src/test/resources/vrpnc1-jsprit-with-deliveries.xml");
|
||||
VehicleRoutingProblem vrp_ = vrpBuilder.build();
|
||||
final VehicleRoutingProblem vrp = createVrpWithLocationIndecesAndMatrix(vrp_,false);
|
||||
VehicleRoutingAlgorithm vra = VehicleRoutingAlgorithms.readAndCreateAlgorithm(vrp, "src/test/resources/algorithmConfig.xml");
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
SolutionAnalyser sa = new SolutionAnalyser(vrp, Solutions.bestOf(solutions), new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to) {
|
||||
return vrp.getTransportCosts().getTransportCost(from,to,0.,null,null);
|
||||
}
|
||||
});
|
||||
System.out.println(sa.getDistance());
|
||||
System.out.println(sa.getTransportTime());
|
||||
}
|
||||
|
||||
|
||||
|
||||
private VehicleRoutingProblem createVrpWithLocationIndecesAndMatrix(VehicleRoutingProblem vrp_, boolean return_to_depot) {
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
List<Location> locations = new ArrayList<Location>();
|
||||
for (Vehicle v : vrp_.getVehicles()) {
|
||||
Location l = Location.Builder.newInstance().setIndex(getIndex()).setId(v.getStartLocation().getId())
|
||||
.setCoordinate(v.getStartLocation().getCoordinate()).build();
|
||||
VehicleImpl.Builder newVehicleBuilder = VehicleImpl.Builder.newInstance(v.getId()).setType(v.getType())
|
||||
.setEarliestStart(v.getEarliestDeparture()).setLatestArrival(v.getLatestArrival())
|
||||
.setStartLocation(l).setReturnToDepot(return_to_depot);
|
||||
VehicleImpl newVehicle = newVehicleBuilder.build();
|
||||
vrpBuilder.addVehicle(newVehicle);
|
||||
locations.add(l);
|
||||
}
|
||||
for (Job j : vrp_.getJobs().values()){
|
||||
Service s = (Service) j;
|
||||
Location l = Location.Builder.newInstance().setIndex(getIndex())
|
||||
.setId(s.getLocation().getId()).setCoordinate(s.getLocation().getCoordinate()).build();
|
||||
Service newService = Service.Builder.newInstance(s.getId()).setServiceTime(s.getServiceDuration())
|
||||
.addSizeDimension(0,s.getSize().get(0))
|
||||
.setLocation(l).build();
|
||||
vrpBuilder.addJob(newService);
|
||||
locations.add(l);
|
||||
}
|
||||
FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(locations.size(),true);
|
||||
for(Location from : locations){
|
||||
for(Location to : locations){
|
||||
double distance = EuclideanDistanceCalculator.calculateDistance(from.getCoordinate(), to.getCoordinate());
|
||||
matrixBuilder.addTransportDistance(from.getIndex(),to.getIndex(), distance);
|
||||
matrixBuilder.addTransportTime(from.getIndex(),to.getIndex(),distance);
|
||||
}
|
||||
}
|
||||
vrpBuilder.setRoutingCost(matrixBuilder.build());
|
||||
return vrpBuilder.build();
|
||||
}
|
||||
|
||||
|
||||
public int getIndex() {
|
||||
int i = index;
|
||||
index++;
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
|
@ -114,7 +114,7 @@ public class RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_IT {
|
|||
VehicleTypeImpl bigType = typeBuilder.build();
|
||||
|
||||
VehicleImpl.Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle");
|
||||
vehicleBuilder.setStartLocationId("1");
|
||||
vehicleBuilder.setStartLocation(Location.newInstance("1"));
|
||||
vehicleBuilder.setType(bigType);
|
||||
vehicleBuilder.setLatestArrival(220);
|
||||
Vehicle bigVehicle = vehicleBuilder.build();
|
||||
|
|
|
|||
|
|
@ -114,7 +114,7 @@ public class RefuseCollectionWithCostsHigherThanTimesAndFiniteFleet_withTimeAndD
|
|||
VehicleTypeImpl bigType = typeBuilder.build();
|
||||
|
||||
VehicleImpl.Builder vehicleBuilder = VehicleImpl.Builder.newInstance("vehicle");
|
||||
vehicleBuilder.setStartLocationId("1");
|
||||
vehicleBuilder.setStartLocation(Location.newInstance("1"));
|
||||
vehicleBuilder.setType(bigType);
|
||||
vehicleBuilder.setLatestArrival(220);
|
||||
Vehicle bigVehicle = vehicleBuilder.build();
|
||||
|
|
|
|||
|
|
@ -94,7 +94,7 @@ public class ServiceInsertionAndLoadConstraintsTest {
|
|||
public void doBefore(){
|
||||
routingCosts = CostFactory.createManhattanCosts();
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0, 2).setCostPerDistance(1).build();
|
||||
vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("0,0").setType(type).build();
|
||||
vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("0,0")).setType(type).build();
|
||||
activityInsertionCostsCalculator = new LocalActivityInsertionCostsCalculator(routingCosts, activityCosts);
|
||||
createInsertionCalculator(hardRouteLevelConstraint);
|
||||
vehicleRoutingProblem = mock(VehicleRoutingProblem.class);
|
||||
|
|
@ -112,7 +112,7 @@ public class ServiceInsertionAndLoadConstraintsTest {
|
|||
Pickup pickup = (Pickup) Pickup.Builder.newInstance("pick").addSizeDimension(0, 15).setLocation(Location.newInstance("0,10")).build();
|
||||
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0, 50).setCostPerDistance(1).build();
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("0,0").setType(type).build();
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("0,0")).setType(type).build();
|
||||
|
||||
final VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addJob(delivery).addJob(pickup).addVehicle(vehicle).build();
|
||||
|
||||
|
|
|
|||
|
|
@ -78,10 +78,10 @@ public class TestCalculatesServiceInsertion {
|
|||
public void setup(){
|
||||
|
||||
VehicleType t1 = VehicleTypeImpl.Builder.newInstance("t1").addCapacityDimension(0, 1000).setCostPerDistance(1.0).build();
|
||||
vehicle = VehicleImpl.Builder.newInstance("vehicle").setLatestArrival(100.0).setStartLocationId("0,0").setType(t1).build();
|
||||
vehicle = VehicleImpl.Builder.newInstance("vehicle").setLatestArrival(100.0).setStartLocation(Location.newInstance("0,0")).setType(t1).build();
|
||||
|
||||
VehicleType t2 = VehicleTypeImpl.Builder.newInstance("t2").addCapacityDimension(0, 1000).setCostPerDistance(2.0).build();
|
||||
newVehicle = VehicleImpl.Builder.newInstance("newVehicle").setLatestArrival(100.0).setStartLocationId("0,0").setType(t2).build();
|
||||
newVehicle = VehicleImpl.Builder.newInstance("newVehicle").setLatestArrival(100.0).setStartLocation(Location.newInstance("0,0")).setType(t2).build();
|
||||
|
||||
driver = DriverImpl.noDriver();
|
||||
|
||||
|
|
|
|||
|
|
@ -78,8 +78,8 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
costs = mock(VehicleRoutingTransportCosts.class);
|
||||
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("t").addCapacityDimension(0,1000).build();
|
||||
vehicle = VehicleImpl.Builder.newInstance("v1").setType(type).setStartLocationId("0,0").setLatestArrival(100.).build();
|
||||
newVehicle = VehicleImpl.Builder.newInstance("v2").setType(type).setStartLocationId("0,0").setLatestArrival(100.).build();
|
||||
vehicle = VehicleImpl.Builder.newInstance("v1").setType(type).setStartLocation(Location.newInstance("0,0")).setLatestArrival(100.).build();
|
||||
newVehicle = VehicleImpl.Builder.newInstance("v2").setType(type).setStartLocation(Location.newInstance("0,0")).setLatestArrival(100.).build();
|
||||
driver = DriverImpl.noDriver();
|
||||
|
||||
costs = new AbstractForwardVehicleRoutingTransportCosts() {
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ package jsprit.core.algorithm.recreate;
|
|||
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.VehicleRoutingProblem.Builder;
|
||||
import jsprit.core.problem.cost.VehicleRoutingActivityCosts;
|
||||
|
|
@ -74,7 +75,7 @@ public class TestDepartureTimeOpt {
|
|||
TimeWindow timeWindow = TimeWindow.newInstance(40, 45);
|
||||
Service service = Service.Builder.newInstance("s")
|
||||
.setLocation(TestUtils.loc("servLoc",Coordinate.newInstance(0, 10))).setTimeWindow(timeWindow).build();
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("vehLoc").setStartLocationCoordinate(Coordinate.newInstance(0, 0))
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.Builder.newInstance().setId("vehLoc").setCoordinate(Coordinate.newInstance(0, 0)).build())
|
||||
.setType(VehicleTypeImpl.Builder.newInstance("vType").build()).build();
|
||||
|
||||
Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
|
|
|||
|
|
@ -89,7 +89,7 @@ public class SolomonSkills_IT {
|
|||
constraintManager.addSkillsConstraint();
|
||||
|
||||
VehicleRoutingAlgorithm vra = vraBuilder.build();
|
||||
vra.setMaxIterations(500);
|
||||
vra.setMaxIterations(2000);
|
||||
|
||||
try {
|
||||
Collection<VehicleRoutingProblemSolution> solutions = vra.searchSolutions();
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ public class StateManagerTest {
|
|||
|
||||
@Test
|
||||
public void whenVehicleDependentInternalRouteStateIsSet_itMustBeSetCorrectly(){
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").build();
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).build();
|
||||
//noinspection UnusedDeclaration
|
||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(vehicle).build();
|
||||
|
||||
|
|
@ -87,7 +87,7 @@ public class StateManagerTest {
|
|||
|
||||
@Test
|
||||
public void whenVehicleDependentInternalRouteStateIsNotSet_itMustBeSetCorrectly(){
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").build();
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).build();
|
||||
//noinspection UnusedDeclaration
|
||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(vehicle).build();
|
||||
|
||||
|
|
@ -221,7 +221,7 @@ public class StateManagerTest {
|
|||
|
||||
@Test
|
||||
public void whenCreatingAVehicleDependentRouteState_itShouldBeMemorized(){
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").build();
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).build();
|
||||
//noinspection UnusedDeclaration
|
||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(vehicle).build();
|
||||
VehicleRoute route = getRoute(vehicle);
|
||||
|
|
@ -235,7 +235,7 @@ public class StateManagerTest {
|
|||
|
||||
@Test
|
||||
public void whenCreatingAVehicleDependentActivityState_itShouldBeMemorized(){
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").build();
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).build();
|
||||
//noinspection UnusedDeclaration
|
||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(vehicle).build();
|
||||
StateManager stateManager = new StateManager(mock(VehicleRoutingProblem.class));
|
||||
|
|
@ -250,7 +250,7 @@ public class StateManagerTest {
|
|||
|
||||
@Test
|
||||
public void whenMemorizingVehicleInfo_itShouldBeMemorized(){
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").build();
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).build();
|
||||
//noinspection UnusedDeclaration
|
||||
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(vehicle).build();
|
||||
VehicleRoute route = getRoute(vehicle);
|
||||
|
|
@ -264,8 +264,8 @@ public class StateManagerTest {
|
|||
@Test
|
||||
public void whenMemorizingTwoVehicleInfoForRoute_itShouldBeMemorized(){
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(4.).build();
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").build();
|
||||
VehicleImpl vehicle2 = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build();
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).build();
|
||||
VehicleImpl vehicle2 = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).setType(type).build();
|
||||
VehicleRoute route = getRoute(vehicle);
|
||||
|
||||
//getting the indices created in vrpBuilder
|
||||
|
|
@ -284,8 +284,8 @@ public class StateManagerTest {
|
|||
@Test
|
||||
public void whenMemorizingTwoVehicleInfoForAct_itShouldBeMemorized(){
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(4.).build();
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").build();
|
||||
VehicleImpl vehicle2 = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build();
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).build();
|
||||
VehicleImpl vehicle2 = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).setType(type).build();
|
||||
|
||||
//getting the indices created in vrpBuilder
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
|
@ -306,8 +306,8 @@ public class StateManagerTest {
|
|||
@Test
|
||||
public void whenClearing_arrElementsShouldBeNull(){
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(4.).build();
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").build();
|
||||
VehicleImpl vehicle2 = VehicleImpl.Builder.newInstance("v").setStartLocationId("loc").setType(type).build();
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).build();
|
||||
VehicleImpl vehicle2 = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("loc")).setType(type).build();
|
||||
|
||||
//getting the indices created in vrpBuilder
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ public class VehicleRouteBuilderTest {
|
|||
Capacity capacity = Capacity.Builder.newInstance().build();
|
||||
when(s.getSize()).thenReturn(capacity);
|
||||
when(s2.getSize()).thenReturn(capacity);
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("vehLoc").setEndLocationId("vehLoc")
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("vehLoc")).setEndLocation(Location.newInstance("vehLoc"))
|
||||
.build();
|
||||
|
||||
VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class));
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.problem.vehicle;
|
||||
|
||||
import jsprit.core.problem.Location;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
|
@ -38,8 +39,8 @@ public class TestVehicleFleetManagerImpl {
|
|||
public void setUp(){
|
||||
List<Vehicle> vehicles = new ArrayList<Vehicle>();
|
||||
|
||||
v1 = VehicleImpl.Builder.newInstance("standard").setStartLocationId("loc").setType(VehicleTypeImpl.Builder.newInstance("standard").build()).build();
|
||||
v2 = VehicleImpl.Builder.newInstance("foo").setStartLocationId("fooLoc").setType(VehicleTypeImpl.Builder.newInstance("foo").build()).build();
|
||||
v1 = VehicleImpl.Builder.newInstance("standard").setStartLocation(Location.newInstance("loc")).setType(VehicleTypeImpl.Builder.newInstance("standard").build()).build();
|
||||
v2 = VehicleImpl.Builder.newInstance("foo").setStartLocation(Location.newInstance("fooLoc")).setType(VehicleTypeImpl.Builder.newInstance("foo").build()).build();
|
||||
|
||||
// v1.
|
||||
vehicles.add(v1);
|
||||
|
|
@ -96,7 +97,7 @@ public class TestVehicleFleetManagerImpl {
|
|||
|
||||
@Test
|
||||
public void testWithPenalty_whenHavingOneRegularVehicleAvailable_noPenaltyVehicleIsReturn(){
|
||||
Vehicle penalty4standard = VehicleImpl.Builder.newInstance("standard_penalty").setStartLocationId("loc").
|
||||
Vehicle penalty4standard = VehicleImpl.Builder.newInstance("standard_penalty").setStartLocation(Location.newInstance("loc")).
|
||||
setType(VehicleTypeImpl.Builder.newInstance("standard").build()).build();
|
||||
|
||||
List<Vehicle> vehicles = new ArrayList<Vehicle>();
|
||||
|
|
@ -114,8 +115,8 @@ public class TestVehicleFleetManagerImpl {
|
|||
@Test
|
||||
public void whenAddingTwoVehiclesWithSameTypeIdAndLocation_getAvailableVehicleShouldReturnOnlyOneOfThem(){
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("standard").build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("loc").setType(type).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setType(type).build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("loc")).setType(type).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("loc")).setType(type).build();
|
||||
VehicleFleetManager fleetManager = new FiniteFleetManagerFactory(Arrays.asList(v1,v2)).createFleetManager();
|
||||
Collection<Vehicle> vehicles = fleetManager.getAvailableVehicles();
|
||||
assertEquals(1,vehicles.size());
|
||||
|
|
@ -124,9 +125,9 @@ public class TestVehicleFleetManagerImpl {
|
|||
@Test
|
||||
public void whenAddingTwoVehiclesWithSameTypeIdStartAndEndLocationAndWorkingShift_getAvailableVehicleShouldReturnOnlyOneOfThem(){
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("standard").build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("loc").setEndLocationId("endLoc")
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc"))
|
||||
.setType(type).setEarliestStart(0.).setLatestArrival(10.).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setEndLocationId("endLoc")
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc"))
|
||||
.setType(type).setEarliestStart(0.).setLatestArrival(10.).build();
|
||||
VehicleFleetManager fleetManager = new FiniteFleetManagerFactory(Arrays.asList(v1,v2)).createFleetManager();
|
||||
Collection<Vehicle> vehicles = fleetManager.getAvailableVehicles();
|
||||
|
|
@ -137,9 +138,9 @@ public class TestVehicleFleetManagerImpl {
|
|||
public void whenAddingTwoVehiclesWithDifferentType_getAvailableVehicleShouldReturnBoth(){
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("standard").build();
|
||||
VehicleTypeImpl type2 = VehicleTypeImpl.Builder.newInstance("type2").build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("loc").setEndLocationId("endLoc")
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc"))
|
||||
.setType(type).setEarliestStart(0.).setLatestArrival(10.).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setEndLocationId("endLoc")
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc"))
|
||||
.setType(type2).setEarliestStart(0.).setLatestArrival(10.).build();
|
||||
VehicleFleetManager fleetManager = new FiniteFleetManagerFactory(Arrays.asList(v1,v2)).createFleetManager();
|
||||
Collection<Vehicle> vehicles = fleetManager.getAvailableVehicles();
|
||||
|
|
@ -151,9 +152,9 @@ public class TestVehicleFleetManagerImpl {
|
|||
@Test
|
||||
public void whenAddingTwoVehiclesWithDifferentStartLocation_getAvailableVehicleShouldReturnBoth(){
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("standard").build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("startloc").setEndLocationId("endLoc")
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("startLoc")).setEndLocation(Location.newInstance("endLoc"))
|
||||
.setType(type).setEarliestStart(0.).setLatestArrival(10.).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setEndLocationId("endLoc")
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc"))
|
||||
.setType(type).setEarliestStart(0.).setLatestArrival(10.).build();
|
||||
VehicleFleetManager fleetManager = new FiniteFleetManagerFactory(Arrays.asList(v1,v2)).createFleetManager();
|
||||
Collection<Vehicle> vehicles = fleetManager.getAvailableVehicles();
|
||||
|
|
@ -165,9 +166,9 @@ public class TestVehicleFleetManagerImpl {
|
|||
@Test
|
||||
public void whenAddingTwoVehiclesWithDifferentEndLocation_getAvailableVehicleShouldReturnBoth(){
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("standard").build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("loc").setEndLocationId("endLocation")
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLocation"))
|
||||
.setType(type).setEarliestStart(0.).setLatestArrival(10.).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setEndLocationId("endLoc")
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc"))
|
||||
.setType(type).setEarliestStart(0.).setLatestArrival(10.).build();
|
||||
VehicleFleetManager fleetManager = new FiniteFleetManagerFactory(Arrays.asList(v1,v2)).createFleetManager();
|
||||
Collection<Vehicle> vehicles = fleetManager.getAvailableVehicles();
|
||||
|
|
@ -179,9 +180,9 @@ public class TestVehicleFleetManagerImpl {
|
|||
@Test
|
||||
public void whenAddingTwoVehiclesWithDifferentEarliestStart_getAvailableVehicleShouldReturnBoth(){
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("standard").build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("loc").setEndLocationId("endLoc")
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc"))
|
||||
.setType(type).setEarliestStart(5.).setLatestArrival(10.).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setEndLocationId("endLoc")
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc"))
|
||||
.setType(type).setEarliestStart(0.).setLatestArrival(10.).build();
|
||||
VehicleFleetManager fleetManager = new FiniteFleetManagerFactory(Arrays.asList(v1,v2)).createFleetManager();
|
||||
Collection<Vehicle> vehicles = fleetManager.getAvailableVehicles();
|
||||
|
|
@ -193,9 +194,9 @@ public class TestVehicleFleetManagerImpl {
|
|||
@Test
|
||||
public void whenAddingTwoVehiclesWithDifferentLatestArr_getAvailableVehicleShouldReturnBoth(){
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("standard").build();
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("loc").setEndLocationId("endLoc")
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc"))
|
||||
.setType(type).setEarliestStart(0.).setLatestArrival(20.).build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("loc").setEndLocationId("endLoc")
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("loc")).setEndLocation(Location.newInstance("endLoc"))
|
||||
.setType(type).setEarliestStart(0.).setLatestArrival(10.).build();
|
||||
VehicleFleetManager fleetManager = new FiniteFleetManagerFactory(Arrays.asList(v1,v2)).createFleetManager();
|
||||
Collection<Vehicle> vehicles = fleetManager.getAvailableVehicles();
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
package jsprit.core.problem.vehicle;
|
||||
|
||||
|
||||
import jsprit.core.problem.Location;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
|
@ -10,18 +11,18 @@ public class VehicleTypeKeyTest {
|
|||
|
||||
@Test
|
||||
public void typeIdentifierShouldBeEqual(){
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("start").addSkill("skill1").addSkill("skill2")
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("start")).addSkill("skill1").addSkill("skill2")
|
||||
.addSkill("skill3").build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("start").addSkill("skill2").addSkill("skill1")
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("start")).addSkill("skill2").addSkill("skill1")
|
||||
.addSkill("skill3").build();
|
||||
assertTrue(v1.getVehicleTypeIdentifier().equals(v2.getVehicleTypeIdentifier()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void typeIdentifierShouldNotBeEqual(){
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("start").addSkill("skill1").addSkill("skill2")
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocation(Location.newInstance("start")).addSkill("skill1").addSkill("skill2")
|
||||
.build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("start").addSkill("skill2").addSkill("skill1")
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance("start")).addSkill("skill2").addSkill("skill1")
|
||||
.addSkill("skill3").build();
|
||||
assertFalse(v1.getVehicleTypeIdentifier().equals(v2.getVehicleTypeIdentifier()));
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue