From bffe8b0dfd1beff41da5dc883e8093d7a7826ffa Mon Sep 17 00:00:00 2001 From: cahon Date: Thu, 25 Apr 2002 14:08:26 +0000 Subject: [PATCH] A toric topology for cellular E.A. --- eo/src/eoToricCellularEasyEA.h | 88 ++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 eo/src/eoToricCellularEasyEA.h diff --git a/eo/src/eoToricCellularEasyEA.h b/eo/src/eoToricCellularEasyEA.h new file mode 100644 index 00000000..bd4149ab --- /dev/null +++ b/eo/src/eoToricCellularEasyEA.h @@ -0,0 +1,88 @@ +// -*- mode: c++; c-indent-level: 4; c++-member-init-indent: 8; comment-column: 35; -*- + +// "eoToricCellularEasyEA.h" + +// (c) OPAC Team, LIFL, 2002 + +/* 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: cahon@lifl.fr +*/ + +#ifndef eoToricCellularEasyEA_h +#define eoToricCellularEasyEA_h + +#include + +#include + +template class eoToricCellularEasyEA : public eoCellularEasyEA { + +public : + + eoToricCellularEasyEA (eoContinue & _cont, + eoEvalFunc & _eval, + eoSelectOne & _sel_neigh, + eoBinOp & _cross, + eoMonOp & _mut, + eoSelectOne & _sel_repl + ) : + eoCellularEasyEA (_cont, + _eval, + _sel_neigh, + _cross, + _mut, + _sel_repl) { + + } + + eoToricCellularEasyEA (eoContinue & _cont, + eoEvalFunc & _eval, + eoSelectOne & _sel_neigh, + eoQuadOp & _cross, + eoMonOp & _mut, + eoSelectOne & _sel_child, + eoSelectOne & _sel_repl + ) : + eoCellularEasyEA (_cont, + _eval, + _sel_neigh, + _cross, + _mut, + _sel_child, + _sel_repl) { + + } + + // Take care :-). The size of the population must be a square number ! (9, 16, ...) + + virtual eoPop neighbours (const eoPop & pop, int rank) { + + int dim2 = pop.size () ; + int dim = (int) sqrt (dim2) ; + int j = rank ; + + eoPop neigh ; + neigh.push_back (pop [j < dim ? dim2 - dim + j : j - dim]) ; + neigh.push_back (pop [(j + dim) % dim2]) ; + neigh.push_back (pop [(j + 1) % dim != 0 ? j + 1 : j + 1 - dim]) ; + neigh.push_back (pop [j % dim != 0 ? j - 1 : j + dim - 1]) ; + + return neigh ; + } + +} ; + +#endif