Please, dont alter the programs sourcecode and recompile at runtime.
There are tons of ways to evaluate functions, some are:
- JavaScript evaluation
- Your own evaluator, start here
- other evaluators, like JEval
You should store the equation in a tree (done for you by many libraries), alter that tree in your genetic algorithm, and evaluate it.
You can store functions easily via interfaces or subclasses... It would be even easier with reflection.
But: You might find more efficient ways to determine that function. We can help you more if you give us the function the program should create.