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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# 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
  if @checkers then
    @checkers.each { |checker| eval checker }
  end
  if @rules then
    s = "  def rules_checker(\#{HASH_NAME})\nreturn ( (\#{@rules.join(\") and (\")}) )\n  end\n"
  else
s = "  def rules_checker(\#{HASH_NAME})\nreturn true\n  end\n"
  end
  eval s
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



65
66
67
68
69
70
71
72
73
74
# File 'lib/BOAST/Optimization/Optimization.rb', line 65

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.



77
78
79
80
81
82
83
84
# File 'lib/BOAST/Optimization/Optimization.rb', line 77

def remove_unfeasible (points = [])
  if @rules then
    points.select!{ |pt|
      rules_checker(pt)
    }
  end
  return points
end

#to_hObject



86
87
88
89
90
91
92
93
94
# File 'lib/BOAST/Optimization/Optimization.rb', line 86

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