Exemplo n.º 1
0
    /// <summary>
    /// Concat all the gene strings in the consultor genome list
    /// </summary>
    /// <returns>Genome converted to string</returns>
    public string GetGenomeString()
    {
        string genome        = ""; //
        int    numberOfGenes = geneList.Count;

        for (int i = 0; i < numberOfGenes; i++)
        {
            NEATGene gene = geneList[i];
            genome += gene.GetGeneString();

            if (i < numberOfGenes - 1)
            {
                genome += "_";
            }
        }
        return(genome);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Check if a given gene already exists within the gene list.
    /// </summary>
    /// <param name="inNodeID">Input node to check</param>
    /// <param name="outNodeID">Output node the check</param>
    /// <returns>Innovation number for this gene</returns>
    public int CheckGeneExistance(int inNodeID, int outNodeID)
    {
        NEATGene gene = null;
        int      oldInnovationNumber = innovationNumber;
        int      numberOfGenes       = geneList.Count;

        //Check if this gene exists in the current consultor gene list
        for (int i = 0; i < numberOfGenes; i++)
        {
            gene = geneList[i];
            int inID  = gene.GetInID();
            int outID = gene.GetOutID();
            if (inID == inNodeID && outID == outNodeID)
            {
                return(gene.GetInnovation());
            }
        }

        AddNewGene(innovationNumber, inNodeID, outNodeID); //create a new gene
        innovationNumber++;                                //increment innovation number

        return(oldInnovationNumber);                       //return old innovation number
    }
Exemplo n.º 3
0
    private List <NEATGene> geneList;                 //consultor gene list

    /// <summary>
    /// Creating consultor structure NEAT packet retrived from database and coefficient information from UI
    /// </summary>
    /// <param name="packet">NEATPacket retrieved from database</param>
    /// <param name="deltaThreshold">Delta threshold to set</param>
    /// <param name="disjointCoefficient">Disjoint coefficient to set</param>
    /// <param name="excessCoefficient">Excess coefficient to set</param>
    /// <param name="averageWeightDifferenceCoefficient">Averange weight difference coefficient to set</param>
    public NEATConsultor(NEATPacket packet, float deltaThreshold, float disjointCoefficient, float excessCoefficient, float averageWeightDifferenceCoefficient)
    {
        this.numberOfInputs  = packet.node_inputs;  //get number of inputs from packet
        this.numberOfOutputs = packet.node_outputs; //get number of outputs from packet

        //copy thresholdes and coefficients
        this.deltaThreshold      = deltaThreshold;
        this.disjointCoefficient = disjointCoefficient;
        this.excessCoefficient   = excessCoefficient;
        this.averageWeightDifferenceCoefficient = averageWeightDifferenceCoefficient;

        int informationSize = NEATGene.GENE_INFORMATION_SIZE;                                               //get number of gene information size

        float[] geneInformation = packet.consultor_genome.Split('_').Select(x => float.Parse(x)).ToArray(); //using Linq libary and delimiters, parse and spilt string genome from neat packet into float array
        geneList = new List <NEATGene>();


        for (int i = 0; i < geneInformation.Length; i += informationSize)
        {
            NEATGene gene = new NEATGene(innovationNumber, (int)geneInformation[i], (int)geneInformation[i + 1], 1f, true);
            geneList.Add(gene);
            innovationNumber++;
        }
    }
Exemplo n.º 4
0
    /// <summary>
    /// Create a new gene and add it to the gene list.
    /// </summary>
    /// <param name="inno">New innovation number</param>
    /// <param name="inNodeID">New input node</param>
    /// <param name="outNodeID">New output node</param>
    public void AddNewGene(int inno, int inNodeID, int outNodeID)
    {
        NEATGene gene = new NEATGene(inno, inNodeID, outNodeID, 1f, true);

        geneList.Add(gene);
    }