Skip to content

Commit

Permalink
Make use of custom profiles and add gauge as encoded value
Browse files Browse the repository at this point in the history
  • Loading branch information
Nakaner committed May 14, 2024
1 parent dc2f7a2 commit 852443b
Show file tree
Hide file tree
Showing 15 changed files with 261 additions and 136 deletions.
181 changes: 81 additions & 100 deletions config.yml
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
# encoder properties
flagEncoderProperties:
- name: tramtrain
electrified: contact_line
voltages: 15000;15000;750
frequencies: 16.7;16.67;0
gauges: 1435
maxspeed: 100
speed_factor: 11
railway: "rail;light_rail;tram"
- name: tgv_all
railway: rail
electrified: contact_line
voltages: 15000;25000;1500;3000
frequencies: 16.7;16.67;50;0
gauges: 1435
maxspeed: 319
speed_factor: 11
- name: non_tgv
gauges: 1435
maxspeed: 120
speed_factor: 5
- name: alltracks
railway: rail;light_rail;tram;subway;narrow_gauge
maxspeed: 120
speed_factor: 5
- name: allelectric
maxspeed: 140
speed_factor: 5
electrified: contact_line,yes
#flagEncoderProperties:
# - name: tramtrain
# electrified: contact_line
# voltages: 15000;15000;750
# frequencies: 16.7;16.67;0
# gauges: 1435
# maxspeed: 100
# speed_factor: 11
# railway: "rail;light_rail;tram"
# - name: tgv_all
# railway: rail
# electrified: contact_line
# voltages: 15000;25000;1500;3000
# frequencies: 16.7;16.67;50;0
# gauges: 1435
# maxspeed: 319
# speed_factor: 11
# - name: non_tgv
# gauges: 1435
# maxspeed: 120
# speed_factor: 5
# - name: alltracks
# railway: rail;light_rail;tram;subway;narrow_gauge
# maxspeed: 120
# speed_factor: 5
# - name: allelectric
# maxspeed: 140
# speed_factor: 5
# electrified: contact_line,yes

graphhopper:
import.osm.ignored_highways: ''
Expand All @@ -36,9 +36,6 @@ graphhopper:

##### Vehicles #####

# # This property determines which flag encoders are enabled. You can use the hardcoded flag encoder configurations
# # or any of the encoders defined with flagEncoderProperties
# graph.flag_encoders: tgv_all|turn_costs=true|u_turn_costs=300,tramtrain|turn_costs=true|u_turn_costs=300

##### Routing Profiles ####

Expand All @@ -48,12 +45,12 @@ graphhopper:
#
# In general a profile consists of the following
# - name (required): a unique string identifier for the profile
# - vehicle (required): refers to the `graph.vehicles` used for this profile
# - weighting (required): the weighting used for this profile like custom
# - turn_costs (true/false, default: false): whether or not turn restrictions should be applied for this profile.
# - weighting (optional): by default 'custom'
# - turn_costs (optional):
# vehicle_types: [motorcar, motor_vehicle] (vehicle types used for vehicle-specific turn restrictions)
# u_turn_costs: 60 (time-penalty for doing a u-turn in seconds)
#
# Depending on the above fields there are other properties that can be used, e.g.
# - u_turn_costs: 60 (time-penalty for doing a u-turn in seconds (only possible when `turn_costs: true`)).
# - custom_model_files: when you specified "weighting: custom" you need to set one or more json files which are searched in
# custom_models.directory or the working directory that defines the custom_model. If you want an empty model you can
# set "custom_model_files: []
Expand All @@ -64,38 +61,35 @@ graphhopper:

profiles:
- name: tgv_all
vehicle: tgv_all
custom_model:
distance_influence: 0.0
speed:
- if: true
limit_to: 310
turn_costs: true
u_turn_costs: 300
- name: tramtrain
vehicle: tramtrain
custom_model:
distance_influence: 0.0
speed:
# Limit speed of this profile to 100 kph
- if: true
limit_to: 100
turn_costs: true
u_turn_costs: 300
turn_costs:
vehicle_types: [train]
u_turn_costs: 300
custom_model_files: [rail.json, tgv_all.json]
# - name: tramtrain
# custom_model:
# distance_influence: 0.0
# speed:
# # Limit speed of this profile to 100 kph
# - if: true
# limit_to: 100
# turn_costs:
# vehicle_types: []
# u_turn_costs: 300
# custom_model_files: [tramtrain.json]

