%new_c1=crossover(parent1,parent2,prob,sigma)
%Purpose: combine two propensities into one new propensity with a chance of mutation for each individual propensity value
%Parameters: parent1 and parent2 are two sets of propensities that will be combined, mut is the chance that each propensity value has of being mutated and sigma is the scale of the distribution the mutation comes from
%Returns: new_c1, a new set of propensities made from the combination of parent1 and parent2
%Author: Jacob Miller 

function new_c1=crossover(parent1,parent2,mut,sigma)

%Create a random point along the length of a parent
midpoint=randi(length(parent1));

%new_c1 will hold the childs propensities and be returned by the function
new_c1=[];

%Loop through the length of a parent to create propensities for child, one propensity at a time
for i=1:length(parent1)
  
  %If still before midpoint, use parent1's propensity at that index, otherwise use parent2's
  if (i<midpoint)
    add=parent1(i);
  else
    add=parent2(i);
  end
  
  %If a random value between 0 and 1 is below mut
  if (mut<rand(1,1))
    
    %Add a value taken from normal distribution centered at zero with sd of sigma
%     add+=normrnd(0,sigma);
    add = add+normrnd(0,sigma);
    %Make sure each new propensity is between 0 and 1
    if (add<0)
      add=0;
    elseif (add>1)
      add=1;
    end
  end
  %add new propensity value to new_c1 array
  new_c1(end+1)=add;
end
end