⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 genome.h

📁 amygdata的神经网络算法源代码
💻 H
字号:
/***************************************************************************                          genome.h  -  description                             -------------------    begin                : Sat Dec 8 2001    copyright            : (C) 2001 by Rudiger Koch    email                : rkoch@rkoch.org ***************************************************************************//*************************************************************************** *                                                                         * *   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.                                   * *                                                                         * ***************************************************************************/#ifndef GENOME_H#define GENOME_H#include <string>#include <vector>#include <utility>#include <amygdala/amygdalaclass.h>#include <amygdala/genomehandler.h>namespace Amygdala {/** @class Genome genome.h amygdala/genome.h  * @brief client class for the geneserver. Controlls the creation of networks from a genome  *  * An object of this class first needs to get a genome, either via HTTP or from a file.  * Once the genome is loaded it can use the supplied GenomeHandler object to create the  * network. Amygdala supplies one such GenomeHandler, SimpleNet.  *  * There are also some utility function to create a random genome and upload them to the server  * as a starting point for the GA.  *  * @see GenomeHandler  * @see SimpleNet  * @author Rudiger Koch <rkoch@rkoch.org>  */class Genome : public AmygdalaClass {public:     /** @param url the server url in the form http://hostname or a filename in the form       * file:/path/to/genome. Do not specify a pathname in the http version of the url! */    Genome(const std::string & url);    ~Genome();  /** get a gene from the  url specified in the constructor  */    void Get();  /** Submit a score to the server. The server will use this to select the genomes    * which are allowed to create offspring */    void Submit(const int score) const;  /** set the handler. This handler must be derived from GenomeHandler   * @param gh An instance of GenomeHandler that matches the genome   */    void SetHandler(GenomeHandler *gh);  /** parse the genome string. Pass all genes to the supplied GenomeHandler object */    void Parse();  /** parses the format string as given by the server.   *  Must be called if a gene is loaded from a file.   * @param format looks like: <i>"Chromosome-format: {genes,size}{genes,size}...."</i>   */    void Format(const std::string & format);  /** Upload a genome to the geneserver specified in the constructor      @see AddGene()      @see StartChromosome()*/    void Upload() const;  /** to build up a client supplied genome call this function for each gene of a chromosome.     * When the Chromosome is complete, call StartChromosome() to start a new chromosome or    * Upload() to upload the chromosome to the server    * @param gene the gene to add. This is a binary string.    * @see StartChromosome()    * @see Upload() */    void AddGene(const std::string & gene);  /** To build up a client supplied genome call this function for each chromosome    * @param mutationMode 'n'= non mutable; 'c' = constant size; 'v'= variable size      @see AddGene()      @see Upload() */    void StartChromosome(const char mutationMode);  /** Convenience function to make a random chromosome.    * @param len the number of genes    * @param genesize the size of gene    * @param mutationMode 'n'= non mutable; 'c' = constant size; 'v'= variable size    */    void MakeChromosome(const unsigned int len, const unsigned int genesize, const char mutationMode);protected: // Protected methods   /** load a genome file from a http server. This server must conform      *  to the Amygdala genome server conventions. */    void GetHttp();    /** load a gene from a file */    void GetFile(const std::string & path);    /** Open a socket to the geneserver        @return the socket descriptor. The descriptor must later be closed by the caller */    int OpenSocket() const;protected: // Protected attributes    typedef struct _ChromosomeFormat {        unsigned int genes;        unsigned int gene_size;        char mutationMode;    } ChromosomeFormat;    /** the Handler must be set before a Genome object is used for anything */    GenomeHandler* gHandler;    unsigned int geneId;    /** the complete genome string without format header */    std::string genome;    /** this is a pair <genes, gene_size> describing the format of the chromosomes */    std::vector <ChromosomeFormat> chromosomes;    /** this part of the gene modifies the likelyhood of a mutation and is only relevant for        the gene server and is ignored here. mutationHeat is the length of the gene to ignore        at the end of each gene */    const unsigned int mutationHeat;    /** the server url to communicate with or the filename */    const std::string url;};} // namespace Amygdala#endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -