• Main Page
  • Modules
  • Classes
  • Files
  • File List

D:/Projekt/ECF_trunk/ECF/cartesian/CartesianCrsOnePoint.cpp

00001 #include "CartesianCrsOnePoint.h"
00002 #include "Cartesian_c.h"
00003 
00004 namespace cart{
00005 
00006 void CartesianCrsOnePoint::registerParameters(StateP state)
00007 {
00008     //TODO: ako ce se jednog dana koristiti vise operatora
00009     //myGenotype_->registerParameter(state, "crx.onepoint", (voidP) new double(0), DOUBLE);
00010 }
00011 
00012 
00013 bool CartesianCrsOnePoint::initialize(StateP state)
00014 {
00015     //TODO: ako ce se jednog dana koristiti vise operatora
00016     //voidP sptr = myGenotype_->getParameterValue(state, "crx.onepoint");
00017     //probability_ = *((double*)sptr.get());
00018     return true;
00019 }
00020 
00021 
00022 bool CartesianCrsOnePoint::mate(GenotypeP gen1, GenotypeP gen2, GenotypeP child)
00023 {
00024     Cartesian* p1 = (Cartesian*) (gen1.get());
00025     Cartesian* p2 = (Cartesian*) (gen2.get());
00026     Cartesian* ch = (Cartesian*) (child.get());
00027 
00028     //crossing point is any integer value in parents
00029     int crsPoint = state_->getRandomizer()->getRandomInteger(p1->size());
00030 
00031     ch->clear();
00032     //randomly choose left side of first parent or second parent
00033     if ((state_->getRandomizer()->getRandomInteger(0, 1)) == 0)
00034     {
00035         for (int i = 0; i < crsPoint; i++)
00036         {
00037             ch->push_back(p1->at(i));
00038         }
00039         for (int i = crsPoint; i < (int)p2->size(); i++)
00040         {
00041             ch->push_back(p2->at(i));
00042         }
00043     }
00044     else
00045     {
00046         for (int i = 0; i < crsPoint; i++)
00047         {
00048             ch->push_back(p2->at(i));
00049         }
00050         for (int i = crsPoint; i < (int)p1->size(); i++)
00051         {
00052             ch->push_back(p1->at(i));
00053         }
00054     }
00055 
00056     return true;
00057 }
00058 
00059 }
00060 

Generated on Tue Nov 4 2014 13:04:30 for ECF by  doxygen 1.7.1