lib/networkx/graph.rb
# Returns subgraph conisting of given edges
#
# @example
#   graph.edge_subgraph([%w[Nagpur Wardha], %w[Nagpur Mumbai]])
#
# @param edges [Array<Object, Object>] the edges to be included in the subraph
Returns subgraph conisting of given edges
Returns subgraph conisting of given edges
def edge_subgraph(edges)
      case edges
      when Array, Set
        sub_graph = NetworkX::Graph.new(@graph)
        edges.each do |u, v|
          raise KeyError, "Edge between #{u} and #{v} does not exist in the graph!" unless @nodes.key?(u)\
                                                                                    && @adj[u].key?(v)
          sub_graph.add_node(u, @nodes[u])
          sub_graph.add_node(v, @nodes[v])
          sub_graph.add_edge(u, v, @adj[u][v])
        end
        return sub_graph
      else
        raise ArgumentError, 'Expected Argument to be Array or Set of edges, '\
        "received #{edges.class.name} instead."
      end
    end
def edge_subgraph ( edges ) case edges when Array , Set sub_graph = NetworkX :: Graph . new ( @graph ) edges . each do | u , v | raise KeyError , "Edge between #{u} and #{v} does not exist in the graph!" unless @nodes . key? ( u ) && @adj [ u ] . key? ( v ) sub_graph . add_node ( u , @nodes [ u ] ) sub_graph . add_node ( v , @nodes [ v ] ) sub_graph . add_edge ( u , v , @adj [ u ] [ v ] ) end return sub_graph else raise ArgumentError , 'Expected Argument to be Array or Set of edges, ' "received #{edges.class.name} instead." end end
Returns subgraph conisting of given edges
Returns subgraph conisting of given edges
edges
the edges to be included in the subraph
the edges to be included in the subraph
example
graph.edge_subgraph([%w[Nagpur Wardha], %w[Nagpur Mumbai]])
graph . edge_subgraph ( [ %w [ Nagpur Wardha ] %w [ Nagpur Mumbai ]] )