Because the simulated annealing algorithm is stochastic—that
is, it makes random choices—you get slightly different results
each time you run it. The algorithm uses the default MATLAB® pseudorandom
number stream. For more information about random number streams, see
RandStream. Each time the algorithm calls
the stream, its state changes. So the next time the algorithm calls
the stream, it returns a different random number.
If you need to reproduce your results exactly, call
output argument. The
contains the current random number generator state in the
Reset the state before running the function again.
For example, to reproduce the output of
to De Jong's fifth function, call
rng(10,'twister') % for reproducibility [x,fval,exitflag,output] = simulannealbnd(@dejong5fcn,[0 0]);
Suppose the results are
x,fval x = -16.1292 -15.8214 fval = 6.9034
The state of the random number generator,
is stored in
output.rngstate. Reset the stream
stream = RandStream.getGlobalStream; stream.State = output.rngstate.State;
If you now run
simulannealbnd a second time,
you get the same results.
If you do not need to reproduce your results, it is better not
to set the states of
RandStream, so that you
get the benefit of the randomness in these algorithms.