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
|
|
@ -16,6 +16,7 @@
|
|||
******************************************************************************/
|
||||
package jsprit.instance.reader;
|
||||
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.problem.cost.VehicleRoutingTransportCosts;
|
||||
import jsprit.core.problem.driver.Driver;
|
||||
import jsprit.core.problem.vehicle.Vehicle;
|
||||
|
|
@ -114,25 +115,25 @@ public class Figliozzi {
|
|||
}
|
||||
|
||||
@Override
|
||||
public double getTransportCost(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return transportDistanceParameter * EuclideanDistanceCalculator.calculateDistance(locations.getCoord(fromId),locations.getCoord(toId)) +
|
||||
transportTimeParameter * getTransportTime(fromId,toId,departureTime, driver, vehicle);
|
||||
public double getTransportCost(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
return transportDistanceParameter * EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()),locations.getCoord(to.getId())) +
|
||||
transportTimeParameter * getTransportTime(from, to,departureTime, driver, vehicle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBackwardTransportCost(String fromId, String toId,double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
return transportDistanceParameter * EuclideanDistanceCalculator.calculateDistance(locations.getCoord(fromId),locations.getCoord(toId)) +
|
||||
transportTimeParameter * getBackwardTransportTime(fromId, toId, arrivalTime, driver, vehicle);
|
||||
public double getBackwardTransportCost(Location from, Location to,double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
return transportDistanceParameter * EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()),locations.getCoord(to.getId())) +
|
||||
transportTimeParameter * getBackwardTransportTime(from, to, arrivalTime, driver, vehicle);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public double getTransportTime(String fromId, String toId, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
if(fromId.equals(toId)){
|
||||
public double getTransportTime(Location from, Location to, double departureTime, Driver driver, Vehicle vehicle) {
|
||||
if(from.equals(to)){
|
||||
return 0.0;
|
||||
}
|
||||
double totalTravelTime = 0.0;
|
||||
double distanceToTravel = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(fromId), locations.getCoord(toId));
|
||||
double distanceToTravel = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId()));
|
||||
double currentTime = departureTime;
|
||||
for(int i=0;i<timeBins.size();i++){
|
||||
double timeThreshold = timeBins.get(i);
|
||||
|
|
@ -154,12 +155,12 @@ public class Figliozzi {
|
|||
|
||||
|
||||
@Override
|
||||
public double getBackwardTransportTime(String fromId, String toId,double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
if(fromId.equals(toId)){
|
||||
public double getBackwardTransportTime(Location from, Location to,double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||
if(from.equals(to)){
|
||||
return 0.0;
|
||||
}
|
||||
double totalTravelTime = 0.0;
|
||||
double distanceToTravel = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(fromId), locations.getCoord(toId));
|
||||
double distanceToTravel = EuclideanDistanceCalculator.calculateDistance(locations.getCoord(from.getId()), locations.getCoord(to.getId()));
|
||||
double currentTime = arrivalTime;
|
||||
for(int i=timeBins.size()-1;i>=0;i--){
|
||||
double nextLowerTimeThreshold;
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@
|
|||
package jsprit.instance.reader;
|
||||
|
||||
|
||||
import jsprit.core.problem.Location;
|
||||
import jsprit.core.util.Coordinate;
|
||||
import jsprit.core.util.Locations;
|
||||
import junit.framework.Assert;
|
||||
|
|
@ -175,7 +176,11 @@ public class FigliozziTest {
|
|||
@Test
|
||||
public void whenConstantTimeDistribution_forwardTimeShouldBeCalculate100(){
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.CLASSIC,100);
|
||||
Assert.assertEquals(100., tdCosts.getTransportTime("from", "to", 0., null, null), 0.01);
|
||||
Assert.assertEquals(100., tdCosts.getTransportTime(loc("from"), loc("to"), 0., null, null), 0.01);
|
||||
}
|
||||
|
||||
private Location loc(String from) {
|
||||
return Location.Builder.newInstance().setId(from).build();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -191,7 +196,7 @@ public class FigliozziTest {
|
|||
20
|
||||
|
||||
*/
|
||||
Assert.assertEquals(76.875,tdCosts.getTransportTime("from","to",0.,null,null),0.01);
|
||||
Assert.assertEquals(76.875,tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -208,7 +213,7 @@ public class FigliozziTest {
|
|||
20
|
||||
|
||||
*/
|
||||
Assert.assertEquals(65.,tdCosts.getTransportTime("from","to",0.,null,null),0.01);
|
||||
Assert.assertEquals(65.,tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -221,7 +226,7 @@ public class FigliozziTest {
|
|||
(20,40) 2.5 = 20 --> 50 dist, 20 time : 70 dist, 40 time
|
||||
(40,60) 1.75 = 30 dist, 17.1428571429 time : 100 dist, 57.1428571429 time
|
||||
*/
|
||||
Assert.assertEquals(57.1428571429,tdCosts.getTransportTime("from","to",0.,null,null),0.01);
|
||||
Assert.assertEquals(57.1428571429,tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -238,7 +243,7 @@ public class FigliozziTest {
|
|||
20
|
||||
|
||||
*/
|
||||
Assert.assertEquals(65.,tdCosts.getBackwardTransportTime("from", "to", 100., null, null),0.01);
|
||||
Assert.assertEquals(65.,tdCosts.getBackwardTransportTime(loc("from"),loc("to"), 100., null, null),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -254,13 +259,13 @@ public class FigliozziTest {
|
|||
20
|
||||
|
||||
*/
|
||||
Assert.assertEquals(76.875,tdCosts.getBackwardTransportTime("from", "to", 100., null, null),0.01);
|
||||
Assert.assertEquals(76.875,tdCosts.getBackwardTransportTime(loc("from"),loc("to"), 100., null, null),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void backwardTimeShouldBeCalculatedCorrectly(){
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.CLASSIC,100);
|
||||
Assert.assertEquals(100.,tdCosts.getBackwardTransportTime("from","to",100.,null,null),0.01);
|
||||
Assert.assertEquals(100.,tdCosts.getBackwardTransportTime(loc("from"),loc("to"),100.,null,null),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -276,7 +281,7 @@ public class FigliozziTest {
|
|||
|
||||
};
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1a,100);
|
||||
double time = tdCosts.getTransportTime("from","to",0.,null,null);
|
||||
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
|
||||
Assert.assertEquals(100.,time,0.01);
|
||||
}
|
||||
|
||||
|
|
@ -293,7 +298,7 @@ public class FigliozziTest {
|
|||
|
||||
};
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1b,100);
|
||||
double time = tdCosts.getTransportTime("from","to",0.,null,null);
|
||||
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
|
||||
Assert.assertEquals(100.,time,0.01);
|
||||
}
|
||||
|
||||
|
|
@ -310,7 +315,7 @@ public class FigliozziTest {
|
|||
|
||||
};
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1c,100);
|
||||
double time = tdCosts.getTransportTime("from","to",0.,null,null);
|
||||
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
|
||||
Assert.assertEquals(100.,time,0.01);
|
||||
}
|
||||
|
||||
|
|
@ -327,7 +332,7 @@ public class FigliozziTest {
|
|||
|
||||
};
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD1d,100);
|
||||
double time = tdCosts.getTransportTime("from","to",0.,null,null);
|
||||
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
|
||||
Assert.assertEquals(100.,time,0.01);
|
||||
}
|
||||
|
||||
|
|
@ -344,7 +349,7 @@ public class FigliozziTest {
|
|||
|
||||
};
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2a,100);
|
||||
double time = tdCosts.getTransportTime("from","to",0.,null,null);
|
||||
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
|
||||
Assert.assertEquals(100.,time,0.01);
|
||||
}
|
||||
|
||||
|
|
@ -361,7 +366,7 @@ public class FigliozziTest {
|
|||
|
||||
};
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2b,100);
|
||||
double time = tdCosts.getTransportTime("from","to",0.,null,null);
|
||||
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
|
||||
Assert.assertEquals(100.,time,0.01);
|
||||
}
|
||||
|
||||
|
|
@ -378,7 +383,7 @@ public class FigliozziTest {
|
|||
|
||||
};
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2c,100);
|
||||
double time = tdCosts.getTransportTime("from","to",0.,null,null);
|
||||
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
|
||||
Assert.assertEquals(100.,time,0.01);
|
||||
}
|
||||
|
||||
|
|
@ -395,7 +400,7 @@ public class FigliozziTest {
|
|||
|
||||
};
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD2d,100);
|
||||
double time = tdCosts.getTransportTime("from","to",0.,null,null);
|
||||
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
|
||||
Assert.assertEquals(100.,time,0.01);
|
||||
}
|
||||
|
||||
|
|
@ -412,7 +417,7 @@ public class FigliozziTest {
|
|||
|
||||
};
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3a,100);
|
||||
double time = tdCosts.getTransportTime("from","to",0.,null,null);
|
||||
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
|
||||
Assert.assertEquals(100.,time,0.01);
|
||||
}
|
||||
|
||||
|
|
@ -429,7 +434,7 @@ public class FigliozziTest {
|
|||
|
||||
};
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3b,100);
|
||||
double time = tdCosts.getTransportTime("from","to",0.,null,null);
|
||||
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
|
||||
Assert.assertEquals(100.,time,0.01);
|
||||
}
|
||||
|
||||
|
|
@ -446,7 +451,7 @@ public class FigliozziTest {
|
|||
|
||||
};
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3c,100);
|
||||
double time = tdCosts.getTransportTime("from","to",0.,null,null);
|
||||
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
|
||||
Assert.assertEquals(100.,time,0.01);
|
||||
}
|
||||
|
||||
|
|
@ -463,7 +468,7 @@ public class FigliozziTest {
|
|||
|
||||
};
|
||||
Figliozzi.TDCosts tdCosts = Figliozzi.TimeDependentTransportCostsFactory.createCosts(locations, Figliozzi.TimeDependentTransportCostsFactory.SpeedDistribution.TD3d,100);
|
||||
double time = tdCosts.getTransportTime("from","to",0.,null,null);
|
||||
double time = tdCosts.getTransportTime(loc("from"),loc("to"),0.,null,null);
|
||||
Assert.assertEquals(100.,time,0.01);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue