Search in sources :

Example 11 with CarFlagEncoder

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

the class TurnCostExtensionTest method testMultipleTurnCosts.

/**
 * Test if multiple turn costs can be safely written to the storage and read from it.
 */
@Test
public void testMultipleTurnCosts() {
    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();
    // introduce some turn costs
    long carRestricted = carEncoder.getTurnFlags(true, 0);
    long carCosts = carEncoder.getTurnFlags(false, 2);
    long bikeRestricted = bikeEncoder.getTurnFlags(true, 0);
    long bikeCosts = bikeEncoder.getTurnFlags(false, 2);
    int edge42 = getEdge(g, 4, 2).getEdge();
    int edge23 = getEdge(g, 2, 3).getEdge();
    int edge31 = getEdge(g, 3, 1).getEdge();
    int edge10 = getEdge(g, 1, 0).getEdge();
    int edge02 = getEdge(g, 0, 2).getEdge();
    int edge24 = getEdge(g, 2, 4).getEdge();
    tcs.mergeOrOverwriteTurnInfo(edge42, 2, edge23, carRestricted, true);
    tcs.mergeOrOverwriteTurnInfo(edge42, 2, edge23, bikeRestricted, true);
    tcs.mergeOrOverwriteTurnInfo(edge23, 3, edge31, carRestricted, true);
    tcs.mergeOrOverwriteTurnInfo(edge23, 3, edge31, bikeCosts, true);
    tcs.mergeOrOverwriteTurnInfo(edge31, 1, edge10, carCosts, true);
    tcs.mergeOrOverwriteTurnInfo(edge31, 1, edge10, bikeRestricted, true);
    tcs.mergeOrOverwriteTurnInfo(edge02, 2, edge24, carRestricted, false);
    tcs.mergeOrOverwriteTurnInfo(edge02, 2, edge24, bikeRestricted, false);
    long flags423 = tcs.getTurnCostFlags(edge42, 2, edge23);
    assertEquals(Double.POSITIVE_INFINITY, carEncoder.getTurnCost(flags423), 0);
    assertEquals(Double.POSITIVE_INFINITY, bikeEncoder.getTurnCost(flags423), 0);
    long flags231 = tcs.getTurnCostFlags(edge23, 3, edge31);
    assertEquals(Double.POSITIVE_INFINITY, carEncoder.getTurnCost(flags231), 0);
    assertEquals(2.0, bikeEncoder.getTurnCost(flags231), 0);
    long flags310 = tcs.getTurnCostFlags(edge31, 1, edge10);
    assertEquals(2.0, carEncoder.getTurnCost(flags310), 0);
    assertEquals(Double.POSITIVE_INFINITY, bikeEncoder.getTurnCost(flags310), 0);
    long flags024 = tcs.getTurnCostFlags(edge02, 2, edge24);
    assertEquals(0.0, carEncoder.getTurnCost(flags024), 0);
    assertEquals(Double.POSITIVE_INFINITY, bikeEncoder.getTurnCost(flags024), 0);
    // merge per default
    tcs.addTurnInfo(edge02, 2, edge23, carRestricted);
    tcs.addTurnInfo(edge02, 2, edge23, bikeRestricted);
    long flags023 = tcs.getTurnCostFlags(edge02, 2, edge23);
    assertEquals(Double.POSITIVE_INFINITY, carEncoder.getTurnCost(flags023), 0);
    assertEquals(Double.POSITIVE_INFINITY, bikeEncoder.getTurnCost(flags023), 0);
    // overwrite
    tcs.mergeOrOverwriteTurnInfo(edge02, 2, edge23, bikeRestricted, false);
    flags023 = tcs.getTurnCostFlags(edge02, 2, edge23);
    assertEquals(0, carEncoder.getTurnCost(flags023), 0);
    assertEquals(Double.POSITIVE_INFINITY, bikeEncoder.getTurnCost(flags023), 0);
    // clear
    tcs.mergeOrOverwriteTurnInfo(edge02, 2, edge23, 0, false);
    flags023 = tcs.getTurnCostFlags(edge02, 2, edge23);
    assertEquals(0, carEncoder.getTurnCost(flags023), 0);
    assertEquals(0, 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 12 with CarFlagEncoder

use of com.graphhopper.routing.util.CarFlagEncoder 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)

Example 13 with CarFlagEncoder

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

the class PrepareContractionHierarchiesTest method testMultiplePreparationsDifferentView.

@Test
public void testMultiplePreparationsDifferentView() {
    CarFlagEncoder tmpCarEncoder = new CarFlagEncoder();
    BikeFlagEncoder tmpBikeEncoder = new BikeFlagEncoder();
    EncodingManager tmpEncodingManager = new EncodingManager(tmpCarEncoder, tmpBikeEncoder);
    Weighting carWeighting = new FastestWeighting(tmpCarEncoder);
    Weighting bikeWeighting = new FastestWeighting(tmpBikeEncoder);
    List<Weighting> chWeightings = Arrays.asList(carWeighting, bikeWeighting);
    GraphHopperStorage ghStorage = new GraphHopperStorage(chWeightings, dir, tmpEncodingManager, false, new GraphExtension.NoOpExtension()).create(1000);
    initShortcutsGraph(ghStorage);
    EdgeIteratorState edge = GHUtility.getEdge(ghStorage, 9, 14);
    edge.setFlags(tmpBikeEncoder.setAccess(edge.getFlags(), false, false));
    ghStorage.freeze();
    checkPath(ghStorage, carWeighting, 7, 5, Helper.createTList(3, 9, 14, 16, 13, 12));
    // detour around blocked 9,14
    checkPath(ghStorage, bikeWeighting, 9, 5, Helper.createTList(3, 10, 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) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) Test(org.junit.Test)

Example 14 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)14 EncodingManager (com.graphhopper.routing.util.EncodingManager)14 Test (org.junit.Test)9 BikeFlagEncoder (com.graphhopper.routing.util.BikeFlagEncoder)4 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)4 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)4 Before (org.junit.Before)4 ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)3 GraphBuilder (com.graphhopper.storage.GraphBuilder)3 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)3 DefaultEdgeFilter (com.graphhopper.routing.util.DefaultEdgeFilter)2 Weighting (com.graphhopper.routing.weighting.Weighting)2 File (java.io.File)2 GraphHopper (com.graphhopper.GraphHopper)1 GHIntHashSet (com.graphhopper.coll.GHIntHashSet)1 ReaderWay (com.graphhopper.reader.ReaderWay)1 EdgeBasedRoutingAlgorithmTest (com.graphhopper.routing.EdgeBasedRoutingAlgorithmTest)1 EdgeFilter (com.graphhopper.routing.util.EdgeFilter)1 CHGraph (com.graphhopper.storage.CHGraph)1 RAMDirectory (com.graphhopper.storage.RAMDirectory)1