[galib] Constrainted Optimization (Bruckmann, Tobias)

matthew wall mwall at oculustech.com
Mon Dec 3 11:08:17 EST 2007

On Mon, 3 Dec 2007 at 10:37:10, Bruckmann, Tobias wrote:

> The problem is that the population object is declared as "const" while
> destroy() calls remove() which is NOT const. I'm not an experienced C++
> programmer, so I'm having problems to get the point. What is the reason to
> introduce a "const" population while a function is offered to kill
> individuals (which fails because of the protection)? Or does it lead to
> problems to change the population size during run time? This idea came to my
> mind since I'm not sure if the implementation creates a new population with
> the original size also from a reduced population.
> I guess there is a legal way to solve the problem (as a bad hack, I could try
> to replace the "const" population, but this shouldn't be the way...).

the 'population' method on the GA class is const because the GA does not want
you to muck about with its population.  you can read it, but you cannot modify
it.  internally there are (or may be, depending on the GA) other objects that
use the population object, and if the population object is modified without
telling them, they will not be happy.

if you want to make changes to the population, then you should do so from within
a GA class of your own.

another way is to make your own population class then feed that to a standard GA.


More information about the galib mailing list