Changeset 37


Ignore:
Timestamp:
Dec 16, 2009, 5:06:53 PM (15 years ago)
Author:
Rick van der Zwet
Message:

Working under matlab

File:
1 edited

Legend:

Unmodified
Added
Removed
  • liacs/nc/laser-pulse-shaping/pso.m

    r36 r37  
    4848
    4949idle_counter = 0;
    50 start_time = time();
     50tic();
    5151
    5252% Code not optimised for performance, but for readablility
     
    8484    % Stop conditions
    8585    if idle_counter == iteration_break
    86         printf("Caught by idle_counter\n");
    87         break;
     86        fprintf('Caught by idle_counter\n');
     87        return;
    8888    end
    89     if time - start_time > max_time
    90         printf("Caught by max_time used \n");
    91         break;
     89    if toc > max_time
     90        fprintf('Caught by max_time used \n');
     91        return;
    9292    end
    9393   
    9494
    95     printf("%i : %.15f\n", i, g_fitness);
     95    fprintf('%i : %.15f\n', i, g_fitness);
    9696    fitness_iterations = [fitness_iterations, i];
    9797    fitness_history = [fitness_history, g_fitness];
     
    104104    for s = 1:local_swarms
    105105        for p = 1:local_swarm_size
    106             flock_v(:,p,s) = flock_v(:,p,s) * wander;
    107             flock_v(:,p,s) = flock_v(:,p,s) + (g_best - flock_p(:,p,s)) * (c_cognitive * r_cognitive);
    108             flock_v(:,p,s) = flock_v(:,p,s) + (n_best(:,s) - flock_p(:,p,s)) * (c_social * r_social);
    109             flock_v(:,p,s) = flock_v(:,p,s) + (l_best(:,p,s) - flock_p(:,p,s)) * (c_ego * r_ego);
     106            flock_v(:,p,s) = flock_v(:,p,s) * wander + ...
     107              (g_best - flock_p(:,p,s)) * (c_cognitive * r_cognitive) + ...
     108              (n_best(:,s) - flock_p(:,p,s)) * (c_social * r_social) + ...
     109              (l_best(:,p,s) - flock_p(:,p,s)) * (c_ego * r_ego);
    110110            flock_p(:,p,s) = flock_p(:,p,s) + flock_v(:,p,s);
    111111        end
     
    120120grid on;
    121121legend(sprintf('Parameters %i',parameters));
    122 print("pso-fitness.eps","-depsc2");
    123 
     122print('pso-fitness.eps','-depsc2');
Note: See TracChangeset for help on using the changeset viewer.