Module: Tangle::Mixin::Connectedness::Graph
- Defined in:
- lib/tangle/mixin/connectedness.rb
Overview
Mixin for adding connectedness to a graph
Instance Method Summary collapse
-
#connected? ⇒ Boolean
A graph is connected if all vertices are connected to all vertices An empty graph is disconnected.
-
#connected_subgraph(vertex) ⇒ Object
(also: #component, #connected_component)
Get the largest connected subgraph for a vertex.
-
#disconnected? ⇒ Boolean
A graph is disconnected if any vertex is not connected to all other.
-
#disconnected_subgraph(vertex) ⇒ Object
Get the largest subgraph that is not connected to a vertex, or what’s left after removing the connected subgraph.
Instance Method Details
#connected? ⇒ Boolean
A graph is connected if all vertices are connected to all vertices An empty graph is disconnected.
29 30 31 32 33 34 35 36 |
# File 'lib/tangle/mixin/connectedness.rb', line 29 def connected? return false if vertices.empty? vertices.combination(2).all? do |pair| this, that = pair.to_a this.connected?(that) end end |
#connected_subgraph(vertex) ⇒ Object Also known as: component, connected_component
Get the largest connected subgraph for a vertex. Also aliased as :component and :connected_component
connected_subgraph(vertex) => Graph
13 14 15 |
# File 'lib/tangle/mixin/connectedness.rb', line 13 def connected_subgraph(vertex) subgraph { |other| vertex.connected?(other) } end |
#disconnected? ⇒ Boolean
A graph is disconnected if any vertex is not connected to all other. An empty graph is disconnected.
41 42 43 |
# File 'lib/tangle/mixin/connectedness.rb', line 41 def disconnected? !connected? end |
#disconnected_subgraph(vertex) ⇒ Object
Get the largest subgraph that is not connected to a vertex, or what’s left after removing the connected subgraph.
22 23 24 |
# File 'lib/tangle/mixin/connectedness.rb', line 22 def disconnected_subgraph(vertex) subgraph { |other| !vertex.connected?(other) } end |