Changeset 39 for liacs/nc/low-correlation/sa.m
- Timestamp:
- Dec 16, 2009, 8:37:47 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
liacs/nc/low-correlation/sa.m
r38 r39 3 3 % Rick van der Zwet - 0433373 - <hvdzwet@liacs.nl> 4 4 5 function [fitness,value] = sa(length, temperature, stopLimit) 6 best_fitness = 0; 7 s = initseq(length); 8 stopCounter = 0; 5 function [iteration_history,fitness_history] = sa(seq, stopLimit) 6 fitness = 0; 7 temperature = stopLimit; 9 8 10 while (stopCounter < stopLimit) 9 iteration_history = []; 10 fitness_history = []; 11 12 for iteration = 1:stopLimit 11 13 % Generate new mutation 12 newseq = mutation(s); 14 newseq = mutation(seq); 15 16 new_fitness = autocorrelation(newseq); 13 17 14 18 % Better is always accept 15 fitness = autocorrelation(newseq); 16 if (fitness > best_fitness) 17 best_value = s; 18 best_fitness = fitness; 19 s = newseq; 19 if (new_fitness > fitness) 20 fitness = new_fitness; 20 21 % disp(rot90(newseq,-1)); 21 stopCounter =0;22 temperature = temperature - 10; 22 23 else 23 24 % Make the next 'move' less atractive 24 temperature = -1;25 temperature = temperature + 1; 25 26 26 stopCounter =+ 1;27 27 % Accept on an certain probability 28 if (temperature < 0)28 if (temperature < 1) 29 29 break; 30 30 else 31 if(randint(0,temperature) > temperature / 4) 32 s = newseq; 31 % XXX: Some more cleaver cooling would be great 32 if( e^((fitness - new_fitness) / temperature) > rand()) 33 seq = newseq; 33 34 end 34 35 end 35 end36 end37 value = best_value;38 fitness = best_fitness;36 end 37 iteration_history = [ iteration_history, iteration ]; 38 fitness_history = [ fitness_history, fitness ]; 39 end 39 40 end
Note:
See TracChangeset
for help on using the changeset viewer.