mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
issue #144 - change VehicleRoutingTransportCosts from String to Location
This commit is contained in:
parent
7e39d08e3d
commit
7ea5c5d650
51 changed files with 904 additions and 800 deletions
|
|
@ -18,6 +18,7 @@ package jsprit.core.algorithm;
|
|||
|
||||
import jsprit.core.algorithm.box.SchrimpfFactory;
|
||||
import jsprit.core.algorithm.termination.IterationWithoutImprovementTermination;
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.VehicleRoutingProblem.FleetSize;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
|
|
@ -116,25 +117,25 @@ public class RefuseCollection_IT {
|
|||
}
|
||||
|
||||
@Override
|
||||
public double getTransportTime(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return getTransportCost(fromId, toId, departureTime, driver, vehicle);
|
||||
public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return getTransportCost(from, to, departureTime, driver, vehicle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBackwardTransportTime(String fromId, String toId, double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
return getTransportCost(fromId, toId, arrivalTime, driver, vehicle);
|
||||
public double getBackwardTransportTime(Location from, Location to, double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
return getTransportCost(from, to, arrivalTime, driver, vehicle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTransportCost(String fromId, String toId,double departureTime, Driver driver, Vehicle vehicle) {
|
||||
if(fromId.equals(toId)) return 0.0;
|
||||
RelationKey key = RelationKey.newKey(fromId, toId);
|
||||
public double getTransportCost(Location from, Location to,double departureTime, Driver driver, Vehicle vehicle) {
|
||||
if(from.equals(to)) return 0.0;
|
||||
RelationKey key = RelationKey.newKey(from.getId(), to.getId());
|
||||
return distances.get(key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBackwardTransportCost(String fromId, String toId,double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
return getTransportCost(fromId, toId, arrivalTime, driver, vehicle);
|
||||
public double getBackwardTransportCost(Location from, Location to,double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
return getTransportCost(from, to, arrivalTime, driver, vehicle);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,27 +1,24 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
* Copyright (C) 2014 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import jsprit.core.algorithm.VehicleRoutingAlgorithm;
|
||||
import jsprit.core.algorithm.io.VehicleRoutingAlgorithms;
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.VehicleRoutingProblem.FleetSize;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
|
|
@ -36,6 +33,10 @@ import jsprit.core.util.Coordinate;
|
|||
import jsprit.core.util.CrowFlyCosts;
|
||||
import jsprit.core.util.Solutions;
|
||||
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
|
||||
public class CalcWithTimeSchedulingTest {
|
||||
|
||||
|
|
@ -65,26 +66,26 @@ public class CalcWithTimeSchedulingTest {
|
|||
return new VehicleRoutingTransportCosts() {
|
||||
|
||||
@Override
|
||||
public double getBackwardTransportCost(String fromId, String toId,double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
return getTransportCost(fromId, toId, arrivalTime, driver, vehicle);
|
||||
public double getBackwardTransportCost(Location from, Location to,double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
return getTransportCost(from, to, arrivalTime, driver, vehicle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTransportCost(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
if(departureTime < 50){
|
||||
return baseCosts.getTransportCost(fromId, toId, departureTime, driver, vehicle)*2.0;
|
||||
return baseCosts.getTransportCost(from, to, departureTime, driver, vehicle)*2.0;
|
||||
}
|
||||
return baseCosts.getTransportCost(fromId, toId, departureTime, driver, vehicle);
|
||||
return baseCosts.getTransportCost(from, to, departureTime, driver, vehicle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBackwardTransportTime(String fromId, String toId,double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
return getTransportTime(fromId, toId, arrivalTime, driver, vehicle);
|
||||
public double getBackwardTransportTime(Location from, Location to,double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
return getTransportTime(from, to, arrivalTime, driver, vehicle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTransportTime(String fromId, String toId,double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return getTransportCost(fromId, toId, departureTime, driver, vehicle);
|
||||
public double getTransportTime(Location from, Location to,double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return getTransportCost(from, to, departureTime, driver, vehicle);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import jsprit.core.algorithm.recreate.listener.BeforeJobInsertionListener;
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Job;
|
||||
|
|
@ -169,7 +170,7 @@ public class RegretInsertionTest {
|
|||
Vehicle vehicle = vrp.getVehicles().iterator().next();
|
||||
InsertionData iData = null;
|
||||
if(currentRoute.isEmpty()){
|
||||
double mc = getCost(service.getLocationId(), vehicle.getStartLocationId());
|
||||
double mc = getCost(service.getLocation(), vehicle.getStartLocation());
|
||||
iData = new InsertionData(2*mc,-1,0,vehicle,newDriver);
|
||||
}
|
||||
else {
|
||||
|
|
@ -197,13 +198,13 @@ public class RegretInsertionTest {
|
|||
}
|
||||
|
||||
private double getMarginalCost(Service service, TourActivity prevAct, TourActivity act) {
|
||||
double prev_new = getCost(prevAct.getLocationId(),service.getLocationId());
|
||||
double new_act = getCost(service.getLocationId(),act.getLocationId());
|
||||
double prev_act = getCost(prevAct.getLocationId(),act.getLocationId());
|
||||
double prev_new = getCost(prevAct.getLocation(),service.getLocation());
|
||||
double new_act = getCost(service.getLocation(),act.getLocation());
|
||||
double prev_act = getCost(prevAct.getLocation(),act.getLocation());
|
||||
return prev_new + new_act - prev_act;
|
||||
}
|
||||
|
||||
private double getCost(String loc1, String loc2) {
|
||||
private double getCost(Location loc1, Location loc2) {
|
||||
return vrp.getTransportCosts().getTransportCost(loc1,loc2,0.,null,null);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
******************************************************************************/
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.cost.VehicleRoutingActivityCosts;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.solution.route.activity.End;
|
||||
|
|
@ -45,22 +46,26 @@ public class TestAuxilliaryCostCalculator {
|
|||
routingCosts = mock(VehicleRoutingTransportCosts.class);
|
||||
actCosts = mock(VehicleRoutingActivityCosts.class);
|
||||
|
||||
when(routingCosts.getTransportCost("i", "j", 0.0, null, vehicle)).thenReturn(2.0);
|
||||
when(routingCosts.getTransportTime("i", "j", 0.0, null, vehicle)).thenReturn(0.0);
|
||||
when(routingCosts.getTransportCost("i", "k", 0.0, null, vehicle)).thenReturn(3.0);
|
||||
when(routingCosts.getTransportTime("i", "k", 0.0, null, vehicle)).thenReturn(0.0);
|
||||
when(routingCosts.getTransportCost("k", "j", 0.0, null, vehicle)).thenReturn(3.0);
|
||||
when(routingCosts.getTransportTime("k", "j", 0.0, null, vehicle)).thenReturn(0.0);
|
||||
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);
|
||||
}
|
||||
|
||||
private Location loc(String i) {
|
||||
return Location.Builder.newInstance().setId(i).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenRouteIsClosed_itCalculatesCostUpToEnd_v1(){
|
||||
TourActivity prevAct = mock(TourActivity.class);
|
||||
when(prevAct.getLocationId()).thenReturn("i");
|
||||
when(prevAct.getLocation()).thenReturn(loc("i"));
|
||||
TourActivity nextAct = mock(TourActivity.class);
|
||||
when(nextAct.getLocationId()).thenReturn("j");
|
||||
when(nextAct.getLocation()).thenReturn(loc("j"));
|
||||
TourActivity newAct = mock(TourActivity.class);
|
||||
when(newAct.getLocationId()).thenReturn("k");
|
||||
when(newAct.getLocation()).thenReturn(loc("k"));
|
||||
|
||||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
|
||||
|
|
@ -72,10 +77,10 @@ public class TestAuxilliaryCostCalculator {
|
|||
@Test
|
||||
public void whenRouteIsClosed_itCalculatesCostUpToEnd_v2(){
|
||||
TourActivity prevAct = mock(TourActivity.class);
|
||||
when(prevAct.getLocationId()).thenReturn("i");
|
||||
when(prevAct.getLocation()).thenReturn(loc("i"));
|
||||
End nextAct = new End("j", 0.0, 0.0);
|
||||
TourActivity newAct = mock(TourActivity.class);
|
||||
when(newAct.getLocationId()).thenReturn("k");
|
||||
when(newAct.getLocation()).thenReturn(loc("k"));
|
||||
|
||||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
|
||||
|
|
@ -87,11 +92,11 @@ public class TestAuxilliaryCostCalculator {
|
|||
@Test
|
||||
public void whenRouteIsOpen_itCalculatesCostUpToEnd_v1(){
|
||||
TourActivity prevAct = mock(TourActivity.class);
|
||||
when(prevAct.getLocationId()).thenReturn("i");
|
||||
when(prevAct.getLocation()).thenReturn(loc("i"));
|
||||
TourActivity nextAct = mock(TourActivity.class);
|
||||
when(nextAct.getLocationId()).thenReturn("j");
|
||||
when(nextAct.getLocation()).thenReturn(loc("j"));
|
||||
TourActivity newAct = mock(TourActivity.class);
|
||||
when(newAct.getLocationId()).thenReturn("k");
|
||||
when(newAct.getLocation()).thenReturn(loc("k"));
|
||||
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
|
||||
|
|
@ -103,10 +108,10 @@ public class TestAuxilliaryCostCalculator {
|
|||
@Test
|
||||
public void whenRouteIsOpen_itCalculatesCostUpToEnd_v2(){
|
||||
TourActivity prevAct = mock(TourActivity.class);
|
||||
when(prevAct.getLocationId()).thenReturn("i");
|
||||
when(prevAct.getLocation()).thenReturn(loc("i"));
|
||||
End nextAct = End.newInstance("j", 0.0, 0.0);
|
||||
TourActivity newAct = mock(TourActivity.class);
|
||||
when(newAct.getLocationId()).thenReturn("k");
|
||||
when(newAct.getLocation()).thenReturn(loc("k"));
|
||||
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
* Copyright (C) 2014 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
|
|
@ -19,6 +19,7 @@ package jsprit.core.algorithm.recreate;
|
|||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.problem.AbstractActivity;
|
||||
import jsprit.core.problem.JobActivityFactory;
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.constraint.ConstraintManager;
|
||||
import jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts;
|
||||
|
|
@ -98,13 +99,13 @@ public class TestCalculatesServiceInsertion {
|
|||
costs = new AbstractForwardVehicleRoutingTransportCosts() {
|
||||
|
||||
@Override
|
||||
public double getTransportTime(String fromId, String toId,double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return ManhattanDistanceCalculator.calculateDistance(locations.getCoord(fromId), locations.getCoord(toId));
|
||||
public double getTransportTime(Location from, Location to,double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return ManhattanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTransportCost(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return vehicle.getType().getVehicleCostParams().perDistanceUnit*ManhattanDistanceCalculator.calculateDistance(locations.getCoord(fromId), locations.getCoord(toId));
|
||||
public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return vehicle.getType().getVehicleCostParams().perDistanceUnit*ManhattanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId()));
|
||||
}
|
||||
};
|
||||
|
||||
|
|
@ -231,13 +232,13 @@ public class TestCalculatesServiceInsertion {
|
|||
AbstractForwardVehicleRoutingTransportCosts routingCosts = new AbstractForwardVehicleRoutingTransportCosts() {
|
||||
|
||||
@Override
|
||||
public double getTransportTime(String fromId, String toId,double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return getTransportCost(fromId, toId, departureTime, driver, vehicle);
|
||||
public double getTransportTime(Location from, Location to,double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return getTransportCost(from, to, departureTime, driver, vehicle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTransportCost(String fromId, String toId,double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return EuclideanDistanceCalculator.calculateDistance(coords.get(fromId), coords.get(toId));
|
||||
public double getTransportCost(Location from, Location to,double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return EuclideanDistanceCalculator.calculateDistance(coords.get(from.getId()), coords.get(to.getId()));
|
||||
}
|
||||
};
|
||||
Vehicle oldVehicle = VehicleImpl.Builder.newInstance("oldV").setStartLocationId("oldV").build();
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
* Copyright (C) 2014 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
|
|
@ -19,10 +19,7 @@ package jsprit.core.algorithm.recreate;
|
|||
import jsprit.core.algorithm.ExampleActivityCostFunction;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.algorithm.state.UpdateVariableCosts;
|
||||
import jsprit.core.problem.AbstractActivity;
|
||||
import jsprit.core.problem.AbstractVehicle;
|
||||
import jsprit.core.problem.JobActivityFactory;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.*;
|
||||
import jsprit.core.problem.constraint.ConstraintManager;
|
||||
import jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
|
|
@ -90,13 +87,13 @@ public class TestCalculatesServiceInsertionOnRouteLevel {
|
|||
VehicleRoutingTransportCosts routingCosts = CostFactory.createManhattanCosts();
|
||||
|
||||
@Override
|
||||
public double getTransportTime(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTransportCost(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
double tpCosts = routingCosts.getTransportCost(fromId,toId,departureTime,driver,vehicle);
|
||||
public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
double tpCosts = routingCosts.getTransportCost(from, to,departureTime,driver,vehicle);
|
||||
if(vehicle.getId().equals("v1")) return tpCosts;
|
||||
return 2. * tpCosts;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,23 +1,22 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Stefan Schroeder.
|
||||
*
|
||||
* Copyright (C) 2014 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Contributors:
|
||||
* Stefan Schroeder - initial API and implementation
|
||||
******************************************************************************/
|
||||
package jsprit.core.algorithm.recreate;
|
||||
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.cost.VehicleRoutingActivityCosts;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.misc.JobInsertionContext;
|
||||
|
|
@ -59,25 +58,29 @@ public class TestLocalActivityInsertionCostsCalculator {
|
|||
when(jic.getNewVehicle()).thenReturn(vehicle);
|
||||
|
||||
tpCosts = mock(VehicleRoutingTransportCosts.class);
|
||||
when(tpCosts.getTransportCost("i", "j", 0.0, null, vehicle)).thenReturn(2.0);
|
||||
when(tpCosts.getTransportTime("i", "j", 0.0, null, vehicle)).thenReturn(0.0);
|
||||
when(tpCosts.getTransportCost("i", "k", 0.0, null, vehicle)).thenReturn(3.0);
|
||||
when(tpCosts.getTransportTime("i", "k", 0.0, null, vehicle)).thenReturn(0.0);
|
||||
when(tpCosts.getTransportCost("k", "j", 0.0, null, vehicle)).thenReturn(3.0);
|
||||
when(tpCosts.getTransportTime("k", "j", 0.0, null, vehicle)).thenReturn(0.0);
|
||||
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);
|
||||
|
||||
actCosts = mock(VehicleRoutingActivityCosts.class);
|
||||
calc = new LocalActivityInsertionCostsCalculator(tpCosts, actCosts);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
private Location loc(String i) {
|
||||
return Location.Builder.newInstance().setId(i).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenInsertingActBetweenTwoRouteActs_itCalcsMarginalTpCosts(){
|
||||
TourActivity prevAct = mock(TourActivity.class);
|
||||
when(prevAct.getLocationId()).thenReturn("i");
|
||||
when(prevAct.getLocation()).thenReturn(loc("i"));
|
||||
TourActivity nextAct = mock(TourActivity.class);
|
||||
when(nextAct.getLocationId()).thenReturn("j");
|
||||
when(nextAct.getLocation()).thenReturn(loc("j"));
|
||||
TourActivity newAct = mock(TourActivity.class);
|
||||
when(newAct.getLocationId()).thenReturn("k");
|
||||
when(newAct.getLocation()).thenReturn(loc("k"));
|
||||
|
||||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
|
||||
|
|
@ -88,10 +91,10 @@ public class TestLocalActivityInsertionCostsCalculator {
|
|||
@Test
|
||||
public void whenInsertingActBetweenLastActAndEnd_itCalcsMarginalTpCosts(){
|
||||
TourActivity prevAct = mock(TourActivity.class);
|
||||
when(prevAct.getLocationId()).thenReturn("i");
|
||||
when(prevAct.getLocation()).thenReturn(loc("i"));
|
||||
End nextAct = End.newInstance("j", 0.0, 0.0);
|
||||
TourActivity newAct = mock(TourActivity.class);
|
||||
when(newAct.getLocationId()).thenReturn("k");
|
||||
when(newAct.getLocation()).thenReturn(loc("k"));
|
||||
|
||||
when(vehicle.isReturnToDepot()).thenReturn(true);
|
||||
|
||||
|
|
@ -102,11 +105,11 @@ public class TestLocalActivityInsertionCostsCalculator {
|
|||
@Test
|
||||
public void whenInsertingActBetweenTwoRouteActsAndRouteIsOpen_itCalcsMarginalTpCosts(){
|
||||
TourActivity prevAct = mock(TourActivity.class);
|
||||
when(prevAct.getLocationId()).thenReturn("i");
|
||||
when(prevAct.getLocation()).thenReturn(loc("i"));
|
||||
TourActivity nextAct = mock(TourActivity.class);
|
||||
when(nextAct.getLocationId()).thenReturn("j");
|
||||
when(nextAct.getLocation()).thenReturn(loc("j"));
|
||||
TourActivity newAct = mock(TourActivity.class);
|
||||
when(newAct.getLocationId()).thenReturn("k");
|
||||
when(newAct.getLocation()).thenReturn(loc("k"));
|
||||
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
|
||||
|
|
@ -117,10 +120,10 @@ public class TestLocalActivityInsertionCostsCalculator {
|
|||
@Test
|
||||
public void whenInsertingActBetweenLastActAndEndAndRouteIsOpen_itCalculatesTpCostsFromPrevToNewAct(){
|
||||
TourActivity prevAct = mock(TourActivity.class);
|
||||
when(prevAct.getLocationId()).thenReturn("i");
|
||||
when(prevAct.getLocation()).thenReturn(loc("i"));
|
||||
End nextAct = End.newInstance("j", 0.0, 0.0);
|
||||
TourActivity newAct = mock(TourActivity.class);
|
||||
when(newAct.getLocationId()).thenReturn("k");
|
||||
when(newAct.getLocation()).thenReturn(loc("k"));
|
||||
|
||||
when(vehicle.isReturnToDepot()).thenReturn(false);
|
||||
|
||||
|
|
|
|||
|
|
@ -1,27 +1,26 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (C) 2013 Stefan Schroeder
|
||||
*
|
||||
* Copyright (C) 2014 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
******************************************************************************/
|
||||
package jsprit.core.algorithm.ruin.distance;
|
||||
|
||||
import jsprit.core.algorithm.ruin.distance.AvgServiceDistance;
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.job.Service;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
|
|
@ -31,20 +30,20 @@ public class TestJobDistanceAvgCosts {
|
|||
VehicleRoutingTransportCosts costs = new VehicleRoutingTransportCosts() {
|
||||
|
||||
@Override
|
||||
public double getBackwardTransportTime(String fromId, String toId,double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
public double getBackwardTransportTime(Location from, Location to,double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBackwardTransportCost(String fromId, String toId,
|
||||
public double getBackwardTransportCost(Location from, Location to,
|
||||
double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTransportCost(String fromId, String toId,
|
||||
public double getTransportCost(Location from, Location to,
|
||||
double departureTime, Driver driver, Vehicle vehicle) {
|
||||
@SuppressWarnings("unused")
|
||||
String vehicleId = vehicle.getId();
|
||||
|
|
@ -52,7 +51,7 @@ public class TestJobDistanceAvgCosts {
|
|||
}
|
||||
|
||||
@Override
|
||||
public double getTransportTime(String fromId, String toId,
|
||||
public double getTransportTime(Location from, Location to,
|
||||
double departureTime, Driver driver, Vehicle vehicle) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
|
|
@ -68,20 +67,20 @@ public class TestJobDistanceAvgCosts {
|
|||
VehicleRoutingTransportCosts costs = new VehicleRoutingTransportCosts() {
|
||||
|
||||
@Override
|
||||
public double getBackwardTransportTime(String fromId, String toId,double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
public double getBackwardTransportTime(Location from, Location to,double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBackwardTransportCost(String fromId, String toId,
|
||||
public double getBackwardTransportCost(Location from, Location to,
|
||||
double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTransportCost(String fromId, String toId,
|
||||
public double getTransportCost(Location from, Location to,
|
||||
double departureTime, Driver driver, Vehicle vehicle) {
|
||||
@SuppressWarnings("unused")
|
||||
String vehicleId = vehicle.getId();
|
||||
|
|
@ -89,7 +88,7 @@ public class TestJobDistanceAvgCosts {
|
|||
}
|
||||
|
||||
@Override
|
||||
public double getTransportTime(String fromId, String toId,
|
||||
public double getTransportTime(Location from, Location to,
|
||||
double departureTime, Driver driver, Vehicle vehicle) {
|
||||
// TODO Auto-generated method stub
|
||||
return 0;
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
|
|
@ -262,21 +262,25 @@ public class VehicleRoutingProblemTest {
|
|||
builder.setRoutingCost(new AbstractForwardVehicleRoutingTransportCosts() {
|
||||
|
||||
@Override
|
||||
public double getTransportTime(String fromId, String toId,
|
||||
public double getTransportTime(Location from, Location to,
|
||||
double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTransportCost(String fromId, String toId,
|
||||
public double getTransportCost(Location from, Location to,
|
||||
double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return 4.0;
|
||||
}
|
||||
});
|
||||
|
||||
VehicleRoutingProblem problem = builder.build();
|
||||
assertEquals(4.0,problem.getTransportCosts().getTransportCost("", "", 0.0, null, null),0.01);
|
||||
assertEquals(4.0,problem.getTransportCosts().getTransportCost(loc(""), loc(""), 0.0, null, null),0.01);
|
||||
}
|
||||
|
||||
private Location loc(String i) {
|
||||
return Location.Builder.newInstance().setId(i).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void whenAddingAVehicle_getAddedVehicleTypesShouldReturnItsType(){
|
||||
|
|
|
|||
|
|
@ -1,26 +1,25 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Stefan Schroeder.
|
||||
*
|
||||
* Copyright (C) 2014 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Contributors:
|
||||
* Stefan Schroeder - initial API and implementation
|
||||
******************************************************************************/
|
||||
package jsprit.core.problem.constraint;
|
||||
|
||||
import jsprit.core.algorithm.state.InternalStates;
|
||||
import jsprit.core.algorithm.state.StateManager;
|
||||
import jsprit.core.problem.Capacity;
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.VehicleRoutingProblem;
|
||||
import jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
|
|
@ -60,12 +59,12 @@ public class ServiceLoadRouteLevelConstraintTest {
|
|||
VehicleRoutingTransportCosts routingCosts = new AbstractForwardVehicleRoutingTransportCosts() {
|
||||
|
||||
@Override
|
||||
public double getTransportTime(String fromId, String toId,double departureTime, Driver driver, Vehicle vehicle) {
|
||||
public double getTransportTime(Location from, Location to,double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getTransportCost(String fromId, String toId,double departureTime, Driver driver, Vehicle vehicle) {
|
||||
public double getTransportCost(Location from, Location to,double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -152,6 +152,7 @@ public class VrpXMLWriterTest {
|
|||
VehicleRoutingProblem readVrp = vrpToReadBuilder.build();
|
||||
Shipment s1_read = (Shipment) readVrp.getJobs().get("1");
|
||||
assertTrue(s1_read.getName().equals("cleaning"));
|
||||
assertEquals(1,s1_read.getPickupLocation().getIndex());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
|||
|
|
@ -1,31 +1,30 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2014 Stefan Schroeder.
|
||||
*
|
||||
* Copyright (C) 2014 Stefan Schroeder
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
* License as published by the Free Software Foundation; either
|
||||
* License as published by the Free Software Foundation; either
|
||||
* version 3.0 of the License, or (at your option) any later version.
|
||||
*
|
||||
*
|
||||
* This library is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* Lesser General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Lesser General Public
|
||||
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Contributors:
|
||||
* Stefan Schroeder - initial API and implementation
|
||||
******************************************************************************/
|
||||
package jsprit.core.util;
|
||||
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
import jsprit.core.problem.vehicle.VehicleType;
|
||||
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class VehicleRoutingTransportCostsMatrixTest {
|
||||
|
||||
|
|
@ -34,9 +33,9 @@ public class VehicleRoutingTransportCostsMatrixTest {
|
|||
VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true);
|
||||
matrixBuilder.addTransportDistance("1", "2", 2.);
|
||||
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
|
||||
assertEquals(2.,matrix.getTransportCost("1", "2", 0.0, null, null),0.1);
|
||||
assertEquals(2.,matrix.getTransportCost(loc("1"), loc("2"), 0.0, null, null),0.1);
|
||||
assertEquals(2.,matrix.getDistance("1", "2"),0.1);
|
||||
assertEquals(2.,matrix.getTransportCost("2", "1", 0.0, null, null),0.1);
|
||||
assertEquals(2.,matrix.getTransportCost(loc("2"), loc("1"), 0.0, null, null),0.1);
|
||||
assertEquals(2.,matrix.getDistance("2", "1"),0.1);
|
||||
}
|
||||
|
||||
|
|
@ -45,9 +44,9 @@ public class VehicleRoutingTransportCostsMatrixTest {
|
|||
VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true);
|
||||
matrixBuilder.addTransportDistance("from", "to", 2.);
|
||||
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
|
||||
assertEquals(2.,matrix.getTransportCost("from", "to", 0.0, null, null),0.1);
|
||||
assertEquals(2.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, null),0.1);
|
||||
assertEquals(2.,matrix.getDistance("from", "to"),0.1);
|
||||
assertEquals(2.,matrix.getTransportCost("to", "from", 0.0, null, null),0.1);
|
||||
assertEquals(2.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, null),0.1);
|
||||
assertEquals(2.,matrix.getDistance("from", "to"),0.1);
|
||||
}
|
||||
|
||||
|
|
@ -59,9 +58,9 @@ public class VehicleRoutingTransportCostsMatrixTest {
|
|||
matrixBuilder.addTransportDistance("from", "to", 4.);
|
||||
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
|
||||
|
||||
assertEquals(4.,matrix.getTransportCost("from", "to", 0.0, null, null),0.1);
|
||||
assertEquals(4.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, null),0.1);
|
||||
assertEquals(4.,matrix.getDistance("from", "to"),0.1);
|
||||
assertEquals(4.,matrix.getTransportCost("to", "from", 0.0, null, null),0.1);
|
||||
assertEquals(4.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, null),0.1);
|
||||
assertEquals(4.,matrix.getDistance("from", "to"),0.1);
|
||||
}
|
||||
|
||||
|
|
@ -73,9 +72,9 @@ public class VehicleRoutingTransportCostsMatrixTest {
|
|||
matrixBuilder.addTransportDistance("to", "from", 4.);
|
||||
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
|
||||
|
||||
assertEquals(4.,matrix.getTransportCost("from", "to", 0.0, null, null),0.1);
|
||||
assertEquals(4.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, null),0.1);
|
||||
assertEquals(4.,matrix.getDistance("from", "to"),0.1);
|
||||
assertEquals(4.,matrix.getTransportCost("to", "from", 0.0, null, null),0.1);
|
||||
assertEquals(4.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, null),0.1);
|
||||
assertEquals(4.,matrix.getDistance("from", "to"),0.1);
|
||||
}
|
||||
|
||||
|
|
@ -84,15 +83,19 @@ public class VehicleRoutingTransportCostsMatrixTest {
|
|||
VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false);
|
||||
matrixBuilder.addTransportDistance("1", "2", 2.);
|
||||
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
|
||||
assertEquals(2.,matrix.getTransportCost("1", "2", 0.0, null, null),0.1);
|
||||
assertEquals(2.,matrix.getTransportCost(loc("1"), loc("2"), 0.0, null, null),0.1);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalStateException.class)
|
||||
|
||||
private Location loc(String s) {
|
||||
return Location.Builder.newInstance().setId(s).build();
|
||||
}
|
||||
|
||||
@Test(expected=IllegalStateException.class)
|
||||
public void whenRequestingRelationThatDoesNotExist_itShouldThrowException(){
|
||||
VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false);
|
||||
matrixBuilder.addTransportDistance("1", "2", 2.);
|
||||
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
|
||||
matrix.getTransportCost("2", "1", 0.0, null, null);
|
||||
matrix.getTransportCost(loc("2"), loc("1"), 0.0, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -101,8 +104,8 @@ public class VehicleRoutingTransportCostsMatrixTest {
|
|||
matrixBuilder.addTransportDistance("from", "to", 2.);
|
||||
matrixBuilder.addTransportDistance("to", "from", 4.);
|
||||
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
|
||||
assertEquals(2.,matrix.getTransportCost("from", "to", 0.0, null, null),0.1);
|
||||
assertEquals(4.,matrix.getTransportCost("to", "from", 0.0, null, null),0.1);
|
||||
assertEquals(2.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, null),0.1);
|
||||
assertEquals(4.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, null),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -110,8 +113,8 @@ public class VehicleRoutingTransportCostsMatrixTest {
|
|||
VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true);
|
||||
matrixBuilder.addTransportTime("1", "2", 2.);
|
||||
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
|
||||
assertEquals(2.,matrix.getTransportTime("1", "2", 0.0, null, null),0.1);
|
||||
assertEquals(2.,matrix.getTransportTime("2", "1", 0.0, null, null),0.1);
|
||||
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);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -119,8 +122,8 @@ public class VehicleRoutingTransportCostsMatrixTest {
|
|||
VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(true);
|
||||
matrixBuilder.addTransportTime("from", "to", 2.);
|
||||
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
|
||||
assertEquals(2.,matrix.getTransportTime("from", "to", 0.0, null, null),0.1);
|
||||
assertEquals(2.,matrix.getTransportTime("to", "from", 0.0, null, null),0.1);
|
||||
assertEquals(2.,matrix.getTransportTime(loc("from"), loc("to"), 0.0, null, null),0.1);
|
||||
assertEquals(2.,matrix.getTransportTime(loc("to"), loc("from"), 0.0, null, null),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -128,7 +131,7 @@ public class VehicleRoutingTransportCostsMatrixTest {
|
|||
VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false);
|
||||
matrixBuilder.addTransportTime("1", "2", 2.);
|
||||
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
|
||||
assertEquals(2.,matrix.getTransportTime("1", "2", 0.0, null, null),0.1);
|
||||
assertEquals(2.,matrix.getTransportTime(loc("1"), loc("2"), 0.0, null, null),0.1);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalStateException.class)
|
||||
|
|
@ -136,7 +139,7 @@ public class VehicleRoutingTransportCostsMatrixTest {
|
|||
VehicleRoutingTransportCostsMatrix.Builder matrixBuilder = VehicleRoutingTransportCostsMatrix.Builder.newInstance(false);
|
||||
matrixBuilder.addTransportTime("1", "2", 2.);
|
||||
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
|
||||
matrix.getTransportTime("2", "1", 0.0, null, null);
|
||||
matrix.getTransportTime(loc("2"), loc("1"), 0.0, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -145,8 +148,8 @@ public class VehicleRoutingTransportCostsMatrixTest {
|
|||
matrixBuilder.addTransportTime("from", "to", 2.);
|
||||
matrixBuilder.addTransportTime("to", "from", 4.);
|
||||
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
|
||||
assertEquals(2.,matrix.getTransportTime("from", "to", 0.0, null, null),0.1);
|
||||
assertEquals(4.,matrix.getTransportTime("to", "from", 0.0, null, null),0.1);
|
||||
assertEquals(2.,matrix.getTransportTime(loc("from"), loc("to"), 0.0, null, null),0.1);
|
||||
assertEquals(4.,matrix.getTransportTime(loc("to"), loc("from"), 0.0, null, null),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -160,8 +163,8 @@ public class VehicleRoutingTransportCostsMatrixTest {
|
|||
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
|
||||
// assertEquals(2.,matrix.getTransportTime("from", "to", 0.0, null, null),0.1);
|
||||
// assertEquals(4.,matrix.getTransportTime("to", "from", 0.0, null, null),0.1);
|
||||
assertEquals(2.,matrix.getTransportCost("from", "to", 0.0, null, vehicle),0.1);
|
||||
assertEquals(4.,matrix.getTransportCost("to", "from", 0.0, null, vehicle),0.1);
|
||||
assertEquals(2.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, vehicle),0.1);
|
||||
assertEquals(4.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, vehicle),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -173,8 +176,8 @@ public class VehicleRoutingTransportCostsMatrixTest {
|
|||
Vehicle vehicle = mock(Vehicle.class);
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(1.).setCostPerTime(2.).build();
|
||||
when(vehicle.getType()).thenReturn(type);
|
||||
assertEquals(24.,matrix.getTransportCost("1", "2", 0.0, null, vehicle),0.1);
|
||||
assertEquals(24.,matrix.getTransportCost("2", "1", 0.0, null, vehicle),0.1);
|
||||
assertEquals(24.,matrix.getTransportCost(loc("1"), loc("2"), 0.0, null, vehicle),0.1);
|
||||
assertEquals(24.,matrix.getTransportCost(loc("2"), loc("1"), 0.0, null, vehicle),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -185,8 +188,8 @@ public class VehicleRoutingTransportCostsMatrixTest {
|
|||
VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(1.).setCostPerTime(2.).build();
|
||||
when(vehicle.getType()).thenReturn(type);
|
||||
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
|
||||
assertEquals(4.,matrix.getTransportCost("from", "to", 0.0, null, vehicle),0.1);
|
||||
assertEquals(4.,matrix.getTransportCost("to", "from", 0.0, null, vehicle),0.1);
|
||||
assertEquals(4.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, vehicle),0.1);
|
||||
assertEquals(4.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, vehicle),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -198,8 +201,8 @@ public class VehicleRoutingTransportCostsMatrixTest {
|
|||
Vehicle vehicle = mock(Vehicle.class);
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(1.).setCostPerTime(2.).build();
|
||||
when(vehicle.getType()).thenReturn(type);
|
||||
assertEquals(4.,matrix.getTransportCost("1", "2", 0.0, null, vehicle),0.1);
|
||||
assertEquals(16.,matrix.getTransportCost("2", "1", 0.0, null, vehicle),0.1);
|
||||
assertEquals(4.,matrix.getTransportCost(loc("1"), loc("2"), 0.0, null, vehicle),0.1);
|
||||
assertEquals(16.,matrix.getTransportCost(loc("2"), loc("1"), 0.0, null, vehicle),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -213,8 +216,8 @@ public class VehicleRoutingTransportCostsMatrixTest {
|
|||
Vehicle vehicle = mock(Vehicle.class);
|
||||
VehicleType type = VehicleTypeImpl.Builder.newInstance("t").setCostPerDistance(1.).setCostPerTime(2.).build();
|
||||
when(vehicle.getType()).thenReturn(type);
|
||||
assertEquals(5.,matrix.getTransportCost("from", "to", 0.0, null, vehicle),0.1);
|
||||
assertEquals(11.,matrix.getTransportCost("to", "from", 0.0, null, vehicle),0.1);
|
||||
assertEquals(5.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, vehicle),0.1);
|
||||
assertEquals(11.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, vehicle),0.1);
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -231,8 +234,8 @@ public class VehicleRoutingTransportCostsMatrixTest {
|
|||
matrixBuilder.addTransportDistance("to", "from", 5.);
|
||||
VehicleRoutingTransportCostsMatrix matrix = matrixBuilder.build();
|
||||
|
||||
assertEquals(8.,matrix.getTransportCost("from", "to", 0.0, null, vehicle),0.1);
|
||||
assertEquals(14.,matrix.getTransportCost("to", "from", 0.0, null, vehicle),0.1);
|
||||
assertEquals(8.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, vehicle),0.1);
|
||||
assertEquals(14.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, vehicle),0.1);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -251,8 +254,8 @@ public class VehicleRoutingTransportCostsMatrixTest {
|
|||
when(vehicle.getType()).thenReturn(type);
|
||||
assertEquals(1.,matrix.getDistance("from", "to"),0.1);
|
||||
assertEquals(1.,matrix.getDistance("to", "from"),0.1);
|
||||
assertEquals(1.,matrix.getTransportCost("from", "to", 0.0, null, vehicle),0.1);
|
||||
assertEquals(1.,matrix.getTransportCost("to", "from", 0.0, null, vehicle),0.1);
|
||||
assertEquals(1.,matrix.getTransportCost(loc("from"), loc("to"), 0.0, null, vehicle),0.1);
|
||||
assertEquals(1.,matrix.getTransportCost(loc("to"), loc("from"), 0.0, null, vehicle),0.1);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,37 +21,87 @@
|
|||
<problemType>
|
||||
<fleetSize>INFINITE</fleetSize>
|
||||
</problemType>
|
||||
<shipments>
|
||||
<shipment id="1">
|
||||
<pickup>
|
||||
<location>
|
||||
<id>pick</id>
|
||||
<index>1</index>
|
||||
</location>
|
||||
<duration>0.0</duration>
|
||||
<timeWindows>
|
||||
<timeWindow>
|
||||
<start>0.0</start>
|
||||
<end>1.7976931348623157E308</end>
|
||||
</timeWindow>
|
||||
</timeWindows>
|
||||
</pickup>
|
||||
<delivery>
|
||||
<location>
|
||||
<id>del</id>
|
||||
</location>
|
||||
<duration>0.0</duration>
|
||||
<timeWindows>
|
||||
<timeWindow>
|
||||
<start>0.0</start>
|
||||
<end>1.7976931348623157E308</end>
|
||||
</timeWindow>
|
||||
</timeWindows>
|
||||
</delivery>
|
||||
<vehicles>
|
||||
<vehicle>
|
||||
<id>v1</id>
|
||||
<typeId>vehType</typeId>
|
||||
<startLocation>
|
||||
<id>loc</id>
|
||||
</startLocation>
|
||||
<endLocation>
|
||||
<id>loc</id>
|
||||
</endLocation>
|
||||
<timeSchedule>
|
||||
<start>0.0</start>
|
||||
<end>1.7976931348623157E308</end>
|
||||
</timeSchedule>
|
||||
<returnToDepot>true</returnToDepot>
|
||||
</vehicle>
|
||||
</vehicles>
|
||||
<vehicleTypes>
|
||||
<type>
|
||||
<id>vehType</id>
|
||||
<capacity-dimensions>
|
||||
<dimension index="0">0</dimension>
|
||||
<dimension index="0">20</dimension>
|
||||
</capacity-dimensions>
|
||||
<name>cleaning</name>
|
||||
</shipment>
|
||||
</shipments>
|
||||
<costs>
|
||||
<fixed>0.0</fixed>
|
||||
<distance>1.0</distance>
|
||||
<time>0.0</time>
|
||||
</costs>
|
||||
</type>
|
||||
</vehicleTypes>
|
||||
<services>
|
||||
<service id="2" type="service">
|
||||
<location>
|
||||
<id>loc2</id>
|
||||
</location>
|
||||
<capacity-dimensions>
|
||||
<dimension index="0">1</dimension>
|
||||
</capacity-dimensions>
|
||||
<duration>4.0</duration>
|
||||
<timeWindows>
|
||||
<timeWindow>
|
||||
<start>0.0</start>
|
||||
<end>1.7976931348623157E308</end>
|
||||
</timeWindow>
|
||||
</timeWindows>
|
||||
</service>
|
||||
<service id="1" type="service">
|
||||
<location>
|
||||
<id>loc</id>
|
||||
</location>
|
||||
<capacity-dimensions>
|
||||
<dimension index="0">1</dimension>
|
||||
</capacity-dimensions>
|
||||
<duration>2.0</duration>
|
||||
<timeWindows>
|
||||
<timeWindow>
|
||||
<start>0.0</start>
|
||||
<end>1.7976931348623157E308</end>
|
||||
</timeWindow>
|
||||
</timeWindows>
|
||||
</service>
|
||||
</services>
|
||||
<solutions>
|
||||
<solution>
|
||||
<cost>10.0</cost>
|
||||
<routes>
|
||||
<route>
|
||||
<driverId>noDriver</driverId>
|
||||
<vehicleId>v1</vehicleId>
|
||||
<start>0.0</start>
|
||||
<act type="service">
|
||||
<serviceId>1</serviceId>
|
||||
<arrTime>0.0</arrTime>
|
||||
<endTime>0.0</endTime>
|
||||
</act>
|
||||
<end>0.0</end>
|
||||
</route>
|
||||
</routes>
|
||||
<unassignedJobs>
|
||||
<job id="2"/>
|
||||
</unassignedJobs>
|
||||
</solution>
|
||||
</solutions>
|
||||
</problem>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue