libfgen  0.1.15
Library for optimization using a genetic algorithm or particle swarm optimization
Data Structures | Defines | Typedefs | Functions
fpso (Particle Swarm Optimization) API

Data Structures

struct  FpsoIndividual
struct  FpsoPopulation

Defines

#define FPSO_DEFAULT_OMEGA   0.7298
#define FPSO_DEFAULT_PHI1   1.49618
#define FPSO_DEFAULT_PHI2   1.49618
#define FPSO_TOPOLOGY_GBEST   0
#define FPSO_TOPOLOGY_LBEST   1
#define FPSO_BOUND_VELOCITY_ELEMENT   1
#define FPSO_BOUND_POSITION_ELEMENT   2
#define FPSO_BOUND_NOTHING   0
#define FPSO_BOUND_VELOCITY   1
#define FPSO_BOUND_POSITION   2
#define FPSO_BOUND_POSITION_AND_VELOCITY   3

Typedefs

typedef void(* FpsoGenerationCallbackFunc )(FpsoPopulation *pop, int generation)
typedef double(* FpsoCalculateErrorFunc )(const FpsoPopulation *pop, const double *parameters)

Functions

FGEN_API FpsoPopulation * fpso_create (int population_size, int nu_parameters, FpsoGenerationCallbackFunc fpso_generation_callback_func, FpsoCalculateErrorFunc fpso_calculate_error_func)
FGEN_API void fpso_set_parameters (FpsoPopulation *pop, int topology, int bounding_strategy, double omega, double phi1, double phi2)
FGEN_API void fpso_run (FpsoPopulation *pop, int max_generation)
FGEN_API void fpso_destroy (FpsoPopulation *pop)
FGEN_API void fpso_signal_stop (FpsoPopulation *pop)
FGEN_API void fpso_set_parameter_bounds (FpsoPopulation *pso, int parameter_index, double min_bound, double max_bound)
FGEN_API void fpso_set_topology (FpsoPopulation *pso, int type)
FGEN_API void fpso_set_bounding_strategy (FpsoPopulation *pso, int type)
FGEN_API void fpso_set_user_data (FpsoPopulation *pop, void *user_data)
FGEN_API void fpso_bound_position (const FpsoPopulation *pop, const double *source, double *dest)
FGEN_API double * fpso_get_best_known_position (const FpsoPopulation *pop)
FGEN_API double fpso_get_best_known_error (const FpsoPopulation *pop)
FGEN_API FgenRNGfpso_get_rng (const FpsoPopulation *pop)

Function Documentation

FGEN_API FpsoPopulation* fpso_create ( int  population_size,
int  nu_parameters,
FpsoGenerationCallbackFunc  fpso_generation_callback_func,
FpsoCalculateErrorFunc  fpso_calculate_error_func 
)

Create a PSO population.

Parameters:
population_sizeThe size of the swarm population.
nu_parametersThe number of parameters per individual.
fpso_generation_callback_funcThe generation callback function that is called after every generation of the algorithm.
fpso_calculate_error_funcThe error evaluation function that calculates the function value or error of an individual.
Returns:
The created population.

Definition at line 23 of file pso.c.

FGEN_API void fpso_set_parameters ( FpsoPopulation *  pop,
int  topology,
int  bounding_strategy,
double  omega,
double  phi1,
double  phi2 
)

Set the parameters for an fpso population.

Parameters:
popThe population.
topologyThe swarm topology. One of FPSO_TOPOLOGY_GBEST and FPSO_TOPOLOGY_LBEST.
bounding_strategyThe bounding strategy for parameters used in the algorithm. One of the following:
  • FPSO_BOUND_NOTHING
  • FPSO_BOUND_POSITION
  • FPSO_BOUND_VELOCITY
  • FPSO_BOUND_POSITION_AND_VELOCITY Irrespective of the value, the FpsoCalculateErrorFunc will always received bounded parameters.
omegaThe omega value used in the PSO. A default value is defined as FPSO_DEFAULT_OMEGA.
phi1The phi1 value used in the PSO. A default value is defined as FPSO_DEFAULT_PHI1.
phi2the phi2 value used in the PSO. A default value is defined as FPSO_DEFAULT_PHI2.

Definition at line 60 of file pso.c.

FGEN_API void fpso_run ( FpsoPopulation *  pop,
int  max_generation 
)

Run the particle swarm optimization algorithm.

Parameters:
popThe PSO population.
max_generationThe number of generations to run. The algorithm terminates when this generation is reached. If it is equal to - 1, the algorithm runs indefinitely until fpso_signal_stop() is called.

Definition at line 245 of file pso.c.

FGEN_API void fpso_destroy ( FpsoPopulation *  pop)

Destroy all data structures associated with a PSO population.

Parameters:
popThe PSO population.

Definition at line 74 of file pso.c.

FGEN_API void fpso_signal_stop ( FpsoPopulation *  pop)

Signal stop to the PSO algorithm. When called from the generation callback function, the algorithm will terminate after the callback function returns.

Parameters:
popThe PSO population.

Definition at line 392 of file pso.c.

FGEN_API void fpso_set_parameter_bounds ( FpsoPopulation *  pop,
int  index,
double  min_bound,
double  max_bound 
)

Set the bounds for a parameter.

Parameters:
popThe PSO population.
indexThe index (starting with 0) of the parameter of which the bounds are to be set.
min_boundThe lower bound of the range.
max_boundThe upper bound of the range (exclusive).

Definition at line 325 of file pso.c.

FGEN_API void fpso_set_topology ( FpsoPopulation *  pop,
int  type 
)

Set the swarm topology.

Parameters:
popThe PSO population.
typeThe swarm topology. One of FPSO_TOPOLOGY_GBEST and FPSO_TOPOLOGY_LBEST.

Definition at line 336 of file pso.c.

FGEN_API void fpso_set_bounding_strategy ( FpsoPopulation *  pop,
int  type 
)

Set the bounding strategy used in the algorithm.

Parameters:
popThe PSO population.
typeThe bounding strategy for parameters used in the algorithm. Irrespective of the value, the FpsoCalculateErrorFunc will always received bounded parameters. The value must be one of the following:
  • FPSO_BOUND_NOTHING
  • FPSO_BOUND_POSITION
  • FPSO_BOUND_VELOCITY
  • FPSO_BOUND_POSITION_AND_VELOCITY

Definition at line 353 of file pso.c.

FGEN_API void fpso_set_user_data ( FpsoPopulation *  pop,
void *  user_data 
)

Set the user_data field of the PSO population.

Definition at line 362 of file pso.c.

FGEN_API void fpso_bound_position ( const FpsoPopulation *  pop,
const double *  src,
double *  dest 
)

Bound the parameters given in src to the predefined parameter ranges and store them in dest.

Parameters:
popThe PSO population.
srcThe source parameters.
destThe location where the bounded parameters are stored.

Definition at line 104 of file pso.c.

FGEN_API double* fpso_get_best_known_position ( const FpsoPopulation *  pop)

Return the global best known position (parameters with the smallest known error) of the PSO population.

Parameters:
popThe PSO population.
Returns:
A pointer to the best known parameters.

Definition at line 372 of file pso.c.

FGEN_API double fpso_get_best_known_error ( const FpsoPopulation *  pop)

Return the error value associated with the global best known position.

Parameters:
popThe PSO population.
Returns:
The best error value.

Definition at line 382 of file pso.c.

FGEN_API FgenRNG* fpso_get_rng ( const FpsoPopulation *  pop)

Return the random number generator belonging to the PSO population.

Definition at line 400 of file pso.c.

 All Data Structures Functions Variables