예제 #1
0
        private string SpliceWith(GPSolution mateWith, string key)
        {
            if (!valores.ContainsKey(key))
            {
                return(null);
            }
            if (!mateWith.valores.ContainsKey(key))
            {
                return(null);
            }
            GPAbstractNode rootNode1 = valores[key];
            GPAbstractNode rootNode2 = mateWith.valores[key];

            if (rootNode1.Size() > 1 && rootNode2.Size() > 1)
            {
                int            count    = 0;
                GPAbstractNode rndNode1 = rootNode1.GetNthChild(Utils.RandomInt(2, rootNode1.Size()), ref count);
                count = 0;
                GPAbstractNode rndNode2 = rootNode2.GetNthChild(Utils.RandomInt(2, rootNode2.Size()), ref count);
                if (!rndNode1.nodePai.TransferNode(rndNode1, rndNode2))
                {
                    Utils.Error("Erro fazendo transferNode!");
                    return(null);
                }
            }
            else
            {
                valores.Remove(key);
                mateWith.valores.Remove(key);
                valores.Add(key, rootNode2);
                mateWith.valores.Add(key, rootNode1);
            }
            return(key);
        }
예제 #2
0
        public GPSolution Clone()
        {
            GPSolution result = new GPSolution(template);

            foreach (string key in valores.Keys)
            {
                GPAbstractNode node = valores[key].Clone();
                result.valores.Add(key, node);
            }

            return(result);
        }
예제 #3
0
        public GPSolution CreateChildWith(GPSolution solution2, out GPSolution child2)
        {
            child2 = solution2.Clone();
            GPSolution child = this.Clone();

            foreach (string key in valores.Keys)
            {
                /* GPAbstractNode node1 = child.valores[key];
                *  GPAbstractNode node2 = child2.valores[key];*/
                child.SpliceWith(child2, key);
            }

            return(child);
        }
예제 #4
0
        public string SpliceWith(GPSolution mateWith)
        {
            int           minSize   = 2;
            List <string> validKeys = new List <string>();

            foreach (string key in valores.Keys)
            {
                if (valores[key].Size() > minSize && mateWith.valores[key].Size() > minSize)
                {
                    validKeys.Add(key);
                }
            }

            if (validKeys.Count > 0)
            {
                string key = validKeys[Utils.RandomInt(0, validKeys.Count)];
                return(SpliceWith(mateWith, key));
            }
            else
            {
                Utils.Error("Nenhuma chave válida com tamanho minimo de " + minSize);
                return(null);
            }
        }