Search in sources :

Example 1 with CarFlagEncoder

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

the class InstructionListTest method setUp.

@Before
public void setUp() {
    carEncoder = new CarFlagEncoder();
    carManager = new EncodingManager(carEncoder);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) Before(org.junit.Before)

Example 2 with CarFlagEncoder

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

the class OSMTurnRelationTest method testGetRestrictionAsEntries.

@Test
public void testGetRestrictionAsEntries() {
    CarFlagEncoder encoder = new CarFlagEncoder(5, 5, 1);
    final Map<Long, Integer> osmNodeToInternal = new HashMap<Long, Integer>();
    final Map<Integer, Long> internalToOSMEdge = new HashMap<Integer, Long>();
    osmNodeToInternal.put(3L, 3);
    // edge ids are only stored if they occured before in an OSMRelation
    internalToOSMEdge.put(3, 3L);
    internalToOSMEdge.put(4, 4L);
    GraphHopperStorage ghStorage = new GraphBuilder(new EncodingManager(encoder)).create();
    EdgeBasedRoutingAlgorithmTest.initGraph(ghStorage);
    OSMReader osmReader = new OSMReader(ghStorage) {

        @Override
        public int getInternalNodeIdOfOsmNode(long nodeOsmId) {
            return osmNodeToInternal.get(nodeOsmId);
        }

        @Override
        public long getOsmIdOfInternalEdge(int edgeId) {
            Long l = internalToOSMEdge.get(edgeId);
            if (l == null)
                return -1;
            return l;
        }
    };
    EdgeExplorer edgeExplorer = ghStorage.createEdgeExplorer();
    // TYPE == ONLY
    OSMTurnRelation instance = new OSMTurnRelation(4, 3, 3, Type.ONLY);
    Collection<OSMTurnRelation.TurnCostTableEntry> result = instance.getRestrictionAsEntries(encoder, edgeExplorer, edgeExplorer, osmReader);
    assertEquals(2, result.size());
    Iterator<OSMTurnRelation.TurnCostTableEntry> iter = result.iterator();
    OSMTurnRelation.TurnCostTableEntry entry = iter.next();
    assertEquals(4, entry.edgeFrom);
    assertEquals(6, entry.edgeTo);
    assertEquals(3, entry.nodeVia);
    entry = iter.next();
    assertEquals(4, entry.edgeFrom);
    assertEquals(2, entry.edgeTo);
    assertEquals(3, entry.nodeVia);
    // TYPE == NOT
    instance = new OSMTurnRelation(4, 3, 3, Type.NOT);
    result = instance.getRestrictionAsEntries(encoder, edgeExplorer, edgeExplorer, osmReader);
    assertEquals(1, result.size());
    iter = result.iterator();
    entry = iter.next();
    assertEquals(4, entry.edgeFrom);
    assertEquals(3, entry.edgeTo);
    assertEquals(3, entry.nodeVia);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) HashMap(java.util.HashMap) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) EdgeExplorer(com.graphhopper.util.EdgeExplorer) GraphBuilder(com.graphhopper.storage.GraphBuilder) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) Test(org.junit.Test) EdgeBasedRoutingAlgorithmTest(com.graphhopper.routing.EdgeBasedRoutingAlgorithmTest)

Example 3 with CarFlagEncoder

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

the class PrepareContractionHierarchiesTest method testMultiplePreparationsIdenticalView.

@Test
public void testMultiplePreparationsIdenticalView() {
    CarFlagEncoder tmpCarEncoder = new CarFlagEncoder();
    BikeFlagEncoder tmpBikeEncoder = new BikeFlagEncoder();
    EncodingManager tmpEncodingManager = new EncodingManager(tmpCarEncoder, tmpBikeEncoder);
    // FastestWeighting would lead to different shortcuts due to different default speeds for bike and car
    Weighting carWeighting = new ShortestWeighting(tmpCarEncoder);
    Weighting bikeWeighting = new ShortestWeighting(tmpBikeEncoder);
    List<Weighting> chWeightings = Arrays.asList(carWeighting, bikeWeighting);
    GraphHopperStorage ghStorage = new GraphHopperStorage(chWeightings, dir, tmpEncodingManager, false, new GraphExtension.NoOpExtension()).create(1000);
    initShortcutsGraph(ghStorage);
    ghStorage.freeze();
    for (Weighting w : chWeightings) {
        checkPath(ghStorage, w, 7, 5, Helper.createTList(3, 9, 14, 16, 13, 12));
    }
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Weighting(com.graphhopper.routing.weighting.Weighting) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) BikeFlagEncoder(com.graphhopper.routing.util.BikeFlagEncoder) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) Test(org.junit.Test)

Example 4 with CarFlagEncoder

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

the class GraphEdgeIdFinderTest method testParseStringHints.

