Search in sources :

Example 1 with GraphHopperStorage

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

the class FastestWeightingTest method testTime.

@Test
public void testTime() {
    FlagEncoder tmpEnc = new Bike2WeightFlagEncoder();
    GraphHopperStorage g = new GraphBuilder(new EncodingManager(tmpEnc)).create();
    Weighting w = new FastestWeighting(tmpEnc);
    long flags = tmpEnc.setSpeed(tmpEnc.setReverseSpeed(tmpEnc.setAccess(0, true, true), 10), 15);
    EdgeIteratorState edge = GHUtility.createMockedEdgeIteratorState(100000, flags);
    assertEquals(375 * 60 * 1000, w.calcMillis(edge, false, EdgeIterator.NO_EDGE));
    assertEquals(600 * 60 * 1000, w.calcMillis(edge, true, EdgeIterator.NO_EDGE));
    g.close();
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) Bike2WeightFlagEncoder(com.graphhopper.routing.util.Bike2WeightFlagEncoder) Bike2WeightFlagEncoder(com.graphhopper.routing.util.Bike2WeightFlagEncoder) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) EdgeIteratorState(com.graphhopper.util.EdgeIteratorState) GHUtility.createMockedEdgeIteratorState(com.graphhopper.util.GHUtility.createMockedEdgeIteratorState) VirtualEdgeIteratorState(com.graphhopper.routing.VirtualEdgeIteratorState) GraphBuilder(com.graphhopper.storage.GraphBuilder) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Example 2 with GraphHopperStorage

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

the class Measurement method start.

// creates properties file in the format key=value
// Every value is one y-value in a separate diagram with an identical x-value for every Measurement.start call
void start(CmdArgs args) {
    String graphLocation = args.get("graph.location", "");
    String propLocation = args.get("measurement.location", "");
    if (Helper.isEmpty(propLocation))
        propLocation = "measurement" + new SimpleDateFormat("yyyy-MM-dd_HH_mm_ss").format(new Date()) + ".properties";
    seed = args.getLong("measurement.seed", 123);
    String gitCommit = args.get("measurement.gitinfo", "");
    int count = args.getInt("measurement.count", 5000);
    GraphHopper hopper = new GraphHopperOSM() {

        @Override
        protected void prepareCH() {
            StopWatch sw = new StopWatch().start();
            super.prepareCH();
            put(Parameters.CH.PREPARE + "time", sw.stop().getTime());
            int edges = getGraphHopperStorage().getAllEdges().getMaxId();
            if (getCHFactoryDecorator().hasWeightings()) {
                Weighting weighting = getCHFactoryDecorator().getWeightings().get(0);
                int edgesAndShortcuts = getGraphHopperStorage().getGraph(CHGraph.class, weighting).getAllEdges().getMaxId();
                put(Parameters.CH.PREPARE + "shortcuts", edgesAndShortcuts - edges);
            }
        }

        @Override
        protected DataReader importData() throws IOException {
            StopWatch sw = new StopWatch().start();
            DataReader dr = super.importData();
            put("graph.import_time", sw.stop().getSeconds());
            return dr;
        }
    };
    hopper.init(args).forDesktop();
    hopper.getCHFactoryDecorator().setDisablingAllowed(true);
    hopper.getLMFactoryDecorator().setDisablingAllowed(true);
    hopper.importOrLoad();
    GraphHopperStorage g = hopper.getGraphHopperStorage();
    String vehicleStr = args.get("graph.flag_encoders", "car");
    FlagEncoder encoder = hopper.getEncodingManager().getEncoder(vehicleStr);
    StopWatch sw = new StopWatch().start();
    try {
        maxNode = g.getNodes();
        boolean isCH = false;
        boolean isLM = false;
        GHBitSet allowedEdges = printGraphDetails(g, vehicleStr);
        printMiscUnitPerfTests(g, isCH, encoder, count * 100, allowedEdges);
        printLocationIndexQuery(g, hopper.getLocationIndex(), count);
        printTimeOfRouteQuery(hopper, isCH, isLM, count / 20, "routing", vehicleStr, true, -1);
        if (hopper.getLMFactoryDecorator().isEnabled()) {
            System.gc();
            isLM = true;
            int activeLMCount = 12;
            for (; activeLMCount > 3; activeLMCount -= 4) {
                printTimeOfRouteQuery(hopper, isCH, isLM, count / 4, "routingLM" + activeLMCount, vehicleStr, true, activeLMCount);
            }
        // compareRouting(hopper, vehicleStr, count / 5);
        }
        if (hopper.getCHFactoryDecorator().isEnabled()) {
            isCH = true;
            if (hopper.getLMFactoryDecorator().isEnabled()) {
                isLM = true;
                System.gc();
                // try just one constellation, often ~4-6 is best
                int lmCount = 5;
                printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCHLM" + lmCount, vehicleStr, true, lmCount);
            }
            isLM = false;
            System.gc();
            Weighting weighting = hopper.getCHFactoryDecorator().getWeightings().get(0);
            CHGraph lg = g.getGraph(CHGraph.class, weighting);
            fillAllowedEdges(lg.getAllEdges(), allowedEdges);
            printMiscUnitPerfTests(lg, isCH, encoder, count * 100, allowedEdges);
            printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH", vehicleStr, true, -1);
            printTimeOfRouteQuery(hopper, isCH, isLM, count, "routingCH_no_instr", vehicleStr, false, -1);
        }
        logger.info("store into " + propLocation);
    } catch (Exception ex) {
        logger.error("Problem while measuring " + graphLocation, ex);
        put("error", ex.toString());
    } finally {
        put("measurement.gitinfo", gitCommit);
        put("measurement.count", count);
        put("measurement.seed", seed);
        put("measurement.time", sw.stop().getTime());
        System.gc();
        put("measurement.totalMB", Helper.getTotalMB());
        put("measurement.usedMB", Helper.getUsedMB());
        try {
            store(new FileWriter(propLocation), "measurement finish, " + new Date().toString() + ", " + Constants.BUILD_DATE);
        } catch (IOException ex) {
            logger.error("Problem while storing properties " + graphLocation + ", " + propLocation, ex);
        }
    }
}
Also used : GHBitSet(com.graphhopper.coll.GHBitSet) FileWriter(java.io.FileWriter) GraphHopperOSM(com.graphhopper.reader.osm.GraphHopperOSM) GraphHopper(com.graphhopper.GraphHopper) IOException(java.io.IOException) Date(java.util.Date) IOException(java.io.IOException) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) DataReader(com.graphhopper.reader.DataReader) Weighting(com.graphhopper.routing.weighting.Weighting) CHGraph(com.graphhopper.storage.CHGraph) SimpleDateFormat(java.text.SimpleDateFormat)

Example 3 with GraphHopperStorage

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

the class OSMTurnRelationTest method testGetRestrictionAsEntries.

@Test
public void testGetRestrictionAsEntries() {
    CarFlagEncoder encoder = new CarFlagEncoder(5, 5, 1);
    final Map<Long, Integer> osmNodeToInternal = new HashMap<Long, Integer>();
    final Map<Integer, Long> internalToOSMEdge = new HashMap<Integer, Long>();
    osmNodeToInternal.put(3L, 3);
    // edge ids are only stored if they occured before in an OSMRelation
    internalToOSMEdge.put(3, 3L);
    internalToOSMEdge.put(4, 4L);
    GraphHopperStorage ghStorage = new GraphBuilder(new EncodingManager(encoder)).create();
    EdgeBasedRoutingAlgorithmTest.initGraph(ghStorage);
    OSMReader osmReader = new OSMReader(ghStorage) {

        @Override
        public int getInternalNodeIdOfOsmNode(long nodeOsmId) {
            return osmNodeToInternal.get(nodeOsmId);
        }

        @Override
        public long getOsmIdOfInternalEdge(int edgeId) {
            Long l = internalToOSMEdge.get(edgeId);
            if (l == null)
                return -1;
            return l;
        }
    };
    EdgeExplorer edgeExplorer = ghStorage.createEdgeExplorer();
    // TYPE == ONLY
    OSMTurnRelation instance = new OSMTurnRelation(4, 3, 3, Type.ONLY);
    Collection<OSMTurnRelation.TurnCostTableEntry> result = instance.getRestrictionAsEntries(encoder, edgeExplorer, edgeExplorer, osmReader);
    assertEquals(2, result.size());
    Iterator<OSMTurnRelation.TurnCostTableEntry> iter = result.iterator();
    OSMTurnRelation.TurnCostTableEntry entry = iter.next();
    assertEquals(4, entry.edgeFrom);
    assertEquals(6, entry.edgeTo);
    assertEquals(3, entry.nodeVia);
    entry = iter.next();
    assertEquals(4, entry.edgeFrom);
    assertEquals(2, entry.edgeTo);
    assertEquals(3, entry.nodeVia);
    // TYPE == NOT
    instance = new OSMTurnRelation(4, 3, 3, Type.NOT);
    result = instance.getRestrictionAsEntries(encoder, edgeExplorer, edgeExplorer, osmReader);
    assertEquals(1, result.size());
    iter = result.iterator();
    entry = iter.next();
    assertEquals(4, entry.edgeFrom);
    assertEquals(3, entry.edgeTo);
    assertEquals(3, entry.nodeVia);
}
Also used : EncodingManager(com.graphhopper.routing.util.EncodingManager) HashMap(java.util.HashMap) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) EdgeExplorer(com.graphhopper.util.EdgeExplorer) GraphBuilder(com.graphhopper.storage.GraphBuilder) CarFlagEncoder(com.graphhopper.routing.util.CarFlagEncoder) Test(org.junit.Test) EdgeBasedRoutingAlgorithmTest(com.graphhopper.routing.EdgeBasedRoutingAlgorithmTest)

Example 4 with GraphHopperStorage

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

the class RoutingAlgorithmIT method createAlgos.

public static List<AlgoHelperEntry> createAlgos(final GraphHopper hopper, final HintsMap hints, TraversalMode tMode) {
    GraphHopperStorage ghStorage = hopper.getGraphHopperStorage();
    LocationIndex idx = hopper.getLocationIndex();
    String addStr = "";
    if (tMode.isEdgeBased())
        addStr = "turn|";
    FlagEncoder encoder = hopper.getEncodingManager().getEncoder(hints.getVehicle());
    Weighting weighting = hopper.createWeighting(hints, encoder, hopper.getGraphHopperStorage());
    HintsMap defaultHints = new HintsMap().put(Parameters.CH.DISABLE, true).put(Parameters.Landmark.DISABLE, true).setVehicle(hints.getVehicle()).setWeighting(hints.getWeighting());
    AlgorithmOptions defaultOpts = AlgorithmOptions.start(new AlgorithmOptions("", weighting, tMode)).hints(defaultHints).build();
    List<AlgoHelperEntry> prepare = new ArrayList<>();
    prepare.add(new AlgoHelperEntry(ghStorage, AlgorithmOptions.start(defaultOpts).algorithm(ASTAR).build(), idx, "astar|beeline|" + addStr + weighting));
    // later: include dijkstraOneToMany
    prepare.add(new AlgoHelperEntry(ghStorage, AlgorithmOptions.start(defaultOpts).algorithm(DIJKSTRA).build(), idx, "dijkstra|" + addStr + weighting));
    AlgorithmOptions astarbiOpts = AlgorithmOptions.start(defaultOpts).algorithm(ASTAR_BI).build();
    astarbiOpts.getHints().put(ASTAR_BI + ".approximation", "BeelineSimplification");
    AlgorithmOptions dijkstrabiOpts = AlgorithmOptions.start(defaultOpts).algorithm(DIJKSTRA_BI).build();
    prepare.add(new AlgoHelperEntry(ghStorage, astarbiOpts, idx, "astarbi|beeline|" + addStr + weighting));
    prepare.add(new AlgoHelperEntry(ghStorage, dijkstrabiOpts, idx, "dijkstrabi|" + addStr + weighting));
    // add additional preparations if CH and LM preparation are enabled
    if (hopper.getLMFactoryDecorator().isEnabled()) {
        final HintsMap lmHints = new HintsMap(defaultHints).put(Parameters.Landmark.DISABLE, false);
        prepare.add(new AlgoHelperEntry(ghStorage, AlgorithmOptions.start(astarbiOpts).hints(lmHints).build(), idx, "astarbi|landmarks|" + weighting) {

            @Override
            public RoutingAlgorithmFactory createRoutingFactory() {
                return hopper.getAlgorithmFactory(lmHints);
            }
        });
    }
    if (hopper.getCHFactoryDecorator().isEnabled()) {
        final HintsMap chHints = new HintsMap(defaultHints).put(Parameters.CH.DISABLE, false);
        Weighting pickedWeighting = null;
        for (Weighting tmpWeighting : hopper.getCHFactoryDecorator().getWeightings()) {
            if (tmpWeighting.equals(weighting)) {
                pickedWeighting = tmpWeighting;
                break;
            }
        }
        if (pickedWeighting == null)
            throw new IllegalStateException("Didn't find weighting " + hints.getWeighting() + " in " + hopper.getCHFactoryDecorator().getWeightings());
        prepare.add(new AlgoHelperEntry(ghStorage.getGraph(CHGraph.class, pickedWeighting), AlgorithmOptions.start(dijkstrabiOpts).hints(chHints).build(), idx, "dijkstrabi|ch|prepare|" + hints.getWeighting()) {

            @Override
            public RoutingAlgorithmFactory createRoutingFactory() {
                return hopper.getAlgorithmFactory(chHints);
            }
        });
        prepare.add(new AlgoHelperEntry(ghStorage.getGraph(CHGraph.class, pickedWeighting), AlgorithmOptions.start(astarbiOpts).hints(chHints).build(), idx, "astarbi|ch|prepare|" + hints.getWeighting()) {

            @Override
            public RoutingAlgorithmFactory createRoutingFactory() {
                return hopper.getAlgorithmFactory(chHints);
            }
        });
    }
    return prepare;
}
Also used : HintsMap(com.graphhopper.routing.util.HintsMap) AlgoHelperEntry(com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry) FlagEncoder(com.graphhopper.routing.util.FlagEncoder) ArrayList(java.util.ArrayList) LocationIndex(com.graphhopper.storage.index.LocationIndex) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Weighting(com.graphhopper.routing.weighting.Weighting)

