mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
added skills
This commit is contained in:
parent
b991793aba
commit
ea7407d936
12 changed files with 1705 additions and 76 deletions
|
|
@ -81,7 +81,20 @@ public class Skills {
|
|||
return skills.contains(skill.toLowerCase());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
Skills skills1 = (Skills) o;
|
||||
|
||||
if (skills != null ? !skills.equals(skills1.skills) : skills1.skills != null) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return skills != null ? skills.hashCode() : 0;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -417,7 +417,7 @@ public class VehicleRoutingProblem {
|
|||
Set<VehicleTypeKey> vehicleTypeKeys = new HashSet<VehicleTypeKey>();
|
||||
List<Vehicle> uniqueVehicles = new ArrayList<Vehicle>();
|
||||
for(Vehicle v : this.uniqueVehicles){
|
||||
VehicleTypeKey key = new VehicleTypeKey(v.getType().getTypeId(),v.getStartLocationId(),v.getEndLocationId(),v.getEarliestDeparture(),v.getLatestArrival());
|
||||
VehicleTypeKey key = new VehicleTypeKey(v.getType().getTypeId(),v.getStartLocationId(),v.getEndLocationId(),v.getEarliestDeparture(),v.getLatestArrival(), v.getSkills());
|
||||
if(!vehicleTypeKeys.contains(key)){
|
||||
uniqueVehicles.add(v);
|
||||
vehicleTypeKeys.add(key);
|
||||
|
|
@ -439,7 +439,8 @@ public class VehicleRoutingProblem {
|
|||
VehicleImpl penVehicle = VehicleImpl.Builder.newInstance(vehicleId).setEarliestStart(v.getEarliestDeparture())
|
||||
.setLatestArrival(v.getLatestArrival()).setStartLocationCoordinate(v.getStartLocationCoordinate()).setStartLocationId(v.getStartLocationId())
|
||||
.setEndLocationId(v.getEndLocationId()).setEndLocationCoordinate(v.getEndLocationCoordinate())
|
||||
.setReturnToDepot(v.isReturnToDepot()).setType(penType).build();
|
||||
.addSkills(v.getSkills())
|
||||
.setReturnToDepot(v.isReturnToDepot()).setType(penType).build();
|
||||
addVehicle(penVehicle);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class InfiniteVehicles implements VehicleFleetManager{
|
|||
|
||||
private void extractTypes(Collection<Vehicle> vehicles) {
|
||||
for(Vehicle v : vehicles){
|
||||
VehicleTypeKey typeKey = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocationId(),v.getEndLocationId(), v.getEarliestDeparture(), v.getLatestArrival());
|
||||
VehicleTypeKey typeKey = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocationId(),v.getEndLocationId(), v.getEarliestDeparture(), v.getLatestArrival(), v.getSkills());
|
||||
types.put(typeKey,v);
|
||||
sortedTypes.add(typeKey);
|
||||
|
||||
|
|
@ -81,7 +81,7 @@ class InfiniteVehicles implements VehicleFleetManager{
|
|||
@Override
|
||||
public Collection<Vehicle> getAvailableVehicles(Vehicle withoutThisType) {
|
||||
Collection<Vehicle> vehicles = new ArrayList<Vehicle>();
|
||||
VehicleTypeKey thisKey = new VehicleTypeKey(withoutThisType.getType().getTypeId(), withoutThisType.getStartLocationId(), withoutThisType.getEndLocationId(), withoutThisType.getEarliestDeparture(), withoutThisType.getLatestArrival());
|
||||
VehicleTypeKey thisKey = new VehicleTypeKey(withoutThisType.getType().getTypeId(), withoutThisType.getStartLocationId(), withoutThisType.getEndLocationId(), withoutThisType.getEarliestDeparture(), withoutThisType.getLatestArrival(), withoutThisType.getSkills());
|
||||
for(VehicleTypeKey key : types.keySet()){
|
||||
if(!key.equals(thisKey)){
|
||||
vehicles.add(types.get(key));
|
||||
|
|
|
|||
|
|
@ -122,11 +122,11 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
|
|||
}
|
||||
String typeId = v.getType().getTypeId();
|
||||
if(v.getType() instanceof PenaltyVehicleType){
|
||||
VehicleTypeKey typeKey = new VehicleTypeKey(typeId, v.getStartLocationId(), v.getEndLocationId(), v.getEarliestDeparture(), v.getLatestArrival());
|
||||
VehicleTypeKey typeKey = new VehicleTypeKey(typeId, v.getStartLocationId(), v.getEndLocationId(), v.getEarliestDeparture(), v.getLatestArrival(), v.getSkills());
|
||||
penaltyVehicles.put(typeKey, v);
|
||||
}
|
||||
else{
|
||||
VehicleTypeKey typeKey = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocationId(), v.getEndLocationId(), v.getEarliestDeparture(), v.getLatestArrival());
|
||||
VehicleTypeKey typeKey = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocationId(), v.getEndLocationId(), v.getEarliestDeparture(), v.getLatestArrival(), v.getSkills());
|
||||
if(!typeMapOfAvailableVehicles.containsKey(typeKey)){
|
||||
typeMapOfAvailableVehicles.put(typeKey, new TypeContainer());
|
||||
}
|
||||
|
|
@ -137,7 +137,7 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
|
|||
private void removeVehicle(Vehicle v){
|
||||
//it might be better to introduce a class PenaltyVehicle
|
||||
if(!(v.getType() instanceof PenaltyVehicleType)){
|
||||
VehicleTypeKey key = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocationId(), v.getEndLocationId(), v.getEarliestDeparture(), v.getLatestArrival());
|
||||
VehicleTypeKey key = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocationId(), v.getEndLocationId(), v.getEarliestDeparture(), v.getLatestArrival(), v.getSkills());
|
||||
if(typeMapOfAvailableVehicles.containsKey(key)){
|
||||
typeMapOfAvailableVehicles.get(key).remove(v);
|
||||
}
|
||||
|
|
@ -170,7 +170,7 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
|
|||
@Override
|
||||
public Collection<Vehicle> getAvailableVehicles(Vehicle withoutThisType) {
|
||||
List<Vehicle> vehicles = new ArrayList<Vehicle>();
|
||||
VehicleTypeKey thisKey = new VehicleTypeKey(withoutThisType.getType().getTypeId(), withoutThisType.getStartLocationId(), withoutThisType.getEndLocationId(), withoutThisType.getEarliestDeparture(), withoutThisType.getLatestArrival());
|
||||
VehicleTypeKey thisKey = new VehicleTypeKey(withoutThisType.getType().getTypeId(), withoutThisType.getStartLocationId(), withoutThisType.getEndLocationId(), withoutThisType.getEarliestDeparture(), withoutThisType.getLatestArrival(), withoutThisType.getSkills());
|
||||
for(VehicleTypeKey key : typeMapOfAvailableVehicles.keySet()){
|
||||
if(key.equals(thisKey)) continue;
|
||||
if(!typeMapOfAvailableVehicles.get(key).isEmpty()){
|
||||
|
|
|
|||
|
|
@ -244,8 +244,12 @@ public class VehicleImpl extends AbstractVehicle{
|
|||
* @return vehicle builder
|
||||
*/
|
||||
public static Builder newInstance(String vehicleId){ return new Builder(vehicleId); }
|
||||
|
||||
}
|
||||
|
||||
public Builder addSkills(Skills skills) {
|
||||
this.skillBuilder.addAllSkills(skills.values());
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns empty/noVehicle which is a vehicle having no capacity, no type and no reasonable id.
|
||||
|
|
@ -294,8 +298,8 @@ public class VehicleImpl extends AbstractVehicle{
|
|||
startLocationCoord = builder.startLocationCoord;
|
||||
endLocationId = builder.endLocationId;
|
||||
endLocationCoord = builder.endLocationCoord;
|
||||
setVehicleIdentifier(new VehicleTypeKey(type.getTypeId(),startLocationId,endLocationId,earliestDeparture,latestArrival));
|
||||
skills = builder.skills;
|
||||
setVehicleIdentifier(new VehicleTypeKey(type.getTypeId(),startLocationId,endLocationId,earliestDeparture,latestArrival,skills));
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -19,6 +19,7 @@
|
|||
package jsprit.core.problem.vehicle;
|
||||
|
||||
import jsprit.core.problem.AbstractVehicle;
|
||||
import jsprit.core.problem.Skills;
|
||||
|
||||
/**
|
||||
* Key to identify similar vehicles
|
||||
|
|
@ -35,67 +36,51 @@ public class VehicleTypeKey extends AbstractVehicle.AbstractTypeKey{
|
|||
public final String endLocationId;
|
||||
public final double earliestStart;
|
||||
public final double latestEnd;
|
||||
public final Skills skills;
|
||||
|
||||
public VehicleTypeKey(String typeId, String startLocationId, String endLocationId, double earliestStart, double latestEnd) {
|
||||
public VehicleTypeKey(String typeId, String startLocationId, String endLocationId, double earliestStart, double latestEnd, Skills skills) {
|
||||
super();
|
||||
this.type = typeId;
|
||||
this.startLocationId = startLocationId;
|
||||
this.endLocationId = endLocationId;
|
||||
this.earliestStart = earliestStart;
|
||||
this.latestEnd = latestEnd;
|
||||
this.skills = skills;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
long temp;
|
||||
temp = Double.doubleToLongBits(earliestStart);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
result = prime * result
|
||||
+ ((endLocationId == null) ? 0 : endLocationId.hashCode());
|
||||
temp = Double.doubleToLongBits(latestEnd);
|
||||
result = prime * result + (int) (temp ^ (temp >>> 32));
|
||||
result = prime * result
|
||||
+ ((startLocationId == null) ? 0 : startLocationId.hashCode());
|
||||
result = prime * result + ((type == null) ? 0 : type.hashCode());
|
||||
return result;
|
||||
}
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) return true;
|
||||
if (!(o instanceof VehicleTypeKey)) return false;
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj)
|
||||
return true;
|
||||
if (obj == null)
|
||||
return false;
|
||||
if (getClass() != obj.getClass())
|
||||
return false;
|
||||
VehicleTypeKey other = (VehicleTypeKey) obj;
|
||||
if (Double.doubleToLongBits(earliestStart) != Double
|
||||
.doubleToLongBits(other.earliestStart))
|
||||
return false;
|
||||
if (endLocationId == null) {
|
||||
if (other.endLocationId != null)
|
||||
return false;
|
||||
} else if (!endLocationId.equals(other.endLocationId))
|
||||
return false;
|
||||
if (Double.doubleToLongBits(latestEnd) != Double
|
||||
.doubleToLongBits(other.latestEnd))
|
||||
return false;
|
||||
if (startLocationId == null) {
|
||||
if (other.startLocationId != null)
|
||||
return false;
|
||||
} else if (!startLocationId.equals(other.startLocationId))
|
||||
return false;
|
||||
if (type == null) {
|
||||
if (other.type != null)
|
||||
return false;
|
||||
} else if (!type.equals(other.type))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
VehicleTypeKey that = (VehicleTypeKey) o;
|
||||
|
||||
@Override
|
||||
if (Double.compare(that.earliestStart, earliestStart) != 0) return false;
|
||||
if (Double.compare(that.latestEnd, latestEnd) != 0) return false;
|
||||
if (!endLocationId.equals(that.endLocationId)) return false;
|
||||
if (!skills.equals(that.skills)) return false;
|
||||
if (!startLocationId.equals(that.startLocationId)) return false;
|
||||
if (!type.equals(that.type)) return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result;
|
||||
long temp;
|
||||
result = type.hashCode();
|
||||
result = 31 * result + startLocationId.hashCode();
|
||||
result = 31 * result + endLocationId.hashCode();
|
||||
temp = Double.doubleToLongBits(earliestStart);
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
temp = Double.doubleToLongBits(latestEnd);
|
||||
result = 31 * result + (int) (temp ^ (temp >>> 32));
|
||||
result = 31 * result + skills.hashCode();
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
stringBuilder.append(type).append("_").append(startLocationId).append("_").append(endLocationId)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue