Returns the dominance frontier of the graph.

 If the start node is not provided, it is assumed the receiver is a
 ControlFlowGraph and has an #enter method.

 return: Node => Set<Node>
191439
def dominance_frontier(start_node = self.enter, dom_tree)
      vertices.inject(Hash.new { |h, k| h[k] = Set.new }) do |result, b|
        preds = b.real_predecessors
        if preds.size >= 2
          preds.each do |p|
            b_dominator = dom_tree[b].successors.first
            break unless b_dominator
            runner = dom_tree[p]
            while runner && runner != b_dominator
              result[runner] << b
              runner = runner.successors.first
            end
          end
        end
        result
      end
    end
89385
def _dinic_step(graph, capacity, lev, flow, u, target, limit):
    
    if limit <= 0:
        return 0
    if u == target:
        return limit
    val = 0
    for v in graph[u]:
        residual = capacity[u][v] - flow[u][v]
        if lev[v] == lev[u] + 1 and residual > 0:
            z = min(limit, residual)
            aug = _dinic_step(graph, capacity, lev, flow, v, target, z)
            flow[u][v] += aug
            flow[v][u] -= aug
            val += aug
            limit -= aug
    if val == 0:
        lev[u] = None         # remove unreachable node
    return val
1313926
def get_roots(self):
    
    if self.__directionless:
      sys.stderr.write("ERROR: can't get roots of an undirected graph\n")
      sys.exit()
    outputids = self.__nodes.keys()
    #print outputids
    rootset  = set(outputids) -  set(self.__child_to_parent.keys())
    return [self.__nodes[x] for x in rootset]
327054
protected int getFirstFreeInputGateIndex() {

		for (int i = 0; i < this.backwardEdges.size(); i++) {

			if (this.backwardEdges.get(i) == null) {
				return i;
			}
		}

		return this.backwardEdges.size();
	}
1052112
def bfs(graph, start=0):
    
    to_visit = deque()
    dist = [float('inf')] * len(graph)
    prec = [None] * len(graph)
    dist[start] = 0
    to_visit.appendleft(start)
    while to_visit:              # an empty queue is considered False
        node = to_visit.pop()
        for neighbor in graph[node]:
            if dist[neighbor] == float('inf'):
                dist[neighbor] = dist[node] + 1
                prec[neighbor] = node
                to_visit.appendleft(neighbor)
    return dist, prec
405436
function deriveBFS(fromModel) {
	const graph = buildGraph();
	const queue = [fromModel]; // Unshift -> queue -> pop

	graph[fromModel].distance = 0;

	while (queue.length) {
		const current = queue.pop();
		const adjacents = Object.keys(conversions[current]);

		for (let len = adjacents.length, i = 0; i < len; i++) {
			const adjacent = adjacents[i];
			const node = graph[adjacent];

			if (node.distance === -1) {
				node.distance = graph[current].distance + 1;
				node.parent = current;
				queue.unshift(adjacent);
			}
		}
	}

	return graph;
}
558639
@SuppressWarnings("unchecked")  // The type is always ControlFlowGraph<Node>
  public ControlFlowGraph<Node> getControlFlowGraph() {
    ControlFlowGraph<Node> result;
    Object o = cfgs.peek();
    if (o instanceof Node) {
      Node cfgRoot = (Node) o;
      ControlFlowAnalysis cfa = new ControlFlowAnalysis(compiler, false, true);
      cfa.process(null, cfgRoot);
      result = cfa.getCfg();
      cfgs.pop();
      cfgs.push(result);
    } else {
      result = (ControlFlowGraph<Node>) o;
    }
    return result;
  }
119127
def diameter(self):
        '''
        '''
        d = dict(); best = float('-inf')
        for node in self.traverse_postorder():
            if node.is_leaf():
                d[node] = 0
            else:
                dists = sorted(d[c]+c.edge_length for c in node.children)
                d[node] = dists[-1]; max_pair = dists[-1]+dists[-2]
                if max_pair > best:
                    best = max_pair
        return best
887484
def getRankMap(self):
        

        # We sort the candidates based on the number of incoming edges they have in the graph. If 
        # two candidates have the same number, we assume that they are tied.
        incEdgesMap = self.getIncEdgesMap()
        sortedKeys = sorted(incEdgesMap.keys(), reverse = True)
        rankMap = dict()
        pos = 1
        for key in sortedKeys:
            cands = incEdgesMap[key]
            for cand in cands:
                rankMap[cand] = pos
            pos += 1
        return rankMap
1060190
def _initialize_graph_status_for_traversing(self):
        '''
        
        '''
        # In the beginning, we set is_root and is_leaf true. For is_fed, we have two different behaviors depending on
        # whether root_names is empty.
        for variable in self.unordered_variable_iterator():
            # If root_names is set, we only set those variable to be fed. Otherwise, all roots would be fed.
            if self.root_names:
                if variable.onnx_name in self.root_names:
                    variable.is_fed = True
                else:
                    variable.is_fed = False
            else:
                variable.is_fed = True
            variable.is_root = True
            variable.is_leaf = True

        # Then, we flip some flags by applying some simple rules so that only
        #   1. all roots get is_root=True and is_fed=True
        #   2. all leaves get is_leaf=True
        for operator in self.unordered_operator_iterator():
            operator.is_evaluated = False  # All operators are not processed in the beginning
            for variable in operator.outputs:
                # Output cannot be fed before graph traversing
                variable.is_fed = False
                # If the variable is an output of one operator, it must not be a root
                variable.is_root = False
            for variable in operator.inputs:
                # If the variable is an input of one operator, it must not be a leaf
                variable.is_leaf = False
622499
def calculateBoundingRect(self, nodes):
        
        out = QRectF()
        for node in nodes:
            rect = node.rect()
            pos = node.pos()
            
            bounding = QRectF(pos.x(), pos.y(), rect.width(), rect.height())
            out = out.united(bounding)
        
        return out
506877
def node_to_edge(edges, directed=True):
    
    outgoing = defaultdict(set)
    incoming = defaultdict(set) if directed else outgoing
    nodes = set()
    for i, edge in enumerate(edges):
        a, b, = edge[:2]
        outgoing[a].add(i)
        incoming[b].add(i)
        nodes.add(a)
        nodes.add(b)
    nodes = sorted(nodes)
    if directed:
        return outgoing, incoming, nodes
    return outgoing, nodes
1261728
def inc_edges(self, node):
        
        try:
            return list(self.nodes[node][0])
        except KeyError:
            raise GraphError('Invalid node %s' % node)

        return None
1294484
def ind_nodes(self):
        
        graph = self.graph

        dependent_nodes = set(
            node for dependents
            in graph.values() for node in dependents)
        return [node_ for node_ in graph if node_ not in dependent_nodes]
722443
def comparison(self):
        
        node = self.expr()

        while self.token.nature in (
            Nature.EQ,
            Nature.NE,
            Nature.LE,
            Nature.GE,
            Nature.LT,
            Nature.GT,
        ):
            token = self.token
            if token.nature == Nature.EQ:
                self._process(Nature.EQ)
            elif token.nature == Nature.NE:
                self._process(Nature.NE)
            elif token.nature == Nature.LE:
                self._process(Nature.LE)
            elif token.nature == Nature.GE:
                self._process(Nature.GE)
            elif token.nature == Nature.LT:
                self._process(Nature.LT)
            elif token.nature == Nature.GT:
                self._process(Nature.GT)
            else:
                self.error()

            node = BinaryOperation(left=node, op=token, right=self.expr())

        return node
119635
def all_edges(self, node):
        
        return set(self.inc_edges(node) + self.out_edges(node))
185075
function slack(g, e) {
  return g.node(e.w).rank - g.node(e.v).rank - g.edge(e).minlen;
}