@Override public String toString() { String str; if (flags == PrepareEncoder.getScDirMask()) str = from + "<->"; else str = from + "->"; return str + to + ", weight:" + weight + " (" + skippedEdge1 + "," + skippedEdge2 + ")"; } }
@Override public void foundShortcut(int fromNode, int toNode, double existingDirectWeight, double existingDistSum, int outgoingEdge, int outOrigEdgeCount, int incomingEdge, int inOrigEdgeCount) { // FOUND shortcut // but be sure that it is the only shortcut in the collection // and also in the graph for u->w. If existing AND identical weight => update setProperties. // Hint: shortcuts are always one-way due to distinct level of every node but we don't // know yet the levels so we need to determine the correct direction or if both directions Shortcut sc = new Shortcut(fromNode, toNode, existingDirectWeight, existingDistSum); if (shortcuts.containsKey(sc)) return; Shortcut tmpSc = new Shortcut(toNode, fromNode, existingDirectWeight, existingDistSum); Shortcut tmpRetSc = shortcuts.get(tmpSc); // overwrite flags only if skipped edges are identical if (tmpRetSc != null && tmpRetSc.skippedEdge2 == incomingEdge && tmpRetSc.skippedEdge1 == outgoingEdge) { tmpRetSc.flags = PrepareEncoder.getScDirMask(); return; } Shortcut old = shortcuts.put(sc, sc); if (old != null) throw new IllegalStateException("Shortcut did not exist (" + sc + ") but was overwriting another one? " + old); sc.skippedEdge1 = incomingEdge; sc.skippedEdge2 = outgoingEdge; sc.originalEdges = inOrigEdgeCount + outOrigEdgeCount; } }
@Test public void testOverwrite() { long forward = PrepareEncoder.getScFwdDir(); long backward = PrepareEncoder.getScFwdDir() ^ PrepareEncoder.getScDirMask(); long both = PrepareEncoder.getScDirMask(); assertEquals(1, PrepareEncoder.getScMergeStatus(forward, forward)); assertEquals(1, PrepareEncoder.getScMergeStatus(backward, backward)); assertEquals(2, PrepareEncoder.getScMergeStatus(forward, both)); assertEquals(2, PrepareEncoder.getScMergeStatus(backward, both)); assertEquals(1, PrepareEncoder.getScMergeStatus(both, both)); assertEquals(0, PrepareEncoder.getScMergeStatus(both, forward)); assertEquals(0, PrepareEncoder.getScMergeStatus(both, backward)); assertEquals(0, PrepareEncoder.getScMergeStatus(forward, backward)); assertEquals(0, PrepareEncoder.getScMergeStatus(backward, forward)); } }
EdgeIteratorState bikeSC02 = bikeCHGraph.shortcut(0, 2).setWeight(10).setFlags(PrepareEncoder.getScDirMask()).setDistance(20);
@Test public void testGetWeightIfAdvancedEncoder() { FlagEncoder customEncoder = new Bike2WeightFlagEncoder(); EncodingManager em = new EncodingManager(customEncoder); FastestWeighting weighting = new FastestWeighting(customEncoder); GraphHopperStorage ghStorage = new GraphBuilder(em).setCHGraph(weighting).create(); ghStorage.edge(0, 2); ghStorage.freeze(); CHGraphImpl lg = (CHGraphImpl) ghStorage.getGraph(CHGraph.class, weighting); CHEdgeIteratorState sc1 = lg.shortcut(0, 1); long flags = customEncoder.setProperties(10, false, true); sc1.setFlags(flags); sc1.setWeight(100.123); assertEquals(100.123, lg.getEdgeIteratorState(sc1.getEdge(), sc1.getAdjNode()).getWeight(), 1e-3); assertEquals(100.123, lg.getEdgeIteratorState(sc1.getEdge(), sc1.getBaseNode()).getWeight(), 1e-3); assertEquals(100.123, ((CHEdgeIteratorState) GHUtility.getEdge(lg, sc1.getBaseNode(), sc1.getAdjNode())).getWeight(), 1e-3); assertEquals(100.123, ((CHEdgeIteratorState) GHUtility.getEdge(lg, sc1.getAdjNode(), sc1.getBaseNode())).getWeight(), 1e-3); sc1 = lg.shortcut(1, 0); assertTrue(sc1.isShortcut()); sc1.setFlags(PrepareEncoder.getScDirMask()); sc1.setWeight(1.011011); assertEquals(1.011011, sc1.getWeight(), 1e-3); }
@Override public String toString() { String str; if (flags == PrepareEncoder.getScDirMask()) str = from + "<->"; else str = from + "->"; return str + to + ", weight:" + weight + " (" + skippedEdge1 + "," + skippedEdge2 + ")"; } }
@Override public String toString() { String str; if (flags == PrepareEncoder.getScDirMask()) str = from + "<->"; else str = from + "->"; return str + to + ", weight:" + weight + " (" + skippedEdge1 + "," + skippedEdge2 + ")"; } }
@Override public String toString() { String str; if (flags == PrepareEncoder.getScDirMask()) str = from + "<->"; else str = from + "->"; return str + to + ", weight:" + weight + " (" + skippedEdge1 + "," + skippedEdge2 + ")"; } }
sc1to4.setFlags(PrepareEncoder.getScDirMask()); sc1to4.setWeight(2); sc1to4.setDistance(2);
@Override public void foundShortcut(int fromNode, int toNode, double existingDirectWeight, double existingDistSum, int outgoingEdge, int outOrigEdgeCount, int incomingEdge, int inOrigEdgeCount) { // FOUND shortcut // but be sure that it is the only shortcut in the collection // and also in the graph for u->w. If existing AND identical weight => update setProperties. // Hint: shortcuts are always one-way due to distinct level of every node but we don't // know yet the levels so we need to determine the correct direction or if both directions Shortcut sc = new Shortcut(fromNode, toNode, existingDirectWeight, existingDistSum); if (shortcuts.containsKey(sc)) return; Shortcut tmpSc = new Shortcut(toNode, fromNode, existingDirectWeight, existingDistSum); Shortcut tmpRetSc = shortcuts.get(tmpSc); // overwrite flags only if skipped edges are identical if (tmpRetSc != null && tmpRetSc.skippedEdge2 == incomingEdge && tmpRetSc.skippedEdge1 == outgoingEdge) { tmpRetSc.flags = PrepareEncoder.getScDirMask(); return; } Shortcut old = shortcuts.put(sc, sc); if (old != null) throw new IllegalStateException("Shortcut did not exist (" + sc + ") but was overwriting another one? " + old); sc.skippedEdge1 = incomingEdge; sc.skippedEdge2 = outgoingEdge; sc.originalEdges = inOrigEdgeCount + outOrigEdgeCount; } }
@Override public void foundShortcut(int u_fromNode, int w_toNode, double existingDirectWeight, double existingDistSum, EdgeIterator outgoingEdges, int skippedEdge1, int incomingEdgeOrigCount) { // FOUND shortcut // but be sure that it is the only shortcut in the collection // and also in the graph for u->w. If existing AND identical weight => update setProperties. // Hint: shortcuts are always one-way due to distinct level of every node but we don't // know yet the levels so we need to determine the correct direction or if both directions Shortcut sc = new Shortcut(u_fromNode, w_toNode, existingDirectWeight, existingDistSum); if (shortcuts.containsKey(sc)) return; Shortcut tmpSc = new Shortcut(w_toNode, u_fromNode, existingDirectWeight, existingDistSum); Shortcut tmpRetSc = shortcuts.get(tmpSc); if (tmpRetSc != null) { // overwrite flags only if skipped edges are identical if (tmpRetSc.skippedEdge2 == skippedEdge1 && tmpRetSc.skippedEdge1 == outgoingEdges.getEdge()) { tmpRetSc.flags = PrepareEncoder.getScDirMask(); return; } } Shortcut old = shortcuts.put(sc, sc); if (old != null) throw new IllegalStateException("Shortcut did not exist (" + sc + ") but was overwriting another one? " + old); sc.skippedEdge1 = skippedEdge1; sc.skippedEdge2 = outgoingEdges.getEdge(); sc.originalEdges = incomingEdgeOrigCount + getOrigEdgeCount(outgoingEdges.getEdge()); } }
tmpRetSc.flags = PrepareEncoder.getScDirMask(); return;