#!/usr/bin/env ruby
require("gsl")
include GSL::Siman

N_TRIES = 200
ITERS_FIXED_T = 10
STEP_SIZE = 10
K = 1.0
T_INITIAL = 0.002
MU_T = 1.005
T_MIN = 2.0e-6

params = Siman::Params.new(N_TRIES, ITERS_FIXED_T, STEP_SIZE, K, T_INITIAL,
                           MU_T, T_MIN)

efunc = Efunc.new { |vx|
  x = vx[0]
  s = (x - 1.0)
  Math::exp(-s*s)*Math::sin(8*x)
}

metric = Metric.new { |vx, vy|
  (x[0] - y[0]).abs
}

step = Step.new { |rng, vx, step_size|
  r = rng.uniform
  old_x = vx[0]
  a =  r * 2 * step_size - step_size + old_x
  vx[0] = a
}

simanprint = Print.new { |vx|
  printf("%12g", vx[0])
}

x = Vector.new([15.5])
Rng.env_setup()
r = Rng.new()

Siman::solve(r, x, efunc, step, metric, simanprint, params)
#Siman::solve(r, x, efunc, step, metric, nil, params)
p x
