Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduces under_score notation for all properties, fixes #682 #719

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 9 additions & 9 deletions config-example.properties
Expand Up @@ -2,11 +2,11 @@

# Possible options: car,foot,bike,bike2,mtb,racingbike,motorcycle (comma separated)
# bike2 takes elevation data into account (like up-hill is slower than down-hill) and requires enabling graph.elevation.provider below
graph.flagEncoders=car
graph.flag_encoders=car

# Enable turn restrictions for car or motorcycle.
# Currently you need to additionally set prepare.chWeightings=no before using this (see below and #270)
# graph.flagEncoders=car|turnCosts=true
# graph.flag_encoders=car|turn_costs=true



Expand All @@ -16,7 +16,7 @@ graph.flagEncoders=car
# graph.elevation.provider=srtm

# default location for cache is /tmp/srtm
# graph.elevation.cachedir=./srtmprovider/
# graph.elevation.cache_dir=./srtmprovider/

# If you have a slow disk or plenty of RAM change the default MMAP to:
# graph.elevation.dataaccess=RAM_STORE
Expand All @@ -28,10 +28,10 @@ graph.flagEncoders=car
# By default the speed-up mode with the 'fastest' weighting is used. Internally a graph preparation via
# contraction hierarchies (CH) is done to speed routing up. This requires more RAM/disc space for holding the
# graph but less for every request. You can also setup multiple weightings, by providing a coma separated list.
prepare.chWeightings=fastest
prepare.ch.weightings=fastest

# Disable the speed-up mode. Should be use only with routing.maxVisitedNodes
# prepare.chWeightings=no
# prepare.ch.weightings=no

# To make preparation faster for multiple flagEncoders you can increase the default threads if you have enough RAM.
# Change this setting only if you know what you are doing and if the default worked for you and really make sure you have enough RAM!
Expand All @@ -43,19 +43,19 @@ prepare.chWeightings=fastest

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

# If enabled, allows a user to run flexibility requests even if speed-up mode is enabled. Every request then has to include a hint routing.flexibleMode.force=true.
# Attention, non-CH route calculations take way more time and resources, compared to CH routing.
# A possible attacker might exploit this to slow down your service. Only enable it if you need it and with routing.maxVisitedNodes
# routing.flexibleMode.allowed=true
# routing.ch.disabling_allowed=true



##### Web #####

# if you want to support jsonp response type you need to add it explicitely here. By default it is disabled for stronger security.
# web.jsonpAllowed=true
# web.jsonp_allowed=true



Expand All @@ -68,4 +68,4 @@ graph.dataaccess=RAM_STORE
# osmreader.instructions=false

# will write way names in the preferred language (language code as defined in ISO 639-1 or ISO 639-2):
# osmreader.preferred-language=en
# osmreader.preferred_language=en
4 changes: 3 additions & 1 deletion core/files/changelog.txt
@@ -1,4 +1,6 @@
0.7
0.7
several constants changed to under score notation see #719 with a few breaking changes
moving all string parameter constants into the Parameters class
no more acceptedRailways set see #662 for more information
web API: content type of gpx export is now application/gpx+xml if not explicitely specified
use prepare.chWeightings instead of prepare.chWeighting e.g. for disabling CH use prepare.chWeightings=no
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/com/graphhopper/GHRequest.java
Expand Up @@ -205,7 +205,7 @@ public List<GHPoint> getPoints()
public GHRequest setAlgorithm( String algo )
{
if (algo != null)
this.algo = algo;
this.algo = Helper.camelCaseToUnderScore(algo);
return this;
}

Expand Down
72 changes: 43 additions & 29 deletions core/src/main/java/com/graphhopper/GraphHopper.java
Expand Up @@ -35,6 +35,9 @@
import com.graphhopper.storage.index.LocationIndexTree;
import com.graphhopper.storage.index.QueryResult;
import com.graphhopper.util.*;
import static com.graphhopper.util.Parameters.Algorithms.*;
import com.graphhopper.util.Parameters.CH;
import com.graphhopper.util.Parameters.Routing;
import com.graphhopper.util.shapes.GHPoint;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -591,15 +594,15 @@ public GraphHopper init( CmdArgs args )

// graph
setGraphHopperLocation(graphHopperFolder);
defaultSegmentSize = args.getInt("graph.dataaccess.segmentSize", defaultSegmentSize);
defaultSegmentSize = args.getInt("graph.dataaccess.segment_size", defaultSegmentSize);

String graphDATypeStr = args.get("graph.dataaccess", "RAM_STORE");
dataAccessType = DAType.fromString(graphDATypeStr);

