Optimization algorithms in Scala