Pallas Solver  0.1
C++ Global Optimization Algorithms
Classes | Public Member Functions | List of all members
pallas::SimulatedAnnealing Class Reference

Minimizes a function using simulated annealing. More...

#include <simulated_annealing.h>

Classes

struct  HistoryOutput
 Stores information about the state of the system for at a given iteration number. More...
 
struct  Options
 
struct  Summary
 Contains a summary of the optimization. More...
 

Public Member Functions

 SimulatedAnnealing ()
 Default constructor.
 
void Solve (const SimulatedAnnealing::Options &options, const GradientProblem &problem, double *parameters, SimulatedAnnealing::Summary *global_summary)
 Minimizes the specified gradient problem. More...
 

Detailed Description

Minimizes a function using simulated annealing.

Uses simulated annealing, a random algorithm that uses no derivative information from the function being optimized. Other names for this family of approaches include: “Monte Carlo”, “Metropolis”, “Metropolis-Hastings”, etc.
Example

#include "glog/logging.h"
// Each solver is defined in its own header file.
// include the solver you wish you use:
#include "pallas/simulated_annealing.h"
// define a problem you wish to solve by inheriting
// from the pallas::GradientCostFunction interface
// and implementing the Evaluate and NumParameters methods.
class Rosenbrock : public pallas::GradientCostFunction {
public:
virtual ~Rosenbrock() {}
virtual bool Evaluate(const double* parameters,
double* cost,
double* gradient) const {
const double x = parameters[0];
const double y = parameters[1];
cost[0] = (1.0 - x) * (1.0 - x) + 100.0 * (y - x * x) * (y - x * x);
if (gradient != NULL) {
gradient[0] = -2.0 * (1.0 - x) - 200.0 * (y - x * x) * 2.0 * x;
gradient[1] = 200.0 * (y - x * x);
}
return true;
}
virtual int NumParameters() const { return 2; }
};
int main(int argc, char** argv) {
google::InitGoogleLogging(argv[0]);
// define the starting point for the optimization
double parameters[2] = {-1.2, 0.0};
// set up global optimizer options only initialization
// is need to accept the default options
// Increase the number of iterations
// SA often requires many iterations to get
// with 1 to 2 significant figures of the
// optimal solution
options.max_iterations = 1000;
options.dwell_iterations = 1000;
options.max_stagnant_iterations = 1000;
// set a high initial temperature to allow
// the SA algorithm to fully explore the
// parameter space
// quit the optimization of cost gets within
// 3 significant figures of global minimum
options.minimum_cost = 0.001;
// define custom step function which will bound the
// randomized candidate solution in order to limit
// the search and speed up convergence
double upper_bounds [2] = {5, 5};
double lower_bounds [2] = {-5, -5};
unsigned int num_parameters = 2;
double step_size = 0.1;
upper_bounds,
lower_bounds,
num_parameters));
options.set_step_function(step_function);
// initialize a summary object to hold the
// optimization details
// create a problem from your cost function
pallas::GradientProblem problem(new Rosenbrock());
// solve the problem and store the optimal position
// in parameters and the optimization details in
// the summary
pallas::Solve(options, problem, parameters, &summary);
std::cout << summary.FullReport() << std::endl;
std::cout << "Global minimum found at:" << std::endl;
std::cout << "\tx: " << parameters[0] << "\ty: " << parameters[1] << std::endl;
return 0;
}

Member Function Documentation

void pallas::SimulatedAnnealing::Solve ( const SimulatedAnnealing::Options options,
const GradientProblem &  problem,
double *  parameters,
SimulatedAnnealing::Summary global_summary 
)

Minimizes the specified gradient problem.

The specified options are used to setup a simulated annealing instance which is then used to minimize the GradientProblem. The optimal solution is stored in parameters and a summary of the global optimization can be found in summary.

Parameters
optionspallas::SimulatedAnnealing::Options. Options used to configure the optimization.
problempallas::GradientProblem. The problem to optimize.
parametersdouble*. The starting point for further optimization.
summarySimulatedAnnealing::Summary*. Summary instance to store the optimization details.

Here is the call graph for this function:

Here is the caller graph for this function:


The documentation for this class was generated from the following files: