/****************************************************************** * * * Nest version 2 - 3D Wasp Nest Simulator * * Copyright (C) 1997 Sylvain GUERIN * * LIASC, ENST Bretagne & Santa Fe Institute * * * ****************************************************************** E-mail: Sylvain.Guerin@enst-bretagne.fr or: Sylvain Guerin 13 rue des Monts Lorgeaux, 51460 L'EPINE, FRANCE ****************************************************************** This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program 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 General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ****************************************************************** Name : pattern.h Component : fitness evaluation Fonctionality : contains specifications for class Pattern ******************************************************************/ #ifndef __pattern_H #define __pattern_H #include "config.h" #include "algo.h" class Pattern; class PatternPlanEncoding; /* types de correlation */ enum correlationType { includes, isIncluded, matches, different }; /* classe PatternPlanEncoding */ /* Cette classe code sous forme d'entiers et en binaire un plan de pattern. On a deux entiers: - le premier correspond a Cellule/Pas cellule - le second correspond a Rouge/Autre (C'est plutot binaire, mais vous etiez prevenus, hein...) et ces entiers sont codes pour les 4 ou 6 rotations (selon cubic ou hexa) */ class PatternPlanEncoding { public: PatternPlanEncoding (Pattern* aPattern, int aZ, SimulationType aSimuType); ~PatternPlanEncoding (); SimulationType getSimuType (); int getCells (int angle, int index); int getTypes (int angle, int index); int nbits (int anInt); int cellsNumber (); void matchWithOtherPlan (PatternPlanEncoding* aPlan, int angle, /* de 0 a 3 (cubic) ou 0 a 5 (hexa) */ int dx, int dy, int* d1, int* d2, int* d3); /* les trois dernieres variables sont retournees et correspondent: d1: au nombre de cellules "en moins" dans le patternPlan courant d2: au nombre de cellules "en moins" dans le patternPlan en parametre d3: au nombre de cellules qui matchent bien, mais pour lesquelles on a un probleme de couleur */ /* P1: patternPlan courant P2: patternPlan passe en parametre c1 = cells (P1) t1 = types (P1) c2 = cells (P2) t2 = types (P2) d1 = nbits (~c1 & c2) d2 = nbits (c1 & ~c2) d3 = nbits (c1 & c2 & [(~t1 & t2) | (t1 & ~t2)]) */ void mergeWithPlan (PatternPlanEncoding* aPlan, int angle, int dx, int dy); void debug (int angle); protected: Pattern* pattern; int z; SimulationType simuType; /* cubic ou hexa */ int numberOfCells; int** cells; /* cell (1) or not cell (0) ? */ int** types; /* red (1) or other (0) */ int minX (); int maxX (); int minY (); int maxY (); int minZ (); int maxZ (); }; /* classe Pattern */ class Pattern { public: Pattern (int aMaxSize, int anInitRuleId, SimulationType aSimuType); ~Pattern (); void set (int x, int y, int z, typeOfCell aCellType, int ruleId, int cellId); typeOfCell getTypeOfCell (int x, int y, int z); int getRuleId (int x, int y, int z); int cellsNumber (); void setClassIndex (int anIndex); int getClassIndex (); PatternPlanEncoding* getPlan (int z); void debug (); int getMinX (); int getMaxX (); int getMinY (); int getMaxY (); int getMinZ (); int getMaxZ (); /* il faut pouvoir faire du pattern matching tres rapidement, d'ou les structures de codage binaire et les methodes associees */ void setEncoding (); void freeEncoding (); float matchWithOtherPattern (Pattern* aPattern, correlationType* correlation, /* = ou < ou > */ int* angle,/* de 0-3 (cubic) ou 0-5 (hexa) */ int* dx, int* dy, int* dz); /* les valeurs correlation, angle, dx, dy, dz sont des valeurs retournees, la valeur reelle retournee est l'indice de correlation trouve */ void matchPattern (Pattern* aPattern, int angle, int dx, int dy, int dz, int* d1, int* d2, int* d3); /* renvoie les valeurs de d1, d2, d3 pour le pattern matching effectue avec les parametres (angle, dx, dy, dz) */ void initWithPattern (Pattern* aPattern); /* initialise un pattern avec un autre */ void mergeWithPattern (Pattern* aPattern, int angle, int dx, int dy, int dz); /* addition de formes */ protected: SimulationType simuType; /* cubic ou hexa */ int initRuleId; int numberOfCells; int maxSize; int minX, maxX; int minY, maxY; int minZ, maxZ; int classIndex; Cell*** cell; PatternPlanEncoding** plans; int isEncoded; }; #endif