SedSat3 1.1.6
Sediment Source Apportionment Tool - Advanced statistical methods for environmental pollution research
Loading...
Searching...
No Matches
CGA< T > Class Template Reference

Genetic Algorithm optimizer for global parameter estimation. More...

#include <GA/GA.h>

Inheritance diagram for CGA< T >:
Inheritance graph
Collaboration diagram for CGA< T >:
Collaboration graph

Public Member Functions

 CGA ()
 Default constructor.
 
virtual ~CGA ()
 Destructor.
 
 CGA (const CGA &C)
 Copy constructor.
 
CGA operator= (CGA &C)
 Assignment operator.
 
 CGA (std::string filename, const T &model)
 Constructor from configuration file and model.
 
 CGA (T *model)
 Constructor from model pointer.
 
void initialize ()
 Initialize GA structures and allocate memory.
 
double getfromoutput (std::string filename)
 Read best solution from previous output file.
 
void getinifromoutput (std::string filename)
 Initialize population from previous output file.
 
void getinitialpop (std::string filename)
 Read initial population from file.
 
int optimize ()
 Main optimization loop.
 
bool SetProperty (const std::string &varname, const std::string &value)
 Set GA property from string key-value pair.
 
bool SetProperties (const std::map< std::string, std::string > &arguments)
 Set multiple GA properties from map.
 
void InitiatePopulation ()
 Create initial population.
 
void SetRunTimeWindow (ProgressWindow *_rtw)
 Set progress window for GUI updates.
 

Public Attributes

double sumfitness
 Sum of all fitness values in current population.
 
double MaxFitness
 Maximum fitness value in current population.
 
GA_Tweaking_parameters GA_params
 GA algorithm configuration parameters.
 
_filenames filenames
 File paths for GA input/output.
 
std::vector< double > calc_output_percentiles
 Percentiles to calculate for output distributions.
 
std::vector< std::vector< double > > initial_pop
 Initial population loaded from file.
 
std::vector< double > final_params
 Final optimized parameter values.
 
std::vector< int > params
 Parameter indices being optimized.
 
std::vector< int > loged
 Flags indicating if parameters are log-transformed.
 
std::vector< int > to_ts
 Time series index for each parameter (if applicable)
 
std::vector< double > fixedinputvale
 Fixed values for non-optimized parameters.
 
std::vector< double > minval
 Lower bounds for each parameter.
 
std::vector< double > maxval
 Upper bounds for each parameter.
 
std::vector< bool > apply_to_all
 Flags indicating if parameter applies to all entities.
 
std::vector< std::vector< int > > outcompare
 Output comparison indices (legacy, may be unused)
 
std::vector< CIndividualInd
 Current population of individuals.
 
std::vector< CIndividualInd_old
 Previous generation's population.
 
std::vector< std::string > paramname
 Names of parameters being optimized.
 
std::vector< T > Models
 Copies of model for parallel fitness evaluation.
 
Model_out
 Output model configured with best parameters.
 
T * Model
 Pointer to the model being optimized.
 
std::string last_error
 Last error message from GA execution.
 

Private Member Functions

void Setminmax (int a, double minrange, double maxrange, int prec)
 Set parameter bounds and precision.
 
void fitnessdistini ()
 Initialize fitness distribution for selection.
 
void crossover ()
 Perform crossover operation on population.
 
double avgfitness ()
 Calculate average fitness of population.
 
void mutate (double mu)
 Apply mutation to population.
 
void assignfitnesses ()
 Evaluate fitness for all individuals in population.
 
int maxfitness ()
 Find index of individual with maximum fitness.
 
double variancefitness ()
 Calculate variance of population fitness.
 
double stdfitness ()
 Calculate standard deviation of population fitness.
 
double avg_actual_fitness ()
 Calculate average of actual (untransformed) fitness values.
 
void write_to_detailed_GA (std::string s)
 Write detailed GA information to file.
 
void setnumpop (int n)
 Set population size.
 
double avg_inv_actual_fitness ()
 Calculate average of inverse actual fitness.
 
int optimize (int nGens, char DefOutPutFileName[])
 Optimize for specified number of generations.
 
void setnparams (int n)
 Set number of parameters.
 
void assignfixedvalues ()
 Assign fixed values to non-optimized parameters.
 
void assignrank ()
 Assign ranks to individuals based on fitness.
 
