class BOAST::OptimizationSpace

Constants

HASH_NAME

Attributes

checkers[R]
parameters[R]
rules[R]

Public Class Methods

new( *parameters ) click to toggle source
# 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 = <<EOF
  def rules_checker(#{HASH_NAME})
    return ( (#{@rules.join(") and (")}) )
  end
EOF
      else
s = <<EOF
  def rules_checker(#{HASH_NAME})
    return true
  end
EOF
      end
      eval s
    end

Public Instance Methods

format_rules() click to toggle source

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

# 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 = []) click to toggle source

Remove all points that do not meet ALL the rules.

# 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_h() click to toggle source
# 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