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());
}
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());
}
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);
}
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();
}
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);
}
Aggregations