Tabnine Logo
PrepareContractionHierarchies
Code IndexAdd Tabnine to your IDE (free)

How to use
PrepareContractionHierarchies
in
com.graphhopper.routing.ch

Best Java code snippets using com.graphhopper.routing.ch.PrepareContractionHierarchies (Showing top 20 results out of 315)

origin: graphhopper/graphhopper

public CHAlgoFactoryDecorator addPreparation(PrepareContractionHierarchies pch) {
  preparations.add(pch);
  int lastIndex = preparations.size() - 1;
  if (lastIndex >= weightings.size())
    throw new IllegalStateException("Cannot access weighting for PrepareContractionHierarchies with " + pch.getWeighting()
        + ". Call add(Weighting) before");
  if (preparations.get(lastIndex).getWeighting() != weightings.get(lastIndex))
    throw new IllegalArgumentException("Weighting of PrepareContractionHierarchies " + preparations.get(lastIndex).getWeighting()
        + " needs to be identical to previously added " + weightings.get(lastIndex));
  return this;
}
origin: graphhopper/graphhopper

  private RoutingAlgorithm createCHAlgo(GraphHopperStorage graph, CHGraph chGraph, boolean withSOD, AlgorithmOptions algorithmOptions) {
    PrepareContractionHierarchies ch = new PrepareContractionHierarchies(
        chGraph, algorithmOptions.getWeighting(), TraversalMode.NODE_BASED);
    if (!withSOD) {
      algorithmOptions.getHints().put("stall_on_demand", false);
    }
    return ch.createAlgo(chGraph, algorithmOptions);
  }
}
origin: graphhopper/graphhopper

void checkPath(GraphHopperStorage g, Weighting w, int expShortcuts, double expDistance, IntIndexedContainer expNodes) {
  CHGraph lg = g.getGraph(CHGraph.class, w);
  PrepareContractionHierarchies prepare = createPrepareContractionHierarchies(g, lg, w);
  prepare.doWork();
  assertEquals(w.toString(), expShortcuts, prepare.getShortcuts());
  RoutingAlgorithm algo = prepare.createAlgo(lg, new AlgorithmOptions(DIJKSTRA_BI, w, tMode));
  Path p = algo.calcPath(3, 12);
  assertEquals(w.toString(), expDistance, p.getDistance(), 1e-5);
  assertEquals(w.toString(), expNodes, p.calcNodes());
}
origin: graphhopper/graphhopper

protected void runGraphContraction() {
  if (!prepareNodes())
    return;
  contractNodes();
}
origin: graphhopper/graphhopper

@Override
public RoutingAlgorithmFactory createFactory(GraphHopperStorage ghStorage, AlgorithmOptions opts) {
  ghStorage.freeze();
  PrepareContractionHierarchies ch = PrepareContractionHierarchies.fromGraphHopperStorage(
      ghStorage, opts.getWeighting(), TraversalMode.NODE_BASED);
  ch.doWork();
  return ch;
}
origin: com.rgi-corp/graphhopper

      int priority = oldPriorities[node] = calculatePriority(node);
      sortedNodes.insert(node, priority);
        + ", shortcuts:" + Helper.nf(newShortcuts)
        + ", dijkstras:" + Helper.nf(dijkstraCount)
        + ", " + getTimesAsString()
        + ", meanDegree:" + (long) meanDegree
        + ", algo:" + prepareAlgo.getMemoryUsageAsString()
    int priority = oldPriorities[polledNode] = calculatePriority(polledNode);
    if (priority > sortedNodes.peekValue()) {
  findShortcuts(addScHandler.setNode(polledNode));
  newShortcuts += addShortcuts(shortcuts.keySet());
  prepareGraph.setLevel(polledNode, level);
  level++;
      neighborSW.start();
      int oldPrio = oldPriorities[nn];
      int priority = oldPriorities[nn] = calculatePriority(nn);
      if (priority != oldPrio)
        sortedNodes.update(nn, oldPrio, priority);
close();
    + ", " + prepareWeighting
    + ", dijkstras:" + dijkstraCount
    + ", " + getTimesAsString()
    + ", meanDegree:" + (long) meanDegree
origin: com.rgi-corp/graphhopper

public void createPreparations(GraphHopperStorage ghStorage, TraversalMode traversalMode) {
  if (!isEnabled() || !preparations.isEmpty())
    return;
  if (weightings.isEmpty())
    throw new IllegalStateException("No CH weightings found");
  traversalMode = getNodeBase();
  for (Weighting weighting : getWeightings()) {
    if (weighting instanceof GenericWeighting) {
      ((GenericWeighting) weighting).setGraph(ghStorage);
    }
    PrepareContractionHierarchies tmpPrepareCH = new PrepareContractionHierarchies(
        new GHDirectory("", DAType.RAM_INT), ghStorage, ghStorage.getGraph(CHGraph.class, weighting),
        weighting, traversalMode);
    tmpPrepareCH.setPeriodicUpdates(preparationPeriodicUpdates).
        setLazyUpdates(preparationLazyUpdates).
        setNeighborUpdates(preparationNeighborUpdates).
        setLogMessages(preparationLogMessages);
    addPreparation(tmpPrepareCH);
  }
}
origin: com.rgi-corp/graphhopper

@Override
public void doWork() {
  if (prepareWeighting == null)
    throw new IllegalStateException("No weight calculation set.");
  allSW.start();
  super.doWork();
  initFromGraph();
  if (!prepareNodes())
    return;
  contractNodes();
}
origin: graphhopper/graphhopper

@Override
public void doSpecificWork() {
  allSW.start();
  initFromGraph();
  runGraphContraction();
  logger.info("took:" + (int) allSW.stop().getSeconds() + "s "
      + ", new shortcuts: " + nf(nodeContractor.getAddedShortcutsCount())
      + ", initSize:" + nf(initSize)
      + ", " + prepareWeighting
      + ", periodic:" + params.getPeriodicUpdatesPercentage()
      + ", lazy:" + params.getLastNodesLazyUpdatePercentage()
      + ", neighbor:" + params.getNeighborUpdatePercentage()
      + ", " + getTimesAsString()
      + ", lazy-overhead: " + (int) (100 * ((checkCounter / (double) initSize) - 1)) + "%"
      + ", " + Helper.getMemInfo());
  int edgeCount = prepareGraph.getOriginalEdges();
  logger.info("graph now - num edges: {}, num nodes: {}, num shortcuts: {}",
      nf(edgeCount), nf(prepareGraph.getNodes()), nf(prepareGraph.getEdges() - edgeCount));
}
origin: graphhopper/graphhopper

        continue;
      float priority = oldPriorities[node] = calculatePriority(node);
      sortedNodes.insert(node, priority);
    logStats(updateCounter);
    float priority = oldPriorities[polledNode] = calculatePriority(polledNode);
    if (priority > sortedNodes.peekValue()) {
      neighborUpdateSW.start();
      float oldPrio = oldPriorities[nn];
      float priority = oldPriorities[nn] = calculatePriority(nn);
      if (priority != oldPrio)
        sortedNodes.update(nn, oldPrio, priority);
logStats(updateCounter);
close();
origin: graphhopper/graphhopper

  @Override
  public void run() {
    // toString is not taken into account so we need to cheat, see http://stackoverflow.com/q/6113746/194609 for other options
    Thread.currentThread().setName(name);
    prepare.doWork();
    properties.put(CH.PREPARE + "date." + name, createFormatter().format(new Date()));
  }
}, name);
origin: graphhopper/graphhopper

@Test
public void testCircleBug() {
  GraphHopperStorage g = createGHStorage();
  CHGraph lg = g.getGraph(CHGraph.class);
  //  /--1
  // -0--/
  //  |
  g.edge(0, 1, 10, true);
  g.edge(0, 1, 4, true);
  g.edge(0, 2, 10, true);
  g.edge(0, 3, 10, true);
  PrepareContractionHierarchies prepare = createPrepareContractionHierarchies(g, lg);
  prepare.doWork();
  assertEquals(0, prepare.getShortcuts());
}
origin: graphhopper/graphhopper

