WPILibC++ 2024.1.1-beta-4
frc::SimulatedAnnealing< State > Class Template Reference

An implementation of the Simulated Annealing stochastic nonlinear optimization method. More...

#include <frc/optimization/SimulatedAnnealing.h>

Public Member Functions

constexpr SimulatedAnnealing (double initialTemperature, std::function< State(const State &)> neighbor, std::function< double(const State &)> cost)
 Constructor for Simulated Annealing that can be used for the same functions but with different initial states. More...
 
State Solve (const State &initialGuess, int iterations)
 Runs the Simulated Annealing algorithm. More...
 

Detailed Description

template<typename State>
class frc::SimulatedAnnealing< State >

An implementation of the Simulated Annealing stochastic nonlinear optimization method.

See also
https://en.wikipedia.org/wiki/Simulated_annealing
Template Parameters
StateThe type of the state to optimize.

Constructor & Destructor Documentation

◆ SimulatedAnnealing()

template<typename State >
constexpr frc::SimulatedAnnealing< State >::SimulatedAnnealing ( double  initialTemperature,
std::function< State(const State &)>  neighbor,
std::function< double(const State &)>  cost 
)
inlineconstexpr

Constructor for Simulated Annealing that can be used for the same functions but with different initial states.

Parameters
initialTemperatureThe initial temperature. Higher temperatures make it more likely a worse state will be accepted during iteration, helping to avoid local minima. The temperature is decreased over time.
neighborFunction that generates a random neighbor of the current state.
costFunction that returns the scalar cost of a state.

Member Function Documentation

◆ Solve()

template<typename State >
State frc::SimulatedAnnealing< State >::Solve ( const State &  initialGuess,
int  iterations 
)
inline

Runs the Simulated Annealing algorithm.

Parameters
initialGuessThe initial state.
iterationsNumber of iterations to run the solver.
Returns
The optimized state.

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