public Design Mutate(MathNet.Numerics.Distributions.IContinuousDistribution dist, double rate)
        {
            Design copy = (Design)this.DesignClone();

            // loop over all the design variables
            foreach (DesignVar var in copy.DesignVariables)
            {
                var.Mutate(rate, dist);
            }

            copy.CheckConstraints();
            return(copy);
        }
        private double GetDistance(Design s1, Design s2)
        {
            double dist = 0;

            for (int i = 0; i < s1.DesignVariables.Count; i++)
            {
                double var1 = s1.DesignVariables[i].Value;
                double var2 = s2.DesignVariables[i].Value;
                double sq   = Math.Pow((var1 - var2), 2);
                dist += sq;
            }
            dist = Math.Sqrt(dist);
            return(dist);
        }
 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;
        }
        public bool IsDiverse(List <IDesign> existing, IDesign candidate, double rate)
        {
            this.Best         = existing;
            this.Candidate    = (Design)candidate;
            this.MutationRate = rate;

            double diff = this.GetDiffSize();

            foreach (Design s in this.Best)
            {
                double dist = GetDistance(s, Candidate);
                if (dist < diff)
                {
                    return(false);
                }
            }
            return(true);
        }