1
0
Fork 0
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:
oblonski 2017-07-05 10:41:23 +02:00
parent b5998e1d93
commit db0c39e1c2
No known key found for this signature in database
GPG key ID: 179DE487285680D1
22 changed files with 448 additions and 436 deletions

View file

@ -17,14 +17,6 @@
*/
package com.graphhopper.jsprit.core.algorithm;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.graphhopper.jsprit.core.algorithm.SearchStrategy.DiscoveredSolution;
import com.graphhopper.jsprit.core.algorithm.listener.SearchStrategyListener;
import com.graphhopper.jsprit.core.algorithm.listener.SearchStrategyModuleListener;
@ -38,6 +30,13 @@ import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolutio
import com.graphhopper.jsprit.core.problem.solution.route.VehicleRoute;
import com.graphhopper.jsprit.core.problem.solution.route.activity.TourActivity;
import com.graphhopper.jsprit.core.util.Solutions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;
/**

View file

@ -190,6 +190,49 @@ public class UpdateMaxTimeInVehicle implements StateUpdater, ActivityVisitor{
}
}
public void finish(List<TourActivity> activities, Job ignore) {
for (Vehicle v : vehicles) {
int vehicleIndex = v.getVehicleTypeIdentifier().getIndex();
//!!! open routes !!!
double routeEnd;
if (!v.isReturnToDepot()) routeEnd = prevActEndTimes[vehicleIndex];
else
routeEnd = prevActEndTimes[vehicleIndex] + transportTime.getTransportTime(prevActLocations[vehicleIndex], v.getEndLocation(), prevActEndTimes[vehicleIndex], route.getDriver(), v);
Map<String, Double> openDeliveries = new HashMap<>();
for (Job job : openPickupEndTimes.get(vehicleIndex).keySet()) {
if (job == ignore) continue;
double actEndTime = openPickupEndTimes.get(vehicleIndex).get(job);
double slackTime = job.getMaxTimeInVehicle() - (routeEnd - actEndTime);
openDeliveries.put(job.getId(), slackTime);
}
double minSlackTimeAtEnd = minSlackTime(openDeliveries);
stateManager.putRouteState(route, v, latestStartId, routeEnd + minSlackTimeAtEnd);
List<TourActivity> acts = new ArrayList<>(activities);
Collections.reverse(acts);
for (TourActivity act : acts) {
if (act instanceof ServiceActivity || act instanceof PickupActivity) {
String jobId = ((TourActivity.JobActivity) act).getJob().getId();
openDeliveries.remove(jobId);
double minSlackTime = minSlackTime(openDeliveries);
double latestStart = actStart(act, v) + minSlackTime;
stateManager.putActivityState(act, v, latestStartId, latestStart);
} else {
String jobId = ((TourActivity.JobActivity) act).getJob().getId();
if (slackTimes.get(vehicleIndex).containsKey(act)) {
double slackTime = slackTimes.get(vehicleIndex).get(act);
openDeliveries.put(jobId, slackTime);
}
double minSlackTime = minSlackTime(openDeliveries);
double latestStart = actStart(act, v) + minSlackTime;
stateManager.putActivityState(act, v, latestStartId, latestStart);
}
}
}
}
private double actStart(TourActivity act, Vehicle v) {
return actStartTimes.get(v.getVehicleTypeIdentifier().getIndex()).get(act);
}

View file

@ -63,7 +63,7 @@ public class VehicleDependentTraveledDistance implements StateUpdater, ActivityV
private List<Vehicle> uniqueVehicles;
private Map<VehicleTypeKey,State> states;
private Map<VehicleTypeKey, State> states;
public VehicleDependentTraveledDistance(TransportDistance transportCostMatrices, StateManager stateManager, StateId distanceInRouteId, Collection<Vehicle> vehicles) {
this.transportDistance = transportCostMatrices;
@ -75,8 +75,8 @@ public class VehicleDependentTraveledDistance implements StateUpdater, ActivityV
private List<Vehicle> getUniqueVehicles(Collection<Vehicle> vehicles) {
Set<VehicleTypeKey> types = new HashSet<>();
List<Vehicle> uniqueVehicles = new ArrayList<>();
for(Vehicle v : vehicles){
if(!types.contains(v.getVehicleTypeIdentifier())){
for (Vehicle v : vehicles) {
if (!types.contains(v.getVehicleTypeIdentifier())) {
types.add(v.getVehicleTypeIdentifier());
uniqueVehicles.add(v);
}
@ -88,32 +88,32 @@ public class VehicleDependentTraveledDistance implements StateUpdater, ActivityV
public void begin(VehicleRoute route) {
this.route = route;
states = new HashMap<>();
for(Vehicle v : uniqueVehicles){
State state = new State(v.getStartLocation(),0);
states.put(v.getVehicleTypeIdentifier(),state);
for (Vehicle v : uniqueVehicles) {
State state = new State(v.getStartLocation(), 0);
states.put(v.getVehicleTypeIdentifier(), state);
}
}
@Override
public void visit(TourActivity activity) {
for(Vehicle v : uniqueVehicles){
for (Vehicle v : uniqueVehicles) {
State old = states.get(v.getVehicleTypeIdentifier());
double distance = old.getDistance();
distance += transportDistance.getDistance(old.getPrevLocation(),activity.getLocation(),0,v);
stateManager.putActivityState(activity,v,traveledDistanceId,distance);
states.put(v.getVehicleTypeIdentifier(),new State(activity.getLocation(),distance));
distance += transportDistance.getDistance(old.getPrevLocation(), activity.getLocation(), 0, v);
stateManager.putActivityState(activity, v, traveledDistanceId, distance);
states.put(v.getVehicleTypeIdentifier(), new State(activity.getLocation(), distance));
}
}
@Override
public void finish() {
for(Vehicle v : uniqueVehicles){
for (Vehicle v : uniqueVehicles) {
State old = states.get(v.getVehicleTypeIdentifier());
double distance = old.getDistance();
if(v.isReturnToDepot()) {
if (v.isReturnToDepot()) {
distance += transportDistance.getDistance(old.getPrevLocation(), v.getEndLocation(), 0, v);
}
stateManager.putRouteState(route,v,traveledDistanceId, distance);
stateManager.putRouteState(route, v, traveledDistanceId, distance);
}
}

View file

@ -74,14 +74,13 @@ public final class Location implements HasIndex, HasId {
/**
* Sets user specific domain data associated with the object.
*
* <p>
* <p>
* The user data is a black box for the framework, it only stores it,
* but never interacts with it in any way.
* </p>
*
* @param userData
* any object holding the domain specific user data
* @param userData any object holding the domain specific user data
* associated with the object.
* @return builder
*/
@ -130,7 +129,7 @@ public final class Location implements HasIndex, HasId {
* @param name
* @return
*/
public Builder setName(String name){
public Builder setName(String name) {
this.name = name;
return this;
}
@ -191,7 +190,9 @@ public final class Location implements HasIndex, HasId {
return coordinate;
}
public String getName() { return name; }
public String getName() {
return name;
}
@Override
public boolean equals(Object o) {

View file

@ -34,7 +34,7 @@ import java.util.Map;
/**
* Created by schroeder on 11/10/16.
*/
public class MaxDistanceConstraint implements HardActivityConstraint{
public class MaxDistanceConstraint implements HardActivityConstraint {
private StateManager stateManager;
@ -44,7 +44,7 @@ public class MaxDistanceConstraint implements HardActivityConstraint{
private Double[] maxDistances;
public MaxDistanceConstraint(StateManager stateManager, StateId distanceId, TransportDistance distanceCalculator, Map<Vehicle,Double> maxDistancePerVehicleMap) {
public MaxDistanceConstraint(StateManager stateManager, StateId distanceId, TransportDistance distanceCalculator, Map<Vehicle, Double> maxDistancePerVehicleMap) {
this.stateManager = stateManager;
this.distanceId = distanceId;
this.distanceCalculator = distanceCalculator;
@ -53,50 +53,50 @@ public class MaxDistanceConstraint implements HardActivityConstraint{
private void makeArray(Map<Vehicle, Double> maxDistances) {
int maxIndex = getMaxIndex(maxDistances.keySet());
this.maxDistances = new Double[maxIndex+1];
for(Vehicle v : maxDistances.keySet()){
this.maxDistances[v.getIndex()]=maxDistances.get(v);
this.maxDistances = new Double[maxIndex + 1];
for (Vehicle v : maxDistances.keySet()) {
this.maxDistances[v.getIndex()] = maxDistances.get(v);
}
}
private int getMaxIndex(Collection<Vehicle> vehicles) {
int index = 0;
for(Vehicle v : vehicles){
if(v.getIndex() > index) index = v.getIndex();
for (Vehicle v : vehicles) {
if (v.getIndex() > index) index = v.getIndex();
}
return index;
}
@Override
public ConstraintsStatus fulfilled(JobInsertionContext iFacts, TourActivity prevAct, TourActivity newAct, TourActivity nextAct, double prevActDepTime) {
if(!hasMaxDistance(iFacts.getNewVehicle())) return ConstraintsStatus.FULFILLED;
if (!hasMaxDistance(iFacts.getNewVehicle())) return ConstraintsStatus.FULFILLED;
Double currentDistance = 0d;
boolean routeIsEmpty = iFacts.getRoute().isEmpty();
if(!routeIsEmpty){
currentDistance = stateManager.getRouteState(iFacts.getRoute(),iFacts.getNewVehicle(), distanceId,Double.class);
if (!routeIsEmpty) {
currentDistance = stateManager.getRouteState(iFacts.getRoute(), iFacts.getNewVehicle(), distanceId, Double.class);
}
double maxDistance = getMaxDistance(iFacts.getNewVehicle());
if(currentDistance > maxDistance) return ConstraintsStatus.NOT_FULFILLED_BREAK;
if (currentDistance > maxDistance) return ConstraintsStatus.NOT_FULFILLED_BREAK;
double distancePrevAct2NewAct = distanceCalculator.getDistance(prevAct.getLocation(), newAct.getLocation(), iFacts.getNewDepTime(), iFacts.getNewVehicle());
double distanceNewAct2nextAct = distanceCalculator.getDistance(newAct.getLocation(), nextAct.getLocation(), iFacts.getNewDepTime(), iFacts.getNewVehicle());
double distancePrevAct2NextAct = distanceCalculator.getDistance(prevAct.getLocation(), nextAct.getLocation(), prevActDepTime, iFacts.getNewVehicle());
if(prevAct instanceof Start && nextAct instanceof End) distancePrevAct2NextAct = 0;
if(nextAct instanceof End && !iFacts.getNewVehicle().isReturnToDepot()){
if (prevAct instanceof Start && nextAct instanceof End) distancePrevAct2NextAct = 0;
if (nextAct instanceof End && !iFacts.getNewVehicle().isReturnToDepot()) {
distanceNewAct2nextAct = 0;
distancePrevAct2NextAct = 0;
}
double additionalDistance = distancePrevAct2NewAct + distanceNewAct2nextAct - distancePrevAct2NextAct;
if(currentDistance + additionalDistance > maxDistance) return ConstraintsStatus.NOT_FULFILLED;
if (currentDistance + additionalDistance > maxDistance) return ConstraintsStatus.NOT_FULFILLED;
double additionalDistanceOfPickup = 0;
if(newAct instanceof DeliverShipment){
if (newAct instanceof DeliverShipment) {
int iIndexOfPickup = iFacts.getRelatedActivityContext().getInsertionIndex();
TourActivity pickup = iFacts.getAssociatedActivities().get(0);
TourActivity actBeforePickup;
if(iIndexOfPickup > 0) actBeforePickup = iFacts.getRoute().getActivities().get(iIndexOfPickup-1);
else actBeforePickup = new Start(iFacts.getNewVehicle().getStartLocation(),0,Double.MAX_VALUE);
if (iIndexOfPickup > 0) actBeforePickup = iFacts.getRoute().getActivities().get(iIndexOfPickup - 1);
else actBeforePickup = new Start(iFacts.getNewVehicle().getStartLocation(), 0, Double.MAX_VALUE);
TourActivity actAfterPickup;
if (iIndexOfPickup < iFacts.getRoute().getActivities().size())
actAfterPickup = iFacts.getRoute().getActivities().get(iIndexOfPickup);
@ -114,21 +114,21 @@ public class MaxDistanceConstraint implements HardActivityConstraint{
}
if(currentDistance + additionalDistance + additionalDistanceOfPickup > maxDistance){
if (currentDistance + additionalDistance + additionalDistanceOfPickup > maxDistance) {
return ConstraintsStatus.NOT_FULFILLED;
}
return ConstraintsStatus.FULFILLED;
}
private boolean hasMaxDistance(Vehicle newVehicle){
if(newVehicle.getIndex() >= this.maxDistances.length) return false;
private boolean hasMaxDistance(Vehicle newVehicle) {
if (newVehicle.getIndex() >= this.maxDistances.length) return false;
return this.maxDistances[newVehicle.getIndex()] != null;
}
private double getMaxDistance(Vehicle newVehicle) {
Double maxDistance = this.maxDistances[newVehicle.getIndex()];
if(maxDistance == null) return Double.MAX_VALUE;
if (maxDistance == null) return Double.MAX_VALUE;
return maxDistance;
}
}

View file

@ -72,6 +72,7 @@ public interface Vehicle extends HasId, HasIndex {
public abstract VehicleTypeKey getVehicleTypeIdentifier();
public abstract Skills getSkills();
/**
* @return User-specific domain data associated with the vehicle
*/

View file

@ -17,13 +17,12 @@
*/
package com.graphhopper.jsprit.core.problem.vehicle;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.graphhopper.jsprit.core.problem.AbstractVehicle;
import com.graphhopper.jsprit.core.problem.Location;
import com.graphhopper.jsprit.core.problem.Skills;
import com.graphhopper.jsprit.core.problem.job.Break;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
@ -153,14 +152,13 @@ public class VehicleImpl extends AbstractVehicle {
/**
* Sets user specific domain data associated with the object.
*
* <p>
* <p>
* The user data is a black box for the framework, it only stores it,
* but never interacts with it in any way.
* </p>
*
* @param userData
* any object holding the domain specific user data
* @param userData any object holding the domain specific user data
* associated with the object.
* @return builder
*/

View file

@ -97,9 +97,9 @@ public class FastVehicleRoutingTransportCostsMatrix extends AbstractForwardVehic
return this;
}
public Builder addTransportTimeAndDistance(int fromIndex, int toIndex, double time, double distance){
public Builder addTransportTimeAndDistance(int fromIndex, int toIndex, double time, double distance) {
addTransportTime(fromIndex, toIndex, time);
addTransportDistance(fromIndex,toIndex,distance);
addTransportDistance(fromIndex, toIndex, distance);
return this;
}
/**

View file

@ -138,9 +138,10 @@ public class UnassignedJobReasonTracker implements JobUnassignedListener {
public String getHumanReadableReason(String failedConstraintName) {
return getCodesToReason().get(getCode(failedConstraintName));
}
/**
* Returns the most likely reason code i.e. the reason (failed constraint) being observed most often.
*
* <p>
* 1 --> "cannot serve required skill
* 2 --> "cannot be visited within time window"
* 3 --> "does not fit into any vehicle due to capacity"

View file

@ -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.));

View file

@ -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);
}

View file

@ -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),

View file

@ -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 {

View file

@ -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 {

View file

@ -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 {
@ -125,47 +119,47 @@ 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();
assertTrue(s.getRequiredSkills().containsSkill("drill"));
@ -174,7 +168,7 @@ public class ServiceTest {
}
@Test
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly(){
public void whenAddingSkillsCaseSens_theyShouldBeAddedCorrectly() {
Service s = Service.Builder.newInstance("s").setLocation(Location.newInstance("loc"))
.addRequiredSkill("DriLl").addRequiredSkill("screwDriver").build();
assertTrue(s.getRequiredSkills().containsSkill("drill"));
@ -221,23 +215,23 @@ public class ServiceTest {
}
@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());
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(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.))

View file

@ -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 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 {

View file

@ -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 {

View file

@ -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 {

View file

@ -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);