Beispiel #1
0
        public void MinResultTest()
        {
            var           functionConstraint = new[] { "4x1 + 9x2", "11x1 + 3x2 <= 45", "4x1 + 3x2 <= 24", "4x1 + 15x2 <= 48" };
            SimplexMethod optimize           = new SimplexMethod(functionConstraint);
            var           result             = optimize.SimplexCalculate();

            Assert.AreEqual(34.353, Math.Round(result, 3));
        }
Beispiel #2
0
        public void MaxResultTest()
        {
            var           functionConstraint = new[] { "2x1+4x2+x3", "x1+x2+2x3>=500", "10x1+8x2+5x3>=2000", "2x1+x2>=100" };
            SimplexMethod optimize           = new SimplexMethod(functionConstraint);
            double        result             = optimize.SimplexCalculate();

            Assert.AreEqual(400, result);
        }
Beispiel #3
0
        public void ExpMinResultTest()
        {
            try
            {
                var           functionConstraint = new[] { "4x1 + 9x2", "11x1 + 3x2 >= 45", "4x1 + 3x2 <= 24", "4x1 + 15x2 <= 48" };
                SimplexMethod optimize           = new SimplexMethod(functionConstraint);
                var           result             = optimize.SimplexCalculate();
            }
            catch (Exception ex)

            {
                Assert.AreEqual("Неправильное выражение для нахождения максимума (11x1 + 3x2 >= 45)", ex.Message);
            }
        }
Beispiel #4
0
        private void BtStart_OnClick(object sender, RoutedEventArgs e)
        {
            double lambda;

            if (!string.IsNullOrEmpty(TbLambda.Text))
            {
                lambda = double.Parse(TbLambda.Text);
            }
            else
            {
                MessageBox.Show("Введите λ");
                return;
            }
            TbResult.Text += $"Критерий Байеса: {Criterions.Bayes(_table, _p).index} Выигрыш {Criterions.Bayes(_table, _p).win}\r\n";
            TbResult.Text += $"Критерий Вальда: {Criterions.Wald(_table).index} Выигрыш {Criterions.Wald(_table).win} \r\n";
            TbResult.Text += $"Критерий Сэвиджа: {Criterions.Savage(AT(_table)).index} Выигрыш {Criterions.Savage(AT(_table)).win} \r\n";
            TbResult.Text += $"Критерий Гурвица: {Criterions.Hurwitz(_table,lambda).index} Выигрыш {Criterions.Hurwitz(_table, lambda).win} \r\n";
            var sm = new SimplexMethod(_table);

            TbResult.Text      += $"Цена игры: {sm.GamePriceA}\r\n";
            TbResult.Text      += $"Стратегия игрока A: {string.Join("\t", sm.ResultsA.Select(x => (x * sm.GamePriceA).ToString("0.#####")))}\r\n";
            BtStartEx.IsEnabled = true;
        }
Beispiel #5
0
        static void Main(string[] args)
        {
            Console.WriteLine("Численные методы многомерной оптимизации.");
            Console.WriteLine();

            Console.WriteLine("1. Метод случайного поиска ");
            Console.WriteLine("Найти безусловный минимум функции f(x,y) = x^2 + y^2. ");
            Console.WriteLine();
            Logic a = new Logic();

            a.randomSearchMethod();

            Console.WriteLine();
            Console.WriteLine("2. Симплексный метод ");
            Console.WriteLine("Вычислить оптиму при заданных ограничениях и целевой функции. ");
            Console.WriteLine();

            SimplexMethod b = new SimplexMethod();

            b.mySimplex();

            Console.ReadKey();
        }
