private void tsBtnAddEdge_Click(object sender, EventArgs e)
        {
            if (sourceModel == null || stockModel == null ||
                sourceModel.Key == stockModel.Key)
            {
                return;
            }

            string weight = null;

            if (_field.IsWeighted)
            {
                SetWeightForm window = new SetWeightForm();
                window.Owner = this;
                window.ShowDialog();
                if (window.Ok)
                {
                    weight = window.Weight;
                }
            }
            AEdgeModel edgeModel;

            if (_field.IsOrgraph)
            {
                edgeModel = new OrientEdgeModel(sourceModel, stockModel, weight);
            }
            else
            {
                edgeModel = new NonOrientEdgeModel(sourceModel, stockModel, weight);
            }

            CommandEntered?.Invoke(this, new AddModelCommandArgs(edgeModel));
            _field.UnmarkGraphModels();
        }
Exemplo n.º 2
0
 private void tsmiFordBellmanAlgorithm_Click(object sender, EventArgs e)
 {
     if (_field.Status == false)
     {
         return;
     }
     if (_field.MarkedVertexModelCount == 2)
     {
         SetWeightForm form = new SetWeightForm("Укажите макс длину L", "Найти");
         form.Owner = this;
         form.ShowDialog();
         if (!form.Ok)
         {
             return;
         }
         bool succsess = int.TryParse(form.Weight, out var l);
         if (!succsess)
         {
             PostErrorMessage("Некорректное число L");
             return;
         }
         new Thread(() =>
         {
             var args = new WayNoMoreThenLCommandArgs(sourceModel, stockModel, l);
             CommandEntered.Invoke(this, args);
             if (args.SuccsessOut)
             {
                 if (!args.Exist)
                 {
                     PostMessage($"Пути не больше {l} не существуют!!");
                 }
                 else
                 {
                     StringBuilder sb = new StringBuilder();
                     args.OutWays.ForEach(w => sb.AppendLine(w));
                     ResultForm resform = new ResultForm(args.TaskNameOut, args.AlgorithmNameOut, sb.ToString());
                     BeginInvoke((MethodInvoker)(() =>
                     {
                         resform.Owner = this;
                         resform.ShowDialog();
                         if (resform.Stream != null)
                         {
                             sb.Clear();
                             sb.AppendLine(resform.TaskName);
                             sb.AppendLine(resform.AlgorithmName);
                             sb.AppendLine(resform.ResultText);
                             CommandEntered?.Invoke(this, new SaveAlgorithmResultCommandArgs(resform.Stream, sb.ToString()));
                         }
                     }));
                 }
             }
         }).Start();
     }
     else
     {
         PostWarningMessage("Надо вбрать две вершини!!!");
     }
 }
Exemplo n.º 3
0
 private void tsmiNPeriohery_Click(object sender, EventArgs e)
 {
     if (_field.Status == false)
     {
         return;
     }
     if (_field.MarkedVertexModelCount == 1)
     {
         SetWeightForm form = new SetWeightForm("Укажите N", "Найти");
         form.Owner = this;
         form.ShowDialog();
         if (!form.Ok)
         {
             return;
         }
         bool succsess = int.TryParse(form.Weight, out var N);
         if (!succsess)
         {
             PostErrorMessage("Некорректное число N");
             return;
         }
         new Thread(() =>
         {
             var args = new NPeripheryCommandArgs(sourceModel, N);
             CommandEntered.Invoke(this, args);
             if (args.SuccsessOut)
             {
                 StringBuilder sb = new StringBuilder();
                 args.NPeripheryOut.ForEach(w => sb.AppendLine(w));
                 ResultForm resform = new ResultForm(args.TaskNameOut, args.AlgorithmNameOut, sb.ToString());
                 BeginInvoke((MethodInvoker)(() =>
                 {
                     resform.Owner = this;
                     resform.ShowDialog();
                     if (resform.Stream != null)
                     {
                         sb.Clear();
                         sb.AppendLine(resform.TaskName);
                         sb.AppendLine(resform.AlgorithmName);
                         sb.AppendLine(resform.ResultText);
                         CommandEntered?.Invoke(this, new SaveAlgorithmResultCommandArgs(resform.Stream, sb.ToString()));
                     }
                 }));
             }
         }).Start();
     }
     else
     {
         PostWarningMessage("Надо вбрать одну вершину!!!");
     }
 }