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
This commit is contained in:
evomarc 2001-01-27 07:43:58 +00:00
commit 72e9590544

63
eo/src/utils/eoDistance.h Normal file
View file

@ -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 <eoFunctor.h>
/**
This is a generic class for distance functors:
takes 2 things ane returns a double
*/
template< class EOT >
class eoDistance : public eoBF<const EOT &, const EOT &, double>
{};
/**
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<vector<T> >
{
public:
double operator()(const vector<T> & _v1, const vector<T> & _v2)
{
double sum=0.0;
for (unsigned i=0; i<_v1.size(); i++)
{
double r = static_cast<double> (_v1[i]) - static_cast<double> (_v2[i]);
sum += r*r;
}
return sum;
}
};
#endif