Exemplo n.º 1
0
 public void AddRegister(LGPRegister register, double weight = 1)
 {
     mRegisters.Add(new KeyValuePair <LGPRegister, double>(register, weight));
     register.mRegisterIndex = mRegisters.Count - 1;
     register.mIsConstant    = true;
     mWeightSum += weight;
 }
Exemplo n.º 2
0
        public void AddConstant(double value, double weight)
        {
            LGPRegister register = new LGPRegister();

            register.Value = value;
            AddRegister(register);
        }
Exemplo n.º 3
0
        public LGPRegister FindRandomRegister(LGPRegister current_register = null)
        {
            for (int attempts = 0; attempts < 10; attempts++)
            {
                double r = mWeightSum * maths.Distribution.DistributionModel.GetUniform();

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

            return(current_register);
        }
Exemplo n.º 4
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();
        }
Exemplo n.º 5
0
        public LGPRegister Clone()
        {
            LGPRegister clone = new LGPRegister();

            clone.mRegisterIndex = mRegisterIndex;
            clone.mIsConstant    = mIsConstant;
            clone.mValue         = mValue;
            return(clone);
        }
Exemplo n.º 6
0
        public virtual void MutateRegister(double p_const = 0.5)
        {
            double r = maths.Distribution.DistributionModel.GetUniform();

            if (r < 0.5)
            {
                mDestinationRegister = mProgram.RegisterSet.FindRandomRegister(mDestinationRegister);
            }
            else
            {
                r = maths.Distribution.DistributionModel.GetUniform();
                LGPRegister arg1, arg2;
                if (r < 0.5)
                {
                    arg1 = mOperand1;
                    arg2 = mOperand2;
                }
                else
                {
                    arg1 = mOperand2;
                    arg2 = mOperand1;
                }

                if (arg2.IsConstant)
                {
                    arg1 = mProgram.RegisterSet.FindRandomRegister();
                }
                else
                {
                    r = maths.Distribution.DistributionModel.GetUniform();
                    if (r < p_const)
                    {
                        arg1 = mProgram.ConstantSet.FindRandomRegister();
                    }
                    else
                    {
                        arg1 = mProgram.RegisterSet.FindRandomRegister();
                    }
                }

                mOperand1 = arg1;
                mOperand2 = arg2;
            }
        }
 public abstract OperatorExecutionStatus Execute(LGPRegister operand1, LGPRegister operand2, LGPRegister destination_register);