From c137da31c5dc414e5390eb7a5346d2b6668b42d7 Mon Sep 17 00:00:00 2001 From: jhumeau Date: Wed, 28 May 2008 13:20:05 +0000 Subject: [PATCH] DominanceMatrix is used for some fitnessAssignment. git-svn-id: svn://scm.gforge.inria.fr/svnroot/paradiseo@1192 331e1502-861f-0410-8da2-ba01fb791d7f --- .../src/utils/moeoDominanceMatrix.h | 217 ++++++++++++++++++ 1 file changed, 217 insertions(+) create mode 100644 trunk/paradiseo-moeo/src/utils/moeoDominanceMatrix.h diff --git a/trunk/paradiseo-moeo/src/utils/moeoDominanceMatrix.h b/trunk/paradiseo-moeo/src/utils/moeoDominanceMatrix.h new file mode 100644 index 000000000..9dd70ee5a --- /dev/null +++ b/trunk/paradiseo-moeo/src/utils/moeoDominanceMatrix.h @@ -0,0 +1,217 @@ +/* +* +* Copyright (C) DOLPHIN Project-Team, INRIA Lille-Nord Europe, 2006-2008 +* (C) OPAC Team, LIFL, 2002-2008 +* +* Arnaud Liefooghe +* Jeremie Humeau +* +* This software is governed by the CeCILL license under French law and +* abiding by the rules of distribution of free software. You can use, +* modify and/ or redistribute the software under the terms of the CeCILL +* license as circulated by CEA, CNRS and INRIA at the following URL +* "http://www.cecill.info". +* +* As a counterpart to the access to the source code and rights to copy, +* modify and redistribute granted by the license, users are provided only +* with a limited warranty and the software's author, the holder of the +* economic rights, and the successive licensors have only limited liability. +* +* In this respect, the user's attention is drawn to the risks associated +* with loading, using, modifying and/or developing or reproducing the +* software by the user in light of its specific status of free software, +* that may mean that it is complicated to manipulate, and that also +* therefore means that it is reserved for developers and experienced +* professionals having in-depth computer knowledge. Users are therefore +* encouraged to load and test the software's suitability as regards their +* requirements in conditions enabling the security of their systems and/or +* data to be ensured and, more generally, to use and operate it in the +* same conditions as regards security. +* The fact that you are presently reading this means that you have had +* knowledge of the CeCILL license and that you accept its terms. +* +* ParadisEO WebSite : http://paradiseo.gforge.inria.fr +* Contact: paradiseo-help@lists.gforge.inria.fr +* +*/ +//----------------------------------------------------------------------------- +// moeoDominanceMatrix.h +//----------------------------------------------------------------------------- +#ifndef MOEODOMINANCEMATRIX_H_ +#define MOEODOMINANCEMATRIX_H_ + +#include + +template +class moeoDominanceMatrix: public eoBF< eoPop< MOEOT >&, eoPop< MOEOT >& , void>,eoUF&,void>, std::vector < std::vector > { + +public: + + using std::vector< std::vector >::size; + using std::vector< std::vector >::resize; + using std::vector< std::vector >::operator[]; + using std::vector< std::vector >::begin; + using std::vector< std::vector >::end; + + /** The type for objective vector */ + typedef typename MOEOT::ObjectiveVector ObjectiveVector; + + moeoDominanceMatrix(bool _nocopy=true):std::vector < std::vector >(),comparator(paretoComparator), nocopy(_nocopy) {} + + moeoDominanceMatrix(moeoObjectiveVectorComparator < ObjectiveVector > & _comparator, bool _nocopy=true):std::vector < std::vector >(),comparator(_comparator), nocopy(_nocopy) {} + + + void operator()(eoPop& _pop) { + eoPop dummyPop; + (*this).operator()(_pop, dummyPop); + } + + /** + * Filling up the Dominance Matrix of first and second population (if you have only one population, the second must be empty) + * @param _pop1 first population + * @param _pop2 second population + */ + void operator()(eoPop& _pop1,eoPop& _pop2) { + + //Initialization + unsigned int i= _pop1.size(); + unsigned int j= _pop2.size(); + resize(i+j); + countVector.resize(i+j); + rankVector.resize(i+j); + for (unsigned int k=0; k < i+j; k++) { + (*this)[k].resize(i+j); + countVector[k]=0; + rankVector[k]=0; + for (unsigned l=0; l= i) )) { + if ( comparator(_pop2[l-i].objectiveVector(), _pop1[k].objectiveVector())) { + (*this)[k][l]=true; + countVector[k]++; + rankVector[l]++; + } + else if ( comparator(_pop1[k].objectiveVector(), _pop2[l-i].objectiveVector())) { + (*this)[l][k]=true; + countVector[l]++; + rankVector[k]++; + } + else if (nocopy && (_pop1[k].objectiveVector() == _pop2[l-i].objectiveVector())) + copySet.insert(l); + } + else { + if ( comparator(_pop2[l-i].objectiveVector(), _pop2[k-i].objectiveVector())) { + (*this)[k][l]=true; + countVector[k]++; + rankVector[l]++; + } + else if ( comparator(_pop2[k-i].objectiveVector(), _pop2[l-i].objectiveVector())) { + (*this)[l][k]=true; + countVector[l]++; + rankVector[k]++; + } + else if (nocopy && (_pop2[k-i].objectiveVector() == _pop2[l-i].objectiveVector())) + copySet.insert(l); + } + } + } + + + //if we don't want copy, matrix, rankVector and countVector are updating + if (nocopy) { + std::set::iterator it=copySet.begin(); + + while (it!=copySet.end()) { + for (unsigned int l=0; l< (*this).size(); l++) { + if (!(*this)[l][*it]) { + (*this)[l][*it]=true; + countVector[l]++; + } + } + it++; + } + it=copySet.begin(); + while (it!=copySet.end()) { + for (unsigned int l=0; l< (*this).size(); l++) { + if ((*this)[*it][l]) { + (*this)[*it][l]=false; + rankVector[l]--; + } + } + it++; + } + it=copySet.begin(); + while (it!=copySet.end()) { + countVector[*it]=0; + rankVector[*it]=(*this).size()-copySet.size(); + it++; + } + } + /* + for(unsigned k=0; k countVector; + /** vector contains CountRankFitnessAssignment */ + std::vector rankVector; + /** vector contains index of copys */ + std::set copySet; + /** Functor to compare two objective vectors */ + moeoObjectiveVectorComparator < ObjectiveVector > & comparator; + /** Functor to compare two objective vectors according to Pareto dominance relation */ + moeoParetoObjectiveVectorComparator < ObjectiveVector > paretoComparator; + +}; + +#endif /*MOEODOMINANCEMATRIX_H_*/