Skip to content

Commit

Permalink
refactor: rename vehicle type and product to category in core and sup…
Browse files Browse the repository at this point in the history
…ply package
  • Loading branch information
munterfi committed Nov 19, 2024
1 parent 269b5d4 commit 8be99e1
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,10 +102,9 @@ private void addTrains() {

private void createAndAddTransitLine(Trainrun train, EnumMap<RouteDirection, List<TrainrunSection>> sequence) {

// get vehicle type info from train category and create line id based on forward direction or trainrun name
String vehicleType = lookup.categories.get(train.getCategoryId()).getShortName();
String lineId = createTransitLineId(train, sequence.get(RouteDirection.FORWARD), vehicleType);
builder.addTransitLine(lineId, vehicleType);
String category = lookup.categories.get(train.getCategoryId()).getShortName();
String lineId = createTransitLineId(train, sequence.get(RouteDirection.FORWARD), category);
builder.addTransitLine(lineId, category);

// add transit route for each direction
for (RouteDirection direction : RouteDirection.values()) {
Expand Down Expand Up @@ -180,15 +179,15 @@ private void createAndAddTransitRoute(String lineId, Trainrun train, List<Trainr
departures.forEach(departure -> builder.addDeparture(routeId, departure));
}

private String createTransitLineId(Trainrun train, List<TrainrunSection> sections, String vehicleType) {
private String createTransitLineId(Trainrun train, List<TrainrunSection> sections, String category) {

// check if option is set to use train name; also avoid name if it is empty (optional field in NGE)
String lineId;
if (config.isUseTrainNamesAsIds() && !train.getName().isBlank()) {
lineId = train.getName();
} else {
// create id from vehicle type with origin and destination, ignore the train name from nge
lineId = String.format("%s_%s_%s", vehicleType,
// create id from category with origin and destination, ignore the train name from nge
lineId = String.format("%s_%s_%s", category,
lookup.nodes.get(sections.getFirst().getSourceNodeId()).getBetriebspunktName(),
lookup.nodes.get(sections.getLast().getTargetNodeId()).getBetriebspunktName());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

public interface RollingStockRepository {

VehicleTypeInfo getVehicleType(String productId);
VehicleTypeInfo getVehicleType(String category);

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public interface SupplyBuilder {

SupplyBuilder addStopFacility(String id, double x, double y);

SupplyBuilder addTransitLine(String id, String productId);
SupplyBuilder addTransitLine(String id, String category);

SupplyBuilder addTransitRoute(String id, String lineId, String originStopId, Duration dwellTimeAtOrigin);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@
public class TransitLineInfo {

String id;
String productId;
String category;

}
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public class NoRollingStockRepository implements RollingStockRepository {
public static final double DEFAULT_MAX_VELOCITY = 120 / 3.6; // meters per second

@Override
public VehicleTypeInfo getVehicleType(String productId) {
return new VehicleTypeInfo(productId, DEFAULT_CAPACITY, DEFAULT_LENGTH, DEFAULT_MAX_VELOCITY, Map.of());
public VehicleTypeInfo getVehicleType(String category) {
return new VehicleTypeInfo(category, DEFAULT_CAPACITY, DEFAULT_LENGTH, DEFAULT_MAX_VELOCITY, Map.of());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ public List<VehicleAllocation> plan() {

return departureInfos.stream().sorted(Comparator.comparing(DepartureInfo::getTime)).map(departureInfo -> {

// get vehicle type based on product
String productId = departureInfo.getTransitRouteInfo().getTransitLineInfo().getProductId();
VehicleTypeInfo vehicleTypeInfo = vehicleTypeInfos.get(productId);
// get vehicle type based on category (product)
String category = departureInfo.getTransitRouteInfo().getTransitLineInfo().getCategory();
VehicleTypeInfo vehicleTypeInfo = vehicleTypeInfos.get(category);
if (vehicleTypeInfo == null) {
vehicleTypeInfo = rollingStockRepository.getVehicleType(productId);
vehicleTypeInfos.put(productId, vehicleTypeInfo);
vehicleTypeInfo = rollingStockRepository.getVehicleType(category);
vehicleTypeInfos.put(category, vehicleTypeInfo);
}

// update vehicle counts and departure counts
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ public SupplyBuilder addStopFacility(String id, double x, double y) {
}

@Override
public SupplyBuilder addTransitLine(String id, String productId) {
public SupplyBuilder addTransitLine(String id, String category) {
if (transitLineInfos.containsKey(id)) {
throw new RuntimeException("Transit line already exists for id " + id);
}

transitLineInfos.put(id, new TransitLineInfo(id, productId));
transitLineInfos.put(id, new TransitLineInfo(id, category));

return this;
}
Expand Down

0 comments on commit 8be99e1

Please sign in to comment.