Skip to content

Conversation

@jkhanGitHub
Copy link

This PR closes issue #322.

I made a comment on it a month ago, how this could be implemented. The way i described it on issue #322 was only partially possible. This means to ensure the program still runs the same i made only slight changes. I did not allow the user to write the gene in nested array form like i said i would, but i kept the gene_structure parameter. Therefore the user now gives num_genes and all other parameters, as well as the new gene_structure parameter to describe the nested form of its genes.

For example given a gene length of 8 the user proposes the following structure [2,1,1,1,3], then the gene has the form [ [i_0,i_1], i_2, i_3, i_4, [i_5,i_2,i_6] ].

The gene_structure then is used to calculate boundaries via the np.cumsum method.
np.cumsum(gene_structure) == num_genes; must be given.
Once a gene_structure is given it is absolute, and all genes will be in this form.
Boundaries is an array that holds all the indices that can be chosen as crossoverpoint. The length of the gene_structure parameter is continously used instead of num_genes or the offspring length for the mutation methods in order to ensure that the probabilities of mutation are the same for all genetypes regardless of their length.

The algorithm itself still uses a 1 dimensional array even when using the gene_structure. When the gene_structure is given it simply respects the boundaries and ensures atomicity. Meaning crossovers can not happen inbetween an array. Also if a complex genetype is selected to mutate all values inside will mutate (atomicity).

The fitnesswrapper was not implemented, since i did not allow the user to give nested arrays, therefore the user uses the fitness function the same way as before, control over every allele was already given.

Also added some test to confirm functionality.

Documentation should be added automatically by following the given pattern.

Some Mutation methods are slightly altered, but the functionality is the same. Uniform use of the boundaries is applied. Meaning if no gene_structure is given the boundaries are idx, idx+1 resulting in the loop with an start, end index working the same for both a given gene_structure and None.

For further questions you can address me.

…ons and add comprehensive atomicity tests for mutation and crossover.

Modified all crossover and Mutation methods to support the gene_structure given by the user.

Added Test to test the atomicity and functionality of the crossover methods and mutation methods when gene_structure parameter is provided.

Added integration test for crossover parameter
@jkhanGitHub jkhanGitHub changed the title Adding Complex Genetypes closes issue#322 Adding Complex Genetypes closes #322 Feb 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant