Search in sources :

Example 6 with FlagEncoder

use of com.graphhopper.routing.util.FlagEncoder in project graphhopper by graphhopper.

the class PrepareRoutingSubnetworks method doWork.

public void doWork() {
    if (minNetworkSize <= 0 && minOneWayNetworkSize <= 0)
        return;
    logger.info("start finding subnetworks (min:" + minNetworkSize + ", min one way:" + minOneWayNetworkSize + ") " + Helper.getMemInfo());
    int unvisitedDeadEnds = 0;
    for (FlagEncoder encoder : encoders) {
        // mark edges for one vehicle as inaccessible
        PrepEdgeFilter filter = new PrepEdgeFilter(encoder);
        if (minOneWayNetworkSize > 0)
            unvisitedDeadEnds += removeDeadEndUnvisitedNetworks(filter);
        List<IntArrayList> components = findSubnetworks(filter);
        keepLargeNetworks(filter, components);
        subnetworks = Math.max(components.size(), subnetworks);
        logger.info(components.size() + " subnetworks found for " + encoder + ", " + Helper.getMemInfo());
    }
    markNodesRemovedIfUnreachable();
    logger.info("optimize to remove subnetworks (" + subnetworks + "), " + "unvisited-dead-end-nodes (" + unvisitedDeadEnds + "), " + "maxEdges/node (" + maxEdgesPerNode.get() + ")");
    ghStorage.optimize();
}
Also used : FlagEncoder(com.graphhopper.routing.util.FlagEncoder) GHIntArrayList(com.graphhopper.coll.GHIntArrayList) IntArrayList(com.carrotsearch.hppc.IntArrayList)

Example 7 with FlagEncoder

use of com.graphhopper.routing.util.FlagEncoder in project graphhopper by graphhopper.

the class PrepareRoutingSubnetworks method keepLargeNetworks.

/**
 * Deletes all but the largest subnetworks.
 */
int keepLargeNetworks(PrepEdgeFilter filter, List<IntArrayList> components) {
    if (components.size() <= 1)
        return 0;
    int maxCount = -1;
    IntIndexedContainer oldComponent = null;
    int allRemoved = 0;
    FlagEncoder encoder = filter.getEncoder();
    EdgeExplorer explorer = ghStorage.createEdgeExplorer(filter);
    for (IntArrayList component : components) {
        if (maxCount < 0) {
            maxCount = component.size();
            oldComponent = component;
            continue;
        }
        int removedEdges;
        if (maxCount < component.size()) {
            // new biggest area found. remove old
            removedEdges = removeEdges(explorer, encoder, oldComponent, minNetworkSize);
            maxCount = component.size();
            oldComponent = component;
        } else {
            removedEdges = removeEdges(explorer, encoder, component, minNetworkSize);
        }
        allRemoved += removedEdges;
    }
    if (allRemoved > ghStorage.getAllEdges().getMaxId() / 2)
        throw new IllegalStateException("Too many total edges were removed: " + allRemoved + ", all edges:" + ghStorage.getAllEdges().getMaxId());
    return allRemoved;
}
Also used : FlagEncoder(com.graphhopper.routing.util.FlagEncoder) IntIndexedContainer(com.carrotsearch.hppc.IntIndexedContainer) GHIntArrayList(com.graphhopper.coll.GHIntArrayList) IntArrayList(com.carrotsearch.hppc.IntArrayList)

Example 8 with FlagEncoder

use of com.graphhopper.routing.util.FlagEncoder in project graphhopper by graphhopper.

the class TurnCostExtensionTest method testMergeFlagsBeforeAdding.

@Test
public void testMergeFlagsBeforeAdding() {
    FlagEncoder carEncoder = new CarFlagEncoder(5, 5, 3);
    FlagEncoder bikeEncoder = new BikeFlagEncoder(5, 5, 3);
    EncodingManager manager = new EncodingManager(carEncoder, bikeEncoder);
    GraphHopperStorage g = new GraphBuilder(manager).create();
    initGraph(g);
    TurnCostExtension tcs = (TurnCostExtension) g.getExtension();
    long carRestricted = carEncoder.getTurnFlags(true, 0);
    long bikeRestricted = bikeEncoder.getTurnFlags(true, 0);
    int edge23 = getEdge(g, 2, 3).getEdge();
    int edge02 = getEdge(g, 0, 2).getEdge();
    tcs.addTurnInfo(edge02, 2, edge23, carRestricted | bikeRestricted);
    long flags023 = tcs.getTurnCostFlags(edge02, 2, edge23);
    assertEquals(Double.POSITIVE_INFINITY, carEncoder.getTurnCost(flags023), 0);
    assertEquals(Double.POSITIVE_INFINITY, bikeEncoder.getTurnCost(flags023), 0);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) BikeFlagEncoder(com.graphhopper.routing.util.BikeFlagEncoder) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) BikeFlagEncoder(com.graphhopper.routing.util.BikeFlagEncoder) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) Test(org.junit.Test)

Example 9 with FlagEncoder

use of com.graphhopper.routing.util.FlagEncoder in project graphhopper by graphhopper.

the class LocationIndexTreeCHTest method testCHGraph.

