mirror of
https://github.com/graphhopper/jsprit.git
synced 2020-01-24 07:45:05 +01:00
modify problem reader/writer to deal vehicles that can start AND end at
specified locations
This commit is contained in:
parent
6575b6d48e
commit
63060f3b35
10 changed files with 310 additions and 38 deletions
|
|
@ -472,20 +472,44 @@ public class VrpXMLReader{
|
|||
if(type == null) throw new IllegalStateException("vehicleType with typeId " + typeId + " is missing.");
|
||||
builder.setType(type);
|
||||
String locationId = vehicleConfig.getString("location.id");
|
||||
if(locationId == null) {
|
||||
locationId = vehicleConfig.getString("startLocation.id");
|
||||
}
|
||||
if(locationId == null) throw new IllegalStateException("location.id is missing.");
|
||||
builder.setLocationId(locationId);
|
||||
builder.setStartLocationId(locationId);
|
||||
String coordX = vehicleConfig.getString("location.coord[@x]");
|
||||
String coordY = vehicleConfig.getString("location.coord[@y]");
|
||||
if(coordX == null || coordY == null) {
|
||||
coordX = vehicleConfig.getString("startLocation.coord[@x]");
|
||||
coordY = vehicleConfig.getString("startLocation.coord[@y]");
|
||||
}
|
||||
if(coordX == null || coordY == null) {
|
||||
if(!doNotWarnAgain) {
|
||||
logger.warn("location.coord is missing. will not warn you again.");
|
||||
doNotWarnAgain = true;
|
||||
}
|
||||
}
|
||||
else{
|
||||
Coordinate coordinate = Coordinate.newInstance(Double.parseDouble(coordX), Double.parseDouble(coordY));
|
||||
builder.setStartLocationCoordinate(coordinate);
|
||||
}
|
||||
|
||||
String endLocationId = vehicleConfig.getString("endLocation.id");
|
||||
if(endLocationId != null) builder.setEndLocationId(endLocationId);
|
||||
String endCoordX = vehicleConfig.getString("endLocation.coord[@x]");
|
||||
String endCoordY = vehicleConfig.getString("endLocation.coord[@y]");
|
||||
if(endCoordX == null || endCoordY == null) {
|
||||
if(!doNotWarnAgain) {
|
||||
logger.warn("location.coord is missing. do not warn you again.");
|
||||
logger.warn("endLocation.coord is missing. will not warn you again.");
|
||||
doNotWarnAgain = true;
|
||||
}
|
||||
}
|
||||
else{
|
||||
Coordinate coordinate = Coordinate.newInstance(Double.parseDouble(coordX), Double.parseDouble(coordY));
|
||||
builder.setLocationCoord(coordinate);
|
||||
Coordinate coordinate = Coordinate.newInstance(Double.parseDouble(endCoordX), Double.parseDouble(endCoordY));
|
||||
builder.setEndLocationCoordinate(coordinate);
|
||||
}
|
||||
|
||||
|
||||
String start = vehicleConfig.getString("timeSchedule.start");
|
||||
String end = vehicleConfig.getString("timeSchedule.end");
|
||||
if(start != null) builder.setEarliestStart(Double.parseDouble(start));
|
||||
|
|
|
|||
|
|
@ -236,10 +236,15 @@ public class VrpXMLWriter {
|
|||
}
|
||||
xmlConfig.setProperty(vehiclePathString + "("+counter+").id", vehicle.getId());
|
||||
xmlConfig.setProperty(vehiclePathString + "("+counter+").typeId", vehicle.getType().getTypeId());
|
||||
xmlConfig.setProperty(vehiclePathString + "("+counter+").location.id", vehicle.getLocationId());
|
||||
if(vehicle.getCoord() != null){
|
||||
xmlConfig.setProperty(vehiclePathString + "("+counter+").location.coord[@x]", vehicle.getCoord().getX());
|
||||
xmlConfig.setProperty(vehiclePathString + "("+counter+").location.coord[@y]", vehicle.getCoord().getY());
|
||||
xmlConfig.setProperty(vehiclePathString + "("+counter+").startLocation.id", vehicle.getStartLocationId());
|
||||
if(vehicle.getStartLocationCoordinate() != null){
|
||||
xmlConfig.setProperty(vehiclePathString + "("+counter+").startLocation.coord[@x]", vehicle.getStartLocationCoordinate().getX());
|
||||
xmlConfig.setProperty(vehiclePathString + "("+counter+").startLocation.coord[@y]", vehicle.getStartLocationCoordinate().getY());
|
||||
}
|
||||
xmlConfig.setProperty(vehiclePathString + "("+counter+").endLocation.id", vehicle.getEndLocationId());
|
||||
if(vehicle.getEndLocationCoordinate() != null){
|
||||
xmlConfig.setProperty(vehiclePathString + "("+counter+").endLocation.coord[@x]", vehicle.getEndLocationCoordinate().getX());
|
||||
xmlConfig.setProperty(vehiclePathString + "("+counter+").endLocation.coord[@y]", vehicle.getEndLocationCoordinate().getY());
|
||||
}
|
||||
xmlConfig.setProperty(vehiclePathString + "("+counter+").timeSchedule.start", vehicle.getEarliestDeparture());
|
||||
xmlConfig.setProperty(vehiclePathString + "("+counter+").timeSchedule.end", vehicle.getLatestArrival());
|
||||
|
|
|
|||
|
|
@ -99,6 +99,7 @@ public interface Vehicle {
|
|||
|
||||
/**
|
||||
* Returns the end-locationId of this vehicle.
|
||||
*
|
||||
*/
|
||||
public abstract String getEndLocationId();
|
||||
|
||||
|
|
|
|||
|
|
@ -239,8 +239,15 @@ public class VehicleImpl implements Vehicle {
|
|||
* <p>if {@link VehicleType} is not set, default vehicle-type is set with id="default" and
|
||||
* capacity=0
|
||||
*
|
||||
* <p>if startLocationId || locationId is null (=> startLocationCoordinate || locationCoordinate must be set) then startLocationId=startLocationCoordinate.toString()
|
||||
* and locationId=locationCoordinate.toString() [coord.toString() --> [x=x_val][y=y_val])
|
||||
* <p>if endLocationId is null and endLocationCoordinate is set then endLocationId=endLocationCoordinate.toString()
|
||||
* <p>if endLocationId==null AND endLocationCoordinate==null then endLocationId=startLocationId AND endLocationCoord=startLocationCoord
|
||||
* Thus endLocationId can never be null even returnToDepot is false.
|
||||
*
|
||||
* @return vehicle
|
||||
* @throw IllegalStateException if both locationId and locationCoord is not set
|
||||
* @throws IllegalStateException if both locationId and locationCoord is not set or (endLocationCoord!=null AND returnToDepot=false)
|
||||
* or (endLocationId!=null AND returnToDepot=false)
|
||||
*/
|
||||
public VehicleImpl build(){
|
||||
if(locationId == null && locationCoord != null) {
|
||||
|
|
@ -249,15 +256,13 @@ public class VehicleImpl implements Vehicle {
|
|||
}
|
||||
if(locationId == null && locationCoord == null) throw new IllegalStateException("locationId and locationCoord is missing.");
|
||||
if(locationCoord == null) log.warn("locationCoord for vehicle " + id + " is missing.");
|
||||
if(endLocationCoord != null && returnToDepot == false) throw new IllegalStateException("this must not be. you specified both endLocationCoord and open-routes. this is contradictory. <br>" +
|
||||
"if you set endLocation, returnToDepot must be true. if returnToDepot is false, endLocationCoord must not be specified.");
|
||||
if(endLocationId != null && returnToDepot == false) throw new IllegalStateException("this must not be. you specified both endLocationId and open-routes. this is contradictory. <br>" +
|
||||
"if you set endLocation, returnToDepot must be true. if returnToDepot is false, endLocationCoord must not be specified.");
|
||||
if(endLocationId == null && endLocationCoord != null) endLocationId = endLocationCoord.toString();
|
||||
if(endLocationId == null && endLocationCoord == null) {
|
||||
endLocationId = startLocationId;
|
||||
endLocationCoord = startLocationCoord;
|
||||
}
|
||||
if( !startLocationId.equals(endLocationId) && returnToDepot == false) throw new IllegalStateException("this must not be. you specified both endLocationId and open-routes. this is contradictory. <br>" +
|
||||
"if you set endLocation, returnToDepot must be true. if returnToDepot is false, endLocationCoord must not be specified.");
|
||||
return new VehicleImpl(this);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -37,18 +37,28 @@
|
|||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="id" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element name="location">
|
||||
<xs:element name="location" minOccurs="0" maxOccurs="1">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="id" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element name="coord" minOccurs="0" maxOccurs="1">
|
||||
<xs:complexType>
|
||||
<xs:attribute name="x" type="xs:decimal" use="required"/>
|
||||
<xs:attribute name="y" type="xs:decimal" use="required"/>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="coord" type="coordType" minOccurs="0" maxOccurs="1"/>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="startLocation" minOccurs="0" maxOccurs="1">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="id" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element name="coord" type="coordType" minOccurs="0" maxOccurs="1"/>
|
||||
</xs:all>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="endLocation" minOccurs="0" maxOccurs="1">
|
||||
<xs:complexType>
|
||||
<xs:all>
|
||||
<xs:element name="id" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
||||
<xs:element name="coord" type="coordType" minOccurs="0" maxOccurs="1"/>
|
||||
</xs:all>
|
||||
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="typeId" type="xs:string" minOccurs="1" maxOccurs="1"/>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue