diff --git a/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLReader.java b/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLReader.java index ab45c336..0429873a 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLReader.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLReader.java @@ -36,12 +36,13 @@ import jsprit.core.problem.job.Shipment; import jsprit.core.problem.solution.VehicleRoutingProblemSolution; import jsprit.core.problem.solution.route.VehicleRoute; import jsprit.core.problem.solution.route.activity.End; -import jsprit.core.problem.solution.route.activity.Start; import jsprit.core.problem.solution.route.activity.TimeWindow; import jsprit.core.problem.solution.route.activity.TourActivityFactory; +import jsprit.core.problem.vehicle.PenaltyVehicleType; 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; @@ -421,7 +422,7 @@ public class VrpXMLReader{ private void readVehiclesAndTheirTypes(XMLConfiguration vrpProblem) { //read vehicle-types - Map types = new HashMap(); + Map types = new HashMap(); List typeConfigs = vrpProblem.configurationsAt("vehicleTypes.type"); for(HierarchicalConfiguration typeConfig : typeConfigs){ String typeId = typeConfig.getString("id"); @@ -435,9 +436,16 @@ public class VrpXMLReader{ if(fix != null) typeBuilder.setFixedCost(fix); if(timeC != null) typeBuilder.setCostPerTime(timeC); if(distC != null) typeBuilder.setCostPerDistance(distC); - VehicleTypeImpl type = typeBuilder.build(); - types.put(type.getTypeId(), type); -// vrpBuilder.addVehicleType(type); + VehicleType type = typeBuilder.build(); + String id = type.getTypeId(); + String penalty = typeConfig.getString("[@type]"); + if(penalty != null){ + if(penalty.equals("penalty")){ + type = new PenaltyVehicleType(type); + id = id + "_penalty"; + } + } + types.put(id, type); } //read vehicles @@ -449,7 +457,13 @@ public class VrpXMLReader{ Builder builder = VehicleImpl.Builder.newInstance(vehicleId); String typeId = vehicleConfig.getString("typeId"); if(typeId == null) throw new IllegalStateException("typeId is missing."); - VehicleTypeImpl type = types.get(typeId); + String vType = vehicleConfig.getString("[@type]"); + if(vType!=null){ + if(vType.equals("penalty")){ + typeId+="_penalty"; + } + } + VehicleType type = types.get(typeId); if(type == null) throw new IllegalStateException("vehicleType with typeId " + typeId + " is missing."); builder.setType(type); String locationId = vehicleConfig.getString("location.id"); diff --git a/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLWriter.java b/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLWriter.java index 64643d6c..3416f15b 100644 --- a/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLWriter.java +++ b/jsprit-core/src/main/java/jsprit/core/problem/io/VrpXMLWriter.java @@ -29,6 +29,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; import jsprit.core.problem.vehicle.Vehicle; import jsprit.core.problem.vehicle.VehicleType; @@ -224,6 +225,9 @@ public class VrpXMLWriter { append(Schema.VEHICLE).toString(); 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+").location.id", vehicle.getLocationId()); @@ -242,6 +246,9 @@ 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+").id", type.getTypeId()); xmlConfig.setProperty(typePathString + "("+typeCounter+").capacity", type.getCapacity()); xmlConfig.setProperty(typePathString + "("+typeCounter+").costs.fixed", type.getVehicleCostParams().fix); diff --git a/jsprit-core/src/main/resources/vrp_xml_schema.xsd b/jsprit-core/src/main/resources/vrp_xml_schema.xsd index f1722126..f631f2f4 100644 --- a/jsprit-core/src/main/resources/vrp_xml_schema.xsd +++ b/jsprit-core/src/main/resources/vrp_xml_schema.xsd @@ -55,6 +55,7 @@ + @@ -80,6 +81,7 @@ +