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 });

            formTables.UpdateGrid();
        }
Beispiel #2
0
        private void графическийМетодToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //dataGridView1[2, 2] = new Fraction(21 / 24);
            //return;

            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.Exclamation, MessageBoxDefaultButton.Button1);
                return;
            }

            #region specialno dlya djema))) podrobnosti

            richTextBox1.Text += " ---===== Детали ====--- " + "\r\n";
            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
                    ) + "\r\n";
            }

            // 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
                ) + "\r\n";

            #endregion

            formTables.UpdateGrid();
        }