public void MutateNode(Genome genome)
        {
            NodeGene newNode;

            List <ConnectionGene> candidateConnections = genome.Connections.Values.ToList();
            int            randomIndex       = rand.Next(0, candidateConnections.Count);
            ConnectionGene connectionToSplit = candidateConnections[randomIndex];

            RecordIndex index      = new RecordIndex(connectionToSplit.Input.Innovation, connectionToSplit.Output.Innovation);
            NodeGene    wasSplitBy = this.archive.GetRecord(index).wasSplitBy;

            if (wasSplitBy != null)
            {
                newNode = new NodeGene(wasSplitBy);
            }
            else
            {
                newNode = new NodeGene(InnovationGenerator.ID, Constants.NodeType.HIDDEN);
            }

            ConnectionGene connection1 = new ConnectionGene(InnovationGenerator.ID, connectionToSplit.Input, newNode, connectionToSplit.Weight);
            ConnectionGene connection2 = new ConnectionGene(InnovationGenerator.ID, newNode, connectionToSplit.Output);

            //genome.Connections.Remove(connectionToSplit.Innovation);
            genome.Connections[connectionToSplit.Innovation].Enabled = false;
            genome.Add(newNode);
            genome.Add(connection1, connection2);

            this.archive.CreateRecord(genome.Connections[connectionToSplit.Innovation], newNode);
            this.archive.CreateRecord(connection1);
            this.archive.CreateRecord(connection2);
        }
Пример #2
0
        }                                 //consider removing the gene from the genome entirely when this is set to false

        #endregion


        #region Constructors

        public ConnectionGene(int innovation, NodeGene input, NodeGene output, double weight = 1, bool enabled = true)
        {
            this.Innovation = innovation;
            this.Input      = input;
            this.Output     = output;
            this.Weight     = weight;
            this.Enabled    = enabled;
        }
Пример #3
0
        private List <NodeGene> GenerateNodes(int count, Constants.NodeType type)
        {
            List <NodeGene> nodes = new List <NodeGene>();

            for (int i = 0; i < count; i++)
            {
                NodeGene node = new NodeGene(InnovationGenerator.ID, type);
                nodes.Add(node);
            }

            return(nodes);
        }
Пример #4
0
 public NodeGene(NodeGene node)
 {
     this.Innovation = node.Innovation;
     this.Type       = node.Type;
     this.Value      = node.Value;
 }
Пример #5
0
 public ArchiveRecord(ConnectionGene connection, NodeGene node)
 {
     this.connection = connection;
     this.wasSplitBy = node;
 }