Ignore:
Timestamp:
Dec 16, 2009, 8:37:47 PM (15 years ago)
Author:
Rick van der Zwet
Message:

Make it run properly (iterations vs fitness)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • liacs/nc/low-correlation/sa.m

    r38 r39  
    33% Rick van der Zwet - 0433373 - <hvdzwet@liacs.nl>
    44
    5 function [fitness,value] = sa(length, temperature, stopLimit)
    6     best_fitness = 0;
    7     s = initseq(length);
    8     stopCounter = 0;
     5function [iteration_history,fitness_history] = sa(seq, stopLimit)
     6    fitness = 0;
     7    temperature = stopLimit;
    98
    10     while (stopCounter < stopLimit)
     9    iteration_history = [];
     10    fitness_history = [];
     11
     12    for iteration = 1:stopLimit
    1113        % Generate new mutation
    12         newseq = mutation(s);
     14        newseq = mutation(seq);
     15
     16        new_fitness = autocorrelation(newseq);
    1317
    1418        % 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;
    2021            % disp(rot90(newseq,-1));
    21             stopCounter = 0;
     22            temperature = temperature - 10;
    2223        else
    2324            % Make the next 'move' less atractive
    24             temperature =- 1;
     25            temperature = temperature + 1;
    2526
    26             stopCounter =+ 1;
    2727            % Accept on an certain probability
    28             if (temperature < 0)
     28            if (temperature < 1)
    2929                break;
    3030            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;
    3334               end
    3435           end
    35        end
    36    end
    37     value = best_value;
    38     fitness = best_fitness;
     36        end
     37        iteration_history = [ iteration_history, iteration ];
     38        fitness_history = [ fitness_history, fitness ];
     39    end
    3940end
Note: See TracChangeset for help on using the changeset viewer.