@Test
public void testParseStringHints() {
    FlagEncoder encoder = new CarFlagEncoder();
    EncodingManager em = new EncodingManager(encoder);
    GraphHopperStorage graph = new GraphBuilder(em).create();
    // 0-1-2
    // | |
    // 3-4
    graph.edge(0, 1, 1, true);
    graph.edge(1, 2, 1, true);
    graph.edge(3, 4, 1, true);
    graph.edge(0, 3, 1, true);
    graph.edge(1, 4, 1, true);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 0, 0.01, 0.00);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 1, 0.01, 0.01);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 2, 0.01, 0.02);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 3, 0.00, 0.00);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 4, 0.00, 0.01);
    LocationIndex locationIndex = new LocationIndexTree(graph, new RAMDirectory()).prepareIndex();
    HintsMap hints = new HintsMap();
    hints.put(Parameters.Routing.BLOCK_AREA, "0.01,0.005,1");
    ConfigMap cMap = new ConfigMap();
    GraphEdgeIdFinder graphFinder = new GraphEdgeIdFinder(graph, locationIndex);
    ConfigMap result = graphFinder.parseStringHints(cMap, hints, new DefaultEdgeFilter(encoder));
    GHIntHashSet blockedEdges = new GHIntHashSet();
    blockedEdges.add(0);
    assertEquals(blockedEdges, result.get(BLOCKED_EDGES, new GHIntHashSet()));
    List<Shape> blockedShapes = new ArrayList<>();
    assertEquals(blockedShapes, result.get(BLOCKED_SHAPES, new ArrayList<>()));
    // big area converts into shapes
    hints.put(Parameters.Routing.BLOCK_AREA, "0,0,1000");
    result = graphFinder.parseStringHints(cMap, hints, new DefaultEdgeFilter(encoder));
    blockedEdges.clear();
    assertEquals(blockedEdges, result.get(BLOCKED_EDGES, new GHIntHashSet()));
    blockedShapes.add(new Circle(0, 0, 1000));
    assertEquals(blockedShapes, result.get(BLOCKED_SHAPES, new ArrayList<>()));
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) HintsMap(com.graphhopper.routing.util.HintsMap) Circle(com.graphhopper.util.shapes.Circle) GHIntHashSet(com.graphhopper.coll.GHIntHashSet) Shape(com.graphhopper.util.shapes.Shape) ConfigMap(com.graphhopper.util.ConfigMap) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) ArrayList(java.util.ArrayList) LocationIndex(com.graphhopper.storage.index.LocationIndex) DefaultEdgeFilter(com.graphhopper.routing.util.DefaultEdgeFilter) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) Test(org.junit.Test)

Example 5 with CarFlagEncoder

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

the class CHEdgeIteratorTest method testUpdateFlags.

@Test
public void testUpdateFlags() {
    CarFlagEncoder carFlagEncoder = new CarFlagEncoder();
    EncodingManager encodingManager = new EncodingManager(carFlagEncoder);
    FastestWeighting weighting = new FastestWeighting(carFlagEncoder);
    EdgeFilter carOutFilter = new DefaultEdgeFilter(carFlagEncoder, false, true);
    GraphHopperStorage ghStorage = new GraphBuilder(encodingManager).setCHGraph(weighting).create();
    CHGraph g = ghStorage.getGraph(CHGraph.class, weighting);
    g.edge(0, 1).setDistance(12).setFlags(carFlagEncoder.setProperties(10, true, true));
    g.edge(0, 2).setDistance(13).setFlags(carFlagEncoder.setProperties(20, true, true));
    ghStorage.freeze();
    assertEquals(2, GHUtility.count(g.getAllEdges()));
    assertEquals(1, GHUtility.count(g.createEdgeExplorer(carOutFilter).setBaseNode(1)));
    EdgeIteratorState iter = GHUtility.getEdge(g, 0, 1);
    assertEquals(1, iter.getAdjNode());
    assertEquals(carFlagEncoder.setProperties(10, true, true), iter.getFlags());
    // update setProperties
    iter.setFlags(carFlagEncoder.setProperties(20, true, false));
    assertEquals(12, iter.getDistance(), 1e-4);
    // update distance
    iter.setDistance(10);
    assertEquals(10, iter.getDistance(), 1e-4);
    assertEquals(0, GHUtility.count(g.createEdgeExplorer(carOutFilter).setBaseNode(1)));
    iter = GHUtility.getEdge(g, 0, 1);
    assertEquals(carFlagEncoder.setProperties(20, true, false), iter.getFlags());
    assertEquals(10, iter.getDistance(), 1e-4);
    assertEquals(1, GHUtility.getNeighbors(g.createEdgeExplorer().setBaseNode(1)).size());
    assertEquals(0, GHUtility.getNeighbors(g.createEdgeExplorer(carOutFilter).setBaseNode(1)).size());
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) CHGraph(com.graphhopper.storage.CHGraph) EdgeFilter(com.graphhopper.routing.util.EdgeFilter) DefaultEdgeFilter(com.graphhopper.routing.util.DefaultEdgeFilter) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) GraphBuilder(com.graphhopper.storage.GraphBuilder) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) DefaultEdgeFilter(com.graphhopper.routing.util.DefaultEdgeFilter) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Aggregations

CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)8 EncodingManager (com.graphhopper.routing.util.EncodingManager)8 Test (org.junit.Test)6 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)4 ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)3 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)3 BikeFlagEncoder (com.graphhopper.routing.util.BikeFlagEncoder)2 DefaultEdgeFilter (com.graphhopper.routing.util.DefaultEdgeFilter)2 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)2 Weighting (com.graphhopper.routing.weighting.Weighting)2 GraphBuilder (com.graphhopper.storage.GraphBuilder)2 GHIntHashSet (com.graphhopper.coll.GHIntHashSet)1 EdgeBasedRoutingAlgorithmTest (com.graphhopper.routing.EdgeBasedRoutingAlgorithmTest)1 EdgeFilter (com.graphhopper.routing.util.EdgeFilter)1 HintsMap (com.graphhopper.routing.util.HintsMap)1 CHGraph (com.graphhopper.storage.CHGraph)1 RAMDirectory (com.graphhopper.storage.RAMDirectory)1 LocationIndex (com.graphhopper.storage.index.LocationIndex)1 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)1 ConfigMap (com.graphhopper.util.ConfigMap)1