mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
refine max-time-in-vehicle constraint
This commit is contained in:
parent
b5998e1d93
commit
db0c39e1c2
22 changed files with 448 additions and 436 deletions
|
|
@ -115,8 +115,8 @@ public class TestLocalActivityInsertionCostsCalculator {
|
|||
new StateManager(vrp));
|
||||
double cost = localActivityInsertionCostsCalculator.getCosts(
|
||||
jobInsertionContext,
|
||||
new Start(v.getStartLocation(),0,Double.MAX_VALUE),
|
||||
new End(v.getEndLocation(),0,Double.MAX_VALUE),
|
||||
new Start(v.getStartLocation(), 0, Double.MAX_VALUE),
|
||||
new End(v.getEndLocation(), 0, Double.MAX_VALUE),
|
||||
vrp.getActivities(s).get(0),
|
||||
0);
|
||||
assertEquals(20., cost, Math.ulp(20.));
|
||||
|
|
@ -146,15 +146,15 @@ public class TestLocalActivityInsertionCostsCalculator {
|
|||
new StateManager(vrp));
|
||||
double cost = localActivityInsertionCostsCalculator.getCosts(
|
||||
jobInsertionContext,
|
||||
new Start(v.getStartLocation(),0,Double.MAX_VALUE),
|
||||
new End(v.getEndLocation(),0,Double.MAX_VALUE),
|
||||
new Start(v.getStartLocation(), 0, Double.MAX_VALUE),
|
||||
new End(v.getEndLocation(), 0, Double.MAX_VALUE),
|
||||
vrp.getActivities(s).get(0),
|
||||
0);
|
||||
assertEquals(20., cost, Math.ulp(20.));
|
||||
cost = localActivityInsertionCostsCalculator.getCosts(
|
||||
jobInsertionContext,
|
||||
vrp.getActivities(s).get(0),
|
||||
new End(v.getEndLocation(),0,Double.MAX_VALUE),
|
||||
new End(v.getEndLocation(), 0, Double.MAX_VALUE),
|
||||
vrp.getActivities(s).get(1),
|
||||
0);
|
||||
assertEquals(10, cost, Math.ulp(10.));
|
||||
|
|
|
|||
|
|
@ -18,17 +18,14 @@
|
|||
|
||||
package com.graphhopper.jsprit.core.problem;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import com.graphhopper.jsprit.core.util.Coordinate;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.graphhopper.jsprit.core.util.Coordinate;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Created by schroeder on 16.12.14.
|
||||
|
|
@ -45,7 +42,7 @@ public class LocationTest {
|
|||
@Test
|
||||
public void whenNameSet_buildLocation() {
|
||||
Location l = Location.Builder.newInstance().setName("mystreet 6a").setIndex(1).build();
|
||||
Assert.assertEquals("mystreet 6a",l.getName());
|
||||
Assert.assertEquals("mystreet 6a", l.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -82,8 +79,8 @@ public class LocationTest {
|
|||
@Test
|
||||
public void whenCoordinateSet_build() {
|
||||
Location l = Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 20)).build();
|
||||
Assert.assertEquals(10., l.getCoordinate().getX(),0.001);
|
||||
Assert.assertEquals(20., l.getCoordinate().getY(),0.001);
|
||||
Assert.assertEquals(10., l.getCoordinate().getX(), 0.001);
|
||||
Assert.assertEquals(20., l.getCoordinate().getY(), 0.001);
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
|
||||
|
|
@ -91,8 +88,8 @@ public class LocationTest {
|
|||
public void whenCoordinateSetWithFactory_returnCorrectLocation() {
|
||||
// Location l = Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10,20)).build();
|
||||
Location l = Location.newInstance(10, 20);
|
||||
Assert.assertEquals(10., l.getCoordinate().getX(),0.001);
|
||||
Assert.assertEquals(20., l.getCoordinate().getY(),0.001);
|
||||
Assert.assertEquals(10., l.getCoordinate().getX(), 0.001);
|
||||
Assert.assertEquals(20., l.getCoordinate().getY(), 0.001);
|
||||
Assert.assertTrue(true);
|
||||
}
|
||||
|
||||
|
|
@ -100,7 +97,7 @@ public class LocationTest {
|
|||
@Test
|
||||
public void whenSettingUserData_itIsAssociatedWithTheLocation() {
|
||||
Location one = Location.Builder.newInstance().setCoordinate(Coordinate.newInstance(10, 20))
|
||||
.setUserData(new HashMap<String, Object>()).build();
|
||||
.setUserData(new HashMap<String, Object>()).build();
|
||||
Location two = Location.Builder.newInstance().setIndex(1).setUserData(42).build();
|
||||
Location three = Location.Builder.newInstance().setIndex(2).build();
|
||||
|
||||
|
|
|
|||
|
|
@ -37,14 +37,14 @@ import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
|
|||
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
|
||||
import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl;
|
||||
import com.graphhopper.jsprit.core.util.ManhattanCosts;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by schroeder on 18/05/16.
|
||||
|
|
@ -63,31 +63,31 @@ public class VehicleDependentTraveledDistanceTest {
|
|||
|
||||
VehicleRoutingProblem vrp;
|
||||
|
||||
Delivery d1,d2,newDelivery;
|
||||
Delivery d1, d2, newDelivery;
|
||||
|
||||
Pickup pickup;
|
||||
|
||||
Shipment s1;
|
||||
|
||||
Map<Vehicle,Double> maxDistanceMap;
|
||||
Map<Vehicle, Double> maxDistanceMap;
|
||||
|
||||
|
||||
@Before
|
||||
public void doBefore(){
|
||||
vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0)).build();
|
||||
vehicle2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance(10,10)).build();
|
||||
public void doBefore() {
|
||||
vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0)).build();
|
||||
vehicle2 = VehicleImpl.Builder.newInstance("v2").setStartLocation(Location.newInstance(10, 10)).build();
|
||||
|
||||
maxDistanceMap = new HashMap<>();
|
||||
maxDistanceMap.put(vehicle,200d);
|
||||
maxDistanceMap.put(vehicle2,200d);
|
||||
maxDistanceMap.put(vehicle, 200d);
|
||||
maxDistanceMap.put(vehicle2, 200d);
|
||||
|
||||
d1 = Delivery.Builder.newInstance("d1").setLocation(Location.newInstance(10,10)).build();
|
||||
d2 = Delivery.Builder.newInstance("d2").setLocation(Location.newInstance(20,15)).build();
|
||||
pickup = Pickup.Builder.newInstance("pickup").setLocation(Location.newInstance(50,50)).build();
|
||||
s1 = Shipment.Builder.newInstance("s1").setPickupLocation(Location.newInstance(35,30))
|
||||
.setDeliveryLocation(Location.newInstance(20,25)).build();
|
||||
d1 = Delivery.Builder.newInstance("d1").setLocation(Location.newInstance(10, 10)).build();
|
||||
d2 = Delivery.Builder.newInstance("d2").setLocation(Location.newInstance(20, 15)).build();
|
||||
pickup = Pickup.Builder.newInstance("pickup").setLocation(Location.newInstance(50, 50)).build();
|
||||
s1 = Shipment.Builder.newInstance("s1").setPickupLocation(Location.newInstance(35, 30))
|
||||
.setDeliveryLocation(Location.newInstance(20, 25)).build();
|
||||
|
||||
newDelivery = Delivery.Builder.newInstance("new").setLocation(Location.newInstance(-10,10)).build();
|
||||
newDelivery = Delivery.Builder.newInstance("new").setLocation(Location.newInstance(-10, 10)).build();
|
||||
|
||||
vrp = VehicleRoutingProblem.Builder.newInstance()
|
||||
.setRoutingCost(new ManhattanCosts()).addVehicle(vehicle).addVehicle(vehicle2)
|
||||
|
|
@ -104,35 +104,35 @@ public class VehicleDependentTraveledDistanceTest {
|
|||
new com.graphhopper.jsprit.core.algorithm.state.VehicleDependentTraveledDistance(new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return new ManhattanCosts().getDistance(from,to,departureTime,vehicle);
|
||||
return new ManhattanCosts().getDistance(from, to, departureTime, vehicle);
|
||||
}
|
||||
},stateManager,traveledDistanceId,Arrays.asList(vehicle,vehicle2));
|
||||
}, stateManager, traveledDistanceId, Arrays.asList(vehicle, vehicle2));
|
||||
|
||||
stateManager.addStateUpdater(traveledDistance);
|
||||
stateManager.informInsertionStarts(Arrays.asList(route), Collections.<Job>emptyList());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenEndLocationIsSet_constraintShouldWork(){
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0,0))
|
||||
.setEndLocation(Location.newInstance(10,0)).build();
|
||||
Pickup pickup = Pickup.Builder.newInstance("pickup").setLocation(Location.newInstance(10,0)).build();
|
||||
public void whenEndLocationIsSet_constraintShouldWork() {
|
||||
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance(0, 0))
|
||||
.setEndLocation(Location.newInstance(10, 0)).build();
|
||||
Pickup pickup = Pickup.Builder.newInstance("pickup").setLocation(Location.newInstance(10, 0)).build();
|
||||
vrp = VehicleRoutingProblem.Builder.newInstance().addVehicle(vehicle).addJob(pickup).build();
|
||||
route = VehicleRoute.emptyRoute();
|
||||
maxDistanceMap = new HashMap<>();
|
||||
maxDistanceMap.put(vehicle,5d);
|
||||
maxDistanceMap.put(vehicle, 5d);
|
||||
|
||||
MaxDistanceConstraint maxDistanceConstraint =
|
||||
new MaxDistanceConstraint(new StateManager(vrp), traveledDistanceId, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportTime(from,to,departureTime, null, vehicle);
|
||||
return vrp.getTransportCosts().getTransportTime(from, to, departureTime, null, vehicle);
|
||||
}
|
||||
},maxDistanceMap);
|
||||
JobInsertionContext context = new JobInsertionContext(route,pickup,vehicle,null,0);
|
||||
}, maxDistanceMap);
|
||||
JobInsertionContext context = new JobInsertionContext(route, pickup, vehicle, null, 0);
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,
|
||||
new Start(vehicle.getStartLocation(),0,Double.MAX_VALUE),vrp.getActivities(pickup).get(0),
|
||||
new End(vehicle.getEndLocation(),0,Double.MAX_VALUE),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
new Start(vehicle.getStartLocation(), 0, Double.MAX_VALUE), vrp.getActivities(pickup).get(0),
|
||||
new End(vehicle.getEndLocation(), 0, Double.MAX_VALUE), 0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
@ -142,121 +142,121 @@ vehicle2: 160.0
|
|||
vehicle2 (max distance): 180.0
|
||||
*/
|
||||
@Test
|
||||
public void insertNewInVehicleShouldFail(){
|
||||
public void insertNewInVehicleShouldFail() {
|
||||
MaxDistanceConstraint maxDistanceConstraint =
|
||||
new MaxDistanceConstraint(stateManager, traveledDistanceId, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportTime(from,to,departureTime, null, vehicle);
|
||||
return vrp.getTransportCosts().getTransportTime(from, to, departureTime, null, vehicle);
|
||||
}
|
||||
},maxDistanceMap);
|
||||
JobInsertionContext context = new JobInsertionContext(route,newDelivery,vehicle,null,0);
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,route.getStart(),newAct(),act(0),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(0),newAct(),act(1),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(1),newAct(),act(2),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(2),newAct(),act(3),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(3),newAct(),act(4),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(4),newAct(),route.getEnd(),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
}, maxDistanceMap);
|
||||
JobInsertionContext context = new JobInsertionContext(route, newDelivery, vehicle, null, 0);
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, route.getStart(), newAct(), act(0), 0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, act(0), newAct(), act(1), 0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, act(1), newAct(), act(2), 0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, act(2), newAct(), act(3), 0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, act(3), newAct(), act(4), 0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, act(4), newAct(), route.getEnd(), 0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void insertNewInVehicle2ShouldBeCorrect(){
|
||||
public void insertNewInVehicle2ShouldBeCorrect() {
|
||||
//current distance vehicle2: 160 allowed: 200
|
||||
MaxDistanceConstraint maxDistanceConstraint =
|
||||
new MaxDistanceConstraint(stateManager, traveledDistanceId, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportTime(from,to,departureTime, null, vehicle);
|
||||
return vrp.getTransportCosts().getTransportTime(from, to, departureTime, null, vehicle);
|
||||
}
|
||||
},maxDistanceMap);
|
||||
JobInsertionContext context = new JobInsertionContext(route,newDelivery,vehicle2,null,0);
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,route.getStart(),newAct(),act(0),0).equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
|
||||
}, maxDistanceMap);
|
||||
JobInsertionContext context = new JobInsertionContext(route, newDelivery, vehicle2, null, 0);
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, route.getStart(), newAct(), act(0), 0).equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
|
||||
//additional distance: 20+35-15=40
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(0),newAct(),act(1),0).equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, act(0), newAct(), act(1), 0).equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
|
||||
//additional distance: 35+65-30=70
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(1),newAct(),act(2),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, act(1), newAct(), act(2), 0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
//additional distance: 65+100-35
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(2),newAct(),act(3),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, act(2), newAct(), act(3), 0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
//additional distance: 100+45-55
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(3),newAct(),act(4),0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, act(3), newAct(), act(4), 0).equals(HardActivityConstraint.ConstraintsStatus.NOT_FULFILLED));
|
||||
//additional distance: 45+20-25
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,act(4),newAct(),route.getEnd(),0).equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context, act(4), newAct(), route.getEnd(), 0).equals(HardActivityConstraint.ConstraintsStatus.FULFILLED));
|
||||
}
|
||||
|
||||
private TourActivity act(int i) {
|
||||
return route.getActivities().get(i);
|
||||
}
|
||||
|
||||
private TourActivity newAct(){
|
||||
private TourActivity newAct() {
|
||||
return vrp.getActivities(newDelivery).get(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void traveledDistanceShouldBeCorrect(){
|
||||
Assert.assertEquals(20d,stateManager.getActivityState(route.getActivities().get(0),vehicle,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(35d,stateManager.getActivityState(route.getActivities().get(1),vehicle,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(65d,stateManager.getActivityState(route.getActivities().get(2),vehicle,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(100d,stateManager.getActivityState(route.getActivities().get(3),vehicle,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(155d,stateManager.getActivityState(route.getActivities().get(4),vehicle,traveledDistanceId,Double.class),0.01);
|
||||
public void traveledDistanceShouldBeCorrect() {
|
||||
Assert.assertEquals(20d, stateManager.getActivityState(route.getActivities().get(0), vehicle, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(35d, stateManager.getActivityState(route.getActivities().get(1), vehicle, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(65d, stateManager.getActivityState(route.getActivities().get(2), vehicle, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(100d, stateManager.getActivityState(route.getActivities().get(3), vehicle, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(155d, stateManager.getActivityState(route.getActivities().get(4), vehicle, traveledDistanceId, Double.class), 0.01);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void traveledDistanceWithVehicle2ShouldBeCorrect(){
|
||||
Assert.assertEquals(0d,stateManager.getActivityState(route.getActivities().get(0),vehicle2,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(15d,stateManager.getActivityState(route.getActivities().get(1),vehicle2,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(45d,stateManager.getActivityState(route.getActivities().get(2),vehicle2,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(80d,stateManager.getActivityState(route.getActivities().get(3),vehicle2,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(135d,stateManager.getActivityState(route.getActivities().get(4),vehicle2,traveledDistanceId,Double.class),0.01);
|
||||
public void traveledDistanceWithVehicle2ShouldBeCorrect() {
|
||||
Assert.assertEquals(0d, stateManager.getActivityState(route.getActivities().get(0), vehicle2, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(15d, stateManager.getActivityState(route.getActivities().get(1), vehicle2, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(45d, stateManager.getActivityState(route.getActivities().get(2), vehicle2, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(80d, stateManager.getActivityState(route.getActivities().get(3), vehicle2, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(135d, stateManager.getActivityState(route.getActivities().get(4), vehicle2, traveledDistanceId, Double.class), 0.01);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceOfShipmentInRoute(){
|
||||
double traveledDistanceBeforePickup = stateManager.getActivityState(route.getActivities().get(2), vehicle,traveledDistanceId, Double.class);
|
||||
public void distanceOfShipmentInRoute() {
|
||||
double traveledDistanceBeforePickup = stateManager.getActivityState(route.getActivities().get(2), vehicle, traveledDistanceId, Double.class);
|
||||
double traveledDistanceBeforeDelivery = stateManager.getActivityState(route.getActivities().get(4), vehicle, traveledDistanceId, Double.class);
|
||||
Assert.assertEquals(90d,traveledDistanceBeforeDelivery-traveledDistanceBeforePickup,0.01);
|
||||
Assert.assertEquals(90d, traveledDistanceBeforeDelivery - traveledDistanceBeforePickup, 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceOfShipmentInRouteVehicle2(){
|
||||
double traveledDistanceBeforePickup = stateManager.getActivityState(route.getActivities().get(2), vehicle2,traveledDistanceId, Double.class);
|
||||
public void distanceOfShipmentInRouteVehicle2() {
|
||||
double traveledDistanceBeforePickup = stateManager.getActivityState(route.getActivities().get(2), vehicle2, traveledDistanceId, Double.class);
|
||||
double traveledDistanceBeforeDelivery = stateManager.getActivityState(route.getActivities().get(4), vehicle2, traveledDistanceId, Double.class);
|
||||
Assert.assertEquals(90d,traveledDistanceBeforeDelivery-traveledDistanceBeforePickup,0.01);
|
||||
Assert.assertEquals(90d, traveledDistanceBeforeDelivery - traveledDistanceBeforePickup, 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceOfPickupInRoute(){
|
||||
public void distanceOfPickupInRoute() {
|
||||
double traveledDistanceBeforePickup = stateManager.getActivityState(route.getActivities().get(3), vehicle, traveledDistanceId, Double.class);
|
||||
double total = stateManager.getRouteState(route, vehicle,traveledDistanceId, Double.class);
|
||||
Assert.assertEquals(100d,total-traveledDistanceBeforePickup,0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceOfPickupInRouteVehicle2(){
|
||||
double traveledDistanceBeforePickup = stateManager.getActivityState(route.getActivities().get(3), vehicle2, traveledDistanceId, Double.class);
|
||||
double total = stateManager.getRouteState(route, vehicle2,traveledDistanceId, Double.class);
|
||||
Assert.assertEquals(80d,total-traveledDistanceBeforePickup,0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceToTravelShouldBeCorrect(){
|
||||
double total = stateManager.getRouteState(route, vehicle, traveledDistanceId, Double.class);
|
||||
Assert.assertEquals(180d,total - stateManager.getActivityState(route.getActivities().get(0),vehicle,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(100d, total - traveledDistanceBeforePickup, 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceOfPickupInRouteVehicle2() {
|
||||
double traveledDistanceBeforePickup = stateManager.getActivityState(route.getActivities().get(3), vehicle2, traveledDistanceId, Double.class);
|
||||
double total = stateManager.getRouteState(route, vehicle2, traveledDistanceId, Double.class);
|
||||
Assert.assertEquals(80d, total - traveledDistanceBeforePickup, 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceToTravelShouldBeCorrect() {
|
||||
double total = stateManager.getRouteState(route, vehicle, traveledDistanceId, Double.class);
|
||||
Assert.assertEquals(180d, total - stateManager.getActivityState(route.getActivities().get(0), vehicle, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(165d, total - stateManager.getActivityState(route.getActivities().get(1), vehicle, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(135d,total - stateManager.getActivityState(route.getActivities().get(2),vehicle,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(135d, total - stateManager.getActivityState(route.getActivities().get(2), vehicle, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(100d, total - stateManager.getActivityState(route.getActivities().get(3), vehicle, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(45d, total - stateManager.getActivityState(route.getActivities().get(4), vehicle, traveledDistanceId, Double.class), 0.01);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void distanceToTravelShouldBeCorrectVehicle2(){
|
||||
public void distanceToTravelShouldBeCorrectVehicle2() {
|
||||
double total = stateManager.getRouteState(route, vehicle2, traveledDistanceId, Double.class);
|
||||
Assert.assertEquals(160d,total - stateManager.getActivityState(route.getActivities().get(0),vehicle2,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(160d, total - stateManager.getActivityState(route.getActivities().get(0), vehicle2, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(145d, total - stateManager.getActivityState(route.getActivities().get(1), vehicle2, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(115d,total - stateManager.getActivityState(route.getActivities().get(2),vehicle2,traveledDistanceId,Double.class),0.01);
|
||||
Assert.assertEquals(115d, total - stateManager.getActivityState(route.getActivities().get(2), vehicle2, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(80d, total - stateManager.getActivityState(route.getActivities().get(3), vehicle2, traveledDistanceId, Double.class), 0.01);
|
||||
Assert.assertEquals(25d, total - stateManager.getActivityState(route.getActivities().get(4), vehicle2, traveledDistanceId, Double.class), 0.01);
|
||||
|
||||
|
|
@ -280,16 +280,16 @@ vehicle2 (max distance): 180.0
|
|||
context.getAssociatedActivities().add(vrp.getActivities(shipment).get(0));
|
||||
context.getAssociatedActivities().add(vrp.getActivities(shipment).get(1));
|
||||
maxDistanceMap = new HashMap<>();
|
||||
maxDistanceMap.put(vehicle,12d);
|
||||
maxDistanceMap.put(vehicle, 12d);
|
||||
|
||||
StateManager stateManager = new StateManager(vrp);
|
||||
MaxDistanceConstraint maxDistanceConstraint =
|
||||
new MaxDistanceConstraint(stateManager, traveledDistanceId, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportTime(from,to,departureTime, null, vehicle);
|
||||
return vrp.getTransportCosts().getTransportTime(from, to, departureTime, null, vehicle);
|
||||
}
|
||||
},maxDistanceMap);
|
||||
}, maxDistanceMap);
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,
|
||||
new Start(vehicle.getStartLocation(), 0, Double.MAX_VALUE),
|
||||
vrp.getActivities(shipment).get(0),
|
||||
|
|
@ -327,16 +327,16 @@ vehicle2 (max distance): 180.0
|
|||
context.getAssociatedActivities().add(vrp.getActivities(shipment).get(0));
|
||||
context.getAssociatedActivities().add(vrp.getActivities(shipment).get(1));
|
||||
maxDistanceMap = new HashMap<>();
|
||||
maxDistanceMap.put(vehicle,10d);
|
||||
maxDistanceMap.put(vehicle, 10d);
|
||||
|
||||
StateManager stateManager = new StateManager(vrp);
|
||||
MaxDistanceConstraint maxDistanceConstraint =
|
||||
new MaxDistanceConstraint(stateManager, traveledDistanceId, new TransportDistance() {
|
||||
@Override
|
||||
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
|
||||
return vrp.getTransportCosts().getTransportTime(from,to,departureTime, null, vehicle);
|
||||
return vrp.getTransportCosts().getTransportTime(from, to, departureTime, null, vehicle);
|
||||
}
|
||||
},maxDistanceMap);
|
||||
}, maxDistanceMap);
|
||||
Assert.assertTrue(maxDistanceConstraint.fulfilled(context,
|
||||
new Start(vehicle.getStartLocation(), 0, Double.MAX_VALUE),
|
||||
vrp.getActivities(shipment).get(0),
|
||||
|
|
|
|||
|
|
@ -17,18 +17,14 @@
|
|||
*/
|
||||
package com.graphhopper.jsprit.core.problem.job;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class DeliveryTest {
|
||||
|
||||
|
|
@ -40,9 +36,9 @@ public class DeliveryTest {
|
|||
@Test
|
||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() {
|
||||
Delivery one = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
||||
.addSizeDimension(0, 2)
|
||||
.addSizeDimension(1, 4)
|
||||
.build();
|
||||
.addSizeDimension(0, 2)
|
||||
.addSizeDimension(1, 4)
|
||||
.build();
|
||||
assertEquals(2, one.getSize().getNuOfDimensions());
|
||||
assertEquals(2, one.getSize().get(0));
|
||||
assertEquals(4, one.getSize().get(1));
|
||||
|
|
@ -52,7 +48,7 @@ public class DeliveryTest {
|
|||
@Test
|
||||
public void whenPickupIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() {
|
||||
Delivery one = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
||||
.build();
|
||||
.build();
|
||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||
assertEquals(0, one.getSize().get(0));
|
||||
}
|
||||
|
|
@ -60,7 +56,7 @@ public class DeliveryTest {
|
|||
@Test
|
||||
public void whenPickupIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() {
|
||||
Delivery one = Delivery.Builder.newInstance("s").addSizeDimension(0, 1).setLocation(Location.newInstance("foofoo"))
|
||||
.build();
|
||||
.build();
|
||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||
assertEquals(1, one.getSize().get(0));
|
||||
}
|
||||
|
|
@ -68,7 +64,7 @@ public class DeliveryTest {
|
|||
@Test
|
||||
public void whenAddingSkills_theyShouldBeAddedCorrectly() {
|
||||
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver"));
|
||||
}
|
||||
|
|
@ -76,7 +72,7 @@ public class DeliveryTest {
|
|||
@Test
|
||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
|
||||
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
|
|
@ -84,7 +80,7 @@ public class DeliveryTest {
|
|||
@Test
|
||||
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
||||
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("screwDriver").build();
|
||||
.addRequiredSkill("screwDriver").build();
|
||||
assertFalse(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertFalse(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
|
|
@ -92,21 +88,21 @@ public class DeliveryTest {
|
|||
@Test
|
||||
public void nameShouldBeAssigned() {
|
||||
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setName("name").build();
|
||||
.setName("name").build();
|
||||
assertEquals("name", s.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingPriorities_itShouldBeSetCorrectly(){
|
||||
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setPriority(3).build();
|
||||
.setPriority(3).build();
|
||||
Assert.assertEquals(3, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenNotSettingPriorities_defaultShouldBe(){
|
||||
Delivery s = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.build();
|
||||
.build();
|
||||
Assert.assertEquals(2, s.getPriority());
|
||||
}
|
||||
|
||||
|
|
@ -129,9 +125,9 @@ public class DeliveryTest {
|
|||
@Test
|
||||
public void whenSettingUserData_itIsAssociatedWithTheJob() {
|
||||
Delivery one = Delivery.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setUserData(new HashMap<String, Object>()).build();
|
||||
.setUserData(new HashMap<String, Object>()).build();
|
||||
Delivery two = Delivery.Builder.newInstance("s2").setLocation(Location.newInstance("loc")).setUserData(42)
|
||||
.build();
|
||||
.build();
|
||||
Delivery three = Delivery.Builder.newInstance("s3").setLocation(Location.newInstance("loc")).build();
|
||||
|
||||
assertTrue(one.getUserData() instanceof Map);
|
||||
|
|
|
|||
|
|
@ -17,18 +17,14 @@
|
|||
*/
|
||||
package com.graphhopper.jsprit.core.problem.job;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class PickupTest {
|
||||
|
||||
|
|
@ -40,9 +36,9 @@ public class PickupTest {
|
|||
@Test
|
||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() {
|
||||
Pickup one = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
||||
.addSizeDimension(0, 2)
|
||||
.addSizeDimension(1, 4)
|
||||
.build();
|
||||
.addSizeDimension(0, 2)
|
||||
.addSizeDimension(1, 4)
|
||||
.build();
|
||||
assertEquals(2, one.getSize().getNuOfDimensions());
|
||||
assertEquals(2, one.getSize().get(0));
|
||||
assertEquals(4, one.getSize().get(1));
|
||||
|
|
@ -52,7 +48,7 @@ public class PickupTest {
|
|||
@Test
|
||||
public void whenPickupIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() {
|
||||
Pickup one = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
||||
.build();
|
||||
.build();
|
||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||
assertEquals(0, one.getSize().get(0));
|
||||
}
|
||||
|
|
@ -60,7 +56,7 @@ public class PickupTest {
|
|||
@Test
|
||||
public void whenPickupIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() {
|
||||
Pickup one = Pickup.Builder.newInstance("s").addSizeDimension(0, 1).setLocation(Location.newInstance("foofoo"))
|
||||
.build();
|
||||
.build();
|
||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||
assertEquals(1, one.getSize().get(0));
|
||||
}
|
||||
|
|
@ -68,7 +64,7 @@ public class PickupTest {
|
|||
@Test
|
||||
public void whenAddingSkills_theyShouldBeAddedCorrectly() {
|
||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver"));
|
||||
|
|
@ -77,7 +73,7 @@ public class PickupTest {
|
|||
@Test
|
||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
|
||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
|
|
@ -85,7 +81,7 @@ public class PickupTest {
|
|||
@Test
|
||||
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("screwDriver").build();
|
||||
.addRequiredSkill("screwDriver").build();
|
||||
assertFalse(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertFalse(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
|
|
@ -93,7 +89,7 @@ public class PickupTest {
|
|||
@Test
|
||||
public void nameShouldBeAssigned() {
|
||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setName("name").build();
|
||||
.setName("name").build();
|
||||
assertEquals("name", s.getName());
|
||||
}
|
||||
|
||||
|
|
@ -101,21 +97,21 @@ public class PickupTest {
|
|||
@Test
|
||||
public void whenSettingPriorities_itShouldBeSetCorrectly(){
|
||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setPriority(3).build();
|
||||
.setPriority(3).build();
|
||||
Assert.assertEquals(3, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenNotSettingPriorities_defaultShouldBe(){
|
||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.build();
|
||||
.build();
|
||||
Assert.assertEquals(2, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingUserData_itIsAssociatedWithTheJob() {
|
||||
Pickup one = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setUserData(new HashMap<String, Object>()).build();
|
||||
.setUserData(new HashMap<String, Object>()).build();
|
||||
Pickup two = Pickup.Builder.newInstance("s2").setLocation(Location.newInstance("loc")).setUserData(42).build();
|
||||
Pickup three = Pickup.Builder.newInstance("s3").setLocation(Location.newInstance("loc")).build();
|
||||
|
||||
|
|
@ -123,7 +119,7 @@ public class PickupTest {
|
|||
assertEquals(42, two.getUserData());
|
||||
assertNull(three.getUserData());
|
||||
}
|
||||
|
||||
|
||||
@Test(expected = UnsupportedOperationException.class)
|
||||
public void whenAddingMaxTimeInVehicle_itShouldThrowEx(){
|
||||
Pickup s = Pickup.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
|
|
|
|||
|
|
@ -17,25 +17,19 @@
|
|||
*/
|
||||
package com.graphhopper.jsprit.core.problem.job;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsCollectionContaining.hasItem;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsCollectionContaining.hasItem;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ServiceTest {
|
||||
|
||||
|
|
@ -75,16 +69,16 @@ public class ServiceTest {
|
|||
@Test
|
||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() {
|
||||
Service one = Service.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
||||
.addSizeDimension(0, 2)
|
||||
.addSizeDimension(1, 4)
|
||||
.build();
|
||||
.addSizeDimension(0, 2)
|
||||
.addSizeDimension(1, 4)
|
||||
.build();
|
||||
assertEquals(2, one.getSize().getNuOfDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenShipmentIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() {
|
||||
Service one = Service.Builder.newInstance("s").setLocation(Location.newInstance("foofoo"))
|
||||
.build();
|
||||
.build();
|
||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||
assertEquals(0, one.getSize().get(0));
|
||||
}
|
||||
|
|
@ -92,7 +86,7 @@ public class ServiceTest {
|
|||
@Test
|
||||
public void whenShipmentIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() {
|
||||
Service one = Service.Builder.newInstance("s").addSizeDimension(0, 1).setLocation(Location.newInstance("foofoo"))
|
||||
.build();
|
||||
.build();
|
||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||
assertEquals(1, one.getSize().get(0));
|
||||
}
|
||||
|
|
@ -125,58 +119,58 @@ public class ServiceTest {
|
|||
|
||||
|
||||
@Test
|
||||
public void whenSettingLocationCoord_itShouldBeSetCorrectly(){
|
||||
public void whenSettingLocationCoord_itShouldBeSetCorrectly() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance(1, 2)).build();
|
||||
assertEquals(1.0,s.getLocation().getCoordinate().getX(),0.01);
|
||||
assertEquals(2.0,s.getLocation().getCoordinate().getY(),0.01);
|
||||
assertEquals(1.0, s.getLocation().getCoordinate().getX(), 0.01);
|
||||
assertEquals(2.0, s.getLocation().getCoordinate().getY(), 0.01);
|
||||
assertEquals(1.0,s.getLocation().getCoordinate().getX(),0.01);
|
||||
assertEquals(2.0,s.getLocation().getCoordinate().getY(),0.01);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenSettingNeitherLocationIdNorCoord_throwsException(){
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSettingNeitherLocationIdNorCoord_throwsException() {
|
||||
@SuppressWarnings("unused")
|
||||
Service s = Service.Builder.newInstance("s").build();
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenServiceTimeSmallerZero_throwIllegalStateException(){
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenServiceTimeSmallerZero_throwIllegalStateException() {
|
||||
@SuppressWarnings("unused")
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setServiceTime(-1).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingServiceTime_itShouldBeSetCorrectly(){
|
||||
public void whenSettingServiceTime_itShouldBeSetCorrectly() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setServiceTime(1).build();
|
||||
assertEquals(1.0,s.getServiceDuration(),0.01);
|
||||
assertEquals(1.0, s.getServiceDuration(), 0.01);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void whenTimeWindowIsNull_throwException(){
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenTimeWindowIsNull_throwException() {
|
||||
@SuppressWarnings("unused")
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setTimeWindow(null).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingTimeWindow_itShouldBeSetCorrectly(){
|
||||
public void whenSettingTimeWindow_itShouldBeSetCorrectly() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc")).setTimeWindow(TimeWindow.newInstance(1.0, 2.0)).build();
|
||||
assertEquals(1.0,s.getTimeWindow().getStart(),0.01);
|
||||
assertEquals(2.0,s.getTimeWindow().getEnd(),0.01);
|
||||
assertEquals(1.0, s.getTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingSkills_theyShouldBeAddedCorrectly(){
|
||||
public void whenAddingSkills_theyShouldBeAddedCorrectly() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly(){
|
||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
|
|
@ -186,9 +180,9 @@ public class ServiceTest {
|
|||
TimeWindow tw1 = TimeWindow.newInstance(1.0, 2.0);
|
||||
TimeWindow tw2 = TimeWindow.newInstance(3.0, 5.0);
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addTimeWindow(tw1)
|
||||
.addTimeWindow(tw2)
|
||||
.build();
|
||||
.addTimeWindow(tw1)
|
||||
.addTimeWindow(tw2)
|
||||
.build();
|
||||
assertEquals(2, s.getTimeWindows().size());
|
||||
assertThat(s.getTimeWindows(),hasItem(is(tw1)));
|
||||
assertThat(s.getTimeWindows(),hasItem(is(tw2)));
|
||||
|
|
@ -197,7 +191,7 @@ public class ServiceTest {
|
|||
@Test
|
||||
public void whenAddingTimeWindow_itShouldBeSetCorrectly(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addTimeWindow(TimeWindow.newInstance(1.0, 2.0)).build();
|
||||
.addTimeWindow(TimeWindow.newInstance(1.0, 2.0)).build();
|
||||
assertEquals(1.0, s.getTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -208,7 +202,7 @@ public class ServiceTest {
|
|||
@Test
|
||||
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addRequiredSkill("screwDriver").build();
|
||||
.addRequiredSkill("screwDriver").build();
|
||||
assertFalse(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertFalse(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
|
|
@ -216,73 +210,73 @@ public class ServiceTest {
|
|||
@Test
|
||||
public void nameShouldBeAssigned() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setName("name").build();
|
||||
.setName("name").build();
|
||||
assertEquals("name", s.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldKnowMultipleTimeWindows(){
|
||||
public void shouldKnowMultipleTimeWindows() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addTimeWindow(TimeWindow.newInstance(0., 10.)).addTimeWindow(TimeWindow.newInstance(20., 30.))
|
||||
.setName("name").build();
|
||||
assertEquals(2,s.getTimeWindows().size());
|
||||
.addTimeWindow(TimeWindow.newInstance(0., 10.)).addTimeWindow(TimeWindow.newInstance(20., 30.))
|
||||
.setName("name").build();
|
||||
assertEquals(2, s.getTimeWindows().size());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenMultipleTWOverlap_throwEx(){
|
||||
public void whenMultipleTWOverlap_throwEx() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addTimeWindow(TimeWindow.newInstance(0.,10.))
|
||||
.addTimeWindow(TimeWindow.newInstance(5., 30.))
|
||||
.setName("name").build();
|
||||
.addTimeWindow(TimeWindow.newInstance(0., 10.))
|
||||
.addTimeWindow(TimeWindow.newInstance(5., 30.))
|
||||
.setName("name").build();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenMultipleTWOverlap2_throwEx(){
|
||||
public void whenMultipleTWOverlap2_throwEx() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.addTimeWindow(TimeWindow.newInstance(20., 30.))
|
||||
.addTimeWindow(TimeWindow.newInstance(0., 25.))
|
||||
.setName("name").build();
|
||||
.addTimeWindow(TimeWindow.newInstance(20., 30.))
|
||||
.addTimeWindow(TimeWindow.newInstance(0., 25.))
|
||||
.setName("name").build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingPriorities_itShouldBeSetCorrectly(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setPriority(1).build();
|
||||
.setPriority(1).build();
|
||||
Assert.assertEquals(1, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingPriorities_itShouldBeSetCorrectly2(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setPriority(3).build();
|
||||
.setPriority(3).build();
|
||||
Assert.assertEquals(3, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingPriorities_itShouldBeSetCorrectly3() {
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setPriority(10).build();
|
||||
.setPriority(10).build();
|
||||
Assert.assertEquals(10, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenNotSettingPriorities_defaultShouldBe2(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.build();
|
||||
.build();
|
||||
Assert.assertEquals(2, s.getPriority());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSettingIncorrectPriorities_itShouldThrowException(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setPriority(30).build();
|
||||
.setPriority(30).build();
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSettingIncorrectPriorities_itShouldThrowException2(){
|
||||
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setPriority(0).build();
|
||||
.setPriority(0).build();
|
||||
|
||||
}
|
||||
|
||||
|
|
@ -304,9 +298,9 @@ public class ServiceTest {
|
|||
@Test
|
||||
public void whenSettingUserData_itIsAssociatedWithTheJob() {
|
||||
Service one = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
|
||||
.setUserData(new HashMap<String, Object>()).build();
|
||||
.setUserData(new HashMap<String, Object>()).build();
|
||||
Service two = Service.Builder.newInstance("s2").setLocation(Location.newInstance("loc")).setUserData(42)
|
||||
.build();
|
||||
.build();
|
||||
Service three = Service.Builder.newInstance("s3").setLocation(Location.newInstance("loc")).build();
|
||||
|
||||
assertTrue(one.getUserData() instanceof Map);
|
||||
|
|
|
|||
|
|
@ -17,34 +17,28 @@
|
|||
*/
|
||||
package com.graphhopper.jsprit.core.problem.job;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsCollectionContaining.hasItem;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import com.graphhopper.jsprit.core.util.Coordinate;
|
||||
import com.graphhopper.jsprit.core.util.TestUtils;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.hamcrest.core.Is.is;
|
||||
import static org.hamcrest.core.IsCollectionContaining.hasItem;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class ShipmentTest {
|
||||
|
||||
@Test
|
||||
public void whenTwoShipmentsHaveTheSameId_theyReferencesShouldBeUnEqual() {
|
||||
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()).
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
Shipment two = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()).
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
|
||||
assertTrue(one != two);
|
||||
}
|
||||
|
|
@ -52,9 +46,9 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenTwoShipmentsHaveTheSameId_theyShouldBeEqual() {
|
||||
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()).
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
Shipment two = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()).
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
|
||||
assertTrue(one.equals(two));
|
||||
}
|
||||
|
|
@ -62,7 +56,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenShipmentIsInstantiatedWithASizeOf10_theSizeShouldBe10() {
|
||||
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 10).setPickupLocation(Location.Builder.newInstance().setId("foo").build()).
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
setDeliveryLocation(TestUtils.loc("foofoo")).setPickupServiceTime(10).setDeliveryServiceTime(20).build();
|
||||
assertEquals(10, one.getSize().get(0));
|
||||
}
|
||||
|
||||
|
|
@ -70,24 +64,24 @@ public class ShipmentTest {
|
|||
public void whenShipmentIsBuiltWithNegativeDemand_itShouldThrowException() {
|
||||
@SuppressWarnings("unused")
|
||||
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, -10)
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenShipmentIsBuiltWithNegativeDemand_itShouldThrowException_v2() {
|
||||
@SuppressWarnings("unused")
|
||||
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, -10)
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenIdIsNull_itShouldThrowException() {
|
||||
@SuppressWarnings("unused")
|
||||
Shipment one = Shipment.Builder.newInstance(null).addSizeDimension(0, 10)
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -124,7 +118,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenPickupCoordIsSet_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s")
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").setCoordinate(Coordinate.newInstance(1, 2)).build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").setCoordinate(Coordinate.newInstance(1, 2)).build()).build();
|
||||
assertEquals(1.0, s.getPickupLocation().getCoordinate().getX(), 0.01);
|
||||
assertEquals(2.0, s.getPickupLocation().getCoordinate().getY(), 0.01);
|
||||
assertEquals(1.0, s.getPickupLocation().getCoordinate().getX(), 0.01);
|
||||
|
|
@ -135,7 +129,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenDeliveryLocationIdIsSet_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s")
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals("delLoc", s.getDeliveryLocation().getId());
|
||||
assertEquals("delLoc", s.getDeliveryLocation().getId());
|
||||
}
|
||||
|
|
@ -144,8 +138,8 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenDeliveryCoordIsSet_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setDeliveryLocation(TestUtils.loc("delLoc", Coordinate.newInstance(1, 2)))
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build())
|
||||
.build();
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build())
|
||||
.build();
|
||||
assertEquals(1.0, s.getDeliveryLocation().getCoordinate().getX(), 0.01);
|
||||
assertEquals(2.0, s.getDeliveryLocation().getCoordinate().getY(), 0.01);
|
||||
assertEquals(1.0, s.getDeliveryLocation().getCoordinate().getX(), 0.01);
|
||||
|
|
@ -155,22 +149,22 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenPickupServiceTimeIsNotSet_itShouldBeZero() {
|
||||
Shipment s = Shipment.Builder.newInstance("s")
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(0.0, s.getPickupServiceTime(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDeliveryServiceTimeIsNotSet_itShouldBeZero() {
|
||||
Shipment s = Shipment.Builder.newInstance("s")
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(0.0, s.getDeliveryServiceTime(), 0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenPickupServiceTimeIsSet_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s")
|
||||
.setPickupServiceTime(2.0)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setPickupServiceTime(2.0)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(2.0, s.getPickupServiceTime(), 0.01);
|
||||
}
|
||||
|
||||
|
|
@ -178,13 +172,13 @@ public class ShipmentTest {
|
|||
public void whenPickupServiceIsSmallerThanZero_itShouldThrowException() {
|
||||
@SuppressWarnings("unused")
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupServiceTime(-2.0)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenDeliveryServiceTimeIsSet_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setDeliveryServiceTime(2.0)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(2.0, s.getDeliveryServiceTime(), 0.01);
|
||||
}
|
||||
|
||||
|
|
@ -210,7 +204,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenPickupTimeWindowIsSet_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupTimeWindow(TimeWindow.newInstance(1, 2))
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -231,7 +225,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenDeliveryTimeWindowIsSet_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setDeliveryTimeWindow(TimeWindow.newInstance(1, 2))
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -239,7 +233,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenUsingAddDeliveryTimeWindow_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(TimeWindow.newInstance(1, 2))
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -247,7 +241,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenUsingAddDeliveryTimeWindow2_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(1, 2)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -257,7 +251,7 @@ public class ShipmentTest {
|
|||
TimeWindow tw1 = TimeWindow.newInstance(1,2);
|
||||
TimeWindow tw2 = TimeWindow.newInstance(4,5);
|
||||
Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(tw1).addDeliveryTimeWindow(tw2)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(s.getDeliveryTimeWindows().size(),2);
|
||||
assertThat(s.getDeliveryTimeWindows(),hasItem(is(tw1)));
|
||||
assertThat(s.getDeliveryTimeWindows(),hasItem(is(tw2)));
|
||||
|
|
@ -266,7 +260,7 @@ public class ShipmentTest {
|
|||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenAddingMultipleOverlappingDeliveryTimeWindows_itShouldThrowException() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").addDeliveryTimeWindow(1, 3).addDeliveryTimeWindow(2,5)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getDeliveryTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getDeliveryTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -276,7 +270,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenUsingAddPickupTimeWindow_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(TimeWindow.newInstance(1, 2))
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -284,7 +278,7 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenUsingAddPickupTimeWindow2_itShouldBeDoneCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(1, 2)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -294,7 +288,7 @@ public class ShipmentTest {
|
|||
TimeWindow tw1 = TimeWindow.newInstance(1,2);
|
||||
TimeWindow tw2 = TimeWindow.newInstance(4,5);
|
||||
Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(tw1).addPickupTimeWindow(tw2)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(s.getPickupTimeWindows().size(),2);
|
||||
assertThat(s.getPickupTimeWindows(), hasItem(is(tw1)));
|
||||
assertThat(s.getPickupTimeWindows(), hasItem(is(tw2)));
|
||||
|
|
@ -303,7 +297,7 @@ public class ShipmentTest {
|
|||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenAddingMultipleOverlappingPickupTimeWindows_itShouldThrowException() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").addPickupTimeWindow(1, 3).addPickupTimeWindow(2,5)
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc")).setPickupLocation(Location.Builder.newInstance().setId("pickLoc").build()).build();
|
||||
assertEquals(1.0, s.getPickupTimeWindow().getStart(), 0.01);
|
||||
assertEquals(2.0, s.getPickupTimeWindow().getEnd(), 0.01);
|
||||
}
|
||||
|
|
@ -314,26 +308,26 @@ public class ShipmentTest {
|
|||
public void whenShipmentHasNegativeCapacityVal_throwIllegalStateExpception() {
|
||||
@SuppressWarnings("unused")
|
||||
Shipment one = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo"))
|
||||
.addSizeDimension(0, -2)
|
||||
.build();
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo"))
|
||||
.addSizeDimension(0, -2)
|
||||
.build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() {
|
||||
Shipment one = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("foo").build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo"))
|
||||
.addSizeDimension(0, 2)
|
||||
.addSizeDimension(1, 4)
|
||||
.build();
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo"))
|
||||
.addSizeDimension(0, 2)
|
||||
.addSizeDimension(1, 4)
|
||||
.build();
|
||||
assertEquals(2, one.getSize().getNuOfDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenShipmentIsBuiltWithoutSpecifyingCapacity_itShouldHvCapWithOneDimAndDimValOfZero() {
|
||||
Shipment one = Shipment.Builder.newInstance("s")
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").setCoordinate(Coordinate.newInstance(0, 0)).build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").setCoordinate(Coordinate.newInstance(0, 0)).build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||
assertEquals(0, one.getSize().get(0));
|
||||
}
|
||||
|
|
@ -341,8 +335,8 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenShipmentIsBuiltWithConstructorWhereSizeIsSpecified_capacityShouldBeSetCorrectly() {
|
||||
Shipment one = Shipment.Builder.newInstance("s").addSizeDimension(0, 1)
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").setCoordinate(Coordinate.newInstance(0, 0)).build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("foo").setCoordinate(Coordinate.newInstance(0, 0)).build())
|
||||
.setDeliveryLocation(TestUtils.loc("foofoo")).build();
|
||||
assertEquals(1, one.getSize().getNuOfDimensions());
|
||||
assertEquals(1, one.getSize().get(0));
|
||||
}
|
||||
|
|
@ -350,8 +344,8 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenAddingSkills_theyShouldBeAddedCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build())
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc"))
|
||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||
.setDeliveryLocation(TestUtils.loc("delLoc"))
|
||||
.addRequiredSkill("drill").addRequiredSkill("screwdriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("ScrewDriver"));
|
||||
|
|
@ -360,9 +354,9 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s")
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("pick").build())
|
||||
.setDeliveryLocation(TestUtils.loc("del"))
|
||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||
.setPickupLocation(Location.Builder.newInstance().setId("pick").build())
|
||||
.setDeliveryLocation(TestUtils.loc("del"))
|
||||
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertTrue(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
|
|
@ -370,8 +364,8 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build())
|
||||
.setDeliveryLocation(TestUtils.loc("del"))
|
||||
.addRequiredSkill("screwDriver").build();
|
||||
.setDeliveryLocation(TestUtils.loc("del"))
|
||||
.addRequiredSkill("screwDriver").build();
|
||||
assertFalse(s.getRequiredSkills().containsSkill("drill"));
|
||||
assertFalse(s.getRequiredSkills().containsSkill("drilL"));
|
||||
}
|
||||
|
|
@ -379,15 +373,15 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void nameShouldBeAssigned() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build())
|
||||
.setDeliveryLocation(TestUtils.loc("del"))
|
||||
.setName("name").build();
|
||||
.setDeliveryLocation(TestUtils.loc("del"))
|
||||
.setName("name").build();
|
||||
assertEquals("name", s.getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingLocation_itShouldWork() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.Builder.newInstance().setId("loc").build())
|
||||
.setDeliveryLocation(Location.Builder.newInstance().setId("del").build()).build();
|
||||
.setDeliveryLocation(Location.Builder.newInstance().setId("del").build()).build();
|
||||
assertEquals("loc", s.getPickupLocation().getId());
|
||||
assertEquals("loc", s.getPickupLocation().getId());
|
||||
assertEquals("del", s.getDeliveryLocation().getId());
|
||||
|
|
@ -397,59 +391,59 @@ public class ShipmentTest {
|
|||
@Test
|
||||
public void whenSettingPriorities_itShouldBeSetCorrectly(){
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(1).build();
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(1).build();
|
||||
Assert.assertEquals(1, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingPriorities_itShouldBeSetCorrectly2(){
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(3).build();
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(3).build();
|
||||
Assert.assertEquals(3, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingPriorities_itShouldBeSetCorrectly3() {
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(10).build();
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(10).build();
|
||||
Assert.assertEquals(10, s.getPriority());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenNotSettingPriorities_defaultShouldBe2(){
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.build();
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.build();
|
||||
Assert.assertEquals(2, s.getPriority());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSettingIncorrectPriorities_itShouldThrowException(){
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(30).build();
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(30).build();
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void whenSettingIncorrectPriorities_itShouldThrowException2(){
|
||||
Shipment s = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(0).build();
|
||||
.setDeliveryLocation(Location.newInstance("loc"))
|
||||
.setPriority(0).build();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenSettingUserData_itIsAssociatedWithTheJob() {
|
||||
Shipment one = Shipment.Builder.newInstance("s").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc")).setUserData(new HashMap<String, Object>()).build();
|
||||
.setDeliveryLocation(Location.newInstance("loc")).setUserData(new HashMap<String, Object>()).build();
|
||||
Shipment two = Shipment.Builder.newInstance("s2").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc")).setUserData(42).build();
|
||||
.setDeliveryLocation(Location.newInstance("loc")).setUserData(42).build();
|
||||
Shipment three = Shipment.Builder.newInstance("s3").setPickupLocation(Location.newInstance("loc"))
|
||||
.setDeliveryLocation(Location.newInstance("loc")).build();
|
||||
.setDeliveryLocation(Location.newInstance("loc")).build();
|
||||
|
||||
assertTrue(one.getUserData() instanceof Map);
|
||||
assertEquals(42, two.getUserData());
|
||||
|
|
|
|||
|
|
@ -18,20 +18,15 @@
|
|||
package com.graphhopper.jsprit.core.problem.vehicle;
|
||||
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.job.Break;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import com.graphhopper.jsprit.core.problem.Location;
|
||||
import com.graphhopper.jsprit.core.problem.job.Break;
|
||||
import com.graphhopper.jsprit.core.problem.solution.route.activity.TimeWindow;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
|
||||
public class VehicleImplTest {
|
||||
|
|
@ -49,8 +44,8 @@ public class VehicleImplTest {
|
|||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
Break aBreak = Break.Builder.newInstance("break").setTimeWindow(TimeWindow.newInstance(100, 200)).setServiceTime(30).build();
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start"))
|
||||
.setType(type1).setEndLocation(Location.newInstance("start"))
|
||||
.setBreak(aBreak).build();
|
||||
.setType(type1).setEndLocation(Location.newInstance("start"))
|
||||
.setBreak(aBreak).build();
|
||||
assertNotNull(v.getBreak());
|
||||
assertEquals(100., v.getBreak().getTimeWindow().getStart(), 0.1);
|
||||
assertEquals(200., v.getBreak().getTimeWindow().getEnd(), 0.1);
|
||||
|
|
@ -62,7 +57,7 @@ public class VehicleImplTest {
|
|||
public void whenAddingSkills_theyShouldBeAddedCorrectly() {
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
|
||||
.addSkill("drill").addSkill("screwdriver").build();
|
||||
.addSkill("drill").addSkill("screwdriver").build();
|
||||
assertTrue(v.getSkills().containsSkill("drill"));
|
||||
assertTrue(v.getSkills().containsSkill("drill"));
|
||||
assertTrue(v.getSkills().containsSkill("screwdriver"));
|
||||
|
|
@ -72,7 +67,7 @@ public class VehicleImplTest {
|
|||
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
|
||||
.addSkill("drill").addSkill("screwdriver").build();
|
||||
.addSkill("drill").addSkill("screwdriver").build();
|
||||
assertTrue(v.getSkills().containsSkill("drill"));
|
||||
assertTrue(v.getSkills().containsSkill("dRill"));
|
||||
assertTrue(v.getSkills().containsSkill("ScrewDriver"));
|
||||
|
|
@ -241,7 +236,7 @@ public class VehicleImplTest {
|
|||
public void whenAddingSkillsCaseSensV2_theyShouldBeAddedCorrectly() {
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
Vehicle v = VehicleImpl.Builder.newInstance("v").setStartLocation(Location.newInstance("start")).setType(type1).setEndLocation(Location.newInstance("start"))
|
||||
.addSkill("drill").build();
|
||||
.addSkill("drill").build();
|
||||
assertFalse(v.getSkills().containsSkill("ScrewDriver"));
|
||||
}
|
||||
|
||||
|
|
@ -249,11 +244,11 @@ public class VehicleImplTest {
|
|||
public void whenSettingUserData_itIsAssociatedWithTheVehicle() {
|
||||
VehicleTypeImpl type1 = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
Vehicle one = VehicleImpl.Builder.newInstance("v").setType(type1)
|
||||
.setStartLocation(Location.newInstance("start")).setUserData(new HashMap<String, Object>()).build();
|
||||
.setStartLocation(Location.newInstance("start")).setUserData(new HashMap<String, Object>()).build();
|
||||
Vehicle two = VehicleImpl.Builder.newInstance("v").setType(type1)
|
||||
.setStartLocation(Location.newInstance("start")).setUserData(42).build();
|
||||
.setStartLocation(Location.newInstance("start")).setUserData(42).build();
|
||||
Vehicle three = VehicleImpl.Builder.newInstance("v").setType(type1)
|
||||
.setStartLocation(Location.newInstance("start")).build();
|
||||
.setStartLocation(Location.newInstance("start")).build();
|
||||
|
||||
assertTrue(one.getUserData() instanceof Map);
|
||||
assertEquals(42, two.getUserData());
|
||||
|
|
|
|||
|
|
@ -17,15 +17,12 @@
|
|||
*/
|
||||
package com.graphhopper.jsprit.core.problem.vehicle;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class VehicleTypeImplTest {
|
||||
|
||||
|
|
@ -38,18 +35,18 @@ public class VehicleTypeImplTest {
|
|||
@Test
|
||||
public void whenAddingTwoCapDimension_nuOfDimsShouldBeTwo() {
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t")
|
||||
.addCapacityDimension(0, 2)
|
||||
.addCapacityDimension(1, 4)
|
||||
.build();
|
||||
.addCapacityDimension(0, 2)
|
||||
.addCapacityDimension(1, 4)
|
||||
.build();
|
||||
assertEquals(2, type.getCapacityDimensions().getNuOfDimensions());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingTwoCapDimension_dimValuesMustBeCorrect() {
|
||||
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("t")
|
||||
.addCapacityDimension(0, 2)
|
||||
.addCapacityDimension(1, 4)
|
||||
.build();
|
||||
.addCapacityDimension(0, 2)
|
||||
.addCapacityDimension(1, 4)
|
||||
.build();
|
||||
assertEquals(2, type.getCapacityDimensions().get(0));
|
||||
assertEquals(4, type.getCapacityDimensions().get(1));
|
||||
}
|
||||
|
|
@ -161,7 +158,7 @@ public class VehicleTypeImplTest {
|
|||
@Test
|
||||
public void whenSettingUserData_itIsAssociatedWithTheVehicleType() {
|
||||
VehicleType one = VehicleTypeImpl.Builder.newInstance("type").setUserData(new HashMap<String, Object>())
|
||||
.build();
|
||||
.build();
|
||||
VehicleType two = VehicleTypeImpl.Builder.newInstance("type").setUserData(42).build();
|
||||
VehicleType three = VehicleTypeImpl.Builder.newInstance("type").build();
|
||||
|
||||
|
|
|
|||
|
|
@ -66,7 +66,7 @@ public class FastVehicleRoutingTransportCostsMatrixTest {
|
|||
@Test
|
||||
public void whenAddingTimeAndDistanceToSymmetricMatrix_itShouldReturnCorrectValues2() {
|
||||
FastVehicleRoutingTransportCostsMatrix.Builder matrixBuilder = FastVehicleRoutingTransportCostsMatrix.Builder.newInstance(3, true);
|
||||
matrixBuilder.addTransportTimeAndDistance(1, 2, 2.,100.);
|
||||
matrixBuilder.addTransportTimeAndDistance(1, 2, 2., 100.);
|
||||
FastVehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
|
||||
assertEquals(2., matrix.getTransportTime(loc(1), loc(2), 0.0, null, null), 0.1);
|
||||
assertEquals(2., matrix.getTransportTime(loc(2), loc(1), 0.0, null, null), 0.1);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue