To solve an optimization problem with bound constraints. More...
Public Types |
Public Member Functions | |
OptSolver () | |
Default constructor. | |
OptSolver (Vect< real_t > &x) | |
Constructor using vector of optimization variables. More... | |
OptSolver (MyOpt &opt, Vect< real_t > &x) | |
Constructor using vector of optimization variables. More... | |
~OptSolver () | |
Destructor. | |
int | getNbFctEval () const |
Return the total number of function evaluations. | |
void | setOptMethod (OptMethod m) |
Choose optimization method. More... | |
void | setBC (const Vect< real_t > &bc) |
Prescribe boundary conditions as constraints. More... | |
void | setObjective (string exp) |
Define the objective function to minimize by an algebraic expression. More... | |
void | setGradient (string exp, int i=1) |
Define a component of the gradient of the objective function to minimize by an algebraic expression. More... | |
void | setOptClass (MyOpt &opt) |
Choose user defined optimization class. More... | |
void | setUpperBound (real_t ub) |
Define upper bound for optimization variable. More... | |
void | setUpperBounds (Vect< real_t > &ub) |
Define upper bounds for optimization variables. More... | |
void | setLowerBound (real_t lb) |
Define lower bound for optimization variable. More... | |
void | setVerbosity (int verb) |
Set verbosity parameter. More... | |
void | setLowerBounds (Vect< real_t > &lb) |
Define lower bounds for optimization variables. More... | |
void | setSAOpt (real_t rt, int ns, int nt, int &neps, int maxevl, real_t t, Vect< real_t > &vm, Vect< real_t > &xopt, real_t &fopt) |
Set Simulated annealing options. More... | |
void | setTolerance (real_t toler) |
Set error tolerance. More... | |
void | setMaxIterations (int n) |
Set maximal number of iterations. | |
int | getNbObjEval () const |
Return number of objective function evaluations. | |
real_t | getTemperature () const |
Return the final temperature. More... | |
int | getNbAcc () const |
Return the number of accepted objective function evaluations. More... | |
int | getNbOutOfBounds () const |
Return the total number of trial function evaluations that would have been out of bounds. More... | |
real_t | getOptObj () const |
Return Optimal value of the objective. | |
int | run () |
Run the optimization algorithm. More... | |
int | run (real_t toler, int max_it, int verb) |
Run the optimization algorithm. More... | |
real_t | getSolution () const |
Return solution in the case of a one variable optimization. More... | |
void | getSolution (Vect< real_t > &x) const |
Get solution vector. More... | |
Friends | |
ostream & | operator<< (ostream &s, const OptSolver &os) |
Output class information. | |
Detailed Description
To solve an optimization problem with bound constraints.
Member Enumeration Documentation
enum OptMethod |
Constructor & Destructor Documentation
Constructor using vector of optimization variables.
- Parameters
-
[in] x Vector having as size the number of optimization variables. It contains the initial guess for the optimization algorithm.
- Remarks
- After using the member function run, the vector x contains the obtained solution if the optimization procedure was successful
Constructor using vector of optimization variables.
- Parameters
-
[in] opt Reference to instance of used defined optimization class. This class inherits from abstract class MyOpt. It must contain the member function double
Objective(const Vect<double> &x)
which returns the value of the objective for a given solution vectorx
. The user defined class must contain, if the optimization algothm requires it the member functionGradient(const Vect<double> &x, Vect<double> &g)
which stores the gradient of the objective in the vectorg
for a given optimization vectorx
. The user defined class must also contain, if the optimization algothm requires it the member function[in] x Vector having as size the number of optimization variables. It contains the initial guess for the optimization algorithm.
- Remarks
- After using the member function run, the vector x contains the obtained solution if the optimization procedure was successful
Member Function Documentation
void setOptMethod | ( | OptMethod | m | ) |
Choose optimization method.
- Parameters
-
[in] m Enumerated value to choose the optimization algorithm to use. Must be chosen among the enumerated values: - GRADIENT: Gradient steepest descent method with projection for bounded constrained problems
- TRUNCATED_NEWTON: The Nash's Truncated Newton Algorithm, due to S.G. Nash (Newton-type Minimization via the Lanczos method, SIAM J. Numer. Anal. 21 (1984) 770-778).
- SIMULATED_ANNEALING: Global optimization simulated annealing method. See Corana et al.'s article: "Minimizing Multimodal Functions of Continuous Variables with the Simulated Annealing Algorithm" in the September 1987 (vol. 13, no. 3, pp. 262-280) issue of the ACM Transactions on Mathematical Software.
- NELDER_MEAD: Global optimization Nelder-Mead method due to John Nelder, Roger Mead (A simplex method for function minimization, Computer Journal, Volume 7, 1965, pages 308-313). As implemented by R. ONeill (Algorithm AS 47: Function Minimization Using a Simplex Procedure, Applied Statistics, Volume 20, Number 3, 1971, pages 338-345).
Prescribe boundary conditions as constraints.
This member function is useful in the case of optimization problems where the optimization variable vector is the solution of a partial differential equation. For this case, Dirichlet boundary conditions can be prescribed as constraints for the optimization problem
- Parameters
-
[in] bc Vector containing the values to impose on degrees of freedom. This vector must have been constructed using the Mesh instance.
- Remarks
- Only degrees of freedom with positive code are taken into account as prescribed
void setObjective | ( | string | exp | ) |
Define the objective function to minimize by an algebraic expression.
- Parameters
-
[in] exp Regular expression defining the objective function
void setGradient | ( | string | exp, |
int | i = 1 |
||
) |
Define a component of the gradient of the objective function to minimize by an algebraic expression.
- Parameters
-
[in] exp Regular expression defining the objective function [in] i Component of gradient [Default: 1
]
void setOptClass | ( | MyOpt & | opt | ) |
Choose user defined optimization class.
- Parameters
-
[in] opt Reference to inherited user specified optimization class
void setUpperBound | ( | real_t | ub | ) |
Define upper bound for optimization variable.
Case of a one-variable problem
- Parameters
-
[in] ub Upper bound
Define upper bounds for optimization variables.
- Parameters
-
[in] ub Vector containing upper values for variables
void setLowerBound | ( | real_t | lb | ) |
Define lower bound for optimization variable.
Case of a one-variable problem
- Parameters
-
[in] lb Lower value
void setVerbosity | ( | int | verb | ) |
Set verbosity parameter.
- Parameters
-
[in] verb Verbosity parameter
Define lower bounds for optimization variables.
- Parameters
-
[in] lb Vector containing lower values for variables
void setSAOpt | ( | real_t | rt, |
int | ns, | ||
int | nt, | ||
int & | neps, | ||
int | maxevl, | ||
real_t | t, | ||
Vect< real_t > & | vm, | ||
Vect< real_t > & | xopt, | ||
real_t & | fopt | ||
) |
Set Simulated annealing options.
- Remarks
- This member function is useful only if simulated annealing is used.
- Parameters
-
[in] rt The temperature reduction factor. The value suggested by Corana et al. is .85. See Goffe et al. for more advice. maxevl [in] The maximum number of function evaluations. If it is exceeded, the return code=1. [in] ns Number of cycles. After ns*nb_var function evaluations, each element of vm is adjusted so that approximately half of all function evaluations are accepted. The suggested value is 20. [in] nt Number of iterations before temperature reduction. After nt*ns*n function evaluations, temperature (t) is changed by the factor rt. Value suggested by Corana et al. is max(100,5*nb_var). See Goffe et al. for further advice. [in] neps Number of final function values used to decide upon termination. See eps
. Suggested value is 4[in] maxevl [in] t The initial temperature. See Goffe et al. for advice. [in] vm The step length vector. On input it should encompass the region of interest given the starting value x. For point x[i], the next trial point is selected is from x[i]-vm[i] to x[i]+vm[i]. Since vm is adjusted so that about half of all points are accepted, the input value is not very important (i.e. is the value is off, OptimSA adjusts vm to the correct value). [in] xopt [in] fopt
void setTolerance | ( | real_t | toler | ) |
Set error tolerance.
- Parameters
-
[in] toler Error tolerance for termination. If the final function values from the last neps temperatures differ from the corresponding value at the current temperature by less than eps and the final function value at the current temperature differs from the current optimal function value by less than toler, execution terminates and the value 0 is returned.
real_t getTemperature | ( | ) | const |
Return the final temperature.
This function is meaningful only if the Simulated Annealing algorithm is used
int getNbAcc | ( | ) | const |
Return the number of accepted objective function evaluations.
This function is meaningful only if the Simulated Annealing algorithm is used
int getNbOutOfBounds | ( | ) | const |
Return the total number of trial function evaluations that would have been out of bounds.
This function is meaningful only if the Simulated Annealing algorithm is used
int run | ( | ) |
Run the optimization algorithm.
This function runs the optimization procedure using default values for parameters. To modify these values, user the function run with arguments
int run | ( | real_t | toler, |
int | max_it, | ||
int | verb | ||
) |
Run the optimization algorithm.
- Parameters
-
[in] toler Tolerance value for convergence testing [in] max_it Maximal number of iterations to achieve convergence [in] verb Verbosity parameter (to choose between 0 and 10)
real_t getSolution | ( | ) | const |
Return solution in the case of a one variable optimization.
In the case of a one variable problem, the solution value is returned, if the optimization procedure was successful
Get solution vector.
The vector x contains the solution of the optimization problem. Note that if the constructor using an initial vector was used, the vector will contain the solution once the member function run has beed used (If the optimization procedure was successful)
- Parameters
-
[out] x solution vector