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

bugfix #96 - modified core.problem.vehicle.VehicleFleetManagerImpl

according to changes in core.problem.vehicle.VehicleTypeKey
This commit is contained in:
oblonski 2014-05-15 13:56:48 +02:00
parent ef05f954e9
commit 20d69a84c0

View file

@ -29,10 +29,6 @@ import jsprit.core.problem.vehicle.VehicleImpl.NoVehicle;
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
class VehicleFleetManagerImpl implements VehicleFleetManager { class VehicleFleetManagerImpl implements VehicleFleetManager {
public VehicleFleetManagerImpl newInstance(Collection<Vehicle> vehicles){ public VehicleFleetManagerImpl newInstance(Collection<Vehicle> vehicles){
@ -132,11 +128,11 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
} }
String typeId = v.getType().getTypeId(); String typeId = v.getType().getTypeId();
if(v.getType() instanceof PenaltyVehicleType){ if(v.getType() instanceof PenaltyVehicleType){
VehicleTypeKey typeKey = new VehicleTypeKey(typeId, v.getStartLocationId(), v.getEndLocationId()); VehicleTypeKey typeKey = new VehicleTypeKey(typeId, v.getStartLocationId(), v.getEndLocationId(), v.getEarliestDeparture(), v.getLatestArrival());
penaltyVehicles.put(typeKey, v); penaltyVehicles.put(typeKey, v);
} }
else{ else{
VehicleTypeKey typeKey = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocationId(), v.getEndLocationId()); VehicleTypeKey typeKey = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocationId(), v.getEndLocationId(), v.getEarliestDeparture(), v.getLatestArrival());
if(!typeMapOfAvailableVehicles.containsKey(typeKey)){ if(!typeMapOfAvailableVehicles.containsKey(typeKey)){
typeMapOfAvailableVehicles.put(typeKey, new TypeContainer(typeKey)); typeMapOfAvailableVehicles.put(typeKey, new TypeContainer(typeKey));
} }
@ -147,7 +143,7 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
private void removeVehicle(Vehicle v){ private void removeVehicle(Vehicle v){
//it might be better to introduce a class PenaltyVehicle //it might be better to introduce a class PenaltyVehicle
if(!(v.getType() instanceof PenaltyVehicleType)){ if(!(v.getType() instanceof PenaltyVehicleType)){
VehicleTypeKey key = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocationId(), v.getEndLocationId()); VehicleTypeKey key = new VehicleTypeKey(v.getType().getTypeId(), v.getStartLocationId(), v.getEndLocationId(), v.getEarliestDeparture(), v.getLatestArrival());
if(typeMapOfAvailableVehicles.containsKey(key)){ if(typeMapOfAvailableVehicles.containsKey(key)){
typeMapOfAvailableVehicles.get(key).remove(v); typeMapOfAvailableVehicles.get(key).remove(v);
} }
@ -192,7 +188,7 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
@Deprecated @Deprecated
public Collection<Vehicle> getAvailableVehicles(String withoutThisType, String withThisLocationId) { public Collection<Vehicle> getAvailableVehicles(String withoutThisType, String withThisLocationId) {
List<Vehicle> vehicles = new ArrayList<Vehicle>(); List<Vehicle> vehicles = new ArrayList<Vehicle>();
VehicleTypeKey thisKey = new VehicleTypeKey(withoutThisType, withThisLocationId, withThisLocationId); VehicleTypeKey thisKey = new VehicleTypeKey(withoutThisType, withThisLocationId, withThisLocationId, 0., 0.);
for(VehicleTypeKey key : typeMapOfAvailableVehicles.keySet()){ for(VehicleTypeKey key : typeMapOfAvailableVehicles.keySet()){
if(key.equals(thisKey)) continue; if(key.equals(thisKey)) continue;
if(!typeMapOfAvailableVehicles.get(key).isEmpty()){ if(!typeMapOfAvailableVehicles.get(key).isEmpty()){
@ -212,7 +208,7 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
@Override @Override
public Collection<Vehicle> getAvailableVehicles(Vehicle withoutThisType) { public Collection<Vehicle> getAvailableVehicles(Vehicle withoutThisType) {
List<Vehicle> vehicles = new ArrayList<Vehicle>(); List<Vehicle> vehicles = new ArrayList<Vehicle>();
VehicleTypeKey thisKey = new VehicleTypeKey(withoutThisType.getType().getTypeId(), withoutThisType.getStartLocationId(), withoutThisType.getEndLocationId()); VehicleTypeKey thisKey = new VehicleTypeKey(withoutThisType.getType().getTypeId(), withoutThisType.getStartLocationId(), withoutThisType.getEndLocationId(), withoutThisType.getEarliestDeparture(), withoutThisType.getLatestArrival());
for(VehicleTypeKey key : typeMapOfAvailableVehicles.keySet()){ for(VehicleTypeKey key : typeMapOfAvailableVehicles.keySet()){
if(key.equals(thisKey)) continue; if(key.equals(thisKey)) continue;
if(!typeMapOfAvailableVehicles.get(key).isEmpty()){ if(!typeMapOfAvailableVehicles.get(key).isEmpty()){