void assignfitness_rank (double N)
 Assign fitness using rank-based scheme.
 
void shake ()
 Apply shake/perturbation to population.
 
void crossoverRC ()
 Real-coded crossover operation.
 
void getfromfile (char filename[])
 Read population from file.
 
void fillfitdist ()
 Fill fitness distribution for roulette wheel selection.
 
double assignfitnesses (std::vector< double > inp)
 Evaluate fitness for specific parameter vector.
 
double Gradient_Descent (std::vector< double > inp)
 Perform gradient descent local search.
 
int getparamno (int i, int ts)
 Get parameter index for variable and time series.
 
int get_act_paramno (int i)
 Get active parameter number.
 
int get_time_series (int i)
 Get time series index for parameter.
 
double evaluateforward ()
 Evaluate model forward (compute predictions)
 
double evaluateforward_mixed (std::vector< double > v)
 Evaluate model with mixed parameters.
 

Private Attributes

int current_generation = 0
 Current generation counter.
 
GADistribution fitdist
 Fitness distribution for parent selection.
 
int numberOfThreads
 Number of threads for parallel fitness evaluation.
 
ProgressWindowrtw = nullptr
 Pointer to progress window for GUI updates.
 

Detailed Description

template<class T>
class CGA< T >

Genetic Algorithm optimizer for global parameter estimation.

The CGA class implements a sophisticated genetic algorithm with both binary and real-coded representations for solving complex optimization problems in sediment source fingerprinting.

Algorithm Overview

Genetic Algorithms are population-based metaheuristic optimization methods inspired by natural evolution:

  1. Initialize: Create random population of candidate solutions
  2. Evaluate: Calculate fitness (objective function) for each individual
  3. Select: Choose parents based on fitness (better individuals more likely)
  4. Crossover: Combine parent solutions to create offspring
  5. Mutate: Randomly perturb offspring to maintain diversity
  6. Replace: Form next generation from offspring (and/or parents)
  7. Repeat: Continue until convergence or generation limit reached

Key Features

  • Multiple encoding schemes: Binary and real-coded representations
  • Flexible selection methods: Fitness proportionate, rank-based, tournament
  • Various crossover operators: Single-point, two-point, uniform, arithmetic
  • Adaptive mutation: Self-adjusting based on convergence state
  • Hybrid optimization: Optional gradient-based local search
  • Parallel evaluation: Thread-safe fitness evaluation
  • Progress tracking: GUI integration for real-time monitoring

Usage in SedSat3

GA provides global optimization for source apportionment when:

  • Posterior is multimodal (multiple local optima)
  • Gradient information unavailable or unreliable
  • Robust global search needed
  • Derivative-free optimization preferred

GA finds parameter values that minimize error between predicted and observed tracer concentrations, subject to constraints (e.g., contributions sum to 100%).

Mathematical Details

Fitness function (for minimization):

fitness = -Σ((y_observed - y_predicted)² / σ²)

Selection probability (fitness proportionate):

P(select individual i) = fitness_i / Σ(fitness_j)

Rank-based fitness:

fitness_rank(i) = N - 2(N-1)(rank(i)-1)/(population_size-1)

where N is selection pressure parameter (typically 1.5-2.0)

Template Parameters
TModel class type (e.g., SourceSinkData) that provides:
  • Parameter setting interface
  • Objective function evaluation
  • Model predictions
Note
Thread-safe for parallel fitness evaluation
Warning
May converge to local optimum; multiple runs recommended
See also
CIndividual
GADistribution
SourceSinkData

Example usage:

// Create GA optimizer for source apportionment
CGA<SourceSinkData> ga(&sourceData);
// Configure GA parameters
ga.GA_params.maxpop = 100;
ga.GA_params.nGen = 500;
ga.GA_params.pcross = 0.8;
ga.GA_params.pmute = 0.02;
ga.GA_params.RCGA = true; // Use real-coded GA
// Set parameter ranges
ga.minval = {0.0, 0.0, 0.0}; // 3 sources
ga.maxval = {1.0, 1.0, 1.0};
// Initialize and run
ga.InitiatePopulation();
ga.optimize();
// Extract best solution
std::vector<double> bestParams = ga.final_params;
Genetic Algorithm optimizer for global parameter estimation.
Definition GA.h:350

Definition at line 349 of file GA.h.

Constructor & Destructor Documentation

◆ CGA() [1/4]

template<class T >
CGA< T >::CGA ( )

Default constructor.

Creates uninitialized GA object. Must call other initialization methods before running.

Definition at line 12 of file GA.cpp.

◆ ~CGA()

template<class T >
CGA< T >::~CGA ( )
virtual

Destructor.

Cleans up allocated memory and closes output files.

Definition at line 203 of file GA.cpp.

◆ CGA() [2/4]

template<class T >
CGA< T >::CGA ( const CGA< T > &  C)

Copy constructor.

Parameters
CThe CGA object to copy from

Creates deep copy including population, settings, and model copies.

Definition at line 169 of file GA.cpp.

References CGA< T >::filenames, CGA< T >::fitdist, CGA< T >::GA_params, CGA< T >::Ind, CGA< T >::loged, CGA< T >::MaxFitness, CGA< T >::paramname, and CGA< T >::params.

◆ CGA() [3/4]

template<class T >
CGA< T >::CGA ( std::string  filename,
const T &  model 
)

Constructor from configuration file and model.

Parameters
filenamePath to GA configuration file
modelReference to model to optimize

Initializes GA from configuration file containing parameters, ranges, and algorithm settings.

◆ CGA() [4/4]

template<class T >
CGA< T >::CGA ( T *  model)

Constructor from model pointer.

Parameters
modelPointer to model to optimize

Preferred constructor linking GA to specific model instance.

Definition at line 108 of file GA.hpp.

References lognormal.

Member Function Documentation

◆ assignfitness_rank()

template<class T >
void CGA< T >::assignfitness_rank ( double  N)
private

Assign fitness using rank-based scheme.

Parameters
NSelection pressure parameter

Calculates fitness from rank using linear ranking formula: fitness(rank) = N - 2(N-1)(rank-1)/(pop_size-1)

Reduces selection pressure compared to raw fitness, preventing premature convergence.

Parameters
NSelection pressure (typically 1.5-2.0)

Definition at line 743 of file GA.cpp.

◆ assignfitnesses() [1/2]

template<class T >
void CGA< T >::assignfitnesses ( )
private

Evaluate fitness for all individuals in population.

Calculates objective function value for each individual. Can be parallelized across multiple threads.

Postcondition
Each individual's fitness member is updated
sumfitness and MaxFitness are updated

Definition at line 241 of file GA.cpp.

References x.

◆ assignfitnesses() [2/2]

template<class T >
double CGA< T >::assignfitnesses ( std::vector< double >  inp)
private

Evaluate fitness for specific parameter vector.

Parameters
inpParameter values to evaluate
Returns
Fitness value for given parameters

Single-point fitness evaluation (not on entire population). Used for local search refinement.

Definition at line 543 of file GA.cpp.

◆ assignfixedvalues()

template<class T >
void CGA< T >::assignfixedvalues ( )
private

Assign fixed values to non-optimized parameters.

For each individual, sets non-variable parameters to their fixed values from fixedinputvale vector.

◆ assignrank()

template<class T >
void CGA< T >::assignrank ( )
private

Assign ranks to individuals based on fitness.

Sorts population by fitness and assigns ranks (1 = best). Used for rank-based selection methods.

Postcondition
Individuals ordered by fitness

Definition at line 728 of file GA.cpp.

◆ avg_actual_fitness()

template<class T >
double CGA< T >::avg_actual_fitness ( )
private

Calculate average of actual (untransformed) fitness values.

Returns
Mean of raw fitness values

Average fitness before any scaling or transformation.

Definition at line 707 of file GA.cpp.

◆ avg_inv_actual_fitness()

template<class T >
double CGA< T >::avg_inv_actual_fitness ( )
private

Calculate average of inverse actual fitness.

Returns
Mean of 1/fitness values

Used for certain fitness scaling schemes where lower raw values are better (minimization).

Definition at line 717 of file GA.cpp.

◆ avgfitness()

template<class T >
double CGA< T >::avgfitness ( )
private

Calculate average fitness of population.

Returns
Mean fitness value across all individuals

Used for monitoring convergence and population quality.

Definition at line 374 of file GA.cpp.

◆ crossover()

template<class T >
void CGA< T >::crossover ( )
private

Perform crossover operation on population.

Applies crossover operator to selected parent pairs to generate offspring. Type of crossover determined by GA_params.cross_over_type.

Postcondition
Offspring replace parents (or are added to population)

Definition at line 322 of file GA.cpp.

References cross(), cross2p(), and x.

◆ crossoverRC()

template<class T >
void CGA< T >::crossoverRC ( )
private

Real-coded crossover operation.

Performs crossover for real-valued (continuous) representation using arithmetic or blend crossover operators.

Note
Used when GA_params.RCGA is true
See also
crossover()

Definition at line 351 of file GA.cpp.

References cross_RC_L(), GetRndUnif(), and x.

◆ evaluateforward()

template<class T >
double CGA< T >::evaluateforward ( )
private

Evaluate model forward (compute predictions)

Returns
Objective function value (model-data misfit)

Runs model with current parameters and calculates error relative to observations.

Definition at line 775 of file GA.cpp.

◆ evaluateforward_mixed()

template<class T >
double CGA< T >::evaluateforward_mixed ( std::vector< double >  v)
private

Evaluate model with mixed parameters.

Parameters
vParameter vector (subset or transformed)
Returns
Objective function value

Variation of forward evaluation for special parameter handling.

◆ fillfitdist()

template<class T >
void CGA< T >::fillfitdist ( )
private

Fill fitness distribution for roulette wheel selection.

Constructs cumulative distribution function (CDF) from individual fitness values for probabilistic parent selection.

Precondition
assignfitnesses() must have been called
Postcondition
fitdist is ready for sampling

Definition at line 754 of file GA.cpp.

◆ fitnessdistini()

template<class T >
void CGA< T >::fitnessdistini ( )
private

Initialize fitness distribution for selection.

Sets up cumulative fitness distribution (CDF) used in roulette wheel selection for choosing parents.

◆ get_act_paramno()

template<class T >
int CGA< T >::get_act_paramno ( int  i)
private

Get active parameter number.

Parameters
iParameter index
Returns
Active parameter index (excluding fixed parameters)

◆ get_time_series()

template<class T >
int CGA< T >::get_time_series ( int  i)
private

Get time series index for parameter.

Parameters
iParameter index
Returns
Time series index

Definition at line 638 of file GA.cpp.

◆ getfromfile()

template<class T >
void CGA< T >::getfromfile ( char  filename[])
private

Read population from file.

Parameters
filenamePath to population file

Loads population state from checkpoint or previous run.

◆ getfromoutput()

template<class T >
double CGA< T >::getfromoutput ( std::string  filename)

Read best solution from previous output file.

Parameters
filenamePath to GA output file
Returns
Best fitness value found in file

Extracts best individual from previous run for warm-starting or comparison.

Definition at line 598 of file GA.cpp.

◆ getinifromoutput()

template<class T >
void CGA< T >::getinifromoutput ( std::string  filename)

Initialize population from previous output file.

Parameters
filenamePath to output file containing population data

Reads population from GA output file format. Extracts parameter values from previous run's final generation to use as starting population.

Definition at line 794 of file GA.cpp.

◆ getinitialpop()

template<class T >
void CGA< T >::getinitialpop ( std::string  filename)

Read initial population from file.

Parameters
filenamePath to population file

Loads pre-specified starting population from file. Used when GA_params.readfromgafile is true.

Definition at line 820 of file GA.cpp.

References x.

◆ getparamno()

template<class T >
int CGA< T >::getparamno ( int  i,
int  ts 
)
private

Get parameter index for variable and time series.

Parameters
iVariable index
tsTime series index
Returns
Parameter index in optimization vector

Definition at line 625 of file GA.cpp.

◆ Gradient_Descent()

template<class T >
double CGA< T >::Gradient_Descent ( std::vector< double >  inp)
private

Perform gradient descent local search.

Parameters
inpStarting parameter values
Returns
Improved fitness after local search

Applies gradient-based refinement to individual for hybrid GA. Accelerates convergence in neighborhood of optimum.

Note
Used when GA_params.Steepest_Descent is true

◆ initialize()

template<class T >
void CGA< T >::initialize ( )

Initialize GA structures and allocate memory.

Sets up:

  • Population arrays
  • Fitness distribution
  • Model copies for parallel evaluation
  • Parameter ranges
Precondition
GA_params must be configured
Parameter ranges (minval, maxval) must be set
Postcondition
Ready for InitiatePopulation() call

Definition at line 209 of file GA.cpp.

◆ InitiatePopulation()

template<class T >
void CGA< T >::InitiatePopulation ( )

Create initial population.

Generates starting population using one of:

  • Random initialization within parameter bounds (default)
  • Loading from file (if readfromgafile is true)
  • Custom initial population (if initial_pop is set)
Precondition
GA must be initialized via initialize()
Parameter bounds must be set
Postcondition
Ind vector contains maxpop individuals
All individuals have random or loaded parameter values
See also
initialize()

Definition at line 165 of file GA.hpp.

References lognormal.

◆ maxfitness()

template<class T >
int CGA< T >::maxfitness ( )
private

Find index of individual with maximum fitness.

Returns
Index of best individual in Ind vector

Identifies elite individual for preservation or output.

Definition at line 670 of file GA.cpp.

◆ mutate()

template<class T >
void CGA< T >::mutate ( double  mu)
private

Apply mutation to population.

Parameters
muMutation probability per gene

Randomly perturbs parameters of individuals with probability mu. Maintains genetic diversity and enables exploration.

Parameters
muProbability of mutating each parameter (0-1)

Definition at line 662 of file GA.cpp.

◆ operator=()

template<class T >
CGA< T > CGA< T >::operator= ( CGA< T > &  C)

Assignment operator.

Parameters
CThe CGA object to assign from
Returns
Reference to this object

Copies all data from another GA object.

Definition at line 186 of file GA.cpp.

References CGA< T >::filenames, CGA< T >::fitdist, CGA< T >::GA_params, CGA< T >::Ind, CGA< T >::Ind_old, CGA< T >::loged, CGA< T >::MaxFitness, CGA< T >::paramname, and CGA< T >::params.

◆ optimize() [1/2]

template<class T >
int CGA< T >::optimize ( )

Main optimization loop.

Returns
0 on success, negative on error

Executes complete GA workflow:

  1. Initialize/load population
  2. Evaluate fitness
  3. For each generation: a. Selection b. Crossover c. Mutation d. Fitness evaluation e. Statistics and output
  4. Return best solution
Precondition
Population must be initialized via InitiatePopulation()
Postcondition
final_params contains best solution
Results written to output file
See also
InitiatePopulation()

Definition at line 394 of file GA.cpp.

References x.

◆ optimize() [2/2]

template<class T >
int CGA< T >::optimize ( int  nGens,
char  DefOutPutFileName[] 
)
private

Optimize for specified number of generations.

Parameters
nGensNumber of generations to evolve
DefOutPutFileNameDefault output filename
Returns
0 on success

Alternative optimize interface with explicit generation count and output file specification.

◆ Setminmax()

template<class T >
void CGA< T >::Setminmax ( int  a,
double  minrange,
double  maxrange,
int  prec 
)
private

Set parameter bounds and precision.

Parameters
aParameter index
minrangeLower bound
maxrangeUpper bound
precPrecision/discretization level (for binary encoding)

Configures search space boundaries for individual parameter.

Definition at line 229 of file GA.cpp.

◆ setnparams()

template<class T >
void CGA< T >::setnparams ( int  n)
private

Set number of parameters.

Parameters
nParameter count

Allocates storage for n-dimensional parameter vectors.

Postcondition
GA_params.nParam is updated
Parameter-related vectors are resized

Definition at line 129 of file GA.cpp.

◆ setnumpop()

template<class T >
void CGA< T >::setnumpop ( int  n)
private

Set population size.

Parameters
nNumber of individuals

Allocates memory for population of size n.

Postcondition
GA_params.maxpop is updated
Ind and Ind_old vectors are resized

Definition at line 142 of file GA.cpp.

References CIndividual::maxrange, CIndividual::minrange, CIndividual::nParams, and CIndividual::precision.

◆ SetProperties()

template<class T >
bool CGA< T >::SetProperties ( const std::map< std::string, std::string > &  arguments)

Set multiple GA properties from map.

Parameters
argumentsMap of property names to values
Returns
true if all properties were set successfully

Batch property setting for configuration management.

Definition at line 549 of file GA.hpp.

◆ SetProperty()

template<class T >
bool CGA< T >::SetProperty ( const std::string &  varname,
const std::string &  value 
)

Set GA property from string key-value pair.

