source: liacs/nc/low-correlation/mcs.m@ 61

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

Report finished = sleep

  • Property svn:keywords set to Id
File size: 859 bytes
Line 
1% Monte-Carlo Search Algoritm on low-autocorrelation program
2% BSDLicence
3% Rick van der Zwet - 0433373 - <hvdzwet@liacs.nl>
4% $Id: mcs.m 46 2009-12-18 01:43:33Z rick $
5
6% Brute-force result of length 20
7% best_20 = [-1,1,1,-1,-1,-1,1,1,-1,1,-1,-1,-1,1,-1,1,1,1,1,1];
8% autocorrelation(best_20);
9
10function [iteration_history,fitness_history] = mcs(length, iterations)
11 iteration_history = [];
12 fitness_history = [];
13
14 best_fitness = 0;
15 for iteration = 1:iterations
16 % Generate a random column s={-1,1}^n
17 n = length;
18 s = rand(n,1);
19 s = round(s);
20 s = s - (s == 0);
21
22 % Find whether we are better than everything else
23 fitness = autocorrelation(s);
24 if (fitness > best_fitness)
25 best_value = s;
26 best_fitness = fitness;
27 end
28 iteration_history = [ iteration_history, iteration ];
29 fitness_history = [ fitness_history, best_fitness ];
30 end
31end
Note: See TracBrowser for help on using the repository browser.