2D vector value replacement using classes; genetic algorithm mutation

Posted by gcolumbus on Stack Overflow See other posts from Stack Overflow or by gcolumbus
Published on 2012-09-05T21:12:41Z Indexed on 2012/09/05 21:38 UTC
Read the original article Hit count: 188

Filed under:
|
|

I have a 2D vector as defined by the classes below. Note that I've used classes because I'm trying to program a genetic algorithm such that many, many 2D vectors will be created and they will all be different.

class Quad: public std::vector<int>
{
    public:
    Quad() : std::vector<int>(4,0) {}
};

class QuadVec : public std::vector<Quad>
{
};

An important part of my algorithm, however, is that I need to be able to "mutate" (randomly change) particular values in a certain number of randomly chosen 2D vectors. This has me stumped. I can easily write code to randomly select the value within the 2D vector that will be selected for "mutation" but how do I actually enact that change using classes? I understand how this would be done with one 2D vector that has already been initialized but how do I do this if it hasn't?

Please let me know if I haven't provided enough info or am not clear as I tend to do that.

Thanks for your time and help!

© Stack Overflow or respective owner

Related posts about c++

Related posts about vector