mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
Merge remote-tracking branch 'origin/master'
This commit is contained in:
commit
a714312685
7 changed files with 23 additions and 98 deletions
|
|
@ -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);
|
||||||
|
|
|
||||||
|
|
@ -72,8 +72,6 @@ public class Service extends AbstractJob {
|
||||||
|
|
||||||
protected double serviceTime;
|
protected double serviceTime;
|
||||||
|
|
||||||
protected TimeWindow timeWindow = TimeWindow.newInstance(0.0, Double.MAX_VALUE);
|
|
||||||
|
|
||||||
protected Capacity.Builder capacityBuilder = Capacity.Builder.newInstance();
|
protected Capacity.Builder capacityBuilder = Capacity.Builder.newInstance();
|
||||||
|
|
||||||
protected Capacity capacity;
|
protected Capacity capacity;
|
||||||
|
|
@ -98,7 +96,7 @@ public class Service extends AbstractJob {
|
||||||
Builder(String id){
|
Builder(String id){
|
||||||
this.id = id;
|
this.id = id;
|
||||||
timeWindows = new TimeWindowsImpl();
|
timeWindows = new TimeWindowsImpl();
|
||||||
timeWindows.add(timeWindow);
|
timeWindows.add(TimeWindow.newInstance(0.0, Double.MAX_VALUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -176,7 +174,6 @@ public class Service extends AbstractJob {
|
||||||
|
|
||||||
public Builder<T> setTimeWindow(TimeWindow tw){
|
public Builder<T> setTimeWindow(TimeWindow tw){
|
||||||
if(tw == null) throw new IllegalArgumentException("time-window arg must not be null");
|
if(tw == null) throw new IllegalArgumentException("time-window arg must not be null");
|
||||||
this.timeWindow = tw;
|
|
||||||
this.timeWindows = new TimeWindowsImpl();
|
this.timeWindows = new TimeWindowsImpl();
|
||||||
timeWindows.add(tw);
|
timeWindows.add(tw);
|
||||||
return this;
|
return this;
|
||||||
|
|
|
||||||
|
|
@ -61,10 +61,6 @@ public class Shipment extends AbstractJob {
|
||||||
|
|
||||||
private double deliveryServiceTime = 0.0;
|
private double deliveryServiceTime = 0.0;
|
||||||
|
|
||||||
private TimeWindow deliveryTimeWindow = TimeWindow.newInstance(0.0, Double.MAX_VALUE);
|
|
||||||
|
|
||||||
private TimeWindow pickupTimeWindow = TimeWindow.newInstance(0.0, Double.MAX_VALUE);
|
|
||||||
|
|
||||||
private Capacity.Builder capacityBuilder = Capacity.Builder.newInstance();
|
private Capacity.Builder capacityBuilder = Capacity.Builder.newInstance();
|
||||||
|
|
||||||
private Capacity capacity;
|
private Capacity capacity;
|
||||||
|
|
@ -107,9 +103,9 @@ public class Shipment extends AbstractJob {
|
||||||
if (id == null) throw new IllegalArgumentException("id must not be null");
|
if (id == null) throw new IllegalArgumentException("id must not be null");
|
||||||
this.id = id;
|
this.id = id;
|
||||||
pickupTimeWindows = new TimeWindowsImpl();
|
pickupTimeWindows = new TimeWindowsImpl();
|
||||||
pickupTimeWindows.add(pickupTimeWindow);
|
pickupTimeWindows.add(TimeWindow.newInstance(0.0, Double.MAX_VALUE));
|
||||||
deliveryTimeWindows = new TimeWindowsImpl();
|
deliveryTimeWindows = new TimeWindowsImpl();
|
||||||
deliveryTimeWindows.add(deliveryTimeWindow);
|
deliveryTimeWindows.add(TimeWindow.newInstance(0.0, Double.MAX_VALUE));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -169,7 +165,6 @@ public class Shipment extends AbstractJob {
|
||||||
*/
|
*/
|
||||||
public Builder setPickupTimeWindow(TimeWindow timeWindow) {
|
public Builder setPickupTimeWindow(TimeWindow timeWindow) {
|
||||||
if (timeWindow == null) throw new IllegalArgumentException("delivery time-window must not be null");
|
if (timeWindow == null) throw new IllegalArgumentException("delivery time-window must not be null");
|
||||||
this.pickupTimeWindow = timeWindow;
|
|
||||||
this.pickupTimeWindows = new TimeWindowsImpl();
|
this.pickupTimeWindows = new TimeWindowsImpl();
|
||||||
this.pickupTimeWindows.add(timeWindow);
|
this.pickupTimeWindows.add(timeWindow);
|
||||||
return this;
|
return this;
|
||||||
|
|
@ -215,7 +210,6 @@ public class Shipment extends AbstractJob {
|
||||||
*/
|
*/
|
||||||
public Builder setDeliveryTimeWindow(TimeWindow timeWindow) {
|
public Builder setDeliveryTimeWindow(TimeWindow timeWindow) {
|
||||||
if (timeWindow == null) throw new IllegalArgumentException("delivery time-window must not be null");
|
if (timeWindow == null) throw new IllegalArgumentException("delivery time-window must not be null");
|
||||||
this.deliveryTimeWindow = timeWindow;
|
|
||||||
this.deliveryTimeWindows = new TimeWindowsImpl();
|
this.deliveryTimeWindows = new TimeWindowsImpl();
|
||||||
this.deliveryTimeWindows.add(timeWindow);
|
this.deliveryTimeWindows.add(timeWindow);
|
||||||
return this;
|
return this;
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
|
|
@ -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);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue