mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
consider service time in cost func and cost spec
This commit is contained in:
parent
11a320c2e4
commit
4f3cd5e684
4 changed files with 59 additions and 58 deletions
|
|
@ -591,8 +591,13 @@ public class Jsprit {
|
||||||
costs += vrp.getTransportCosts().getTransportCost(prevAct.getLocation(), route.getEnd().getLocation(), prevAct.getEndTime(), route.getDriver(), route.getVehicle());
|
costs += vrp.getTransportCosts().getTransportCost(prevAct.getLocation(), route.getEnd().getLocation(), prevAct.getEndTime(), route.getDriver(), route.getVehicle());
|
||||||
if(route.getVehicle().getBreak() != null){
|
if(route.getVehicle().getBreak() != null){
|
||||||
if(!hasBreak){
|
if(!hasBreak){
|
||||||
//break defined but not assigned penalty
|
//break defined and required but not assigned penalty
|
||||||
costs += maxCosts * 2;
|
if(route.getEnd().getArrTime() > route.getVehicle().getBreak().getTimeWindow().getEnd()){
|
||||||
|
costs += maxCosts * 2 + route.getVehicle().getBreak().getServiceDuration() * route.getVehicle().getType().getVehicleCostParams().perServiceTimeUnit;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
costs -= maxCosts * 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,7 +12,9 @@ public class WaitingTimeCosts implements VehicleRoutingActivityCosts {
|
||||||
@Override
|
@Override
|
||||||
public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
|
public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
|
||||||
if (vehicle != null) {
|
if (vehicle != null) {
|
||||||
return vehicle.getType().getVehicleCostParams().perWaitingTimeUnit * Math.max(0., tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime);
|
double waiting = vehicle.getType().getVehicleCostParams().perWaitingTimeUnit * Math.max(0., tourAct.getTheoreticalEarliestOperationStartTime() - arrivalTime);
|
||||||
|
double servicing = vehicle.getType().getVehicleCostParams().perServiceTimeUnit * tourAct.getOperationTime();
|
||||||
|
return waiting + servicing;
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,8 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
*/
|
*/
|
||||||
public static class VehicleCostParams {
|
public static class VehicleCostParams {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static VehicleTypeImpl.VehicleCostParams newInstance(double fix, double perTimeUnit, double perDistanceUnit) {
|
public static VehicleTypeImpl.VehicleCostParams newInstance(double fix, double perTimeUnit, double perDistanceUnit) {
|
||||||
return new VehicleCostParams(fix, perTimeUnit, perDistanceUnit);
|
return new VehicleCostParams(fix, perTimeUnit, perDistanceUnit);
|
||||||
}
|
}
|
||||||
|
|
@ -45,6 +47,7 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
public final double perTransportTimeUnit;
|
public final double perTransportTimeUnit;
|
||||||
public final double perDistanceUnit;
|
public final double perDistanceUnit;
|
||||||
public final double perWaitingTimeUnit;
|
public final double perWaitingTimeUnit;
|
||||||
|
public final double perServiceTimeUnit;
|
||||||
|
|
||||||
private VehicleCostParams(double fix, double perTimeUnit, double perDistanceUnit) {
|
private VehicleCostParams(double fix, double perTimeUnit, double perDistanceUnit) {
|
||||||
super();
|
super();
|
||||||
|
|
@ -53,6 +56,7 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
this.perTransportTimeUnit = perTimeUnit;
|
this.perTransportTimeUnit = perTimeUnit;
|
||||||
this.perDistanceUnit = perDistanceUnit;
|
this.perDistanceUnit = perDistanceUnit;
|
||||||
this.perWaitingTimeUnit = 0.;
|
this.perWaitingTimeUnit = 0.;
|
||||||
|
this.perServiceTimeUnit = 0.;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VehicleCostParams(double fix, double perTimeUnit, double perDistanceUnit, double perWaitingTimeUnit) {
|
public VehicleCostParams(double fix, double perTimeUnit, double perDistanceUnit, double perWaitingTimeUnit) {
|
||||||
|
|
@ -61,6 +65,16 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
this.perTransportTimeUnit = perTimeUnit;
|
this.perTransportTimeUnit = perTimeUnit;
|
||||||
this.perDistanceUnit = perDistanceUnit;
|
this.perDistanceUnit = perDistanceUnit;
|
||||||
this.perWaitingTimeUnit = perWaitingTimeUnit;
|
this.perWaitingTimeUnit = perWaitingTimeUnit;
|
||||||
|
this.perServiceTimeUnit = 0.;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VehicleCostParams(double fix, double perTimeUnit, double perDistanceUnit, double perWaitingTimeUnit, double perServiceTimeUnit) {
|
||||||
|
this.fix = fix;
|
||||||
|
this.perTimeUnit = perTimeUnit;
|
||||||
|
this.perTransportTimeUnit = perTimeUnit;
|
||||||
|
this.perDistanceUnit = perDistanceUnit;
|
||||||
|
this.perWaitingTimeUnit = perWaitingTimeUnit;
|
||||||
|
this.perServiceTimeUnit = perServiceTimeUnit;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
@ -92,6 +106,7 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
private double perDistance = 1.0;
|
private double perDistance = 1.0;
|
||||||
private double perTime = 0.0;
|
private double perTime = 0.0;
|
||||||
private double perWaitingTime = 0.0;
|
private double perWaitingTime = 0.0;
|
||||||
|
private double perServiceTime = 0.0;
|
||||||
|
|
||||||
private String profile = "car";
|
private String profile = "car";
|
||||||
|
|
||||||
|
|
@ -195,6 +210,12 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public VehicleTypeImpl.Builder setCostPerServiceTime(double perServiceTime) {
|
||||||
|
if (perServiceTime < 0.0) throw new IllegalStateException();
|
||||||
|
this.perServiceTime = perServiceTime;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Builds the vehicle-type.
|
* Builds the vehicle-type.
|
||||||
*
|
*
|
||||||
|
|
@ -303,7 +324,7 @@ public class VehicleTypeImpl implements VehicleType {
|
||||||
typeId = builder.id;
|
typeId = builder.id;
|
||||||
capacity = builder.capacity;
|
capacity = builder.capacity;
|
||||||
maxVelocity = builder.maxVelo;
|
maxVelocity = builder.maxVelo;
|
||||||
vehicleCostParams = new VehicleCostParams(builder.fixedCost, builder.perTime, builder.perDistance, builder.perWaitingTime);
|
vehicleCostParams = new VehicleCostParams(builder.fixedCost, builder.perTime, builder.perDistance, builder.perWaitingTime, builder.perServiceTime);
|
||||||
capacityDimensions = builder.capacityDimensions;
|
capacityDimensions = builder.capacityDimensions;
|
||||||
profile = builder.profile;
|
profile = builder.profile;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,24 @@
|
||||||
<problem xmlns="http://www.w3schools.com"
|
<problem xmlns="http://www.w3schools.com"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd">
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.w3schools.com vrp_xml_schema.xsd">
|
||||||
<problemType>
|
<problemType>
|
||||||
<fleetSize>INFINITE</fleetSize>
|
<fleetSize>FINITE</fleetSize>
|
||||||
</problemType>
|
</problemType>
|
||||||
<vehicles>
|
<vehicles>
|
||||||
|
<vehicle>
|
||||||
|
<id>v2</id>
|
||||||
|
<typeId>vehType2</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>
|
||||||
<vehicle>
|
<vehicle>
|
||||||
<id>v1</id>
|
<id>v1</id>
|
||||||
<typeId>vehType</typeId>
|
<typeId>vehType</typeId>
|
||||||
|
|
@ -33,58 +48,16 @@
|
||||||
<time>0.0</time>
|
<time>0.0</time>
|
||||||
</costs>
|
</costs>
|
||||||
</type>
|
</type>
|
||||||
|
<type>
|
||||||
|
<id>vehType2</id>
|
||||||
|
<capacity-dimensions>
|
||||||
|
<dimension index="0">200</dimension>
|
||||||
|
</capacity-dimensions>
|
||||||
|
<costs>
|
||||||
|
<fixed>0.0</fixed>
|
||||||
|
<distance>1.0</distance>
|
||||||
|
<time>0.0</time>
|
||||||
|
</costs>
|
||||||
|
</type>
|
||||||
</vehicleTypes>
|
</vehicleTypes>
|
||||||
<services>
|
|
||||||
<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>
|
|
||||||
<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>
|
|
||||||
</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>
|
</problem>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue