class ChaosDetector::GraphTheory::Reduction

Attributes

reduction_count[R]
reduction_sum[R]

Public Class Methods

combine(primary, secondary) click to toggle source
# File lib/chaos_detector/graph_theory/reduction.rb, line 25
def combine(primary, secondary)
  raise ArgumentError, ('Argument #primary should be Reduction object (was %s)' % primary.class) unless primary.is_a?(ChaosDetector::GraphTheory::Reduction)
  # raise ArgumentError, ('Argument #secondary should be Reduction object (was %s)' % secondary.class) unless secondary.is_a?(ChaosDetector::GraphTheory::Reduction)

  combined = primary ? primary.clone(freeze: false) : ChaosDetector::GraphTheory::Reduction.new
  combined.merge!(secondary)
end
combine_all(reductions) click to toggle source
# File lib/chaos_detector/graph_theory/reduction.rb, line 33
def combine_all(reductions)
  red_sum = reductions.reduce(0) { |tally, r| tally + (r ? r.reduction_count : 1) }
  Reduction.new(reduction_count: reductions.count, reduction_sum: red_sum)
end
new(reduction_count: 1, reduction_sum: 1) click to toggle source
# File lib/chaos_detector/graph_theory/reduction.rb, line 9
def initialize(reduction_count: 1, reduction_sum: 1)
  @reduction_count = reduction_count
  @reduction_sum = reduction_sum
end

Public Instance Methods

merge!(other) click to toggle source
# File lib/chaos_detector/graph_theory/reduction.rb, line 14
def merge!(other)
  @reduction_sum += (other&.reduction_count || 1)
  @reduction_count += 1 #(other&.reduction_count || 1)
  self
end
to_s() click to toggle source
# File lib/chaos_detector/graph_theory/reduction.rb, line 20
def to_s
  'Reduction (count/sum)=(%d, %d)' % [reduction_count, reduction_sum]
end