From 72e959054419a439f0643f4be6a7dd7926e4afec Mon Sep 17 00:00:00 2001 From: evomarc Date: Sat, 27 Jan 2001 07:43:58 +0000 Subject: [PATCH] I have separated the include files into eo everything that is general to any representation es.h everything about real representation (in es dir) ga.h everything related to bitstring representation (in ga dir) To be continued by gp.h, and ... This has lead to some slight modifications in test file eobin and all tutorial examples files... I've also added in utils eoDistance, generic functor to compute distances, including also the generic Euclidian distance --- eo/src/utils/eoDistance.h | 63 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 eo/src/utils/eoDistance.h diff --git a/eo/src/utils/eoDistance.h b/eo/src/utils/eoDistance.h new file mode 100644 index 00000000..84b9d124 --- /dev/null +++ b/eo/src/utils/eoDistance.h @@ -0,0 +1,63 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +//----------------------------------------------------------------------------- +// eoDistance.h +// (c) GeNeura Team, 1998, Marc Schoenauer 2001 +/* + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + Contact: todos@geneura.ugr.es, http://geneura.ugr.es + Marc.Schoenauer@polytechnique.fr + */ +//----------------------------------------------------------------------------- + +#ifndef _eoDistance_H +#define _eoDistance_H + +#include + +/** + This is a generic class for distance functors: + takes 2 things ane returns a double +*/ +template< class EOT > +class eoDistance : public eoBF +{}; + +/** + This is a generic class for Euclidain distance computation: + assumes the 2 things are vectors of something that is double-castable +*/ + +template< class T > +class eoQuadDistance : public eoDistance > +{ +public: + double operator()(const vector & _v1, const vector & _v2) + { + double sum=0.0; + for (unsigned i=0; i<_v1.size(); i++) + { + double r = static_cast (_v1[i]) - static_cast (_v2[i]); + sum += r*r; + } + return sum; + } +}; + + + + +#endif