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

introduce Pickup and Delivery, and adjust tests

This commit is contained in:
oblonski 2013-08-25 18:49:29 +02:00
parent 462864d53e
commit 1f53c72620
8 changed files with 23 additions and 27 deletions

View file

@ -14,6 +14,7 @@ public class Delivery extends Service{
}
public Delivery build(){
this.setType("delivery");
return new Delivery(this);
}

View file

@ -13,6 +13,7 @@ public class Pickup extends Service {
}
public Pickup build(){
this.setType("pickup");
return new Pickup(this);
}

View file

@ -34,7 +34,7 @@ public class Service implements Job {
private String id;
private String locationId;
private String name = "service";
private String type = "service";
private Coordinate coord;
private double serviceTime;
private TimeWindow timeWindow = TimeWindow.newInstance(0.0, Double.MAX_VALUE);
@ -46,8 +46,8 @@ public class Service implements Job {
this.demand = size;
}
public Builder setName(String name){
this.name = name;
protected Builder setType(String name){
this.type = name;
return this;
}
@ -76,7 +76,7 @@ public class Service implements Job {
if(coord == null) throw new IllegalStateException("either locationId or a coordinate must be given. But is not.");
locationId = coord.toString();
}
this.setType("service");
return new Service(this);
}
@ -87,7 +87,7 @@ public class Service implements Job {
private final String locationId;
private final String name;
private final String type;
private final Coordinate coord;
@ -104,7 +104,7 @@ public class Service implements Job {
serviceTime = builder.serviceTime;
timeWindow = builder.timeWindow;
demand = builder.demand;
name = builder.name;
type = builder.type;
}
@Override
@ -137,7 +137,7 @@ public class Service implements Job {
* @return the name
*/
public String getType() {
return name;
return type;
}
@Override

View file

@ -216,7 +216,7 @@ public class VrpXMLReader{
int cap = 0;
if(capacityDemand != null) cap = Integer.parseInt(capacityDemand);
Service.Builder builder = Service.Builder.newInstance(id, cap);
builder.setName(name);
// builder.setType(name);
String serviceLocationId = serviceConfig.getString("locationId");
builder.setLocationId(serviceLocationId);
Coordinate serviceCoord = null;

View file

@ -125,7 +125,7 @@ public class VrpReaderV2Test {
new VrpXMLReader(builder, null).read(inFileName);
VehicleRoutingProblem vrp = builder.build();
Service s1 = (Service) vrp.getJobs().get("1");
assertEquals("delivery",s1.getType());
assertEquals("service",s1.getType());
assertEquals(1,s1.getCapacityDemand());
assertEquals(0.0,s1.getServiceDuration(),0.01);
assertEquals(2, vrp.getJobs().size());

View file

@ -130,8 +130,8 @@ public class VrpWriterV2Test {
builder.addVehicle(v1);
builder.addVehicle(v2);
Service s1 = Service.Builder.newInstance("1", 1).setLocationId("loc").setName("delivery").setServiceTime(2.0).build();
Service s2 = Service.Builder.newInstance("2", 1).setLocationId("loc2").setName("delivery").setServiceTime(4.0).build();
Service s1 = Service.Builder.newInstance("1", 1).setLocationId("loc").setServiceTime(2.0).build();
Service s2 = Service.Builder.newInstance("2", 1).setLocationId("loc2").setServiceTime(4.0).build();
VehicleRoutingProblem vrp = builder.addService(s1).addService(s2).build();
new VrpXMLWriter(vrp, null).write(infileName);
@ -144,7 +144,7 @@ public class VrpWriterV2Test {
Service s1_read = (Service) vrp.getJobs().get("1");
assertEquals("1", s1_read.getId());
assertEquals("loc", s1_read.getLocationId());
assertEquals("delivery", s1_read.getType());
assertEquals("service", s1_read.getType());
assertEquals(2.0,s1_read.getServiceDuration(),0.01);
}
@ -162,8 +162,8 @@ public class VrpWriterV2Test {
builder.addVehicle(v1);
builder.addVehicle(v2);
Service s1 = Service.Builder.newInstance("1", 1).setLocationId("loc").setName("delivery").setServiceTime(2.0).build();
Service s2 = Service.Builder.newInstance("2", 1).setLocationId("loc2").setName("delivery").setServiceTime(4.0).build();
Service s1 = Service.Builder.newInstance("1", 1).setLocationId("loc").setServiceTime(2.0).build();
Service s2 = Service.Builder.newInstance("2", 1).setLocationId("loc2").setServiceTime(4.0).build();
builder.addService(s1).addService(s2);
VehicleRoutingProblem vrp = builder.build();

View file

@ -20,8 +20,6 @@
******************************************************************************/
package basics.io;
import static org.junit.Assert.assertEquals;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -31,19 +29,15 @@ import org.junit.Test;
import basics.Service;
import basics.VehicleRoutingProblem;
import basics.VehicleRoutingProblemSolution;
import basics.Service.Builder;
import basics.VehicleRoutingProblem.FleetComposition;
import basics.VehicleRoutingProblem.FleetSize;
import basics.io.VrpXMLReader;
import basics.io.VrpXMLWriter;
import basics.VehicleRoutingProblemSolution;
import basics.route.End;
import basics.route.ServiceActivity;
import basics.route.Start;
import basics.route.Vehicle;
import basics.route.VehicleImpl;
import basics.route.VehicleRoute;
import basics.route.VehicleType;
import basics.route.VehicleTypeImpl;
public class VrpWriterV3Test {
@ -69,8 +63,8 @@ public class VrpWriterV3Test {
builder.addVehicle(v1);
builder.addVehicle(v2);
Service s1 = Service.Builder.newInstance("1", 1).setLocationId("loc").setName("delivery").setServiceTime(2.0).build();
Service s2 = Service.Builder.newInstance("2", 1).setLocationId("loc2").setName("delivery").setServiceTime(4.0).build();
Service s1 = Service.Builder.newInstance("1", 1).setLocationId("loc").setServiceTime(2.0).build();
Service s2 = Service.Builder.newInstance("2", 1).setLocationId("loc2").setServiceTime(4.0).build();
builder.addService(s1).addService(s2);
VehicleRoutingProblem vrp = builder.build();

View file

@ -50,7 +50,7 @@
</type>
</vehicleTypes>
<services>
<service id="2" type="delivery">
<service id="2" type="service">
<locationId>loc2</locationId>
<capacity-demand>1</capacity-demand>
<duration>4.0</duration>
@ -61,7 +61,7 @@
</timeWindow>
</timeWindows>
</service>
<service id="1" type="delivery">
<service id="1" type="service">
<locationId>loc</locationId>
<capacity-demand>1</capacity-demand>
<duration>2.0</duration>
@ -82,12 +82,12 @@
<driverId>noDriver</driverId>
<vehicleId>v1</vehicleId>
<start>10.0</start>
<act type="delivery">
<act type="service">
<serviceId>1</serviceId>
<arrTime>20.0</arrTime>
<endTime>30.0</endTime>
</act>
<act type="delivery">
<act type="service">
<serviceId>2</serviceId>
<arrTime>40.0</arrTime>
<endTime>80.0</endTime>