Skip to content

Commit

Permalink
transport cost test and examples
Browse files Browse the repository at this point in the history
  • Loading branch information
braktar committed Aug 16, 2016
1 parent c757911 commit cec6e02
Show file tree
Hide file tree
Showing 21 changed files with 279 additions and 277 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ public void whenCalcTimeWithSolutionAnalyser_itShouldWork() {
SolutionAnalyser sa = new SolutionAnalyser(vrp, Solutions.bestOf(solutions), new TransportDistance() {
@Override
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null);
return vrp.getTransportCosts().getTransportCost(from, to, 0., 0., null, null);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
import com.graphhopper.jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import com.graphhopper.jsprit.core.problem.vehicle.VehicleImpl;
import com.graphhopper.jsprit.core.util.Solutions;

import junit.framework.Assert;

import org.junit.Test;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public double getCosts(VehicleRoutingProblemSolution solution) {
SolutionAnalyser sa = new SolutionAnalyser(vrp, solution, new TransportDistance() {
@Override
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
return vrp.getTransportCosts().getTransportCost(from, to, 0., null, null);
return vrp.getTransportCosts().getTransportCost(from, to, 0., 0., null, null);
}
});
return sa.getWaitingTime() + sa.getDistance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ private double getMarginalCost(Service service, TourActivity prevAct, TourActivi
}

private double getCost(Location loc1, Location loc2) {
return vrp.getTransportCosts().getTransportCost(loc1, loc2, 0., null, null);
return vrp.getTransportCosts().getTransportCost(loc1, loc2, 0., 0., null, null);
}
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,12 @@ public void doBefore() {
routingCosts = mock(VehicleRoutingTransportCosts.class);
actCosts = mock(VehicleRoutingActivityCosts.class);

when(routingCosts.getTransportCost(loc("i"), loc("j"), 0.0, null, vehicle)).thenReturn(2.0);
when(routingCosts.getTransportTime(loc("i"), loc("j"), 0.0, null, vehicle)).thenReturn(0.0);
when(routingCosts.getTransportCost(loc("i"), loc("k"), 0.0, null, vehicle)).thenReturn(3.0);
when(routingCosts.getTransportTime(loc("i"), loc("k"), 0.0, null, vehicle)).thenReturn(0.0);
when(routingCosts.getTransportCost(loc("k"), loc("j"), 0.0, null, vehicle)).thenReturn(3.0);
when(routingCosts.getTransportTime(loc("k"), loc("j"), 0.0, null, vehicle)).thenReturn(0.0);
when(routingCosts.getTransportCost(loc("i"), loc("j"), 0.0, 0., null, vehicle)).thenReturn(2.0);
when(routingCosts.getTransportTime(loc("i"), loc("j"), 0.0, 0., null, vehicle)).thenReturn(0.0);
when(routingCosts.getTransportCost(loc("i"), loc("k"), 0.0, 0., null, vehicle)).thenReturn(3.0);
when(routingCosts.getTransportTime(loc("i"), loc("k"), 0.0, 0., null, vehicle)).thenReturn(0.0);
when(routingCosts.getTransportCost(loc("k"), loc("j"), 0.0, 0., null, vehicle)).thenReturn(3.0);
when(routingCosts.getTransportTime(loc("k"), loc("j"), 0.0, 0., null, vehicle)).thenReturn(0.0);
}

private Location loc(String i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,12 @@ public Coordinate getCoord(String id) {
costs = new AbstractForwardVehicleRoutingTransportCosts() {

@Override
public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
public double getTransportTime(Location from, Location to, double departureTime, double setupDuration, Driver driver, Vehicle vehicle) {
return ManhattanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId()));
}

@Override
public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
public double getTransportCost(Location from, Location to, double departureTime, double setupDuration, Driver driver, Vehicle vehicle) {
return vehicle.getType().getVehicleCostParams().perDistanceUnit * ManhattanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId()));
}
};
Expand Down Expand Up @@ -232,12 +232,12 @@ public void whenInsertingJobAndCurrRouteAndNewVehicleHaveDifferentLocations_acce
AbstractForwardVehicleRoutingTransportCosts routingCosts = new AbstractForwardVehicleRoutingTransportCosts() {

@Override
public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
return getTransportCost(from, to, departureTime, driver, vehicle);
public double getTransportTime(Location from, Location to, double departureTime, double setupDuration, Driver driver, Vehicle vehicle) {
return getTransportCost(from, to, departureTime, setupDuration, driver, vehicle);
}

@Override
public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
public double getTransportCost(Location from, Location to, double departureTime, double setupDuration, Driver driver, Vehicle vehicle) {
return EuclideanDistanceCalculator.calculateDistance(coords.get(from.getId()), coords.get(to.getId()));
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ public void setup() {
VehicleRoutingTransportCosts routingCosts = CostFactory.createManhattanCosts();

@Override
public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
public double getTransportTime(Location from, Location to, double departureTime, double setupDuration, Driver driver, Vehicle vehicle) {
return 0;
}

@Override
public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
double tpCosts = routingCosts.getTransportCost(from, to, departureTime, driver, vehicle);
public double getTransportCost(Location from, Location to, double departureTime, double setupDuration, Driver driver, Vehicle vehicle) {
double tpCosts = routingCosts.getTransportCost(from, to, departureTime, setupDuration, driver, vehicle);
if (vehicle.getId().equals("v1")) return tpCosts;
return 2. * tpCosts;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ public void doBefore() {
when(vehicle.getType()).thenReturn(VehicleTypeImpl.Builder.newInstance("type").build());

tpCosts = mock(VehicleRoutingTransportCosts.class);
when(tpCosts.getTransportCost(loc("i"), loc("j"), 0.0, null, vehicle)).thenReturn(2.0);
when(tpCosts.getTransportTime(loc("i"), loc("j"), 0.0, null, vehicle)).thenReturn(0.0);
when(tpCosts.getTransportCost(loc("i"), loc("k"), 0.0, null, vehicle)).thenReturn(3.0);
when(tpCosts.getTransportTime(loc("i"), loc("k"), 0.0, null, vehicle)).thenReturn(0.0);
when(tpCosts.getTransportCost(loc("k"), loc("j"), 0.0, null, vehicle)).thenReturn(3.0);
when(tpCosts.getTransportTime(loc("k"), loc("j"), 0.0, null, vehicle)).thenReturn(0.0);
when(tpCosts.getTransportCost(loc("i"), loc("j"), 0.0, 0., null, vehicle)).thenReturn(2.0);
when(tpCosts.getTransportTime(loc("i"), loc("j"), 0.0, 0., null, vehicle)).thenReturn(0.0);
when(tpCosts.getTransportCost(loc("i"), loc("k"), 0.0, 0., null, vehicle)).thenReturn(3.0);
when(tpCosts.getTransportTime(loc("i"), loc("k"), 0.0, 0., null, vehicle)).thenReturn(0.0);
when(tpCosts.getTransportCost(loc("k"), loc("j"), 0.0, 0., null, vehicle)).thenReturn(3.0);
when(tpCosts.getTransportTime(loc("k"), loc("j"), 0.0, 0., null, vehicle)).thenReturn(0.0);

actCosts = new WaitingTimeCosts();
calc = new LocalActivityInsertionCostsCalculator(tpCosts, actCosts, mock(StateManager.class));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,28 +31,28 @@ public static void main(String[] args) {
VehicleRoutingTransportCosts costs = new VehicleRoutingTransportCosts() {

@Override
public double getBackwardTransportTime(Location from, Location to, double arrivalTime, Driver driver, Vehicle vehicle) {
public double getBackwardTransportTime(Location from, Location to, double arrivalTime, double setupDuration, Driver driver, Vehicle vehicle) {

return 0;
}

@Override
public double getBackwardTransportCost(Location from, Location to,
double arrivalTime, Driver driver, Vehicle vehicle) {
double arrivalTime, double setupDuration, Driver driver, Vehicle vehicle) {
return 0;
}

@Override
public double getTransportCost(Location from, Location to,
double departureTime, Driver driver, Vehicle vehicle) {
double departureTime, double setupDuration, Driver driver, Vehicle vehicle) {
@SuppressWarnings("unused")
String vehicleId = vehicle.getId();
return 0;
}

@Override
public double getTransportTime(Location from, Location to,
double departureTime, Driver driver, Vehicle vehicle) {
double departureTime, double setupDuration, Driver driver, Vehicle vehicle) {
return 0;
}
};
Expand All @@ -66,28 +66,28 @@ public void whenVehicleAndDriverIsNull_And_CostsDoesNotProvideAMethodForThis_thr
VehicleRoutingTransportCosts costs = new VehicleRoutingTransportCosts() {

@Override
public double getBackwardTransportTime(Location from, Location to, double arrivalTime, Driver driver, Vehicle vehicle) {
public double getBackwardTransportTime(Location from, Location to, double arrivalTime, double setupDuration, Driver driver, Vehicle vehicle) {

return 0;
}

@Override
public double getBackwardTransportCost(Location from, Location to,
double arrivalTime, Driver driver, Vehicle vehicle) {
double arrivalTime, double setupDuration, Driver driver, Vehicle vehicle) {
return 0;
}

@Override
public double getTransportCost(Location from, Location to,
double departureTime, Driver driver, Vehicle vehicle) {
double departureTime, double setupDuration, Driver driver, Vehicle vehicle) {
@SuppressWarnings("unused")
String vehicleId = vehicle.getId();
return 0;
}

@Override
public double getTransportTime(Location from, Location to,
double departureTime, Driver driver, Vehicle vehicle) {
double departureTime, double setupDuration, Driver driver, Vehicle vehicle) {
return 0;
}
};
Expand Down
Loading

0 comments on commit cec6e02

Please sign in to comment.