Best data structure for genetic algorithm in C ++?

I need to implement a genetic algorithm configured for my problem (college project), and in the first version it was encoded as a matrix of short ones (bits per chromosome x population size).

It was a bad design, as I declare a short one, but only using the values ​​"0" and "1" ... but it was just a prototype and it worked as intended, and now it is time for me to develop a new, improved version. Performance is important here, but simplicity is also appreciated.

I researched and came up with:

for a chromosome: - A class of strings (for example, "0100100010") - An array of bool - Vector (vectors are apparently optimized for bool) - Bitset (sounds most natural)

and for the population: - C Array [] - Vector - Queue

I tend to choose a vector for the chromosome and an array for pop music, but I would like someone with experience on this.

Thanks in advance!

+3
source share
4 answers

, . , , . vector<> vector<char> . vector<char> , bitset<> vector<bool> . vector<char> x8 ( , char= ). , , vector<char>. , vector<bool> bitset<>. , bitset<> , , , , , : ) (, , -), ) , bitset bitset, ( ), . , , vector<bool> , vector<char>.

vector<char>, typedef char gene;, vector<gene>, .

A string a vector<char>, .

+7

, . , . . STL, , , , .. ( C) , . , . ( "10110110" )

, . . . Unix-. .

, . . , .

, - .. ..

, .

, , .

Galib

http://lancet.mit.edu/ga/

+1

, ( , kingchris, , ), , . , / .. , , ... , , , , , , "0", "1" 8- , 16- . , , , , , . , , . (), , , .

0

, , , .

" bools", int ints ( (/) ) .

- , . - ( ArrayList, ).

I have had great success with the genetic algorithms with the recipe above. If you properly prepare your member class, it will really simplify the situation and allow you to focus on coding the best genetic algorithms instead of worrying about your data structures.

0
source

Source: https://habr.com/ru/post/1712167/


All Articles