Class: BarabasiAlbertConnectStrategy
- Inherits:
-
ConnectStrategy
- Object
- ConnectStrategy
- BarabasiAlbertConnectStrategy
- Defined in:
- lib/gimuby/genetic/archipelago/connect_strategy/barabasi_albert_connect_strategy.rb
Instance Attribute Summary collapse
-
#average_degree ⇒ Object
Returns the value of attribute average_degree.
-
#score_factor ⇒ Object
Returns the value of attribute score_factor.
Instance Method Summary collapse
- #connect(archipelago) ⇒ Object
-
#initialize ⇒ BarabasiAlbertConnectStrategy
constructor
A new instance of BarabasiAlbertConnectStrategy.
Constructor Details
#initialize ⇒ BarabasiAlbertConnectStrategy
Returns a new instance of BarabasiAlbertConnectStrategy.
6 7 8 9 |
# File 'lib/gimuby/genetic/archipelago/connect_strategy/barabasi_albert_connect_strategy.rb', line 6 def initialize @average_degree = 4.0 @score_factor = 1.0 end |
Instance Attribute Details
#average_degree ⇒ Object
Returns the value of attribute average_degree
11 12 13 |
# File 'lib/gimuby/genetic/archipelago/connect_strategy/barabasi_albert_connect_strategy.rb', line 11 def average_degree @average_degree end |
#score_factor ⇒ Object
Returns the value of attribute score_factor
12 13 14 |
# File 'lib/gimuby/genetic/archipelago/connect_strategy/barabasi_albert_connect_strategy.rb', line 12 def score_factor @score_factor end |
Instance Method Details
#connect(archipelago) ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'lib/gimuby/genetic/archipelago/connect_strategy/barabasi_albert_connect_strategy.rb', line 14 def connect(archipelago) nodes = get_nodes(archipelago) nodes.shuffle! edges_to_build_per_node = (@average_degree.to_f / 2.0).round handled_nodes = nodes.slice!(0, edges_to_build_per_node) # We make a fully connected component of those ones built = make_fully_connected(archipelago, handled_nodes) nodes.each do |node| built += connect_node(archipelago, handled_nodes, node) handled_nodes.push(node) end built end |