Пример #1
0
        public LGPOperator FindRandomOperator(LGPOperator current_operator = null)
        {
            for (int attempts = 0; attempts < 10; attempts++)
            {
                double r = mWeightSum * maths.Distribution.DistributionModel.GetUniform();

                double current_sum = 0;
                foreach (KeyValuePair <LGPOperator, double> point in mOperators)
                {
                    current_sum += point.Value;
                    if (current_sum >= r)
                    {
                        if (point.Key != current_operator)
                        {
                            return(point.Key);
                        }
                        else
                        {
                            break;
                        }
                    }
                }
            }

            return(current_operator);
        }
Пример #2
0
        public virtual void Create()
        {
            mOperator = mProgram.OperatorSet.FindRandomOperator();

            double p_const = 0.5;
            double r       = maths.Distribution.DistributionModel.GetUniform();

            if (r < p_const)
            {
                mOperand1 = mProgram.ConstantSet.FindRandomRegister();
            }
            else
            {
                mOperand1 = mProgram.RegisterSet.FindRandomRegister();
            }
            if (mOperand1.IsConstant)
            {
                mOperand2 = mProgram.RegisterSet.FindRandomRegister();
            }
            else
            {
                r = maths.Distribution.DistributionModel.GetUniform();
                if (r < p_const)
                {
                    mOperand2 = mProgram.ConstantSet.FindRandomRegister();
                }
                else
                {
                    mOperand2 = mProgram.RegisterSet.FindRandomRegister();
                }
            }
            mDestinationRegister = mProgram.RegisterSet.FindRandomRegister();
        }
Пример #3
0
 public void AddOperator(LGPOperator op, double weight = 1)
 {
     mOperators.Add(new KeyValuePair <LGPOperator, double>(op, weight));
     op.mOperatorIndex = mOperators.Count - 1;
     mWeightSum       += weight;
 }
 public void Copy(LGPOperator rhs)
 {
     mOperatorIndex          = rhs.mOperatorIndex;
     mIsConditionalConstruct = rhs.mIsConditionalConstruct;
     mSymbol = rhs.mSymbol;
 }
Пример #5
0
 public virtual void MutateOperator()
 {
     mOperator = mProgram.OperatorSet.FindRandomOperator();
 }