mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
shift from vehicle.getLocation() to vehicle.getStartLocation() and
vehicle.getCoord() to vehicle.getStartLocationCoordinate()
This commit is contained in:
parent
e5dabbdf64
commit
a234bb54c9
36 changed files with 195 additions and 137 deletions
|
|
@ -86,9 +86,15 @@ class InsertionFactory {
|
|||
String weight = config.getString("considerFixedCosts[@weight]");
|
||||
if(weight == null) weight = config.getString("considerFixedCost[@weight]");
|
||||
if(weight != null) fixedCostWeight = Double.parseDouble(weight);
|
||||
else log.warn("parameter considerFixedCosts[@weight] is missing. by default, it is 0.5.");
|
||||
else throw new IllegalStateException("fixedCostsParameter 'weight' must be set, e.g. <considerFixedCosts weight=1.0>true</considerFixedCosts>.\n" +
|
||||
"this has to be changed in algorithm-config-xml-file.");
|
||||
iBuilder.considerFixedCosts(fixedCostWeight);
|
||||
}
|
||||
else if(val.equals("false")){
|
||||
|
||||
}
|
||||
else throw new IllegalStateException("considerFixedCosts must either be true or false, i.e. <considerFixedCosts weight=1.0>true</considerFixedCosts> or \n<considerFixedCosts weight=1.0>false</considerFixedCosts>. " +
|
||||
"if latter, you can also omit the tag. this has to be changed in algorithm-config-xml-file");
|
||||
}
|
||||
String timeSliceString = config.getString("experimental[@timeSlice]");
|
||||
String neighbors = config.getString("experimental[@neighboringSlices]");
|
||||
|
|
|
|||
|
|
@ -481,9 +481,6 @@ public class VehicleRoutingAlgorithms {
|
|||
|
||||
@Override
|
||||
public void finish() {
|
||||
if(firstAct){
|
||||
assert vehicle.getLocationId() == end.getLocationId() : "route end and last activity are not equal even route is open. this should not be.";
|
||||
}
|
||||
firstAct = true;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -106,9 +106,9 @@ final class ServiceInsertionCalculator implements JobInsertionCostsCalculator{
|
|||
|
||||
TourActivity deliveryAct2Insert = activityFactory.createActivity(service);
|
||||
|
||||
Start start = Start.newInstance(newVehicle.getLocationId(), newVehicle.getEarliestDeparture(), newVehicle.getLatestArrival());
|
||||
Start start = Start.newInstance(newVehicle.getStartLocationId(), newVehicle.getEarliestDeparture(), Double.MAX_VALUE);
|
||||
start.setEndTime(newVehicleDepartureTime);
|
||||
End end = End.newInstance(newVehicle.getLocationId(), 0.0, newVehicle.getLatestArrival());
|
||||
End end = End.newInstance(newVehicle.getEndLocationId(), 0.0, newVehicle.getLatestArrival());
|
||||
|
||||
TourActivity prevAct = start;
|
||||
double prevActStartTime = newVehicleDepartureTime;
|
||||
|
|
|
|||
|
|
@ -314,22 +314,22 @@ final class ServiceInsertionOnRouteLevelCalculator implements JobInsertionCostsC
|
|||
*/
|
||||
private void initialiseStartAndEnd(final Vehicle newVehicle, double newVehicleDepartureTime) {
|
||||
if(start == null){
|
||||
start = Start.newInstance(newVehicle.getLocationId(), newVehicle.getEarliestDeparture(), newVehicle.getLatestArrival());
|
||||
start = Start.newInstance(newVehicle.getStartLocationId(), newVehicle.getEarliestDeparture(), Double.MAX_VALUE);
|
||||
start.setEndTime(newVehicleDepartureTime);
|
||||
}
|
||||
else{
|
||||
start.setLocationId(newVehicle.getLocationId());
|
||||
start.setLocationId(newVehicle.getStartLocationId());
|
||||
start.setTheoreticalEarliestOperationStartTime(newVehicle.getEarliestDeparture());
|
||||
start.setTheoreticalLatestOperationStartTime(newVehicle.getLatestArrival());
|
||||
start.setTheoreticalLatestOperationStartTime(Double.MAX_VALUE);
|
||||
start.setEndTime(newVehicleDepartureTime);
|
||||
}
|
||||
|
||||
if(end == null){
|
||||
end = End.newInstance(newVehicle.getLocationId(), 0.0, newVehicle.getLatestArrival());
|
||||
end = End.newInstance(newVehicle.getEndLocationId(), 0.0, newVehicle.getLatestArrival());
|
||||
}
|
||||
else{
|
||||
end.setLocationId(newVehicle.getLocationId());
|
||||
end.setTheoreticalEarliestOperationStartTime(newVehicleDepartureTime);
|
||||
end.setLocationId(newVehicle.getEndLocationId());
|
||||
end.setTheoreticalEarliestOperationStartTime(0.0);
|
||||
end.setTheoreticalLatestOperationStartTime(newVehicle.getLatestArrival());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -100,10 +100,10 @@ final class ShipmentInsertionCalculator implements JobInsertionCostsCalculator{
|
|||
int pickupInsertionIndex = InsertionData.NO_INDEX;
|
||||
int deliveryInsertionIndex = InsertionData.NO_INDEX;
|
||||
|
||||
Start start = Start.newInstance(newVehicle.getLocationId(), newVehicle.getEarliestDeparture(), newVehicle.getLatestArrival());
|
||||
Start start = Start.newInstance(newVehicle.getStartLocationId(), newVehicle.getEarliestDeparture(), newVehicle.getLatestArrival());
|
||||
start.setEndTime(newVehicleDepartureTime);
|
||||
|
||||
End end = End.newInstance(newVehicle.getLocationId(), 0.0, newVehicle.getLatestArrival());
|
||||
End end = End.newInstance(newVehicle.getEndLocationId(), 0.0, newVehicle.getLatestArrival());
|
||||
|
||||
TourActivity prevAct = start;
|
||||
double prevActEndTime = newVehicleDepartureTime;
|
||||
|
|
|
|||
|
|
@ -327,7 +327,11 @@ public class VehicleRoutingProblem {
|
|||
if(!vehicleTypes.contains(vehicle.getType())){
|
||||
vehicleTypes.add(vehicle.getType());
|
||||
}
|
||||
coordinates.put(vehicle.getLocationId(), vehicle.getCoord());
|
||||
String startLocationId = vehicle.getStartLocationId();
|
||||
coordinates.put(startLocationId, vehicle.getStartLocationCoordinate());
|
||||
if(!vehicle.getEndLocationId().equals(startLocationId)){
|
||||
coordinates.put(vehicle.getEndLocationId(), vehicle.getEndLocationCoordinate());
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -373,7 +377,7 @@ public class VehicleRoutingProblem {
|
|||
Set<LocTypeKey> locTypeKeys = new HashSet<LocTypeKey>();
|
||||
List<Vehicle> uniqueVehicles = new ArrayList<Vehicle>();
|
||||
for(Vehicle v : vehicles){
|
||||
LocTypeKey key = new LocTypeKey(v.getLocationId(),v.getType().getTypeId());
|
||||
LocTypeKey key = new LocTypeKey(v.getStartLocationId(),v.getType().getTypeId());
|
||||
if(!locTypeKeys.contains(key)){
|
||||
uniqueVehicles.add(v);
|
||||
locTypeKeys.add(key);
|
||||
|
|
@ -390,9 +394,10 @@ public class VehicleRoutingProblem {
|
|||
.setFixedCost(fixed)
|
||||
.build();
|
||||
PenaltyVehicleType penType = new PenaltyVehicleType(t,penaltyFactor);
|
||||
String vehicleId = "penaltyVehicle_" + v.getLocationId() + "_" + t.getTypeId();
|
||||
String vehicleId = "penaltyVehicle_" + v.getStartLocationId() + "_" + t.getTypeId();
|
||||
Vehicle penVehicle = VehicleImpl.Builder.newInstance(vehicleId).setEarliestStart(v.getEarliestDeparture())
|
||||
.setLatestArrival(v.getLatestArrival()).setLocationCoord(v.getCoord()).setLocationId(v.getLocationId())
|
||||
.setLatestArrival(v.getLatestArrival()).setStartLocationCoordinate(v.getStartLocationCoordinate()).setLocationId(v.getStartLocationId())
|
||||
.setEndLocationId(v.getEndLocationId()).setEndLocationCoordinate(v.getEndLocationCoordinate())
|
||||
.setReturnToDepot(v.isReturnToDepot()).setType(penType).build();
|
||||
addVehicle(penVehicle);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -165,7 +165,7 @@ public class VehicleRoute {
|
|||
this.driver = driver;
|
||||
start = Start.newInstance(vehicle.getStartLocationId(), vehicle.getEarliestDeparture(), Double.MAX_VALUE);
|
||||
start.setEndTime(vehicle.getEarliestDeparture());
|
||||
end = End.newInstance(vehicle.getLocationId(), 0.0, vehicle.getLatestArrival());
|
||||
end = End.newInstance(vehicle.getEndLocationId(), 0.0, vehicle.getLatestArrival());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -47,7 +47,9 @@ public interface Vehicle {
|
|||
* <p> Consequently, it should be the end-location of this vehicle, if returnToDepot is true.
|
||||
*
|
||||
* @return location-id of this vehicle
|
||||
* @deprecated use getStartLocationId() instead
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract String getLocationId();
|
||||
|
||||
/**
|
||||
|
|
@ -56,7 +58,9 @@ public interface Vehicle {
|
|||
* <p> Consequently, it should be the coordinate of the end-location, if returnToDepot is true.
|
||||
*
|
||||
* @return coordinate of this vehicle
|
||||
* @deprecated use getStartLocationCoordinate() instead
|
||||
*/
|
||||
@Deprecated
|
||||
public abstract Coordinate getCoord();
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -176,10 +176,8 @@ public class VehicleImpl implements Vehicle {
|
|||
*
|
||||
* @param coord
|
||||
* @return this builder
|
||||
* @throws IllegalArgumentException if start-coordinate is null
|
||||
*/
|
||||
public Builder setStartLocationCoordinate(Coordinate coord){
|
||||
if(coord == null) throw new IllegalArgumentException("start-coordinate must not be null");
|
||||
this.startLocationCoord = coord;
|
||||
this.locationCoord = coord;
|
||||
return this;
|
||||
|
|
@ -190,10 +188,8 @@ public class VehicleImpl implements Vehicle {
|
|||
*
|
||||
* @param endLocationId
|
||||
* @return this builder
|
||||
* @throws IllegalArgumentException if endLocation is null
|
||||
*/
|
||||
public Builder setEndLocationId(String endLocationId){
|
||||
if(endLocationId == null) throw new IllegalArgumentException("end-locationId must not be null");
|
||||
this.endLocationId = endLocationId;
|
||||
return this;
|
||||
}
|
||||
|
|
@ -203,10 +199,8 @@ public class VehicleImpl implements Vehicle {
|
|||
*
|
||||
* @param coord
|
||||
* @return this builder
|
||||
* @throws IllegalArgumentException if coord is null
|
||||
*/
|
||||
public Builder setEndLocationCoordinate(Coordinate coord){
|
||||
if(coord == null) throw new IllegalArgumentException("end-coordinate must not be null");
|
||||
this.endLocationCoord = coord;
|
||||
return this;
|
||||
}
|
||||
|
|
@ -336,6 +330,10 @@ public class VehicleImpl implements Vehicle {
|
|||
return "[id="+id+"][type="+type+"][locationId="+locationId+"][coord=" + coord + "][isReturnToDepot=" + isReturnToDepot() + "]";
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use getStartLocationCoordinate() instead
|
||||
*/
|
||||
@Deprecated
|
||||
public Coordinate getCoord() {
|
||||
return coord;
|
||||
}
|
||||
|
|
@ -350,6 +348,10 @@ public class VehicleImpl implements Vehicle {
|
|||
return latestArrival;
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated use getStartLocationId() instead
|
||||
*/
|
||||
@Deprecated
|
||||
@Override
|
||||
public String getLocationId() {
|
||||
return locationId;
|
||||
|
|
|
|||
|
|
@ -226,7 +226,8 @@
|
|||
<xs:extension base="xs:string">
|
||||
<xs:attribute name="weight" type="xs:double"/>
|
||||
</xs:extension>
|
||||
</xs:simpleContent>
|
||||
</xs:simpleContent>
|
||||
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="allowVehicleSwitch" type="xs:boolean" minOccurs="0" maxOccurs="1"/>
|
||||
|
|
|
|||
|
|
@ -53,8 +53,8 @@ public class CalcVehicleTypeDependentServiceInsertionTest {
|
|||
veh2 = mock(Vehicle.class);
|
||||
when(veh1.getType()).thenReturn(VehicleTypeImpl.Builder.newInstance("type1", 0).build());
|
||||
when(veh2.getType()).thenReturn(VehicleTypeImpl.Builder.newInstance("type2", 0).build());
|
||||
when(veh1.getLocationId()).thenReturn("loc1");
|
||||
when(veh2.getLocationId()).thenReturn("loc2");
|
||||
when(veh1.getStartLocationId()).thenReturn("loc1");
|
||||
when(veh2.getStartLocationId()).thenReturn("loc2");
|
||||
fleetManager = mock(VehicleFleetManager.class);
|
||||
service = mock(Service.class);
|
||||
vehicleRoute = mock(VehicleRoute.class);
|
||||
|
|
|
|||
|
|
@ -75,14 +75,16 @@ public class TestCalculatesServiceInsertion {
|
|||
costs = mock(VehicleRoutingTransportCosts.class);
|
||||
vehicle = mock(Vehicle.class);
|
||||
when(vehicle.getCapacity()).thenReturn(1000);
|
||||
when(vehicle.getLocationId()).thenReturn("depot");
|
||||
when(vehicle.getStartLocationId()).thenReturn("depot");
|
||||
when(vehicle.getEndLocationId()).thenReturn("depot");
|
||||
when(vehicle.getEarliestDeparture()).thenReturn(0.0);
|
||||
when(vehicle.getLatestArrival()).thenReturn(100.0);
|
||||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
|
||||
newVehicle = mock(Vehicle.class);
|
||||
when(newVehicle.getCapacity()).thenReturn(1000);
|
||||
when(newVehicle.getLocationId()).thenReturn("depot");
|
||||
when(newVehicle.getStartLocationId()).thenReturn("depot");
|
||||
when(newVehicle.getEndLocationId()).thenReturn("depot");
|
||||
when(newVehicle.getEarliestDeparture()).thenReturn(0.0);
|
||||
when(newVehicle.getLatestArrival()).thenReturn(100.0);
|
||||
when(newVehicle.isReturnToDepot()).thenReturn(true);
|
||||
|
|
|
|||
|
|
@ -79,7 +79,6 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
costs = mock(VehicleRoutingTransportCosts.class);
|
||||
vehicle = mock(Vehicle.class);
|
||||
when(vehicle.getCapacity()).thenReturn(1000);
|
||||
when(vehicle.getLocationId()).thenReturn("0,0");
|
||||
when(vehicle.getStartLocationId()).thenReturn("0,0");
|
||||
when(vehicle.getEndLocationId()).thenReturn("0,0");
|
||||
when(vehicle.getEarliestDeparture()).thenReturn(0.0);
|
||||
|
|
@ -88,7 +87,6 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
|
||||
newVehicle = mock(Vehicle.class);
|
||||
when(newVehicle.getCapacity()).thenReturn(1000);
|
||||
when(newVehicle.getLocationId()).thenReturn("0,0");
|
||||
when(newVehicle.getStartLocationId()).thenReturn("0,0");
|
||||
when(newVehicle.getEndLocationId()).thenReturn("0,0");
|
||||
when(newVehicle.getEarliestDeparture()).thenReturn(0.0);
|
||||
|
|
|
|||
|
|
@ -22,7 +22,6 @@ public class TestInserter {
|
|||
public void whenInsertingServiceAndRouteIsClosed_itInsertsCorrectly(){
|
||||
Service service = mock(Service.class);
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.getLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.getStartLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.getEndLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
|
|
@ -42,14 +41,13 @@ public class TestInserter {
|
|||
|
||||
assertEquals(2,route.getTourActivities().getActivities().size());
|
||||
assertEquals(route.getTourActivities().getActivities().get(1).getLocationId(),serviceToInsert.getLocationId());
|
||||
assertEquals(route.getEnd().getLocationId(),vehicle.getLocationId());
|
||||
assertEquals(route.getEnd().getLocationId(),vehicle.getEndLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertingServiceAndRouteIsOpen_itInsertsCorrectlyAndSwitchesEndLocation(){
|
||||
Service service = mock(Service.class);
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.getLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.getStartLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.getEndLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
|
|
@ -76,7 +74,6 @@ public class TestInserter {
|
|||
public void whenInsertingShipmentAndRouteIsClosed_itInsertsCorrectly(){
|
||||
Shipment shipment = mock(Shipment.class);
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.getLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.getStartLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.getEndLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
|
|
@ -98,14 +95,13 @@ public class TestInserter {
|
|||
assertEquals(4,route.getTourActivities().getActivities().size());
|
||||
assertEquals(route.getTourActivities().getActivities().get(2).getLocationId(),shipmentToInsert.getPickupLocation());
|
||||
assertEquals(route.getTourActivities().getActivities().get(3).getLocationId(),shipmentToInsert.getDeliveryLocation());
|
||||
assertEquals(route.getEnd().getLocationId(),vehicle.getLocationId());
|
||||
assertEquals(route.getEnd().getLocationId(),vehicle.getEndLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertingShipmentAndRouteIsOpen_itInsertsCorrectlyAndSwitchesEndLocation(){
|
||||
Shipment shipment = mock(Shipment.class);
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.getLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
when(vehicle.getId()).thenReturn("vehId");
|
||||
|
||||
|
|
@ -148,7 +144,7 @@ public class TestInserter {
|
|||
Inserter inserter = new Inserter(mock(InsertionListeners.class));
|
||||
inserter.insertJob(shipmentToInsert, iData, route);
|
||||
|
||||
assertEquals(newVehicle.getLocationId(),route.getEnd().getLocationId());
|
||||
assertEquals(route.getEnd().getLocationId(),newVehicle.getEndLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ public class TestTourStateUpdaterWithService {
|
|||
public void testStatesOfAct0(){
|
||||
states.informInsertionStarts(Arrays.asList(vehicleRoute), null);
|
||||
assertEquals(0.0, vehicleRoute.getStart().getEndTime(),0.05);
|
||||
assertEquals(vehicleRoute.getVehicle().getLocationId(), vehicleRoute.getStart().getLocationId());
|
||||
assertEquals(vehicleRoute.getVehicle().getStartLocationId(), vehicleRoute.getStart().getLocationId());
|
||||
assertEquals(vehicleRoute.getVehicle().getEarliestDeparture(), vehicleRoute.getStart().getTheoreticalEarliestOperationStartTime(),0.05);
|
||||
assertEquals(Double.MAX_VALUE, vehicleRoute.getStart().getTheoreticalLatestOperationStartTime(),0.05);
|
||||
|
||||
|
|
|
|||
|
|
@ -66,10 +66,10 @@ public class VehicleRoutingProblemTest {
|
|||
public void whenBuildingWithFourVehicles_vrpShouldContainTheCorrectNuOfVehicles(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
||||
Vehicle v1 = mock(VehicleImpl.class);
|
||||
Vehicle v2 = mock(VehicleImpl.class);
|
||||
Vehicle v3 = mock(VehicleImpl.class);
|
||||
Vehicle v4 = mock(VehicleImpl.class);
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("start").build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("start").build();
|
||||
Vehicle v3 = VehicleImpl.Builder.newInstance("v3").setStartLocationId("start").build();
|
||||
Vehicle v4 = VehicleImpl.Builder.newInstance("v4").setStartLocationId("start").build();
|
||||
|
||||
builder.addVehicle(v1).addVehicle(v2).addVehicle(v3).addVehicle(v4);
|
||||
|
||||
|
|
@ -82,10 +82,10 @@ public class VehicleRoutingProblemTest {
|
|||
public void whenAddingFourVehiclesAllAtOnce_vrpShouldContainTheCorrectNuOfVehicles(){
|
||||
VehicleRoutingProblem.Builder builder = VehicleRoutingProblem.Builder.newInstance();
|
||||
|
||||
Vehicle v1 = mock(VehicleImpl.class);
|
||||
Vehicle v2 = mock(VehicleImpl.class);
|
||||
Vehicle v3 = mock(VehicleImpl.class);
|
||||
Vehicle v4 = mock(VehicleImpl.class);
|
||||
Vehicle v1 = VehicleImpl.Builder.newInstance("v1").setStartLocationId("start").build();
|
||||
Vehicle v2 = VehicleImpl.Builder.newInstance("v2").setStartLocationId("start").build();
|
||||
Vehicle v3 = VehicleImpl.Builder.newInstance("v3").setStartLocationId("start").build();
|
||||
Vehicle v4 = VehicleImpl.Builder.newInstance("v4").setStartLocationId("start").build();
|
||||
|
||||
builder.addAllVehicles(Arrays.asList(v1,v2,v3,v4));
|
||||
|
||||
|
|
@ -471,4 +471,22 @@ public class VehicleRoutingProblemTest {
|
|||
assertTrue(anotherPenVehInCollection);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingVehicleWithDiffStartAndEnd_startLocationMustBeRegisteredInLocationMap(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("end").build();
|
||||
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.addVehicle(vehicle);
|
||||
assertTrue(vrpBuilder.getLocationMap().containsKey("start"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingVehicleWithDiffStartAndEnd_endLocationMustBeRegisteredInLocationMap(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("end").build();
|
||||
|
||||
VehicleRoutingProblem.Builder vrpBuilder = VehicleRoutingProblem.Builder.newInstance();
|
||||
vrpBuilder.addVehicle(vehicle);
|
||||
assertTrue(vrpBuilder.getLocationMap().containsKey("end"));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -70,9 +70,9 @@ public class VrpReaderV2Test {
|
|||
VehicleRoutingProblem vrp = builder.build();
|
||||
Vehicle v1 = getVehicle("v1",vrp.getVehicles());
|
||||
assertEquals(20,v1.getCapacity());
|
||||
assertEquals(100.0,v1.getCoord().getX(),0.01);
|
||||
assertEquals(100.0,v1.getStartLocationCoordinate().getX(),0.01);
|
||||
assertEquals(0.0,v1.getEarliestDeparture(),0.01);
|
||||
assertEquals("depotLoc2",v1.getLocationId());
|
||||
assertEquals("depotLoc2",v1.getStartLocationId());
|
||||
assertNotNull(v1.getType());
|
||||
assertEquals("vehType", v1.getType().getTypeId());
|
||||
assertEquals(1000.0,v1.getLatestArrival(),0.01);
|
||||
|
|
@ -229,8 +229,8 @@ public class VrpReaderV2Test {
|
|||
new VrpXMLReader(builder, null).read(inFileName);
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
Vehicle v3 = getVehicle("v3",vrp.getVehicles());
|
||||
assertEquals(10.0,v3.getCoord().getX(),0.01);
|
||||
assertEquals(100.0,v3.getCoord().getY(),0.01);
|
||||
assertEquals(10.0,v3.getStartLocationCoordinate().getX(),0.01);
|
||||
assertEquals(100.0,v3.getStartLocationCoordinate().getY(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -239,7 +239,7 @@ public class VrpReaderV2Test {
|
|||
new VrpXMLReader(builder, null).read(inFileName);
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
Vehicle v3 = getVehicle("v3",vrp.getVehicles());
|
||||
assertEquals("startLoc",v3.getLocationId());
|
||||
assertEquals("startLoc",v3.getStartLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -286,8 +286,8 @@ public class VrpReaderV2Test {
|
|||
new VrpXMLReader(builder, null).read(inFileName);
|
||||
VehicleRoutingProblem vrp = builder.build();
|
||||
Vehicle v = getVehicle("v4",vrp.getVehicles());
|
||||
assertEquals(10.0,v.getCoord().getX(),0.01);
|
||||
assertEquals(100.0,v.getCoord().getY(),0.01);
|
||||
assertEquals(10.0,v.getStartLocationCoordinate().getX(),0.01);
|
||||
assertEquals(100.0,v.getStartLocationCoordinate().getY(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -164,42 +164,49 @@ public class TestVehicleRoute {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenBuildingRouteWithVehicleThatHasDifferentStartAndEndLocation_routeMustHaveCorrectStartLocation(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("end").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
assertTrue(vRoute.getStart().getLocationId().equals("start"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenBuildingRouteWithVehicleThatHasDifferentStartAndEndLocation_routeMustHaveCorrectEndLocation(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("end").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
assertTrue(vRoute.getEnd().getLocationId().equals("end"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenBuildingRouteWithVehicleThatHasSameStartAndEndLocation_routeMustHaveCorrectStartLocation(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("start").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
assertTrue(vRoute.getStart().getLocationId().equals("start"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenBuildingRouteWithVehicleThatHasSameStartAndEndLocation_routeMustHaveCorrectEndLocation(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setStartLocationId("start").setEndLocationId("start").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
assertTrue(vRoute.getEnd().getLocationId().equals("start"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenBuildingRouteWithVehicleThatHasSameStartAndEndLocation_routeMustHaveCorrectStartLocationV2(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("start").setEndLocationId("start").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
assertTrue(vRoute.getStart().getLocationId().equals("start"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenBuildingRouteWithVehicleThatHasSameStartAndEndLocation_routeMustHaveCorrectEndLocationV2(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setLocationId("start").setEndLocationId("start").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
assertTrue(vRoute.getEnd().getLocationId().equals("start"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenBuildingRouteWithVehicleThatHasDifferentStartAndEndLocation_routeMustHaveCorrectDepartureTime(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setStartLocationId("start").setEndLocationId("end").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
|
|
@ -207,13 +214,14 @@ public class TestVehicleRoute {
|
|||
assertEquals(vRoute.getStart().getEndTime(),100.0,0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenBuildingRouteWithVehicleThatHasDifferentStartAndEndLocation_routeMustHaveCorrectEndTime(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocationId("start").setEndLocationId("end").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
assertEquals(vRoute.getEnd().getArrTime(),100.0,0.01);
|
||||
assertEquals(vRoute.getEnd().getTheoreticalLatestOperationStartTime(),100.0,0.01);
|
||||
assertEquals(200.0,vRoute.getEnd().getTheoreticalLatestOperationStartTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingDepartureTimeInBetweenEarliestStartAndLatestArr_routeMustHaveCorrectDepartureTime(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocationId("start").setEndLocationId("end").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
|
|
@ -222,6 +230,7 @@ public class TestVehicleRoute {
|
|||
assertEquals(vRoute.getDepartureTime(),150.0,0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingDepartureEarlierThanEarliestStart_routeMustHaveEarliestDepTimeAsDepTime(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocationId("start").setEndLocationId("end").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
|
|
@ -230,6 +239,7 @@ public class TestVehicleRoute {
|
|||
assertEquals(vRoute.getDepartureTime(),100.0,0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingDepartureTimeLaterThanLatestArrival_routeMustHaveThisDepTime(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocationId("start").setEndLocationId("end").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
|
|
@ -238,12 +248,14 @@ public class TestVehicleRoute {
|
|||
assertEquals(vRoute.getDepartureTime(),100.0,0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenCreatingEmptyRoute_itMustReturnEmptyRoute(){
|
||||
@SuppressWarnings("unused")
|
||||
VehicleRoute route = VehicleRoute.emptyRoute();
|
||||
assertTrue(true);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenIniRouteWithNewVehicle_startLocationMustBeCorrect(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocationId("start").setEndLocationId("end").build();
|
||||
Vehicle new_vehicle = VehicleImpl.Builder.newInstance("new_v").setEarliestStart(1000).setLatestArrival(2000).setStartLocationId("new_start").setEndLocationId("new_end").build();
|
||||
|
|
@ -252,14 +264,16 @@ public class TestVehicleRoute {
|
|||
assertEquals("new_start",vRoute.getStart().getLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenIniRouteWithNewVehicle_endLocationMustBeCorrect(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocationId("start").setEndLocationId("end").build();
|
||||
Vehicle new_vehicle = VehicleImpl.Builder.newInstance("new_v").setEarliestStart(1000).setLatestArrival(2000).setStartLocationId("new_start").setEndLocationId("new_end").build();
|
||||
VehicleRoute vRoute = VehicleRoute.Builder.newInstance(vehicle, DriverImpl.noDriver()).build();
|
||||
vRoute.setVehicleAndDepartureTime(new_vehicle, 50.0);
|
||||
assertEquals("new_end",vRoute.getStart().getLocationId());
|
||||
assertEquals("new_end",vRoute.getEnd().getLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenIniRouteWithNewVehicle_depTimeMustBeEarliestDepTimeOfNewVehicle(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocationId("start").setEndLocationId("end").build();
|
||||
Vehicle new_vehicle = VehicleImpl.Builder.newInstance("new_v").setEarliestStart(1000).setLatestArrival(2000).setStartLocationId("new_start").setEndLocationId("new_end").build();
|
||||
|
|
@ -268,6 +282,7 @@ public class TestVehicleRoute {
|
|||
assertEquals(1000.0,vRoute.getDepartureTime(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenIniRouteWithNewVehicle_depTimeMustBeSetDepTime(){
|
||||
Vehicle vehicle = VehicleImpl.Builder.newInstance("v").setEarliestStart(100).setLatestArrival(200).setStartLocationId("start").setEndLocationId("end").build();
|
||||
Vehicle new_vehicle = VehicleImpl.Builder.newInstance("new_v").setEarliestStart(1000).setLatestArrival(2000).setStartLocationId("new_start").setEndLocationId("new_end").build();
|
||||
|
|
|
|||
|
|
@ -65,14 +65,15 @@ public class VehicleRouteBuilderTest {
|
|||
Shipment s2 = mock(Shipment.class);
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
when(vehicle.getLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.getStartLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.getEndLocationId()).thenReturn("vehLoc");
|
||||
VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class));
|
||||
builder.addPickup(s);
|
||||
builder.addPickup(s2);
|
||||
builder.addDelivery(s);
|
||||
builder.addDelivery(s2);
|
||||
VehicleRoute route = builder.build();
|
||||
assertEquals(route.getEnd().getLocationId(), vehicle.getLocationId());
|
||||
assertEquals("vehLoc",route.getEnd().getLocationId());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -82,7 +83,7 @@ public class VehicleRouteBuilderTest {
|
|||
when(s2.getDeliveryLocation()).thenReturn("delLoc");
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
when(vehicle.getLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.getStartLocationId()).thenReturn("vehLoc");
|
||||
VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class));
|
||||
builder.addPickup(s);
|
||||
builder.addPickup(s2);
|
||||
|
|
@ -99,7 +100,7 @@ public class VehicleRouteBuilderTest {
|
|||
when(s2.getDeliveryLocation()).thenReturn("delLoc");
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
when(vehicle.getLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.getStartLocationId()).thenReturn("vehLoc");
|
||||
VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class));
|
||||
builder.addPickup(s);
|
||||
builder.addPickup(s2);
|
||||
|
|
@ -119,7 +120,7 @@ public class VehicleRouteBuilderTest {
|
|||
when(s2.getDeliveryLocation()).thenReturn("delLoc");
|
||||
Vehicle vehicle = mock(Vehicle.class);
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
when(vehicle.getLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.getStartLocationId()).thenReturn("vehLoc");
|
||||
when(vehicle.getLatestArrival()).thenReturn(200.0);
|
||||
VehicleRoute.Builder builder = VehicleRoute.Builder.newInstance(vehicle, mock(Driver.class));
|
||||
builder.addPickup(s);
|
||||
|
|
|
|||
|
|
@ -121,12 +121,6 @@ public class VehicleImplTest {
|
|||
assertEquals(2.0, v.getCoord().getY(),0.01);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenStartLocationCoordIsNull_itThrowsException(){
|
||||
@SuppressWarnings("unused")
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationCoordinate(null).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenEndLocationIsSet_itIsDoneCorrectly(){
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("startLoc").setEndLocationId("endLoc").build();
|
||||
|
|
@ -134,12 +128,6 @@ public class VehicleImplTest {
|
|||
assertEquals("endLoc", v.getEndLocationId());
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenEndLocationIsNull_itThrowsException(){
|
||||
@SuppressWarnings("unused")
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setEndLocationId(null).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenEndLocationCoordIsSet_itIsDoneCorrectly(){
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("startLoc").setEndLocationCoordinate(Coordinate.newInstance(1, 2)).build();
|
||||
|
|
@ -147,12 +135,7 @@ public class VehicleImplTest {
|
|||
assertEquals(2.0, v.getEndLocationCoordinate().getY(),0.01);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenEndLocationCoordIsNull_itThrowsException(){
|
||||
@SuppressWarnings("unused")
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setEndLocationCoordinate(null).build();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void whenNeitherEndLocationIdNorEndLocationCoordAreSet_endLocationIdMustBeEqualToStartLocationId(){
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocationId("startLoc").build();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue