Added a bias function next to bind(). This function will bias the selection to select certain specific guys...
This commit is contained in:
parent
2af4074c2c
commit
007046c134
3 changed files with 27 additions and 8 deletions
|
|
@ -93,7 +93,7 @@ template<class Chrom> class eoBreeder: public eoMonPopOp<Chrom>
|
||||||
eoRandomIndiSelector<Chrom> selector;
|
eoRandomIndiSelector<Chrom> selector;
|
||||||
eoBackInserter<Chrom> inserter;
|
eoBackInserter<Chrom> inserter;
|
||||||
|
|
||||||
(*Gop)(selector.bind(pop, orgsize, i), inserter.bind(pop));
|
(*Gop)(selector.bind(pop, orgsize).bias(i), inserter.bind(pop));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -40,7 +40,7 @@ class eoGOpBreeder: public eoMonPopOp<EOT>
|
||||||
|
|
||||||
for (unsigned i = 0; i < size; i++)
|
for (unsigned i = 0; i < size; i++)
|
||||||
{ // and the one liner
|
{ // 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));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -83,16 +83,16 @@ template <class EOT>
|
||||||
class eoPopIndiSelector : public eoIndiSelector<EOT>
|
class eoPopIndiSelector : public eoIndiSelector<EOT>
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
eoPopIndiSelector(void) : eoIndiSelector<EOT>(), pop(0), last(0), firstChoice(-1) {}
|
eoPopIndiSelector(void) : eoIndiSelector<EOT>(), pop(0), last(0), firstChoice(-1), secondChoice(-1) {}
|
||||||
|
|
||||||
virtual ~eoPopIndiSelector(void) {}
|
virtual ~eoPopIndiSelector(void) {}
|
||||||
|
|
||||||
struct eoUnitializedException{};
|
struct eoUnitializedException{};
|
||||||
|
|
||||||
/** Initialization function, binds the population to the selector, can also
|
/** 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<EOT>& _pop, int _end = -1, int _myGuy = -1)
|
eoPopIndiSelector& bind(const eoPop<EOT>& _pop, int _end = -1)
|
||||||
{
|
{
|
||||||
pop = &_pop;
|
pop = &_pop;
|
||||||
last = _end;
|
last = _end;
|
||||||
|
|
@ -102,10 +102,20 @@ class eoPopIndiSelector : public eoIndiSelector<EOT>
|
||||||
last = pop->size();
|
last = pop->size();
|
||||||
}
|
}
|
||||||
|
|
||||||
firstChoice = _myGuy;
|
|
||||||
return *this;
|
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; }
|
size_t size(void) const { valid(); return last; }
|
||||||
const EOT& operator[](size_t _i) const { valid(); return pop->operator[](_i); }
|
const EOT& operator[](size_t _i) const { valid(); return pop->operator[](_i); }
|
||||||
|
|
||||||
|
|
@ -119,9 +129,17 @@ class eoPopIndiSelector : public eoIndiSelector<EOT>
|
||||||
valid();
|
valid();
|
||||||
if (firstChoice < 0 || firstChoice >= (int) size())
|
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);
|
const EOT& result = pop->operator[](firstChoice);
|
||||||
firstChoice = -1;
|
firstChoice = -1;
|
||||||
return result;
|
return result;
|
||||||
|
|
@ -144,6 +162,7 @@ class eoPopIndiSelector : public eoIndiSelector<EOT>
|
||||||
const eoPop<EOT>* pop; // need a pointer as this the pop argument can be re-instated
|
const eoPop<EOT>* pop; // need a pointer as this the pop argument can be re-instated
|
||||||
int last;
|
int last;
|
||||||
int firstChoice;
|
int firstChoice;
|
||||||
|
int secondChoice;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
||||||
Reference in a new issue