Custom EdgeFilter for CH graph

Hi GraphHopper team,

I want to filter out some edges in routing with CH enabled. The edges to be filtered out can depend on request parameters. My solution works if I send ch.disabled=true along with the request but I cannot seem to make it work with CH enabled. Here is what I did so far-

Class 1 -> CustomEdgeFilter implements EdgeFilter
Class 2 -> CustomCHEdgeFilter implements CHEdgeFilter
Class 3 -> CustomWeightingDecorator implements Weighting
Class 4 -> CustomGraph extends QueryGraph

@Override
public EdgeExplorer createEdgeExplorer(EdgeFilter filter) {
    CustomEdgeFilter customEdgeFilter = new CustomEdgeFilter(filter, parameters);
    return super.createEdgeExplorer(customEdgeFilter);
}

@Override
public EdgeExplorer createEdgeExplorer() {
    return createEdgeExplorer(EdgeFilter.ALL_EDGES);
}

Class 5 -> CustomCHAlgoDecorator extends DijkstraBidirectionCH

public class CustomCHAlgoDecorator extends DijkstraBidirectionCH {

private CustomEdgeFilter customCHEdgeFilter;

public CustomCHAlgoDecorator(RoutingCHGraph graph,
                                CustomEdgeFilter customCHEdgeFilter) {
    super(graph);
    this.customCHEdgeFilter = customCHEdgeFilter;
}

@Override
protected boolean accept(RoutingCHEdgeIteratorState iter, int prevOrNextEdgeId) {
    return customCHEdgeFilter.accept(iter) && super.accept(iter, prevOrNextEdgeId);
}

}

Class 6 -> CustomCHRoutingAlgorithmFactoryDecorator extends CHRoutingAlgorithmFactory

public class CustomCHRoutingAlgorithmFactoryDecorator extends CHRoutingAlgorithmFactory {

private CustomCHEdgeFilter customCHEdgeFilter;
private CustomWeightingDecorator customWeightingDecorator;
private Map parameters;

public CustomCHRoutingAlgorithmFactoryDecorator(CHGraph chGraph, Map parameters) {
    super(chGraph);
    this.customCHEdgeFilter = new CustomCHEdgeFilter(customRepository, parameters);
}

@Override
public RoutingAlgorithm createAlgo(Graph graph, AlgorithmOptions opts) {
    this.customWeightingDecorator = new CustomWeightingDecorator(chConfig.getWeighting(), parameters);
    RoutingCHGraph g = new RoutingCHGraphImpl(graph, customWeightingDecorator);
    return new CustomCHAlgoDecorator(g, customCHEdgeFilter);
}

}

I tried to debug and found out that for the edge I was trying to filter out, accept() method of CustomEdgeFilter was returning false in case of both CH enabled as well as disabled but the edge was only filtered in case of CH disabled.

I thought it’s happening because I had to use CHEdgeFilter instead EdgeFilter so I added CustomCHEdgeFilter as well as CustomWeighting with the same filtering logic. But although the edge which I was trying to filter out was being encountered in CustomEdgeFilter (used by QueryGraph), the same edge was not being encountered in CustomCHEdgeFilter (used by DijkstraBidirectionCH) or CustomWeightingDecorator(used by RoutingCHGraph).

May I know if it is possible to achieve this in some way? Thanks in advance!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.