# create a dataframe for selection 
sel_df <- pop_df

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

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


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

n_even <- floor(nrow(sel_df) / 2) * 2      # make sure pairs are even by removing lowest individual
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),]
index25_crossPlan <- rbind(cbind(as.character(pairs[,1]), as.character(pairs[,2])))

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

F1index25 <- makeCross(DH, index25_crossPlan, simParam=SP)
DHindex25 <- makeDH(F1index25, nDHProdDev)
df_index25 <- data.frame(DHindex25@gv[,-1], strat = "index0.25")
f1_index25 <- data.frame(F1index25@gv[,-1], strat = "index0.25")

