protocol
genetic_algorithm_problem_protocol
Protocol for genetic algorithm problem definitions. A problem object must define the required predicates for individuals, fitness (energy), crossover, and mutation, and may optionally define initial population generation, stopping, progress reporting, diversity, and adaptive rate hooks.
logtalk_load(genetic_algorithm(loader))staticPublic predicates
random_individual/1
Generates a random individual (candidate solution). Used to build the initial population when initial_population/1 is not defined and to replace individuals when needed.
staticrandom_individual(Individual)random_individual(-nonvar) - oneinitial_population/1
Optionally returns a non-empty list of initial individuals. When not defined, the algorithm generates a random initial population of the requested size by repeated calls to random_individual/1.
staticinitial_population(Population)initial_population(-list(nonvar)) - zero_or_onestate_energy/2
Computes the energy (cost / fitness) of the given individual. The algorithm minimizes this value by default; use the objective(maximize) option to maximize it instead.
staticstate_energy(Individual,Energy)state_energy(+nonvar,-number) - onecrossover/4
Recombines two parent individuals into two offspring. This is the most problem-specific operator after representation and strongly influences search quality.
staticcrossover(Parent1,Parent2,Offspring1,Offspring2)crossover(+nonvar,+nonvar,-nonvar,-nonvar) - onemutate/2
Produces a mutated version of the given individual. Mutation introduces diversity and helps escape local optima.
staticmutate(Individual,Mutated)mutate(+nonvar,-nonvar) - onestop_condition/3
True when the search should stop given the current generation, best individual found so far, and its energy. Optional. When not defined by the problem, the search runs until the maximum number of generations is reached.
staticstop_condition(Generation,BestIndividual,BestEnergy)stop_condition(+non_negative_integer,+nonvar,+number) - zero_or_oneprogress/5
Called periodically to report optimization progress. Optional. When not defined by the problem, progress reporting is skipped. The mean energy and diversity are population statistics; diversity is problem-defined when diversity/2 is present, otherwise a simple placeholder.
staticprogress(Generation,BestIndividual,BestEnergy,MeanEnergy,Diversity)progress(+non_negative_integer,+nonvar,+number,+number,+number) - zero_or_onediversity/2
Optionally computes a numeric diversity measure for the current population. When not defined, progress reporting uses 0.0 for diversity.
staticdiversity(Population,Diversity)diversity(+list(nonvar),-number) - zero_or_onecrossover_rate/4
Optional adaptive crossover-rate hook. Called once per generation with the current generation index, the maximum number of generations, and the current crossover rate. When defined and successful, the returned rate (clamped to [0.0, 1.0]) is used for that generation and overrides any crossover_schedule/1 option. When not defined or when it fails, the configured schedule is applied instead.
staticcrossover_rate(Generation,MaxGenerations,CurrentRate,NewRate)crossover_rate(+non_negative_integer,+positive_integer,+float,-float) - zero_or_onemutation_rate/4
Optional adaptive mutation-rate hook. Called once per generation with the current generation index, the maximum number of generations, and the current mutation rate. When defined and successful, the returned rate (clamped to [0.0, 1.0]) is used for that generation and overrides any mutation_schedule/1 option. When not defined or when it fails, the configured schedule is applied instead.
staticmutation_rate(Generation,MaxGenerations,CurrentRate,NewRate)mutation_rate(+non_negative_integer,+positive_integer,+float,-float) - zero_or_oneProtected predicates
(none)
Private predicates
(none)
Operators
(none)