00001 #include <NLstl_utils.h>
00002
00003 #include "GLCrossoverOnePoint.h"
00004 #include "GLInterfaceSwapTails.h"
00005 #include "GLLogicError.h"
00006 #include "GLRandomNumbersGenerator.h"
00013 void GLCrossoverOnePoint::makeOffsprings(
00014 const vector<GLBaseOrganism*>& parents,
00015 vector<GLBaseOrganism*>& children)
00016 {
00017
00018 if (parents.size() != 2)
00019 {
00020 char errormsg[1000];
00021 sprintf(errormsg,
00022 "\nGLCrossoverOnePoint<T>::makeOffspring\n"
00023 "Can accept 2 parents only, while vector of %i parents "
00024 "was passed\n",
00025 (int)parents.size());
00026 throw GLLogicError(errormsg);
00027 }
00028
00029 int min_size = min(parents[0]->getSize(), parents[1]->getSize());
00030 int pos = GLRandomNumbersGenerator::getRandomInteger(min_size);
00031
00032
00033 children.clear();
00034 children[0] = parents[0]->makeClone();
00035 children[1] = parents[1]->makeClone();
00036
00037
00038 GLInterfaceSwapTails *swapper =
00039 nlutils::transform_pointer<GLInterfaceSwapTails,
00040 GLBaseOrganism>(children[0],
00041 "GLCrossoverOnePoint::makeOffspring\n"
00042 "one of parents do not implement the "
00043 "InterfaceSwapTails\n");
00044 swapper->swapTails(children[1], pos);
00045 }