1
0
Fork 0
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:
oblonski 2015-10-06 12:35:15 +02:00
parent 11a320c2e4
commit 4f3cd5e684
4 changed files with 59 additions and 58 deletions

View file

@ -591,8 +591,13 @@ public class Jsprit {
costs += vrp.getTransportCosts().getTransportCost(prevAct.getLocation(), route.getEnd().getLocation(), prevAct.getEndTime(), route.getDriver(), route.getVehicle());
if(route.getVehicle().getBreak() != null){
if(!hasBreak){
//break defined but not assigned penalty
costs += maxCosts * 2;
//break defined and required but not assigned penalty
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;
}
}
}
}

View file

@ -12,7 +12,9 @@ public class WaitingTimeCosts implements VehicleRoutingActivityCosts {
@Override
public double getActivityCost(TourActivity tourAct, double arrivalTime, Driver driver, Vehicle vehicle) {
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;
}

View file

@ -35,6 +35,8 @@ public class VehicleTypeImpl implements VehicleType {
*/
public static class VehicleCostParams {
public static VehicleTypeImpl.VehicleCostParams newInstance(double fix, double perTimeUnit, double perDistanceUnit) {
return new VehicleCostParams(fix, perTimeUnit, perDistanceUnit);
}
@ -45,6 +47,7 @@ public class VehicleTypeImpl implements VehicleType {
public final double perTransportTimeUnit;
public final double perDistanceUnit;
public final double perWaitingTimeUnit;
public final double perServiceTimeUnit;
private VehicleCostParams(double fix, double perTimeUnit, double perDistanceUnit) {
super();
@ -53,6 +56,7 @@ public class VehicleTypeImpl implements VehicleType {
this.perTransportTimeUnit = perTimeUnit;
this.perDistanceUnit = perDistanceUnit;
this.perWaitingTimeUnit = 0.;
this.perServiceTimeUnit = 0.;
}
public VehicleCostParams(double fix, double perTimeUnit, double perDistanceUnit, double perWaitingTimeUnit) {
@ -61,6 +65,16 @@ public class VehicleTypeImpl implements VehicleType {
this.perTransportTimeUnit = perTimeUnit;
this.perDistanceUnit = perDistanceUnit;
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
@ -92,6 +106,7 @@ public class VehicleTypeImpl implements VehicleType {
private double perDistance = 1.0;
private double perTime = 0.0;
private double perWaitingTime = 0.0;
private double perServiceTime = 0.0;
private String profile = "car";
@ -195,6 +210,12 @@ public class VehicleTypeImpl implements VehicleType {
return this;
}
public VehicleTypeImpl.Builder setCostPerServiceTime(double perServiceTime) {
if (perServiceTime < 0.0) throw new IllegalStateException();
this.perServiceTime = perServiceTime;
return this;
}
/**
* Builds the vehicle-type.
*
@ -303,7 +324,7 @@ public class VehicleTypeImpl implements VehicleType {
typeId = builder.id;
capacity = builder.capacity;
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;
profile = builder.profile;
}

View file

@ -2,9 +2,24 @@
<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">
<problemType>
<fleetSize>INFINITE</fleetSize>
<fleetSize>FINITE</fleetSize>
</problemType>
<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>
<id>v1</id>
<typeId>vehType</typeId>
@ -33,58 +48,16 @@
<time>0.0</time>
</costs>
</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>
<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>