Implementing an optimization algorithm