Exemplo n.º 1
0
        /// <summary>
        /// Expanded pont kiszámítása
        /// </summary>
        /// <param name="reflected"></param>
        /// <param name="centroid"></param>
        /// <returns></returns>
        private BaseElement Expanded(BaseElement reflected, BaseElement centroid)
        {
            var parameter = new ArrayList();

            for (int p = 0; p < InitialParameters.Count; p++)
            {
                parameter.Add((gamma * (double)reflected[p]) + ((1 - gamma) * (double)centroid[p]));
                if ((double)parameter[p] > (double)UpperParamBounds[p])
                {
                    parameter[p] = UpperParamBounds[p];
                }
                else if ((double)parameter[p] < (double)LowerParamBounds[p])
                {
                    parameter[p] = LowerParamBounds[p];
                }
                if (Integer[p])
                {
                    parameter[p] = Math.Round((double)parameter[p]);
                }
            }
            return((BaseElement)GetNewElement(FitnessFunction, parameter));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Contracted pont kiszámítása
        /// </summary>
        /// <param name="centroid"></param>
        /// <returns></returns>
        private BaseElement Contracted(BaseElement centroid)
        {
            var parameter  = new ArrayList();
            var worstParam = ((BaseElement)Elements[NumberOfElements - 1]).Position;

            for (int p = 0; p < InitialParameters.Count; p++)
            {
                parameter.Add((beta * (double)worstParam[p]) + ((1 - beta) * (double)centroid[p]));
                if ((double)parameter[p] > (double)UpperParamBounds[p])
                {
                    parameter[p] = UpperParamBounds[p];
                }
                else if ((double)parameter[p] < (double)LowerParamBounds[p])
                {
                    parameter[p] = LowerParamBounds[p];
                }
                if (Integer[p])
                {
                    parameter[p] = Math.Round((double)parameter[p]);
                }
            }
            return((BaseElement)GetNewElement(FitnessFunction, parameter));
        }
Exemplo n.º 3
0
        protected override void CreateNextGeneration()
        {
            BaseElement centroid  = Centroid();
            BaseElement reflected = Reflected(centroid);

            if (reflected.Fitness < ((BaseElement)Elements[0]).Fitness)
            {
                BaseElement expanded = Expanded(reflected, centroid);
                if (expanded.Fitness < ((BaseElement)Elements[0]).Fitness)
                {
                    ReplaceWorst(expanded);
                }
                else
                {
                    ReplaceWorst(reflected);
                }
            }
            if (IsWorseThanAllButWorst(reflected))
            {
                if (reflected.Fitness <= ((BaseElement)Elements[NumberOfElements - 1]).Fitness)
                {
                    ReplaceWorst(reflected);
                }
                BaseElement contracted = Contracted(centroid);
                if (contracted.Fitness < ((BaseElement)Elements[0]).Fitness)
                {
                    ReplaceWorst(contracted);
                }
                else
                {
                    Shrink();
                }
                return;
            }
            ReplaceWorst(reflected);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Legrosszab érték beállítása és az egyedek rendezése
 /// </summary>
 /// <param name="newSolution"></param>
 private void ReplaceWorst(BaseElement newSolution)
 {
     Elements[NumberOfElements - 1] = newSolution;
     Elements.Sort();
 }