GeneralPopulation.cpp

Go to the documentation of this file.
00001 #include "GeneralPopulation.h"
00002 #include "VecMat.h"
00003 using namespace std;
00004 namespace gplib
00005   {
00006     GeneralPopulation::GeneralPopulation(const int popsize, const int genesize) :
00007       Probabilities(popsize), CrowdingDistances(popsize), Population(popsize,
00008           genesize)
00009       {
00010         OldStored = false;
00011       }
00012 
00013     GeneralPopulation::~GeneralPopulation()
00014       {
00015       }
00016 
00017     GeneralPopulation::GeneralPopulation(GeneralPopulation &Old):
00018       OldPopulation(Old.OldPopulation), Probabilities(Old.Probabilities),
00019           CrowdingDistances(Old.CrowdingDistances), Population(Old.Population)
00020       {
00021         OldStored = Old.OldStored;
00022       }
00023 
00024     GeneralPopulation::GeneralPopulation(const tpopulation &FirstHalf,
00025         const tpopulation &SecondHalf):
00026       OldPopulation(FirstHalf.size1() + SecondHalf.size1(), FirstHalf.size2()),
00027           Probabilities(FirstHalf.size1() + SecondHalf.size1()),
00028           CrowdingDistances(FirstHalf.size1() + SecondHalf.size1()),
00029           Population(FirstHalf.size1() + SecondHalf.size1(), FirstHalf.size2())
00030       {
00031         OldStored = false;
00032         ublas::matrix_range<tpopulation> PopFirstHalf(Population, ublas::range(
00033             0, FirstHalf.size1()), ublas::range(0, FirstHalf.size2()));
00034         ublas::matrix_range<tpopulation> PopSecondHalf(Population,
00035             ublas::range(FirstHalf.size1(), FirstHalf.size1()
00036                 + SecondHalf.size1()), ublas::range(0, FirstHalf.size2()));
00037         PopFirstHalf = FirstHalf;
00038         PopSecondHalf = SecondHalf;
00039       }
00040 
00041     GeneralPopulation& GeneralPopulation::operator=(
00042         const GeneralPopulation &source)
00043       {
00044         if (this != &source)
00045           {
00046             OldPopulation = source.OldPopulation;
00047             Population = source.Population;
00048             Probabilities = source.Probabilities;
00049             CrowdingDistances = source.CrowdingDistances;
00050           }
00051         return *this;
00052       }
00053 
00054     void GeneralPopulation::PrintPopulation(ostream &output) const
00055       {
00056         const int popsize = Population.size1();
00057         const int genesize = Population.size2();
00058         int i, j;
00059         output << popsize << " " << genesize << endl;
00060         for (i = 0; i < popsize; ++i)
00061           {
00062             for (j = 0; j < genesize; ++j)
00063               output << Population(i, j) << " ";
00064             output << endl;
00065           }
00066       }
00067     void GeneralPopulation::ResizePop(const int popsize, const int genesize)
00068       {
00069         OldPopulation.resize(popsize, genesize);
00070         Population.resize(popsize, genesize);
00071         Probabilities.resize(popsize);
00072         CrowdingDistances.resize(popsize);
00073       }
00074 
00075     void GeneralPopulation::ReadPopulation(std::istream &input)
00076       {
00077         unsigned int popsize, genesize, dummy;
00078         unsigned int i, j;
00079 
00080         input >> popsize >> genesize;
00081         ResizePop(popsize, genesize);
00082         for (i = 0; i < popsize; ++i)
00083           {
00084             for (j = 0; j < genesize; ++j)
00085               {
00086                 input >> dummy;
00087                 Population(i, j) = (dummy == 1);
00088               }
00089           }
00090       }
00091     void GeneralPopulation::PrintProbabilities(std::ostream &output) const
00092       {
00093         for (unsigned int i = 0; i < Probabilities.size(); ++i)
00094           {
00095             output << Probabilities(i) << " ";
00096           }
00097         output << endl;
00098       }
00099 
00100     void GeneralPopulation::PrintDistances(std::ostream &output) const
00101       {
00102         for (unsigned int i = 0; i < CrowdingDistances.size(); ++i)
00103           {
00104             output << CrowdingDistances(i) << " ";
00105           }
00106         output << endl;
00107       }
00108   }

Generated on Tue May 4 16:52:14 2010 for GPLIB++ by  doxygen 1.5.8