source: liacs/nc/low-correlation/sa.m@ 74

Last change on this file since 74 was 44, checked in by Rick van der Zwet, 15 years ago

Make it cute

  • Property svn:keywords set to Id
File size: 1.0 KB
RevLine 
[32]1% Simulated Annealing low-autocorrelation program
[28]2% BSDLicence
3% Rick van der Zwet - 0433373 - <hvdzwet@liacs.nl>
[44]4% $Id: sa.m 44 2009-12-17 22:23:16Z rick $
[28]5
[39]6function [iteration_history,fitness_history] = sa(seq, stopLimit)
[44]7 fitness = 0;
8 temperature = stopLimit;
[32]9
[44]10 iteration_history = [];
11 fitness_history = [];
[39]12
[44]13 for iteration = 1:stopLimit
14 % Generate new mutation
15 newseq = mutation(seq);
[32]16
[44]17 new_fitness = autocorrelation(newseq);
[39]18
[44]19 % Better is always accept
20 if (new_fitness > fitness)
21 fitness = new_fitness;
22 % disp(rot90(newseq,-1));
23 temperature = temperature - 10;
24 else
25 % Make the next 'move' less atractive
26 temperature = temperature + 1;
[32]27
[44]28 % Accept on an certain probability
29 if (temperature < 1)
30 break;
31 else
32 % XXX: Some more cleaver cooling would be great
33 if( exp(1)^((fitness - new_fitness) / temperature) > rand())
34 seq = newseq;
35 end
36 end
[39]37 end
[44]38 iteration_history = [ iteration_history, iteration ];
39 fitness_history = [ fitness_history, fitness ];
40 end
[38]41end
Note: See TracBrowser for help on using the repository browser.