Beispiel #6
0
        public void SimplexMethodUniversalResult()
        {
            FS.VecB    = new double [] { 200f, 1000f, 900f, 5000f };
            FS.MatrixA = new double [, ] {
                { 1f, 0f, 1f, 2.5f }, { 0f, 1f, 1f, 6f }
            };
            FS.VecC = new double [] { 24, 24 };
            FS.Znak = new string [] { "<", "<", ">", "=" };
            var result = FS.StartProgram();

            //Проверка Z
            Assert.AreEqual((double)result [3], 21600, 1);
            //Проверка итоговых значений X
            Array.Sort((Int32 [])result [4]); //просто в начале нужно указать интересующие Х
            Int32 [] testRes = new [] { 0, 0, 1, 2 };
            Assert.AreEqual(result [4], testRes);
            var expected = (double [])result [1];
            var actual   = new double [] { 85.66, 214.34, 114.34, 785.66 };

            for (int ex = 0; ex < expected.Length; ex++)
            {
                Assert.AreEqual(expected [ex], actual [ex], 1);
            }

            FS.VecB    = new double [] { 800, 700, 500, 400, 1900, 10545 };
            FS.MatrixA = new double [, ]
            {
                { 1, 0, 0, 0, 1, 1.95 },
                { 0, 1, 0, 0, 1, 5.15 },
                { 0, 0, 1, 0, 1, 5 },
                { 0, 0, 0, 1, 1, 5.55 }
            };
            FS.VecC = new double [] { 11.52, 71.07, 52.8, 59.25 };
            FS.Znak = new string [] { "<", "<", "<", "<", ">", "=" };
            result  = FS.StartProgram();

            //Проверка Z
            Assert.AreEqual((double)result [3], 103305, 1);
            //Проверка итоговых значений X
            Array.Sort((Int32 [])result [4]); //просто в начале нужно указать интересующие Х
            testRes = new [] { 0, 0, 1, 2, 3, 4 };
            Assert.AreEqual(result [4], testRes);
            expected = (double [])result [1];
            actual   = new double [] { 500, 700, 500, 400, 300, 1635 };
            for (int ex = 0; ex < expected.Length; ex++)
            {
                Assert.AreEqual(expected [ex], actual [ex], 1);
            }

            FS.VecB    = new double [] { 800, 700, 500, 400, 1900, 10545 };
            FS.MatrixA = new double [, ]
            {
                { 1, 0, 0, 0, 1, 1.95 },
                { 0, 1, 0, 0, 1, 5.15 },
                { 0, 0, 1, 0, 1, 5 },
                { 0, 0, 0, 1, 1, 5.55 }
            };
            FS.VecC = new double [] { 21.27, 71.07, 52.8, 59.25 };
            FS.Znak = new string [] { "<", "<", "<", "<", ">", "=" };
            result  = FS.StartProgram();

            //Проверка Z
            Assert.AreEqual((double)result [3], 106230, 1);
            //Проверка итоговых значений X
            Array.Sort((Int32 [])result [4]); //просто в начале нужно указать интересующие Х
            testRes = new [] { 0, 0, 1, 2, 3, 4 };
            Assert.AreEqual(result [4], testRes);
            expected = (double [])result [1];
            actual   = new double [] { 500, 700, 500, 400, 300, 1635 };
            for (int ex = 0; ex < expected.Length; ex++)
            {
                Assert.AreEqual(expected [ex], actual [ex], 1);
            }

            FS.VecB    = new Double [] { 1700, 1600 };
            FS.MatrixA = new Double [, ]
            {
                { 3, 2 },
                { 4, 5 },
            };
            FS.VecC = new double [] { -2, -4 };
            FS.Znak = new string [] { "<", "<" };
            result  = FS.StartProgram();

            //Проверка Z
            Assert.AreEqual((double)result [3], -1400, 1);
            //Проверка итоговых значений X
            Array.Sort((Int32 [])result [4]); //просто в начале нужно указать интересующие Х
            testRes = new [] { 1, 2 };
            Assert.AreEqual(result [4], testRes);

            expected = (double [])result [1];
            actual   = new double [] { 300, 200 };
            for (int ex = 0; ex < expected.Length; ex++)
            {
                Assert.AreEqual(expected [ex], actual [ex], 1);
            }
        }