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 'origin/master'

This commit is contained in:
oblonski 2017-11-08 19:40:12 +01:00
commit a714312685
No known key found for this signature in database
GPG key ID: 179DE487285680D1
7 changed files with 23 additions and 98 deletions

View file

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

View file

@ -72,8 +72,6 @@ public class Service extends AbstractJob {
protected double serviceTime;
protected TimeWindow timeWindow = TimeWindow.newInstance(0.0, Double.MAX_VALUE);
protected Capacity.Builder capacityBuilder = Capacity.Builder.newInstance();
protected Capacity capacity;
@ -98,7 +96,7 @@ public class Service extends AbstractJob {
Builder(String id){
this.id = id;
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){
if(tw == null) throw new IllegalArgumentException("time-window arg must not be null");
this.timeWindow = tw;
this.timeWindows = new TimeWindowsImpl();
timeWindows.add(tw);
return this;

View file

@ -61,10 +61,6 @@ public class Shipment extends AbstractJob {
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 capacity;
@ -107,9 +103,9 @@ public class Shipment extends AbstractJob {
if (id == null) throw new IllegalArgumentException("id must not be null");
this.id = id;
pickupTimeWindows = new TimeWindowsImpl();
pickupTimeWindows.add(pickupTimeWindow);
pickupTimeWindows.add(TimeWindow.newInstance(0.0, Double.MAX_VALUE));
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) {
if (timeWindow == null) throw new IllegalArgumentException("delivery time-window must not be null");
this.pickupTimeWindow = timeWindow;
this.pickupTimeWindows = new TimeWindowsImpl();
this.pickupTimeWindows.add(timeWindow);
return this;
@ -215,7 +210,6 @@ public class Shipment extends AbstractJob {
*/
public Builder setDeliveryTimeWindow(TimeWindow timeWindow) {
if (timeWindow == null) throw new IllegalArgumentException("delivery time-window must not be null");
this.deliveryTimeWindow = timeWindow;
this.deliveryTimeWindows = new TimeWindowsImpl();
this.deliveryTimeWindows.add(timeWindow);
return this;

View file

@ -21,80 +21,29 @@
package com.graphhopper.jsprit.core.util;
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
*/
public class CrowFlyCosts extends AbstractForwardVehicleRoutingTransportCosts {
public int speed = 1;
public double detourFactor = 1.0;
public class CrowFlyCosts extends EuclideanCosts {
private Locations locations;
public CrowFlyCosts(Locations locations) {
super();
this.locations = locations;
}
@Override
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) {
double calculateDistance(Location fromLocation, Location toLocation) {
Coordinate from = null;
Coordinate to = null;
if (fromLocation.getCoordinate() != null & toLocation.getCoordinate() != null) {
if (fromLocation.getCoordinate() != null && toLocation.getCoordinate() != null) {
from = fromLocation.getCoordinate();
to = toLocation.getCoordinate();
} else if (locations != null) {
from = locations.getCoord(fromLocation.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);
}
}

View file

@ -42,42 +42,32 @@ public class EuclideanCosts extends AbstractForwardVehicleRoutingTransportCosts
@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 distance = calculateDistance(from, to);
if (vehicle != null && vehicle.getType() != null) {
return distance * vehicle.getType().getVehicleCostParams().perDistanceUnit;
}
double costs = distance;
if (vehicle != null) {
if (vehicle.getType() != null) {
costs = distance * vehicle.getType().getVehicleCostParams().perDistanceUnit;
}
}
return costs;
return distance;
}
private double calculateDistance(Location fromLocation, Location toLocation) {
double calculateDistance(Location fromLocation, Location toLocation) {
return calculateDistance(fromLocation.getCoordinate(), toLocation.getCoordinate());
}
private double calculateDistance(Coordinate from, Coordinate to) {
return EuclideanDistanceCalculator.calculateDistance(from, to) * detourFactor;
double calculateDistance(Coordinate from, Coordinate to) {
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
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;
return calculateDistance(from, to) / speed;
}
@Override
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");
VehicleTypeImpl vehicleType = typeBuilder.build();
double end = Double.parseDouble(tokens[8])*timeProjectionFactor;
for(int i=0;i<10;i++) {
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("solomonVehicle"+(i+1)).setEarliestStart(0.).setLatestArrival(end)
.setStartLocation(Location.Builder.newInstance().setId(customerId)
VehicleImpl vehicle = VehicleImpl.Builder.newInstance("solomonVehicle").setEarliestStart(0.).setLatestArrival(end)
.setStartLocation(Location.Builder.newInstance().setId(customerId)
.setCoordinate(coord).build()).setType(vehicleType).build();
vrpBuilder.addVehicle(vehicle);
}
vrpBuilder.addVehicle(vehicle);
}
else{
Service.Builder serviceBuilder = Service.Builder.newInstance(customerId);

View file

@ -86,7 +86,7 @@ public class LuiShenReader {
if (counter == 10) {
createVehicles(vehicleFile, costScenario, customerId, coord, start, end);
} 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)
.setTimeWindow(TimeWindow.newInstance(start, end)).build();
vrpBuilder.addJob(service);