public virtual double[] Execute(double [] register_values) { for (int i = 0; i < mRegisterSet.RegisterCount; ++i) { mRegisterSet.FindRegisterByIndex(i).Value = register_values[i % register_values.Length]; } LGPOperator.OperatorExecutionStatus command = LGPOperator.OperatorExecutionStatus.LGP_EXECUTE_NEXT_INSTRUCTION; LGPInstruction current_effective_instruction = null; LGPInstruction prev_effective_instruction = null; foreach (LGPInstruction instruction in mInstructions) { if (instruction.IsStructuralIntron) { continue; } prev_effective_instruction = current_effective_instruction; current_effective_instruction = instruction; if (command == LGPOperator.OperatorExecutionStatus.LGP_EXECUTE_NEXT_INSTRUCTION) { command = current_effective_instruction.Execute(); } else { // Xianshun says: // as suggested in Linear Genetic Programming // the condictional construct is restricted to single condictional construct // an example of single conditional construct would be // line 1: if(register[a]) // line 2: <action1> // line 3: <action2> // if register[a]==true, then <action1> and <action2> are executed // if register[a]==false, then <action1> is skipped and <action2> is executed // <action1> and <action2> are restricted to effective instruction if (prev_effective_instruction.IsConditionalConstruct) { command = LGPOperator.OperatorExecutionStatus.LGP_EXECUTE_NEXT_INSTRUCTION; } } } double[] outputs = new double[mRegisterSet.RegisterCount]; for (int i = 0; i < outputs.Length; ++i) { outputs[i] = mRegisterSet.FindRegisterByIndex(i).Value; } return(outputs); }
protected void ExecuteOnFitnessCase(LGPFitnessCase fitness_case) { mPop.InitializeProgramRegisters(this, fitness_case); LGPOperator.OperatorExecutionStatus command = LGPOperator.OperatorExecutionStatus.LGP_EXECUTE_NEXT_INSTRUCTION; LGPInstruction current_effective_instruction = null; LGPInstruction prev_effective_instruction = null; foreach (LGPInstruction instruction in mInstructions) { if (instruction.IsStructuralIntron) { continue; } prev_effective_instruction = current_effective_instruction; current_effective_instruction = instruction; if (command == LGPOperator.OperatorExecutionStatus.LGP_EXECUTE_NEXT_INSTRUCTION) { command = current_effective_instruction.Execute(); fitness_case.ReportProgress(instruction.Operator, instruction.Operand1, instruction.Operand2, instruction.DestinationRegister, RegisterSet); } else { // Xianshun says: // as suggested in Linear Genetic Programming // the condictional construct is restricted to single condictional construct // an example of single conditional construct would be // line 1: if(register[a]) // line 2: <action1> // line 3: <action2> // if register[a]==true, then <action1> and <action2> are executed // if register[a]==false, then <action1> is skipped and <action2> is executed // <action1> and <action2> are restricted to effective instruction if (prev_effective_instruction.IsConditionalConstruct) { command = LGPOperator.OperatorExecutionStatus.LGP_EXECUTE_NEXT_INSTRUCTION; } } } double[] outputs = new double[mRegisterSet.RegisterCount]; for (int i = 0; i < outputs.Length; ++i) { outputs[i] = mRegisterSet.FindRegisterByIndex(i).Value; } fitness_case.RunLGPProgramCompleted(outputs); }