private boolean prepareNodes() {
  int nodes = prepareGraph.getNodes();
  for (int node = 0; node < nodes; node++) {
    prepareGraph.setLevel(node, maxLevel);
  }
  periodicUpdateSW.start();
  for (int node = 0; node < nodes; node++) {
    float priority = oldPriorities[node] = calculatePriority(node);
    sortedNodes.insert(node, priority);
  }
  periodicUpdateSW.stop();
  return !sortedNodes.isEmpty();
}
origin: graphhopper/graphhopper

public static PrepareContractionHierarchies fromGraphHopperStorage(GraphHopperStorage ghStorage, Weighting weighting, TraversalMode traversalMode) {
  return new PrepareContractionHierarchies(ghStorage.getGraph(CHGraph.class, weighting), weighting, traversalMode);
}
origin: graphhopper/graphhopper

@Test
public void testRoundaboutUnpacking() {
  GraphHopperStorage g = createGHStorage();
  CHGraph lg = g.getGraph(CHGraph.class);
  initRoundaboutGraph(g);
  int oldCount = g.getAllEdges().length();
  PrepareContractionHierarchies prepare = createPrepareContractionHierarchies(g, lg);
  prepare.doWork();
  assertEquals(oldCount, g.getEdges());
  assertEquals(oldCount + 23, lg.getEdges());
  RoutingAlgorithm algo = prepare.createAlgo(lg, new AlgorithmOptions(DIJKSTRA_BI, weighting, tMode));
  Path p = algo.calcPath(4, 7);
  assertEquals(IntArrayList.from(4, 5, 6, 7), p.calcNodes());
}
origin: com.graphhopper/graphhopper-core

public void createPreparations(GraphHopperStorage ghStorage, TraversalMode traversalMode) {
  if (!isEnabled() || !preparations.isEmpty())
    return;
  if (weightings.isEmpty())
    throw new IllegalStateException("No CH weightings found");
  traversalMode = getNodeBase();
  for (Weighting weighting : getWeightings()) {
    PrepareContractionHierarchies tmpPrepareCH = new PrepareContractionHierarchies(
        new GHDirectory("", DAType.RAM_INT), ghStorage, ghStorage.getGraph(CHGraph.class, weighting), traversalMode);
    tmpPrepareCH.setParams(pMap);
    addPreparation(tmpPrepareCH);
  }
}
origin: graphhopper/graphhopper

private void logStats(int updateCounter) {
  logger.info(String.format(Locale.ROOT,
      "nodes: %10s, shortcuts: %10s, updates: %2d, checked-nodes: %10s, %s, %s, %s",
      nf(sortedNodes.getSize()),
      nf(nodeContractor.getAddedShortcutsCount()),
      updateCounter,
      nf(checkCounter),
      getTimesAsString(),
      nodeContractor.getStatisticsString(),
      Helper.getMemInfo()));
}
origin: com.graphhopper/graphhopper

      int priority = oldPriorities[node] = calculatePriority(node);
      sortedNodes.insert(node, priority);
        + ", shortcuts:" + Helper.nf(newShortcuts)
        + ", dijkstras:" + Helper.nf(dijkstraCount)
        + ", " + getTimesAsString()
        + ", meanDegree:" + (long) meanDegree
        + ", algo:" + prepareAlgo.getMemoryUsageAsString()
    int priority = oldPriorities[polledNode] = calculatePriority(polledNode);
    if (priority > sortedNodes.peekValue())
  newShortcuts += addShortcuts(polledNode);
  prepareGraph.setLevel(polledNode, level);
  level++;
      int priority = oldPriorities[nn] = calculatePriority(nn);
      if (priority != oldPrio)
        sortedNodes.update(nn, oldPrio, priority);
