00001
00002
00003
00004
00005 #include <set>
00006
00007 #include <eo>
00008 #include <eoInt.h>
00009 #include <eoOrderXover.h>
00010
00011
00012
00013
00014 typedef eoInt<int> Chrom;
00015
00016
00017
00018 bool check_permutation(const Chrom& _chrom){
00019 unsigned size= _chrom.size();
00020 std::set<unsigned> verif;
00021 for(unsigned i=0; i< size; i++){
00022 if(verif.insert(_chrom[i]).second==false){
00023 std::cout << " Error: Wrong permutation !" << std::endl;
00024 std::string s;
00025 s.append( " Wrong permutation in t-eoShiftMutation");
00026 throw std::runtime_error( s );
00027 return false;
00028 }
00029 }
00030 return true;
00031 }
00032
00033
00034 int main()
00035 {
00036 const unsigned POP_SIZE = 3, CHROM_SIZE = 8;
00037 unsigned i;
00038
00039
00040 eoInitPermutation <Chrom> random(CHROM_SIZE);
00041
00042
00043 eoPop<Chrom> pop;
00044
00045
00046
00047
00048 for (i = 0; i < POP_SIZE; ++i)
00049 {
00050 Chrom chrom(CHROM_SIZE);
00051 random(chrom);
00052
00053 pop.push_back(chrom);
00054 }
00055
00056
00057 eoOrderXover<Chrom> cross;
00058
00059 for (i = 0; i < POP_SIZE; ++i)
00060 std::cout << " Initial chromosome n�" << i << " : " << pop[i] << "..." << std::endl;
00061
00062 cross(pop[0],pop[1]);
00063 cross(pop[1],pop[2]);
00064
00065 for (i = 0; i < POP_SIZE; ++i) {
00066 std::cout << " Initial chromosome n�" << i << " becomes : " << pop[i] << " after orderXover" << std::endl;
00067 check_permutation(pop[i]);
00068 }
00069 return 0;
00070 }
00071
00072