Search in sources :

Example 36 with EncodingManager

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

the class RoutingCHGraphImplTest method testShortcutConnection.

@Test
void testShortcutConnection() {
    // 4 ------ 1 > 0
    // ^ \
    // 3  2
    FlagEncoder encoder = FlagEncoders.createCar();
    EncodingManager em = EncodingManager.create(encoder);
    BaseGraph graph = new BaseGraph.Builder(em).create();
    EdgeExplorer baseCarOutExplorer = graph.createEdgeExplorer(AccessFilter.outEdges(encoder.getAccessEnc()));
    GHUtility.setSpeed(60, true, true, encoder, graph.edge(4, 1).setDistance(30));
    graph.freeze();
    CHConfig chConfig = CHConfig.nodeBased("ch", new FastestWeighting(encoder));
    CHStorage store = CHStorage.fromGraph(graph, chConfig);
    CHStorageBuilder chBuilder = new CHStorageBuilder(store);
    chBuilder.setIdentityLevels();
    chBuilder.addShortcutNodeBased(0, 1, PrepareEncoder.getScBwdDir(), 10, 12, 13);
    chBuilder.addShortcutNodeBased(1, 2, PrepareEncoder.getScDirMask(), 10, 10, 11);
    chBuilder.addShortcutNodeBased(1, 3, PrepareEncoder.getScBwdDir(), 10, 14, 15);
    RoutingCHGraph lg = RoutingCHGraphImpl.fromGraph(graph, store, chConfig);
    RoutingCHEdgeExplorer chOutExplorer = lg.createOutEdgeExplorer();
    RoutingCHEdgeExplorer chInExplorer = lg.createInEdgeExplorer();
    // shortcuts are only visible from the lower level node, for example we do not see node 1 from node 2, or node
    // 0 from node 1
    assertEquals(0, GHUtility.count(chOutExplorer.setBaseNode(2)));
    assertEquals(0, GHUtility.count(chInExplorer.setBaseNode(2)));
    assertEquals(2, GHUtility.count(chOutExplorer.setBaseNode(1)));
    assertEquals(3, GHUtility.count(chInExplorer.setBaseNode(1)));
    assertEquals(GHUtility.asSet(2, 4), GHUtility.getNeighbors(chOutExplorer.setBaseNode(1)));
    assertEquals(GHUtility.asSet(4), GHUtility.getNeighbors(baseCarOutExplorer.setBaseNode(1)));
    assertEquals(0, GHUtility.count(chOutExplorer.setBaseNode(3)));
    assertEquals(0, GHUtility.count(chInExplorer.setBaseNode(3)));
    assertEquals(0, GHUtility.count(chOutExplorer.setBaseNode(0)));
    assertEquals(1, GHUtility.count(chInExplorer.setBaseNode(0)));
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) EdgeExplorer(com.graphhopper.util.EdgeExplorer) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Test(org.junit.jupiter.api.Test)

Example 37 with EncodingManager

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

the class DecimalEncodedValueTest method testMaxValue.

@Test
public void testMaxValue() {
    FlagEncoder carEncoder = FlagEncoders.createCar(new PMap("speed_bits=10|speed_factor=0.5"));
    EncodingManager em = EncodingManager.create(carEncoder);
    DecimalEncodedValue carAverageSpeedEnc = em.getDecimalEncodedValue(EncodingManager.getKey(carEncoder, "average_speed"));
    CarTagParser carTagParser = new CarTagParser(em, new PMap());
    carTagParser.init(new DateRangeParser());
    ReaderWay way = new ReaderWay(1);
    way.setTag("highway", "motorway_link");
    way.setTag("maxspeed", "70 mph");
    IntsRef flags = carTagParser.handleWayTags(em.createEdgeFlags(), way);
    assertEquals(101.5, carAverageSpeedEnc.getDecimal(true, flags), 1e-1);
    DecimalEncodedValue instance1 = new DecimalEncodedValueImpl("test1", 8, 0.5, false);
    instance1.init(new EncodedValue.InitializerConfig());
    flags = em.createEdgeFlags();
    instance1.setDecimal(false, flags, 100d);
    assertEquals(100, instance1.getDecimal(false, flags), 1e-1);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) CarTagParser(com.graphhopper.routing.util.CarTagParser) PMap(com.graphhopper.util.PMap) ReaderWay(com.graphhopper.reader.ReaderWay) IntsRef(com.graphhopper.storage.IntsRef) DateRangeParser(com.graphhopper.reader.osm.conditional.DateRangeParser) Test(org.junit.jupiter.api.Test)

Example 38 with EncodingManager

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

the class GtfsReader method connectStopsToStreetNetwork.

