I have written some code in Java which tests the fitness of two solutions.
I am looking to then compare the two solutions and keep the one which has the best fitness and to discard the other.
For example:
if(fitness1 < fitness2)
keep fitness1 and discard/ignore fitness2
else
keep fitness2 and discard/ignore fitness1
How would I go about achieving this? Eventually I hope to have a list (size n) of the best fitness levels. I imagine that I would have to add the best fitness in each iteration to a list of some type?
fitness1andfitness2are both double variables.discardjust means 'ignore' - I am only looking to keep track of the best fitness level.fitness1andfitness2? What do you mean by "discard"? Java has automatic garbage collection, so you don't need to do anything to discard an object; just don't keep a reference to it.