Пример #1
0
        public GPProgramTreeFactory(GPModelerServer Config, int InputDimension)
        {
            m_Config         = Config;
            m_InputDimension = InputDimension;

            m_OperatorADF = new GPProgramBranchFactoryADF(null, Config);
            m_OperatorADL = new GPProgramBranchFactoryADL(null, Config);
            m_OperatorADR = new GPProgramBranchFactoryADR(null, Config);
            m_OperatorRPB = new GPProgramBranchFactoryRPB(null, Config);
        }
Пример #2
0
        /// <summary>
        /// This directs a crossover to be made with a sibling.
        /// A random selection is made from each of the program branches
        /// and then that branch is requested to perform mutation with
        /// the sibling.
        /// </summary>
        /// <param name="sibling"></param>
        /// <returns></returns>
        public GPProgram Crossover(GPProgram sibling)
        {
            //
            // Make a random selection about which program branch to select
            int Count = 1;             // 1 is for the RPB

            if (m_Program.CountRPBADFNodes > 0)
            {
                Count += m_Program.ADF.Count;
            }
            if (m_Program.CountRPBADLNodes > 0)
            {
                Count += m_Program.ADL.Count;
            }
            if (m_Program.CountRPBADRNodes > 0)
            {
                Count += m_Program.ADR.Count;
            }

            int Selection = GPUtilities.rngNextInt(Count);

            if (Selection == 0)                 // RPB
            {
                GPProgramBranchFactoryRPB rpbOperator = new GPProgramBranchFactoryRPB(m_Program.RPB, m_Config);
                rpbOperator.Crossover(sibling.RPB);

                return(sibling);
            }
            Selection--;
            //
            // See if we hit an ADF
            if ((Selection < m_Program.ADF.Count) && (m_Program.CountRPBADFNodes > 0))
            {
                GPProgramBranchFactoryADF adfOperator = new GPProgramBranchFactoryADF(m_Program.ADF[Selection], m_Config);
                adfOperator.Crossover(sibling.ADF[Selection]);

                return(sibling);
            }
            if (m_Program.CountRPBADFNodes > 0)
            {
                Selection -= m_Program.ADF.Count;
            }

            //
            // See if we hit an ADL
            if ((Selection < m_Program.ADL.Count) && (m_Program.CountRPBADLNodes > 0))
            {
                GPProgramBranchFactoryADL adlOperator = new GPProgramBranchFactoryADL(m_Program.ADL[Selection], m_Config);
                adlOperator.Crossover(sibling.ADL[Selection]);

                return(sibling);
            }
            if (m_Program.CountRPBADLNodes > 0)
            {
                Selection -= m_Program.ADL.Count;
            }

            //
            // See if we hit an ADR
            if ((Selection < m_Program.ADR.Count) && (m_Program.CountRPBADRNodes > 0))
            {
                GPProgramBranchFactoryADR adrOperator = new GPProgramBranchFactoryADR(m_Program.ADR[Selection], m_Config);
                adrOperator.Crossover(sibling.ADR[Selection]);

                return(sibling);
            }
            if (m_Program.CountRPBADRNodes > 0)
            {
                Selection -= m_Program.ADR.Count;
            }

            return(null);
        }
Пример #3
0
        /// <summary>
        /// Performs a random mutation somewhere within the program tree.  All of
        /// the various program branches are equally weighted for selection.
        /// </summary>
        public void Mutate()
        {
            //
            // Make a random selection about which program branch to mutate.  We check
            // to see if the RPB uses an ADF, ADL or ADR, if not, they are not included as
            // an option for mutation.  This is an evoluationary optimization, don't waste
            // time mutating something that isn't being used.
            int Count = 1;             // 1 is for the RPB

            if (m_Program.CountRPBADFNodes > 0)
            {
                Count += m_Program.ADF.Count;
            }
            if (m_Program.CountRPBADLNodes > 0)
            {
                Count += m_Program.ADL.Count;
            }
            if (m_Program.CountRPBADRNodes > 0)
            {
                Count += m_Program.ADR.Count;
            }

            int Selection = GPUtilities.rngNextInt(Count);

            //
            // Let's find out what we hit
            if (Selection == 0)                 // RPB
            {
                GPProgramBranchFactoryRPB rpbOperator = new GPProgramBranchFactoryRPB(m_Program.RPB, m_Config);
                rpbOperator.Mutate();
                return;
            }
            Selection--;
            //
            // See if we hit an ADF - and there are ADFs in use
            if ((Selection < m_Program.ADF.Count) && (m_Program.CountRPBADFNodes > 0))
            {
                GPProgramBranchFactoryADF adfOperator = new GPProgramBranchFactoryADF(m_Program.ADF[Selection], m_Config);
                adfOperator.Mutate();
                return;
            }
            if (m_Program.CountRPBADFNodes > 0)                 // only subtract if ADFs are in use
            {
                Selection -= m_Program.ADF.Count;
            }

            //
            // See if we hit an ADL - and ADLs are in use
            if ((Selection < m_Program.ADL.Count) && (m_Program.CountRPBADLNodes > 0))
            {
                GPProgramBranchFactoryADL adlOperator = new GPProgramBranchFactoryADL(m_Program.ADL[Selection], m_Config);
                adlOperator.Mutate();
                return;
            }
            if (m_Program.CountRPBADLNodes > 0)             // only subtract if ADLs are in use
            {
                Selection -= m_Program.ADL.Count;
            }

            //
            // See if we hit an ADR - and ADRs are in use
            if ((Selection < m_Program.ADR.Count) && (m_Program.CountRPBADRNodes > 0))
            {
                GPProgramBranchFactoryADR adrOperator = new GPProgramBranchFactoryADR(m_Program.ADR[Selection], m_Config);
                adrOperator.Mutate();
                return;
            }
            if (m_Program.CountRPBADRNodes > 0)             // only subtract if ADRs are in use
            {
                Selection -= m_Program.ADR.Count;
            }
        }