Search in sources :

Example 21 with FastestWeighting

use of com.graphhopper.routing.weighting.FastestWeighting in project graphhopper by graphhopper.

the class PathBidirRefTest method testExtract.

@Test
public void testExtract() {
    Graph g = createGraph();
    g.edge(1, 2, 10, true);
    PathBidirRef pw = new PathBidirRef(g, new FastestWeighting(carEncoder));
    EdgeExplorer explorer = g.createEdgeExplorer(carOutEdges);
    EdgeIterator iter = explorer.setBaseNode(1);
    iter.next();
    pw.sptEntry = new SPTEntry(iter.getEdge(), 2, 0);
    pw.sptEntry.parent = new SPTEntry(EdgeIterator.NO_EDGE, 1, 10);
    pw.edgeTo = new SPTEntry(EdgeIterator.NO_EDGE, 2, 0);
    Path p = pw.extract();
    assertEquals(Helper.createTList(1, 2), p.calcNodes());
    assertEquals(10, p.getDistance(), 1e-4);
}
Also used : SPTEntry(com.graphhopper.storage.SPTEntry) EdgeIterator(com.graphhopper.util.EdgeIterator) Graph(com.graphhopper.storage.Graph) EdgeExplorer(com.graphhopper.util.EdgeExplorer) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Test(org.junit.Test)

Example 22 with FastestWeighting

use of com.graphhopper.routing.weighting.FastestWeighting in project graphhopper by graphhopper.

the class GraphHopperStorageCHTest method testShortcutCreationAndAccessForManyVehicles.

@Test
public void testShortcutCreationAndAccessForManyVehicles() {
    FlagEncoder tmpCar = new CarFlagEncoder();
    FlagEncoder tmpBike = new Bike2WeightFlagEncoder();
    EncodingManager em = new EncodingManager(tmpCar, tmpBike);
    List<Weighting> chWeightings = new ArrayList<Weighting>();
    chWeightings.add(new FastestWeighting(tmpCar));
    chWeightings.add(new FastestWeighting(tmpBike));
    graph = new GraphHopperStorage(chWeightings, new RAMDirectory(), em, false, new GraphExtension.NoOpExtension()).create(1000);
    graph.edge(0, 1).setDistance(10).setFlags(tmpCar.setProperties(100, true, true) | tmpBike.setProperties(10, true, true));
    graph.edge(1, 2).setDistance(10).setFlags(tmpCar.setProperties(100, true, true) | tmpBike.setProperties(10, true, true));
    graph.freeze();
    CHGraph carCHGraph = graph.getGraph(CHGraph.class, chWeightings.get(0));
    // enable forward directions for car
    EdgeIteratorState carSC02 = carCHGraph.shortcut(0, 2).setWeight(10).setFlags(PrepareEncoder.getScFwdDir()).setDistance(20);
    CHGraph bikeCHGraph = graph.getGraph(CHGraph.class, chWeightings.get(1));
    // enable both directions for bike
    EdgeIteratorState bikeSC02 = bikeCHGraph.shortcut(0, 2).setWeight(10).setFlags(PrepareEncoder.getScDirMask()).setDistance(20);
    // assert car CH graph
    assertTrue(carCHGraph.getEdgeIteratorState(carSC02.getEdge(), 2).isForward(tmpCar));
    assertFalse(carCHGraph.getEdgeIteratorState(carSC02.getEdge(), 2).isBackward(tmpCar));
    // throw exception for wrong encoder
    try {
        assertFalse(carCHGraph.getEdgeIteratorState(carSC02.getEdge(), 2).isForward(tmpBike));
        assertTrue(false);
    } catch (AssertionError ex) {
    }
    // assert bike CH graph
    assertTrue(bikeCHGraph.getEdgeIteratorState(bikeSC02.getEdge(), 2).isForward(tmpBike));
    assertTrue(bikeCHGraph.getEdgeIteratorState(bikeSC02.getEdge(), 2).isBackward(tmpBike));
    // throw exception for wrong encoder
    try {
        assertFalse(bikeCHGraph.getEdgeIteratorState(bikeSC02.getEdge(), 2).isBackward(tmpCar));
        assertTrue(false);
    } catch (AssertionError ex) {
    }
}
Also used : ArrayList(java.util.ArrayList) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Weighting(com.graphhopper.routing.weighting.Weighting) FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Test(org.junit.Test)

