示例#1
0
        public void Reset(int inputSize, int outputSize)
        {
            InputSize  = inputSize;
            OutputSize = outputSize;

            Connections.Clear();
            Nodes.Clear();

            // Directly access property of the newly addded node to list
            for (int i = 0; i < inputSize; i++)
            {
                NodeGene n = AddNode();
                n.X = 0.1f;                 // Used for drawing

                float _testa = i + 1;
                float _testb = inputSize + 1;
                float _testc = _testa / _testb;
                //n.Y = _testc;
                n.Y = i + 1 / inputSize + 1;
            }
            for (int i = 0; i < outputSize; i++)
            {
                NodeGene n = AddNode();
                n.X = 0.9f;                 // Used for drawing
                n.Y = i + 1 / outputSize + 1;
            }
        }
示例#2
0
        public int GetReplaceIndex(NodeGene node1, NodeGene node2)
        {
            ConnectionGene con  = new ConnectionGene(node1, node2);
            ConnectionGene data = Connections[con];

            if (data == null)
            {
                return(0);
            }
            return(data.ReplaceIndex);
        }
示例#3
0
        /// <summary>
        /// Add a new node to the nervous system
        /// </summary>
        /// <returns>Returns the added node</returns>
        public NodeGene AddNode()
        {
            if (Nodes.Count > MAX_NODES)
            {
                return(null);
            }
            NodeGene n = new NodeGene(Nodes.Count + 1);

            Nodes.Add(n);
            return(n);
        }
示例#4
0
        public ConnectionGene AddConnection(NodeGene node1, NodeGene node2)
        {
            /// Check if the current connection exists on the current genome
            ConnectionGene connectionGene = new ConnectionGene(node1, node2);

            if (Connections.ContainsKey(connectionGene))
            {
                connectionGene.InnovationNumber = Connections[connectionGene].InnovationNumber;
            }
            else
            {
                connectionGene.InnovationNumber = Connections.Count + 1;
                Connections.Add(connectionGene, connectionGene);
            }
            return(connectionGene);
        }
示例#5
0
 public ConnectionGene(NodeGene from, NodeGene to) : this()
 {
     From = from;
     To   = to;
 }
示例#6
0
 public void SetReplaceIndex(NodeGene node1, NodeGene node2, int index)
 {
     Connections[new ConnectionGene(node1, node2)].ReplaceIndex = index;
 }