Class: BOAST::OptimizationSpace

Inherits:
Object
  • Object
show all
Defined in:
lib/BOAST/Optimization/Optimization.rb

Constant Summary collapse

HASH_NAME =
"options"

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*parameters) ⇒ OptimizationSpace

Returns a new instance of OptimizationSpace.



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/BOAST/Optimization/Optimization.rb', line 27

def initialize( *parameters )
  @rules = nil
  @checkers = nil
  if parameters.length == 1 and parameters[0].is_a?(Hash) then
    @parameters = []
    parameters[0].each { |key, value|
      if key == :rules then
        @rules = [value].flatten
        format_rules
      elsif key == :checkers then
        @checkers = [value].flatten
      else
        @parameters.push( OptimizationParameter::new(key, value) )
      end
    }
  else
    @parameters = parameters
  end
end

Instance Attribute Details

#checkersObject (readonly)

Returns the value of attribute checkers.



24
25
26
# File 'lib/BOAST/Optimization/Optimization.rb', line 24

def checkers
  @checkers
end

#parametersObject (readonly)

Returns the value of attribute parameters.



22
23
24
# File 'lib/BOAST/Optimization/Optimization.rb', line 22

def parameters
  @parameters
end

#rulesObject (readonly)

Returns the value of attribute rules.



23
24
25
# File 'lib/BOAST/Optimization/Optimization.rb', line 23

def rules
  @rules
end

Instance Method Details

#format_rulesObject

Add to the parameters of the rules the name of the hash variable



48
49
50
51
52
53
54
55
56
57
# File 'lib/BOAST/Optimization/Optimization.rb', line 48

def format_rules
  regxp = /(?<!#{HASH_NAME}\[):\w+(?!\])/
  @rules.each{|r|
    matches = r.scan(regxp)
    matches = matches.uniq
    matches.each{ |m|
      r.gsub!(/(?<!#{HASH_NAME}\[)#{m}(?!\])/, "#{HASH_NAME}[#{m}]")
    }
  }
end

#remove_unfeasible(points = []) ⇒ Object

Remove all points that do not meet ALL the rules.



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/BOAST/Optimization/Optimization.rb', line 60

def remove_unfeasible (points = [])
  if @rules then
    if @checkers
      @checkers.each { |checker| eval checker }
    end
    s = "  points.reject!{ |\#{HASH_NAME}|\n    not @rules.all?{ |r| eval r }\n  }\n"
    eval s
  end
end

#to_hObject



74
75
76
77
78
79
80
81
82
# File 'lib/BOAST/Optimization/Optimization.rb', line 74

def to_h
  h = {}
  @parameters.each { |p|
    h[p.name] = p.values
  }
  h[:rules] = @rules if @rules
  h[:checkers] = @checkers if @checkers
  return h
end