mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
make reader/writer read and write penalty-flags indicating whether a
vehicle/vehicle-type is a penalty-vehicle/type
This commit is contained in:
parent
e7d7d3c799
commit
149c4d4ecb
3 changed files with 29 additions and 6 deletions
|
|
@ -36,12 +36,13 @@ import jsprit.core.problem.job.Shipment;
|
||||||
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||||
import jsprit.core.problem.solution.route.activity.End;
|
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.TimeWindow;
|
||||||
import jsprit.core.problem.solution.route.activity.TourActivityFactory;
|
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.Vehicle;
|
||||||
import jsprit.core.problem.vehicle.VehicleImpl;
|
import jsprit.core.problem.vehicle.VehicleImpl;
|
||||||
import jsprit.core.problem.vehicle.VehicleImpl.Builder;
|
import jsprit.core.problem.vehicle.VehicleImpl.Builder;
|
||||||
|
import jsprit.core.problem.vehicle.VehicleType;
|
||||||
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
import jsprit.core.problem.vehicle.VehicleTypeImpl;
|
||||||
import jsprit.core.util.Coordinate;
|
import jsprit.core.util.Coordinate;
|
||||||
import jsprit.core.util.Resource;
|
import jsprit.core.util.Resource;
|
||||||
|
|
@ -421,7 +422,7 @@ public class VrpXMLReader{
|
||||||
private void readVehiclesAndTheirTypes(XMLConfiguration vrpProblem) {
|
private void readVehiclesAndTheirTypes(XMLConfiguration vrpProblem) {
|
||||||
|
|
||||||
//read vehicle-types
|
//read vehicle-types
|
||||||
Map<String, VehicleTypeImpl> types = new HashMap<String, VehicleTypeImpl>();
|
Map<String, VehicleType> types = new HashMap<String, VehicleType>();
|
||||||
List<HierarchicalConfiguration> typeConfigs = vrpProblem.configurationsAt("vehicleTypes.type");
|
List<HierarchicalConfiguration> typeConfigs = vrpProblem.configurationsAt("vehicleTypes.type");
|
||||||
for(HierarchicalConfiguration typeConfig : typeConfigs){
|
for(HierarchicalConfiguration typeConfig : typeConfigs){
|
||||||
String typeId = typeConfig.getString("id");
|
String typeId = typeConfig.getString("id");
|
||||||
|
|
@ -435,9 +436,16 @@ public class VrpXMLReader{
|
||||||
if(fix != null) typeBuilder.setFixedCost(fix);
|
if(fix != null) typeBuilder.setFixedCost(fix);
|
||||||
if(timeC != null) typeBuilder.setCostPerTime(timeC);
|
if(timeC != null) typeBuilder.setCostPerTime(timeC);
|
||||||
if(distC != null) typeBuilder.setCostPerDistance(distC);
|
if(distC != null) typeBuilder.setCostPerDistance(distC);
|
||||||
VehicleTypeImpl type = typeBuilder.build();
|
VehicleType type = typeBuilder.build();
|
||||||
types.put(type.getTypeId(), type);
|
String id = type.getTypeId();
|
||||||
// vrpBuilder.addVehicleType(type);
|
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
|
//read vehicles
|
||||||
|
|
@ -449,7 +457,13 @@ public class VrpXMLReader{
|
||||||
Builder builder = VehicleImpl.Builder.newInstance(vehicleId);
|
Builder builder = VehicleImpl.Builder.newInstance(vehicleId);
|
||||||
String typeId = vehicleConfig.getString("typeId");
|
String typeId = vehicleConfig.getString("typeId");
|
||||||
if(typeId == null) throw new IllegalStateException("typeId is missing.");
|
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.");
|
if(type == null) throw new IllegalStateException("vehicleType with typeId " + typeId + " is missing.");
|
||||||
builder.setType(type);
|
builder.setType(type);
|
||||||
String locationId = vehicleConfig.getString("location.id");
|
String locationId = vehicleConfig.getString("location.id");
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ import jsprit.core.problem.solution.VehicleRoutingProblemSolution;
|
||||||
import jsprit.core.problem.solution.route.VehicleRoute;
|
import jsprit.core.problem.solution.route.VehicleRoute;
|
||||||
import jsprit.core.problem.solution.route.activity.TourActivity;
|
import jsprit.core.problem.solution.route.activity.TourActivity;
|
||||||
import jsprit.core.problem.solution.route.activity.TourActivity.JobActivity;
|
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.Vehicle;
|
||||||
import jsprit.core.problem.vehicle.VehicleType;
|
import jsprit.core.problem.vehicle.VehicleType;
|
||||||
|
|
||||||
|
|
@ -224,6 +225,9 @@ public class VrpXMLWriter {
|
||||||
append(Schema.VEHICLE).toString();
|
append(Schema.VEHICLE).toString();
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
for(Vehicle vehicle : vrp.getVehicles()){
|
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+").id", vehicle.getId());
|
||||||
xmlConfig.setProperty(vehiclePathString + "("+counter+").typeId", vehicle.getType().getTypeId());
|
xmlConfig.setProperty(vehiclePathString + "("+counter+").typeId", vehicle.getType().getTypeId());
|
||||||
xmlConfig.setProperty(vehiclePathString + "("+counter+").location.id", vehicle.getLocationId());
|
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();
|
String typePathString = Schema.builder().append(Schema.TYPES).dot(Schema.TYPE).build();
|
||||||
int typeCounter = 0;
|
int typeCounter = 0;
|
||||||
for(VehicleType type : vrp.getTypes()){
|
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+").id", type.getTypeId());
|
||||||
xmlConfig.setProperty(typePathString + "("+typeCounter+").capacity", type.getCapacity());
|
xmlConfig.setProperty(typePathString + "("+typeCounter+").capacity", type.getCapacity());
|
||||||
xmlConfig.setProperty(typePathString + "("+typeCounter+").costs.fixed", type.getVehicleCostParams().fix);
|
xmlConfig.setProperty(typePathString + "("+typeCounter+").costs.fixed", type.getVehicleCostParams().fix);
|
||||||
|
|
|
||||||
|
|
@ -55,6 +55,7 @@
|
||||||
<xs:element name="timeSchedule" type="timeWindowType"/>
|
<xs:element name="timeSchedule" type="timeWindowType"/>
|
||||||
<xs:element name="returnToDepot" type="xs:boolean" minOccurs="0" maxOccurs="1"/>
|
<xs:element name="returnToDepot" type="xs:boolean" minOccurs="0" maxOccurs="1"/>
|
||||||
</xs:all>
|
</xs:all>
|
||||||
|
<xs:attribute name="type" type="xs:string" use="optional" />
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
|
|
||||||
|
|
@ -80,6 +81,7 @@
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
</xs:all>
|
</xs:all>
|
||||||
|
<xs:attribute name="type" type="xs:string" use="optional" />
|
||||||
</xs:complexType>
|
</xs:complexType>
|
||||||
</xs:element>
|
</xs:element>
|
||||||
</xs:sequence>
|
</xs:sequence>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue