original_docstring:  Return an approximation to the minimum Steiner tree of a graph.
  
      Parameters
      ----------
      G : NetworkX graph
  
      terminal_nodes : list
           A list of terminal nodes for which minimum steiner tree is
           to be found.
  
      Returns
      -------
      NetworkX graph
          Approximation to the minimum steiner tree of `G` induced by
          `terminal_nodes` .
  
      Notes
      -----
      Steiner tree can be approximated by computing the minimum spanning
      tree of the subgraph of the metric closure of the graph induced by the
      terminal nodes, where the metric closure of *G* is the complete graph in
      which each edge is weighted by the shortest path distance between the
      nodes in *G* .
      This algorithm produces a tree whose weight is within a (2 - (2 / t))
      factor of the weight of the optimal Steiner tree where *t* is number of
      terminal nodes.
  
      
docstring: Return an approximation to the minimum Steiner tree of a graph.
  Parameters
  
  G : NetworkX graph
  
  terminal_nodes : list
  A list of terminal nodes for which minimum steiner tree is
  to be found.
  
  Returns
  
  NetworkX graph
  Approximation to the minimum steiner tree of `G` induced by
  `terminal_nodes` .
  
  Notes
  
  Steiner tree can be approximated by computing the minimum spanning
  tree of the subgraph of the metric closure of the graph induced by the
  terminal nodes, where the metric closure of *G* is the complete graph in
  which each edge is weighted by the shortest path distance between the
  nodes in *G* .
  This algorithm produces a tree whose weight is within a (2 - (2 / t))
  factor of the weight of the optimal Steiner tree where *t* is number of
  terminal nodes.
docstring_tokens: Return an approximation to the minimum Steiner tree of a graph . Parameters G : NetworkX graph terminal_nodes : list A list of terminal nodes for which minimum steiner tree is to be found . Returns NetworkX graph Approximation to the minimum steiner tree of ` G ` induced by ` terminal_nodes ` . Notes Steiner tree can be approximated by computing the minimum spanning tree of the subgraph of the metric closure of the graph induced by the terminal nodes where the metric closure of * G * is the complete graph in which each edge is weighted by the shortest path distance between the nodes in * G * . This algorithm produces a tree whose weight is within a ( 2 - ( 2 / t )) factor of the weight of the optimal Steiner tree where * t * is number of terminal nodes .
code: def steiner_tree(G, terminal_nodes, weight='weight'):
      """ Return an approximation to the minimum Steiner tree of a graph.
  
      Parameters
      ----------
      G : NetworkX graph
  
      terminal_nodes : list
           A list of terminal nodes for which minimum steiner tree is
           to be found.
  
      Returns
      -------
      NetworkX graph
          Approximation to the minimum steiner tree of `G` induced by
          `terminal_nodes` .
  
      Notes
      -----
      Steiner tree can be approximated by computing the minimum spanning
      tree of the subgraph of the metric closure of the graph induced by the
      terminal nodes, where the metric closure of *G* is the complete graph in
      which each edge is weighted by the shortest path distance between the
      nodes in *G* .
      This algorithm produces a tree whose weight is within a (2 - (2 / t))
      factor of the weight of the optimal Steiner tree where *t* is number of
      terminal nodes.
  
      """
      # M is the subgraph of the metric closure induced by the terminal nodes of
      # G.
      M = metric_closure(G, weight=weight)
      # Use the 'distance' attribute of each edge provided by the metric closure
      # graph.
      H = M.subgraph(terminal_nodes)
      mst_edges = nx.minimum_spanning_edges(H, weight='distance', data=True)
      # Create an iterator over each edge in each shortest path; repeats are okay
      edges = chain.from_iterable(pairwise(d['path']) for u, v, d in mst_edges)
      T = G.edge_subgraph(edges)
      return T
code_tokens: def steiner_tree ( G , terminal_nodes , weight = 'weight' ) : M = metric_closure ( G , weight = weight ) H = M . subgraph ( terminal_nodes ) mst_edges = nx . minimum_spanning_edges ( H , weight = 'distance' , data = True ) edges = chain . from_iterable ( pairwise ( d [ 'path' ] ) for u , v , d in mst_edges ) T = G . edge_subgraph ( edges ) return T
short_docstring: Return an approximation to the minimum Steiner tree of a graph.
short_docstring_tokens: Return an approximation to the minimum Steiner tree of a graph .
comment: """ Return an approximation to the minimum Steiner tree of a graph.
  
      Parameters
      ----------
      G : NetworkX graph
  
      terminal_nodes : list
           A list of terminal nodes for which minimum steiner tree is
           to be found.
  
      Returns
      -------
      NetworkX graph
          Approximation to the minimum steiner tree of `G` induced by
          `terminal_nodes` .
  
      Notes
      -----
      Steiner tree can be approximated by computing the minimum spanning
      tree of the subgraph of the metric closure of the graph induced by the
      terminal nodes, where the metric closure of *G* is the complete graph in
      which each edge is weighted by the shortest path distance between the
      nodes in *G* .
      This algorithm produces a tree whose weight is within a (2 - (2 / t))
      factor of the weight of the optimal Steiner tree where *t* is number of
      terminal nodes.
  
      """$SEP$# M is the subgraph of the metric closure induced by the terminal nodes of$SEP$# G.$SEP$# Use the 'distance' attribute of each edge provided by the metric closure$SEP$# graph.$SEP$# Create an iterator over each edge in each shortest path; repeats are okay