예제 #1
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                start = main_form.graph.nodes.Find(node => node.name == Convert.ToInt32(tbStart.Text));
                goal  = main_form.graph.nodes.Find(node => node.name == Convert.ToInt32(tbGoal.Text));
                if ((start == null) || (goal == null))
                {
                    throw new FormatException();
                }
                Close();
                switch (algorithm)
                {
                case (int)algorithms.BFS:
                    main_form.graph.doAlgorithm(new Graph.Algorithm.BFS(main_form.graph, start, goal));
                    break;

                case (int)algorithms.DFS:
                    main_form.graph.doAlgorithm(new Graph.Algorithm.DFS(main_form.graph, start, goal));
                    break;
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("Невірно введені дані!",
                                "Помилка!",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }
예제 #2
0
 private void graphics_MouseClick(object sender, MouseEventArgs e)
 {
     if (!graph.highlightNode(e.X, e.Y))
     {
         if (!switcher)
         {
             graph.addNode(e.X, e.Y);
             if (!graph.connect(e.X, e.Y))
             {
                 switcher = true;
             }
         }
         else
         {
             var node = new Graph.Node(e.X, e.Y);
             graph.addNode(node);
             graph.connect(node, weight);
             switcher = false;
         }
     }
     else
     {
         switcher = false;
     }
 }
예제 #3
0
 private void button2_Click(object sender, EventArgs e)
 {
     try
     {
         source = main_form.graph.nodes.Find(node => node.name == Convert.ToInt32(tbStart.Text));
         drain  = main_form.graph.nodes.Find(node => node.name == Convert.ToInt32(tbGoal.Text));
         if ((source == null) || (drain == null))
         {
             throw new FormatException();
         }
         Close();
         main_form.graph.doAlgorithm(new Graph.Algorithm.MaxFlow(main_form.graph, source, drain));
     }
     catch (FormatException)
     {
         MessageBox.Show("Невірно введені дані!",
                         "Помилка!",
                         MessageBoxButtons.OK,
                         MessageBoxIcon.Error);
     }
 }
예제 #4
0
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                start = main_form.graph.nodes.Find(node => node.name == Convert.ToInt32(tbStart.Text));
                goal  = main_form.graph.nodes.Find(node => node.name == Convert.ToInt32(tbGoal.Text));
                if ((start == null) || (goal == null))
                {
                    throw new FormatException();
                }
                Close();
                switch (algorithm)
                {
                case (int)algorithms.DIJKSTRAS:
                    main_form.graph.doAlgorithm(new Graph.Algorithm.Dijkstras(main_form.graph, start, goal));
                    break;

                case (int)algorithms.FLOYD_WARSH:
                    main_form.graph.doAlgorithm(new Graph.Algorithm.Floyd_Warsh(main_form.graph, start, goal));
                    break;

                case (int)algorithms.BELL_FORD:
                    main_form.graph.doAlgorithm(new Graph.Algorithm.Bell_Ford(main_form.graph, start, goal));
                    break;

                case (int)algorithms.JOHNSON:
                    main_form.graph.doAlgorithm(new Graph.Algorithm.Johnson(main_form.graph, start, goal));
                    break;
                }
            }
            catch (FormatException)
            {
                MessageBox.Show("Невірно введені дані!",
                                "Помилка!",
                                MessageBoxButtons.OK,
                                MessageBoxIcon.Error);
            }
        }