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

OPTI-505 include break data in vehicle key (#78)

* include break data in vehicle key

* add fixed cost
This commit is contained in:
kandelirina 2019-02-11 07:58:53 +02:00 committed by GitHub
parent cd92742547
commit ca72c6f05f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 64 additions and 6 deletions

View file

@ -364,7 +364,12 @@ public class VehicleImpl extends AbstractVehicle {
aBreak = builder.aBreak;
prohibitedTasks = builder.prohibitedTasks;
// setVehicleIdentifier(new VehicleTypeKey(type.getTypeId(),startLocation.getId(),endLocation.getId(),earliestDeparture,latestArrival,skills));
setVehicleIdentifier(new VehicleTypeKey(type.getTypeId(), startLocation.getId(), endLocation.getId(), earliestDeparture, latestArrival, skills, returnToDepot, getUserData()));
if (builder.aBreak != null) {
setVehicleIdentifier(new VehicleTypeKey(type.getTypeId(), startLocation.getId(), endLocation.getId(), earliestDeparture, latestArrival, skills, returnToDepot, getUserData(), aBreak.getTimeWindow().getStart(), aBreak.getTimeWindow().getEnd(), aBreak.getServiceDuration()));
} else {
setVehicleIdentifier(new VehicleTypeKey(type.getTypeId(), startLocation.getId(), endLocation.getId(), earliestDeparture, latestArrival, skills, returnToDepot, getUserData()));
}
}
/**

View file

@ -39,9 +39,11 @@ public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey {
public final Skills skills;
public final boolean returnToDepot;
public final Object userData;
public final double earliestBreakStart;
public final double latestBreakStart;
public final double breakDuration;
public VehicleTypeKey(String typeId, String startLocationId, String endLocationId, double earliestStart, double latestEnd, Skills skills, boolean returnToDepot, Object userData) {
super();
public VehicleTypeKey(String typeId, String startLocationId, String endLocationId, double earliestStart, double latestEnd, Skills skills, boolean returnToDepot, Object userData, double earliestBreakStart, double latestBreakStart, double breakDuration) {
this.type = typeId;
this.startLocationId = startLocationId;
this.endLocationId = endLocationId;
@ -50,6 +52,13 @@ public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey {
this.skills = skills;
this.returnToDepot = returnToDepot;
this.userData = userData;
this.earliestBreakStart = earliestBreakStart;
this.latestBreakStart = latestBreakStart;
this.breakDuration = breakDuration;
}
public VehicleTypeKey(String typeId, String startLocationId, String endLocationId, double earliestStart, double latestEnd, Skills skills, boolean returnToDepot, Object userData) {
this(typeId, startLocationId, endLocationId, earliestStart, latestEnd, skills, returnToDepot, userData, 0, Double.MAX_VALUE, 0);
}
public VehicleTypeKey(String typeId, String startLocationId, String endLocationId, double earliestStart, double latestEnd, Skills skills, boolean returnToDepot) {
@ -71,6 +80,9 @@ public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey {
if (!startLocationId.equals(that.startLocationId)) return false;
if (!type.equals(that.type)) return false;
if (!Objects.equals(that.userData, this.userData)) return false;
if (Double.compare(that.breakDuration, breakDuration) != 0) return false;
if (Double.compare(that.earliestBreakStart, earliestBreakStart) != 0) return false;
if (Double.compare(that.latestBreakStart, latestBreakStart) != 0) return false;
return true;
}
@ -91,6 +103,13 @@ public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey {
if (userData != null)
result = 31 * result + userData.hashCode();
temp = Double.doubleToLongBits(breakDuration);
result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(earliestBreakStart);
result = 31 * result + (int) (temp ^ (temp >>> 32));
temp = Double.doubleToLongBits(latestBreakStart);
result = 31 * result + (int) (temp ^ (temp >>> 32));
return result;
}

View file

@ -235,10 +235,13 @@ public class MaxTimeInVehicleTest {
.setMaxTimeInVehicle(14)
.setLocation(Location.newInstance(10, 5)).setServiceTime(2).build();
final VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("1").setFixedCost(1).build();
VehicleImpl v1 = VehicleImpl.Builder.newInstance("v1")
.setType(type)
.setStartLocation(Location.newInstance(8,5)).setReturnToDepot(true).build();
VehicleImpl v2 = VehicleImpl.Builder.newInstance("v2")
.setType(type)
.setStartLocation(Location.newInstance(5,0)).setReturnToDepot(true).build();
VehicleRoutingProblem vrp = VehicleRoutingProblem.Builder.newInstance()
@ -258,9 +261,9 @@ public class MaxTimeInVehicleTest {
VehicleRoutingAlgorithm vra = Jsprit.Builder.newInstance(vrp).setStateAndConstraintManager(stateManager,constraintManager).buildAlgorithm();
VehicleRoutingProblemSolution solution = Solutions.bestOf(vra.searchSolutions());
SolutionPrinter.print(vrp,solution, SolutionPrinter.Print.VERBOSE);
assertEquals(1,solution.getRoutes().size());
assertEquals(0,solution.getUnassignedJobs().size());
SolutionPrinter.print(vrp, solution, SolutionPrinter.Print.VERBOSE);
assertEquals(1, solution.getRoutes().size());
assertEquals(0, solution.getUnassignedJobs().size());
}

View file

@ -25,6 +25,7 @@ import org.junit.Test;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import static org.junit.Assert.*;
@ -255,4 +256,34 @@ public class VehicleImplTest {
assertNull(three.getUserData());
}
@Test
public void testBreakTimesIncludedInKey() {
VehicleTypeImpl type = VehicleTypeImpl.Builder.newInstance("type").build();
Vehicle one = VehicleImpl.Builder.newInstance("v1").setType(type)
.setStartLocation(Location.newInstance("start"))
.setEndLocation(Location.newInstance("end"))
.setEarliestStart(100)
.setLatestArrival(300)
.setBreak(Break.Builder.newInstance(UUID.randomUUID().toString()).addTimeWindow(0, 150).setServiceTime(60).build())
.build();
Vehicle two = VehicleImpl.Builder.newInstance("v2").setType(type)
.setStartLocation(Location.newInstance("start"))
.setEndLocation(Location.newInstance("end"))
.setEarliestStart(100)
.setLatestArrival(300)
.setBreak(Break.Builder.newInstance(UUID.randomUUID().toString()).addTimeWindow(0, 150).setServiceTime(60).build())
.build();
Vehicle three = VehicleImpl.Builder.newInstance("v3").setType(type)
.setStartLocation(Location.newInstance("start"))
.setEndLocation(Location.newInstance("end"))
.setEarliestStart(100)
.setLatestArrival(300)
.setBreak(Break.Builder.newInstance(UUID.randomUUID().toString()).addTimeWindow(100, 250).setServiceTime(60).build())
.build();
assertEquals(one.getVehicleTypeIdentifier(), two.getVehicleTypeIdentifier());
assertNotEquals(one.getVehicleTypeIdentifier(), three.getVehicleTypeIdentifier());
}
}