Beispiel #1
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="ea"></param>
        public Network(EvolutionaryAlogorithm ea, Genome genome)
        {
            this._ea     = ea;
            this._genome = genome;

            this._neurons = new Neuron[this._ea.MaxNodes + this._ea.Outputs];

            for (int i = 0; i < this._ea.Inputs; i++)
            {
                this._neurons[i] = new Neuron();
            }
            for (int i = 0; i < this._ea.Outputs; i++)
            {
                this._neurons[i + this._ea.MaxNodes] = new Neuron();
            }

            genome.Genes.Sort(delegate(Gene g1, Gene g2)
            {
                if (g1.Out == g2.Out)
                {
                    return(0);
                }
                else if (g1.Out > g2.Out)
                {
                    return(1);
                }
                else if (g1.Out < g2.Out)
                {
                    return(-1);
                }
                else
                {
                    return(0);
                }
            });

            foreach (Gene gene in genome.Genes)
            {
                if (!gene.Enable)
                {
                    continue;
                }
                if (this._neurons[gene.Out] == null)
                {
                    this._neurons[gene.Out] = new Neuron();
                }

                if (this._neurons[gene.Into] == null)
                {
                    this._neurons[gene.Into] = new Neuron();
                }

                this._neurons[gene.Out].Incomings.Add(gene);
            }
        }
Beispiel #2
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="ea"></param>
 public Genome(EvolutionaryAlogorithm ea, Pool pool)
 {
     this._ea        = ea;
     this._pool      = pool;
     this._maxNeuron = this._ea.Inputs;
     this._connectionsMutationChance = this._ea.ConnectionsMutationChance;
     this._connectionsMutationStep   = this._ea.ConnectionsMutationStep;
     this._linkMutationChance        = this._ea.LinkMutationChance;
     this._biasMutationChance        = this._ea.BiasMutationChance;
     this._nodeMutationChance        = this._ea.NodeMutationChance;
     this._enableMutationChance      = this._ea.EnableMutationChance;
     this._disableMutationChance     = this._ea.DisableMutationChance;
     this.Mutate();
 }
Beispiel #3
0
        /// <summary>
        /// Constructor (Crossover two genome)
        /// </summary>
        /// <param name="genome1"></param>
        /// <param name="genome2"></param>
        public Genome(Genome genome1, Genome genome2)
        {
            this._ea   = genome1._ea;
            this._pool = genome1._pool;

            if (genome2._fitness > genome1._fitness)
            {
                Genome temp = genome1;
                genome1 = genome2;
                genome2 = temp;
            }

            Gene[] innovations = new Gene[this._ea.Pool.Innovation];
            foreach (Gene g2 in genome2._genes)
            {
                innovations[g2.Innovation] = g2;
            }

            foreach (Gene g1 in genome1._genes)
            {
                Gene g2 = innovations[g1.Innovation];
                if (g2 != null && g2.Enable && this._ea.Random.Next(0, 2) == 1)
                {
                    this._genes.Add(new Gene(g2));
                }
                else
                {
                    this._genes.Add(new Gene(g1));
                }
            }

            this._maxNeuron = Math.Max(genome1._maxNeuron, genome2._maxNeuron);
            this._connectionsMutationChance = genome1._connectionsMutationChance;
            this._linkMutationChance        = genome1._linkMutationChance;
            this._biasMutationChance        = genome1._biasMutationChance;
            this._nodeMutationChance        = genome1._nodeMutationChance;
            this._enableMutationChance      = genome1._enableMutationChance;
            this._disableMutationChance     = genome1._disableMutationChance;
        }
Beispiel #4
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="ea"></param>
 public Gene(EvolutionaryAlogorithm ea)
 {
     this._ea = ea;
 }
Beispiel #5
0
 /// <summary>
 /// Constructor
 /// </summary>
 public Species(EvolutionaryAlogorithm ea)
 {
     this._ea = ea;
 }
Beispiel #6
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="ea"></param>
 public Pool(EvolutionaryAlogorithm ea)
 {
     this._ea         = ea;
     this._innovation = this._ea.Outputs;
 }