sortGraph = args.getBool("graph.doSort", sortGraph);
removeZipped = args.getBool("graph.removeZipped", removeZipped);
int bytesForFlags = args.getInt("graph.bytesForFlags", 4);
String flagEncoders = args.get("graph.flagEncoders", "");
sortGraph = args.getBool("graph.do_sort", sortGraph);
removeZipped = args.getBool("graph.remove_zipped", removeZipped);
int bytesForFlags = args.getInt("graph.bytes_for_flags", 4);
String flagEncoders = args.get("graph.flag_encoders", "");
if (!flagEncoders.isEmpty())
setEncodingManager(new EncodingManager(flagEncoders, bytesForFlags));

Expand All @@ -610,9 +613,20 @@ public GraphHopper init( CmdArgs args )

// elevation
String eleProviderStr = args.get("graph.elevation.provider", "noop").toLowerCase();
boolean eleCalcMean = args.getBool("graph.elevation.calcmean", false);
String cacheDirStr = args.get("graph.elevation.cachedir", "");
String baseURL = args.get("graph.elevation.baseurl", "");

// keep fallback until 0.8
boolean eleCalcMean = args.has("graph.elevation.calcmean")
? args.getBool("graph.elevation.calcmean", false)
: args.getBool("graph.elevation.calc_mean", false);

String cacheDirStr = args.get("graph.elevation.cache_dir", "");
if (cacheDirStr.isEmpty())
cacheDirStr = args.get("graph.elevation.cachedir", "");

String baseURL = args.get("graph.elevation.base_url", "");
if (baseURL.isEmpty())
args.get("graph.elevation.baseurl", "");

DAType elevationDAType = DAType.fromString(args.get("graph.elevation.dataaccess", "MMAP"));
ElevationProvider tmpProvider = ElevationProvider.NOOP;
if (eleProviderStr.equalsIgnoreCase("srtm"))
Expand All @@ -633,26 +647,26 @@ public GraphHopper init( CmdArgs args )
setElevationProvider(tmpProvider);

// optimizable prepare
minNetworkSize = args.getInt("prepare.minNetworkSize", minNetworkSize);
minOneWayNetworkSize = args.getInt("prepare.minOneWayNetworkSize", minOneWayNetworkSize);
minNetworkSize = args.getInt("prepare.min_network_size", minNetworkSize);
minOneWayNetworkSize = args.getInt("prepare.min_one_way_network_size", minOneWayNetworkSize);

// prepare CH
chFactoryDecorator.init(args);

// osm import
osmReaderWayPointMaxDistance = args.getDouble("osmreader.wayPointMaxDistance", osmReaderWayPointMaxDistance);
osmReaderWayPointMaxDistance = args.getDouble(Routing.INIT_WAY_POINT_MAX_DISTANCE, osmReaderWayPointMaxDistance);

workerThreads = args.getInt("osmreader.workerThreads", workerThreads);
workerThreads = args.getInt("osmreader.worker_threads", workerThreads);
enableInstructions = args.getBool("osmreader.instructions", enableInstructions);
preferredLanguage = args.get("osmreader.preferred-language", preferredLanguage);
preferredLanguage = args.get("osmreader.preferred_language", preferredLanguage);

// index
preciseIndexResolution = args.getInt("index.highResolution", preciseIndexResolution);
maxRegionSearch = args.getInt("index.maxRegionSearch", maxRegionSearch);
preciseIndexResolution = args.getInt("index.high_resolution", preciseIndexResolution);
maxRegionSearch = args.getInt("index.max_region_search", maxRegionSearch);

// routing
maxVisitedNodes = args.getInt("routing.maxVisitedNodes", Integer.MAX_VALUE);
maxRoundTripRetries = args.getInt("routing.roundTrip.maxRetries", maxRoundTripRetries);
maxVisitedNodes = args.getInt(Routing.INIT_MAX_VISITED_NODES, Integer.MAX_VALUE);
maxRoundTripRetries = args.getInt(RoundTrip.INIT_MAX_RETRIES, maxRoundTripRetries);

return this;
}
Expand Down Expand Up @@ -1012,7 +1026,7 @@ protected List<Path> calcPaths( GHRequest request, GHResponse ghRsp )
}

TraversalMode tMode;
String tModeStr = request.getHints().get("traversal_mode", traversalMode.toString());
String tModeStr = request.getHints().get(Routing.TRAVERSAL_MODE, traversalMode.toString());
try
{
tMode = TraversalMode.fromString(tModeStr);
Expand All @@ -1023,13 +1037,13 @@ protected List<Path> calcPaths( GHRequest request, GHResponse ghRsp )
}

FlagEncoder encoder = encodingManager.getEncoder(vehicle);
List<GHPoint> points = request.getPoints();
String algoStr = request.getAlgorithm().isEmpty() ? AlgorithmOptions.DIJKSTRA_BI : request.getAlgorithm();
List<GHPoint> points = request.getPoints();
String algoStr = request.getAlgorithm().isEmpty() ? DIJKSTRA_BI : request.getAlgorithm();

