Code covered by the BSD License  

Highlights from
Speeding Up Optimization Problems with Parallel Computing

image thumbnail

Speeding Up Optimization Problems with Parallel Computing

by

 

Files from the webinar: Speeding up optimization problems with parallel computing

Editor's Notes:

This file was selected as MATLAB Central Pick of the Week

generateinitpopNcK(n,k)
function initPop = generateinitpopNcK(n,k)
% Oren Rosen
% 4/1/2008
% Copyright 2008 The MathWorks, Inc.
%
% This function is used for the N-choose-K bit-string genetic algorithm.
% It is used to generate a simple and regular initial population.
% For example, if n=10 and k=5 it will generate the following matrix of
% bit-strings:
%
% [ 1 1 1 1 1 0 0 0 0 0
%   0 1 1 1 1 1 0 0 0 0
%   0 0 1 1 1 1 1 0 0 0
%   0 0 0 1 1 1 1 1 0 0
%   0 0 0 0 1 1 1 1 1 0
%   0 0 0 0 0 1 1 1 1 1 ]
%
% As a consequence of the structure - there will be exactly n-k+1
% individuals in each population.
% 
% This implementation was a quick and intuitive way to structure this
% function. It is by no means optimized and the end user is encouraged to
% experiment with other methods.

initPop = zeros(n-k+1,n);

for i=1:n-k+1
    initPop(i,i:i+k-1) = 1;
end

Contact us