Completed
Push — master ( 3f4b33...e37d52 )
by Michael
03:01
created

BarbasiAlbertNetwork   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 37
ccs 21
cts 21
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A create_entities() 0 22 3
A initialize() 0 8 1
1 1
module NoSE
0 ignored issues
show
coding-style introduced by
Missing frozen string literal comment.
Loading history...
2 1
  module Random
3 1
    class BarbasiAlbertNetwork < Network
0 ignored issues
show
Coding Style introduced by
This class should have a documentation comment as per coding style.
Loading history...
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
0 ignored issues
show
Coding Style introduced by
The Assignment, Branch, Condition size for create_entities is considered too high. [21.68/20]. The ABC size is based on assignments, branches (method calls), and conditions.
Loading history...
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
41
end
42