//Получаем список индексов точек, из которых будем выбирать первый узел private static void GetFirstNodePretenders(int prevIndex, int prevNodesCount, List<IndexWithNodesCount> nodes, List<List<int>> starsForPoints, List<Point> orderedPoints) { List<int> allIndexes = new List<int>(); allIndexes.Add(prevIndex + 1); List<int> indexesOnTeCurrentLevel = new List<int>(); List<int> indexesOnTeNextLevel = new List<int>(); foreach (int ind in starsForPoints[prevIndex]) { indexesOnTeCurrentLevel.Add(ind); } foreach (int ind in indexesOnTeCurrentLevel) { allIndexes.Add(ind); } int count = orderedPoints.Count; int nodesCount = 1; while (allIndexes.Count < count) { foreach (int ind in indexesOnTeCurrentLevel) { foreach (int neiborNode in starsForPoints[ind - 1]) { if (!allIndexes.Contains(neiborNode)) { allIndexes.Add(neiborNode); indexesOnTeNextLevel.Add(neiborNode); } } } nodesCount++; indexesOnTeCurrentLevel.Clear(); foreach (int elem in indexesOnTeNextLevel) { indexesOnTeCurrentLevel.Add(elem); } indexesOnTeNextLevel.Clear(); } IndexWithNodesCount element = new IndexWithNodesCount(prevIndex, nodesCount); nodes.Add(element); if (nodesCount > prevNodesCount) { int minNeibors = starsForPoints[indexesOnTeCurrentLevel.ElementAt(0) - 1].Count; foreach (int ind in indexesOnTeCurrentLevel) { if (starsForPoints[ind - 1].Count < minNeibors) minNeibors = starsForPoints[ind - 1].Count; } foreach (int ind in indexesOnTeCurrentLevel) { if (starsForPoints[ind - 1].Count == minNeibors) GetFirstNodePretenders(ind - 1, nodesCount, nodes, starsForPoints, orderedPoints); } } }
//Получаем список индексов точек, из которых будем выбирать первый узел private static void GetFirstNodePretenders(int prevIndex, int prevNodesCount, List <IndexWithNodesCount> nodes, List <List <int> > starsForPoints, List <Point> orderedPoints) { List <int> allIndexes = new List <int>(); allIndexes.Add(prevIndex + 1); List <int> indexesOnTeCurrentLevel = new List <int>(); List <int> indexesOnTeNextLevel = new List <int>(); foreach (int ind in starsForPoints[prevIndex]) { indexesOnTeCurrentLevel.Add(ind); } foreach (int ind in indexesOnTeCurrentLevel) { allIndexes.Add(ind); } int count = orderedPoints.Count; int nodesCount = 1; while (allIndexes.Count < count) { foreach (int ind in indexesOnTeCurrentLevel) { foreach (int neiborNode in starsForPoints[ind - 1]) { if (!allIndexes.Contains(neiborNode)) { allIndexes.Add(neiborNode); indexesOnTeNextLevel.Add(neiborNode); } } } nodesCount++; indexesOnTeCurrentLevel.Clear(); foreach (int elem in indexesOnTeNextLevel) { indexesOnTeCurrentLevel.Add(elem); } indexesOnTeNextLevel.Clear(); } IndexWithNodesCount element = new IndexWithNodesCount(prevIndex, nodesCount); nodes.Add(element); if (nodesCount > prevNodesCount) { int minNeibors = starsForPoints[indexesOnTeCurrentLevel.ElementAt(0) - 1].Count; foreach (int ind in indexesOnTeCurrentLevel) { if (starsForPoints[ind - 1].Count < minNeibors) { minNeibors = starsForPoints[ind - 1].Count; } } foreach (int ind in indexesOnTeCurrentLevel) { if (starsForPoints[ind - 1].Count == minNeibors) { GetFirstNodePretenders(ind - 1, nodesCount, nodes, starsForPoints, orderedPoints); } } } }