traitecoevo/plant

Moving new individual's state initialization into strategy

Opened this issue · 0 comments

Hello,

When adding a new strategy new states are initialized in the individual class as opposed to in the strategy which becomes a problem if one needs to initialize more states than just the height.

A proposed solution is to create an initialize_state() method in each strategy that will be called in the individual (most likely a virtual method in the base Strategy class).

Here is my proposed solution in the Individual class constructor (see last line changed):

Individual(strategy_type_ptr s) : strategy(s) { if (strategy->aux_index.size() != s->aux_size()) { strategy->refresh_indices(); } vars.resize(strategy_type::state_size(), s->aux_size()); // = Internals(strategy_type::state_size()); s->initialize_states(vars); }

And then in the strategy class (FF16 for illustration):

void FF16_Strategy::initialize_states(Internals &vars){ vars.set_state(HEIGHT_INDEX, height_0); update_dependent_aux(HEIGHT_INDEX, vars); }