Search in sources :

Example 91 with EdgeIteratorState

use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.

the class GenericWeightingTest method testDisabledRoadAttributes.

@Test
public void testDisabledRoadAttributes() {
    DataFlagEncoder simpleEncoder = new DataFlagEncoder();
    EncodingManager simpleEncodingManager = new EncodingManager(simpleEncoder);
    Graph simpleGraph = new GraphBuilder(simpleEncodingManager).create();
    ReaderWay way = new ReaderWay(27l);
    way.setTag("highway", "primary");
    way.setTag("maxspeed", "10");
    way.setTag("maxheight", "4.4");
    // 0-1
    simpleGraph.edge(0, 1, 1, true);
    AbstractRoutingAlgorithmTester.updateDistancesFor(simpleGraph, 0, 0.00, 0.00);
    AbstractRoutingAlgorithmTester.updateDistancesFor(simpleGraph, 1, 0.01, 0.01);
    simpleGraph.getEdgeIteratorState(0, 1).setFlags(simpleEncoder.handleWayTags(way, 1, 0));
    Weighting instance = new GenericWeighting(simpleEncoder, new HintsMap().put(GenericWeighting.HEIGHT_LIMIT, 5.0));
    EdgeIteratorState edge = simpleGraph.getEdgeIteratorState(0, 1);
    assertEquals(edgeWeight, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), 1e-8);
}
Also used : DataFlagEncoder(com.graphhopper.routing.util.DataFlagEncoder) EncodingManager(com.graphhopper.routing.util.EncodingManager) HintsMap(com.graphhopper.routing.util.HintsMap) Graph(com.graphhopper.storage.Graph) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) GraphBuilder(com.graphhopper.storage.GraphBuilder) ReaderWay(com.graphhopper.reader.ReaderWay) Test(org.junit.Test)

Example 92 with EdgeIteratorState

use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.

the class RoutingCHEdgeIteratorStateImpl method getOrigEdgeWeight.

/**
 * @param needWeight if true this method will return as soon as its clear that the weight is finite (no need to
 *                   do the full computation)
 */
double getOrigEdgeWeight(boolean reverse, boolean needWeight) {
    // todo: for #1835 move the access check into the weighting
    final EdgeIteratorState baseEdge = getBaseGraphEdgeState();
    final boolean access = reverse ? baseEdge.getReverse(accessEnc) : baseEdge.get(accessEnc);
    if (baseEdge.getBaseNode() != baseEdge.getAdjNode() && !access) {
        return Double.POSITIVE_INFINITY;
    }
    if (!needWeight) {
        return 0;
    }
    return weighting.calcEdgeWeight(baseEdge, reverse);
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState)

Example 93 with EdgeIteratorState

use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.

the class WheelchairFlagEncoderTest method testCombined.

@Test
public void testCombined() {
    Graph g = new GraphBuilder(encodingManager).create();
    FlagEncoder carEncoder = encodingManager.getEncoder("car");
    EdgeIteratorState edge = g.edge(0, 1);
    edge.set(wheelchairAvSpeedEnc, 10.0).set(wheelchairAccessEnc, true, true);
    edge.set(carAvSpeedEnc, 100.0).set(carAccessEnc, true, false);
    assertEquals(10, edge.get(wheelchairAvSpeedEnc), .1);
    assertTrue(edge.get(wheelchairAccessEnc));
    assertTrue(edge.getReverse(wheelchairAccessEnc));
    assertEquals(100, edge.get(carAvSpeedEnc), .1);
    assertTrue(edge.get(carAccessEnc));
    assertFalse(edge.getReverse(carAccessEnc));
    IntsRef raw = encodingManager.createEdgeFlags();
    wheelchairAvSpeedEnc.setDecimal(false, raw, 10);
    wheelchairAccessEnc.setBool(false, raw, true);
    wheelchairAccessEnc.setBool(true, raw, true);
    assertEquals(0, carAvSpeedEnc.getDecimal(false, raw), .1);
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) Test(org.junit.jupiter.api.Test)

Example 94 with EdgeIteratorState

use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.

the class WheelchairFlagEncoderTest method testApplyWayTags.

