Solver switching support & implementation of Nesterov's accelerated grad...

...ient and AdaGrad
@leelurch @jeffdonahue @longjon Thanks for the insightful comments! It's my first time to contribute to a big C++ code base, and there is still a lot to learn.

I've converted the solver pointer to `shared_ptr` according to the comments.