Пример #1
0
  /** After configuring this storage you need to create it explicitly. */
  @Override
  public GraphHopperStorage create(long byteCount) {
    baseGraph.checkInit();
    if (encodingManager == null) {
      throw new IllegalStateException("EncodingManager can only be null if you call loadExisting");
    }

    long initSize = Math.max(byteCount, 100);
    properties.create(100);

    properties.put("graph.bytesForFlags", encodingManager.getBytesForFlags());
    properties.put("graph.flagEncoders", encodingManager.toDetailsString());

    properties.put("graph.byteOrder", dir.getByteOrder());
    properties.put("graph.dimension", baseGraph.nodeAccess.getDimension());
    properties.putCurrentVersions();

    baseGraph.create(initSize);

    for (CHGraphImpl cg : chGraphs) {
      cg.create(byteCount);
    }

    properties.put("graph.chWeightings", getCHWeightings().toString());
    return this;
  }
Пример #2
0
  @Test
  public void internalDisconnect() {
    GraphHopperStorage storage = createGHStorage();
    BaseGraph graph = (BaseGraph) storage.getGraph(Graph.class);
    EdgeIteratorState iter0 = graph.edge(0, 1, 10, true);
    EdgeIteratorState iter2 = graph.edge(1, 2, 10, true);
    EdgeIteratorState iter3 = graph.edge(0, 3, 10, true);

    EdgeExplorer explorer = graph.createEdgeExplorer();

    assertEquals(GHUtility.asSet(3, 1), GHUtility.getNeighbors(explorer.setBaseNode(0)));
    assertEquals(GHUtility.asSet(2, 0), GHUtility.getNeighbors(explorer.setBaseNode(1)));
    // remove edge "1-2" but only from 1 not from 2
    graph.edgeAccess.internalEdgeDisconnect(
        iter2.getEdge(), -1, iter2.getBaseNode(), iter2.getAdjNode());
    assertEquals(GHUtility.asSet(0), GHUtility.getNeighbors(explorer.setBaseNode(1)));
    assertEquals(GHUtility.asSet(1), GHUtility.getNeighbors(explorer.setBaseNode(2)));
    // let 0 unchanged -> no side effects
    assertEquals(GHUtility.asSet(3, 1), GHUtility.getNeighbors(explorer.setBaseNode(0)));

    // remove edge "0-1" but only from 0
    graph.edgeAccess.internalEdgeDisconnect(
        iter0.getEdge(),
        (long) iter3.getEdge() * graph.edgeEntryBytes,
        iter0.getBaseNode(),
        iter0.getAdjNode());
    assertEquals(GHUtility.asSet(3), GHUtility.getNeighbors(explorer.setBaseNode(0)));
    assertEquals(GHUtility.asSet(0), GHUtility.getNeighbors(explorer.setBaseNode(3)));
    assertEquals(GHUtility.asSet(0), GHUtility.getNeighbors(explorer.setBaseNode(1)));
    storage.close();
  }
Пример #3
0
  @Override
  public boolean loadExisting() {
    baseGraph.checkInit();
    if (properties.loadExisting()) {
      properties.checkVersions(false);
      // check encoding for compatiblity
      String acceptStr = properties.get("graph.flagEncoders");

      if (encodingManager == null) {
        if (acceptStr.isEmpty())
          throw new IllegalStateException(
              "No EncodingManager was configured. And no one was found in the graph: "
                  + dir.getLocation());

        int bytesForFlags = 4;
        if ("8".equals(properties.get("graph.bytesForFlags"))) bytesForFlags = 8;
        encodingManager = new EncodingManager(acceptStr, bytesForFlags);
      } else if (!acceptStr.isEmpty()
          && !encodingManager.toDetailsString().equalsIgnoreCase(acceptStr)) {
        throw new IllegalStateException(
            "Encoding does not match:\nGraphhopper config: "
                + encodingManager.toDetailsString()
                + "\nGraph: "
                + acceptStr
                + ", dir:"
                + dir.getLocation());
      }

      String byteOrder = properties.get("graph.byteOrder");
      if (!byteOrder.equalsIgnoreCase("" + dir.getByteOrder()))
        throw new IllegalStateException(
            "Configured graph.byteOrder ("
                + dir.getByteOrder()
                + ") is not equal to loaded "
                + byteOrder
                + "");

      String bytesForFlags = properties.get("graph.bytesForFlags");
      if (!bytesForFlags.equalsIgnoreCase("" + encodingManager.getBytesForFlags()))
        throw new IllegalStateException(
            "Configured graph.bytesForFlags ("
                + encodingManager.getBytesForFlags()
                + ") is not equal to loaded "
                + bytesForFlags);

      String dim = properties.get("graph.dimension");
      baseGraph.loadExisting(dim);

      for (CHGraphImpl cg : chGraphs) {
        if (!cg.loadExisting()) throw new IllegalStateException("Cannot load " + cg);
      }

      return true;
    }
    return false;
  }
