Search in sources :

Example 26 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 27 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 28 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 29 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)

Example 30 with FastestWeighting

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

the class AbstractRoutingAlgorithmTester method testMultipleVehicles_issue548.

@Test
public void testMultipleVehicles_issue548() {
    FastestWeighting footWeighting = new FastestWeighting(footEncoder);
    AlgorithmOptions footOptions = AlgorithmOptions.start().weighting(footWeighting).build();
    FastestWeighting carWeighting = new FastestWeighting(carEncoder);
    AlgorithmOptions carOptions = AlgorithmOptions.start().weighting(carWeighting).build();
    GraphHopperStorage ghStorage = createGHStorage(encodingManager, Arrays.asList(footOptions.getWeighting(), carOptions.getWeighting()), false);
    initFootVsCar(ghStorage);
    // normal path would be 0-4-6-7 but block 4-6
    GHUtility.getEdge(ghStorage, 4, 6).setFlags(carEncoder.setProperties(20, false, false));
    RoutingAlgorithm algoFoot = createFactory(ghStorage, footOptions).createAlgo(getGraph(ghStorage, footWeighting), footOptions);
    RoutingAlgorithm algoCar = createFactory(ghStorage, carOptions).createAlgo(getGraph(ghStorage, carWeighting), carOptions);
    Path p1 = algoCar.calcPath(0, 7);
    assertEquals(Helper.createTList(0, 1, 5, 6, 7), p1.calcNodes());
    assertEquals(p1.toString(), 26000, p1.getDistance(), 1e-6);
}
Also used : FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Test(org.junit.Test)

Aggregations

FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)35 Test (org.junit.Test)33 Weighting (com.graphhopper.routing.weighting.Weighting)15 ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)6 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)5 QueryResult (com.graphhopper.storage.index.QueryResult)5 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)4 EncodingManager (com.graphhopper.routing.util.EncodingManager)4 Graph (com.graphhopper.storage.Graph)4 GHPoint (com.graphhopper.util.shapes.GHPoint)4 RAMDirectory (com.graphhopper.storage.RAMDirectory)3 LocationIndex (com.graphhopper.storage.index.LocationIndex)3 LocationIndexTree (com.graphhopper.storage.index.LocationIndexTree)3 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)3 GHRequest (com.graphhopper.GHRequest)2 GHResponse (com.graphhopper.GHResponse)2 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