示例#1
0
        /// <summary>
        /// Adds the given connection gene pattern if not already there.
        /// </summary>
        /// <param name="connectionGenePattern">The connection gene pattern to add.</param>
        /// <returns>True if added. False if already contained.</returns>
        /// <exception cref="ArgumentNullException">When the connection gene pattern is null.</exception>
        public bool AddConnectionGenePattern(ConnectionGenePattern connectionGenePattern)
        {
            Helpers.ThrowOnNull(connectionGenePattern, "connectionGenePattern");


            if (connectionGenePatterns.ContainsKey(connectionGenePattern.InnovationNumber))
            {
                return(false);
            }


            connectionGenePatterns.Add(connectionGenePattern.InnovationNumber, connectionGenePattern);

            return(true);
        }
示例#2
0
        /// <summary>
        /// Creates a connection gene with the given connections, weight, and enabled. Adds the pattern to the tracker if it doesn't exist.
        /// </summary>
        /// <param name="from">The from node gene of the connection gene.</param>
        /// <param name="to">The to node gene of the connection gene.</param>
        /// <param name="weight">The weight of the connection gene.</param>
        /// <param name="enabled">Whether or not the connection is enabled.</param>
        /// <returns>The created connection gene.</returns>
        /// <exception cref="ArgumentNullException">When from/to is null.</exception>
        public ConnectionGene Create_ConnectionGene(NodeGene from, NodeGene to, double weight, bool enabled)
        {
            Helpers.ThrowOnNull(from, "from");
            Helpers.ThrowOnNull(to, "to");


            int innovation_number = ConnectionGenePattern.GetHashCode(this, from.NodeGenePattern, to.NodeGenePattern);

            if (connectionGenePatterns.ContainsKey(innovation_number))
            {
                return(new ConnectionGene(connectionGenePatterns[innovation_number], weight, enabled));
            }


            ConnectionGenePattern created_connectionGenePattern = new ConnectionGenePattern(this, innovation_number, from.NodeGenePattern, to.NodeGenePattern, max_replacingNumber++);

            connectionGenePatterns.Add(innovation_number, created_connectionGenePattern);

            return(new ConnectionGene(created_connectionGenePattern, weight, enabled));
        }
示例#3
0
 /// <summary>
 /// Creates a connection gene with the given pattern, weight, and enabled.
 /// </summary>
 /// <param name="connectionGenePattern">The connection gene pattern of the connection gene.</param>
 /// <param name="weight">The weight of the connection gene.</param>
 /// <param name="enabled">Whether or not the connection is enabled.</param>
 /// <returns>The created connection gene.</returns>
 /// <exception cref="ArgumentNullException">When the connection gene pattern is null.</exception>
 public ConnectionGene Create_ConnectionGene(ConnectionGenePattern connectionGenePattern, double weight, bool enabled)
 {
     return(new ConnectionGene(connectionGenePattern, weight, enabled));
 }