Example #1
0
        public override Object Clone()
        {
            // Instruction.Clone() does a shallow MemberwiseClone()
            PushInstruction myobj = (PushInstruction)base.Clone();

            return(myobj);
        }
Example #2
0
        public override void Setup(IEvolutionState state, IParameter paramBase)
        {
            base.Setup(state, paramBase);

            IParameter def = DefaultBase;

            // Load my standard instructions
            int len = state.Parameters.GetInt(paramBase.Push(P_INSTRUCTION).Push(P_NUM_INSTRUCTIONS),
                                              def.Push(P_NUM_INSTRUCTIONS), 1);

            if (len < 1)
            {
                state.Output.Fatal("Number of instructions must be >= 1",
                                   paramBase.Push(P_INSTRUCTION).Push(P_NUM_INSTRUCTIONS), def.Push(P_NUM_INSTRUCTIONS));
            }

            Instructions = new String[len];
            PushInstruction[] insts = new PushInstruction[len];

            for (int i = 0; i < len; i++)
            {
                Instructions[i] = state.Parameters.GetString(paramBase.Push(P_INSTRUCTION).Push("" + i), def.Push("" + i));
                if (Instructions[i] == null)
                {
                    state.Output.Fatal("Terminal number " + i + " is missing.", paramBase.Push(P_INSTRUCTION).Push("" + i),
                                       def.Push("" + i));
                }

                // load Instruction if there is one
                IParameter bb = paramBase.Push(P_INSTRUCTION).Push("" + i).Push(P_FUNC);
                IParameter dd = def.Push("" + i).Push(P_FUNC);
                if (state.Parameters.ParameterExists(bb, dd)) // got one
                {
                    String s = state.Parameters.GetString(bb, dd);
                    state.Output.Message("Adding Instruction " + Instructions[i] + " --> " + s);
                    PushInstruction inst =
                        (PushInstruction)state.Parameters.GetInstanceForParameter(bb, dd, typeof(PushInstruction));
                    if (inst == null) // uh oh
                    {
                        state.Output.Fatal("Terminal number " + i + ", named " + Instructions[i] +
                                           ", has an invalid function class: " + s);
                    }
                    // load that sucker
                    insts[i] = inst;
                }
            }

            // compress instruction list
            int count = 0;

            for (int i = 0; i < len; i++)
            {
                if (insts[i] != null)
                {
                    count++;
                }
            }
            CustomInstructions = new PushInstruction[count];
            Indices            = new int[count];

            count = 0;
            for (int i = 0; i < len; i++)
            {
                if (insts[i] != null)
                {
                    CustomInstructions[count] = insts[i];
                    Indices[count]            = i;
                    count++;
                }
            }

            // load float ERC bounds
            IParameter b = paramBase.Push(P_FLOAT).Push(P_MIN);
            IParameter d = PushDefaults.ParamBase.Push(P_FLOAT).Push(P_MIN);

            if (!state.Parameters.ParameterExists(b, d))
            {
                state.Output.Warning("No " + ERC_NAMES[FLOAT_ERC] + " min value provided, using " + MinFloatERC, b, d);
            }
            else
            {
                double min = state.Parameters.GetDoubleWithDefault(b, d, double.NaN);
                if (double.IsNaN(min)) // it's NaN
                {
                    state.Output.Fatal("Malformed " + ERC_NAMES[FLOAT_ERC] + " min value", b, d);
                }
                else
                {
                    MinFloatERC = min;
                }
            }

            b = paramBase.Push(P_FLOAT).Push(P_MAX);
            d = PushDefaults.ParamBase.Push(P_FLOAT).Push(P_MAX);

            if (!state.Parameters.ParameterExists(b, d))
            {
                state.Output.Warning("No " + ERC_NAMES[FLOAT_ERC] + " max value provided, using " + MaxFloatERC, b, d);
            }
            else
            {
                double max = state.Parameters.GetDoubleWithDefault(b, d, double.NaN);
                if (double.IsNaN(max)) // it's NaN
                {
                    state.Output.Fatal("Malformed " + ERC_NAMES[FLOAT_ERC] + " max value", b, d);
                }
                else
                {
                    MaxFloatERC = max;
                }
            }
            if (MinFloatERC > MaxFloatERC) // uh oh
            {
                state.Output.Fatal("" + ERC_NAMES[FLOAT_ERC] + " min value is greater than max value.\nMin: " +
                                   MinFloatERC + "\nMax: " + MaxFloatERC);
            }

            b = paramBase.Push(P_INTEGER).Push(P_MIN);
            d = PushDefaults.ParamBase.Push(P_INTEGER).Push(P_MIN);

            // load integer ERC bounds
            if (!state.Parameters.ParameterExists(b, d))
            {
                state.Output.Warning("No " + ERC_NAMES[INTEGER_ERC] + " min value provided, using " + MinIntegerERC, b,
                                     d);
            }
            else
            {
                double min = state.Parameters.GetDoubleWithDefault(b, d, double.NaN);
                if (double.IsNaN(min) || min != (int)min)  // it's NaN or invalid
                {
                    state.Output.Fatal("Malformed " + ERC_NAMES[INTEGER_ERC] + " min value", b, d);
                }
                MinIntegerERC = (int)min;
            }

            b = paramBase.Push(P_INTEGER).Push(P_MAX);
            d = PushDefaults.ParamBase.Push(P_INTEGER).Push(P_MAX);

            if (!state.Parameters.ParameterExists(b, d))
            {
                state.Output.Warning("No " + ERC_NAMES[INTEGER_ERC] + " max value provided, using " + MaxIntegerERC, b,
                                     d);
            }
            else
            {
                double max = state.Parameters.GetDoubleWithDefault(b, d, double.NaN);
                if (double.IsNaN(max) || (max != (int)max))  // it's NaN or invalid
                {
                    state.Output.Fatal("Malformed " + ERC_NAMES[INTEGER_ERC] + " max value", b, d);
                }
                else
                {
                    MaxIntegerERC = (int)max;
                }
            }
            if (MinIntegerERC > MaxIntegerERC) // uh oh
            {
                state.Output.Fatal("" + ERC_NAMES[INTEGER_ERC] + " min value is greater than max value.\nMin: " +
                                   MinIntegerERC + "\nMax: " + MaxIntegerERC);
            }
        }