Beispiel #1
0
        private void оптимизироватьToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                DowndateGrid();
            }
            catch
            {
                return;
            }

            Fraction F;

            Fraction[]    solution;
            SimplexSolver solver = new SimplexSolver();

            solver.DebugNewSimplexTable += new SimplexSolver.DebugSimplexTableHandler(solver_DebugNewSimplexTable);
            formTables = null;

            for (int i = 0; i < m; i++)
            {
                solver.AddLimtation(A[i], S[i], B[i]);
            }
            solver.SetTargetFunctionCoefficients(C);

            // решаем
            solution = solver.Solve();

            F = 0;
            for (int i = 0; i < C.Length; i++)
            {
                F += C[i] * solution[i];
            }

            formTables.AddLine("Решение (max):", solution);
            formTables.AddLine("Значение Fmax:", new Fraction[] { F });

            // переделываем под минимизацию
            for (int i = 0; i < C.Length; i++)
            {
                C[i] = -C[i];
            }
            solver.SetTargetFunctionCoefficients(C);

            formTables.ResetIterationCounter();

            // снова решаем
            solution = solver.Solve();

            F = 0;
            for (int i = 0; i < C.Length; i++)
            {
                F -= C[i] * solution[i];
            }

            formTables.AddLine("Решение (min):", solution);
            formTables.AddLine("Значение Fmin:", new Fraction[] { F });
        }
Beispiel #2
0
 void solver_DebugNewSimplexTable(int[] basisJ, Fraction[] c, Fraction[,] table)
 {
     if (formTables == null)
     {
         formTables = new FormSTables();
     }
     formTables.AddTable(basisJ, c, table);
     formTables.Show();
 }
Beispiel #3
0
        void solver_DebugGaussProcessMatrix(Fraction[,] matrix)
        {
            if (formTables == null)
            {
                formTables = new FormSTables();
            }

            formTables.AddTable(matrix);
            formTables.Show();
        }
Beispiel #4
0
        private void выделитьБазисМатрицыAToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                DowndateGrid();
            }
            catch
            {
                return;
            }

            int maxJ = 0;

            for (int i = 0; i < A.Length; i++)
            {
                if (A[i].Length > maxJ)
                {
                    maxJ = A[i].Length;
                }
            }
            Fraction[,] a = new Fraction[A.Length, maxJ];
            for (int i = 0; i < A.Length; i++)
            {
                for (int j = 0; j < A[i].Length; j++)
                {
                    a[i, j] = A[i][j];
                }
            }


            if (formTables == null)
            {
                formTables = new FormSTables();
            }

            formTables.AddTable(a);
            for (uint i = 0; i < (a.GetLength(0) < a.GetLength(1) ? a.GetLength(0) : a.GetLength(1)); i++)
            {
                SimplexSolver.GGaussProcess(ref a, i, i);
                formTables.AddTable(a);
            }

            formTables.Show();
        }
Beispiel #5
0
        private void графическийМетодToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                DowndateGrid();
            }
            catch
            {
                MessageBox.Show("Input error!");
                return;
            }

            if (df != null)
            {
                df.RemoveAllGraphics();
            }

            richTextBox1.Text = "";

            GraphicSolver solver = new GraphicSolver();

            solver.DebugPolygon            += new GraphicSolver.DebugPolygonEventHandler(solver_DebugPolygonEvent);
            solver.DebugMaxMinPts          += new GraphicSolver.DebugMaxMinEventHandler(solver_DebugMaxMin);
            solver.DebugMaxSolution        += new GraphicSolver.DebugExtremumEventHandler(solver_DebugMaxSolution);
            solver.DebugMinSolution        += new GraphicSolver.DebugExtremumEventHandler(solver_DebugMinSolution);
            solver.DebugGaussProcessMatrix += new GraphicSolver.DebugGaussProcessMatrixHandler(solver_DebugGaussProcessMatrix);

            for (int i = 0; i < A.Length; i++)
            {
                solver.AddLimtation(A[i], S[i], B[i]);
            }
            solver.SetTargetFunctionCoefficients(C);

            //solver_DebugGaussProcessMatrix((Fraction[,])A);
            formTables = new FormSTables();

            try
            {
                solver.Solve();
            }
            catch (InvalidOperationException exc)
            {
                MessageBox.Show(exc.Message, "Error",
                                MessageBoxButtons.OK, MessageBoxIcon.Stop);
                return;
            }

            #region specialno dlya djema))) podrobnosti

            richTextBox1.Text += " ---===== Детали ====--- " + Environment.NewLine;
            for (int i = 0; i < m; i++)
            {
                richTextBox1.Text += string.Format(
                    " x{0} = {1}·x1 {2} {3}·x2 {4} {5}",       // x3 = 4/5·x1 + 1/2·x2 - 7/5
                    i + 1,                                     // 0
                    -solver.A[i, 1],                           // 1
                    Math.Sign(-solver.A[i, 2]) < 0 ? "" : "+", // 2
                    -solver.A[i, 2],                           // 3
                    Math.Sign(solver.A[i, 0]) < 0 ? "" : "+",  // 4
                    solver.A[i, 0]                             // 5
                    ) + Environment.NewLine;
            }

            // F(x1,x2) = c1x1 + c2x2 + d
            richTextBox1.Text += string.Format(
                " F = {0}·x1 {1} {2}·x2 {3} {4}",    // e.g.: F = 4/5·x1 + 1/2·x2 - 7/5
                solver.C1,                           // 0
                Math.Sign(solver.C2) < 0 ? "" : "+", // 1
                solver.C2,                           // 2
                Math.Sign(solver.D) < 0 ? "" : "+",  // 3
                solver.D                             // 4
                ) + Environment.NewLine;

            #endregion
        }