Class: ConstantDegreeConnectStrategy
- Inherits:
-
ConnectStrategy
- Object
- ConnectStrategy
- ConstantDegreeConnectStrategy
- Defined in:
- lib/gimuby/genetic/archipelago/connect_strategy/constant_degree_connect_strategy.rb
Instance Attribute Summary collapse
-
#average_degree ⇒ Object
Returns the value of attribute average_degree.
Instance Method Summary collapse
- #connect(archipelago) ⇒ Object
-
#initialize ⇒ ConstantDegreeConnectStrategy
constructor
A new instance of ConstantDegreeConnectStrategy.
Constructor Details
#initialize ⇒ ConstantDegreeConnectStrategy
Returns a new instance of ConstantDegreeConnectStrategy.
5 6 7 |
# File 'lib/gimuby/genetic/archipelago/connect_strategy/constant_degree_connect_strategy.rb', line 5 def initialize @average_degree = 4.0 end |
Instance Attribute Details
#average_degree ⇒ Object
Returns the value of attribute average_degree.
9 10 11 |
# File 'lib/gimuby/genetic/archipelago/connect_strategy/constant_degree_connect_strategy.rb', line 9 def average_degree @average_degree end |
Instance Method Details
#connect(archipelago) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/gimuby/genetic/archipelago/connect_strategy/constant_degree_connect_strategy.rb', line 11 def connect(archipelago) nodes = get_nodes(archipelago) # This won't create a graph where all nodes have same degree # since we may try to connect the same node twice number_times = (@average_degree.to_f / 2.0).round number_times.times do |_| archipelago.connect_path(nodes.shuffle!, TRUE) end end |