Example 23 with FastestWeighting

use of com.graphhopper.routing.weighting.FastestWeighting in project graphhopper by graphhopper.

the class GraphHopperStorageCHTest method testGetWeightIfAdvancedEncoder.

@Test
public void testGetWeightIfAdvancedEncoder() {
    FlagEncoder customEncoder = new Bike2WeightFlagEncoder();
    EncodingManager em = new EncodingManager(customEncoder);
    FastestWeighting weighting = new FastestWeighting(customEncoder);
    GraphHopperStorage ghStorage = new GraphBuilder(em).setCHGraph(weighting).create();
    ghStorage.edge(0, 2);
    ghStorage.freeze();
    CHGraphImpl lg = (CHGraphImpl) ghStorage.getGraph(CHGraph.class, weighting);
    CHEdgeIteratorState sc1 = lg.shortcut(0, 1);
    long flags = customEncoder.setProperties(10, false, true);
    sc1.setFlags(flags);
    sc1.setWeight(100.123);
    assertEquals(100.123, lg.getEdgeIteratorState(sc1.getEdge(), sc1.getAdjNode()).getWeight(), 1e-3);
    assertEquals(100.123, lg.getEdgeIteratorState(sc1.getEdge(), sc1.getBaseNode()).getWeight(), 1e-3);
    assertEquals(100.123, ((CHEdgeIteratorState) GHUtility.getEdge(lg, sc1.getBaseNode(), sc1.getAdjNode())).getWeight(), 1e-3);
    assertEquals(100.123, ((CHEdgeIteratorState) GHUtility.getEdge(lg, sc1.getAdjNode(), sc1.getBaseNode())).getWeight(), 1e-3);
    sc1 = lg.shortcut(1, 0);
    assertTrue(sc1.isShortcut());
    sc1.setFlags(PrepareEncoder.getScDirMask());
    sc1.setWeight(1.011011);
    assertEquals(1.011011, sc1.getWeight(), 1e-3);
}
Also used : FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Test(org.junit.Test)

Example 24 with FastestWeighting

use of com.graphhopper.routing.weighting.FastestWeighting 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)

Example 25 with FastestWeighting

use of com.graphhopper.routing.weighting.FastestWeighting in project graphhopper by graphhopper.

the class GHUtilityTest method testCopyWithSelfRef.

@Test
public void testCopyWithSelfRef() {
    Graph g = initUnsorted(createGraph());
    g.edge(0, 0, 11, true);
    CHGraph lg = new GraphBuilder(encodingManager).chGraphCreate(new FastestWeighting(carEncoder));
    GHUtility.copyTo(g, lg);
    assertEquals(g.getAllEdges().getMaxId(), lg.getAllEdges().getMaxId());
}
Also used : FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Test(org.junit.Test)

Aggregations

FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)32 Test (org.junit.Test)30 Weighting (com.graphhopper.routing.weighting.Weighting)14 ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)6 Graph (com.graphhopper.storage.Graph)5 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)4 EncodingManager (com.graphhopper.routing.util.EncodingManager)4 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)4 QueryResult (com.graphhopper.storage.index.QueryResult)4 GHPoint (com.graphhopper.util.shapes.GHPoint)3 BikeFlagEncoder (com.graphhopper.routing.util.BikeFlagEncoder)2 DefaultEdgeFilter (com.graphhopper.routing.util.DefaultEdgeFilter)2 EdgeFilter (com.graphhopper.routing.util.EdgeFilter)2 AbstractWeighting (com.graphhopper.routing.weighting.AbstractWeighting)2 GraphBuilder (com.graphhopper.storage.GraphBuilder)2 RAMDirectory (com.graphhopper.storage.RAMDirectory)2 SPTEntry (com.graphhopper.storage.SPTEntry)2 LocationIndex (com.graphhopper.storage.index.LocationIndex)2 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)2 EdgeExplorer (com.graphhopper.util.EdgeExplorer)2