Esempio n. 1
0
        public Genome(NeatManager neat, Species species, int[] inputNeurons, int[] outputNeurons)
        {
            this.instanceID = Guid.NewGuid();
            this.neat       = neat;

            this.species = species;


            foreach (int inNeuron in inputNeurons)
            {
                this.addInputNeuron(inNeuron);
            }

            foreach (int outNeuron in outputNeurons)
            {
                this.addOutputNeuron(outNeuron);
            }
        }
Esempio n. 2
0
        private void btnTrain_Click(object sender, EventArgs e)
        {
            btnTrain.Text      = "Training";
            btnTrain.Enabled   = false;
            btnPlay.Enabled    = false;
            cbFeedback.Enabled = false;
            if (_chartForm != null)
            {
                _chartForm.Hide();
                _chartForm.Dispose();
            }

            InfoManager.clear();
            _neat = new NeatManager(_game, (int)nGenerations.Value);

            btnTrain.Text      = "Train";
            btnTrain.Enabled   = true;
            btnPlay.Enabled    = true;
            cbFeedback.Enabled = true;
        }
Esempio n. 3
0
        public static Genome cross(NeatManager neat, Genome a, Genome b)
        {
            double aFitness = a.fitness;
            double bFitness = b.fitness;

            Genome strongest;
            Genome weakest;

            if (aFitness > bFitness)
            {
                strongest = a;
                weakest   = b;
            }
            else
            {
                strongest = b;
                weakest   = a;
            }

            return(crossDominant(neat, strongest, weakest));
        }
Esempio n. 4
0
        private static Genome crossDominant(NeatManager neat, Genome dominant, Genome other)
        {
            if (dominant.synapses.Count == 0 || other.synapses.Count == 0)
            {
                return(null);
            }

            int similarityNeurons = -1;

            for (int i = 1; i < 100000; i++)
            {
                if (dominant.hasSynapse(i) && other.hasSynapse(i))
                {
                    similarityNeurons = i;
                }
            }

            if (similarityNeurons == -1)
            {
                throw new Exception("No similarity between Genomes");
            }

            Genome newGenome = new Genome(neat, null, dominant.inputNeurons.ToArray(), dominant.outputNeurons.ToArray());

            for (int i = 1; i <= dominant.getHighestInnovationNumber(); i++)
            {
                if (dominant.hasSynapse(i))
                {
                    int    innovationNumber, inputNeuron, outputNeuron;
                    double weigth;
                    bool   enabled;

                    if (other.hasSynapse(i))
                    {
                        Random r = new Random();

                        if (r.Next(0, 1) == 1)
                        {
                            innovationNumber = dominant.synapses[i].innovationNumber;
                            inputNeuron      = dominant.synapses[i].from;
                            outputNeuron     = dominant.synapses[i].to;
                            weigth           = dominant.synapses[i].weight;
                            enabled          = dominant.synapses[i].enabled;
                        }
                        else
                        {
                            innovationNumber = other.synapses[i].innovationNumber;
                            inputNeuron      = other.synapses[i].from;
                            outputNeuron     = other.synapses[i].to;
                            weigth           = other.synapses[i].weight;
                            enabled          = other.synapses[i].enabled;
                        }
                    }
                    else
                    {
                        innovationNumber = dominant.synapses[i].innovationNumber;
                        inputNeuron      = dominant.synapses[i].from;
                        outputNeuron     = dominant.synapses[i].to;
                        weigth           = dominant.synapses[i].weight;
                        enabled          = dominant.synapses[i].enabled;
                    }
                    newGenome.addSynapse(new Synapse(innovationNumber, inputNeuron, outputNeuron, weigth, enabled), dominant, other);
                }
            }

            newGenome.removeDuplicateSynapses();
            newGenome.mutate();

            return(newGenome);
        }
Esempio n. 5
0
 public Population(NeatManager neat)
 {
     this.neat = neat;
 }