mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
Addprohibitedtasksupport (#36)
* add prohibited task option * add to builder * add to constructor * array to set * cr * remove unsused import
This commit is contained in:
parent
dd5b326e52
commit
4398bb6311
2 changed files with 35 additions and 1 deletions
|
|
@ -83,4 +83,7 @@ public interface Vehicle extends HasId, HasIndex {
|
|||
// default Object getUserData() {
|
||||
// return null;
|
||||
// };
|
||||
public abstract boolean isTaskPermited(String taskId);
|
||||
|
||||
public abstract void addProhibitedTask(String taskId);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import com.graphhopper.jsprit.core.problem.job.Break;
|
|||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
/**
|
||||
|
|
@ -97,6 +97,16 @@ public class VehicleImpl extends AbstractVehicle {
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTaskPermited(String taskId) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addProhibitedTask(String taskId) {
|
||||
throw new IllegalArgumentException("NoVehicle should not have prohibited tasks");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -134,6 +144,8 @@ public class VehicleImpl extends AbstractVehicle {
|
|||
|
||||
private Object userData;
|
||||
|
||||
private Set<String> prohibitedTasks = new HashSet<>();
|
||||
|
||||
private Builder(String id) {
|
||||
super();
|
||||
this.id = id;
|
||||
|
|
@ -248,6 +260,12 @@ public class VehicleImpl extends AbstractVehicle {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Builder addExcludedTask(String taskId){
|
||||
if (taskId != null)
|
||||
prohibitedTasks.add(taskId);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds and returns the vehicle.
|
||||
* <p>
|
||||
|
|
@ -331,6 +349,8 @@ public class VehicleImpl extends AbstractVehicle {
|
|||
|
||||
private final Break aBreak;
|
||||
|
||||
private final Set<String> prohibitedTasks;
|
||||
|
||||
private VehicleImpl(Builder builder) {
|
||||
setUserData(builder.userData);
|
||||
id = builder.id;
|
||||
|
|
@ -342,6 +362,7 @@ public class VehicleImpl extends AbstractVehicle {
|
|||
endLocation = builder.endLocation;
|
||||
startLocation = builder.startLocation;
|
||||
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));
|
||||
}
|
||||
|
|
@ -407,6 +428,16 @@ public class VehicleImpl extends AbstractVehicle {
|
|||
return aBreak;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isTaskPermited(String taskId) {
|
||||
return !prohibitedTasks.contains(taskId);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addProhibitedTask(String taskId) {
|
||||
prohibitedTasks.add(taskId);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see java.lang.Object#hashCode()
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue