Search in sources :

Example 16 with ShortestWeighting

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

the class PathTest method testCalcStreetNameDetails.

@Test
public void testCalcStreetNameDetails() {
    Path p = new Dijkstra(pathDetailGraph, new ShortestWeighting(encoder), TraversalMode.NODE_BASED).calcPath(1, 5);
    assertTrue(p.isFound());
    Map<String, List<PathDetail>> details = p.calcDetails(Arrays.asList(new String[] { STREET_NAME }), new PathDetailsBuilderFactory(), 0);
    assertTrue(details.size() == 1);
    List<PathDetail> streetNameDetails = details.get(STREET_NAME);
    assertTrue(details.size() == 1);
    assertEquals(4, streetNameDetails.size());
    assertEquals("1-2", streetNameDetails.get(0).getValue());
    assertEquals("2-3", streetNameDetails.get(1).getValue());
    assertEquals("3-4", streetNameDetails.get(2).getValue());
    assertEquals("4-5", streetNameDetails.get(3).getValue());
    assertEquals(0, streetNameDetails.get(0).getFirst());
    assertEquals(1, streetNameDetails.get(1).getFirst());
    assertEquals(2, streetNameDetails.get(2).getFirst());
    assertEquals(3, streetNameDetails.get(3).getFirst());
    assertEquals(4, streetNameDetails.get(3).getLast());
}
Also used : PathDetailsBuilderFactory(com.graphhopper.util.details.PathDetailsBuilderFactory) PathDetail(com.graphhopper.util.details.PathDetail) AbstractGraphStorageTester.assertPList(com.graphhopper.storage.AbstractGraphStorageTester.assertPList) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) Test(org.junit.Test)

Example 17 with ShortestWeighting

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

the class PathTest method testCalcAverageSpeedDetails.

@Test
public void testCalcAverageSpeedDetails() {
    Path p = new Dijkstra(pathDetailGraph, new ShortestWeighting(encoder), TraversalMode.NODE_BASED).calcPath(1, 5);
    assertTrue(p.isFound());
    Map<String, List<PathDetail>> details = p.calcDetails(Arrays.asList(new String[] { AVERAGE_SPEED }), new PathDetailsBuilderFactory(), 0);
    assertTrue(details.size() == 1);
    List<PathDetail> averageSpeedDetails = details.get(AVERAGE_SPEED);
    assertEquals(4, averageSpeedDetails.size());
    assertEquals(45.0, averageSpeedDetails.get(0).getValue());
    assertEquals(90.0, averageSpeedDetails.get(1).getValue());
    assertEquals(10.0, averageSpeedDetails.get(2).getValue());
    assertEquals(45.0, averageSpeedDetails.get(3).getValue());
    assertEquals(0, averageSpeedDetails.get(0).getFirst());
    assertEquals(1, averageSpeedDetails.get(1).getFirst());
    assertEquals(2, averageSpeedDetails.get(2).getFirst());
    assertEquals(3, averageSpeedDetails.get(3).getFirst());
    assertEquals(4, averageSpeedDetails.get(3).getLast());
}
Also used : PathDetailsBuilderFactory(com.graphhopper.util.details.PathDetailsBuilderFactory) PathDetail(com.graphhopper.util.details.PathDetail) AbstractGraphStorageTester.assertPList(com.graphhopper.storage.AbstractGraphStorageTester.assertPList) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) Test(org.junit.Test)

Example 18 with ShortestWeighting

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

the class AStarBidirectionTest method testInitFromAndTo.

@Test
public void testInitFromAndTo() {
    Graph g = createGHStorage(false);
    g.edge(0, 1, 1, true);
    updateDistancesFor(g, 0, 0.00, 0.00);
    updateDistancesFor(g, 1, 0.01, 0.01);
    final AtomicReference<AStar.AStarEntry> fromRef = new AtomicReference<AStar.AStarEntry>();
    final AtomicReference<AStar.AStarEntry> toRef = new AtomicReference<AStar.AStarEntry>();
    AStarBidirection astar = new AStarBidirection(g, new ShortestWeighting(carEncoder), traversalMode) {

        @Override
        public void initFrom(int from, double weight) {
            super.initFrom(from, weight);
            fromRef.set(currFrom);
        }

        @Override
        public void initTo(int to, double weight) {
            super.initTo(to, weight);
            toRef.set(currTo);
        }
    };
    astar.initFrom(0, 1);
    astar.initTo(1, 0.5);
    assertEquals(1, fromRef.get().weightOfVisitedPath, .1);
    assertEquals(787.3, fromRef.get().weight, .1);
    assertEquals(0.5, toRef.get().weightOfVisitedPath, .1);
    assertEquals(786.8, toRef.get().weight, .1);
}
Also used : Graph(com.graphhopper.storage.Graph) AtomicReference(java.util.concurrent.atomic.AtomicReference) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) Test(org.junit.Test)

