# create a dataframe for selection 
sel_df <- pop_df

# Calculate the index 
sel_df$index <- sel_df$main_effect - wt*sel_df$rot_rmsd_kmax

# rank IDs by the index
sel_df <- sel_df[order(-sel_df$index),]


#------ Select pairs for product development (best to best) ----------- 

n_even <- floor(nrow(sel_df) / 2) * 2      # make sure pairs are even by removing lowest individaul
pairs <- data.frame(
 id1 = sel_df$id[seq(1, n_even, by = 2)],
 id2 = sel_df$id[seq(2, n_even, by = 2)]
  )
  
pairs <- pairs[1:(nPairsProdDev),]
index_crossPlan <- rbind(cbind(as.character(pairs[,1]), as.character(pairs[,2])))

#---- Make PD population and record GVs in a dataframe ----

F1index <- makeCross(DH, index_crossPlan, simParam=SP)
DHindex <- makeDH(F1index, nDHProdDev)
df_index <- data.frame(DHindex@gv[,-1], strat = "index1.0")
f1_index <- data.frame(F1index@gv[,-1], strat = "index1.0")

