function pop = read_mlppop(fname)
% Read into a population structure from a result file

% Initialize with "0 objectives" to keep track of sanity below.
pop.nobj = 0;

iind = 0;

fid = fopen(fname);
while 1
  tline = fgetl(fid);
  if ~ischar(tline) break; end;
  iind = iind + 1;

  repr = sscanf(tline,'%f');

  % General multiobjective part of the representation:
  pop.id(iind)     = repr(1); % "running index / unique ID"
  pop.rank(iind)   = repr(2); % "domination rank within population"
  pop.constr(iind) = repr(3); % "constraint violation"
  pop.crowd(iind)  = repr(4); % "crowding / niching measure"
  
  if ((pop.nobj > 0) && (repr(5) ~= pop.nobj))
    error('Number of objectives on line %s:%d is %d. Expected %d.', ...
	  fname, iind, repr(5), pop.nobj);
  end
  pop.nobj        = repr(5);  % "number of objectives"
  pop.obj(iind,:) = repr(6:6+pop.nobj-1); % "objective vector"
  
  % MLP-specific part of the representation:
  pop.net{iind}   = decode_jyu_mlp(repr((6+pop.nobj):end));
end
pop.size = iind;

fclose(fid);
