private void Button_Click_deleteOtherComp(object sender, RoutedEventArgs e) { int id1 = -1; try { id1 = int.Parse(tb_find_id.Text); if (!compV.used_id.Contains(id1)) { throw new Exception(); } } catch { MessageBox.Show("Некорректно заданы поля"); return; } compV st = compV.get_vertex(id1); List <compV> componenta = st.get_Componenta(); for (int i = 0; i < compV.all_vertex.Count; i++) { if (!componenta.Contains(compV.all_vertex[i])) { compV.all_vertex[i].remove_vertex(); i--; } } refresh(); update_neighbor(); }
private void Button_Click_checkTwoID(object sender, RoutedEventArgs e) { int id1 = -1; int id2 = -1; try { id1 = int.Parse(tb_id1.Text); id2 = int.Parse(tb_id2.Text); if (id1 == id2 || !compV.used_id.Contains(id1) || !compV.used_id.Contains(id2)) { throw new Exception(); } } catch { MessageBox.Show("Некорректно заданы поля", "Ошибка!", MessageBoxButton.OK, MessageBoxImage.Error); return; } compV st = compV.get_vertex(id1); List <compV> componenta = st.get_Componenta(); foreach (var a in componenta) { if (id2 == a.ID) { MessageBox.Show("Вершины связанны между собой", "Результат работы", MessageBoxButton.OK); return; } } MessageBox.Show("Вершины не связанны между собой", "Результат работы", MessageBoxButton.OK); }
private void Button_Click_countComp(object sender, RoutedEventArgs e) { int id1 = -1; try { id1 = int.Parse(tb_find_id.Text); if (!compV.used_id.Contains(id1)) { throw new Exception(); } } catch { MessageBox.Show("Некорректно заданы поля", "Ошибка!", MessageBoxButton.OK, MessageBoxImage.Error); return; } compV st = compV.get_vertex(id1); List <compV> componenta = st.get_Componenta(); tb_count_comp.Text = componenta.Count.ToString(); }
private void Button_Click_start(object sender, RoutedEventArgs e) { if (cb_start_vertex.SelectedIndex == -1) { return; } log_box.Clear(); compV start = compV.get_vertex(int.Parse(cb_start_vertex.SelectedItem.ToString())); List <compV> componenta = start.get_Componenta(); if (componenta.Count != compV.all_vertex.Count) { MessageBox.Show("Граф не связен.", "Внимание!"); return; } int count_algs = 0; int max_count_step = 0; try { count_algs = int.Parse(tb_count_algs.Text); max_count_step = int.Parse(tb_count_step.Text); if (count_algs < 0 || max_count_step < 0) { MessageBox.Show("Некорретно задано поле.", "Ошибка!", MessageBoxButton.OK, MessageBoxImage.Error); } } catch { MessageBox.Show("Некорретно задано поле.", "Ошибка!", MessageBoxButton.OK, MessageBoxImage.Error); } List <compV> botnet = new List <compV>(); int total_step = 0; int botnet_fail = 0; for (int k = 0; k < count_algs; k++) { compV.refreshGraph(); botnet.Clear(); botnet.Add(start); start.status = true; int step = 1; int count = 1; log_box.Text += (k + 1) + " PASS" + "\r\n\r\n"; log_box.Text += "Start vertex = " + start.ID + "\r\n"; while (botnet.Count != compV.all_vertex.Count && max_count_step > step) { log_box.Text += "Step " + step + ":\r\n"; count = 0; int c = botnet.Count; for (int i = 0; i < c; i++) { List <compV> atLst = botnet[i].attack(); foreach (var j in atLst) { log_box.Text += (botnet[i].ID + " -> " + j.ID + " "); j.status = true; botnet.Add(j); count++; } } if (count != 0) { log_box.Text += "\r\nbotnet count = " + botnet.Count + " new= " + count + "\r\n"; } step++; } log_box.Text += "\r\n\r\n________________________________________________________________\r\n\r\n"; if (max_count_step == step) { botnet_fail++; } total_step += step; } tb_botnet_fail.Text = "Успешных защит = " + botnet_fail; tb_sred_step.Text = "Среднее количество шагов = " + (float)total_step / count_algs; cb_numAlg.Items.Clear(); for (int i = 0; i < count_algs; ++i) { cb_numAlg.Items.Add(i + 1); } if (cb_start_vertex.Items.Count != 0) { cb_numAlg.SelectedIndex = 0; } }