RoutingTemplate routingTemplate;
if (AlgorithmOptions.ROUND_TRIP.equalsIgnoreCase(algoStr))
if (ROUND_TRIP.equalsIgnoreCase(algoStr))
routingTemplate = new RoundTripRoutingTemplate(request, ghRsp, locationIndex, maxRoundTripRetries);
else if (AlgorithmOptions.ALT_ROUTE.equalsIgnoreCase(algoStr))
else if (ALT_ROUTE.equalsIgnoreCase(algoStr))
routingTemplate = new AlternativeRoutingTemplate(request, ghRsp, locationIndex);
else
routingTemplate = new ViaRoutingTemplate(request, ghRsp, locationIndex);
Expand All @@ -1050,7 +1064,7 @@ else if (AlgorithmOptions.ALT_ROUTE.equalsIgnoreCase(algoStr))
Weighting weighting;
Graph routingGraph = ghStorage;

boolean forceFlexibleMode = request.getHints().getBool(CHAlgoFactoryDecorator.DISABLE, false);
boolean forceFlexibleMode = request.getHints().getBool(CH.DISABLE, false);
if (!chFactoryDecorator.isDisablingAllowed() && forceFlexibleMode)
{
ghRsp.addError(new IllegalStateException("Flexible mode not enabled on the server-side"));
Expand All @@ -1059,7 +1073,7 @@ else if (AlgorithmOptions.ALT_ROUTE.equalsIgnoreCase(algoStr))

if (chFactoryDecorator.isEnabled() && !forceFlexibleMode)
{
boolean forceCHHeading = request.getHints().getBool(CHAlgoFactoryDecorator.FORCE_HEADING, false);
boolean forceCHHeading = request.getHints().getBool(CH.FORCE_HEADING, false);
if (!forceCHHeading && request.hasFavoredHeading(0))
throw new IllegalStateException("Heading is not (fully) supported for CHGraph. See issue #483");

Expand All @@ -1075,10 +1089,10 @@ else if (AlgorithmOptions.ALT_ROUTE.equalsIgnoreCase(algoStr))
queryGraph.lookup(qResults);
weighting = createTurnWeighting(weighting, queryGraph, encoder);

int maxVisitedNodesForRequest = request.getHints().getInt("routing.maxVisitedNodes", maxVisitedNodes);
int maxVisitedNodesForRequest = request.getHints().getInt(Routing.MAX_VISITED_NODES, maxVisitedNodes);
if (maxVisitedNodesForRequest > maxVisitedNodes)
{
ghRsp.addError(new IllegalStateException("The routing.maxVisitedNodes parameter has to be below or equal to:" + maxVisitedNodes));
ghRsp.addError(new IllegalStateException("The max_visited_nodes parameter has to be below or equal to:" + maxVisitedNodes));
return Collections.emptyList();
}

Expand All @@ -1089,9 +1103,9 @@ else if (AlgorithmOptions.ALT_ROUTE.equalsIgnoreCase(algoStr))
build();

altPaths = routingTemplate.calcPaths(queryGraph, tmpAlgoFactory, algoOpts);
boolean tmpEnableInstructions = request.getHints().getBool("instructions", enableInstructions);
boolean tmpCalcPoints = request.getHints().getBool("calcPoints", calcPoints);
double wayPointMaxDistance = request.getHints().getDouble("wayPointMaxDistance", 1d);
boolean tmpEnableInstructions = request.getHints().getBool(Routing.INSTRUCTIONS, enableInstructions);
boolean tmpCalcPoints = request.getHints().getBool(Routing.CALC_POINTS, calcPoints);
double wayPointMaxDistance = request.getHints().getDouble(Routing.WAY_POINT_MAX_DISTANCE, 1d);
DouglasPeucker peucker = new DouglasPeucker().setMaxDistance(wayPointMaxDistance);
PathMerger pathMerger = new PathMerger().
setCalcPoints(tmpCalcPoints).
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/com/graphhopper/coll/OSMIDMap.java
Expand Up @@ -47,9 +47,9 @@ public OSMIDMap( Directory dir, int noNumber )
{
this.dir = dir;
this.noEntryValue = noNumber;
keys = dir.find("osmidMapKeys");
keys = dir.find("osmid_map_keys");
keys.create(2000);
values = dir.find("osmidMapValues");
values = dir.find("osmid_map_values");
values.create(1000);
}

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/com/graphhopper/reader/PillarInfo.java
Expand Up @@ -40,7 +40,7 @@ public PillarInfo( boolean enabled3D, Directory dir )
{
this.enabled3D = enabled3D;
this.dir = dir;
this.da = dir.find("tmpPillarInfo").create(100);
this.da = dir.find("tmp_pillar_info").create(100);
this.rowSizeInBytes = getDimension() * 4;
}

Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/com/graphhopper/routing/AStar.java
Expand Up @@ -32,6 +32,7 @@
import com.graphhopper.storage.Graph;
import com.graphhopper.util.EdgeExplorer;
import com.graphhopper.util.EdgeIterator;
import com.graphhopper.util.Parameters;

/**
* This class implements the A* algorithm according to
Expand Down Expand Up @@ -199,6 +200,6 @@ public final double getWeightOfVisitedPath()
@Override
public String getName()
{
return AlgorithmOptions.ASTAR;
return Parameters.Algorithms.ASTAR;
}
}
Expand Up @@ -317,6 +317,6 @@ public void updateBestPath( EdgeIteratorState edgeState, AStarEntry entryCurrent
@Override
public String getName()
{
return AlgorithmOptions.ASTAR_BI;
return Parameters.Algorithms.ASTAR_BI;
}
}
31 changes: 2 additions & 29 deletions core/src/main/java/com/graphhopper/routing/AlgorithmOptions.java
Expand Up @@ -21,6 +21,7 @@
import com.graphhopper.routing.util.TraversalMode;
import com.graphhopper.routing.util.Weighting;
import com.graphhopper.util.PMap;
import com.graphhopper.util.Parameters;

/**
* The algorithm options. Create an immutable object via:
Expand All @@ -35,35 +36,7 @@
*/
public class AlgorithmOptions
{
/**
* Bidirectional Dijkstra
*/
public static final String DIJKSTRA_BI = "dijkstrabi";
/**
* Unidirectional Dijkstra
*/
public static final String DIJKSTRA = "dijkstra";
/**
* one to many Dijkstra
*/
public static final String DIJKSTRA_ONE_TO_MANY = "dijkstraOneToMany";
/**
* Unidirectional A*
*/
public static final String ASTAR = "astar";
/**
* Bidirectional A*
*/
public static final String ASTAR_BI = "astarbi";
/**
* alternative route algorithm
*/
public static final String ALT_ROUTE = "alternativeRoute";
/**
* round trip algorithm
*/
public static final String ROUND_TRIP = "roundTrip";
private String algorithm = DIJKSTRA_BI;
private String algorithm = Parameters.Algorithms.DIJKSTRA_BI;
private Weighting weighting;
private TraversalMode traversalMode = TraversalMode.NODE_BASED;
private FlagEncoder flagEncoder;
Expand Down
Expand Up @@ -18,7 +18,6 @@
package com.graphhopper.routing;

import com.graphhopper.routing.AStar.AStarEntry;
import static com.graphhopper.routing.AlgorithmOptions.ALT_ROUTE;
import com.graphhopper.routing.util.FlagEncoder;
import com.graphhopper.routing.util.TraversalMode;
import com.graphhopper.routing.util.Weighting;
Expand All @@ -27,6 +26,7 @@
import com.graphhopper.util.EdgeIterator;
import com.graphhopper.util.EdgeIteratorState;
import com.graphhopper.util.GHUtility;
import com.graphhopper.util.Parameters;
import gnu.trove.map.TIntObjectMap;
import gnu.trove.map.hash.TIntObjectHashMap;

Expand Down Expand Up @@ -188,7 +188,7 @@ public int compare( AlternativeInfo o1, AlternativeInfo o2 )
@Override
public String getName()
{
return ALT_ROUTE;
return Parameters.Algorithms.ALT_ROUTE;
}

@Override
Expand Down
3 changes: 2 additions & 1 deletion core/src/main/java/com/graphhopper/routing/Dijkstra.java
Expand Up @@ -29,6 +29,7 @@
import com.graphhopper.storage.Graph;
import com.graphhopper.util.EdgeExplorer;
import com.graphhopper.util.EdgeIterator;
import com.graphhopper.util.Parameters;

/**
* Implements a single source shortest path algorithm
Expand Down Expand Up @@ -144,6 +145,6 @@ public int getVisitedNodes()
@Override
public String getName()
{
return AlgorithmOptions.DIJKSTRA;
return Parameters.Algorithms.DIJKSTRA;
}
}
Expand Up @@ -27,10 +27,7 @@
import com.graphhopper.routing.util.Weighting;
import com.graphhopper.storage.SPTEntry;
import com.graphhopper.storage.Graph;
import com.graphhopper.util.EdgeExplorer;
import com.graphhopper.util.EdgeIterator;
import com.graphhopper.util.EdgeIteratorState;
import com.graphhopper.util.GHUtility;
import com.graphhopper.util.*;

/**
* Calculates best path in bidirectional way.
Expand Down Expand Up @@ -306,6 +303,6 @@ void setBestPath( PathBidirRef bestPath )
@Override
public String getName()
{
return AlgorithmOptions.DIJKSTRA_BI;
return Parameters.Algorithms.DIJKSTRA_BI;
}
}