コード例 #1
0
        /// <summary>
        /// Loads an ERC from the ERCBank given the value in the genome.
        /// If there is no such ERC, then one is created and randomized, then added to the bank.
        /// The point of this mechanism is to enable ERCs to appear in multiple places in a GPTree.
        /// </summary>
        public GPNode ObtainERC(IEvolutionState state, int genomeVal, int threadnum,
                                GPNode node, IDictionary <int, GPNode> ercMapsForFancyPrint)
        {
            // TODO: BRS: Questionable key here because of Java -> C# conversion (hash codes)
            var ercList = (IList <GPNode>)ERCBank[genomeVal];

            if (ercList == null)
            {
                ercList            = new List <GPNode>();
                ERCBank[genomeVal] = ercList;
            }

            GPNode dummy;

            // search array list for an ERC of the same type we want
            for (var i = 0; i < ercList.Count; i++)
            {
                dummy = ercList[i];

                // ERC was found inside the list
                if (dummy.NodeEquivalentTo(node))
                {
                    if (ercMapsForFancyPrint != null)
                    {
                        ercMapsForFancyPrint[genomeVal] = dummy;
                    }
                    return(dummy.LightClone());
                }
            }

            // erc was not found in the array list lets make one
            node = node.LightClone();
            node.ResetNode(state, threadnum);
            ercList.Add(node);
            if (ercMapsForFancyPrint != null)
            {
                ercMapsForFancyPrint[genomeVal] = node;
            }
            return(node);
        }