| Total Complexity | 4 |
| Total Lines | 37 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | 1 | module NoSE |
|
| 3 | 1 | class BarbasiAlbertNetwork < Network |
|
| 4 | 1 | def initialize(params = {}) |
|
| 5 | 6 | super params |
|
| 6 | |||
| 7 | # We assume for now that m0 = m = 2 |
||
| 8 | |||
| 9 | 6 | create_entities |
|
| 10 | 6 | add_foreign_keys |
|
| 11 | end |
||
| 12 | |||
| 13 | 1 | private |
|
| 14 | |||
| 15 | # Create all the entities in the graph and their connections |
||
| 16 | # @return [void] |
||
| 17 | 1 | def create_entities |
|
| 18 | # Add the initial one or two entities |
||
| 19 | 6 | @entities = [create_entity(0)] |
|
| 20 | 6 | return if @nodes_nb == 1 |
|
| 21 | |||
| 22 | 6 | @entities << create_entity(1) |
|
| 23 | 6 | add_link 0, 1 |
|
| 24 | 6 | return if @nodes_nb == 2 |
|
| 25 | |||
| 26 | # Add and connect more entities as needed |
||
| 27 | 6 | edges = 2 |
|
| 28 | 6 | 2.upto(@nodes_nb - 1).each do |node| |
|
| 29 | 48 | @entities << create_entity(node) |
|
| 30 | 48 | pick = Pickup.new(0.upto(node - 1).to_a, |
|
| 31 | 436 | weight_func: ->(x) { x }, |
|
| 32 | 436 | uniq: true) { |n| @neighbours[n].size } |
|
| 33 | 48 | pick.pick(2).each do |node2| |
|
| 34 | 96 | add_link node, node2 |
|
| 35 | 96 | edges += 2 |
|
| 36 | end |
||
| 37 | end |
||
| 38 | end |
||
| 39 | end |
||
| 40 | end |
||
| 42 |