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

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

Working version using brute-force

File size: 676 bytes
RevLine 
[28]1% Monte-Carlo Search Algoritm on low-autocorrelation program
2% BSDLicence
3% Rick van der Zwet - 0433373 - <hvdzwet@liacs.nl>
4
[30]5% Brute-force result of length 20
6% best_20 = [-1,1,1,-1,-1,-1,1,1,-1,1,-1,-1,-1,1,-1,1,1,1,1,1];
7% autocorrelation(best_20);
8
9
[28]10best_fitness = 0;
11while (1)
[30]12 % Generate a random column s={-1,1}^n
[28]13 n = 20;
14 s = rand(n,1);
15 s = round(s);
[30]16 s = s - (s == 0);
[28]17
18 % Find whether we are better than everything else
[30]19 fitness = autocorrelation(s);
[28]20 if (fitness > best_fitness)
[30]21 best_result = s;
[29]22 best_fitness = fitness
[28]23 % Little hack to display output nicely
[30]24 disp(rot90(best_result,-1));
[28]25 endif
26endwhile
27
Note: See TracBrowser for help on using the repository browser.