Class: RoadForest::SourceRigor::CredenceAnnealer

Inherits:
Object
  • Object
show all
Defined in:
lib/roadforest/source-rigor/credence-annealer.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(graph) ⇒ CredenceAnnealer

Returns a new instance of CredenceAnnealer.



5
6
7
8
# File 'lib/roadforest/source-rigor/credence-annealer.rb', line 5

def initialize(graph)
  @graph = graph
  @attempts = 5
end

Instance Attribute Details

#attemptsObject

Returns the value of attribute attempts.



10
11
12
# File 'lib/roadforest/source-rigor/credence-annealer.rb', line 10

def attempts
  @attempts
end

Instance Method Details

#resolve(&block) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/roadforest/source-rigor/credence-annealer.rb', line 12

def resolve(&block)
  attempts = @attempts

  @graph.force_impulse

  begin
    raise "Annealing failed after #@attempts attempts" if (attempts -= 1) < 0
    @graph.next_impulse
    block.call
  end until @graph.quiet_impulse?
end