Search in sources :

Example 56 with GraphBuilder

use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.

the class ChangeGraphHelperTest method setUp.

@Before
public void setUp() {
    encodingManager = new EncodingManager("car");
    graph = new GraphBuilder(encodingManager).create();
    ghson = new GHJsonFactory().create();
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) GHJsonFactory(com.graphhopper.json.GHJsonFactory) GraphBuilder(com.graphhopper.storage.GraphBuilder) Before(org.junit.Before)

Example 57 with GraphBuilder

use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.

the class RoutingAlgorithmIT method testPerformance.

@Test
public void testPerformance() throws IOException {
    int N = 10;
    int noJvmWarming = N / 4;
    Random rand = new Random(0);
    final EncodingManager eManager = new EncodingManager("car");
    final GraphHopperStorage graph = new GraphBuilder(eManager).create();
    String bigFile = "10000EWD.txt.gz";
    new PrincetonReader(graph).setStream(new GZIPInputStream(PrincetonReader.class.getResourceAsStream(bigFile))).read();
    GraphHopper hopper = new GraphHopper() {

        {
            setCHEnabled(false);
            setEncodingManager(eManager);
            loadGraph(graph);
        }

        @Override
        protected LocationIndex createLocationIndex(Directory dir) {
            return new LocationIndexTree(graph, dir);
        }
    };
    Collection<AlgoHelperEntry> prepares = createAlgos(hopper, new HintsMap().setWeighting("shortest").setVehicle("car"), TraversalMode.NODE_BASED);
    for (AlgoHelperEntry entry : prepares) {
        StopWatch sw = new StopWatch();
        for (int i = 0; i < N; i++) {
            int node1 = Math.abs(rand.nextInt(graph.getNodes()));
            int node2 = Math.abs(rand.nextInt(graph.getNodes()));
            RoutingAlgorithm d = entry.createRoutingFactory().createAlgo(graph, entry.getAlgorithmOptions());
            if (i >= noJvmWarming)
                sw.start();
            Path p = d.calcPath(node1, node2);
            // avoid jvm optimization => call p.distance
            if (i >= noJvmWarming && p.getDistance() > -1)
                sw.stop();
        // System.out.println("#" + i + " " + name + ":" + sw.getSeconds() + " " + p.nodes());
        }
        float perRun = sw.stop().getSeconds() / ((float) (N - noJvmWarming));
        System.out.println("# " + getClass().getSimpleName() + " " + entry + ":" + sw.stop().getSeconds() + ", per run:" + perRun);
        assertTrue("speed to low!? " + perRun + " per run", perRun < 0.08);
    }
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) AlgoHelperEntry(com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry) HintsMap(com.graphhopper.routing.util.HintsMap) PrincetonReader(com.graphhopper.reader.PrincetonReader) GraphHopper(com.graphhopper.GraphHopper) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) LocationIndexTree(com.graphhopper.storage.index.LocationIndexTree) StopWatch(com.graphhopper.util.StopWatch) GZIPInputStream(java.util.zip.GZIPInputStream) Random(java.util.Random) GraphBuilder(com.graphhopper.storage.GraphBuilder) Directory(com.graphhopper.storage.Directory) Test(org.junit.Test)

Example 58 with GraphBuilder

use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.

the class DataFlagEncoderTest method testSpatialId.

@Test
public void testSpatialId() {
    final GermanySpatialRule germany = new GermanySpatialRule();
    germany.setBorders(Collections.singletonList(new Polygon(new double[] { 0, 0, 1, 1 }, new double[] { 0, 1, 1, 0 })));
    SpatialRuleLookup index = new SpatialRuleLookup() {

        @Override
        public SpatialRule lookupRule(double lat, double lon) {
            for (Polygon polygon : germany.getBorders()) {
                if (polygon.contains(lat, lon)) {
                    return germany;
                }
            }
            return SpatialRule.EMPTY;
        }

        @Override
        public SpatialRule lookupRule(GHPoint point) {
            return lookupRule(point.lat, point.lon);
        }

        @Override
        public int getSpatialId(SpatialRule rule) {
            if (germany.equals(rule)) {
                return 1;
            } else {
                return 0;
            }
        }

        @Override
        public int size() {
            return 2;
        }

        @Override
        public BBox getBounds() {
            return new BBox(-180, 180, -90, 90);
        }
    };
    DataFlagEncoder encoder = new DataFlagEncoder(new PMap());
    encoder.setSpatialRuleLookup(index);
    EncodingManager em = new EncodingManager(encoder);
    ReaderWay way = new ReaderWay(27l);
    way.setTag("highway", "track");
    way.setTag("estimated_center", new GHPoint(0.005, 0.005));
    ReaderWay way2 = new ReaderWay(28l);
    way2.setTag("highway", "track");
    way2.setTag("estimated_center", new GHPoint(-0.005, -0.005));
    ReaderWay livingStreet = new ReaderWay(29l);
    livingStreet.setTag("highway", "living_street");
    livingStreet.setTag("estimated_center", new GHPoint(0.005, 0.005));
    ReaderWay livingStreet2 = new ReaderWay(30l);
    livingStreet2.setTag("highway", "living_street");
    livingStreet2.setTag("estimated_center", new GHPoint(-0.005, -0.005));
    Graph graph = new GraphBuilder(em).create();
    EdgeIteratorState e1 = graph.edge(0, 1, 1, true);
    EdgeIteratorState e2 = graph.edge(0, 2, 1, true);
    EdgeIteratorState e3 = graph.edge(0, 3, 1, true);
    EdgeIteratorState e4 = graph.edge(0, 4, 1, true);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 0, 0.00, 0.00);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 1, 0.01, 0.01);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 2, -0.01, -0.01);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 3, 0.01, 0.01);
    AbstractRoutingAlgorithmTester.updateDistancesFor(graph, 4, -0.01, -0.01);
    e1.setFlags(encoder.handleWayTags(way, 1, 0));
    e2.setFlags(encoder.handleWayTags(way2, 1, 0));
    e3.setFlags(encoder.handleWayTags(livingStreet, 1, 0));
    e4.setFlags(encoder.handleWayTags(livingStreet2, 1, 0));
    assertEquals(index.getSpatialId(new GermanySpatialRule()), encoder.getSpatialId(e1.getFlags()));
    assertEquals(index.getSpatialId(SpatialRule.EMPTY), encoder.getSpatialId(e2.getFlags()));
    assertEquals(AccessValue.EVENTUALLY_ACCESSIBLE, encoder.getAccessValue(e1.getFlags()));
    assertEquals(AccessValue.ACCESSIBLE, encoder.getAccessValue(e2.getFlags()));
    assertEquals(5, encoder.getMaxspeed(e3, -1, false), .1);
    assertEquals(-1, encoder.getMaxspeed(e4, -1, false), .1);
}
Also used : PMap(com.graphhopper.util.PMap) GermanySpatialRule(com.graphhopper.routing.util.spatialrules.countries.GermanySpatialRule) ReaderWay(com.graphhopper.reader.ReaderWay) Graph(com.graphhopper.storage.Graph) BBox(com.graphhopper.util.shapes.BBox) GraphBuilder(com.graphhopper.storage.GraphBuilder) GHPoint(com.graphhopper.util.shapes.GHPoint) GermanySpatialRule(com.graphhopper.routing.util.spatialrules.countries.GermanySpatialRule) Test(org.junit.Test)

Example 59 with GraphBuilder

use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.

the class GenericWeightingTest method testDisabledRoadAttributes.

@Test
public void testDisabledRoadAttributes() {
    DataFlagEncoder simpleEncoder = new DataFlagEncoder();
    EncodingManager simpleEncodingManager = new EncodingManager(simpleEncoder);
    Graph simpleGraph = new GraphBuilder(simpleEncodingManager).create();
    ReaderWay way = new ReaderWay(27l);
    way.setTag("highway", "primary");
    way.setTag("maxspeed", "10");
    way.setTag("maxheight", "4.4");
    // 0-1
    simpleGraph.edge(0, 1, 1, true);
    AbstractRoutingAlgorithmTester.updateDistancesFor(simpleGraph, 0, 0.00, 0.00);
    AbstractRoutingAlgorithmTester.updateDistancesFor(simpleGraph, 1, 0.01, 0.01);
    simpleGraph.getEdgeIteratorState(0, 1).setFlags(simpleEncoder.handleWayTags(way, 1, 0));
    Weighting instance = new GenericWeighting(simpleEncoder, new HintsMap().put(GenericWeighting.HEIGHT_LIMIT, 5.0));
    EdgeIteratorState edge = simpleGraph.getEdgeIteratorState(0, 1);
    assertEquals(edgeWeight, instance.calcWeight(edge, false, EdgeIterator.NO_EDGE), 1e-8);
}
Also used : DataFlagEncoder(com.graphhopper.routing.util.DataFlagEncoder) EncodingManager(com.graphhopper.routing.util.EncodingManager) HintsMap(com.graphhopper.routing.util.HintsMap) Graph(com.graphhopper.storage.Graph) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) GraphBuilder(com.graphhopper.storage.GraphBuilder) ReaderWay(com.graphhopper.reader.ReaderWay) Test(org.junit.Test)

Example 60 with GraphBuilder

use of com.graphhopper.storage.GraphBuilder in project graphhopper by graphhopper.

the class PrincetonReaderTest method testMediumRead.

@Test
public void testMediumRead() throws IOException {
    Graph graph = new GraphBuilder(encodingManager).create();
    new PrincetonReader(graph).setStream(new GZIPInputStream(PrincetonReader.class.getResourceAsStream("mediumEWD.txt.gz"))).read();
    assertEquals(250, graph.getNodes());
    EdgeExplorer explorer = graph.createEdgeExplorer(carOutEdges);
    assertEquals(13, count(explorer.setBaseNode(244)));
    assertEquals(11, count(explorer.setBaseNode(16)));
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) Graph(com.graphhopper.storage.Graph) EdgeExplorer(com.graphhopper.util.EdgeExplorer) GraphBuilder(com.graphhopper.storage.GraphBuilder) Test(org.junit.Test)

Aggregations

GraphBuilder (com.graphhopper.storage.GraphBuilder)98 Test (org.junit.jupiter.api.Test)60 Graph (com.graphhopper.storage.Graph)48 GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)40 NodeAccess (com.graphhopper.storage.NodeAccess)30 ShortestWeighting (com.graphhopper.routing.weighting.ShortestWeighting)22 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)21 EncodingManager (com.graphhopper.routing.util.EncodingManager)19 Test (org.junit.Test)16 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)15 RepeatedTest (org.junit.jupiter.api.RepeatedTest)14 ConnectedComponents (com.graphhopper.routing.subnetwork.EdgeBasedTarjanSCC.ConnectedComponents)12 Dijkstra (com.graphhopper.routing.Dijkstra)10 Path (com.graphhopper.routing.Path)10 ReaderWay (com.graphhopper.reader.ReaderWay)9 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)8 BeforeEach (org.junit.jupiter.api.BeforeEach)7 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)6 IntsRef (com.graphhopper.storage.IntsRef)6 Random (java.util.Random)6