close();
    + ", " + prepareFlagEncoder
    + ", dijkstras:" + dijkstraCount
    + ", " + getTimesAsString()
    + ", meanDegree:" + (long) meanDegree
    + ", initSize:" + initSize
origin: com.graphhopper/graphhopper

public void createPreparations( GraphHopperStorage ghStorage, TraversalMode traversalMode )
{
  if (!isEnabled() || !preparations.isEmpty())
    return;
  if (weightings.isEmpty())
    throw new IllegalStateException("No CH weightings found");
  traversalMode = getNodeBase();
  for (Weighting weighting : getWeightings())
  {
    PrepareContractionHierarchies tmpPrepareCH = new PrepareContractionHierarchies(
        new GHDirectory("", DAType.RAM_INT), ghStorage, ghStorage.getGraph(CHGraph.class, weighting),
        weighting.getFlagEncoder(), weighting, traversalMode);
    tmpPrepareCH.setPeriodicUpdates(preparationPeriodicUpdates).
        setLazyUpdates(preparationLazyUpdates).
        setNeighborUpdates(preparationNeighborUpdates).
        setLogMessages(preparationLogMessages);
    addPreparation(tmpPrepareCH);
  }
}
origin: com.graphhopper/graphhopper

@Override
public void doWork()
{
  if (prepareFlagEncoder == null)
    throw new IllegalStateException("No vehicle encoder set.");
  if (prepareWeighting == null)
    throw new IllegalStateException("No weight calculation set.");
  allSW.start();
  super.doWork();
  initFromGraph();
  if (!prepareNodes())
    return;
  contractNodes();
}
com.graphhopper.routing.chPrepareContractionHierarchies

Javadoc

This class prepares the graph for a bidirectional algorithm supporting contraction hierarchies ie. an algorithm returned by createAlgo.

There are several descriptions of contraction hierarchies available. The following is one of the more detailed: http://web.cs.du.edu/~sturtevant/papers/highlevelpathfinding.pdf

The only difference is that we use two skipped edges instead of one skipped node for faster unpacking.

Most used methods

  • getWeighting
  • <init>
  • doWork
  • calculatePriority
    Calculates the priority of adjNode v without changing the graph. Warning: the calculated priority mu
  • close
  • contractNodes
  • getTimesAsString
  • initFromGraph
  • prepareNodes
  • addShortcuts
    Introduces the necessary shortcuts for adjNode v in the graph.
  • findShortcuts
    Finds shortcuts, does not change the underlying graph.
  • fromGraphHopperStorage
  • findShortcuts,
  • fromGraphHopperStorage,
  • getCoords,
  • getOrigEdgeCount,
  • setLazyUpdates,
  • setLogMessages,
  • setNeighborUpdates,
  • setOrigEdgeCount,
  • setPeriodicUpdates,
  • createAStarBidirection

Popular in Java

  • Updating database using SQL prepared statement
  • getOriginalFilename (MultipartFile)
    Return the original filename in the client's filesystem.This may contain path information depending
  • getApplicationContext (Context)
  • runOnUiThread (Activity)
  • ObjectMapper (com.fasterxml.jackson.databind)
    ObjectMapper provides functionality for reading and writing JSON, either to and from basic POJOs (Pl
  • HttpURLConnection (java.net)
    An URLConnection for HTTP (RFC 2616 [http://tools.ietf.org/html/rfc2616]) used to send and receive d
  • Connection (java.sql)
    A connection represents a link from a Java application to a database. All SQL statements and results
  • Timestamp (java.sql)
    A Java representation of the SQL TIMESTAMP type. It provides the capability of representing the SQL
  • List (java.util)
    An ordered collection (also known as a sequence). The user of this interface has precise control ove
  • HttpServletRequest (javax.servlet.http)
    Extends the javax.servlet.ServletRequest interface to provide request information for HTTP servlets.
  • CodeWhisperer alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now