Class: ChaosDetector::GraphTheory::NodeMetrics

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/chaos_detector/graph_theory/node_metrics.rb

Constant Summary collapse

GRAPH_PROPERTIES =
%i[ total_couplings afference efference instability ].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(node, afference: 0, efference: 0, terminal_routes:, circular_routes:) ⇒ NodeMetrics

Returns a new instance of NodeMetrics.



25
26
27
28
29
30
31
32
33
# File 'lib/chaos_detector/graph_theory/node_metrics.rb', line 25

def initialize(node, afference: 0, efference: 0, terminal_routes:, circular_routes:)
  raise ArgumentError("node is required") if node.nil?

  @node = node
  @afference = afference
  @efference = efference
  @terminal_routes = terminal_routes || []
  @circular_routes = circular_routes || []
end

Instance Attribute Details

#afferenceObject

Returns the value of attribute afference.



9
10
11
# File 'lib/chaos_detector/graph_theory/node_metrics.rb', line 9

def afference
  @afference
end

#circular_routesObject

Returns the value of attribute circular_routes.



12
13
14
# File 'lib/chaos_detector/graph_theory/node_metrics.rb', line 12

def circular_routes
  @circular_routes
end

#efferenceObject

Returns the value of attribute efference.



10
11
12
# File 'lib/chaos_detector/graph_theory/node_metrics.rb', line 10

def efference
  @efference
end

#nodeObject (readonly)

Returns the value of attribute node.



13
14
15
# File 'lib/chaos_detector/graph_theory/node_metrics.rb', line 13

def node
  @node
end

#terminal_routesObject

Returns the value of attribute terminal_routes.



11
12
13
# File 'lib/chaos_detector/graph_theory/node_metrics.rb', line 11

def terminal_routes
  @terminal_routes
end

Instance Method Details

#instabilityObject

en.wikipedia.org/wiki/Software_package_metrics I = Ce / (Ce + Ca). I = efference / (total couplings) Value from 0.0 to 1.0 I = 0.0 is maximally stable while I = 1.0 is maximally unstable.



41
42
43
44
# File 'lib/chaos_detector/graph_theory/node_metrics.rb', line 41

def instability
  cT = total_couplings.to_f
  (cT.zero?) ? 0.0 : @efference / cT
end

#reduction_countObject



21
22
23
# File 'lib/chaos_detector/graph_theory/node_metrics.rb', line 21

def reduction_count
  @node&.reduction&.reduction_count || 1
end

#reduction_sumObject



17
18
19
# File 'lib/chaos_detector/graph_theory/node_metrics.rb', line 17

def reduction_sum
  @node&.reduction&.reduction_sum || 1
end

#summaryObject



50
51
52
# File 'lib/chaos_detector/graph_theory/node_metrics.rb', line 50

def summary
  'I = Ce / (Ce + Ca)'
end

#to_hObject



54
55
56
57
58
59
60
61
# File 'lib/chaos_detector/graph_theory/node_metrics.rb', line 54

def to_h
  {
    afference: afference,
    efference: efference,
    instability: instability.round(2),
    total_couplings: total_couplings
  }
end

#to_sObject



63
64
65
# File 'lib/chaos_detector/graph_theory/node_metrics.rb', line 63

def to_s
  "Ce: #{@efference}, Ca: #{@afference}, I: #{instability}"
end

#total_couplingsObject



46
47
48
# File 'lib/chaos_detector/graph_theory/node_metrics.rb', line 46

def total_couplings
  @afference + @efference
end