Class: Gargor::Individual
- Inherits:
-
Object
- Object
- Gargor::Individual
- Defined in:
- lib/gargor/individual.rb
Instance Attribute Summary collapse
-
#fitness ⇒ Object
Returns the value of attribute fitness.
-
#params ⇒ Object
Returns the value of attribute params.
Instance Method Summary collapse
- #attack ⇒ Object
- #deploy ⇒ Object
-
#initialize ⇒ Individual
constructor
A new instance of Individual.
- #load_now ⇒ Object
- #set_params ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize ⇒ Individual
Returns a new instance of Individual.
9 10 11 12 |
# File 'lib/gargor/individual.rb', line 9 def initialize @params = {} @fitness = nil end |
Instance Attribute Details
#fitness ⇒ Object
Returns the value of attribute fitness.
8 9 10 |
# File 'lib/gargor/individual.rb', line 8 def fitness @fitness end |
#params ⇒ Object
Returns the value of attribute params.
8 9 10 |
# File 'lib/gargor/individual.rb', line 8 def params @params end |
Instance Method Details
#attack ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/gargor/individual.rb', line 56 def attack ret = nil;out = nil cmd = Gargor.opt('attack_cmd') puts "==> attack" puts "execute: #{cmd}" tms = Benchmark.realtime do out = `#{cmd}` ret = $? end @fitness = Gargor.opt('evaluate_proc').call(ret.to_i,out,tms) puts "fitness: #{@fitness}" @fitness end |
#deploy ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/gargor/individual.rb', line 38 def deploy ret = true Gargor.opt("target_nodes").each { |node| puts "==> deploy to #{node}" cmd = Gargor.opt("target_cooking_cmd") % [node] puts " #{cmd}" r = system(cmd) unless r puts "deploy failed" @fitness = 0 sleep 1 end ret &= r } ret end |
#load_now ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/gargor/individual.rb', line 18 def load_now @params.each { |name,param| json = File.open(param.file).read @params[name].value = JsonPath.on(json,param.path).first } self end |
#set_params ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/gargor/individual.rb', line 26 def set_params puts "==> set params" puts @params @params.each { |name,param| json = File.open(param.file).read json = JSON.pretty_generate(JsonPath.for(json).gsub(param.path) { |v| param.value }.to_hash) # 書き出し File.open(param.file,"w") { |f| f.write(json) } puts " write #{param.file}" } end |
#to_s ⇒ Object
14 15 16 |
# File 'lib/gargor/individual.rb', line 14 def to_s [@params,@fitness].to_s end |