//Возвращает ноль, если все цвета уже присвоены public static bool НеВсёЗакрашено(Graf[] mass) { int flag = 0; for (int x = 0; x < mass.Length; x++) //Цикл проверяет - все ли цвета посещены { if (mass[x].color <= mass.Length) flag++; } if (flag == mass.Length) return false; else return true; }
//Инициализируем все цвета цифрой 100 - для "красоты", т.к. граф из 100 вершин вряд ли будет рассматриваться public static void ЗаполнитьГраф(Graf[] mass, int n) { for (int s = 0; s < n; s++) { mass[s].color = 100; } }
//Выводит результат public static void ПечатьГрафа(Graf[] mass) { for (int s = 0; s < mass.Length; s++) { //Выводит - вершина и её цвет Console.WriteLine(mass[s].number + " -- " + mass[s].color); } }
/// <summary> /// Построенние дорожного графа /// </summary> /// <param name="file_name">Файл с нав. датой</param> public void LoadGraf(string file_name) { using (StreamReader myStream = new StreamReader(file_name)) { tree = new Graf(myStream.ReadLine().Split(' ')[1].Split('"')[1]); while (!myStream.EndOfStream) { string data = myStream.ReadLine().Split(' ')[1].Split('"')[1]; tree.AddNode(new GrafNode(data, '/', ';')); } } }
/// <summary> /// Соединение точек линиями /// </summary> /// <param name="tree">Граф</param> /// <param name="index">Индекс карты</param> public void getLine(Graf tree, int index) { foreach (var item in tree.tree) { using (var g = Graphics.FromImage(temp_map)) { foreach (var ind_broth in item.Value.broth_node) { g.DrawLine(new Pen(Brushes.Black, 1), getPoint(item.Value.parametrs.coords, index), getPoint(tree[ind_broth].parametrs.coords, index)); } } } }
public async void chart(string pln, string ap, int tip, string str, string dt_from, string dt_to) { GetF101_data_List_chart.Clear(); GetF101_data_List_chart = await myAPI.GetF101_groups("group_to_Pln_Ap_IndCode" + pln + ap, tip, str, dt_from, dt_to); //GetF101_data_List_chart = GetF101_data_List_chart.OrderBy(order => order.dt).ToList(); Graf gr = new Graf(); gr.Charts(GetF101_data_List_chart, tip, dt_from, dt_to); cv_f101_dynamic.ItemsSource = gr.cv_f101_dynamic_template_list; }
/// <summary> /// Соединение точек линиями /// </summary> /// <param name="tree">Граф</param> /// <param name="indexes">Индексы соседей</param> /// <param name="index">Индекс карты</param> /// <param name="color">Цвет линии</param> public void getWay(Graf tree, List <long> indexes, int index, Brush color) { using (var g = Graphics.FromImage(temp_map)) { Point first_point = getPoint(tree[indexes[0]].parametrs.coords, index); Point second_point; for (int i = 1; i < indexes.Count; i++) { second_point = getPoint(tree[indexes[i]].parametrs.coords, index); g.DrawLine(new Pen(color, 1), first_point, second_point); first_point = second_point; } } }
public async void chart(int tip, string indCode, string dt_from, string dt_to, string filtered_bankname) { GetF101_data_List_chart.Clear(); GetF101_data_List_chart = await myAPI.GetF101_data("IndCode", tip, indCode, dt_from, dt_to); GetF101_data_List_chart = GetF101_data_List_chart.Where(x => x.regn == filtered_bankname) .OrderBy(order => order.col_3).Reverse() .ToList(); Graf gr = new Graf(); gr.Charts(GetF101_data_List_chart, tip, dt_from, dt_to); cv_f101_dynamic.ItemsSource = gr.cv_f101_dynamic_template_list; }
static int[] KolorujGraf(int iloscWierzcholkow, Graf g, IEnumerable <int> kolejnosc) { int[] pokolorowanie = new int[iloscWierzcholkow]; int aktualnaIloscKolorow = 0; foreach (int w in kolejnosc) { List <int> koloryDopuszczalne = ZnajdzKoloryDopuszczalne(aktualnaIloscKolorow, g.Sasiedzi(w), pokolorowanie); pokolorowanie[w] = koloryDopuszczalne[0]; aktualnaIloscKolorow = Math.Max(aktualnaIloscKolorow, koloryDopuszczalne[0]); } return(pokolorowanie); }
static void Main(string[] args) { const int iloscWierzcholkow = 6; Graf g = new Graf(iloscWierzcholkow); //g.DodajKrawedzNieskierowana(0, 1); //g.DodajKrawedzNieskierowana(1, 2); //g.DodajKrawedzNieskierowana(2, 3); //g.DodajKrawedzNieskierowana(1, 4); //g.DodajKrawedzNieskierowana(4, 5); //g.DodajKrawedzNieskierowana(5, 2); g.DodajKrawedzNieskierowana(0, 2); g.DodajKrawedzNieskierowana(0, 4); g.DodajKrawedzNieskierowana(1, 3); g.DodajKrawedzNieskierowana(1, 5); g.DodajKrawedzNieskierowana(2, 5); g.DodajKrawedzNieskierowana(3, 4); List <int> stopien = new List <int>(); for (int i = 0; i < iloscWierzcholkow; i++) { stopien.Add(g.Sasiedzi(i).Count); } Queue <int> kolejnosc = new Queue <int>(); while (true) { int maxIndex = stopien.IndexOf(stopien.Max()); if (stopien[maxIndex] < 0) { break; } kolejnosc.Enqueue(maxIndex); stopien[maxIndex] = -1; } var pokolorowanie = KolorujGraf(iloscWierzcholkow, g, kolejnosc); Console.ReadLine(); }
public PrymitywnyPasazerDijkstry(int czasWsiadania, int czasWysiadania, Przystanek przystanekPoczatkowy, Przystanek przystanekKoncowy, Graf.Graf <TimeSpan> graf) : base(czasWsiadania, czasWysiadania, przystanekPoczatkowy, przystanekKoncowy) { this.graf = graf; trasaPasazera = ZnajdzTrase(graf); graf.ZresetujGraf(TimeSpan.MaxValue); if (trasaPasazera.Count > 1) { przystanekPoczatkowy = trasaPasazera[0]; przystanekKoncowy = trasaPasazera[trasaPasazera.Count - 1]; obecnyPrzystanek = przystanekPoczatkowy; } UsunPierwszyElementTrasy(); // Usuwanie pierwszego elementu dla ulatwienia implementacji logiki porozy. }
public static bool CzySpelnialne(Graf g) { int[] SSS = g.WyznaczSSS(); int n = g.IloscWierzcholkow / 2; for (int w = 0; w < n; w++) { if (SSS[w] == SSS[w + n]) { return(false); } } return(true); }
public void BuildSpain_Test_AloneVertex()//проверка корректности работы при одной вершине { List <Graf> grafs3 = new List <Graf>(); List <Graf> grafs2 = new List <Graf>(); grafs3.Add(new Graf(1, 2, 3, 2, 1)); grafs2 = grafs3; Graf graf = new Graf(0, 0, 0, 0, 0); graf.sets = new int[10]; for (int i = 1; i < 10; i++) { graf.sets[i] = i; } graf.BuildSpanningTree(2, grafs3); Assert.Equal(grafs3[0].edges.distance, grafs2[0].edges.distance); }
/// <summary> /// Соединение точек линиями /// </summary> /// <param name="tree">Граф</param> /// <param name="Look">Массив рассмотренных точек</param> /// <param name="Not_Look">Массив потенциальных точек</param> /// <param name="index">Индекс карты</param> public void getWay(Graf tree, List <SavedData> Look, List <SavedData> Not_Look, int index) { using (var g = Graphics.FromImage(temp_map)) { int Look_counter = Look.Count; int Not_Look_counter = Not_Look.Count - 1; for (int i = 0; i < Not_Look_counter; i++) { Point first_point = getPoint(tree[Not_Look[i].index_root].parametrs.coords, index); Point second_point = getPoint(tree[Not_Look[i].index].parametrs.coords, index); g.DrawLine(new Pen(Brushes.Blue, 1), first_point, second_point); } for (int i = 0; i < Look_counter; i++) { Point first_point = getPoint(tree[Look[i].index_root].parametrs.coords, index); Point second_point = getPoint(tree[Look[i].index].parametrs.coords, index); g.DrawLine(new Pen(Brushes.Green, 1), first_point, second_point); } } }
internal static int[,] GetMatrix(Graf graf) { var count = graf.GetVertexCount(); var matrix = new int[count, count]; foreach (var edge in graf.GetEdgeList()) { if (edge.Route) { matrix[edge.StartVertex - 1, edge.FinishVertex - 1] = edge.Weight; } else { matrix[edge.StartVertex - 1, edge.FinishVertex - 1] = edge.Weight; matrix[edge.FinishVertex - 1, edge.StartVertex - 1] = edge.Weight; } } return(matrix); }
public void SortByDistance_Test_MoreVertex()//проверка корректности сортировки { List <Graf> grafs3 = new List <Graf>(); List <Graf> grafs2 = new List <Graf>(); grafs3.Add(new Graf(1, 2, 3, 2, 1)); grafs3.Add(new Graf(1, 4, 5, 2, 1)); grafs3.Add(new Graf(1, 3, 2, 2, 1)); Graf graf = new Graf(0, 0, 0, 0, 0); graf.sets = new int[10]; for (int i = 1; i < 10; i++) { graf.sets[i] = i; } int result = 2; graf.BuildSpanningTree(2, grafs3); Assert.Equal(grafs3[1].edges.distance, result); Assert.Equal(grafs3[2].edges.distance, 5); }
private static void StworzImplikacje(Graf g, int n1, int n2) // W tej metodzie indeksowanie od 1 { if (n1 == 0 || n2 == 0 || g == null) { throw new Exception(); } if (n1 < 0) { n1 = Zaneguj(-n1, g.IloscWierzcholkow); } if (n2 < 0) { n2 = Zaneguj(-n2, g.IloscWierzcholkow); } // X1 | X2 -> ~X2 => X1 g.DodajKrawedzSkierowana(Zaneguj(n2, g.IloscWierzcholkow) - 1, n1 - 1); // X1 | X2 -> ~X1 => X2 g.DodajKrawedzSkierowana(Zaneguj(n1, g.IloscWierzcholkow) - 1, n2 - 1); }
public void AddVertex_Test() { List <Graf> grafsResult = new List <Graf>(); grafsResult.Add(new Graf(1, 5, 2, 4, 2)); grafsResult.Add(new Graf(2, 5, 2, 4, 2)); List <Graf> grafs = new List <Graf>(); Graf graf = new Graf(0, 0, 0, 0, 0); grafs.Add(graf.AddVertex(1, 5, 2, 4, 2)); grafs.Add(graf.AddVertex(2, 5, 2, 4, 2)); Assert.Equal(grafsResult[0].edges.U, grafs[0].edges.U); Assert.Equal(grafsResult[0].edges.V, grafs[0].edges.V); Assert.Equal(grafsResult[1].edges.U, grafs[1].edges.U); Assert.Equal(grafsResult[1].edges.V, grafs[1].edges.V); Assert.Equal(grafsResult[0].edges.distance, grafs[0].edges.distance); Assert.Equal(grafsResult[0].edges.edgesCount, grafs[0].edges.edgesCount); Assert.Equal(grafsResult[0].edges.verticlesCount, grafs[0].edges.verticlesCount); Assert.Equal(grafsResult[1].edges.distance, grafs[1].edges.distance); Assert.Equal(grafsResult[1].edges.edgesCount, grafs[1].edges.edgesCount); Assert.Equal(grafsResult[1].edges.verticlesCount, grafs[1].edges.verticlesCount); }
public PasazerKrotkodystansowy(int czasWsiadania, int czasWysiadania, Przystanek przystanekPoczatkowy, Przystanek przystanekKoncowy, Graf <ulong> graf, TimeSpan czasOstatniegoStworzeniaTrasy) : base(czasWsiadania, czasWysiadania, przystanekPoczatkowy, przystanekKoncowy, czasOstatniegoStworzeniaTrasy) { this.graf = graf; var temp = CzyTrasaObliczona(przystanekPoczatkowy, przystanekKoncowy); if (temp == null) { trasaPasazera = ZnajdzTrase(graf); if (trasaPasazera != null) { obliczoneTrasy.Add(trasaPasazera); } this.czasOstatniegoStworzeniaTrasy = czasOstatniegoStworzeniaTrasy; } else { trasaPasazera = new TrasaPasazera(temp, temp.CzasWaznosci); } }
private static int[,] GrafToMatrix(Graf graf) { int[,] tomb = new int[graf.Csucsok.Count, graf.Csucsok.Count]; for (int i = 0; i < graf.Csucsok.Count; i++) { for (int j = 0; j < graf.Csucsok.Count; j++) { if (graf.VezetEL(graf.Csucsok[i], graf.Csucsok[j])) { El el = graf.GetEl(graf.Csucsok[i], graf.Csucsok[j]); tomb[i, j] = (int)el.Tavolsag; } else { tomb[i, j] = 0; } } } return(tomb); }
/// <summary> /// Соединение точек линиями /// </summary> /// <param name="tree">Граф</param> /// <param name="Look">Массив рассмотренных точек</param> /// <param name="Not_Look">Массив потенциальных точек</param> /// <param name="index">Индекс карты</param> public void getWay(Graf tree, Dictionary <long, List <long> > Look, Dictionary <long, List <long> > Not_Look, int index) { using (var g = Graphics.FromImage(temp_map)) { foreach (var item in Not_Look) { Point first_point = getPoint(tree[item.Key].parametrs.coords, index); foreach (var item_val in item.Value) { Point second_point = getPoint(tree[item_val].parametrs.coords, index); g.DrawLine(new Pen(Brushes.Blue, 1), first_point, second_point); } } foreach (var item in Look) { Point first_point = getPoint(tree[item.Key].parametrs.coords, index); foreach (var item_val in item.Value) { Point second_point = getPoint(tree[item_val].parametrs.coords, index); g.DrawLine(new Pen(Brushes.Blue, 1), first_point, second_point); } } } }
public void DifferenceTest0() { var graf = new Graf<char>(); var v0Vertex = new Vertex<char>('0'); var v1Vertex = new Vertex<char>('1'); var v2Vertex = new Vertex<char>('2'); var v3Vertex = new Vertex<char>('3'); var v4Vertex = new Vertex<char>('4'); var v5Vertex = new Vertex<char>('5'); v0Vertex.AddDirectedEdge(0, v1Vertex); v0Vertex.AddDirectedEdge(0, v2Vertex); v0Vertex.AddDirectedEdge(0, v3Vertex); v0Vertex.AddDirectedEdge(0, v4Vertex); v0Vertex.AddDirectedEdge(0, v5Vertex); v1Vertex.AddDirectedEdge(5, v3Vertex); v1Vertex.AddDirectedEdge(4, v4Vertex); v2Vertex.AddDirectedEdge(0, v1Vertex); v3Vertex.AddDirectedEdge(-1, v4Vertex); v3Vertex.AddDirectedEdge(-3, v5Vertex); v4Vertex.AddDirectedEdge(-3, v5Vertex); v5Vertex.AddDirectedEdge(-1, v1Vertex); v5Vertex.AddDirectedEdge(1, v2Vertex); graf.AddVertex(v0Vertex); graf.AddVertex(v1Vertex); graf.AddVertex(v2Vertex); graf.AddVertex(v3Vertex); graf.AddVertex(v4Vertex); graf.AddVertex(v5Vertex); bool res = graf.BellmanFordShortestPaths(v0Vertex); Assert.Equal(true, res); Assert.Equal(0, v0Vertex.DiscoveryTime); Assert.Equal(-5, v1Vertex.DiscoveryTime); Assert.Equal(-3, v2Vertex.DiscoveryTime); Assert.Equal(0, v3Vertex.DiscoveryTime); Assert.Equal(-1, v4Vertex.DiscoveryTime); Assert.Equal(-4, v5Vertex.DiscoveryTime); }
public Laba4DFS(MainDrawer mainDrawer, Graf graf) { _mainDrawer = mainDrawer; _graf = graf; }
internal Floyd(Graf graf) { _graf = graf; Matrix = ConvertToMatrix.GetMatrix(_graf); ApplyAlgoritm(); }
public double calc(int amount, string fromUnit, string toUnit) { var from = (Units) Enum.Parse(typeof (Units), fromUnit.Replace("in", "inch")); var to = (Units) Enum.Parse(typeof (Units), toUnit.Replace("in", "inch")); var dgraf = new Graf<Units>(); var ftVertex = new Vertex<Units>(Units.ft); var inVertex = new Vertex<Units>(Units.inch); var ydVertex = new Vertex<Units>(Units.yd); var miVertex = new Vertex<Units>(Units.mi); ftVertex.AddDirectedEdge(12, inVertex); inVertex.AddDirectedEdge(1D / 12, ftVertex); ydVertex.AddDirectedEdge(3, ftVertex); ftVertex.AddDirectedEdge(1D / 3, ydVertex); miVertex.AddDirectedEdge(1760, ydVertex); ydVertex.AddDirectedEdge(1D / 1760, miVertex); dgraf.AddVertex(ftVertex); dgraf.AddVertex(inVertex); dgraf.AddVertex(ydVertex); dgraf.AddVertex(miVertex); var source = dgraf.Vertexes.FirstOrDefault(vertex => vertex.Key == from); var target = dgraf.Vertexes.FirstOrDefault(vertex => vertex.Key == to); var vertexPath = dgraf.GetBreadthPath(source, target).ToList(); var edgePath = new System.Collections.Generic.Stack<Edge<Units>>(); if (target.Color != Vertex<Units>.VertexColor.Black) return 0; var currentVertex = target; while (currentVertex != null && currentVertex != source && currentVertex.Parent != null) { var currentEdge = currentVertex.Parent.Edges.FirstOrDefault(edge => edge.Target == currentVertex); edgePath.Push(currentEdge); currentVertex = currentVertex.Parent; } if (source == target) return amount; if (!edgePath.Any()) return 0; double res = amount; double weigth = 1; foreach (var pathEdge in edgePath) weigth *= pathEdge.Weigth; return res * weigth; }
public void SingleSourceTest3() { var graf = new Graf<char>(); var sVertex = new Vertex<char>('s'); var tVertex = new Vertex<char>('t'); var xVertex = new Vertex<char>('x'); var yVertex = new Vertex<char>('y'); var zVertex = new Vertex<char>('z'); sVertex.AddDirectedEdge(10, tVertex); sVertex.AddDirectedEdge(5, yVertex); tVertex.AddDirectedEdge(1, xVertex); tVertex.AddDirectedEdge(2, yVertex); xVertex.AddDirectedEdge(4, zVertex); zVertex.AddDirectedEdge(6, xVertex); zVertex.AddDirectedEdge(7, sVertex); yVertex.AddDirectedEdge(3, tVertex); yVertex.AddDirectedEdge(9, xVertex); yVertex.AddDirectedEdge(2, zVertex); graf.AddVertex(sVertex); graf.AddVertex(tVertex); graf.AddVertex(xVertex); graf.AddVertex(yVertex); graf.AddVertex(zVertex); graf.DejkstraShortestPaths(sVertex); Assert.Equal(0, sVertex.DiscoveryTime); Assert.Equal(8, tVertex.DiscoveryTime); Assert.Equal(9, xVertex.DiscoveryTime); Assert.Equal(5, yVertex.DiscoveryTime); Assert.Equal(7, zVertex.DiscoveryTime); }
public void SingleSourceTest1() { var graf = new Graf<char>(); var sVertex = new Vertex<char>('s'); var tVertex = new Vertex<char>('t'); var xVertex = new Vertex<char>('x'); var yVertex = new Vertex<char>('y'); var zVertex = new Vertex<char>('z'); sVertex.AddDirectedEdge(6, tVertex); sVertex.AddDirectedEdge(7, yVertex); tVertex.AddDirectedEdge(-5, xVertex); xVertex.AddDirectedEdge(2, tVertex); tVertex.AddDirectedEdge(8, yVertex); zVertex.AddDirectedEdge(7, xVertex); zVertex.AddDirectedEdge(2, sVertex); tVertex.AddDirectedEdge(-4, zVertex); yVertex.AddDirectedEdge(-3, xVertex); yVertex.AddDirectedEdge(9, zVertex); graf.AddVertex(sVertex); graf.AddVertex(tVertex); graf.AddVertex(xVertex); graf.AddVertex(yVertex); graf.AddVertex(zVertex); bool res = graf.BellmanFordShortestPaths(sVertex); Assert.Equal(false, res); }
public void ShortestsPathsTest1() { var graf = new Graf<char>(); var v1Vertex = new Vertex<char>('1'); var v2Vertex = new Vertex<char>('2'); var v3Vertex = new Vertex<char>('3'); var v4Vertex = new Vertex<char>('4'); var v5Vertex = new Vertex<char>('5'); v1Vertex.AddDirectedEdge(3, v2Vertex); v1Vertex.AddDirectedEdge(-4, v5Vertex); v2Vertex.AddDirectedEdge(1, v4Vertex); v2Vertex.AddDirectedEdge(7, v5Vertex); v3Vertex.AddDirectedEdge(4, v2Vertex); v4Vertex.AddDirectedEdge(2, v1Vertex); v4Vertex.AddDirectedEdge(-5, v3Vertex); v5Vertex.AddDirectedEdge(6, v4Vertex); graf.AddVertex(v1Vertex); graf.AddVertex(v2Vertex); graf.AddVertex(v3Vertex); graf.AddVertex(v4Vertex); graf.AddVertex(v5Vertex); var res = graf.GetAllPairsShortestsPathsFloydWarshall(graf.GetWeights()); Assert.Equal(0, res.Item1[0, 0]); Assert.Equal(3, res.Item1[1, 0]); Assert.Equal(7, res.Item1[2, 0]); Assert.Equal(2, res.Item1[3, 0]); Assert.Equal(8, res.Item1[4, 0]); Assert.Equal(1, res.Item1[0, 1]); Assert.Equal(0, res.Item1[1, 1]); Assert.Equal(4, res.Item1[2, 1]); Assert.Equal(-1, res.Item1[3, 1]); Assert.Equal(5, res.Item1[4, 1]); Assert.Equal(-3, res.Item1[0, 2]); Assert.Equal(-4, res.Item1[1, 2]); Assert.Equal(0, res.Item1[2, 2]); Assert.Equal(-5, res.Item1[3, 2]); Assert.Equal(1, res.Item1[4, 2]); Assert.Equal(2, res.Item1[0, 3]); Assert.Equal(1, res.Item1[1, 3]); Assert.Equal(5, res.Item1[2, 3]); Assert.Equal(0, res.Item1[3, 3]); Assert.Equal(6, res.Item1[4, 3]); Assert.Equal(-4, res.Item1[0, 4]); Assert.Equal(-1, res.Item1[1, 4]); Assert.Equal(3, res.Item1[2, 4]); Assert.Equal(-2, res.Item1[3, 4]); Assert.Equal(0, res.Item1[4, 4]); Assert.Null(res.Item2[0, 0]); Assert.Equal(3, res.Item2[1, 0].Value); Assert.Equal(3, res.Item2[2, 0].Value); Assert.Equal(3, res.Item2[3, 0].Value); Assert.Equal(3, res.Item2[4, 0].Value); Assert.Equal(2, res.Item2[0, 1].Value); Assert.Null(res.Item2[1, 1]); Assert.Equal(2, res.Item2[2, 1].Value); Assert.Equal(2, res.Item2[3, 1].Value); Assert.Equal(2, res.Item2[4, 1].Value); Assert.Equal(3, res.Item2[0, 2].Value); Assert.Equal(3, res.Item2[1, 2].Value); Assert.Null(res.Item2[2, 2]); Assert.Equal(3, res.Item2[3, 2].Value); Assert.Equal(3, res.Item2[4, 2].Value); Assert.Equal(4, res.Item2[0, 3].Value); Assert.Equal(1, res.Item2[1, 3].Value); Assert.Equal(1, res.Item2[2, 3].Value); Assert.Null(res.Item2[3, 3]); Assert.Equal(4, res.Item2[4, 3].Value); Assert.Equal(0, res.Item2[0, 4].Value); Assert.Equal(0, res.Item2[1, 4].Value); Assert.Equal(0, res.Item2[2, 4].Value); Assert.Equal(0, res.Item2[3, 4].Value); Assert.Null(res.Item2[4, 4]); }
static void Main(string[] args) { const int n = 4;// Количество вершин в графе int versh = 0; //Для таблицы смежности 4 на 4 = >Максимальное число цветов равно количеству вершин int[] colors = { 1, 2, 3, 4 };// // Создадим графф Graf[] graf = new Graf[n];//Граф //Матрица смежности int[,] m = new int[n, n] { { 0, 1, 1, 0 }, { 1, 0, 1, 0 }, { 1, 1, 0, 1 }, { 0, 0, 1, 0 } }; ЗаполнитьГраф(graf, n);//Забиваем все цвета по умолчанию - 100 //Находим степени вершин по матрице смежности for (int i = 0; i < n; i++, versh++) { graf[versh].stepeni = 0; graf[versh].number = i; for (int j = 0; j < n; j++) { if (m[i, j] == 1) { graf[versh].stepeni++; } } } //Сортировка структуры графа по степеням с наибольшей по наименьшую for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (graf[i].stepeni > graf[j].stepeni) { Graf temp = graf[i]; graf[i] = graf[j]; graf[j] = temp; } } } //Алгоритм по присвоению цветов int t = 0, flag, metka = 0; for (int x = 0; НеВсёЗакрашено(graf); x++)//Цикл по цветам. Условие выхода - все цвета окрашены! Пока не раскрашено( НеВсёЗакрашено) - работает { if (graf[x].color == 100) { graf[x].color = colors[x];//Присваиваем первый цвет } // продолжаем дальше; for (int i = 0; i < n; i++) //цикл, чтобы не только одни вершины раскрасить, а ВСЕ НЕ смежные { t = graf[i].number; //Запоминаем номер исследуемой вершины flag = 0; //Обнуляем Флаг - считает количество вершин, не раскрашенных как исследуемая for (int j = 0; j < n; j++) //Идем по строке матрицы по номеру { //Блок условий проверки на возможность "раскраски" вершины. Под раскраской - подразумевается присваивание номера if ((m[t, j] == 1 && t != j))//Если 1 - можно перейти на какое-то ребро и это ребро - не та же самая вершина(которая рассматривается { for (int s = 0; s < n; s++) { if (j == graf[s].number && graf[s].color != colors[x]) { flag++; } } } ; if (graf[j].number == t) { metka = j; } if (flag == graf[metka].stepeni && graf[metka].color == 100)//Если вершина ещё не посещена - забиваем в неё определенный цвет из массива цветов { graf[metka].color = colors[x]; } } } } Console.WriteLine("Результат раскраски - второй столбик. Первый столбик - номер вершины"); //Показываем результат ПечатьГрафа(graf); Console.ReadKey(); }
internal Warshall(Graf graf) { _graf = graf; _intMatrix = ConvertToMatrix.GetMatrix(_graf); ApplyAlgoritm(); }
public RGR(Graf graf) { _graf = graf; }
public DFS(Graf graf) { _graf = graf; _matrix = ConvertToMatrix.GetMatrix(_graf); }
static void Main(string[] args) { try { var m1 = new HadtortenetiMuzeum(); var csucs1 = new Csucs(m1); var m2 = new IparmuveszetiMuzeum(); var csucs2 = new Csucs(m2); var m3 = new NeprajziMuzeum(); var csucs3 = new Csucs(m3); var m4 = new SzepmuveszetiMuzeum(); var csucs4 = new Csucs(m4); var m5 = new Babamuzeum(); var csucs5 = new Csucs(m5); m1.HasonloMuzeumokElejereBeszur(m2); m1.HasonloMuzeumokElejereBeszur(m3); m1.HasonloMuzeumokElejereBeszur(m4); var hasonlo = m1.HasonloMuzeumok(); m1.HasonloMuzeumTorol(m3); var hasonlo2 = m1.HasonloMuzeumok(); var graf = new Graf(); graf.CsucsHozzaad(csucs1); graf.CsucsHozzaad(csucs2); graf.CsucsHozzaad(csucs3); graf.CsucsHozzaad(csucs4); graf.CsucsHozzaad(csucs5); var el1_2 = new El(csucs1, csucs2, 10); var el1_3 = new El(csucs1, csucs3, 1); var el1_4 = new El(csucs1, csucs4, 1); var el2_3 = new El(csucs3, csucs2, 2); var el2_4 = new El(csucs2, csucs2, 4); var el3_4 = new El(csucs3, csucs4, 1); var el4_5 = new El(csucs4, csucs5, 1); graf.ElHozzaad(el1_2); graf.ElHozzaad(el1_3); graf.ElHozzaad(el1_4); graf.ElHozzaad(el2_3); graf.ElHozzaad(el2_4); graf.ElHozzaad(el3_4); graf.ElHozzaad(el4_5); var utvonalGraf = graf.UtvonalGraf(csucs1, csucs5, new[] { csucs3 }); graf.EleketFrissit(RandomEl); } catch (Exception ex) { Console.WriteLine(ex.Message); } Console.ReadKey(); }
static void Main(string[] args) { int n = 0;// Количество вершин в графе int k = 0; int versh = 0; StreamReader sr = new StreamReader("input.txt"); string line = sr.ReadLine(); string[] mas = line.Split(' '); n = Convert.ToInt32(mas[0]); k = Convert.ToInt32(mas[1]); int[,] m = new int[n, n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { m[i, j] = 0; } } ; //Для таблицы смежности 4 на 4 = >Максимальное число цветов равно количеству вершин int[] colors = new int[n];// for (int i = 0; i < n; i++) { colors[i] = i + 1; } do { line = sr.ReadLine(); mas = line.Split(' '); int i = Convert.ToInt32(mas[0]) - 1; int j = Convert.ToInt32(mas[1]) - 1; m[i, j] = 1; m[j, i] = 1; }while (!sr.EndOfStream); sr.Close(); // Создадим графф Graf[] graf = new Graf[n]; //Граф Fill(graf, n); //Забиваем все цвета по умолчанию - -1 //Находим степени вершин по матрице смежности for (int i = 0; i < n; i++, versh++) { graf[versh].stepeni = 0; graf[versh].number = i; for (int j = 0; j < n; j++) { if (m[i, j] == 1) { graf[versh].stepeni++; } } } //Сортировка структуры графа по степеням с наибольшей по наименьшую for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (graf[i].stepeni > graf[j].stepeni) { Graf temp = graf[i]; graf[i] = graf[j]; graf[j] = temp; } } } //Алгоритм по присвоению цветов int t = 0, flag, metka = 0; for (int x = 0; NotAllinColor(graf); x++)//Цикл по цветам. Условие выхода - все цвета окрашены! Пока не раскрашено( НеВсёЗакрашено) - работает { if (graf[x].color == -1) { graf[x].color = colors[x];//Присваиваем первый цвет } // продолжаем дальше; for (int i = 0; i < n; i++) //цикл, чтобы не только одни вершины раскрасить, а ВСЕ НЕ смежные { t = graf[i].number; //Запоминаем номер исследуемой вершины flag = 0; //Обнуляем Флаг - считает количество вершин, не раскрашенных как исследуемая for (int j = 0; j < n; j++) //Идем по строке матрицы по номеру { //Блок условий проверки на возможность "раскраски" вершины. Под раскраской - подразумевается присваивание номера if ((m[t, j] == 1 && t != j))//Если 1 - можно перейти на какое-то ребро и это ребро - не та же самая вершина(которая рассматривается { for (int s = 0; s < n; s++) { if (j == graf[s].number && graf[s].color != colors[x]) { flag++; } } } ; if (graf[j].number == t) { metka = j; } if (flag == graf[metka].stepeni && graf[metka].color == -1)//Если вершина ещё не посещена - забиваем в неё определенный цвет из массива цветов { graf[metka].color = colors[x]; } } } } PrintMas(m, n); Console.WriteLine(); Console.WriteLine("Результат раскраски - второй столбик. Первый столбик - номер вершины"); //Показываем результат PrintGraph(graf); Console.ReadKey(); }
public void TopologicalTest3() { var graf = new Graf<char>(); var mVertex = new Vertex<char>('m'); var nVertex = new Vertex<char>('n'); var oVertex = new Vertex<char>('o'); var pVertex = new Vertex<char>('p'); var qVertex = new Vertex<char>('q'); var rVertex = new Vertex<char>('r'); var sVertex = new Vertex<char>('s'); var tVertex = new Vertex<char>('t'); var uVertex = new Vertex<char>('u'); var vVertex = new Vertex<char>('v'); var wVertex = new Vertex<char>('w'); var xVertex = new Vertex<char>('x'); var yVertex = new Vertex<char>('y'); var zVertex = new Vertex<char>('z'); mVertex.AddDirectedEdge(1, qVertex); mVertex.AddDirectedEdge(1, rVertex); mVertex.AddDirectedEdge(1, xVertex); nVertex.AddDirectedEdge(1, qVertex); nVertex.AddDirectedEdge(1, uVertex); nVertex.AddDirectedEdge(1, oVertex); oVertex.AddDirectedEdge(1, rVertex); oVertex.AddDirectedEdge(1, sVertex); pVertex.AddDirectedEdge(1, oVertex); pVertex.AddDirectedEdge(1, sVertex); pVertex.AddDirectedEdge(1, zVertex); qVertex.AddDirectedEdge(1, tVertex); rVertex.AddDirectedEdge(1, uVertex); rVertex.AddDirectedEdge(1, yVertex); sVertex.AddDirectedEdge(1, rVertex); uVertex.AddDirectedEdge(1, tVertex); vVertex.AddDirectedEdge(1, wVertex); vVertex.AddDirectedEdge(1, xVertex); wVertex.AddDirectedEdge(1, zVertex); yVertex.AddDirectedEdge(1, vVertex); graf.AddVertex(mVertex); graf.AddVertex(nVertex); graf.AddVertex(oVertex); graf.AddVertex(pVertex); graf.AddVertex(qVertex); graf.AddVertex(rVertex); graf.AddVertex(sVertex); graf.AddVertex(tVertex); graf.AddVertex(uVertex); graf.AddVertex(vVertex); graf.AddVertex(wVertex); graf.AddVertex(xVertex); graf.AddVertex(yVertex); graf.AddVertex(zVertex); graf.DFS(); var topologicalSort = graf.GetTopologicalSort().ToList(); Assert.NotNull(topologicalSort); Assert.Equal(14, topologicalSort.Count); Assert.Equal('p', topologicalSort.First().Key); Assert.Equal(27, topologicalSort.First().DiscoveryTime); Assert.Equal(28, topologicalSort.First().FinishingTime); Assert.Equal('t', topologicalSort.Last().Key); Assert.Equal(3, topologicalSort.Last().DiscoveryTime); Assert.Equal(4, topologicalSort.Last().FinishingTime); var grafT = graf.GetGrafT(); var components = grafT.GetStronglyConnectedComponents(topologicalSort); Assert.Equal(14, components.Count); }
public void MSTTest1() { var graf = new Graf<char>(); var bVertex = new Vertex<char>('b'); var cVertex = new Vertex<char>('c'); var dVertex = new Vertex<char>('d'); var aVertex = new Vertex<char>('a'); var iVertex = new Vertex<char>('i'); var eVertex = new Vertex<char>('e'); var hVertex = new Vertex<char>('h'); var gVertex = new Vertex<char>('g'); var fVertex = new Vertex<char>('f'); aVertex.AddUnDirectedEdge(4, bVertex); bVertex.AddUnDirectedEdge(8, cVertex); cVertex.AddUnDirectedEdge(7, dVertex); dVertex.AddUnDirectedEdge(9, eVertex); dVertex.AddUnDirectedEdge(14, fVertex); eVertex.AddUnDirectedEdge(10, fVertex); aVertex.AddUnDirectedEdge(8, hVertex); bVertex.AddUnDirectedEdge(11, hVertex); cVertex.AddUnDirectedEdge(2, iVertex); cVertex.AddUnDirectedEdge(4, fVertex); iVertex.AddUnDirectedEdge(7, hVertex); iVertex.AddUnDirectedEdge(6, gVertex); hVertex.AddUnDirectedEdge(1, gVertex); gVertex.AddUnDirectedEdge(2, fVertex); graf.AddVertex(aVertex); graf.AddVertex(bVertex); graf.AddVertex(cVertex); graf.AddVertex(dVertex); graf.AddVertex(iVertex); graf.AddVertex(eVertex); graf.AddVertex(hVertex); graf.AddVertex(gVertex); graf.AddVertex(fVertex); var mstGraf = graf.GetMSTGrafKruskal(); double weigth = 0; for (int i = 0; i < mstGraf.Vertexes.Count; i++) { for (int j = 0; j < mstGraf.Vertexes[i].Edges.Count; j++) { mstGraf.Vertexes[i].Edges[j].Marked = false; } } for (int i = 0; i < mstGraf.Vertexes.Count; i++) { for (int j = 0; j < mstGraf.Vertexes[i].Edges.Count; j++) { var adjacentVertex = mstGraf.Vertexes[i].Edges[j].Other(mstGraf.Vertexes[i]); if (!mstGraf.Vertexes[i].Edges[j].Marked) { weigth += mstGraf.Vertexes[i].Edges[j].Weigth; mstGraf.Vertexes[i].Edges[j].Marked = true; } } } Assert.Equal(37, weigth); }
public void DFSTest1() { var graf = new Graf<char>(); var qVertex = new Vertex<char>('q'); var rVertex = new Vertex<char>('r'); var sVertex = new Vertex<char>('s'); var tVertex = new Vertex<char>('t'); var uVertex = new Vertex<char>('u'); var vVertex = new Vertex<char>('v'); var wVertex = new Vertex<char>('w'); var xVertex = new Vertex<char>('x'); var yVertex = new Vertex<char>('y'); var zVertex = new Vertex<char>('z'); qVertex.AddDirectedEdge(1, sVertex); qVertex.AddDirectedEdge(1, tVertex); qVertex.AddDirectedEdge(1, wVertex); sVertex.AddDirectedEdge(1, vVertex); vVertex.AddDirectedEdge(1, wVertex); wVertex.AddDirectedEdge(1, sVertex); tVertex.AddDirectedEdge(1, xVertex); tVertex.AddDirectedEdge(1, yVertex); xVertex.AddDirectedEdge(1, zVertex); yVertex.AddDirectedEdge(1, qVertex); rVertex.AddDirectedEdge(1, uVertex); rVertex.AddDirectedEdge(1, yVertex); uVertex.AddDirectedEdge(1, yVertex); graf.AddVertex(qVertex); graf.AddVertex(rVertex); graf.AddVertex(sVertex); graf.AddVertex(tVertex); graf.AddVertex(uVertex); graf.AddVertex(vVertex); graf.AddVertex(wVertex); graf.AddVertex(xVertex); graf.AddVertex(yVertex); graf.AddVertex(zVertex); graf.DFS(); Assert.Equal(1, qVertex.DiscoveryTime); Assert.Equal(16, qVertex.FinishingTime); Assert.Equal(17, rVertex.DiscoveryTime); Assert.Equal(20, rVertex.FinishingTime); Assert.Equal(2, sVertex.DiscoveryTime); Assert.Equal(7, sVertex.FinishingTime); Assert.Equal(8, tVertex.DiscoveryTime); Assert.Equal(15, tVertex.FinishingTime); Assert.Equal(18, uVertex.DiscoveryTime); Assert.Equal(19, uVertex.FinishingTime); Assert.Equal(3, vVertex.DiscoveryTime); Assert.Equal(6, vVertex.FinishingTime); Assert.Equal(4, wVertex.DiscoveryTime); Assert.Equal(5, wVertex.FinishingTime); Assert.Equal(9, xVertex.DiscoveryTime); Assert.Equal(12, xVertex.FinishingTime); Assert.Equal(13, yVertex.DiscoveryTime); Assert.Equal(14, yVertex.FinishingTime); Assert.Equal(10, zVertex.DiscoveryTime); Assert.Equal(11, zVertex.FinishingTime); }
public TrasaPasazera ZnajdzTrase(Graf <ulong> graf) { return(ZnajdzNajwygodniejszaTrase(graf)); }
public void ShortestsPathsTest2() { var graf = new Graf<char>(); var v1Vertex = new Vertex<char>('1'); var v2Vertex = new Vertex<char>('2'); var v3Vertex = new Vertex<char>('3'); var v4Vertex = new Vertex<char>('4'); var v5Vertex = new Vertex<char>('5'); v1Vertex.AddDirectedEdge(3, v2Vertex); v1Vertex.AddDirectedEdge(-4, v5Vertex); v2Vertex.AddDirectedEdge(1, v4Vertex); v2Vertex.AddDirectedEdge(7, v5Vertex); v3Vertex.AddDirectedEdge(4, v2Vertex); v4Vertex.AddDirectedEdge(2, v1Vertex); v4Vertex.AddDirectedEdge(-5, v3Vertex); v5Vertex.AddDirectedEdge(6, v4Vertex); graf.AddVertex(v1Vertex); graf.AddVertex(v2Vertex); graf.AddVertex(v3Vertex); graf.AddVertex(v4Vertex); graf.AddVertex(v5Vertex); var res = graf.GetAllPairsShortestsPathsJohnson(); Assert.Equal(0, res[0, 0]); Assert.Equal(3, res[1, 0]); Assert.Equal(7, res[2, 0]); Assert.Equal(2, res[3, 0]); Assert.Equal(8, res[4, 0]); Assert.Equal(1, res[0, 1]); Assert.Equal(0, res[1, 1]); Assert.Equal(4, res[2, 1]); Assert.Equal(-1, res[3, 1]); Assert.Equal(5, res[4, 1]); Assert.Equal(-3, res[0, 2]); Assert.Equal(-4, res[1, 2]); Assert.Equal(0, res[2, 2]); Assert.Equal(-5, res[3, 2]); Assert.Equal(1, res[4, 2]); Assert.Equal(2, res[0, 3]); Assert.Equal(1, res[1, 3]); Assert.Equal(5, res[2, 3]); Assert.Equal(0, res[3, 3]); Assert.Equal(6, res[4, 3]); Assert.Equal(-4, res[0, 4]); Assert.Equal(-1, res[1, 4]); Assert.Equal(3, res[2, 4]); Assert.Equal(-2, res[3, 4]); Assert.Equal(0, res[4, 4]); }
private TrasaPasazera ZnajdzTrase(Graf <byte> graf) { return(ZnajdzNajwygodniejszaTrase(graf)); }
public void SingleSourceTest2() { var graf = new Graf<char>(); var rVertex = new Vertex<char>('r'); var sVertex = new Vertex<char>('s'); var tVertex = new Vertex<char>('t'); var xVertex = new Vertex<char>('x'); var yVertex = new Vertex<char>('y'); var zVertex = new Vertex<char>('z'); rVertex.AddDirectedEdge(5, sVertex); rVertex.AddDirectedEdge(3, tVertex); sVertex.AddDirectedEdge(2, tVertex); sVertex.AddDirectedEdge(6, xVertex); tVertex.AddDirectedEdge(7, xVertex); tVertex.AddDirectedEdge(4, yVertex); tVertex.AddDirectedEdge(2, zVertex); xVertex.AddDirectedEdge(-1, yVertex); xVertex.AddDirectedEdge(-2, zVertex); yVertex.AddDirectedEdge(-2, zVertex); graf.AddVertex(rVertex); graf.AddVertex(sVertex); graf.AddVertex(tVertex); graf.AddVertex(xVertex); graf.AddVertex(yVertex); graf.AddVertex(zVertex); graf.TopologicalShortestPaths(sVertex); var topologicalSort = graf.GetTopologicalSort().ToList(); Assert.NotNull(topologicalSort); Assert.Equal(double.PositiveInfinity, rVertex.DiscoveryTime); Assert.Equal(0, sVertex.DiscoveryTime); Assert.Equal(2, tVertex.DiscoveryTime); Assert.Equal(6, xVertex.DiscoveryTime); Assert.Equal(5, yVertex.DiscoveryTime); Assert.Equal(3, zVertex.DiscoveryTime); }
static void Main(string[] args) { const int n = 4;// Количество вершин в графе int versh = 0; //Для таблицы смежности 4 на 4 = >Максимальное число цветов равно количеству вершин int[] colors = { 1, 2, 3, 4 };// // Создадим графф Graf[] graf = new Graf[n];//Граф //Матрица смежности int[,] m = new int[n, n]{{0, 1, 1, 0}, {1, 0, 1, 0}, {1, 1, 0, 1}, {0, 0, 1, 0}}; ЗаполнитьГраф(graf, n);//Забиваем все цвета по умолчанию - 100 //Находим степени вершин по матрице смежности for (int i = 0; i < n; i++, versh++) { graf[versh].stepeni = 0; graf[versh].number = i; for (int j = 0; j < n; j++) { if (m[i, j] == 1) graf[versh].stepeni++; } } //Сортировка структуры графа по степеням с наибольшей по наименьшую for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) { if (graf[i].stepeni > graf[j].stepeni) { Graf temp = graf[i]; graf[i] = graf[j]; graf[j] = temp; } } //Алгоритм по присвоению цветов int t = 0, flag, metka = 0; for (int x = 0; НеВсёЗакрашено(graf); x++)//Цикл по цветам. Условие выхода - все цвета окрашены! Пока не раскрашено( НеВсёЗакрашено) - работает { if (graf[x].color == 100) graf[x].color = colors[x];//Присваиваем первый цвет // продолжаем дальше; for (int i = 0; i < n; i++)//цикл, чтобы не только одни вершины раскрасить, а ВСЕ НЕ смежные { t = graf[i].number;//Запоминаем номер исследуемой вершины flag = 0;//Обнуляем Флаг - считает количество вершин, не раскрашенных как исследуемая for (int j = 0; j < n; j++)//Идем по строке матрицы по номеру { //Блок условий проверки на возможность "раскраски" вершины. Под раскраской - подразумевается присваивание номера if ((m[t, j] == 1 && t != j))//Если 1 - можно перейти на какое-то ребро и это ребро - не та же самая вершина(которая рассматривается { for (int s = 0; s < n; s++) if (j == graf[s].number && graf[s].color != colors[x]) { flag++; } }; if (graf[j].number == t) metka = j; if (flag == graf[metka].stepeni && graf[metka].color == 100)//Если вершина ещё не посещена - забиваем в неё определенный цвет из массива цветов graf[metka].color = colors[x]; } } } Console.WriteLine("Результат раскраски - второй столбик. Первый столбик - номер вершины"); //Показываем результат ПечатьГрафа(graf); Console.ReadKey(); }
public void TopologicalTest1() { var graf = new Graf<char>(); var qVertex = new Vertex<char>('q'); var rVertex = new Vertex<char>('r'); var sVertex = new Vertex<char>('s'); var tVertex = new Vertex<char>('t'); var uVertex = new Vertex<char>('u'); var vVertex = new Vertex<char>('v'); var wVertex = new Vertex<char>('w'); var xVertex = new Vertex<char>('x'); var yVertex = new Vertex<char>('y'); var zVertex = new Vertex<char>('z'); qVertex.AddDirectedEdge(1, sVertex); qVertex.AddDirectedEdge(1, tVertex); qVertex.AddDirectedEdge(1, wVertex); sVertex.AddDirectedEdge(1, vVertex); vVertex.AddDirectedEdge(1, wVertex); wVertex.AddDirectedEdge(1, sVertex); tVertex.AddDirectedEdge(1, xVertex); tVertex.AddDirectedEdge(1, yVertex); xVertex.AddDirectedEdge(1, zVertex); yVertex.AddDirectedEdge(1, qVertex); rVertex.AddDirectedEdge(1, uVertex); rVertex.AddDirectedEdge(1, yVertex); uVertex.AddDirectedEdge(1, yVertex); graf.AddVertex(qVertex); graf.AddVertex(rVertex); graf.AddVertex(sVertex); graf.AddVertex(tVertex); graf.AddVertex(uVertex); graf.AddVertex(vVertex); graf.AddVertex(wVertex); graf.AddVertex(xVertex); graf.AddVertex(yVertex); graf.AddVertex(zVertex); graf.DFS(); Assert.Null(graf.GetTopologicalSort()); }
public Process() { _graf = new Graf(); _mainDrawer = new MainDrawer(_graf); }
public void TopologicalTest4() { var graf = new Graf<char>(); var bVertex = new Vertex<char>('b'); var cVertex = new Vertex<char>('c'); var dVertex = new Vertex<char>('d'); var aVertex = new Vertex<char>('a'); var iVertex = new Vertex<char>('i'); var eVertex = new Vertex<char>('e'); var hVertex = new Vertex<char>('h'); var gVertex = new Vertex<char>('g'); var fVertex = new Vertex<char>('f'); aVertex.AddUnDirectedEdge(4, bVertex); bVertex.AddUnDirectedEdge(8, cVertex); cVertex.AddUnDirectedEdge(7, dVertex); dVertex.AddUnDirectedEdge(9, eVertex); dVertex.AddUnDirectedEdge(14, fVertex); eVertex.AddUnDirectedEdge(10, fVertex); aVertex.AddUnDirectedEdge(8, hVertex); bVertex.AddUnDirectedEdge(11, hVertex); cVertex.AddUnDirectedEdge(2, iVertex); cVertex.AddUnDirectedEdge(4, fVertex); iVertex.AddUnDirectedEdge(7, hVertex); iVertex.AddUnDirectedEdge(6, gVertex); hVertex.AddUnDirectedEdge(1, gVertex); gVertex.AddUnDirectedEdge(2, fVertex); graf.AddVertex(aVertex); graf.AddVertex(bVertex); graf.AddVertex(cVertex); graf.AddVertex(dVertex); graf.AddVertex(iVertex); graf.AddVertex(eVertex); graf.AddVertex(hVertex); graf.AddVertex(gVertex); graf.AddVertex(fVertex); var components = graf.GetStronglyConnectedComponentsWithUnions(); Assert.Equal(1, components.Count); }
internal MainDrawer(Graf graf) { _graf = graf; }