diff --git a/eo/src/eoBreeder.h b/eo/src/eoBreeder.h index f7d08351..5da02fd5 100644 --- a/eo/src/eoBreeder.h +++ b/eo/src/eoBreeder.h @@ -93,7 +93,7 @@ template class eoBreeder: public eoMonPopOp eoRandomIndiSelector selector; eoBackInserter inserter; - (*Gop)(selector.bind(pop, orgsize, i), inserter.bind(pop)); + (*Gop)(selector.bind(pop, orgsize).bias(i), inserter.bind(pop)); break; } } diff --git a/eo/src/eoGOpBreeder.h b/eo/src/eoGOpBreeder.h index 078428da..8e26f77e 100644 --- a/eo/src/eoGOpBreeder.h +++ b/eo/src/eoGOpBreeder.h @@ -40,7 +40,7 @@ class eoGOpBreeder: public eoMonPopOp for (unsigned i = 0; i < size; i++) { // and the one liner - opSel.selectOp()(selector.bind(_pop,size, i), inserter.bind(_pop)); + opSel.selectOp()(selector.bind(_pop,size).bias(i), inserter.bind(_pop)); } } diff --git a/eo/src/eoIndiSelector.h b/eo/src/eoIndiSelector.h index b2617e7c..26ffe476 100644 --- a/eo/src/eoIndiSelector.h +++ b/eo/src/eoIndiSelector.h @@ -83,16 +83,16 @@ template class eoPopIndiSelector : public eoIndiSelector { public : - eoPopIndiSelector(void) : eoIndiSelector(), pop(0), last(0), firstChoice(-1) {} + eoPopIndiSelector(void) : eoIndiSelector(), pop(0), last(0), firstChoice(-1), secondChoice(-1) {} virtual ~eoPopIndiSelector(void) {} struct eoUnitializedException{}; /** Initialization function, binds the population to the selector, can also - be used to specify an optional end and the first individual to return in operator() + be used to specify an optional end */ - eoPopIndiSelector& bind(const eoPop& _pop, int _end = -1, int _myGuy = -1) + eoPopIndiSelector& bind(const eoPop& _pop, int _end = -1) { pop = &_pop; last = _end; @@ -102,10 +102,20 @@ class eoPopIndiSelector : public eoIndiSelector last = pop->size(); } - firstChoice = _myGuy; return *this; } + /** Bias function to bias the selection function to select specific individuals + first before applying a selection algorithm defined in derived classes + */ + eoPopIndiSelector& bias(int _first, int _second = -1) + { + firstChoice = _first; + secondChoice = _second; + return *this; + } + + size_t size(void) const { valid(); return last; } const EOT& operator[](size_t _i) const { valid(); return pop->operator[](_i); } @@ -119,9 +129,17 @@ class eoPopIndiSelector : public eoIndiSelector valid(); if (firstChoice < 0 || firstChoice >= (int) size()) { - return do_select(); // let the child figure out what to do + // see if we have a second choice + if (secondChoice < 0 || secondChoice >= (int) size()) + { + return do_select(); // let the child figure out what to do + } + + const EOT& result = pop->operator[](secondChoice); + secondChoice = -1; + return result; } - + const EOT& result = pop->operator[](firstChoice); firstChoice = -1; return result; @@ -144,6 +162,7 @@ class eoPopIndiSelector : public eoIndiSelector const eoPop* pop; // need a pointer as this the pop argument can be re-instated int last; int firstChoice; + int secondChoice; }; #endif