- Main Page
- Classes
- Files

- Search for |

# moeoDistanceMatrix.h

    00001 // -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*-
    00002
    00003 //-----------------------------------------------------------------------------
    00004 // moeoDistanceMatrix.h
    00005 // (c) OPAC Team (LIFL), Dolphin Project (INRIA), 2007
    00006 /*
    00007     This library...
    00008
    00009     Contact: paradiseo-help@lists.gforge.inria.fr, http://paradiseo.gforge.inria.fr
    00010  */
    00011 //-----------------------------------------------------------------------------
    00012
    00013 #ifndef MOEODISTANCEMATRIX_H_
    00014 #define MOEODISTANCEMATRIX_H_
    00015
    00016 #include <vector>
    00017 #include <eoFunctor.h>
    00018 #include <distance/moeoDistance.h>
    00019
    00023 template < class MOEOT , class Type >
    00024 class moeoDistanceMatrix : public eoUF < const eoPop < MOEOT > &, void > , public std::vector< std::vector < Type > >
    00025 {
    00026 public:
    00027
    00028     using std::vector< std::vector < Type > > :: size;
    00029     using std::vector< std::vector < Type > > :: operator[];
    00030
    00031
    00037     moeoDistanceMatrix (unsigned int _size, moeoDistance < MOEOT , Type > & _distance) : distance(_distance)
    00038     {
    00039         this->resize(_size);
    00040         for (unsigned int i=0; i<_size; i++)
    00041         {
    00042             this->operator[](i).resize(_size);
    00043         }
    00044     }
    00045
    00046
    00051     void operator()(const eoPop < MOEOT > & _pop)
    00052     {
    00053         // 1 - setup the bounds (if necessary)
    00054         distance.setup(_pop);
    00055         // 2 - compute distances
    00056         this->operator[](0).operator[](0) = Type();
    00057         for (unsigned int i=0; i<size(); i++)
    00058         {
    00059             this->operator[](i).operator[](i) = Type();
    00060             for (unsigned int j=0; j<i; j++)
    00061             {
    00062                 this->operator[](i).operator[](j) = distance(_pop[i], _pop[j]);
    00063                 this->operator[](j).operator[](i) = this->operator[](i).operator[](j);
    00064             }
    00065         }
    00066     }
    00067
    00068
    00069 private:
    00070
    00072     moeoDistance < MOEOT , Type > & distance;
    00073
    00074 };
    00075
    00076 #endif /*MOEODISTANCEMATRIX_H_*/