Пример #1
0
        public virtual ISolution Clone()
        {
            TGPSolution clone = new TGPSolution(mPop, mTrees.Count);

            clone.Copy(this);
            return(clone);
        }
Пример #2
0
        public bool IsBetterThan(TGPSolution rhs)
        {
            if (mFitness > rhs.Fitness)
            {
                return(true);
            }
            else if (mFitness == rhs.Fitness)
            {
                int this_better_count = 0;
                for (int i = 0; i < mTrees.Count; ++i)
                {
                    if (mTrees[i].IsBetterThan(rhs.mTrees[i]))
                    {
                        this_better_count++;
                    }
                }

                if (this_better_count * 2 > mTrees.Count)
                {
                    return(true);
                }

                return(false);
            }
            else
            {
                return(false);
            }
        }
Пример #3
0
 protected virtual void Copy(TGPSolution rhs)
 {
     mFitness        = rhs.mFitness;
     mIsFitnessValid = rhs.mIsFitnessValid;
     mObjectiveValue = rhs.mObjectiveValue;
     mTrees.Clear();
     for (int i = 0; i < rhs.mTrees.Count; ++i)
     {
         mTrees.Add(rhs.mTrees[i].Clone());
     }
     foreach (string attrname in rhs.mAttributes.Keys)
     {
         mAttributes[attrname] = rhs.mAttributes[attrname];
     }
 }
Пример #4
0
 public int Compare(TGPSolution rhs)
 {
     return(mFitness.CompareTo(rhs.mFitness));
     //if (mFitness > rhs.mFitness)
     //{
     //    return 1;
     //}
     //else if (mFitness == rhs.mFitness)
     //{
     //    return 0;
     //}
     //else
     //{
     //    return -1;
     //}
 }
Пример #5
0
        public void SubtreeCrossover(IGPSolution _rhs, int iMaxDepthForCrossOver, string method, object tag = null)
        {
            TGPSolution rhs        = (TGPSolution)_rhs;
            int         tree_count = mTrees.Count;

            for (int i = 0; i < tree_count; ++i)
            {
                if (tree_count > 1 && DistributionModel.GetUniform() < 0.5)
                {
                    TGPProgram temp = rhs.mTrees[i];
                    rhs.mTrees[i] = mTrees[i];
                    mTrees[i]     = temp;
                }
                else
                {
                    mTrees[i].SubtreeCrossover(rhs.mTrees[i], iMaxDepthForCrossOver, method, tag);
                }
            }


            TrashFitness();
            rhs.TrashFitness();
        }