private static void CyclicGraph2() { Graph1 <char> Cyclic = new Graph1 <char>(); Console.WriteLine("Cyclic Graph"); Cyclic.AddEdge('A', 'B', false); Cyclic.AddEdge('B', 'C', false); Cyclic.AddEdge('C', 'A', false); Cyclic.AddEdge('D', 'C', false); Console.Write("Is it cyclic? "); var i = Cyclic.IsCyclic(); if (i) { Console.Write("Yes."); } else { Console.Write("No."); } Console.WriteLine("\nLast Line"); Console.ReadLine(); }
private static void GermanCities() { Graph1 <string> germanCities = new Graph1 <string>(); germanCities.AddEdge("Frankfurt", "Mannheim", false); germanCities.AddEdge("Frankfurt", "Wurzburg", false); germanCities.AddEdge("Frankfurt", "Kassel", false); germanCities.AddEdge("Mannheim", "Karlsruhe", false); germanCities.AddEdge("Karlsruhe", "Augsburg", false); germanCities.AddEdge("Augsburg", "Munchen", false); germanCities.AddEdge("Wurzburg", "Erfurt", false); germanCities.AddEdge("Wurzburg", "Nurnberg", false); germanCities.AddEdge("Nurnberg", "Stuttgart", false); germanCities.AddEdge("Nurnberg", "Munchen", false); germanCities.AddEdge("Kassel", "Munchen", false); Console.WriteLine("\n**** DFS Iterative *****"); germanCities.DFS("Frankfurt"); Console.WriteLine("--------------"); Console.WriteLine("\n**** DFS Recursive ****\n"); germanCities.DFS("Frankfurt", true); Console.WriteLine("**************"); Console.WriteLine(); Console.WriteLine("**** BFS *****"); germanCities.BFS("Frankfurt"); Console.WriteLine("**************"); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~"); germanCities.FindSpanningTree(); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~"); germanCities.FindPathBetweenTwoVertices("Frankfurt", "Stuttgart"); Console.ReadLine(); }
private void btnGraph_Click(object sender, EventArgs e) //GRAPH BUTTON { //Declaring a new instance of Graph and displaying properties to the Windows Form Graph1 graph = new Graph1(); richTextBox2.AppendText(graph.AccessTime + " "); richTextBox2.AppendText(graph.SearchTime + "\n"); richTextBox2.AppendText(graph.InsertTime + " "); richTextBox2.AppendText(graph.DeleteTime + "\n"); richTextBox2.AppendText(graph.SpaceComplexity + "\n"); richTextBox2.AppendText("*All Big-O values represent worst-case scenarios unless otherwise noted"); //Displaying the Advantages and Disadvantages of Graph to the Windows Form richTextBox1.AppendText("GRAPHS\n"); richTextBox1.AppendText(graph.Advantages("A Graph is a non-linear data structure consisting of " + "nodes and edges. Graphs are used to solve many real-life problems. Graphs are used to represent networks. Trees are a type of graph.")); richTextBox1.AppendText("\n\n"); richTextBox1.AppendText(graph.Disadvantages("Types of Graph: \n" + "Undirected Graph: nodes are connected by edges that are all bidirectional. \n" + "Directed Graph: nodes are connected by directed edges - they only go in one direction. \n" + "\nTypes of Graph Represntations: \n" + "Adjacency List is an array of lists. The size of the array is equal to the number of nodes.\n" + "Adjacency Matrix is a 2D array of size n*n where n is the number of nodes in a graph.")); //Displaying extra notes from a rich text file in the bin using (StreamReader Reader = new StreamReader(@"C:\Users\Clayt\source\repos\CSC205\CSC205_StudyProject\CSC205_StudyProject\bin\Graph.rtf")) { while (!Reader.EndOfStream) { richTextBox5.AppendText(Reader.ReadLine()); } } }
private void numericUpDown9_ValueChanged(object sender, EventArgs e) { GraphPane pane = Graph1.GraphPane; pane.XAxis.Scale.Max = decimal.ToDouble(numericUpDown9.Value); GraphPane pane2 = Graph2.GraphPane; pane2.XAxis.Scale.Max = decimal.ToDouble(numericUpDown9.Value); GraphPane pane3 = Graph3.GraphPane; pane3.XAxis.Scale.Max = decimal.ToDouble(numericUpDown9.Value); pane.YAxis.Scale.MinAuto = true; pane.YAxis.Scale.MaxAuto = true; pane.IsBoundedRanges = true; pane3.YAxis.Scale.MinAuto = true; pane3.YAxis.Scale.MaxAuto = true; pane3.IsBoundedRanges = true; Graph1.AxisChange(); Graph1.Invalidate(); Graph2.AxisChange(); Graph2.Invalidate(); Graph3.AxisChange(); Graph3.Invalidate(); }
private void Form1_Shown(object sender, EventArgs e) { Form3 frm3 = new Form3(this); this.Hide(); frm3.Show(); grp1 = new Graph1(); }
public MainWindow() { InitializeComponent(); Graph1.Init(App.Controller1, 3, 2000); Graph2.Init(App.Controller2, 3, 2000); Parameter1.Init(App.Controller1); Parameter2.Init(App.Controller2); }
public void ToString_error() { Graph1 g = new Graph1(); g.AddNode("Kyiv"); g.AddNode("Lviv"); Assert.AreEqual("Kyiv Lviv ", g.ToString()); }
public void AddNode_error() { Graph1 g = new Graph1(); g.AddNode("Kyiv"); g.AddNode("Lviv"); g.AddNode("Donetsk"); Assert.AreEqual(3, g.nodes.Length); }
private void AtualizarTempoReal() { textBoxReceber.Text = ""; if (valor1 >= 0 && valor1 <= 100) { progressBar1.Value = valor1; } if (valor2 >= 0 && valor2 <= 100) { progressBar2.Value = valor2; } if (valor3 >= 0 && valor3 <= 100) { progressBar3.Value = valor3; } //if (CBTipo.SelectedIndex == 0) //{ atualizaTextBox(); //} if (Graph.Series[0].Points.Count >= 9) { Graph.Series[0].Points.RemoveAt(0); Graph.Update(); } if (Graph1.Series[0].Points.Count >= 9) { Graph1.Series[0].Points.RemoveAt(0); Graph1.Update(); } if (Graph2.Series[0].Points.Count >= 9) { Graph2.Series[0].Points.RemoveAt(0); Graph2.Update(); } string hora = DateTime.Now.ToLongTimeString(); Graph.Series[0].Points.AddXY(hora, valor1); Graph1.Series[0].Points.AddXY(hora, valor2); Graph2.Series[0].Points.AddXY(hora, valor3); }
private static void FindPathBetweenTwoNodes() { Graph1 <int> Graph = new Graph1 <int>(); Graph.AddEdge(1, 2, false); Graph.AddEdge(2, 3, false); Graph.AddEdge(3, 4, false); Graph.AddEdge(1, 5, false); Graph.AddEdge(5, 6, false); Graph.AddEdge(6, 7, false); Graph.AddEdge(5, 8, false); Graph.AddEdge(1, 9, false); Graph.AddEdge(9, 10, false); Graph.FindPathBetweenTwoVertices(1, 7); Console.ReadLine(); }
static void ex4() { int[,] distances = new int[10, 10]; for (int i = 0; i < distances.GetLength(0); i++) for (int j = 0; j < distances.GetLength(1); j++) distances[i, j] = -1; for (int i = 0; i < distances.GetLength(0); i++) distances[i, rnd.Next(0, i)] = rnd.Next(40, 120); for (int i = 0; i < distances.GetLength(0); i++) for (int j = 0; j < distances.GetLength(1); j++) if (j > i) distances[i, j] = distances[j, i]; for (int i = 0; i < distances.GetLength(0); i++) { for (int j = 0; j < distances.GetLength(1); j++) Console.Write("{0, -3} ", distances[i, j]); Console.WriteLine("\n"); } Console.WriteLine(); int city = 0, limit = 200; while (city < 1 || city > distances.GetLength(0)) { Console.Write("Enter the number of city (from 1 to " + distances.GetLength(0) + "): "); city = int.Parse(Console.ReadLine()); } Console.WriteLine(); Graph1 G = new Graph1(distances, distances.GetLength(0)); Dictionary<string, int> dist = new Dictionary<string, int>(); Console.WriteLine("\nPaths:\n"); for (int j = 0; j < distances.GetLength(0); j++) if (!dist.ContainsKey("From " + city + " to " + j + 1) && city != j + 1) { var stackBFS = G.BFS1(city - 1, j); ShowPath1(stackBFS); Console.WriteLine(); DictionaryAdd(stackBFS, distances, ref dist, city); } Console.WriteLine("\nDistances:\n"); foreach (var item in dist) if (item.Value <= limit) Console.WriteLine(item.Key + " : " + item.Value + "\n"); }
private static void TremauxExecution() { Graph1 <char> Tremaux = new Graph1 <char>(); Tremaux.AddEdge('A', 'B', true); Tremaux.AddEdge('A', 'C', true); Tremaux.AddEdge('A', 'E', true); Tremaux.AddEdge('B', 'D', true); Tremaux.AddEdge('B', 'F', true); Tremaux.AddEdge('C', 'G', true); Tremaux.AddEdge('E', 'F', true); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~"); Console.WriteLine("Printing Whole Graph:\n" + Tremaux.ToString()); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~"); Console.WriteLine("\n**** DFS iterative ****\n"); Tremaux.DFS('A'); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~"); Console.WriteLine("\n**** DFS recursive ****\n"); Tremaux.DFS('A', true); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~"); Console.WriteLine("\n**** BFS ****\n"); Tremaux.BFS('A'); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~"); Console.WriteLine("\n**** Spanning Tree ****\n"); Tremaux.FindSpanningTree(); Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~~~~~~"); Console.Write("Is it cyclic? "); var i = Tremaux.IsCyclic(); if (i) { Console.Write("Yes."); } else { Console.Write("No."); } Console.WriteLine("\nLast Line"); Console.ReadLine(); }
private void newToolStripMenuItem_Click(object sender, EventArgs e) { /* * if (dot.Count > 0 && saved == 0) * { * this.SaveChanges(this, e, "new"); * } */ file_path = ""; if (plug_name != null) { this.Text = Application.ProductName; } Graph1.count = 0; int what = 1; Graph1.GraphChange(this, e, what); }
private void numericUpDown10_ValueChanged(object sender, EventArgs e) { if (decimal.ToDouble(numericUpDown9.Value) > decimal.ToDouble(numericUpDown10.Value)) { GraphPane pane = Graph1.GraphPane; GraphPane pane2 = Graph2.GraphPane; GraphPane pane3 = Graph3.GraphPane; pane.XAxis.Scale.Min = decimal.ToDouble(numericUpDown10.Value); pane2.XAxis.Scale.Min = decimal.ToDouble(numericUpDown10.Value); pane3.XAxis.Scale.Min = decimal.ToDouble(numericUpDown10.Value); Graph1.AxisChange(); Graph1.Invalidate(); Graph2.AxisChange(); Graph2.Invalidate(); Graph3.AxisChange(); Graph3.Invalidate(); } else { numericUpDown10.Value = numericUpDown10.Value - 100; } }
public void AddNode_exception_error() { Graph1 g = new Graph1(); Assert.Throws(typeof(ArgumentException), () => g.AddNode("")); }
public void ToStringEmpty_error() { Graph1 g = new Graph1(); Assert.Throws(typeof(InvalidOperationException), () => g.ToString()); }
public void ToStringNull_error() { Graph1 g = null; Assert.Throws(typeof(NullReferenceException), () => g.ToString()); }
private void prioritiesToolStripMenuItem_Click(object sender, EventArgs e) { Graph1 graph3 = new Graph1(3); graph3.ShowDialog(); }
private void processorFreeTimePercentageToolStripMenuItem_Click(object sender, EventArgs e) { Graph1 graph2 = new Graph1(2); graph2.ShowDialog(); }
private void Button_Click(object sender, RoutedEventArgs e) { Graph1 graph1 = new Graph1(); graph1.Show(); }
static void Main(string[] args) { int[,] matrixAdj = { //1 2 3 4 5 6 7 8 { 0, 1, 1, 0, 0, 0, 0, 0 }, //1 { 1, 0, 0, 0, 0, 1, 1, 0 }, //2 { 1, 0, 0, 1, 0, 1, 0, 1 }, //3 { 0, 0, 1, 0, 1, 0, 0, 0 }, //4 { 0, 0, 0, 1, 0, 1, 0, 0 }, //5 { 0, 1, 1, 0, 1, 0, 0, 0 }, //6 { 0, 1, 0, 0, 0, 0, 0, 1 }, //7 { 0, 0, 1, 0, 0, 0, 1, 0 } //8 }; Graph1 graph = new Graph1(matrixAdj, 8); Console.Write("Введите вершину X:"); int X = int.Parse(Console.ReadLine()); while (X == 0 || X > 8) { Console.WriteLine("Значение введено не верно.Введите верное значение от 1 до 8:"); X = int.Parse(Console.ReadLine()); } Console.Write("Введите вершину Y:"); int Y = int.Parse(Console.ReadLine()); while (Y == 0 || Y > 8) { Console.WriteLine("Значение введено не верно.Введите верное значение от 1 до 8:"); Y = int.Parse(Console.ReadLine()); } Console.WriteLine("В виде матрицы инцидентности:"); Console.WriteLine("DFS:"); Stack <int> DFS = graph.DFS(X - 1, Y - 1); PrintPath(DFS); Console.WriteLine(); Console.WriteLine("BFS:"); Stack <int> BFS = graph.BFS(X - 1, Y - 1); PrintPath(BFS); Console.WriteLine(); Console.WriteLine("В виде связного списка:"); Dictionary <int, List <int> > graph1 = new Dictionary <int, List <int> >(); graph1[1] = new List <int> { 2, 3 }; graph1[2] = new List <int> { 1, 6, 7 }; graph1[3] = new List <int> { 1, 4, 6, 8 }; graph1[4] = new List <int> { 3, 5 }; graph1[5] = new List <int> { 4, 6 }; graph1[6] = new List <int> { 2, 3, 5 }; graph1[7] = new List <int> { 2, 8 }; graph1[8] = new List <int> { 3, 7 }; Graph2 graphList = new Graph2(graph1, 8); Console.WriteLine("DFS:"); Stack <int> DFSList = graphList.DFS(X - 1, Y - 1); PrintPath(DFSList); Console.WriteLine(); Console.WriteLine("BFS:"); Stack <int> BFSList = graphList.BFS(X - 1, Y - 1); PrintPath(BFSList); }
private void clearToolStripMenuItem_Click(object sender, EventArgs e) { int what = 1; Graph1.GraphChange(this, e, what); }
private void inputFlowToolStripMenuItem_Click(object sender, EventArgs e) { Graph1 graph1 = new Graph1(1); graph1.ShowDialog(); }
private void DrawGraph() { turn = 0; int j = 0; double rejected = 0; double accepted = 0; double[] mass3y = new double[decimal.ToInt64(numericUpDown1.Value)]; double[] mass3dlina = new double[decimal.ToInt64(numericUpDown1.Value)]; // Получим панель для рисования GraphPane pane = Graph1.GraphPane; GraphPane pane2 = Graph2.GraphPane; GraphPane pane3 = Graph3.GraphPane; // Очистим список кривых на тот случай, если до этого сигналы уже были нарисованы pane.CurveList.Clear(); pane2.CurveList.Clear(); pane2.GraphObjList.Clear(); pane3.CurveList.Clear(); // Создадим список точек PointPairList list1 = new PointPairList(); PointPairList list1_1 = new PointPairList(); PointPairList list1_2 = new PointPairList(); PointPairList list2 = new PointPairList(); PointPairList list2_2 = new PointPairList(); PointPairList list3 = new PointPairList(); double y = 0; double x = 0; double valuePuasson = 0; double valueTreatment = 0; double valueTreatmentPast = 0; list3.Add(0, 0); list1_2.Add(0, 0); list1_1.Add(0, 0); numericUpDown9.Value = 100; pane.YAxis.Title.Text = "Количество заявок"; pane.XAxis.Title.Text = "Время"; pane2.YAxis.Title.Text = "Серверы"; pane2.XAxis.Title.Text = "Время"; pane3.YAxis.Title.Text = "Очередь"; pane3.XAxis.Title.Text = "Время"; // Заполняем список точек for (int i = 0; i < decimal.ToDouble(numericUpDown1.Value); i++) { mass3y[i] = y; list2.Add(y, 3); // заполняем значения для второго графика //подписываем графики TextObj text2 = new TextObj("t" + i.ToString(), y, 2.5); pane2.GraphObjList.Add(text2); text2.FontSpec.Border.IsVisible = false; text2.FontSpec.Size = 20; list1.Add(y, x); // заполняем значения для первого графика x++; list1.Add(y, x); valuePuasson = rand.Generate(decimal.ToDouble(numericUpDown4.Value)); valueTreatment = y + rand.Generate(decimal.ToDouble(numericUpDown8.Value)); // заполняем значения для 2 графика if (valueTreatmentPast <= y) { list2_2.Add(y, 1); list2_2.Add(valueTreatment, 1); //подписываем графики TextObj text = new TextObj("m" + i.ToString(), (y + valueTreatment) / 2, 0.75); pane2.GraphObjList.Add(text); text.FontSpec.Size = 15; mass3dlina[i] = valueTreatment; } else { valueTreatment += valueTreatmentPast; mass3dlina[i] = valueTreatment; list2_2.Add(valueTreatmentPast, 1); list2_2.Add(valueTreatment, 1); //подписываем графики TextObj text = new TextObj("m" + i.ToString(), (valueTreatmentPast + valueTreatment) / 2, 0.75); pane2.GraphObjList.Add(text); text.FontSpec.Size = 15; } valueTreatmentPast = valueTreatment; list2_2.Add(PointPair.Missing, PointPair.Missing); y += valuePuasson; } //заполняем точки для графика очереди for (int i = 0; i < decimal.ToDouble(numericUpDown1.Value) - 1; i++) { //пока есть точки концов продолжительности между двумя входными запросами уменьшаем график на 1 while (turn > 0 && mass3y[i] < mass3dlina[j] && mass3y[i + 1] > mass3dlina[j]) { list3.Add(mass3dlina[j], turn); turn--; list3.Add(mass3dlina[j], turn); j++; } //если точка входящего запроса меньше точки длины предыдущего то увеличиваем график на 1 if (mass3y[i + 1] < mass3dlina[i]) { if (turn != decimal.ToDouble(numericUpDown3.Value)) { list3.Add(mass3y[i + 1], turn); turn++; list3.Add(mass3y[i + 1], turn); //заполняем график обработанных запросов точками list1_2.Add(mass3dlina[i], accepted); accepted++; list1_2.Add(mass3dlina[i], accepted); } else //заполняем график отказов точками { list1_1.Add(mass3y[i + 1], rejected); rejected++; list1_1.Add(mass3y[i + 1], rejected); } } else { j++;//показатель того сколько отрезков продолжительности прошли //заполняем график обработанных запросов точками list1_2.Add(mass3dlina[i], accepted); accepted++; list1_2.Add(mass3dlina[i], accepted); } } //дорисовываем концовку графика while (turn > 0) { list3.Add(mass3dlina[j], turn); turn--; list3.Add(mass3dlina[j], turn); j++; } list1_2.Add(mass3dlina[decimal.ToInt64(numericUpDown1.Value) - 1], accepted); list1_2.Add(mass3dlina[decimal.ToInt64(numericUpDown1.Value) - 1], accepted + 1); // Создадим кривые LineItem myCurve2 = pane2.AddCurve("Заявка", list2, Color.Blue, SymbolType.VDash); LineItem myCurve2_2 = pane2.AddCurve("Процесс обработки заявки", list2_2, Color.Blue, SymbolType.VDash); LineItem myCurve1 = pane.AddCurve("Всего", list1, Color.Blue, SymbolType.None); LineItem myCurve1_1 = pane.AddCurve("Отказ", list1_1, Color.Red, SymbolType.None); LineItem myCurve1_2 = pane.AddCurve("Обработаны", list1_2, Color.Green, SymbolType.None); LineItem myCurve3 = pane3.AddCurve("Очередь", list3, Color.Red, SymbolType.None); //2 кривую делаем невидимой myCurve2.Line.IsVisible = false; //толщина кривых myCurve1.Line.Width = 2.0f; myCurve1_1.Line.Width = 2.0f; myCurve1_2.Line.Width = 2.0f; myCurve2.Line.Width = 2.0f; myCurve2_2.Line.Width = 2.0f; myCurve3.Line.Width = 2.0f; //myCurve2_2.Line.Fill = new ZedGraph.Fill( Color.Blue); //размеры шрифтов pane.XAxis.Scale.FontSpec.Size = 20; pane.YAxis.Scale.FontSpec.Size = 20; pane2.XAxis.Scale.FontSpec.Size = 20; pane2.YAxis.Scale.FontSpec.Size = 20; pane3.XAxis.Scale.FontSpec.Size = 20; pane3.YAxis.Scale.FontSpec.Size = 20; pane.Legend.FontSpec.Size = 20; pane2.Legend.FontSpec.Size = 20; pane3.Legend.FontSpec.Size = 20; pane.XAxis.Title.FontSpec.Size = 20; pane.YAxis.Title.FontSpec.Size = 20; pane2.XAxis.Title.FontSpec.Size = 20; pane2.YAxis.Title.FontSpec.Size = 20; pane3.XAxis.Title.FontSpec.Size = 20; pane3.YAxis.Title.FontSpec.Size = 20; //Задаем начальные приближения графика pane.YAxis.Scale.MinAuto = true; pane.YAxis.Scale.MaxAuto = true; pane.XAxis.Scale.Min = 0; pane.XAxis.Scale.Max = 100; pane.IsBoundedRanges = true; pane2.YAxis.Scale.MinAuto = true; pane2.YAxis.Scale.MaxAuto = true; pane2.XAxis.Scale.Min = 0; pane2.XAxis.Scale.Max = 100; pane2.IsBoundedRanges = true; pane3.YAxis.Scale.Min = 0; pane3.YAxis.Scale.MaxAuto = true; pane3.XAxis.Scale.Min = 0; pane3.XAxis.Scale.Max = 100; pane3.IsBoundedRanges = true; // Вызываем метод AxisChange (), чтобы обновить данные об осях. Graph1.AxisChange(); Graph2.AxisChange(); Graph3.AxisChange(); // Обновляем график Graph1.Invalidate(); Graph2.Invalidate(); Graph3.Invalidate(); }
private void cutToolStripButton_Click(object sender, EventArgs e) { int what = 1; Graph1.GraphChange(this, e, what); }