function Cruces=crosspoint_cervezafix(t,pop1,pop2,ind_str,n)

% CROSSPOINT_CERVEZAFIX	It obtains a fixed number of crossing points for population of variable length
% 
% CROSSP=CROSPOINT_CERVEZAFIX(T,POP1,POP2,IND_STR,N)
%
% It divides each individual in POP1 and POP2, cell matrix with chromosomes of variable lenght delimited by [MIN,MAX], 
% by a maximum of N points, which are selected radomly for each individual. The number of crossing points for the k
% pair of parents is min(min(length(pop1{k}),length(pop2{k}))-1,N)
% The crossing point are returned in the CROSSP cell matrix where cross{k}=[crossp for the first parent; crossp for the
% second parent]
%  T is not used but is provided to let the GA_CROSS function use this funtion as a crossing-point method. 
% IND_STR is the individual structure that defines the population, and in IND_STR.GNUMBER the MIN and MAX values are
% defined.
%
% See also GA_CROSS, IS_NEW, 

% APRENDIZAJE AUTOMÁTICO (G. Pajares y J. M. de la Cruz, Eds.)
% Editorial: RA-MA
% Capítulo 9: El Aprendizaje con Algoritmos Genéticos
% Autores: Bonifacio de Andres y Toro


param=is_fields(ind_str,3);
param=param_use(param{1});

limits=param{1};
PasoTiempo=param{3};
[r,c]=size(pop1);
Cruces=cell(r,1);
randaux=rand(2,n*r);
randsort=rand(2,(n+1)*r);
nplus=n+1;
for i=1:r
   l1=(sum(pop1{i}(2,:))/PasoTiempo)-nplus;	% Le quito para asegurar que todos tienen al menos 1
   l2=(sum(pop2{i}(2,:))/PasoTiempo)-nplus;  %
   newval=zeros(1,n+1);
   [lsort,order]=sort([l1,l2]);
   lmin=lsort(1);
   for j=1:n
      if lmin==0
         break
      end
      newval(j)=round(randaux(1,(i-1)*n+j)*lmin);
      lmin=lmin-newval(j);
   end
   if lmin
      newval(end)=lmin;
   end
   newval=newval+1;
   [aaa,ind]=sort(randsort(1,1+(i-1)*nplus:i*nplus));
   newval=newval(ind);
   cruc=[newval;newval];
   cruc(order(2),end)=cruc(order(2),end)+lsort(2)-lsort(1);
   Cruces{i}=cruc*PasoTiempo;
end




