for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
module NoSE
module Random
class WattsStrogatzNetwork < Network
def initialize(params = {})
super params
@beta = params.fetch :beta, 0.5
@node_degree = params.fetch :node_degree, 2
@nodes = 0..(@nodes_nb - 1)
@entities = @nodes.map do |node|
create_entity node
end
build_initial_links
rewire_links
add_foreign_keys
private
# Set up the initial links between all nodes
# @return [void]
def build_initial_links
@nodes.each do |node|
(@node_degree / 2).times do |i|
add_link node, (node + i + 1) % @nodes_nb
# Rewire all links between nodes
def rewire_links
next unless rand < @beta
neighbour = (node + i + 1) % @nodes_nb
remove_link node, neighbour
add_link node, new_neighbour(node, neighbour)