/****************************************************************** * * * 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 : simu.h Component : simulation Fonctionality : contient les specifications de la classe Simulation ******************************************************************/ #ifndef __simu_H #define __simu_H #include "algo.h" #include "compress.h" class ViewInterface; /* enumerations: donnees pour les options du simulateur */ enum ArchMustBeSavedType { archMustBeSaved, archMustNotBeSaved }; enum PreviewMustBeSavedType { previewMustBeSaved, previewMustNotBeSaved }; enum MustBeCompressedType { noCompression, compression }; /* Definition de la classe Simulation. Elle represente une simulation d'une colonie, c'est a dire qu'y est code la colonie elle-meme et l'architecture en construction. Elle realise aussi tous les operateurs genetiques. */ class Simulation { public: Simulation (unsigned int aNumIndex, unsigned int maxRuleArray, SimulationType aSimuType); ~Simulation (); void setDisplayAndWindow (Display* aDisplay, Visual* aVisual, GC* aGC, Window* aWindow, unsigned long* aColorPointer, XFontStruct* aFontInfo); int load (char* aPathName, char* aFileName, Boolean loadPreview); /* return 1 when ok else 0 */ int save (FileFormat aFileFormat, /*.thr or .rul*/ ArchMustBeSavedType aArchMustBeSavedValue, /*save architecture?*/ PreviewMustBeSavedType aPreviewMustBeSavedValue, /*save preview?*/ MustBeCompressedType aMustBeCompressedType); /* compression ? */ /* return 1 when ok else 0 */ int saveAsResult (char* aPathName, char* aFileName); /* return 1 when ok else 0 */ int loadResult (char* aPathName, char* aFileName); /* return 1 when ok else 0 */ void simulate (int aSize, int anIterationsNumber, int aMaxCells, FitnessType fitnessType, learningMode typeOfLearning, int learningParam, /* allowedFails or toBuidRulesNumber */ int mustBeEvaluated, double noiseRate); int learn (int numberOfRulesLoLearn, int mustRuleBeApplied); void setSimuResults (); void simulateShowsStats (int aSize, int anIterationsNumber, int aMaxCells, FitnessType fitnessType, learningMode typeOfLearning, int learningParam, /* allowedFails or toBuidRulesNumber */ int mustBeEvaluated, double noiseRate, InfoBox* anInfoBox, ViewInterface* aViewInterface, int showCellsSteps); void arrayUpdate (ArrayWindow* simulationsArray); void setFromOtherSimulation (Simulation* aSimulation); /* architecture is not copied */ void randomGenerate (double pRedCell, double pYellowCell, double averageRuleNumber, double varianceRuleNumber, RandomGenerationType randomGenerationType); void crossOver (Simulation* aSimulation, CrossoverType crossoverType); int mutation (double pRedCell, double pYellowCell, double pUsed, double pUnused, RandomGenerationType randomGenerationType); /* return number of mutated colonies */ int swap (double pSwap); /* return number of swaped colonies */ double evaluate (FitnessType fitnessType); /* return the fitness of the architecture */ void classifyRules (); /* classify the rules in: classA, classB, unusedClass */ /* files methods */ FileFormat checkFileFormat (); void setFileNameToRightFormat (FileFormat aFileFormat); /* void compression (char* aPathName, char* aFileName); */ void decompression (char* aPathName, char* aFileName, FileFormat format); void removeTempFiles (char* aPathName, char* aFileName, FileFormat format); char* tempRulFile (char* aFileName, char* tempFile); char* tempThrFile (char* aFileName, char* tempFile); char* tempArchFile (char* aFileName, char* tempFile); char* tempPreviewFile (char* aFileName, char* tempFile); /* return name of temporary decompressed files */ RuleArray* simulationRuleArray; Architecture* simulationArchitecture; unsigned int numIndex; char name[256]; char pathName[256]; char fileName[256]; Boolean isLoaded; Boolean isSimulated; Boolean isDisplayed; Boolean isEdited; Boolean isSaved; Boolean isPreviewed; Boolean isCompressed; unsigned int archSize; unsigned int ruleNumber; double mark; /* *IMPORTANT* en fait c'est la fitness */ SimulationType simuType; char host[50]; int hostNb; /* used for genetic algorithms */ long cellsNumber; long ruleOccurs[maxRules]; /* used for preview pixmap */ Display* previewDisplay; Visual* previewVisual; GC* previewGC; XFontStruct* previewFontInfo; Window* previewWindow; unsigned long* colorPointer; Boolean displayAndWindowSet; /* flag positionne: preview can be loaded */ }; #endif