Module: Tangle::Mixin::Connectedness::Graph
- Included in:
- Ancestry::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.
32 33 34 35 36 37 38 39 |
# File 'lib/tangle/mixin/connectedness.rb', line 32 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
16 17 18 |
# File 'lib/tangle/mixin/connectedness.rb', line 16 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.
44 45 46 |
# File 'lib/tangle/mixin/connectedness.rb', line 44 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.
25 26 27 |
# File 'lib/tangle/mixin/connectedness.rb', line 25 def disconnected_subgraph(vertex) subgraph { |other| !vertex.connected?(other) } end |