class RandomConnectStrategy

Attributes

average_degree[RW]

Public Class Methods

new() click to toggle source
# File lib/gimuby/genetic/archipelago/connect_strategy/random_connect_strategy.rb, line 6
def initialize
  @average_degree = 4.0
end

Public Instance Methods

connect(archipelago) click to toggle source
# File lib/gimuby/genetic/archipelago/connect_strategy/random_connect_strategy.rb, line 12
def connect(archipelago)
  nodes = get_nodes(archipelago)
  connections_to_make = @average_degree * nodes.length
  check_connections_to_make(connections_to_make, nodes)
  made = 0
  begin
    from_node = nodes[rand(nodes.length)]
    to_node = nodes[rand(nodes.length)]
    has_edge = archipelago.has_edge(from_node, to_node)
    if from_node != to_node || has_edge
      archipelago.add_edge(from_node, to_node)
      made += 1
    end
  end while made < connections_to_make
  made
end