Parameters
varnameProperty name (e.g., "population_size", "mutation_rate")
valueProperty value as string
Returns
true if property was recognized and set successfully

Allows configuration from text files or user input. Supports all fields in GA_params structure.

Definition at line 524 of file GA.hpp.

◆ SetRunTimeWindow()

template<class T >
void CGA< T >::SetRunTimeWindow ( ProgressWindow _rtw)
inline

Set progress window for GUI updates.

Parameters
_rtwPointer to ProgressWindow object

Links GA to progress dialog for real-time status updates including:

  • Current generation number
  • Best fitness value
  • Population statistics
  • Convergence plots

Definition at line 686 of file GA.h.

References CGA< T >::rtw.

◆ shake()

template<class T >
void CGA< T >::shake ( )
private

Apply shake/perturbation to population.

Randomly perturbs all individuals to escape local optima or restore diversity. Perturbation magnitude controlled by GA_params.shakescale.

Useful when population has converged but not to optimum.

Definition at line 654 of file GA.cpp.

◆ stdfitness()

template<class T >
double CGA< T >::stdfitness ( )
private

Calculate standard deviation of population fitness.

Returns
Fitness standard deviation

Square root of fitness variance. Easier to interpret as it's in same units as fitness.

Definition at line 696 of file GA.cpp.

◆ variancefitness()

template<class T >
double CGA< T >::variancefitness ( )
private

Calculate variance of population fitness.

Returns
Fitness variance across population

Measure of population diversity. Low variance indicates convergence (all individuals similar). High variance indicates diverse population.

Definition at line 685 of file GA.cpp.

◆ write_to_detailed_GA()

template<class T >
void CGA< T >::write_to_detailed_GA ( std::string  s)
private

Write detailed GA information to file.

Parameters
sString to append to detailed log

Logs generation-by-generation statistics for analysis:

  • Best/worst/average fitness
  • Population diversity metrics
  • Parameter value distributions

Definition at line 383 of file GA.cpp.

Member Data Documentation

◆ apply_to_all

template<class T >
std::vector<bool> CGA< T >::apply_to_all

Flags indicating if parameter applies to all entities.

Used for shared parameters across multiple sources or observations.

Definition at line 460 of file GA.h.

◆ calc_output_percentiles

template<class T >
std::vector<double> CGA< T >::calc_output_percentiles

Percentiles to calculate for output distributions.

Vector of percentile values (0-1 scale) to compute from population of solutions. Typical: {0.025, 0.5, 0.975} for median and 95% range

Definition at line 391 of file GA.h.

◆ current_generation

template<class T >
int CGA< T >::current_generation = 0
private

Current generation counter.

Tracks which generation is currently being evolved. Used for output, termination, and adaptive operators.

Definition at line 979 of file GA.h.

◆ filenames

template<class T >
_filenames CGA< T >::filenames

File paths for GA input/output.

Configuration structure containing paths for initialization files, results output, and checkpoint files.

Definition at line 382 of file GA.h.

Referenced by CGA< T >::CGA(), and CGA< T >::operator=().

◆ final_params

template<class T >
std::vector<double> CGA< T >::final_params

Final optimized parameter values.

Best solution found by GA (parameter vector of best individual from final generation).

Definition at line 407 of file GA.h.

◆ fitdist

template<class T >
GADistribution CGA< T >::fitdist
private

Fitness distribution for parent selection.

Cumulative distribution function used in roulette wheel selection.

Definition at line 986 of file GA.h.

Referenced by CGA< T >::CGA(), and CGA< T >::operator=().

◆ fixedinputvale

template<class T >
std::vector<double> CGA< T >::fixedinputvale

Fixed values for non-optimized parameters.

Parameters not being optimized are held constant at these values.

Definition at line 437 of file GA.h.

◆ GA_params

template<class T >
GA_Tweaking_parameters CGA< T >::GA_params

GA algorithm configuration parameters.

All tuning parameters controlling GA behavior. Modify before calling initialize() or optimize().

Definition at line 374 of file GA.h.

Referenced by CGA< T >::CGA(), and CGA< T >::operator=().

◆ Ind

template<class T >
std::vector<CIndividual> CGA< T >::Ind

Current population of individuals.

Active population of candidate solutions being evolved. Size: GA_params.maxpop

Definition at line 475 of file GA.h.

Referenced by CGA< T >::CGA(), and CGA< T >::operator=().

