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

remove penalty vehicle stuff

This commit is contained in:
oblonski 2015-02-04 08:47:14 +01:00
parent a0419ab3fd
commit 657f85e896
13 changed files with 64 additions and 260 deletions

View file

@ -26,8 +26,11 @@ import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.solution.route.activity.TimeWindow;
import jsprit.core.problem.solution.route.activity.TourActivityFactory;
import jsprit.core.problem.vehicle.*;
import jsprit.core.problem.vehicle.Vehicle;
import jsprit.core.problem.vehicle.VehicleImpl;
import jsprit.core.problem.vehicle.VehicleImpl.Builder;
import jsprit.core.problem.vehicle.VehicleType;
import jsprit.core.problem.vehicle.VehicleTypeImpl;
import jsprit.core.util.Coordinate;
import jsprit.core.util.Resource;
import org.apache.commons.configuration.ConfigurationException;
@ -577,18 +580,6 @@ public class VrpXMLReader{
if(distC != null) typeBuilder.setCostPerDistance(distC);
VehicleType type = typeBuilder.build();
String id = type.getTypeId();
String penalty = typeConfig.getString("[@type]");
if(penalty != null){
if(penalty.equals("penalty")){
String penaltyFactor = typeConfig.getString("[@penaltyFactor]");
if(penaltyFactor != null){
type = new PenaltyVehicleType(type,Double.parseDouble(penaltyFactor));
}
else type = new PenaltyVehicleType(type);
id = id + "_penalty";
}
}
types.put(id, type);
}

View file

@ -26,7 +26,6 @@ import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.problem.solution.route.activity.TourActivity.JobActivity;
import jsprit.core.problem.vehicle.PenaltyVehicleType;
import jsprit.core.problem.vehicle.Vehicle;
import jsprit.core.problem.vehicle.VehicleType;
import org.apache.commons.configuration.ConfigurationException;
@ -315,9 +314,6 @@ public class VrpXMLWriter {
String vehiclePathString = Schema.VEHICLES + "." + Schema.VEHICLE;
int counter = 0;
for(Vehicle vehicle : vrp.getVehicles()){
if(vehicle.getType() instanceof PenaltyVehicleType){
xmlConfig.setProperty(vehiclePathString + "("+counter+")[@type]", "penalty");
}
xmlConfig.setProperty(vehiclePathString + "("+counter+").id", vehicle.getId());
xmlConfig.setProperty(vehiclePathString + "("+counter+").typeId", vehicle.getType().getTypeId());
xmlConfig.setProperty(vehiclePathString + "("+counter+").startLocation.id", vehicle.getStartLocation().getId());
@ -353,10 +349,6 @@ public class VrpXMLWriter {
String typePathString = Schema.builder().append(Schema.TYPES).dot(Schema.TYPE).build();
int typeCounter = 0;
for(VehicleType type : vrp.getTypes()){
if(type instanceof PenaltyVehicleType){
xmlConfig.setProperty(typePathString + "("+typeCounter+")[@type]", "penalty");
xmlConfig.setProperty(typePathString + "("+typeCounter+")[@penaltyFactor]", ((PenaltyVehicleType)type).getPenaltyFactor());
}
xmlConfig.setProperty(typePathString + "("+typeCounter+").id", type.getTypeId());
for(int i=0;i<type.getCapacityDimensions().getNuOfDimensions();i++){

View file

@ -1,65 +0,0 @@
/*******************************************************************************
* Copyright (C) 2013 Stefan Schroeder
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3.0 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
package jsprit.core.problem.vehicle;
import jsprit.core.problem.Capacity;
import jsprit.core.problem.vehicle.VehicleTypeImpl.VehicleCostParams;
public class PenaltyVehicleType implements VehicleType{
private VehicleType type;
private double penaltyFactor = 2;
public PenaltyVehicleType(VehicleType type) {
super();
this.type = type;
}
public PenaltyVehicleType(VehicleType type, double penaltyFactor) {
super();
this.type = type;
this.penaltyFactor = penaltyFactor;
}
public double getPenaltyFactor(){
return this.penaltyFactor;
}
@Override
public String getTypeId() {
return type.getTypeId();
}
@Override
public VehicleCostParams getVehicleCostParams() {
return type.getVehicleCostParams();
}
@Override
public double getMaxVelocity() {
return type.getMaxVelocity();
}
@Override
public Capacity getCapacityDimensions() {
return type.getCapacityDimensions();
}
}

View file

@ -120,27 +120,18 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
if(v.getType() == null){
throw new IllegalStateException("vehicle needs type");
}
String typeId = v.getType().getTypeId();
if(v.getType() instanceof PenaltyVehicleType){
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(), v.getSkills());
if(!typeMapOfAvailableVehicles.containsKey(typeKey)){
typeMapOfAvailableVehicles.put(typeKey, new TypeContainer());
}
typeMapOfAvailableVehicles.get(typeKey).add(v);
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());
}
typeMapOfAvailableVehicles.get(typeKey).add(v);
}
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(), v.getSkills());
if(typeMapOfAvailableVehicles.containsKey(key)){
typeMapOfAvailableVehicles.get(key).remove(v);
}
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);
}
}
@ -193,7 +184,6 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
if(vehicles.isEmpty() || vehicle instanceof NoVehicle){
return;
}
if(vehicle.getType() instanceof PenaltyVehicleType) return;
boolean locked = lockedVehicles.add(vehicle);
removeVehicle(vehicle);
if(!locked){
@ -210,7 +200,6 @@ class VehicleFleetManagerImpl implements VehicleFleetManager {
return;
}
if(vehicle == null) return;
if(vehicle.getType() instanceof PenaltyVehicleType) return;
lockedVehicles.remove(vehicle);
addVehicle(vehicle);
}

View file

@ -24,7 +24,7 @@ import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
import jsprit.core.problem.solution.route.VehicleRoute;
import jsprit.core.problem.solution.route.activity.TourActivity;
import jsprit.core.problem.solution.route.activity.TourActivity.JobActivity;
import jsprit.core.problem.vehicle.PenaltyVehicleType;
/**
* Printer to print the details of a vehicle-routing-problem solution.
@ -143,10 +143,7 @@ public class SolutionPrinter {
}
private static String getVehicleString(VehicleRoute route) {
if(route.getVehicle().getType() instanceof PenaltyVehicleType){
return route.getVehicle().getId()+"*";
}
return route.getVehicle().getId();
return route.getVehicle().getId();
}
private static Jobs getNuOfJobs(VehicleRoutingProblem problem) {