Example 5 with GraphHopperStorage

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

the class PrepareRoutingSubnetworksTest method testRemoveSubnetworkIfOnlyOneVehicle.

@Test
public void testRemoveSubnetworkIfOnlyOneVehicle() {
    GraphHopperStorage g = createSubnetworkTestStorage2(em);
    PrepareRoutingSubnetworks instance = new PrepareRoutingSubnetworks(g, em.fetchEdgeEncoders());
    instance.setMinNetworkSize(4);
    instance.doWork();
    g.optimize();
    assertEquals(6, g.getNodes());
    assertEquals(Arrays.<String>asList(), GHUtility.getProblems(g));
    EdgeExplorer explorer = g.createEdgeExplorer();
    assertEquals(GHUtility.asSet(2, 1, 5), GHUtility.getNeighbors(explorer.setBaseNode(3)));
    // do not remove because small network is big enough
    g = createSubnetworkTestStorage2(em);
    instance = new PrepareRoutingSubnetworks(g, em.fetchEdgeEncoders());
    instance.setMinNetworkSize(3);
    instance.doWork();
    g.optimize();
    assertEquals(9, g.getNodes());
}
Also used : EdgeExplorer(com.graphhopper.util.EdgeExplorer) GraphHopperStorage(com.graphhopper.storage.GraphHopperStorage) Test(org.junit.Test)

Aggregations

GraphHopperStorage (com.graphhopper.storage.GraphHopperStorage)33 Test (org.junit.Test)25 GraphBuilder (com.graphhopper.storage.GraphBuilder)8 EncodingManager (com.graphhopper.routing.util.EncodingManager)7 PrepEdgeFilter (com.graphhopper.routing.subnetwork.PrepareRoutingSubnetworks.PrepEdgeFilter)6 EdgeIteratorState (com.graphhopper.util.EdgeIteratorState)5 IntArrayList (com.carrotsearch.hppc.IntArrayList)4 FastestWeighting (com.graphhopper.routing.weighting.FastestWeighting)4 EdgeExplorer (com.graphhopper.util.EdgeExplorer)4 CarFlagEncoder (com.graphhopper.routing.util.CarFlagEncoder)3 FlagEncoder (com.graphhopper.routing.util.FlagEncoder)3 Weighting (com.graphhopper.routing.weighting.Weighting)3 RAMDirectory (com.graphhopper.storage.RAMDirectory)3 TurnCostExtension (com.graphhopper.storage.TurnCostExtension)3 GraphHopper (com.graphhopper.GraphHopper)2 EdgeFilter (com.graphhopper.routing.util.EdgeFilter)2 HintsMap (com.graphhopper.routing.util.HintsMap)2 AlgoHelperEntry (com.graphhopper.routing.util.TestAlgoCollector.AlgoHelperEntry)2 CHGraph (com.graphhopper.storage.CHGraph)2 GraphExtension (com.graphhopper.storage.GraphExtension)2