Example #1
0
 public SelectBasIndForm(int varCount, int eqCount, MsMethod method)
 {
     InitializeComponent();
     this.varCount = varCount;
     this.eqCount  = eqCount;
     this.method   = method;
     for (int i = 0; i < varCount; i++)
     {
         bool chkState = false;
         if (i < eqCount)
         {
             chkState = true;
         }
         clbBasInd.Items.Add(i, chkState);
     }
 }
Example #2
0
        private void doCalculateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (ReadData() == false)
            {
                return;
            }
            if (cbMax.Checked == false)
            {
                for (int i = 0; i < varCount; i++)
                {
                    C.Elements[0, i] *= -1;
                }
            }
            lbIters.Items.Clear();
            webBrowser1.DocumentText = "<P>Вычисления не завершены</P>";

            ExMatrix[] PsEx = new ExMatrix[varCount + 1];
            for (int j = 0; j < varCount; j++)
            {
                ExMatrix matr = new ExMatrix(eqCount + 1, 1);
                for (int i = 0; i < eqCount; i++)
                {
                    matr.Elements[i, 0] = Ps[j].Elements[i, 0];
                }
                matr.Elements[eqCount, 0] = D.Elements[0, j];
                PsEx[j] = matr;
            }
            PsEx[varCount] = new ExMatrix(eqCount + 1, 1);
            for (int i = 0; i < eqCount; i++)
            {
                PsEx[varCount].Elements[i, 0] = -b.Elements[i, 0];
            }
            PsEx[varCount].Elements[eqCount, 0] = 0;
            ExMatrix bEx = new ExMatrix(eqCount + 1, 1);

            bEx.Elements[eqCount, 0] = 1;
            ExMatrix CEx = new ExMatrix(1, varCount + 1);

            for (int j = 0; j < varCount; j++)
            {
                CEx.Elements[0, j] = C.Elements[0, j];
            }
            CEx.Elements[0, varCount] = 0;

            MsMethod         m     = new MsMethod(PsEx, bEx, CEx, 0);
            SelectBasIndForm sForm = new SelectBasIndForm(varCount + 1, eqCount + 1, m);

            if (sForm.ShowDialog() == DialogResult.Cancel)
            {
                return;
            }
            int[] basInd = sForm.GetBasInd();
            try
            {
                m.SetBasis(basInd);
                while (m.DoIteration())
                {
                    ;
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show("Вычисления прерваны: " + ex.Message,
                                "Прерывание вычислений", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
                return;
            }
            states = m.states;
            lbIters.SuspendLayout();
            for (int i = 0; i < states.Count; i++)
            {
                IterationState s       = states[i] as IterationState;
                int            iterNum = i + 1;
                string         str     = iterNum.ToString();
                if (s.isDecisionLegal)
                {
                    str += " (F = " + s.GetFuncValue().ToString() + ", допустимое решение)";
                }
                else
                {
                    str += " (F = " + s.GetFuncValue().ToString() + ", недопустимое решение)";
                }
                lbIters.Items.Add(str);
            }
            lbIters.ResumeLayout();
            webBrowser1.DocumentText  = (m.states[0] as IterationState).GetReport();
            tabControl1.SelectedIndex = 1;
            if (cbMax.Checked == false)
            {
                MessageBox.Show("Поскольку требуется минимизация, " +
                                "целевая функция была умножена на -1, и далее " +
                                "произведена максимизация",
                                "Целевая функция умножена на -1", MessageBoxButtons.OK,
                                MessageBoxIcon.Information);
            }
        }