# instead of the inbuilt custom models (see ./core/src/main/resources/com/graphhopper/custom_models)
# you can specify a folder where to find your own custom model files
# custom_models.directory: custom_models

# Speed mode:
# Its possible to speed up routing by doing a special graph preparation (Contraction Hierarchies, CH). This requires
# It's possible to speed up routing by doing a special graph preparation (Contraction Hierarchies, CH). This requires
# more RAM/disk space for holding the prepared graph but also means less memory usage per request. Using the following
# list you can define for which of the above routing profiles such preparation shall be performed. Note that to support
# profiles with `turn_costs: true` a more elaborate preparation is required (longer preparation time and more memory
# usage) and the routing will also be slower than with `turn_costs: false`.
profiles_ch:
- profile: tgv_all
- profile: tramtrain
# - profile: tramtrain

# Hybrid mode:
# Similar to speed mode, the hybrid mode (Landmarks, LM) also speeds up routing by doing calculating auxiliary data
Expand All @@ -109,23 +103,15 @@ graphhopper:
profiles_lm: []


#### Vehicles ####

# The vehicle defines the base for how the routing of a profile behaves. It can be adjusted with the turn_costs=true
# option or, only for the roads vehicle, there is the transportation_mode option:
# name=mycustomvehicle,turn_costs=true,transportation_mode=MOTOR_VEHICLE
# But you should prefer to configure the turn_costs via the profile configuration.
# Other standard vehicles: foot,bike,mtb,racingbike,wheelchair


#### Encoded Values ####

# Add additional information to every edge. Used for path details (#1548) and custom models (docs/core/custom-models.md)
# Default values are: road_class,road_class_link,road_environment,max_speed,road_access
# More are: surface,smoothness,max_width,max_height,max_weight,max_weight_except,hgv,max_axle_load,max_length,
# hazmat,hazmat_tunnel,hazmat_water,lanes,osm_way_id,toll,track_type,mtb_rating,hike_rating,horse_rating,
# country,curvature,average_slope,max_slope
# graph.encoded_values: surface,toll,track_type
# country,curvature,average_slope,max_slope,car_temporal_access,bike_temporal_access,foot_temporal_access
# For railway routing, the encoded values rail_access and rail_average_speed must be mentioned.
graph.encoded_values: gauge,road_environment,max_speed,rail_access,rail_average_speed

#### Speed, hybrid and flexible mode ####

Expand Down Expand Up @@ -175,45 +161,44 @@ graphhopper:
# graph.elevation.way_point_max_distance: 10


#### Country-dependent defaults for max speeds ####
#### Country-dependent defaults for max speeds ####

# This features sets a maximum speed in 'max_speed' encoded value if no maxspeed tag was found. It is country-dependent
# and based on several rules. See https://github.com/westnordost/osm-legal-default-speeds
# To use it uncomment the following, then enable urban density below and add 'country' to graph.encoded_values
# max_speed_calculator.enabled: true
# This features sets a maximum speed in 'max_speed' encoded value if no maxspeed tag was found. It is country-dependent
# and based on several rules. See https://github.com/westnordost/osm-legal-default-speeds
# To use it uncomment the following, then enable urban density below and add 'country' to graph.encoded_values
# max_speed_calculator.enabled: true


#### Urban density (built-up areas) ####
#### Urban density (built-up areas) ####

# This feature allows classifying roads into 'rural', 'residential' and 'city' areas (encoded value 'urban_density')
# Use 1 or more threads to enable the feature
# graph.urban_density.threads: 8
# Use higher/lower sensitivities if too little/many roads fall into the according categories.
# Using smaller radii will speed up the classification, but only change these values if you know what you are doing.
# If you do not need the (rather slow) city classification set city_radius to zero.
# graph.urban_density.residential_radius: 400
# graph.urban_density.residential_sensitivity: 6000
# graph.urban_density.city_radius: 1500
# graph.urban_density.city_sensitivity: 1000
# This feature allows classifying roads into 'rural', 'residential' and 'city' areas (encoded value 'urban_density')
# Use 1 or more threads to enable the feature
# graph.urban_density.threads: 8
# Use higher/lower sensitivities if too little/many roads fall into the according categories.
# Using smaller radii will speed up the classification, but only change these values if you know what you are doing.
# If you do not need the (rather slow) city classification set city_radius to zero.
# graph.urban_density.residential_radius: 400
# graph.urban_density.residential_sensitivity: 6000
# graph.urban_density.city_radius: 1500
# graph.urban_density.city_sensitivity: 1000


