Generating Populations for GAs: popgen()

 
//***************************************************
//Function to generate automatically a population with random values
// Input:
// l := length of strings
// n := size of population
// Output:
// A population according to the above defined format
//

function[POPX]=popgen(n,l)
  
  //Generate a matrix with only '0's
  
  POPX = zeros(n,l)
  MaxCells = n*l
  
  // Distribute randomly '1's
  
  for i=1:n
    for j=1:l
      if( rand() < 0.5 ) then POPX(i,j) = 0, else POPX(i,j) = 1, end
    end
    end
         
       endfunction



Gerd Doeben-Henisch 2013-01-14