Example 19 with ShortestWeighting

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

the class AbstractRoutingAlgorithmTester method setUp.

@Before
public void setUp() {
    carEncoder = (CarFlagEncoder) encodingManager.getEncoder("car");
    footEncoder = (FootFlagEncoder) encodingManager.getEncoder("foot");
    defaultOpts = AlgorithmOptions.start().weighting(new ShortestWeighting(carEncoder)).build();
}
Also used : ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) Before(org.junit.Before)

Example 20 with ShortestWeighting

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

the class AbstractRoutingAlgorithmTester method testWithCoordinates.

// a-b-0-c-1
// |   |  _/\
// |  /  /  |
// d-2--3-e-4
@Test
public void testWithCoordinates() {
    Weighting weighting = new ShortestWeighting(carEncoder);
    GraphHopperStorage graph = createGHStorage(encodingManager, Arrays.asList(weighting), false);
    graph.edge(0, 1, 2, true).setWayGeometry(Helper.createPointList(1.5, 1));
    graph.edge(2, 3, 2, true).setWayGeometry(Helper.createPointList(0, 1.5));
    graph.edge(3, 4, 2, true).setWayGeometry(Helper.createPointList(0, 2));
    // duplicate but the second edge is longer
    graph.edge(0, 2, 1.2, true);
    graph.edge(0, 2, 1.5, true).setWayGeometry(Helper.createPointList(0.5, 0));
    graph.edge(1, 3, 1.3, true).setWayGeometry(Helper.createPointList(0.5, 1.5));
    graph.edge(1, 4, 1, true);
    updateDistancesFor(graph, 0, 1, 0.6);
    updateDistancesFor(graph, 1, 1, 1.5);
    updateDistancesFor(graph, 2, 0, 0);
    updateDistancesFor(graph, 3, 0, 1);
    updateDistancesFor(graph, 4, 0, 2);
    AlgorithmOptions opts = new AlgorithmOptions(DIJKSTRA_BI, weighting);
    RoutingAlgorithmFactory prepare = createFactory(graph, opts);
    Path p = prepare.createAlgo(getGraph(graph, opts.getWeighting()), opts).calcPath(4, 0);
    assertEquals(Helper.createTList(4, 1, 0), p.calcNodes());
    assertEquals(Helper.createPointList(0, 2, 1, 1.5, 1.5, 1, 1, 0.6), p.calcPoints());
    assertEquals(274128, p.calcPoints().calcDistance(new DistanceCalcEarth()), 1);
    p = prepare.createAlgo(getGraph(graph, opts.getWeighting()), opts).calcPath(2, 1);
    assertEquals(Helper.createTList(2, 0, 1), p.calcNodes());
    assertEquals(Helper.createPointList(0, 0, 1, 0.6, 1.5, 1, 1, 1.5), p.calcPoints());
    assertEquals(279482, p.calcPoints().calcDistance(new DistanceCalcEarth()), 1);
}
Also used : FastestWeighting(com.graphhopper.routing.weighting.FastestWeighting) Weighting(com.graphhopper.routing.weighting.Weighting) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) ShortestWeighting(com.graphhopper.routing.weighting.ShortestWeighting) Test(org.junit.Test)

Aggregations

ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)20 Test (org.junit.Test)19 Graph (com.graphhopper.storage.Graph)9 Dijkstra (com.graphhopper.routing.Dijkstra)7 Path (com.graphhopper.routing.Path)7 GraphBuilder (com.graphhopper.storage.GraphBuilder)7 NodeAccess (com.graphhopper.storage.NodeAccess)6 PathDetailsBuilderFactory (com.graphhopper.util.details.PathDetailsBuilderFactory)5 AbstractGraphStorageTester.assertPList (com.graphhopper.storage.AbstractGraphStorageTester.assertPList)4 PathDetail (com.graphhopper.util.details.PathDetail)4 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)3 Weighting (com.graphhopper.routing.weighting.Weighting)3 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)2 EncodingManager (com.graphhopper.routing.util.EncodingManager)2 CHEdgeIteratorState (com.graphhopper.util.CHEdgeIteratorState)2 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)2 GraphHopper (com.graphhopper.GraphHopper)1 PathWrapper (com.graphhopper.PathWrapper)1 ReaderWay (com.graphhopper.reader.ReaderWay)1 GraphHopperOSM (com.graphhopper.reader.osm.GraphHopperOSM)1