示例#1
0
        public void TwoDim_EvaluatesCorrectValues(double[] values)
        {
            var evaluator = new StyblinskiTang(2);
            var ds        = evaluator.GetGlobalOptimum().GetDecisionSpace();
            var result    = evaluator.Evaluate(DecisionVector.CreateFromArray(ds, new[] { values[0], values[1] }));

            Assert.True(Math.Abs(values[2] - result.ElementAt(0)) < 0.001);
        }
示例#2
0
        public void TwoDim_CorrectlyIdentifiesLegalSolution()
        {
            var evaluator = new StyblinskiTang(2);
            var ds        = evaluator.GetGlobalOptimum().GetDecisionSpace();
            var legal     = evaluator.GetLegality(DecisionVector.CreateFromArray(ds, new[] { 1.0, 1.0 }));

            Assert.True(legal);
        }
示例#3
0
        public void TwoDim_CorrectlyIdentifiesIllegalSolutions()
        {
            var evaluator = new StyblinskiTang(2);
            var ds        = DecisionSpace.CreateForUniformDoubleArray(2, double.MinValue, double.MaxValue);
            var legal     = evaluator.GetLegality(DecisionVector.CreateFromArray(ds, new[] { -6.0, 2.0 }));

            Assert.False(legal);
            var legal2 = evaluator.GetLegality(DecisionVector.CreateFromArray(ds, new[] { -1.0, 7.0 }));

            Assert.False(legal2);
        }
示例#4
0
文件: Program.cs 项目: Justinius/PSO
        static void Main(string[] args)
        {
            OptimTests myGoal = new StyblinskiTang(2);// (4, 100);

            double[] lb = new double[] { -100, -100, -100, -100, -100 };
            double[] ub = new double[] { 100, 100, 100, 100, 100 };

            PSOSettings optimSettings = new PSOSettings();
            PSO         myPSO         = new PSO(optimSettings, myGoal.numDims, myGoal.goalFunc, myGoal.lbounds, myGoal.ubounds);
            double      best          = myPSO.Optimize();

            Console.WriteLine("Best: " + best);
            Console.ReadLine();

            for (int i = 0; i < myPSO.gBestHistory.Count; i++)
            {
                Console.WriteLine(i + " " + myPSO.gBestHistory[i]);
            }
            Console.ReadLine();
        }