@Test
public void testCHGraph() {
    GraphHopperStorage ghStorage = createGHStorage(new RAMDirectory(), encodingManager, false);
    CHGraph lg = ghStorage.getGraph(CHGraph.class);
    // 0
    // 1
    // 2
    // 3
    // 4
    NodeAccess na = ghStorage.getNodeAccess();
    na.setNode(0, 1, 0);
    na.setNode(1, 0.5, 0);
    na.setNode(2, 0, 0);
    na.setNode(3, -1, 1);
    na.setNode(4, -2, 2);
    EdgeIteratorState iter1 = ghStorage.edge(0, 1, 10, true);
    EdgeIteratorState iter2 = ghStorage.edge(1, 2, 10, true);
    EdgeIteratorState iter3 = ghStorage.edge(2, 3, 14, true);
    EdgeIteratorState iter4 = ghStorage.edge(3, 4, 14, true);
    // create shortcuts
    ghStorage.freeze();
    FlagEncoder car = encodingManager.getEncoder("car");
    long flags = car.setProperties(60, true, true);
    CHEdgeIteratorState iter5 = lg.shortcut(0, 2);
    iter5.setDistance(20).setFlags(flags);
    iter5.setSkippedEdges(iter1.getEdge(), iter2.getEdge());
    CHEdgeIteratorState iter6 = lg.shortcut(2, 4);
    iter6.setDistance(28).setFlags(flags);
    iter6.setSkippedEdges(iter3.getEdge(), iter4.getEdge());
    CHEdgeIteratorState tmp = lg.shortcut(0, 4);
    tmp.setDistance(40).setFlags(flags);
    tmp.setSkippedEdges(iter5.getEdge(), iter6.getEdge());
    LocationIndex index = createIndex(ghStorage, -1);
    assertEquals(2, findID(index, 0, 0.5));
}
Also used : CHEdgeIteratorState(com.graphhopper.util.CHEdgeIteratorState) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) CHEdgeIteratorState(com.graphhopper.util.CHEdgeIteratorState) Test(org.junit.Test)

Example 10 with FlagEncoder

use of com.graphhopper.routing.util.FlagEncoder in project graphhopper by graphhopper.

the class SpatialRuleLookupHelper method buildAndInjectSpatialRuleIntoGH.

public static void buildAndInjectSpatialRuleIntoGH(GraphHopper graphHopper, CmdArgs args) {
    String spatialRuleLocation = args.get("spatial_rules.location", "");
    if (!spatialRuleLocation.isEmpty()) {
        try {
            final BBox maxBounds = BBox.parseBBoxString(args.get("spatial_rules.max_bbox", "-180, 180, -90, 90"));
            final InputStreamReader reader = new InputStreamReader(new FileInputStream(spatialRuleLocation), UTF_CS);
            final SpatialRuleLookup index = SpatialRuleLookupBuilder.buildIndex(new GHJsonFactory().create().fromJson(reader, JsonFeatureCollection.class), "ISO_A3", new CountriesSpatialRuleFactory(), .1, maxBounds);
            logger.info("Set spatial rule lookup with " + index.size() + " rules");
            final FlagEncoderFactory oldFEF = graphHopper.getFlagEncoderFactory();
            graphHopper.setFlagEncoderFactory(new FlagEncoderFactory() {

                @Override
                public FlagEncoder createFlagEncoder(String name, PMap configuration) {
                    if (name.equals(GENERIC)) {
                        return new DataFlagEncoder(configuration).setSpatialRuleLookup(index);
                    }
                    return oldFEF.createFlagEncoder(name, configuration);
                }
            });
        } catch (IOException ex) {
            throw new RuntimeException(ex);
        }
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) DataFlagEncoder(com.graphhopper.routing.util.DataFlagEncoder) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) PMap(com.graphhopper.util.PMap) SpatialRuleLookup(com.graphhopper.routing.util.spatialrules.SpatialRuleLookup) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) DataFlagEncoder(com.graphhopper.routing.util.DataFlagEncoder) BBox(com.graphhopper.util.shapes.BBox) GHJsonFactory(com.graphhopper.json.GHJsonFactory) JsonFeatureCollection(com.graphhopper.json.geo.JsonFeatureCollection) CountriesSpatialRuleFactory(com.graphhopper.routing.util.spatialrules.CountriesSpatialRuleFactory) FlagEncoderFactory(com.graphhopper.routing.util.FlagEncoderFactory)

Aggregations

FlagEncoder (com.graphhopper.routing.util.FlagEncoder)18 Test (org.junit.Test)10 EncodingManager (com.graphhopper.routing.util.EncodingManager)8 IntArrayList (com.carrotsearch.hppc.IntArrayList)4 GHIntArrayList (com.graphhopper.coll.GHIntArrayList)4 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)4 DefaultEdgeFilter (com.graphhopper.routing.util.DefaultEdgeFilter)4 GraphBuilder (com.graphhopper.storage.GraphBuilder)3 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)3 LocationIndex (com.graphhopper.storage.index.LocationIndex)3 ArrayList (java.util.ArrayList)3 BikeFlagEncoder (com.graphhopper.routing.util.BikeFlagEncoder)2 DataFlagEncoder (com.graphhopper.routing.util.DataFlagEncoder)2 Graph (com.graphhopper.storage.Graph)2 RAMDirectory (com.graphhopper.storage.RAMDirectory)2 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)2 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)2 InputStreamReader (java.io.InputStreamReader)2 IntIndexedContainer (com.carrotsearch.hppc.IntIndexedContainer)1 GHRequest (com.graphhopper.GHRequest)1