1
0
Fork 0
mirror of https://github.com/graphhopper/jsprit.git synced 2020-01-24 07:45:05 +01:00

Merge remote-tracking branch 'graphhopper/master'

This commit is contained in:
Kandel Irina 2017-11-07 12:33:17 +02:00
commit ea852eb662
5 changed files with 20 additions and 86 deletions

View file

@ -447,7 +447,6 @@ public class VehicleRoutingProblem {
return new VehicleRoutingProblem(this); return new VehicleRoutingProblem(this);
} }
@SuppressWarnings("UnusedDeclaration")
public Builder addLocation(String locationId, Coordinate coordinate) { public Builder addLocation(String locationId, Coordinate coordinate) {
tentative_coordinates.put(locationId, coordinate); tentative_coordinates.put(locationId, coordinate);
return this; return this;
@ -473,7 +472,6 @@ public class VehicleRoutingProblem {
* @param vehicles vehicles to be added * @param vehicles vehicles to be added
* @return this builder * @return this builder
*/ */
@SuppressWarnings("deprecation")
public Builder addAllVehicles(Collection<? extends Vehicle> vehicles) { public Builder addAllVehicles(Collection<? extends Vehicle> vehicles) {
for (Vehicle v : vehicles) { for (Vehicle v : vehicles) {
addVehicle(v); addVehicle(v);

View file

@ -21,80 +21,29 @@
package com.graphhopper.jsprit.core.util; package com.graphhopper.jsprit.core.util;
import com.graphhopper.jsprit.core.problem.Location; import com.graphhopper.jsprit.core.problem.Location;
import com.graphhopper.jsprit.core.problem.cost.AbstractForwardVehicleRoutingTransportCosts;
import com.graphhopper.jsprit.core.problem.driver.Driver;
import com.graphhopper.jsprit.core.problem.vehicle.Vehicle;
/** /**
* @author stefan schroeder * @author stefan schroeder
*/ */
public class CrowFlyCosts extends AbstractForwardVehicleRoutingTransportCosts { public class CrowFlyCosts extends EuclideanCosts {
public int speed = 1;
public double detourFactor = 1.0;
private Locations locations; private Locations locations;
public CrowFlyCosts(Locations locations) { public CrowFlyCosts(Locations locations) {
super();
this.locations = locations; this.locations = locations;
} }
@Override double calculateDistance(Location fromLocation, Location toLocation) {
public String toString() {
return "[name=crowFlyCosts]";
}
@Override
public double getTransportCost(Location from, Location to, double time, Driver driver, Vehicle vehicle) {
double distance;
try {
distance = calculateDistance(from, to);
} catch (NullPointerException e) {
throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator.");
}
double costs = distance;
if (vehicle != null) {
if (vehicle.getType() != null) {
costs = distance * vehicle.getType().getVehicleCostParams().perDistanceUnit;
}
}
return costs;
}
private double calculateDistance(Location fromLocation, Location toLocation) {
Coordinate from = null; Coordinate from = null;
Coordinate to = null; Coordinate to = null;
if (fromLocation.getCoordinate() != null & toLocation.getCoordinate() != null) { if (fromLocation.getCoordinate() != null && toLocation.getCoordinate() != null) {
from = fromLocation.getCoordinate(); from = fromLocation.getCoordinate();
to = toLocation.getCoordinate(); to = toLocation.getCoordinate();
} else if (locations != null) { } else if (locations != null) {
from = locations.getCoord(fromLocation.getId()); from = locations.getCoord(fromLocation.getId());
to = locations.getCoord(toLocation.getId()); to = locations.getCoord(toLocation.getId());
} }
if (from == null || to == null) throw new NullPointerException();
return calculateDistance(from, to);
}
private double calculateDistance(Coordinate from, Coordinate to) {
return EuclideanDistanceCalculator.calculateDistance(from, to) * detourFactor;
}
@Override
public double getTransportTime(Location from, Location to, double time, Driver driver, Vehicle vehicle) {
double distance;
try {
distance = calculateDistance(from, to);
} catch (NullPointerException e) {
throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator.");
}
return distance / speed;
}
@Override
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
return calculateDistance(from, to); return calculateDistance(from, to);
} }
} }

View file

@ -42,42 +42,32 @@ public class EuclideanCosts extends AbstractForwardVehicleRoutingTransportCosts
@Override @Override
public double getTransportCost(Location from, Location to, double time, Driver driver, Vehicle vehicle) { public double getTransportCost(Location from, Location to, double time, Driver driver, Vehicle vehicle) {
double distance; double distance = calculateDistance(from, to);
try { if (vehicle != null && vehicle.getType() != null) {
distance = calculateDistance(from, to); return distance * vehicle.getType().getVehicleCostParams().perDistanceUnit;
} catch (NullPointerException e) {
throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator.");
} }
double costs = distance; return distance;
if (vehicle != null) {
if (vehicle.getType() != null) {
costs = distance * vehicle.getType().getVehicleCostParams().perDistanceUnit;
}
}
return costs;
} }
private double calculateDistance(Location fromLocation, Location toLocation) { double calculateDistance(Location fromLocation, Location toLocation) {
return calculateDistance(fromLocation.getCoordinate(), toLocation.getCoordinate()); return calculateDistance(fromLocation.getCoordinate(), toLocation.getCoordinate());
} }
private double calculateDistance(Coordinate from, Coordinate to) { double calculateDistance(Coordinate from, Coordinate to) {
return EuclideanDistanceCalculator.calculateDistance(from, to) * detourFactor; try {
return EuclideanDistanceCalculator.calculateDistance(from, to) * detourFactor;
} catch (NullPointerException e) {
throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator.");
}
} }
@Override @Override
public double getTransportTime(Location from, Location to, double time, Driver driver, Vehicle vehicle) { public double getTransportTime(Location from, Location to, double time, Driver driver, Vehicle vehicle) {
double distance; return calculateDistance(from, to) / speed;
try {
distance = calculateDistance(from, to);
} catch (NullPointerException e) {
throw new NullPointerException("cannot calculate euclidean distance. coordinates are missing. either add coordinates or use another transport-cost-calculator.");
}
return distance / speed;
} }
@Override @Override
public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) { public double getDistance(Location from, Location to, double departureTime, Vehicle vehicle) {
return calculateDistance(from, to); return calculateDistance(from, to);
} }
} }

View file

@ -103,13 +103,10 @@ public class BelhaizaReader {
System.out.println("fix: " + fixedCostPerVehicle + "; perDistance: 1.0; perWaitingTime: 0.8"); System.out.println("fix: " + fixedCostPerVehicle + "; perDistance: 1.0; perWaitingTime: 0.8");
VehicleTypeImpl vehicleType = typeBuilder.build(); VehicleTypeImpl vehicleType = typeBuilder.build();
double end = Double.parseDouble(tokens[8])*timeProjectionFactor; double end = Double.parseDouble(tokens[8])*timeProjectionFactor;
for(int i=0;i<10;i++) { VehicleImpl vehicle = VehicleImpl.Builder.newInstance("solomonVehicle").setEarliestStart(0.).setLatestArrival(end)
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("solomonVehicle"+(i+1)).setEarliestStart(0.).setLatestArrival(end) .setStartLocation(Location.Builder.newInstance().setId(customerId)
.setStartLocation(Location.Builder.newInstance().setId(customerId)
.setCoordinate(coord).build()).setType(vehicleType).build(); .setCoordinate(coord).build()).setType(vehicleType).build();
vrpBuilder.addVehicle(vehicle); vrpBuilder.addVehicle(vehicle);
}
} }
else{ else{
Service.Builder serviceBuilder = Service.Builder.newInstance(customerId); Service.Builder serviceBuilder = Service.Builder.newInstance(customerId);

View file

@ -86,7 +86,7 @@ public class LuiShenReader {
if (counter == 10) { if (counter == 10) {
createVehicles(vehicleFile, costScenario, customerId, coord, start, end); createVehicles(vehicleFile, costScenario, customerId, coord, start, end);
} else { } else {
Service service = Service.Builder.newInstance("" + counter).addSizeDimension(0, demand) Service service = Service.Builder.newInstance("" + (counter - 10)).addSizeDimension(0, demand)
.setLocation(Location.Builder.newInstance().setCoordinate(coord).setId(customerId).build()).setServiceTime(serviceTime) .setLocation(Location.Builder.newInstance().setCoordinate(coord).setId(customerId).build()).setServiceTime(serviceTime)
.setTimeWindow(TimeWindow.newInstance(start, end)).build(); .setTimeWindow(TimeWindow.newInstance(start, end)).build();
vrpBuilder.addJob(service); vrpBuilder.addJob(service);