#### Subnetworks ####
#### Subnetworks ####

# In many cases the road network consists of independent components without any routes going in between. In
# the most simple case you can imagine an island without a bridge or ferry connection. The following parameter
# allows setting a minimum size (number of edges) for such detached components. This can be used to reduce the number
# of cases where a connection between locations might not be found.
# In many cases the road network consists of independent components without any routes going in between. In
# the most simple case you can imagine an island without a bridge or ferry connection. The following parameter
# allows setting a minimum size (number of edges) for such detached components. This can be used to reduce the number
# of cases where a connection between locations might not be found.
prepare.min_network_size: 200
prepare.subnetworks.threads: 1

#### Routing ####

#### Routing ####
# You can define the maximum visited nodes when routing. This may result in not found connections if there is no
# connection between two points within the given visited nodes. The default is Integer.MAX_VALUE. Useful for flexibility mode
# routing.max_visited_nodes: 1000000

# You can define the maximum visited nodes when routing. This may result in not found connections if there is no
# connection between two points within the given visited nodes. The default is Integer.MAX_VALUE. Useful for flexibility mode
# routing.max_visited_nodes: 1000000

# The maximum time in milliseconds after which a routing request will be aborted. This has some routing algorithm
# The maximum time in milliseconds after which a routing request will be aborted. This has some routing algorithm
# specific caveats, but generally it should allow the prevention of long-running requests. The default is Long.MAX_VALUE
# routing.timeout_ms: 300000

Expand All @@ -225,7 +210,7 @@ graphhopper:
routing.non_ch.max_waypoint_distance: 1000000


##### Storage #####
#### Storage ####

# Excludes certain types of highways during the OSM import to speed up the process and reduce the size of the graph.
# A typical application is excluding 'footway','cycleway','path' and maybe 'pedestrian' and 'track' highways for
Expand All @@ -241,14 +226,10 @@ graphhopper:
# will write way names in the preferred language (language code as defined in ISO 639-1 or ISO 639-2):
# datareader.preferred_language: en

# Sort the graph after import to make requests roughly ~10% faster. Note that this requires significantly more RAM on import.
# graph.do_sort: true


#### Custom Areas ####

# GraphHopper reads GeoJSON polygon files including their properties from this directory and makes them available
# to all tag parsers, vehicles and custom models. All GeoJSON Features require to have the "id" property.
# to all tag parsers and custom models. All GeoJSON Features require to have the "id" property.
# Country borders are included automatically (see countries.geojson).
# custom_areas.directory: path/to/custom_areas

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.graphhopper.routing.util.TransportationMode;
import com.graphhopper.routing.util.WayAccess;
import com.graphhopper.routing.util.parsers.AbstractAccessParser;
import com.graphhopper.storage.IntsRef;
import com.graphhopper.routing.ev.BooleanEncodedValue;
import com.graphhopper.routing.ev.EdgeIntAccess;
import com.graphhopper.util.PMap;
Expand Down
39 changes: 30 additions & 9 deletions src/main/java/de/geofabrik/railway_routing/RailImportRegistry.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
package de.geofabrik.railway_routing;

import java.util.List;
import java.util.Map;

import com.graphhopper.routing.ev.DecimalEncodedValueImpl;
import com.graphhopper.routing.ev.FerrySpeed;
import com.graphhopper.routing.ev.ImportRegistry;
import com.graphhopper.routing.ev.ImportUnit;
import com.graphhopper.routing.ev.Lanes;
import com.graphhopper.routing.ev.MaxSpeed;
import com.graphhopper.routing.ev.OSMWayID;
import com.graphhopper.routing.ev.RoadClass;
import com.graphhopper.routing.ev.RoadClassLink;
import com.graphhopper.routing.ev.RoadEnvironment;
import com.graphhopper.routing.ev.Roundabout;
import com.graphhopper.routing.ev.VehicleAccess;
import com.graphhopper.routing.ev.VehicleSpeed;
import com.graphhopper.routing.util.FerrySpeedCalculator;
import com.graphhopper.routing.util.parsers.OSMMaxSpeedParser;
import com.graphhopper.routing.util.parsers.OSMRoadClassLinkParser;
import com.graphhopper.routing.util.parsers.OSMRoadClassParser;
import com.graphhopper.routing.util.parsers.OSMRoadEnvironmentParser;
import com.graphhopper.routing.util.parsers.OSMRoundaboutParser;
import com.graphhopper.routing.util.parsers.OSMWayIDParser;
import com.graphhopper.util.PMap;

