/****************************************************************** * * * 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 : genetic.h Component : genetic algorihtm Fonctionality : contient les specifications relatives au deroulement de l'algorithme genetique (classes SimulationStep et GeneticSimulation), ainsi que des simulations en differe ******************************************************************/ #ifndef __genetic_H #define __genetic_H #include "algo.h" #include "config.h" #include "NetInt.h" #include "GenInt.h" #include "MainInt.h" #include "date.h" class SimulationStep; class GeneticSimulation; class GeneticInterface; class MainInterface; /* Definition de l'etat d'une simulation */ enum SimuState { Unused, Running, Done, Waiting }; /* Definition de la classe des parametres de simulation pour l'algorithme genetique */ class SimulationParameters { public: double pRedCell; double pYellowCell; double averageRuleNb; double sdRuleNb; double pCrossOver; double pUsed; double pUnused; double pSwap; int archSize; long iterationsNb; int maxCells; /* rajout 07/10/97 */ FitnessType fitnessType; CrossoverType crossoverType; /* rajout 07/10/97 */ int toBuildRulesNumber; /* rajout 07/10/97:nombre de regles max a apprendre, 0 si pas d'appr. */ SimulationType simulationType; RandomGenerationType randomGenerationType; int coloniesNb; SimulationParameters (); SimulationParameters (double initPRedCell, double initPYellowCell, double initAverageRuleNb, double initSdRuleNb, double initPCrossOver, double initPUsed, double initPUnused, double initPSwap, unsigned int initArchSize, unsigned long initIterationsNb, unsigned int initMaxCells, /* rajout 07/10/97 */ FitnessType initFitnessType, CrossoverType initCrossoverType, /* rajout 07/10/97 */ int initToBuidRulesNumber, /* rajout 07/10/97 */ SimulationType initSimulationType, RandomGenerationType initRandomGenerationType, unsigned int initColoniesNb); ~SimulationParameters (); void setToDefault (); void setFromOtherSimulationParameters (SimulationParameters* simuP); }; /* Definition de la classe SimulationStep, qui correspond a une etape de l'algorithme genetique, autrement dit a une generation */ class SimulationStep { public: SimulationStep (unsigned int aColoniesNumber, GeneticSimulation* aGeneticSimulation); ~SimulationStep (); int loadStep (char* aPathName, char* aFileName, unsigned int step); int saveCurrentStep (); /* return 1 when ok, else 0 */ char* getStepName (char* aName, unsigned int step); char* getColonyName (char* aName, unsigned int step, unsigned int index); void runStep (unsigned int step); void runFirstStep (); void addComment (char* text); void openDirectory (); void loadDataFromOlderStep (); void selection (); void crossOver (); void mutation (); void swap (); unsigned int currentStep; double bestMark; double worstMark; double averageMark; unsigned int coloniesNumber; Simulation** colony; Simulation** oldColony; SimuState* colonyState; GeneticSimulation* geneticSimulation; char stepName[50]; char colonyName[50]; double* probaRep; }; /* Definition de la classe GeneticSimulation, qui correspond a la simulation genetique en cours */ class GeneticSimulation { public: GeneticSimulation (char* aName, char* aDirName, char* aPath, Net* aNet, MainInterface* aMainInterface, int initColoniesNumber, SimulationType aSimulationType); ~GeneticSimulation (); int load (char* aPathName, char* aDirName); /* return 1 when ok, else 0 */ void createDirectories (); int save (); /* return 1 when ok, else 0 */ void run (unsigned int beginIndex, unsigned int endIndex, GeneticInterface* aGeneticInterface ); void stop (); void openCommentFile (); void addComment (char* text); void closeCommentFile (); void simulationControl (); void refreshNetInterface (); void launchProcess (unsigned int colonyIndex, char* host, int aHostNb); int checkIfDone (unsigned int colonyIndex); int checkBeforeLaunching (unsigned int colonyIndex); void loadResults (); MainInterface* mainInterface; GeneticInterface* geneticInterface; SimulationStep* currentSimulationStep; Net* net; char name[30]; char dirName[30]; char pathName[80]; double bestMark[maxSteps+1]; double worstMark[maxSteps+1]; double averageMark[maxSteps+1]; unsigned int currentStep; unsigned int totalSteps; SimulationParameters params; Date currentDate; int commentFile; unsigned int lastStepToCompute; int isRunning; }; /* Definition de l'etat d'une simulation en differe (dans la liste des simulations) */ enum DeferedSimuState { DSWaiting, DSRunning, DSDone }; /* Definition de la classe DeferedSimulation qui correspond aux simulations en differe actuellement memorisees */ class DeferedSimulation { public: DeferedSimulation (char* aName, char* aDirName, char* aPathName, int aBeginIndex, int aEndIndex, Date aDate); ~DeferedSimulation (); char name[30]; char dirName[30]; char pathName[80]; DeferedSimuState deferedSimuState; char cDate[50]; char cTime[50]; int beginIndex; int endIndex; Date execDate; }; /* Definition de la classe DeferedSimuList, qui correspond a la liste des simulations en differe, actuellement memorisees */ class DeferedSimuList { public: DeferedSimuList (int aMaxDeferedSimulations); ~DeferedSimuList (); int add (char* aName, char* aDirName, char* aPathName, int aBeginIndex, int aEndIndex, Date aDate);/* return index */ void update (int index); unsigned int getNumber (); unsigned int getWaitingOrRunningNumber (); ArrayContent* getContent (); int freeLeft (); /* return 1 if free defered simulation left, else 0 */ DeferedSimulation* get (int index); /* when possible */ protected: unsigned int maxDeferedSimu; unsigned int number; DeferedSimulation** deferedSimulation; ArrayContent* deferedSimuListContent; /* structure dont se sert l'interface pour gerer la fenetre */ }; #endif