Class: GoNodes::EdgeList
Instance Attribute Summary collapse
-
#completeness ⇒ Object
readonly
Returns the value of attribute completeness.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other_edge_list) ⇒ Object
- #add_edge(edge_params) ⇒ Object
-
#initialize(node_list) ⇒ EdgeList
constructor
A new instance of EdgeList.
- #maximum_edges ⇒ Object
- #normalized_edge_count(completeness) ⇒ Object
- #populate_with_completeness(completeness) ⇒ Object
- #populate_with_count(edge_count) ⇒ Object
-
#possible_edges ⇒ Object
refactor after everything works - slow with more than a few hundred if loopback edges are required I could use repeated_combination.
- #to_s ⇒ Object
Methods inherited from Set
Constructor Details
Instance Attribute Details
#completeness ⇒ Object (readonly)
Returns the value of attribute completeness.
5 6 7 |
# File 'lib/gonodes/edge_list.rb', line 5 def completeness @completeness end |
Class Method Details
Instance Method Details
#==(other_edge_list) ⇒ Object
27 28 29 |
# File 'lib/gonodes/edge_list.rb', line 27 def ==(other_edge_list) self.sort == other_edge_list.sort end |
#add_edge(edge_params) ⇒ Object
52 53 54 55 |
# File 'lib/gonodes/edge_list.rb', line 52 def add_edge(edge_params) @edges << Edge.new(edge_params) self end |
#maximum_edges ⇒ Object
67 68 69 |
# File 'lib/gonodes/edge_list.rb', line 67 def maximum_edges (@node_list.count * (@node_list.count - 1)) / 2 end |
#normalized_edge_count(completeness) ⇒ Object
57 58 59 |
# File 'lib/gonodes/edge_list.rb', line 57 def normalized_edge_count(completeness) (maximum_edges * completeness).to_i end |
#populate_with_completeness(completeness) ⇒ Object
47 48 49 50 |
# File 'lib/gonodes/edge_list.rb', line 47 def populate_with_completeness(completeness) edge_count = normalized_edge_count(completeness) populate_with_count(edge_count) end |
#populate_with_count(edge_count) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gonodes/edge_list.rb', line 31 def populate_with_count(edge_count) @completeness = (edge_count.to_f / maximum_edges).round(2) node_list_combo = possible_edges.cycle @edges.clear edge_count.times do start_node, end_node = node_list_combo.next @edges << Edge.new( start_node: start_node, end_node: end_node ) end self end |
#possible_edges ⇒ Object
refactor after everything works - slow with more than a few hundred if loopback edges are required I could use repeated_combination
63 64 65 |
# File 'lib/gonodes/edge_list.rb', line 63 def possible_edges @possible_edges ||= @node_list.to_a.combination(2).to_a end |
#to_s ⇒ Object
13 14 15 |
# File 'lib/gonodes/edge_list.rb', line 13 def to_s @edges.map{|edge| edge.to_s}.join("\n\n") end |