◆ Ind_old

template<class T >
std::vector<CIndividual> CGA< T >::Ind_old

Previous generation's population.

Backup of population from previous generation for comparison and elitism strategies.

Definition at line 483 of file GA.h.

Referenced by CGA< T >::operator=().

◆ initial_pop

template<class T >
std::vector<std::vector<double> > CGA< T >::initial_pop

Initial population loaded from file.

Parameter values for starting population when readfromgafile is true. Structure: initial_pop[individual][parameter]

Definition at line 399 of file GA.h.

◆ last_error

template<class T >
std::string CGA< T >::last_error

Last error message from GA execution.

If GA fails or encounters issues, error description stored here.

Definition at line 673 of file GA.h.

◆ loged

template<class T >
std::vector<int> CGA< T >::loged

Flags indicating if parameters are log-transformed.

If loged[i] is true, parameter i is optimized in log-space. Useful for parameters spanning multiple orders of magnitude.

Definition at line 423 of file GA.h.

Referenced by CGA< T >::CGA(), and CGA< T >::operator=().

◆ MaxFitness

template<class T >
double CGA< T >::MaxFitness

Maximum fitness value in current population.

Tracks the best individual's fitness for convergence monitoring and termination criteria.

Definition at line 366 of file GA.h.

Referenced by CGA< T >::CGA(), and CGA< T >::operator=().

◆ maxval

template<class T >
std::vector<double> CGA< T >::maxval

Upper bounds for each parameter.

Maximum allowable values defining search space boundaries. For source contributions: typically 1.0 or 100.0

Definition at line 453 of file GA.h.

◆ minval

template<class T >
std::vector<double> CGA< T >::minval

Lower bounds for each parameter.

Minimum allowable values defining search space boundaries. For source contributions: typically 0.0

Definition at line 445 of file GA.h.

◆ Model

template<class T >
T* CGA< T >::Model

Pointer to the model being optimized.

Reference to model that provides fitness evaluation.

Definition at line 513 of file GA.h.

◆ Model_out

template<class T >
T CGA< T >::Model_out

Output model configured with best parameters.

Model instance set to optimal parameter values after optimization.

Definition at line 506 of file GA.h.

◆ Models

template<class T >
std::vector<T> CGA< T >::Models

Copies of model for parallel fitness evaluation.

Each individual gets its own model copy for thread-safe evaluation. Size: GA_params.maxpop

Definition at line 499 of file GA.h.

◆ numberOfThreads

template<class T >
int CGA< T >::numberOfThreads
private

Number of threads for parallel fitness evaluation.

Controls parallelization of fitness calculations across population.

Definition at line 993 of file GA.h.

◆ outcompare

template<class T >
std::vector<std::vector<int> > CGA< T >::outcompare

Output comparison indices (legacy, may be unused)

Mapping for comparing model outputs to observations.

Definition at line 467 of file GA.h.

◆ paramname

template<class T >
std::vector<std::string> CGA< T >::paramname

Names of parameters being optimized.

Human-readable labels for each parameter (e.g., "Agricultural", "Forest", "Urban") used in output files and visualization.

Definition at line 491 of file GA.h.

Referenced by CGA< T >::CGA(), and CGA< T >::operator=().

◆ params

template<class T >
std::vector<int> CGA< T >::params

Parameter indices being optimized.

Maps GA parameter space to model parameter space. Allows optimizing subset of parameters while fixing others.

Definition at line 415 of file GA.h.

Referenced by CGA< T >::CGA(), and CGA< T >::operator=().

◆ rtw

template<class T >
ProgressWindow* CGA< T >::rtw = nullptr
private

Pointer to progress window for GUI updates.

If not nullptr, GA updates progress bar and displays current generation, best fitness, convergence plot, etc.

Definition at line 1002 of file GA.h.

Referenced by CGA< T >::SetRunTimeWindow().

◆ sumfitness

template<class T >
double CGA< T >::sumfitness

Sum of all fitness values in current population.

Used for fitness proportionate selection (roulette wheel). Updated after each fitness evaluation.

Definition at line 358 of file GA.h.

◆ to_ts

template<class T >
std::vector<int> CGA< T >::to_ts

Time series index for each parameter (if applicable)

Maps parameters to specific time series or observations.

Definition at line 430 of file GA.h.


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