Class: RBF::Optimizer

Inherits:
Object
  • Object
show all
Defined in:
lib/rbf/optimizer.rb

Defined Under Namespace

Classes: Algorithm

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Optimizer

Returns a new instance of Optimizer.



37
38
39
# File 'lib/rbf/optimizer.rb', line 37

def initialize (options={})
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



35
36
37
# File 'lib/rbf/optimizer.rb', line 35

def options
  @options
end

Class Method Details

.optimization(name, &block) ⇒ Object



31
32
33
# File 'lib/rbf/optimizer.rb', line 31

def self.optimization (name, &block)
  (@@optimizations ||= []) << [name, block]
end

Instance Method Details

#algorithmsObject



54
55
56
57
58
# File 'lib/rbf/optimizer.rb', line 54

def algorithms
  @@optimizations.map {|(name, block)|
    Algorithm.new(self, &block) unless options[name] == false
  }.compact
end

#optimize(tree) ⇒ Object



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/rbf/optimizer.rb', line 41

def optimize (tree)
  result = tree.clone

  begin
    changed = algorithms.any? {|algo|
      algo.optimize(result)
    }
  end while changed

  result
end