LibCudaOptimize
1.0
|
Base Optimizer Class. More...
#include <IOptimizer.h>
Public Member Functions | |
IOptimizer (EvalFuncPtr fPtr=NULL, unsigned int dn=PROBLEM_DIMENSIONS, unsigned int sn=NUM_SETS, unsigned int pn=NUM_SOLUTIONS) | |
Create the optimizers. See setParams. | |
virtual bool | init () |
Initialize the optimizer. | |
virtual void | free () |
Free memory. | |
virtual void | optimize () |
Launch the optimization. | |
void | setParams (EvalFuncPtr fPtr=NULL, unsigned int dn=PROBLEM_DIMENSIONS, unsigned int sn=NUM_SETS, unsigned int pn=NUM_SOLUTIONS) |
Set parameters used in the optimization. | |
void | setTerminationFlags (TERMINATION_FLAGS f) |
Set the criteria for stopping the optimization. | |
void | setGenerations (unsigned int gn) |
set maximum number of generations if TERMINATE_GENS is set (see setTerminationFlags) | |
void | setFunctionEvals (unsigned int fn) |
set maximum number of function evaluations if TERMINATE_EVALS is set (see setTerminationFlags) | |
void | setStoppingTime (float st) |
set limit of time if TERMINATE_TIME is set (see setTerminationFlags) | |
void | setStoppingFitness (float f) |
set limit fitness value if TERMINATE_FIT is set (see setTerminationFlags) | |
void | setStoppingFitness (unsigned int sId, float f) |
set limit fitness value to a single set if TERMINATE_FIT is set (see setTerminationFlags) | |
void | setNumberOfSets (unsigned int sn) |
set number of sets involved in the optimization process | |
void | setNumberOfSolutions (unsigned int pn) |
set number of solutions for each set | |
void | setProblemDimension (unsigned int dn) |
set the number of the dimensions of the problem | |
void | setEvalFuncPtr (EvalFuncPtr evalPtr) |
set the fitness function | |
void | setBounds (float2 bounds) |
set bounds for all sets | |
void | setBounds (unsigned int sId, float2 bounds) |
set bounds for a single set | |
void | setBounds (unsigned int sId, unsigned int dId, float2 bounds) |
set bounds for a single dimension in a single set | |
void | setVerbosity (LOG_LEVEL verb) |
set verbosity of the log | |
void | setOptimizationType (OPTIMUM ot) |
receives a OPTIMUM representing if the optimum of the function is the maximum or the minimum | |
void | setHostFitnessEvaluation (bool on) |
set this to true if the fitness evaluation will happen on host side: in this way the host pointer will always be updated | |
void | setFileOutput (std::string f) |
set the file chosen for the log | |
void | resetFileOutput () |
set the stderr for log output | |
const SolutionSet * | getSolutionSet () const |
Get a constant copy of the solution set. | |
unsigned int | getNumberOfSets () const |
get number of sets | |
unsigned int | getNumberOfSolutions () const |
get number of solutions in a set | |
unsigned int | getProblemDimension () const |
get problem dimension | |
unsigned int | getFunctionEvals () const |
get number of evaluations used as a termination criteria | |
unsigned int | getCurrentEvals () const |
get number of evaluations performed in the optimization so far | |
unsigned int | getCurrentGeneration () const |
get number of generations performed in the optimization so far | |
TERMINATION_FLAGS | getTerminationFlags () const |
get termination flags | |
float | getElapsedTime () const |
get time passed from the beginning of optimization | |
virtual float * | getBestFitnesses () |
get a pointer to best fitnesses of all sets | |
virtual float | getBestFitness (unsigned int sid) |
get value of the best fitness for set indicated by the index sid | |
virtual float * | getBestSolution () |
get best solutions of all sets | |
virtual float * | getBestSolution (unsigned int sid) |
get best solution of the set indicated by the index sid | |
bool | isHostFitnessEvaluation () const |
returns true if the fitness evaluation will happen on host side | |
Protected Member Functions | |
virtual void | initSolutions (dim3 initializationGrid, dim3 initializationBlock)=0 |
Initialize solutions. | |
virtual void | step (dim3 initializationGrid, dim3 initializationBlock)=0 |
Generate solutions for subsequent fitnessEvaluation. | |
virtual void | fitnessEvaluation (dim3 initializationGrid, dim3 initializationBlock, bool first=false)=0 |
Evaluate solutions. | |
virtual void | update (dim3 initializationGrid, dim3 initializationBlock, bool first=false)=0 |
Update population according to the algorithm and the results of fitnessEvaluation. | |
virtual void | findBest () |
Updates global best fitnesses, indexes in SolutionSet device memory. |
Base Optimizer Class.
To override this class you need to implement at least 4 methods:
initSolutions
step
fitnessEvaluation
update
Definition at line 71 of file IOptimizer.h.
virtual void IOptimizer::fitnessEvaluation | ( | dim3 | initializationGrid, |
dim3 | initializationBlock, | ||
bool | first = false |
||
) | [protected, pure virtual] |
Evaluate solutions.
initializationGrid | organization of the CUDA blocks |
initializationBlock | organization of the CUDA threads |
first | it signals if it is the first evaluation of the optimization |
Implemented in PSO_Optimizer, DE_Optimizer, and SW_Optimizer.
const SolutionSet* IOptimizer::getSolutionSet | ( | ) | const [inline] |
Get a constant copy of the solution set.
Definition at line 220 of file IOptimizer.h.
virtual void IOptimizer::initSolutions | ( | dim3 | initializationGrid, |
dim3 | initializationBlock | ||
) | [protected, pure virtual] |
Initialize solutions.
initializationGrid | organization of the CUDA blocks |
initializationBlock | organization of the CUDA threads |
Implemented in PSO_Optimizer, DE_Optimizer, and SW_Optimizer.
void IOptimizer::setParams | ( | EvalFuncPtr | fPtr = NULL , |
unsigned int | dn = PROBLEM_DIMENSIONS , |
||
unsigned int | sn = NUM_SETS , |
||
unsigned int | pn = NUM_SOLUTIONS |
||
) | [inline] |
Set parameters used in the optimization.
fPtr | as instance of EvalFuncPtr representing the fitness function |
dn | problem dimension |
sn | number of the sets that will run in the optimization |
pn | number of solutions for each set |
Definition at line 165 of file IOptimizer.h.
void IOptimizer::setTerminationFlags | ( | TERMINATION_FLAGS | f | ) | [inline] |
Set the criteria for stopping the optimization.
More than one criterion can be set using | (or) operator. Possible values are TERMINATE_EVALS (use number of function evaluations), TERMINATE_GENS (number of generations), TERMINATE_FIT (value of fitness), TERMINATE_TIME (time)
f | the termination flags |
Definition at line 182 of file IOptimizer.h.
virtual void IOptimizer::step | ( | dim3 | initializationGrid, |
dim3 | initializationBlock | ||
) | [protected, pure virtual] |
Generate solutions for subsequent fitnessEvaluation.
initializationGrid | organization of the CUDA blocks |
initializationBlock | organization of the CUDA threads |
Implemented in PSO_Optimizer, DE_Optimizer, and SW_Optimizer.
virtual void IOptimizer::update | ( | dim3 | initializationGrid, |
dim3 | initializationBlock, | ||
bool | first = false |
||
) | [protected, pure virtual] |
Update population according to the algorithm and the results of fitnessEvaluation.
initializationGrid | organization of the CUDA blocks |
initializationBlock | organization of the CUDA threads |
first | it signals if it is the first evaluation of the optimization |
Implemented in PSO_Optimizer, DE_Optimizer, and SW_Optimizer.