+other+ The target node to find a route to
 Gives the path weight as a float of the shortest path to the other
962849
def path_weight_to(other)
      shortest_path_to(other,:method => :djikstra).map{|edge| edge.weight.to_f}.sum
    end
1145028
function betweennes(graph, oriented) {
  var Q = [],
    S = []; // Queue and Stack
  // list of predecessors on shortest paths from source
  var pred = Object.create(null);
  // distance from source
  var dist = Object.create(null);
  // number of shortest paths from source to key
  var sigma = Object.create(null);
  // dependency of source on key
  var delta = Object.create(null);

  var currentNode;
  var centrality = Object.create(null);

  graph.forEachNode(setCentralityToZero);
  graph.forEachNode(calculateCentrality);

  if (!oriented) {
    // The centrality scores need to be divided by two if the graph is not oriented,
    // since all shortest paths are considered twice
    Object.keys(centrality).forEach(divideByTwo);
  }

  return centrality;

  function divideByTwo(key) {
    centrality[key] /= 2;
  }

  function setCentralityToZero(node) {
    centrality[node.id] = 0;
  }

  function calculateCentrality(node) {
    currentNode = node.id;
    singleSourceShortestPath(currentNode);
    accumulate();
  }

  function accumulate() {
    graph.forEachNode(setDeltaToZero);
    while (S.length) {
      var w = S.pop();
      var coeff = (1 + delta[w])/sigma[w];
      var predecessors = pred[w];
      for (var idx = 0; idx < predecessors.length; ++idx) {
        var v = predecessors[idx];
        delta[v] += sigma[v] * coeff;
      }
      if (w !== currentNode) {
        centrality[w] += delta[w];
      }
    }
  }

  function setDeltaToZero(node) {
    delta[node.id] = 0;
  }

  function singleSourceShortestPath(source) {
    graph.forEachNode(initNode);
    dist[source] = 0;
    sigma[source] = 1;
    Q.push(source);

    while (Q.length) {
      var v = Q.shift();
      S.push(v);
      graph.forEachLinkedNode(v, toId, oriented);
    }

    function toId(otherNode) {
      // NOTE: This code will also consider multi-edges, which are often
      // ignored by popular software (Gephi/NetworkX). Depending on your use
      // case this may not be desired and deduping needs to be performed. To
      // save memory I'm not deduping here...
      processNode(otherNode.id);
    }

    function initNode(node) {
      var nodeId = node.id;
      pred[nodeId] = []; // empty list
      dist[nodeId] = -1;
      sigma[nodeId] = 0;
    }

    function processNode(w) {
      // path discovery
      if (dist[w] === -1) {
        // Node w is found for the first time
        dist[w] = dist[v] + 1;
        Q.push(w);
      }
      // path counting
      if (dist[w] === dist[v] + 1) {
        // edge (v, w) on a shortest path
        sigma[w] += sigma[v];
        pred[w].push(v);
      }
    }
  }
}
996720
def create_edge_to_and_from(other, weight = 1.0)
      self.class.edge_class.create!(:from_id => id, :to_id => other.id, :weight => weight)
      self.class.edge_class.create!(:from_id => other.id, :to_id => id, :weight => weight)
    end
881932
def find_tree(sub_network, weight='x_pu'):
    

    branches_bus0 = sub_network.branches()["bus0"]
    branches_i = branches_bus0.index
    buses_i = sub_network.buses_i()

    graph = sub_network.graph(weight=weight, inf_weight=1.)
    sub_network.tree = nx.minimum_spanning_tree(graph)

    #find bus with highest degree to use as slack
    tree_slack_bus, slack_degree = max(degree(sub_network.tree), key=itemgetter(1))
    logger.info("Tree slack bus is %s with degree %d.", tree_slack_bus, slack_degree)

    #determine which buses are supplied in tree through branch from slack

    #matrix to store tree structure
    sub_network.T = dok_matrix((len(branches_i),len(buses_i)))

    for j,bus in enumerate(buses_i):
        path = nx.shortest_path(sub_network.tree,bus,tree_slack_bus)
        for i in range(len(path)-1):
            branch = next(iterkeys(graph[path[i]][path[i+1]]))
            branch_i = branches_i.get_loc(branch)
            sign = +1 if branches_bus0.iat[branch_i] == path[i] else -1
            sub_network.T[branch_i,j] = sign
295746
def find_nearest_route(path)
			path_parts = path.parts.dup
			loop do
				route = routes.navigate(*path_parts)&.values&.grep(Route)&.first
				break route if route || path_parts.pop.nil?
			end
		end
95412
function getRoute(node, options) {
	var id = "", nodeType
	var collapseTextNodes = options && options.collapseTextNodes;

	var parent = node.parentNode;
	var index = -1;

	if(!parent) {
		return {id:"0"};
	}

	var child = parent.firstChild;
	var prevNodeType, siblingTag, value;
	while(child) {
		if(collapseTextNodes && child.nodeType === 3) {
			siblingTag = child.nextSibling && child.nextSibling.nodeName;
			if(prevNodeType === 3) {
				value += child.nodeValue;
			}
			// TextNodes before the <head> are ignored.
			else if(siblingTag !== "HEAD") {
				value = child.nodeValue;
				index++;
			}
		} else {
			value = undefined;
			index++;
		}

		if(child === node) {
			break;
		}
		prevNodeType = child.nodeType;
		child = child.nextSibling;
	}

	// ARG!
	
	var parentInfo;

	if(parent.nodeType === 9) {
		parentInfo = {id: ""};
	} else {
		parentInfo = getCachedInfo(parent);
		if(!parentInfo || collapseTextNodes) {
			parentInfo = getRoute(parent, options);
		}
	}

	var parentId = parentInfo.id;

	id = (parentId ? parentId + SEPARATOR : "") + index;

	var routeInfo = createRouteInfo(id,
		getBranch(index, node, parentInfo.branch),
		collapseTextNodes ? value : undefined, collapseTextNodes);

	cache(node, routeInfo);

	return routeInfo;
}
155758
function decendTreeByRoutedToken(node, value, routeToken) {
    var next = null;
    switch (value) {
        case Keys.keys:
        case Keys.integers:
        case Keys.ranges:
            next = node[value];
            if (!next) {
                next = node[value] = {};
            }
            break;
        default:
            break;
    }
    if (next && routeToken) {
        // matches the naming information on the node.
        next[Keys.named] = routeToken.named;
        next[Keys.name] = routeToken.name;
    }

    return next;
}
159140
def calc_cost(self, node_a, node_b):
        
        if node_b.x - node_a.x == 0 or node_b.y - node_a.y == 0:
            # direct neighbor - distance is 1
            ng = 1
        else:
            # not a direct neighbor - diagonal movement
            ng = SQRT2

        # weight for weighted algorithms
        if self.weighted:
            ng *= node_b.weight

        return node_a.g + ng
628676
def build_path(graph, node1, node2, path=None):
    
    if path is None:
        path = []
    if node1 is node2:
        return path
    path.append(node2)
    for pred in graph.all_preds(node2):
        if pred in path:
            continue
        build_path(graph, node1, pred, path)
    return path
584237
def edge_cost(self, node_a, node_b):
        """"""
        cost = float('inf')
        node_object_a = self.get_node(node_a)
        for edge_id in node_object_a['edges']:
            edge = self.get_edge(edge_id)
            tpl = (node_a, node_b)
            if edge['vertices'] == tpl:
                cost = edge['cost']
                break
        return cost
1335994
@VisibleForTesting
  public static List<FlowEdge> dijkstraBasedPathFindingHelper(ServiceNode sourceNode, ServiceNode targetNode,
      DirectedWeightedMultigraph<ServiceNode, FlowEdge> weightedGraph) {
    Map<DistancedNode, ArrayList<FlowEdge>> shortestPath = new HashMap<>();
    Map<DistancedNode, Double> shortestDist = new HashMap<>();
    PriorityQueue<DistancedNode> pq = new PriorityQueue<>(new Comparator<DistancedNode>() {
      @Override
      public int compare(DistancedNode o1, DistancedNode o2) {
        if (o1.getDistToSrc() < o2.getDistToSrc()) {
          return -1;
        } else {
          return 1;
        }
      }
    });
    pq.add(new DistancedNode(sourceNode, 0.0));

    Set<FlowEdge> visitedEdge = new HashSet<>();

    while(!pq.isEmpty()) {
      DistancedNode node = pq.poll();
      if (node.getNode().getNodeName().equals(targetNode.getNodeName())) {
        // Searching finished
        return shortestPath.get(node);
      }

      Set<FlowEdge> outgoingEdges = weightedGraph.outgoingEdgesOf(node.getNode());
      for (FlowEdge outGoingEdge:outgoingEdges) {
        // Since it is a multi-graph problem, should use edge for deduplicaiton instead of vertex.
        if (visitedEdge.contains(outGoingEdge)) {
          continue;
        }

        DistancedNode adjacentNode = new DistancedNode(weightedGraph.getEdgeTarget(outGoingEdge));
        if (shortestDist.containsKey(adjacentNode)) {
          adjacentNode.setDistToSrc(shortestDist.get(adjacentNode));
        }

        double newDist = node.getDistToSrc() + ((LoadBasedFlowEdgeImpl) outGoingEdge).getEdgeLoad();

        if (newDist < adjacentNode.getDistToSrc()) {
          if (pq.contains(adjacentNode)) {
            pq.remove(adjacentNode);
          }

          // Update the shortest path.
          ArrayList<FlowEdge> path = shortestPath.containsKey(node)
              ? new ArrayList<>(shortestPath.get(node)) : new ArrayList<>();
          path.add(outGoingEdge);
          shortestPath.put(adjacentNode, path);
          shortestDist.put(adjacentNode, newDist);

          adjacentNode.setDistToSrc(newDist);
          pq.add(adjacentNode);
        }
        visitedEdge.add(outGoingEdge);
      }
    }
    log.error("No path found");
    return new ArrayList<>();
  }
86733
def -(other)
      other = other.to_key_path
      raise KeyError unless prefix?(other)

      super(other.length)
    end
847419
public static double approxSumPaths(WeightedIntDiGraph g, RealVector startWeights, RealVector endWeights,
            Iterator<DiEdge> seq, DoubleConsumer c) {
        // we keep track of the total weight of discovered paths ending along
        // each edge and the total weight
        // of all paths ending at each node (including the empty path); on each
        // time step, we
        // at each step, we pick an edge (s, t), update the sum at s, and extend
        // each of those (including
        // the empty path starting there) with the edge (s, t)

        DefaultDict<DiEdge, Double> prefixWeightsEndingAt = new DefaultDict<DiEdge, Double>(Void -> 0.0);

        // we'll maintain node sums and overall sum with subtraction rather than
        // re-adding (it's an approximation anyway!)
        RealVector currentSums = startWeights.copy();
        double currentTotal = currentSums.dotProduct(endWeights);
        if (c != null) {
            c.accept(currentTotal);
        }
        for (DiEdge e : ScheduleUtils.iterable(seq)) {
            int s = e.get1();
            int t = e.get2();
            // compute the new sums
            double oldTargetSum = currentSums.getEntry(t);
            double oldEdgeSum = prefixWeightsEndingAt.get(e);
            // new edge sum is the source sum times the edge weight
            double newEdgeSum = currentSums.getEntry(s) * g.getWeight(e);
            // new target sum is the old target sum plus the difference between
            // the new and old edge sums
            double newTargetSum = oldTargetSum + (newEdgeSum - oldEdgeSum);
            // the new total is the old total plus the difference in new and
            // target
            double newTotal = currentTotal + (newTargetSum - oldTargetSum) * endWeights.getEntry(t);
            // store the new sums
            prefixWeightsEndingAt.put(e, newEdgeSum);
            currentSums.setEntry(t, newTargetSum);
            currentTotal = newTotal;
            // and report the new total to the consumer
            if (c != null) {
                c.accept(currentTotal);
            }
        }
        return currentTotal;
    }
1252260
function findLinksOutward( node, graph ) {
    var children = [];

    for( var i = 0; i < graph.length; i++ ) {
      if( node == graph[i].source ) {
        children.push( graph[i] );
      }
    }

    return children;
  }
775471
def value( self, node, parent=None ):
        """"""
        # this is the *weighted* size/contribution of the node 
        try:
            return node['contribution']
        except KeyError, err:
            contribution = int(node.get('totsize',0)/float( len(node.get('parents',())) or 1))
            node['contribution'] = contribution
            return contribution
605423
function  (node) {
		  	var parent = node.parentNode,
			  	path = [],
			  	index = this.getChildIndex(node);

		  if(parent && (path = this.getNodePath(parent))){
			   if(index > -1){
				   path.push(index);
			   }
		  }
		  return path;
		}
824488
function closenessCentrality(options) {
    var _defaults2 = defaults$2(options),
        root = _defaults2.root,
        weight = _defaults2.weight,
        directed = _defaults2.directed,
        harmonic = _defaults2.harmonic;

    root = this.filter(root)[0]; // we need distance from this node to every other node

    var dijkstra = this.dijkstra({
      root: root,
      weight: weight,
      directed: directed
    });
    var totalDistance = 0;
    var nodes = this.nodes();

    for (var i = 0; i < nodes.length; i++) {
      var n = nodes[i];

      if (!n.same(root)) {
        var d = dijkstra.distanceTo(n);

        if (harmonic) {
          totalDistance += 1 / d;
        } else {
          totalDistance += d;
        }
      }
    }

    return harmonic ? totalDistance : 1 / totalDistance;
  }