private void button3_Click_1(object sender, EventArgs e) { // рисовать граф автомата EnsembleGraphNode ens = (EnsembleGraphNode)treeView1.SelectedNode.Tag; /* * if (File.Exists(Directory.GetCurrentDirectory()+"\\automata.png")) * { * File.Delete(Directory.GetCurrentDirectory() + "\\automata.png"); * } */ // automata table string[,] table = ens.getAutomataTable(checkedListBox1.CheckedItems); CalculateDistance g = new CalculateDistance(); g.SetUpEdgesAndCosts(table, ens, checkedListBox1); //g.ShortesDistanceTest(); g.Visualize(); ActivateforImages(); //Image image2 = Image.FromFile("C:\\temp\\distance.png"); //this.pictureBox1.Image = image2; }
private void treeView1_AfterSelect(object sender, TreeViewEventArgs e) { label1.Text = "Ансамбль: " + treeView1.SelectedNode.Text; checkedListBox1.Items.Clear(); EnsembleGraphNode ens = (EnsembleGraphNode)treeView1.SelectedNode.Tag;//.ensemble; foreach (Neuron neur in ens.getInputNeurons()) { checkedListBox1.Items.Add(neur.getId()); } }
private TreeNode getTreeNode(EnsembleGraphNode egN) { TreeNode tekTN = new TreeNode(getNameOfEns(egN.ensemble)); tekTN.Tag = egN; foreach (EnsembleGraphNode egN2 in egN.consistFrom) { tekTN.Nodes.Add(getTreeNode(egN2)); } return(tekTN); }
public void SetUpEdgesAndCosts(string[,] table, EnsembleGraphNode ens, CheckedListBox checkedListBox1) { _graph = new AdjacencyGraph <string, Edge <string> >(); _costs = new Dictionary <Edge <string>, string>(); //for(int i=0; i<table.Length) for (int j = 1; j <= ens.getAutomataWidth() - 1; j++) // по столбцам { for (int i = 1; i <= ens.getAutomataHeigh(checkedListBox1.CheckedItems) - 1; i++) // по строкам { // AddEdgeWithCosts(table[0, j].ToString(), table[i, j].ToString(), 1); AddEdgeWithCosts(table[0, j].ToString(), table[i, j].ToString(), table[i, 0].ToString()); } } /* AddEdgeWithCosts("6", "7", 2.0); * AddEdgeWithCosts("6", "1", 1.0); * AddEdgeWithCosts("6", "8", 5.0); * AddEdgeWithCosts("7", "6", 3.0); * AddEdgeWithCosts("7", "2", 3.0); * AddEdgeWithCosts("7", "8", 3.0); * AddEdgeWithCosts("8", "6", 3.0); * AddEdgeWithCosts("8", "2", 2.0); * AddEdgeWithCosts("1", "6", 2.0); * AddEdgeWithCosts("1", "3", 2.0); * AddEdgeWithCosts("2", "6", 2.0); * AddEdgeWithCosts("2", "1", 4.0); * AddEdgeWithCosts("2", "3", 2.0); * AddEdgeWithCosts("3", "1", 1.0); * AddEdgeWithCosts("3", "5", 5.0); * AddEdgeWithCosts("3", "4", 2.0); * AddEdgeWithCosts("4", "3", 3.0); * AddEdgeWithCosts("4", "2", 3.0); * AddEdgeWithCosts("5", "2", 2.0); * AddEdgeWithCosts("5", "3", 3.0); * AddEdgeWithCosts("5", "4", 3.0);*/ }
private void getAutonataTable() { dataGridView5.Rows.Clear(); dataGridView5.Columns.Clear(); EnsembleGraphNode ens = (EnsembleGraphNode)treeView1.SelectedNode.Tag; string[,] table = ens.getAutomataTable(checkedListBox1.CheckedItems); /*dataGridView1.Columns.Add((j + 1).ToString(), (j + 1).ToString()); * i = dataGridView1.Columns.Count; * dataGridView1.Columns[i - 1].Width = 40; * dataGridView1.Rows.Add(); * dataGridView1.Rows[i - 1].HeaderCell.Value = (j + 1).ToString();*/ for (int i = 1; i <= ens.getAutomataWidth() - 1; i++) { dataGridView5.Columns.Add(table[0, i].ToString(), table[0, i].ToString()); dataGridView5.Columns[i - 1].Width = 40; } for (int i = 1; i <= ens.getAutomataHeigh(checkedListBox1.CheckedItems) - 1; i++) { dataGridView5.Rows.Add(); dataGridView5.Rows[i - 1].HeaderCell.Value = table[i, 0].ToString(); } for (int i = 1; i < ens.getAutomataHeigh(checkedListBox1.CheckedItems); i++) { for (int j = 1; j < ens.getAutomataWidth(); j++) { dataGridView5.Rows[i - 1].Cells[j - 1].Value = table[i, j].ToString(); } } }
public void getTreeView(TreeNodeCollection tv) { //TreeNodeCollection tv = new TreeNodeCollection(); List <List <Neuron> > listEs = getEnsembles(); List <EnsembleGraphNode> eG = new List <EnsembleGraphNode>(); foreach (List <Neuron> ln in listEs) { eG.Add(new EnsembleGraphNode(ln, new List <EnsembleGraphNode>(), new List <EnsembleGraphNode>())); } // формируем граф включений foreach (List <Neuron> ln in listEs) { foreach (List <Neuron> ln2 in listEs) { if (ln2.Count < ln.Count) { if (belongTo(ln2, ln)) { EnsembleGraphNode a = eG.Find(x => x.ensemble == ln2); EnsembleGraphNode b = eG.Find(x => x.ensemble == ln); if (a.belongTo.Exists(x => x.ensemble == b.ensemble) == false) { a.belongTo.Add(b); } if (b.consistFrom.Exists(x => x.ensemble == a.ensemble) == false) { b.consistFrom.Add(a); } } } } } // редактируем граф включений (удаляем опосредованные включения) foreach (EnsembleGraphNode en1 in eG) { en1.length = en1.ensemble.Count; foreach (EnsembleGraphNode en2 in eG) { IEnumerable <EnsembleGraphNode> intersection = en1.belongTo.Intersect(en2.belongTo); if (en1.belongTo.Exists(x => x == en2) == true) { foreach (EnsembleGraphNode gNode in intersection.ToArray <EnsembleGraphNode>()) { en1.belongTo.Remove(gNode); gNode.consistFrom.Remove(en1); } } else if (en2.belongTo.Exists(x => x == en1) == true) { foreach (EnsembleGraphNode gNode in intersection) { en2.belongTo.Remove(gNode); gNode.consistFrom.Remove(en2); } } } } // getNameOfEns foreach (EnsembleGraphNode ln in eG) { if (ln.belongTo.Count == 0) { tv.Add(getTreeNode(ln)); } } //return tv; }