Skip to content

Commit

Permalink
Merge pull request #906 from GIScience/bugfix#905-concurrency_issue_w…
Browse files Browse the repository at this point in the history
…ith_core_edge_filters

Create separate core edge filter instances for each weighting
  • Loading branch information
takb authored Apr 21, 2021
2 parents 5c07e17 + a49fe1f commit 4468efc
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 57 deletions.
7 changes: 3 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,11 @@ RELEASING:
### Changed
- app.config.sample HGV profile has now same settings regarding speed calculation as public API ([#806](https://github.com/GIScience/openrouteservice/issues/806))
### Fixed
- Fixed isochrones algorithm selection for location_type parameter ([#676](https://github.com/GIScience/openrouteservice/issues/676)
- Updated link to client translations in readme
- Concurrency bug in core edge filters which caused crashes during CALT graph preparation ([#905](https://github.com/GIScience/openrouteservice/issues/905))
- Fixed isochrones range documentation ([#882](https://github.com/GIScience/openrouteservice/issues/676))

### Fixed
- Updated installation instructions and usage to reflect v2 api ([#744](https://github.com/GIScience/openrouteservice/issues/744))
- Fixed isochrones algorithm selection for location_type parameter ([#676](https://github.com/GIScience/openrouteservice/issues/676))
- Updated link to client translations in readme

## [6.4.1] - 2021-03-31
### Fixed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,14 +51,11 @@
import org.heigit.ors.routing.AvoidFeatureFlags;
import org.heigit.ors.routing.RouteSearchContext;
import org.heigit.ors.routing.RouteSearchParameters;
import org.heigit.ors.routing.RoutingProfileCategory;
import org.heigit.ors.routing.graphhopper.extensions.core.CoreAlgoFactoryDecorator;
import org.heigit.ors.routing.graphhopper.extensions.core.CoreLMAlgoFactoryDecorator;
import org.heigit.ors.routing.graphhopper.extensions.core.PrepareCore;
import org.heigit.ors.routing.graphhopper.extensions.edgefilters.AvoidFeaturesEdgeFilter;
import org.heigit.ors.routing.graphhopper.extensions.edgefilters.EdgeFilterSequence;
import org.heigit.ors.routing.graphhopper.extensions.edgefilters.core.*;
import org.heigit.ors.routing.graphhopper.extensions.flagencoders.FlagEncoderNames;
import org.heigit.ors.routing.graphhopper.extensions.storages.BordersGraphStorage;
import org.heigit.ors.routing.graphhopper.extensions.storages.GraphStorageUtils;
import org.heigit.ors.routing.graphhopper.extensions.util.ORSPMap;
Expand Down Expand Up @@ -605,54 +602,9 @@ public void postProcessing() {

GraphHopperStorage gs = getGraphHopperStorage();

EncodingManager encodingManager = getEncodingManager();

int routingProfileCategory = RoutingProfileCategory.getFromEncoder(encodingManager);

/* Initialize edge filter sequence */

EdgeFilterSequence coreEdgeFilter = new EdgeFilterSequence();
/* Heavy vehicle filter */

if (encodingManager.hasEncoder(FlagEncoderNames.HEAVYVEHICLE)) {
coreEdgeFilter.add(new HeavyVehicleCoreEdgeFilter(gs));
}

/* Avoid features */

if ((routingProfileCategory & (RoutingProfileCategory.DRIVING | RoutingProfileCategory.CYCLING | RoutingProfileCategory.WALKING | RoutingProfileCategory.WHEELCHAIR)) != 0) {
coreEdgeFilter.add(new AvoidFeaturesCoreEdgeFilter(gs, routingProfileCategory));
}

/* Avoid borders of some form */

if ((routingProfileCategory & (RoutingProfileCategory.DRIVING | RoutingProfileCategory.CYCLING)) != 0) {
coreEdgeFilter.add(new AvoidBordersCoreEdgeFilter(gs));
}

if (routingProfileCategory == RoutingProfileCategory.WHEELCHAIR) {
coreEdgeFilter.add(new WheelchairCoreEdgeFilter(gs));
}

/* Maximum Speed Filter & Turn Restrictions */
if ((routingProfileCategory & RoutingProfileCategory.DRIVING) !=0 ) {
String[] encoders = {FlagEncoderNames.CAR_ORS, FlagEncoderNames.HEAVYVEHICLE};
for (String encoderName: encoders) {
if (encodingManager.hasEncoder(encoderName)) {
FlagEncoder flagEncoder = getEncodingManager().getEncoder(encoderName);
coreEdgeFilter.add(new MaximumSpeedCoreEdgeFilter(flagEncoder, maximumSpeedLowerBound));
if (flagEncoder.supports(TurnWeighting.class))
coreEdgeFilter.add(new TurnRestrictionsCoreEdgeFilter(flagEncoder, gs));
break;
}
}
}

/* End filter sequence initialization */

//Create the core
if(coreFactoryDecorator.isEnabled())
coreFactoryDecorator.createPreparations(gs, coreEdgeFilter);
coreFactoryDecorator.createPreparations(gs, processContext);
if (!isCorePrepared())
prepareCore();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,19 @@
import com.graphhopper.routing.RoutingAlgorithmFactory;
import com.graphhopper.routing.RoutingAlgorithmFactoryDecorator;
import com.graphhopper.routing.util.EdgeFilter;
import com.graphhopper.routing.util.EncodingManager;
import com.graphhopper.routing.util.FlagEncoder;
import com.graphhopper.routing.util.HintsMap;
import com.graphhopper.routing.weighting.AbstractWeighting;
import com.graphhopper.routing.weighting.TurnWeighting;
import com.graphhopper.storage.*;
import com.graphhopper.util.CmdArgs;
import com.graphhopper.util.Helper;
import org.heigit.ors.routing.RoutingProfileCategory;
import org.heigit.ors.routing.graphhopper.extensions.GraphProcessContext;
import org.heigit.ors.routing.graphhopper.extensions.edgefilters.EdgeFilterSequence;
import org.heigit.ors.routing.graphhopper.extensions.edgefilters.core.*;
import org.heigit.ors.routing.graphhopper.extensions.flagencoders.FlagEncoderNames;
import org.heigit.ors.routing.graphhopper.extensions.util.ORSParameters.Core;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -307,16 +315,17 @@ public void prepare(final StorableProperties properties) {
}
}

public void createPreparations(GraphHopperStorage ghStorage, EdgeFilter restrictionFilter) {
public void createPreparations(GraphHopperStorage ghStorage, GraphProcessContext processContext) {
if (!isEnabled() || !preparations.isEmpty())
return;
if (!hasCHProfiles())
throw new IllegalStateException("No profiles found");

for (CHProfile chProfile : chProfiles) {
addPreparation(createCHPreparation(ghStorage, chProfile, restrictionFilter));
addPreparation(createCHPreparation(ghStorage, chProfile, createCoreEdgeFilter(ghStorage, processContext)));
}
}

private PrepareCore createCHPreparation(GraphHopperStorage ghStorage, CHProfile chProfile, EdgeFilter restrictionFilter) {
PrepareCore tmpPrepareCore = new PrepareCore(
new GHDirectory("", DAType.RAM_INT), ghStorage, ghStorage.getCHGraph(chProfile), restrictionFilter);
Expand All @@ -326,4 +335,49 @@ private PrepareCore createCHPreparation(GraphHopperStorage ghStorage, CHProfile
setLogMessages(preparationLogMessages);
return tmpPrepareCore;
}

private EdgeFilter createCoreEdgeFilter(GraphHopperStorage gs, GraphProcessContext processContext) {
EncodingManager encodingManager = gs.getEncodingManager();

int routingProfileCategory = RoutingProfileCategory.getFromEncoder(encodingManager);

/* Initialize edge filter sequence */
EdgeFilterSequence edgeFilterSequence = new EdgeFilterSequence();

/* Heavy vehicle filter */
if (encodingManager.hasEncoder(FlagEncoderNames.HEAVYVEHICLE)) {
edgeFilterSequence.add(new HeavyVehicleCoreEdgeFilter(gs));
}

/* Avoid features */
if ((routingProfileCategory & (RoutingProfileCategory.DRIVING | RoutingProfileCategory.CYCLING | RoutingProfileCategory.WALKING | RoutingProfileCategory.WHEELCHAIR)) != 0) {
edgeFilterSequence.add(new AvoidFeaturesCoreEdgeFilter(gs, routingProfileCategory));
}

/* Avoid borders */
if ((routingProfileCategory & (RoutingProfileCategory.DRIVING | RoutingProfileCategory.CYCLING)) != 0) {
edgeFilterSequence.add(new AvoidBordersCoreEdgeFilter(gs));
}

if (routingProfileCategory == RoutingProfileCategory.WHEELCHAIR) {
edgeFilterSequence.add(new WheelchairCoreEdgeFilter(gs));
}

/* Maximum speed & turn restrictions */
if ((routingProfileCategory & RoutingProfileCategory.DRIVING) !=0) {
String[] encoders = {FlagEncoderNames.CAR_ORS, FlagEncoderNames.HEAVYVEHICLE};
for (String encoderName: encoders) {
if (encodingManager.hasEncoder(encoderName)) {
FlagEncoder flagEncoder = encodingManager.getEncoder(encoderName);
edgeFilterSequence.add(new MaximumSpeedCoreEdgeFilter(flagEncoder, processContext.getMaximumSpeedLowerBound()));
if (flagEncoder.supports(TurnWeighting.class))
edgeFilterSequence.add(new TurnRestrictionsCoreEdgeFilter(flagEncoder, gs));
break;
}
}
}

return edgeFilterSequence;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ public class PrepareCore extends AbstractAlgoPreparation implements RoutingAlgor
private static final Logger LOGGER = Logger.getLogger(PrepareCore.class);
private final CHProfile chProfile;
private final PreparationWeighting prepareWeighting;
private final TraversalMode traversalMode;
private final EdgeFilter restrictionFilter;
private final GraphHopperStorage ghStorage;
private final CHGraphImpl prepareGraph;
Expand Down Expand Up @@ -85,7 +84,6 @@ public PrepareCore(Directory dir, GraphHopperStorage ghStorage, CHGraph chGraph,
this.ghStorage = ghStorage;
this.prepareGraph = (CHGraphImpl) chGraph;
this.chProfile = chGraph.getCHProfile();
this.traversalMode = chProfile.getTraversalMode();
this.weighting = chProfile.getWeighting();
this.flagEncoder = weighting.getFlagEncoder();
this.restrictionFilter = restrictionFilter;
Expand Down

0 comments on commit 4468efc

Please sign in to comment.