## generate_new_population
function [retval,min1,nmin1]=generate_new_population(pop,iPXOVER,iPMUTATION)
  PXOVER=iPXOVER;        ## probability of crossover;
  PMUTATION=iPMUTATION;  ## proportion of mutated variables
   x=pop.x;
   y=pop.y;
   nx=length(pop);
   for i=1:nx
    xx=pop(i).id;
    id1(i,:)=xx;
   endfor
[pop1,min,nmin]=set_population(x,y,id1,nx);
pop1(1)=pop(nmin);
 for i=2:nx
    ## get parent # 1
    while 1
       n1=int64(nx*rand);
       if n1==0 
         n1=1;
       endif
       xxx=pop(n1).RFitness;
       if xxx<PXOVER
         break;
       endif
    endwhile
    ## get parent # 2
    while 1 
       n2=int64(nx*rand);
       if n2==0 
         n2=1;
       endif
       xxx=pop(n2).RFitness;
       if xxx<PXOVER
         break;
       endif
    endwhile
    ## now cross corrolate parents to create a child
      id_child=int_cross_over(pop(n1).id,pop(n2).id);
      ## There are some mutation possibility in here
      if rand<PMUTATION
        id_childm=int_mutate(id_child);
      else
        id_childm=id_child;
      end
    pop1(i)=set_integer_genotype(x,y,id_childm,i);  
 endfor  #for i=1:nx
 total=0.0;
 min1=min;
 nmin1=nmin;
 for i=1:nx
    xx=pop1(i).z;
    if xx<min1
      min1=xx;
      nmin1=pop1(i).no;
    endif
    total=total+xx ;
  endfor
  for i=1:nx
    pop1(i).RFitness= pop1(i).z/total;
  endfor
   min 
   nmin 
   min1 
   nmin1 
 retval=pop1;
endfunction