@Override public RAMGraph createRAMGraph(InputStream in) throws IOException { Reader r = new Reader(); r.read(in); Node n; Edge e; int nodes = 0; int edges = 0; int nofNodes; int nofEdges; long curTime = System.currentTimeMillis(); try { nofNodes = r.getNodeCount(); nofEdges = r.getEdgeCount(); RAMGraph graph = new RAMGraph(nofNodes, nofEdges); while (r.hasNextNode()) { n = r.nextNode(); nodes++; graph.addNode( (float) n.getLat(), (float) n.getLon(), n.getId(), n.getElevation(), (int) n.getOsmId()); if ((nodes % (nofNodes / 10)) == 0) { System.err.print((10 * nodes / (nofNodes / 10) + "% ")); } } System.out.println("Nodes gelesen: " + nodes + " Nodes vorhanden: " + r.getNodeCount()); while (r.hasNextEdge()) { e = r.nextEdge(); edges++; int edgeSource = e.getSource(); int edgeTarget = e.getTarget(); int edgeHeight = graph.getHeight(edgeTarget) - graph.getHeight(edgeSource); int weight = calcWeight(e.getWeight(), e.getType(), e.getMaxspeed()); graph.addEdge(e.getSource(), e.getTarget(), weight, e.getWeight(), edgeHeight); if ((edges % (nofEdges / 10)) == 0) { System.err.print((10 * edges / (nofEdges / 10) + "% ")); } } System.out.println("Edges gelesen: " + edges + " Edges vorhanden: " + r.getEdgeCount()); System.err.println("Parsing took " + (System.currentTimeMillis() - curTime)); graph.setupOffsets(); System.err.println( "Read graph with " + nofNodes + " vertices and " + nofEdges + " edges in time " + (System.currentTimeMillis() - curTime) + "ms"); return graph; } catch (NoGraphOpenException ex) { throw new IOException(ex); } catch (NoSuchElementException ex) { throw new IOException(ex); } }
@Override public RAMGraph createRAMGraph(InputStream in) throws IOException { int nofNodes; int nofEdges; long curTime = System.currentTimeMillis(); BufferedReader inb = new BufferedReader(new InputStreamReader(in)); String line = inb.readLine(); while (line != null && line.trim().startsWith("#")) { line = inb.readLine(); } nofNodes = line != null ? Integer.parseInt(line) : 0; line = inb.readLine(); nofEdges = line != null ? Integer.parseInt(line) : 0; RAMGraph graph = new RAMGraph(nofNodes, nofEdges); float x, y; int altID, OSMID, height; String[] splittedLine; for (int i = 0; i < nofNodes; i++) { splittedLine = COMPILE.split(inb.readLine()); // altID[i]=i; if (splittedLine.length == 5) { altID = Integer.parseInt(splittedLine[0]); OSMID = Integer.parseInt(splittedLine[1]); x = Float.parseFloat(splittedLine[2]); y = Float.parseFloat(splittedLine[3]); height = Integer.parseInt(splittedLine[4]); graph.addNode(x, y, altID, height, OSMID); if ((i % (nofNodes / 10)) == 0) { System.err.print((10 * i / (nofNodes / 10) + "% ")); } } else { nofNodes--; } } int edgeSource, edgeTarget, edgeWeight, edgeLength, edgeHeight; for (int i = 0; i < nofEdges; i++) { splittedLine = COMPILE.split(inb.readLine()); if (splittedLine.length == 4) { edgeSource = Integer.parseInt(splittedLine[0]); edgeTarget = Integer.parseInt(splittedLine[1]); edgeLength = Integer.parseInt(splittedLine[2]); edgeWeight = calcWeight(edgeLength, Integer.parseInt(splittedLine[3])); edgeHeight = graph.getHeight(edgeTarget) - graph.getHeight(edgeSource); if (edgeHeight < 0) { edgeHeight = 0; } graph.addEdge(edgeSource, edgeTarget, edgeWeight, edgeLength, edgeHeight); if ((i % (nofEdges / 10)) == 0) { System.err.print((10 * i / (nofEdges / 10) + "% ")); } } else { nofEdges--; } } if (nofNodes != graph.nofNodes() || nofEdges != graph.nofEdges()) { graph = new RAMGraph(graph, nofNodes, nofEdges); } System.err.println("Parsing took " + (System.currentTimeMillis() - curTime)); graph.setupOffsets(); System.err.println( "Read graph with " + nofNodes + " vertices and " + nofEdges + " edges in time " + (System.currentTimeMillis() - curTime) + "ms"); return graph; }