private int addShortcuts ( Collection < Shortcut > shortcuts ) { int tmpNewShortcuts = 0 ; NEXT_SC : for ( Shortcut sc : shortcuts ) { boolean updatedInGraph = false ; // check if we need to update some existing shortcut in the graph CHEdgeIterator iter = outEdgeExplorer . setBaseNode ( sc . from ) ; while ( iter . next ( ) ) { if ( iter . isShortcut ( ) && iter . getAdjNode ( ) == sc . to ) { int status = iter . getMergeStatus ( sc . flags ) ; if ( status == 0 ) continue ; if ( sc . weight >= prepareWeighting . calcWeight ( iter , false , EdgeIterator . NO_EDGE ) ) { // special case if a bidirectional shortcut has worse weight and still has to be added as otherwise the opposite direction would be missing // see testShortcutMergeBug if ( status == 2 ) break ; continue NEXT_SC ; } if ( iter . getEdge ( ) == sc . skippedEdge1 || iter . getEdge ( ) == sc . skippedEdge2 ) { throw new IllegalStateException ( "Shortcut cannot update itself! " + iter . getEdge ( ) + ", skipEdge1:" + sc . skippedEdge1 + ", skipEdge2:" + sc . skippedEdge2 + ", edge " + iter + ":" + getCoords ( iter , prepareGraph ) + ", sc:" + sc + ", skippedEdge1: " + getCoords ( prepareGraph . getEdgeIteratorState ( sc . skippedEdge1 , sc . from ) , prepareGraph ) + ", skippedEdge2: " + getCoords ( prepareGraph . getEdgeIteratorState ( sc . skippedEdge2 , sc . to ) , prepareGraph ) + ", neighbors:" + GHUtility . getNeighbors ( iter ) ) ; } iter . setFlagsAndWeight ( sc . flags , sc . weight ) ; iter . setDistance ( sc . dist ) ; iter . setSkippedEdges ( sc . skippedEdge1 , sc . skippedEdge2 ) ; setOrigEdgeCount ( iter . getEdge ( ) , sc . originalEdges ) ; updatedInGraph = true ; break ; } } if ( ! updatedInGraph ) { int scId = prepareGraph . shortcut ( sc . from , sc . to , sc . flags , sc . weight , sc . dist , sc . skippedEdge1 , sc . skippedEdge2 ) ; setOrigEdgeCount ( scId , sc . originalEdges ) ; tmpNewShortcuts ++ ; } } return tmpNewShortcuts ; }
Adds the given shortcuts to the graph .