@Test
public void testApplyWayTags() {
    GraphHopperStorage graph = new GraphBuilder(encodingManager).set3D(true).create();
    NodeAccess na = graph.getNodeAccess();
    // incline of 5% over all
    na.setNode(0, 51.1, 12.0010, 50);
    na.setNode(1, 51.1, 12.0015, 55);
    EdgeIteratorState edge01 = graph.edge(0, 1).setWayGeometry(Helper.createPointList3D(51.1, 12.0011, 49, 51.1, 12.0015, 55));
    edge01.setDistance(100);
    GHUtility.setSpeed(5, 5, wheelchairEncoder, edge01);
    // incline of 10% & shorter edge
    na.setNode(2, 51.2, 12.1010, 50);
    na.setNode(3, 51.2, 12.1015, 60);
    EdgeIteratorState edge23 = graph.edge(2, 3).setWayGeometry(Helper.createPointList3D(51.2, 12.1011, 49, 51.2, 12.1015, 55));
    edge23.setDistance(30);
    GHUtility.setSpeed(5, 5, wheelchairEncoder, edge23);
    // incline of 10% & longer edge
    na.setNode(4, 51.2, 12.101, 50);
    na.setNode(5, 51.2, 12.102, 60);
    EdgeIteratorState edge45 = graph.edge(2, 3).setWayGeometry(Helper.createPointList3D(51.2, 12.1011, 49, 51.2, 12.1015, 55));
    edge45.setDistance(100);
    GHUtility.setSpeed(5, 5, wheelchairEncoder, edge45);
    wheelchairEncoder.applyWayTags(new ReaderWay(1), edge01);
    assertTrue(edge01.get(wheelchairAccessEnc));
    assertTrue(edge01.getReverse(wheelchairAccessEnc));
    assertEquals(2, edge01.get(wheelchairEncoder.getAverageSpeedEnc()), 0);
    assertEquals(5, edge01.getReverse(wheelchairEncoder.getAverageSpeedEnc()), 0);
    wheelchairEncoder.applyWayTags(new ReaderWay(2), edge23);
    assertTrue(edge23.get(wheelchairAccessEnc));
    assertTrue(edge23.getReverse(wheelchairAccessEnc));
    assertEquals(2, edge23.get(wheelchairEncoder.getAverageSpeedEnc()), 0);
    assertEquals(2, edge23.getReverse(wheelchairEncoder.getAverageSpeedEnc()), 0);
    // only exclude longer edges with too large incline:
    wheelchairEncoder.applyWayTags(new ReaderWay(3), edge45);
    assertFalse(edge45.get(wheelchairAccessEnc));
    assertFalse(edge45.getReverse(wheelchairAccessEnc));
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) ReaderWay(com.graphhopper.reader.ReaderWay) Test(org.junit.jupiter.api.Test)

Example 95 with EdgeIteratorState

use of com.graphhopper.util.EdgeIteratorState in project graphhopper by graphhopper.

the class MotorcycleFlagEncoderTest method initExampleGraph.

private Graph initExampleGraph() {
    GraphHopperStorage gs = new GraphBuilder(em).set3D(true).create();
    NodeAccess na = gs.getNodeAccess();
    // 50--(0.0001)-->49--(0.0004)-->55--(0.0005)-->60
    na.setNode(0, 51.1, 12.001, 50);
    na.setNode(1, 51.1, 12.002, 60);
    EdgeIteratorState edge = gs.edge(0, 1).setWayGeometry(Helper.createPointList3D(51.1, 12.0011, 49, 51.1, 12.0015, 55));
    edge.setDistance(100);
    edge.set(accessEnc, true, true).set(encoder.getAverageSpeedEnc(), 10.0, 15.0);
    return gs;
}
Also used : EdgeIteratorState(com.graphhopper.util.EdgeIteratorState)

Aggregations

EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)137 Test (org.junit.jupiter.api.Test)55 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)25 Test (org.junit.Test)22 RepeatedTest (org.junit.jupiter.api.RepeatedTest)17 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)13 Snap (com.graphhopper.storage.index.Snap)12 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)11 CHEdgeIteratorState (com.graphhopper.util.CHEdgeIteratorState)11 QueryGraph (com.graphhopper.routing.querygraph.QueryGraph)10 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)10 NodeAccess (com.graphhopper.storage.NodeAccess)10 GHIntHashSet (com.graphhopper.coll.GHIntHashSet)9 GraphBuilder (com.graphhopper.storage.GraphBuilder)8 QueryRoutingCHGraph (com.graphhopper.routing.querygraph.QueryRoutingCHGraph)7 DecimalEncodedValue (com.graphhopper.routing.ev.DecimalEncodedValue)6 EncodingManager (com.graphhopper.routing.util.EncodingManager)6 GHPoint (com.graphhopper.util.shapes.GHPoint)6 Fun (org.mapdb.Fun)6 IntArrayList (com.carrotsearch.hppc.IntArrayList)5