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

BarbasiAlbertNetwork.initialize()   A

Complexity

Conditions 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 1
rs 9.4285
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