public static EdgeMapper importFromDb(Connection conn) throws SQLException { HHDbReader reader = new HHDbReader(conn); RgDAO rg = new RgDAO(conn); // mapping from hhEdgeId to rgEdgeId int[] hhEdgeIdToRgEdgeId = new int[reader.numEdges()]; int[][] rgEdgeIdToHhEdgeId = new int[2][rg.getNumEdges()]; for (int i = 0; i < rgEdgeIdToHhEdgeId[0].length; i++) { rgEdgeIdToHhEdgeId[0][i] = -1; rgEdgeIdToHhEdgeId[1][i] = -1; } BitArray reversed = new BitArray(reader.numEdges()); int hhEdgeId = 0; for (Iterator<HHEdge> iter = reader.getEdges(); iter.hasNext(); ) { HHEdge e = iter.next(); if (e.shortcut) { // edge is not in routing graph hhEdgeIdToRgEdgeId[hhEdgeId] = -1; } else { // edge is in routing graph, either forward or backward // hh -> rg int rgEdgeId = e.id / 2; hhEdgeIdToRgEdgeId[hhEdgeId] = e.id / 2; reversed.set(hhEdgeId, e.id % 2 == 1); // rg ->hh if (rgEdgeIdToHhEdgeId[0][rgEdgeId] == -1) { rgEdgeIdToHhEdgeId[0][rgEdgeId] = hhEdgeId; } else { rgEdgeIdToHhEdgeId[1][rgEdgeId] = hhEdgeId; } } hhEdgeId++; } return new EdgeMapper(hhEdgeIdToRgEdgeId, rgEdgeIdToHhEdgeId, reversed); }
static HHStaticGraph getFromHHDb(Connection conn) throws SQLException { HHDbReader reader = new HHDbReader(conn); HHStaticGraph g = new HHStaticGraph( reader.numVertices(), reader.numLevelVertices(), reader.numEdges(), reader.getGraphProperties()); int offset = 0; for (Iterator<HHVertexLvl> iter = reader.getVertexLvls(); iter.hasNext(); ) { HHVertexLvl v = iter.next(); g.vLvlVNh[offset] = v.neighborhood; if (v.lvl == 0) { g.vFirstLvlVertex[v.id] = offset; } offset++; } for (int i = 0; i < g.numLvlVertices; i++) { g.vLvlFirstEdge[i] = -1; } offset = 0; for (Iterator<HHEdge> iter = reader.getEdges(); iter.hasNext(); ) { HHEdge e = iter.next(); g.eSource[offset] = e.sourceId; g.eTarget[offset] = e.targetId; g.eWeight[offset] = e.weight; g.eDirection[FWD].set(offset, e.fwd); g.eDirection[BWD].set(offset, e.bwd); g.eShortcut.set(offset, e.shortcut); for (int i = 0; i <= e.maxLvl; i++) { if (g.vLvlFirstEdge[g.vFirstLvlVertex[e.sourceId] + i] == -1) { g.vLvlFirstEdge[g.vFirstLvlVertex[e.sourceId] + i] = offset; } } offset++; } return g; }