class Gargor::CLI

Public Instance Methods

best_individual() click to toggle source
# File lib/gargor/cli.rb, line 83
def best_individual
  Gargor.individuals.max { |a,b| a.fitness <=> b.fitness }
end
deploy(i) click to toggle source
# File lib/gargor/cli.rb, line 71
def deploy i
  i.set_params
  i.deploy
end
pbar() click to toggle source
# File lib/gargor/cli.rb, line 66
def pbar
  @pbar = Double.new if options["no_progress_bar"]
  @pbar ||= ProgressBar.new(" Tuning",Gargor.total_trials)
end
recover() click to toggle source
# File lib/gargor/cli.rb, line 54
def recover
  Gargor.base && deploy(Gargor.base)
end
report_error_exit(e,ret = 1) click to toggle source
# File lib/gargor/cli.rb, line 58
def report_error_exit e,ret = 1
  unless $TESTING
    STDERR.puts e.message
    STDERR.puts e.backtrace.join("\n") if options["verbose"]
  end
  exit ret
end
trial(i) click to toggle source
# File lib/gargor/cli.rb, line 76
def trial i
  deploy i
  i.attack
rescue Gargor::DeployError =>e
  i.fitness = 0
end
trials() click to toggle source
# File lib/gargor/cli.rb, line 45
def trials
  begin
    Gargor.populate.each { |i|
      trial(i) if i.fitness == nil 
      pbar.set(Gargor.total_trials-Gargor.last_trials)
    }
  end while(Gargor.next_generation)
end
tune(file="gargor.rb") click to toggle source
# File lib/gargor/cli.rb, line 24
def tune file="gargor.rb"
  require 'gargor/reporter'
  require 'progressbar'
  Gargor.start
  Gargor.load_dsl(file)
  Gargor.options = options

  pbar.set(0)
  trials
  best = best_individual
  deploy best 
  pbar.finish
  puts Gargor::OptimizeReporter.table(Gargor.base,best)
rescue ExterminationError =>e
  recover
  report_error_exit(e)
rescue =>e
  report_error_exit(e)
end