Class: ChaosDetector::GraphTheory::LoopDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/chaos_detector/graph_theory/loop_detector.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(detection: :simple, lookback: 0, tolerance: 0, grace_period: 0) ⇒ LoopDetector

Returns a new instance of LoopDetector.



5
6
7
8
9
10
# File 'lib/chaos_detector/graph_theory/loop_detector.rb', line 5

def initialize(detection: :simple, lookback: 0, tolerance: 0, grace_period: 0)
  @detection = detection
  @lookback = lookback
  @tolerance = tolerance
  @grace_period = grace_period
end

Class Method Details

.simpleObject



26
27
28
# File 'lib/chaos_detector/graph_theory/loop_detector.rb', line 26

def simple
  @simple ||= LoopDetector.new
end

Instance Method Details

#tolerates?(nodes, node) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
# File 'lib/chaos_detector/graph_theory/loop_detector.rb', line 12

def tolerates?(nodes, node)
  return true if (nodes.length <= @grace_period)
  # return false if (lookback.zero? && tolerance.zero? && nodes.include?(node))

  # TODO: lookback
  nodes.count(node) > tolerance

end