Skip to content

Commit 6ee0f8f

Browse files
authored
Merge branch 'main' into kn/aComment
2 parents 44a3c9c + a1fdebc commit 6ee0f8f

7 files changed

Lines changed: 23 additions & 91 deletions

File tree

contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/fleet/FleetModule.java

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@
2424

2525
import org.matsim.api.core.v01.network.Network;
2626
import org.matsim.contrib.dvrp.analysis.ExecutedScheduleCollector;
27-
import org.matsim.contrib.dvrp.load.DefaultDvrpLoadFromFleet;
2827
import org.matsim.contrib.dvrp.load.DefaultDvrpLoadFromVehicle;
2928
import org.matsim.contrib.dvrp.load.DefaultDvrpLoadFromVehicle.CapacityMapping;
30-
import org.matsim.contrib.dvrp.load.DvrpLoadFromFleet;
3129
import org.matsim.contrib.dvrp.load.DvrpLoadFromVehicle;
3230
import org.matsim.contrib.dvrp.load.DvrpLoadModule;
3331
import org.matsim.contrib.dvrp.load.DvrpLoadParams;
@@ -81,13 +79,6 @@ public void install() {
8179

8280
install(new DvrpLoadModule(getMode(), loadParams));
8381

84-
bindModal(DefaultDvrpLoadFromFleet.class).toProvider(modalProvider(getter -> {
85-
DvrpLoadType loadType = getter.getModal(DvrpLoadType.class);
86-
return new DefaultDvrpLoadFromFleet(loadType, loadParams.getMapFleetCapacity());
87-
})).in(Singleton.class);
88-
89-
bindModal(DvrpLoadFromFleet.class).to(modalKey(DefaultDvrpLoadFromFleet.class));
90-
9182
bindModal(DvrpLoadFromVehicle.class).toProvider(modalProvider(getter -> {
9283
DvrpLoadType loadType = getter.getModal(DvrpLoadType.class);
9384
return new DefaultDvrpLoadFromVehicle(loadType, CapacityMapping.build(loadParams));
@@ -96,8 +87,8 @@ public void install() {
9687
if (fleetSpecificationUrl != null) {
9788
bindModal(FleetSpecification.class).toProvider(modalProvider((getter) -> {
9889
FleetSpecification fleetSpecification = new FleetSpecificationImpl();
99-
DvrpLoadFromFleet dvrpLoadFromFleet = getter.getModal(DvrpLoadFromFleet.class);
100-
new FleetReader(fleetSpecification, dvrpLoadFromFleet).parse(fleetSpecificationUrl);
90+
DvrpLoadType loadType = getter.getModal(DvrpLoadType.class);
91+
new FleetReader(fleetSpecification, loadType).parse(fleetSpecificationUrl);
10192
return fleetSpecification;
10293
})).asEagerSingleton();
10394
} else {

contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/fleet/FleetReader.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,11 @@
2020

2121
package org.matsim.contrib.dvrp.fleet;
2222

23-
import java.util.Optional;
2423
import java.util.Stack;
2524

2625
import org.matsim.api.core.v01.Id;
2726
import org.matsim.contrib.dvrp.load.DvrpLoad;
28-
import org.matsim.contrib.dvrp.load.DvrpLoadFromFleet;
27+
import org.matsim.contrib.dvrp.load.DvrpLoadType;
2928
import org.matsim.core.utils.io.MatsimXmlParser;
3029
import org.xml.sax.Attributes;
3130

@@ -38,12 +37,12 @@ public class FleetReader extends MatsimXmlParser {
3837
private static final int DEFAULT_CAPACITY = 1;
3938

4039
private final FleetSpecification fleet;
41-
private final DvrpLoadFromFleet dvrpVehicleLoadCreator;
40+
private final DvrpLoadType loadType;
4241

43-
public FleetReader(FleetSpecification fleet, DvrpLoadFromFleet dvrpVehicleLoadCreator) {
42+
public FleetReader(FleetSpecification fleet, DvrpLoadType loadType) {
4443
super(ValidationType.DTD_ONLY);
4544
this.fleet = fleet;
46-
this.dvrpVehicleLoadCreator = dvrpVehicleLoadCreator;
45+
this.loadType = loadType;
4746
}
4847

4948
@Override
@@ -62,18 +61,13 @@ private DvrpVehicleSpecification createSpecification(Attributes atts) {
6261
return ImmutableDvrpVehicleSpecification.newBuilder()
6362
.id(vehicleId)
6463
.startLinkId(Id.createLinkId(atts.getValue("start_link")))
65-
.capacity(getCapacity(atts.getValue("capacity"), vehicleId, this.dvrpVehicleLoadCreator))
64+
.capacity(getCapacity(atts.getValue("capacity")))
6665
.serviceBeginTime(Double.parseDouble(atts.getValue("t_0")))
6766
.serviceEndTime(Double.parseDouble(atts.getValue("t_1")))
6867
.build();
6968
}
7069

71-
private static DvrpLoad getCapacity(String capacityAttribute, Id<DvrpVehicle> vehicleId, DvrpLoadFromFleet dvrpVehicleLoadCreator) {
72-
double capacity = Double.parseDouble(Optional.ofNullable(capacityAttribute).orElse(DEFAULT_CAPACITY + ""));
73-
if ((int)capacity != capacity) {
74-
//for backwards compatibility: use double when reading files (capacity used to be double)
75-
throw new IllegalArgumentException("capacity must be an integer value");
76-
}
77-
return dvrpVehicleLoadCreator.getDvrpVehicleLoad((int)capacity, vehicleId);
70+
private DvrpLoad getCapacity(String val) {
71+
return loadType.deserialize(val == null ? String.valueOf(DEFAULT_CAPACITY) : val);
7872
}
7973
}

contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/load/DefaultDvrpLoadFromFleet.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/load/DvrpLoadFromFleet.java

Lines changed: 0 additions & 15 deletions
This file was deleted.

contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/load/DvrpLoadParams.java

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,6 @@ public void setMapVehicleTypeOther(String mapVehicleTypeOther) {
7070
this.mapVehicleTypeOther = mapVehicleTypeOther;
7171
}
7272

73-
public String getMapFleetCapacity() {
74-
return mapFleetCapacity;
75-
}
76-
77-
public void setMapFleetCapacity(String mapFleetCapacity) {
78-
this.mapFleetCapacity = mapFleetCapacity;
79-
}
80-
8173
public String getDefaultRequestDimension() {
8274
return defaultRequestDimension;
8375
}
@@ -124,10 +116,6 @@ public enum VehicleCapacitySource {
124116
@Comment("maps the other capacity of a the dvrp vehicle type to a specific dimension")
125117
private String mapVehicleTypeOther = null;
126118

127-
@Parameter
128-
@Comment("maps the vehicle capacity when loading from dvrp fleet format to a specific dimension")
129-
private String mapFleetCapacity = "passengers";
130-
131119
@Parameter
132120
@Comment("if no other load information is given, each request obtains a unit load for the given dimension")
133121
private String defaultRequestDimension = "passengers";
@@ -155,8 +143,5 @@ public void checkConsistency(Config config) {
155143

156144
Preconditions.checkState(getMapVehicleTypeOther() == null || getDimensions().contains(getMapVehicleTypeOther()),
157145
"the dimension configured for the vehicle type other capacity does not exist");
158-
159-
Preconditions.checkState(getMapFleetCapacity() == null || getDimensions().contains(getMapFleetCapacity()),
160-
"the dimension configured for the dvrp fleet vehicle capacity does not exist");
161146
}
162147
}

contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/load/IntegersLoadType.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,13 @@ public DvrpLoad deserialize(String representation) {
9696
// list of numbers
9797

9898
String[] components = representation.split(",");
99-
int[] values = new int[components.length];
99+
if (components.length > dimensions.size()) {
100+
throw new IllegalStateException("Too many load values given: " + representation);
101+
}
102+
103+
int[] values = new int[dimensions.size()];
100104

101-
for (int k = 0; k < values.length; k++) {
105+
for (int k = 0; k < components.length; k++) {
102106
values[k] = Integer.parseInt(components[k].trim());
103107
}
104108

contribs/dvrp/src/main/java/org/matsim/contrib/dvrp/load/README.md

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,16 +45,6 @@ By default, one person is mapped to one slot of the capacity. This is set by def
4545

4646
This example indicates that, if no other load information is provided for a trip/person, a unit load is assumed for the slot *passengers*. An exception will be thrown if the option is set to null. This way, the user can enforce that a load is defined for every request.
4747

48-
### Defining vehicle capacities from the fleet file
49-
50-
One option of loading vehicles for a DVRP mode is to use a fleet file with its respective format. In the fleet file, each *vehicle* has a *capacity* given as an integer. This value is transformed into a capacity by assigning the given integer to a slot that is configurable:
51-
52-
```xml
53-
<parameterset name="load">
54-
<param name="mapFleetCapacity" value="passengers">
55-
</parameterset>
56-
```
57-
5848
### Defining vehicle capacities from the vehicles file
5949

6050
When reading the vehicles for the DVRP fleet from a vehicles file, each vehicle can have a `dvrp:capacity` attribute defining the quantities that are assigned to each capacity slot:
@@ -84,6 +74,14 @@ If neither the vehicle, nor the vehilce type, define capacities, the quantities
8474
</parameterset>
8575
```
8676

77+
### Defining vehicle capacities from the fleet file
78+
79+
One option of loading vehicles for a DVRP mode is to use a fleet file with its respective format. In the fleet file, each *vehicle* has a *capacity*. This value can either be given as an integer (referring to the first dimension of the load, i.e., passengers by default) or as a complex capacity of the format described above:
80+
81+
```xml
82+
<vehicle id="drt1" ... capacity="passengers=4,luggage=8" />
83+
```
84+
8785
### Defining an even more complex load/capacity logic
8886

8987
DVRP now provides the `DvrpLoadType` and `DvrpLoad` interfaces. By creating new implementations of those interfaces one can define an arbitrary logic with respect to how capacities are handled in DVRP. In particular, the base functionality allows to define multi-dimensional loads and capacities that have *independent* slots. This means that, for instance, adding one more luggage to a vehicle does not affect the capacity of passengers. Such a logic, however, can be implemented using the cited interfaces.

0 commit comments

Comments
 (0)