A list,

Introduction of simulated annealing algorithm 3 the parameters of the simulated annealing algorithm simulated annealing is a kind of optimization algorithm, it itself is not exist independently, needs to have a applications, the temperature is simulated annealing to optimize the parameters, if it is applied to clustering analysis, so the clustering analysis has a certain or a few parameters need to optimization, the parameters, Or the parameter set is the temperature. It could be some index, some correlation, some distance, etc.

Ii. Source code

CLC clear % = = = = = = = = = data entry, parameter adjustment = = = = = = = = = = = = = = = = = swarminitNum =20; % Number of particles initially generated; MM=[1 2 3 4 5 6 
    6 6 6 6 6 6]; % Number matrix of workpiece and process, the first line of MM represents the workpiece, and the second line represents the number of processes of each workpiece; machineNum=6; % Number of processing machines; initT=500; Initial temperature of simulated annealing; gen=1000; % Number of iterations; w1=0.35; % variation rate; changeNum=3; % variation transformation logarithm; restrictmatrixM=[3     1     2     4     6     5
                 2     3     5     6     1     4
                 3     4     6     1     2     5
                 2     1     3     4     5     6
                 3     2     5     6     1     4
                 2     4     6     1     5     3]; % Job-shop machine constraint matrix; restrictmatrixT=[1     3     6    7      3     6
                 8     5     10   10     10    4
                 5     4     8     9     1     7
                 5     5     5     3     8     9
                 9     3     5     4     3     1
                 3     3     9     10    4     1]; % Job-shop time constraint matrix; % = = = = = = = = = = = = = = = PSO algorithm = = = = = = = = = = = = = = = = = = = = = = = = = = swarminit = cell (1,swarminitNum);
swarminitLong=sum(MM(2:)); % Number of all processes i.e. particle length;for i=1:swarminitNum, swarminit{i}=randomparticle(MM) ; End % Randomly generate initial particle population [POPu,s] = size(swarminit); trace = ones(1,gen); 
trace(1) = 10000; % Initial global best fitness is set to sufficientfor i = 1:s,
    bestfit(i) = 10000; % Initial individual history best fitness set to sufficiently large end bestPAR = swarminit; % individual history best particle initializationfor u=1:swarminitNum,
    fitlist=[0]; 
end
T=initT;
for step = 1:gen,
    for q=1:swarminitNum, fitlist(q)=timedecode(swarminit{q},restrictmatrixM,restrictmatrixT,machineNum) ; End % Calculate the fitness of each particle of the current particle swarm [minval,sub] = min(fitList); % to obtain the minimum fitness of this generation of particles and their subscriptsif(trace(step) > minval)  ,
         trace(step) = minval; 
         bestparticle = swarminit{sub}; 
    end
    if(step~= gen) ,
        trace(step + 1) = trace(step); % Global optimum fitness and optimum particle adjustment end T=0.97*T;
    for i = 1:s,
        tt=fitlist(i)-bestfit(i);
        if(tt<0)|(min(1.exp(-tt/T))>=rand(1.1)); bestfit(i) = fitlist(i); bestpar{i} = swarminit{i}; End end % Individual history optimal particle and fitness adjustment;for j = 1:s,
       if rand(1.1)<w1,
          bestparticle1=bianyi(bestparticle,changeNum,swarminitLong);
       elsebestparticle1=bestparticle; End % particle variation; l1=1000;
       l2=1;
       l3=1000;
       l4=1;
       while (l1-l2)>swarminitLong,
           m=fix(swarminitLong*rand(1.1));
           n=fix(swarminitLong*rand(1.1));
           l1=max(m,n)+1;
           l2=min(m,n)+1;
       end
       while (l3-l4)>swarminitLong,
           m1=fix(swarminitLong*rand(1.1));
           n1=fix(swarminitLong*rand(1.1));
           l3=max(m1,n1)+1;
           l4=min(m1,n1)+1; end swarminit{j}=cross(bestpar{j},swarminit{j},l2,l1); swarminit{j}=cross(bestparticle1,swarminit{j},l4,l3); % Particle cross;end 
end
function gant(particle,swarminitLong,restrictmatrixM,restrictmatrixT,b)
%particle= [1.0	1.0	3.0	2.0	3.0	4.0	2.0	6.0	4.0	3.0	1.0	6.0	5.0	5.0	6.0	4.0	3.0	2.0	4.0	3.0	2.0	5.0	4.0	6.0	1.0	2.0	1.0	5.0	5.0	6.0	1.0	4.0	2.0	6.0	3.0	5.0];
% restrictmatrixM=[      3     1     2     4     6     5
%                        2     3     5     6     1     4
%                        3     4     6     1     2     5
%                        2     1     3     4     5     6
%                        3     2     5     6     1     4
%                        2     4     6     1     5     3];

%restrictmatrixT=    [    1     3     6    7      3     6
%                         8     5     10   10     10    4
%                         5     4     8     9     1     7
%                         5     5     5     3     8     9
%                         9     3     5     4     3     1
%                         3     3     9     10    4     1];
%                     swarminitLong=36;
for i=1:6
    counter(i)=[1]; % position counter s(I)=[0]; % End time of last process t(I)=[0]; % The end time of a process on the machinefor j=1:swarminitLong, k=particle(j); time(k,counter(k))=restrictmatrixT(k ,counter(k)) ; % time matrix decoding machine(k,counter(k))=restrictmatrixM(k,counter(k)); % machine matrix decoding (ROM) = Max (s (k), t (machine (k) (k, counter))); s(k)=rom+time(k,counter(k)); t(machine(k,counter(k)))=rom+time(k,counter(k)); X =[ROM t(machine(k,counter(k)))]; y=[machine(k,counter(k)) machine(k,counter(k))]; x1=[t(machine(k,counter(k)))0.1 t(machine(k,counter(k)))];
    y1=[machine(k,counter(k)) machine(k,counter(k))];
    plot(x,y,'LineWidth'.7.5.'Color'.'k');
    hold on
    plot(x1,y1,'LineWidth'.7.5.'Color'.'white');
    hold on
    a=k*10+counter(k);

    text((rom+t(machine(k,counter(k))))/2- 1,machine(k,counter(k))0.5,num2str(a))  ;
    %    text((rom+t(machine(k,counter(k))))/2- 1,machine(k,counter(k))0.5,num2str(a))  ;
    hold on
    axis([0 b+5 0 7]) ;


    counter(k)=counter(k)+1   ;
end
 xlabel('time(minute)');
 ylabel('machine');
 title('Gantt chart');
Copy the code

3. Operation results

Fourth, note

Version: 2014 a