public List <List <string> > ShortestWalkStripper(UndirectedWeightedGraph g, Line line, int maxLength, int perimeterEdgeWeight, bool flag, int loops) { //For adjusting odd walks UndirectedWeightedGraph adjustGraph = new UndirectedWeightedGraph(g); //Store paths List <List <string> > allPaths = new List <List <string> >(); //Find shortest path for (int i = 0; i < loops; i++) { if (g.N == 0) { base.Message = "Iterations " + i.ToString(); break; } //1.0 Perimeter weight if (perimeterEdgeWeight != 1) { //How to retrieve edges from a graph if it is represented as adjacency matrix? } //1.1 Split graph into connected subgraphs and pick first one List <UndirectedWeightedGraph> components = g.ConnectedComponents(g); for (int j = 0; j < components.Count; j++) { //Check if this component has one or two elements add them to path and deleter from graph if (components[j].N < 3) { allPaths.Add(components[j].GetVertexNames()); g.DeleteVertices(components[j].GetVertexNames()); components[j].DeleteVertices(components[j].GetVertexNames()); } //If not procede with Walker else { //1.0 Gather all points in that component; vertex name = point index List <string> vnames = components[j].GetVertexNames(); PointCloud componentCloud = new PointCloud(); foreach (var name in vnames) { componentCloud.Add(_pointCloud[Convert.ToInt32(name)].Location, new Vector3d(0, 0, Convert.ToInt32(name))); } //1.1 index of closest nodes to line endpoints; normals are indexes in global _pointCloud int indexA = componentCloud.ClosestPoint(line.From); string startId = ((int)componentCloud[indexA].Normal.Z).ToString(); componentCloud.RemoveAt(indexA); int indexB = componentCloud.ClosestPoint(line.To); string endId = ((int)componentCloud[indexB].Normal.Z).ToString(); //1.2 Shortest Path / Dijkstra List <string> path = components[j].FindPaths(startId, new List <string> { endId })[0]; //1.3 Limit the length if (path.Count > maxLength && maxLength > 1) { path.RemoveRange(0, path.Count - maxLength); } //1.4 Add path to path list allPaths.Add(path); //1.5 Remove edges from the main Graph g.DeleteVertices(path); } } //For } //Combine Odd Walks //2.0 Append very short segments to walks List <List <string> > oddPaths = new List <List <string> >(); List <List <string> > oddPaths2 = new List <List <string> >(); List <List <string> > normalPaths = new List <List <string> >(); for (int i = 0; i < allPaths.Count; i++) { if (allPaths[i].Count == 1) { oddPaths.Add(allPaths[i]); } else { normalPaths.Add(allPaths[i]); } } if (flag) { //2.1 Get neighbour walks by original adjacency map for (int i = 0; i < oddPaths.Count; i++) { Dictionary <string, int> neighbours = adjustGraph.GetAdjacentVertices(oddPaths[i][0], adjustGraph); List <string> _neighbours = new List <string>(neighbours.Keys); for (int j = 0; j < normalPaths.Count; j++) { if (_neighbours.Contains(normalPaths[j].First())) { normalPaths[j].Insert(0, oddPaths[i][0]); break; } else if (_neighbours.Contains(normalPaths[j].Last())) { normalPaths[j].Add(oddPaths[i][0]); break; } else if (j == normalPaths.Count - 1 && true) { oddPaths2.Add(oddPaths[i]); } } } normalPaths.AddRange(oddPaths2); oddWalks = oddPaths2.Count; return(normalPaths); } oddWalks = oddPaths.Count; return(allPaths); }