import de.geofabrik.railway_routing.http.FlagEncoderConfiguration;
import de.geofabrik.railway_routing.ev.Gauge;
import de.geofabrik.railway_routing.parsers.OSMGaugeParser;

public class RailImportRegistry implements ImportRegistry {

private Map<String, PMap> flagEncoderProperties;

public RailImportRegistry(List<FlagEncoderConfiguration> encoderConfigs) {
flagEncoderProperties = FlagEncoderConfiguration.toPMaps(encoderConfigs);
public RailImportRegistry() {
}

@Override
Expand All @@ -35,11 +36,31 @@ public ImportUnit createImportUnit(String name) {
(lookup, props) -> new OSMRoadEnvironmentParser(
lookup.getEnumEncodedValue(RoadEnvironment.KEY, RoadEnvironment.class))
);
else if (Roundabout.KEY.equals(name))
return ImportUnit.create(name, props -> Roundabout.create(),
(lookup, props) -> new OSMRoundaboutParser(
lookup.getBooleanEncodedValue(Roundabout.KEY))
);
else if (RoadClass.KEY.equals(name))
return ImportUnit.create(name, props -> RoadClass.create(),
(lookup, props) -> new OSMRoadClassParser(
lookup.getEnumEncodedValue(RoadClass.KEY, RoadClass.class))
);
else if (RoadClassLink.KEY.equals(name))
return ImportUnit.create(name, props -> RoadClassLink.create(),
(lookup, props) -> new OSMRoadClassLinkParser(
lookup.getBooleanEncodedValue(RoadClassLink.KEY))
);
else if (MaxSpeed.KEY.equals(name))
return ImportUnit.create(name, props -> MaxSpeed.create(),
(lookup, props) -> new OSMMaxSpeedParser(
lookup.getDecimalEncodedValue(MaxSpeed.KEY))
);
else if (Gauge.KEY.equals(name))
return ImportUnit.create(name, props -> Gauge.create(),
(lookup, props) -> new OSMGaugeParser(
lookup.getIntEncodedValue(Gauge.KEY))
);
else if (OSMWayID.KEY.equals(name))
return ImportUnit.create(name, props -> OSMWayID.create(),
(lookup, props) -> new OSMWayIDParser(
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/de/geofabrik/railway_routing/RailwayHopper.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
package de.geofabrik.railway_routing;

import java.util.List;

import com.graphhopper.GraphHopper;

import de.geofabrik.railway_routing.http.FlagEncoderConfiguration;
import de.geofabrik.railway_routing.reader.OSMRailwayReader;
import de.geofabrik.railway_routing.reader.RailwayOSMParsers;

public class RailwayHopper extends GraphHopper {

public RailwayHopper(List<FlagEncoderConfiguration> encoderConfigs) {
public RailwayHopper() {
super();
setImportRegistry(new RailImportRegistry(encoderConfigs));
setImportRegistry(new RailImportRegistry());
setOsmParsersSupplier(RailwayOSMParsers::new);
setOsmReaderSupplier((baseGraph, osmParsers, config) -> new OSMRailwayReader(baseGraph, osmParsers, config));
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/de/geofabrik/railway_routing/ev/Gauge.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package de.geofabrik.railway_routing.ev;

import com.graphhopper.routing.ev.IntEncodedValue;
import com.graphhopper.routing.ev.IntEncodedValueImpl;

public class Gauge {
public static final String KEY = "gauge";

public static IntEncodedValue create() {
return new IntEncodedValueImpl(KEY, 11, false);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,7 @@ protected void run(Bootstrap<RailwayRoutingServerConfiguration> bootstrap, Names
if (output != null) {
configuration.getGraphHopperConfiguration().putObject("graph.location", output);
}
final RailwayRoutingManaged graphHopper = new RailwayRoutingManaged(configuration.getGraphHopperConfiguration(),
configuration.getFlagEncoderConfigurations());
final RailwayRoutingManaged graphHopper = new RailwayRoutingManaged(configuration.getGraphHopperConfiguration());
graphHopper.getGraphHopper().importAndClose();
}
}
Loading

0 comments on commit 852443b

Please sign in to comment.