void connectStopsToStreetNetwork() {
    EncodingManager em = graph.getEncodingManager();
    FlagEncoder footEncoder = em.getEncoder("foot");
    final EdgeFilter filter = new DefaultSnapFilter(new FastestWeighting(footEncoder), em.getBooleanEncodedValue(Subnetwork.key("foot")));
    for (Stop stop : feed.stops.values()) {
        if (stop.location_type == 0) {
            // Only stops. Not interested in parent stations for now.
            Snap locationSnap = walkNetworkIndex.findClosest(stop.stop_lat, stop.stop_lon, filter);
            Integer stopNode;
            if (locationSnap.isValid()) {
                stopNode = gtfsStorage.getStreetToPt().get(locationSnap.getClosestNode());
                if (stopNode == null) {
                    stopNode = out.createNode();
                    indexBuilder.addToAllTilesOnLine(stopNode, stop.stop_lat, stop.stop_lon, stop.stop_lat, stop.stop_lon);
                    gtfsStorage.getPtToStreet().put(stopNode, locationSnap.getClosestNode());
                    gtfsStorage.getStreetToPt().put(locationSnap.getClosestNode(), stopNode);
                }
            } else {
                stopNode = out.createNode();
                indexBuilder.addToAllTilesOnLine(stopNode, stop.stop_lat, stop.stop_lon, stop.stop_lat, stop.stop_lon);
            }
            gtfsStorage.getStationNodes().put(new GtfsStorage.FeedIdWithStopId(id, stop.stop_id), stopNode);
        }
    }
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) DefaultSnapFilter(com.graphhopper.routing.util.DefaultSnapFilter) EdgeFilter(com.graphhopper.routing.util.EdgeFilter) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Snap(com.graphhopper.storage.index.Snap)

Example 39 with EncodingManager

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

the class HeadingRoutingTest method createSquareGraphWithTunnel.

private GraphHopperStorage createSquareGraphWithTunnel() {
    CarFlagEncoder carEncoder = new CarFlagEncoder();
    EncodingManager encodingManager = new EncodingManager.Builder().add(carEncoder).add(Subnetwork.create("profile")).build();
    GraphHopperStorage g = new GraphBuilder(encodingManager).create();
    // 2----3---4
    // |    |   |
    // 1->- 8 >-5 (edge 1->5 is not connected to 8)
    // |    |   |
    // 0----7---6
    NodeAccess na = g.getNodeAccess();
    na.setNode(0, 0.000, 0.000);
    na.setNode(1, 0.001, 0.000);
    na.setNode(2, 0.002, 0.000);
    na.setNode(3, 0.002, 0.001);
    na.setNode(4, 0.002, 0.002);
    na.setNode(5, 0.001, 0.002);
    na.setNode(6, 0.000, 0.002);
    na.setNode(7, 0.000, 0.001);
    na.setNode(8, 0.001, 0.001);
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(0, 1).setDistance(100));
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(1, 2).setDistance(100));
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(2, 3).setDistance(100));
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(3, 4).setDistance(100));
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(4, 5).setDistance(100));
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(5, 6).setDistance(100));
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(6, 7).setDistance(100));
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(7, 0).setDistance(100));
    GHUtility.setSpeed(60, true, false, carEncoder, g.edge(1, 5).setDistance(110));
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(3, 8).setDistance(110));
    GHUtility.setSpeed(60, true, true, carEncoder, g.edge(7, 8).setDistance(110));
    return g;
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder)

Example 40 with EncodingManager

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

the class ShapeFileReaderTest method initHopper.

private static GraphHopper initHopper(GraphHopper gh, String inputFile, String outDir) {
    URL resourceURL = ShapeFileReaderTest.class.getResource(inputFile);
    try {
        inputFile = new File(resourceURL.toURI()).getAbsolutePath();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    // turn off geometry simplification so geometry should be the same
    // between pbf and shapefile readers
    gh.setWayPointMaxDistance(0);
    return gh.setStoreOnFlush(false).setDataReaderFile(inputFile).setGraphHopperLocation(new File(outDir).getAbsolutePath()).setEncodingManager(new EncodingManager(new CarFlagEncoder())).setCHEnabled(false).importOrLoad();
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) File(java.io.File) URL(java.net.URL) URISyntaxException(java.net.URISyntaxException) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder)

Aggregations

EncodingManager (com.graphhopper.routing.util.EncodingManager)83 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)47 Test (org.junit.jupiter.api.Test)41 BaseGraph (com.graphhopper.storage.BaseGraph)26 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)23 GraphHopperOSM (com.graphhopper.reader.osm.GraphHopperOSM)18 GHPoint (com.graphhopper.util.shapes.GHPoint)12 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)10 Test (org.junit.Test)10 GHRequest (com.graphhopper.GHRequest)8 GHResponse (com.graphhopper.GHResponse)8 NodeAccess (com.graphhopper.storage.NodeAccess)8 ReaderWay (com.graphhopper.reader.ReaderWay)7 GraphBuilder (com.graphhopper.storage.GraphBuilder)7 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)7 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)6 GraphHopper (com.graphhopper.GraphHopper)5 Dijkstra (com.graphhopper.routing.Dijkstra)5 Path (com.graphhopper.routing.Path)5 PMap (com.graphhopper.util.PMap)5