Пример #4
0
  @Override
  public void setSegmentSize(int bytes) {
    baseGraph.setSegmentSize(bytes);

    for (CHGraphImpl cg : chGraphs) {
      cg.setSegmentSize(bytes);
    }
  }
Пример #5
0
  @Override
  public long getCapacity() {
    long cnt = baseGraph.getCapacity() + properties.getCapacity();

    for (CHGraphImpl cg : chGraphs) {
      cnt += cg.getCapacity();
    }
    return cnt;
  }
Пример #6
0
  @Override
  public void close() {
    properties.close();
    baseGraph.close();

    for (CHGraphImpl cg : chGraphs) {
      cg.close();
    }
  }
Пример #7
0
  @Override
  public String toDetailsString() {
    String str = baseGraph.toDetailsString();
    for (CHGraphImpl cg : chGraphs) {
      str += ", " + cg.toDetailsString();
    }

    return str;
  }
Пример #8
0
  @Override
  public void optimize() {
    if (isFrozen()) {
      throw new IllegalStateException("do not optimize after graph was frozen");
    }

    int delNodes = baseGraph.getRemovedNodes().getCardinality();
    if (delNodes <= 0) {
      return;
    }

    // Deletes only nodes.
    // It reduces the fragmentation of the node space but introduces new unused edges.
    baseGraph.inPlaceNodeRemove(delNodes);

    // Reduce memory usage
    baseGraph.trimToSize();
  }
Пример #9
0
  @Override
  public void flush() {
    for (CHGraphImpl cg : chGraphs) {
      cg.setEdgesHeader();
      cg.flush();
    }

    baseGraph.flush();
    properties.flush();
  }
Пример #10
0
 @Override
 public final AllEdgesIterator getAllEdges() {
   return baseGraph.getAllEdges();
 }
Пример #11
0
 @Override
 public final EdgeIteratorState getEdgeIteratorState(int edgeId, int adjNode) {
   return baseGraph.getEdgeIteratorState(edgeId, adjNode);
 }
Пример #12
0
 @Override
 public final EdgeIteratorState edge(int a, int b, double distance, boolean bothDirections) {
   return baseGraph.edge(a, b, distance, bothDirections);
 }
Пример #13
0
 @Override
 public final EdgeIteratorState edge(int a, int b) {
   return baseGraph.edge(a, b);
 }
Пример #14
0
 @Override
 public final BBox getBounds() {
   return baseGraph.getBounds();
 }
Пример #15
0
 @Override
 public final NodeAccess getNodeAccess() {
   return baseGraph.getNodeAccess();
 }
Пример #16
0
 @Override
 public final int getNodes() {
   return baseGraph.getNodes();
 }
Пример #17
0
 public void setAdditionalEdgeField(long edgePointer, int value) {
   baseGraph.setAdditionalEdgeField(edgePointer, value);
 }
Пример #18
0
 @Override
 public final Graph copyTo(Graph g) {
   return baseGraph.copyTo(g);
 }
Пример #19
0
 @Override
 public final EdgeExplorer createEdgeExplorer(EdgeFilter filter) {
   return baseGraph.createEdgeExplorer(filter);
 }
Пример #20
0
 @Override
 public void markNodeRemoved(int index) {
   baseGraph.getRemovedNodes().add(index);
 }
Пример #21
0
 @Override
 public boolean isNodeRemoved(int index) {
   return baseGraph.getRemovedNodes().contains(index);
 }
Пример #22
0
 @Override
 public final EdgeExplorer createEdgeExplorer() {
   return baseGraph.createEdgeExplorer();
 }
Пример #23
0
 /**
  * Avoid that edges and nodes of the base graph are further modified. Necessary as hook for e.g.
  * ch graphs on top to initilize themself
  */
 public void freeze() {
   if (!baseGraph.isFrozen()) {
     baseGraph.freeze();
   }
 }
Пример #24
0
 @Override
 public final GraphExtension getExtension() {
   return baseGraph.getExtension();
 }
Пример #25
0
 boolean isFrozen() {
   return baseGraph.isFrozen();
 }