public static Design Crossover(Design d, List<Design> seeds)
        {
            Design crossed = d.DesignClone();

            // if no parents are selected, crossover does not occur
            if (seeds == null || seeds.Count == 0)
            {
                return crossed;
            }

            // otherwise, return a crossover of all the parent seeds
            else
            {
                for (int i = 0; i < d.DesignVariables.Count; i++)
                {
                    DesignVar var = crossed.DesignVariables[i];
                    List<DesignVar> seedvars = new List<DesignVar>();

                    foreach (Design s in seeds)
                    {
                        seedvars.Add(s.DesignVariables[i]);
                    }

                    var.Crossover(seedvars);
                }

                return crossed;
            }
        }
        public static Design GenerateDesign(Design myFirstDesign, List<Design> seeds, IContinuousDistribution dist, double rate)
        {
            // generate new design through crossover of parent seeds
            Design copy = myFirstDesign.DesignClone();
            Design design = Crossover(copy, seeds);

            // mutate new structure
            Design newDesign= Mutate(design, dist, rate);
            return newDesign;
        }
 public static List<Design> NewGeneration(Design myFirstDesign, List<Design> seeds, IContinuousDistribution dist, int popsize, double rate) 
 {
     // generate new generation
     List<Design> Designs = new List<Design>();
     int count = 0;
     while (count < popsize)
     {
         // generate random new design
         Design randDesign = GenerateDesign( myFirstDesign, seeds, dist, rate);
         count++;
         Designs.Add(randDesign.DesignClone());
     }
     return Designs;
 }
        public static Design Mutate(Design d, IContinuousDistribution dist, double rate)
        {
            Design copy = d.DesignClone();
            List<DesignVar> newdvars = new List<DesignVar>();
            // loop over all the design variables

            foreach (DesignVar var in copy.DesignVariables)
            {
                DesignVar varcopy = var.VarClone();
                varcopy.Mutate(rate, dist);
                varcopy.FixConstraint();
                newdvars.Add(varcopy);
            }
            copy.DesignVariables = newdvars;
            return copy;
        }