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>

Collaboration diagram for CGA< T >:
Collaboration graph

Public Member Functions

 CGA ()
 Default constructor.
virtual ~CGA ()
 Destructor.
 CGA (const CGA &C)
 Copy constructor.
CGA & operator= (const 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 (ProgressReporter *_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< CIndividual > Ind
 Current population of individuals.
std::vector< CIndividual > Ind_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.
T Model_out
 Output model configured with best parameters.
T * Model = nullptr
 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.
ProgressReporter * rtw = 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;
CGA()
Default constructor.
Definition GA.hpp:38

Definition at line 352 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 38 of file GA.hpp.

References fitdist, GA_params, Ind, Ind_old, MaxFitness, and numberOfThreads.

Referenced by CGA(), and operator=().

◆ ~CGA()

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

Destructor.

Cleans up allocated memory and closes output files.

Definition at line 312 of file GA.hpp.

◆ 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 276 of file GA.hpp.

References CGA(), filenames, fitdist, GA_params, Ind, Ind_old, loged, MaxFitness, GA_Tweaking_parameters::maxpop, paramname, and 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 128 of file GA.hpp.

References apply_to_all, filenames, fitdist, GA_params, Ind, Ind_old, loged, lognormal, MaxFitness, maxval, minval, Model, numberOfThreads, paramname, params, and Setminmax().

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 987 of file GA.hpp.

References assignrank(), GA_params, and Ind.

Referenced by assignfitnesses().

◆ 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 350 of file GA.hpp.

References assignfitness_rank(), counter, filenames, GA_params, Ind, loged, maxfitness(), Model_out, Models, numberOfThreads, OpenGAFile(), rtw, sumfitness, and x.

Referenced by evaluateforward(), getfromoutput(), and optimize().

◆ 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.

◆ 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 972 of file GA.hpp.

References GA_params, and Ind.

Referenced by assignfitness_rank().

◆ 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 951 of file GA.hpp.

References GA_params, and Ind.

◆ 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 961 of file GA.hpp.

References GA_params, and Ind.

Referenced by stdfitness().

◆ 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 578 of file GA.hpp.

References GA_params, and Ind.

Referenced by variancefitness().

◆ 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 492 of file GA.hpp.

References cross(), cross2p(), fitdist, GA_params, Ind, Ind_old, maxfitness(), and x.

Referenced by optimize().

◆ 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 521 of file GA.hpp.

References cross_RC_L(), fitdist, GA_params, GetRndUnif(), Ind, Ind_old, maxfitness(), and x.

Referenced by optimize().

◆ 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 1019 of file GA.hpp.

References assignfitnesses(), filenames, GA_params, and params.

◆ 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 998 of file GA.hpp.

References fitdist, GA_params, and Ind.

Referenced by optimize().

◆ 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 880 of file GA.hpp.

References GA_params.

◆ 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 839 of file GA.hpp.

References assignfitnesses(), final_params, GA_params, and write_to_detailed_GA().

◆ 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 1038 of file GA.hpp.

References GA_params, initial_pop, and loged.

Referenced by initialize().

◆ 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 1064 of file GA.hpp.

References initial_pop, and 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 866 of file GA.hpp.

References apply_to_all.

◆ 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 318 of file GA.hpp.

References filenames, GA_params, getinifromoutput(), Ind, initial_pop, and loged.

Referenced by optimize().

◆ 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 185 of file GA.hpp.

References apply_to_all, fitdist, GA_params, Ind, Ind_old, loged, lognormal, MaxFitness, maxval, minval, Model, paramname, params, and Setminmax().

◆ 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 914 of file GA.hpp.

References GA_params, and Ind.

Referenced by assignfitnesses(), crossover(), crossoverRC(), and optimize().

◆ 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 906 of file GA.hpp.

References GA_params, Ind, and mutate().

Referenced by mutate(), and optimize().

◆ operator=()

template<class T>
CGA< T > & CGA< T >::operator= ( const 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 293 of file GA.hpp.

References CGA(), filenames, fitdist, GA_params, Ind, Ind_old, loged, MaxFitness, paramname, and 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 596 of file GA.hpp.

References assignfitnesses(), crossover(), crossoverRC(), current_generation, filenames, fillfitdist(), final_params, GA_params, GAFitMeasure(), Ind, initialize(), loged, MaxFitness, maxfitness(), Model, Models, mutate(), OpenGAFile(), paramname, rtw, shake(), write_to_detailed_GA(), and 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 338 of file GA.hpp.

References GA_params, and Ind.

Referenced by CGA(), and InitiatePopulation().

◆ 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 234 of file GA.hpp.

References GA_params, Ind, and Ind_old.

◆ 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 249 of file GA.hpp.

References fitdist, GA_params, Ind, Ind_old, CIndividual::maxrange, CIndividual::minrange, and CIndividual::precision.

Referenced by SetProperty().

◆ 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 570 of file GA.hpp.

References SetProperty().

◆ 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 545 of file GA.hpp.

References filenames, GA_params, last_error, numberOfThreads, and setnumpop().

Referenced by SetProperties().

◆ SetRunTimeWindow()

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

Set progress window for GUI updates.

Parameters
_rtwPointer to ProgressReporter 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 689 of file GA.h.

References 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 898 of file GA.hpp.

References GA_params, Ind, and shake().

Referenced by optimize(), and shake().

◆ 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 940 of file GA.hpp.

References avg_inv_actual_fitness(), GA_params, and Ind.

◆ 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 929 of file GA.hpp.

References avgfitness(), GA_params, and Ind.

◆ 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 587 of file GA.hpp.

References filenames, and OpenGAFile().

Referenced by getfromoutput(), and optimize().

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 463 of file GA.h.

Referenced by CGA(), getparamno(), and InitiatePopulation().

◆ 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 394 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 982 of file GA.h.

Referenced by optimize().

◆ 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 385 of file GA.h.

Referenced by CGA(), CGA(), assignfitnesses(), evaluateforward(), initialize(), operator=(), optimize(), SetProperty(), and write_to_detailed_GA().

◆ 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 410 of file GA.h.

Referenced by getfromoutput(), and optimize().

◆ 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 989 of file GA.h.

Referenced by CGA(), CGA(), CGA(), crossover(), crossoverRC(), fillfitdist(), InitiatePopulation(), operator=(), and setnumpop().

◆ 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 440 of file GA.h.

◆ GA_params

◆ 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 478 of file GA.h.

Referenced by CGA(), CGA(), CGA(), assignfitness_rank(), assignfitnesses(), assignrank(), avg_actual_fitness(), avg_inv_actual_fitness(), avgfitness(), crossover(), crossoverRC(), fillfitdist(), initialize(), InitiatePopulation(), maxfitness(), mutate(), operator=(), optimize(), Setminmax(), setnparams(), setnumpop(), shake(), stdfitness(), and variancefitness().

◆ 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 486 of file GA.h.

Referenced by CGA(), CGA(), CGA(), crossover(), crossoverRC(), InitiatePopulation(), operator=(), setnparams(), and setnumpop().

◆ 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 402 of file GA.h.

Referenced by getinifromoutput(), getinitialpop(), and initialize().

◆ 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 676 of file GA.h.

Referenced by SetProperty().

◆ 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 426 of file GA.h.

Referenced by CGA(), CGA(), assignfitnesses(), getinifromoutput(), initialize(), InitiatePopulation(), operator=(), and optimize().

◆ 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 369 of file GA.h.

Referenced by CGA(), CGA(), CGA(), InitiatePopulation(), operator=(), and optimize().

◆ 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 456 of file GA.h.

Referenced by CGA(), and InitiatePopulation().

◆ 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 448 of file GA.h.

Referenced by CGA(), and InitiatePopulation().

◆ Model

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

Pointer to the model being optimized.

Reference to model that provides fitness evaluation.

Definition at line 516 of file GA.h.

Referenced by CGA(), InitiatePopulation(), and optimize().

◆ 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 509 of file GA.h.

Referenced by assignfitnesses().

◆ 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 502 of file GA.h.

Referenced by assignfitnesses(), and optimize().

◆ 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 996 of file GA.h.

Referenced by CGA(), CGA(), assignfitnesses(), and SetProperty().

◆ 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 470 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 494 of file GA.h.

Referenced by CGA(), CGA(), InitiatePopulation(), operator=(), and optimize().

◆ 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 418 of file GA.h.

Referenced by CGA(), CGA(), evaluateforward(), InitiatePopulation(), and operator=().

◆ rtw

template<class T>
ProgressReporter* 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 1005 of file GA.h.

Referenced by assignfitnesses(), optimize(), and 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 361 of file GA.h.

Referenced by assignfitnesses().

◆ 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 433 of file GA.h.


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