示例#1
0
        public void TheBisectionAlgorithmTest()
        {
            var func = new FunctionDefinition("f(x1,x2) = (x1)^2 + 2*(x2)^2 - 6*x1 + x1*x2");
            var D    = new List <double> {
                1, 0
            };
            var point     = new Point("0,0");
            var beta      = 0.4;
            var tauR      = 9;
            var epsilon   = 0.00001;
            var algorithm = new TheBisectionAlgorithmWithGoldsteinTwoSidedTest
                                (func, point, D, tauR, beta, epsilon);
            var result    = algorithm.Run();
            var expected0 = 6;
            var expected1 = 0;

            if (Math.Abs(result.ListOfVariables[0] - expected0) <= epsilon && Math.Abs(result.ListOfVariables[1] - expected1) <= epsilon)
            {
                Assert.True(true);
            }
            else
            {
                Assert.False(true);
            }
        }
示例#2
0
        public void TheBisectionAlgorithmTestV2()
        {
            var func  = new FunctionDefinition("f(x1,x2) = 2*(x1)^2+(x2)^2 -2*x1*x2");
            var point = new Point("2,3");
            var D     = MathUtility.Gradient(func, point);

            D = MathUtility.DirectionD(D);
            var beta      = 0.25;
            var tauR      = 0.1;
            var epsilon   = 0.00001;
            var algorithm = new TheBisectionAlgorithmWithGoldsteinTwoSidedTest
                                (func, point, D, tauR, beta, epsilon);

            Assert.Throws <InvalidTauException>(() => algorithm.Run());
        }