00001
00010 #include <string>
00011 #include <iostream>
00012 #include <vector>
00013 #include <memory>
00014 #include <random>
00015
00016 using namespace std;
00017
00018 #ifndef INDIVIDUAL_HPP_
00019 #define INDIVIDUAL_HPP_
00020
00030 class Individual
00031 {
00032 protected:
00033 int _id;
00034 int _rank;
00035 vector<double> _objectives;
00036 double _constraintViolation;
00037 double _crowding;
00038
00040 virtual void impl_from_stream(istream & repr) = 0;
00042 virtual void impl_to_stream(ostream & repr) = 0;
00043
00044 public:
00045
00047 Individual(){};
00048
00050 Individual(size_t numObjectives);
00051
00052 virtual ~Individual() {};
00053
00054
00055
00056
00060 virtual Individual * clone() = 0;
00061
00067 virtual void evaluate() = 0;
00068
00069
00070
00072 virtual void mutate() = 0;
00073
00075 virtual void improve(mt19937 * mt) = 0;
00076
00078 virtual pair<unique_ptr<Individual>,unique_ptr<Individual> >
00079 crossWith(Individual & other) = 0;
00080
00081
00082
00083
00084
00085 virtual int getId();
00086 virtual void setId(int id);
00087
00088 virtual int getRank();
00089 virtual void setRank(int rank);
00090
00091 virtual double getCrowdingDistance();
00092 virtual void setCrowdingDistance(double crowdingDistance);
00093
00094 virtual double getObjective(size_t index);
00095 virtual void setObjective(size_t index, double value);
00096
00101 virtual vector<double> getTrace();
00102
00108 friend int checkDominance(const Individual &ind1, const Individual &ind2);
00109
00117 virtual bool winsTournamentAgainst(const Individual &opponent, mt19937* mt);
00118
00119
00120
00124 virtual void fromStream(istream & ist);
00125
00127 virtual void toStream(ostream & ost);
00128
00129 };
00130
00131
00136 class IndividualReader {
00137 public:
00138 virtual Individual * fromStream(istream & ist) const = 0;
00139 };
00140
00141 #endif
00142