00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011 #include <iostream>
00012 #include <vector>
00013 #include <memory>
00014 #include <random>
00015
00016 #include "Individual.hpp"
00017
00018 using namespace std;
00019
00020 #ifndef POPULATION_HPP_
00021 #define POPULATION_HPP_
00022
00029 class Population {
00030
00031
00032 protected:
00036 vector<unique_ptr<Individual> > _individuals;
00037
00041 size_t _nobj;
00042
00043 public:
00044
00046 Population(int nobj);
00047 Population() = delete;
00048
00049
00050
00051 virtual ~Population();
00052
00053
00054
00056 void fromStream(istream & ist, const IndividualReader * rdr);
00058 void toStream (ostream & ost) const;
00059
00061 double getObjectiveValue (int individualIndex, int objectiveIndex) const;
00062
00064 vector<double> getTrace (int individualIndex) const;
00065
00067 int getIndividualID (int individualIndex) const;
00068
00070 void setIndividualID (int individualIndex, int newID);
00071
00073 size_t size() const;
00074
00076 void adopt(unique_ptr<Individual> indiv);
00077
00079 void clear();
00080
00082 void adoptFrom(Population & p1);
00083
00085 void adoptFromTwo(Population & p1, Population & p2);
00086
00088 void deepCopyFrom(Population & p1);
00089
00090
00091
00093 void evaluate();
00094
00098 void mutate();
00099
00105 void improve(mt19937 * mt);
00106
00110 int binaryTournament(int ii1, int ii2, mt19937 * mt);
00111
00112
00113
00114 #if 1 //----------------- FIXME: NOT YET (RE-) IMPLEMENTED PROPERLY
00115 public:
00116
00118 void assignRankAndCrowdingDistance();
00119
00123 void fillNondominatedSortFrom(Population &parent);
00124
00125
00126
00127 void selectAndCrossFrom(Population &parent, mt19937 *mt);
00128
00129
00130
00131 protected:
00132 void quicksortFrontObj(int objcount, int *obj_array, int front_size) const;
00133 void quicksortDist(int *dist, int front_size) const;
00134 void crowdingFillFrom(Population &mixed, int count, int front_size, void *plstelite);
00135 void assignCrowdingDistance (int *dist, int **obj_array, int front_size);
00136 void assignCrowdingDistanceList (void *plst, int front_size);
00137 void assignCrowdingDistanceIndices (int c1, int c2);
00138 int binaryTournament (int a, int b, mt19937 *mt) const;
00139
00140 #endif // ---------------------------- end of unimplemented part.
00141
00142 };
00143
00144 #endif
00145