Esempio n. 1
0
        /// <summary>Serves as unit test for <see cref="PraxisOptimizer"/> with respect to a quadratic test function with several constraints.
        /// </summary>
        public void FindMinimum_QuadraticTestFunction2WithConstraints_AnalyticResult()
        {
            /* Constraints:
             * x_0 + x_1 + x_2 >= 6,
             * -x_0 - x_1 + 2* x_2 >= 2,
             * x_0, x_1, x_2  >= 0,
             * */

            var optimizer = new PraxisOptimizer(CreateStubRandomNumberStream(), PraxisOptimizerAbortCondition.Create(requiredNumberOfAcceptedPoints: 100), MultiDimOptimizerConstraintProvider.QuadraticPenalty);

            var boxConstraint        = optimizer.Constraint.Create(MultiDimRegion.Interval.Create(3, new[] { 0.0, 0.0, 0.0 }, new[] { Double.NaN, Double.NaN, Double.NaN }));
            var inequalityConstraint = optimizer.Constraint.Create(new MultiDimRegion.LinearInequality(new DenseMatrix(3, 2, new[] { 1.0, 1.0, 1.0, -1.0, -1.0, 2.0 }), new[] { 6.0, 2.0 }));

            var algorithm = optimizer.Create(boxConstraint, inequalityConstraint);

            var A = new DenseMatrix(3, 3, new[] { 2.0, 1.0, 0.0, 1.0, 4.0, 2.0, 0.0, 2.0, 4.0 });
            var b = new[] { 4.0, 6.0, 12.0 };

            algorithm.Function = optimizer.Function.Create(3, x => 0.5 * DenseMatrix.GetBilinearForm(A, x) + BLAS.Level1.ddot(3, x, b));

            var    actualArgMin = new[] { 3.3333, 0.0001, 2.66 };
            double actualMinimum;

            var state = algorithm.FindMinimum(actualArgMin, out actualMinimum);

            var expectedArgMin  = new[] { 3 + 1.0 / 3.0, 0.0, 2 + 2.0 / 3.0 };
            var expectedMinimum = 70.666666666666666;

            Assert.That(actualMinimum, Is.EqualTo(expectedMinimum).Within(1E-7), String.Format("State: {0}; actual Minimum: {1}; expected Minimum: {2}; actual argMin: [{3}; {4}]; expected argMin: [{5}; {6}].", state, actualMinimum, expectedMinimum, actualArgMin[0], actualArgMin[1], expectedArgMin[0], expectedArgMin[1]));
            Assert.That(actualArgMin, Is.EqualTo(expectedArgMin).AsCollection.Within(1E-7), String.Format("State: {0}; actual Minimum: {1}; expected Minimum: {2}; actual argMin: [{3}; {4}]; expected argMin: [{5}; {6}].", state, actualMinimum, expectedMinimum, actualArgMin[0], actualArgMin[1], expectedArgMin[0], expectedArgMin[1]));
        }
Esempio n. 2
0
 /// <summary>Initializes the <see cref="PraxisOptimizer" /> class.
 /// </summary>
 static PraxisOptimizer()
 {
     StandardAbortCondition     = PraxisOptimizerAbortCondition.Create();
     StandardConstraintProvider = MultiDimOptimizerConstraintProvider.BoxTransformation;
 }