コード例 #1
0
ファイル: Form1.cs プロジェクト: ilyichumakov/FlowTask
        private void критическиеПутиToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int[][] matrix = initial2Ddata();

            Flows.FlowAlgorythms g = new Flows.FlowAlgorythms(new Graph(matrix));

            Tuple <int[], int[]> res = g.CriticalPath();
            string path = String.Join(", ", res.Item1);
            string time = String.Join(", ", res.Item2);

            LabelState.Text = "Критический путь: " + path + Environment.NewLine + "Старт каждой работы: " + time;
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: ilyichumakov/FlowTask
        private void максимальныйПотокToolStripMenuItem_Click(object sender, EventArgs e)
        {
            int[][] matrix = initial2Ddata();

            int count = matrix.GetUpperBound(0) + 1;

            for (int i = 0; i < count; i++)
            {
                for (int j = 0; j < count; j++)
                {
                    if (matrix[i][j] == Int32.MaxValue)
                    {
                        matrix[i][j] = 0;
                    }
                }
            }

            string title = "Максимальный поток";

            Graph g = new Graph(matrix);

            Flows.FlowAlgorythms alg = new Flows.FlowAlgorythms(g);

            Form prompt = new Form()
            {
                Width           = 200,
                Height          = 250,
                FormBorderStyle = FormBorderStyle.FixedDialog,
                Text            = title,
                StartPosition   = FormStartPosition.CenterScreen
            };
            Label fromLabel = new Label()
            {
                Left = 20, Top = 20, Text = "Из"
            };
            TextBox from = new TextBox()
            {
                Left = 60, Top = 20, Width = 100
            };
            Label textLabel = new Label()
            {
                Left = 20, Top = 50, Text = "В"
            };
            TextBox to = new TextBox()
            {
                Left = 60, Top = 50, Width = 100
            };
            Button confirmation = new Button()
            {
                Text = "Ok", Left = 50, Width = 100, Top = 160, DialogResult = DialogResult.OK
            };

            confirmation.Click += (sendr, evt) => { prompt.Close(); };
            prompt.Controls.Add(from);
            prompt.Controls.Add(to);
            prompt.Controls.Add(confirmation);
            prompt.Controls.Add(fromLabel);
            prompt.Controls.Add(textLabel);
            prompt.AcceptButton = confirmation;
            if (prompt.ShowDialog() == DialogResult.OK)
            {
                try
                {
                    int source = Int32.Parse(from.Text);
                    int target = Int32.Parse(to.Text);

                    int res = alg.FordFalkerson(source, target);

                    MessageBox.Show(res.ToString(), "Результат", MessageBoxButtons.OK);

                    LabelState.Text = title;
                }
                catch (Exception)
                {
                    MessageBox.Show("Неверно заданы узлы!", "Ошибка", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }