C# PSO particle swarm optimization algorithm genetic algorithm random algorithm to solve the maximum and minimum values of complex equations

You can define complex equations by yourself. The following is to look at other people's questions and then do it yourself.
Insert image description here
The following are the calculation results.

Insert image description here

private void GetMinResult(out double resultX1, out double min)
        {
    
    
            double x1, result;
            Random random1 = new Random(DateTime.Now.Millisecond* DateTime.Now.Second);
            min = 999999;
            resultX1 = 0;
            for (int i = 0; i < 654321; i++)
            {
    
    
                if (random1.Next(0, 100) % 2 == 0)
                {
    
    
                    x1 = resultX1 + random1.NextDouble()*100;

                }
                else
                {
    
    
                    x1 = resultX1 - random1.NextDouble()*100;
                }
                if (x1 < 0 || x1 > 50)
                {
    
    
                    continue;
                }
                result = x1 * Math.Sin(x1) * Math.Cos(2 * x1) - 2 * x1 * Math.Sin(3 * x1) + 3 * x1 * Math.Sin(4 * x1);
                if (result < min)
                {
    
    
                    resultX1 = x1;
                    min = result;
                }
            }
        }

Guess you like

Origin blog.csdn.net/qq_34677276/article/details/132696765