private static List<List<string>> GetStraight(MatrixWithHeaders matrixWithHeaders) { Dictionary<object, IEnumerable<IEdge<object>>> vertexEdges = new Dictionary<object, IEnumerable<IEdge<object>>>(); BidirectionalGraph<object, IEdge<object>> graph = Graph.AdjacentyMatrixToGraph(matrixWithHeaders) as BidirectionalGraph<object, IEdge<object>>; List<List<string>> straight = new List<List<string>>(); EdgeList<string, Edge<string>> candidates = new EdgeList<string, Edge<string>>(); var matrix = matrixWithHeaders.Matrix; var headers = matrixWithHeaders.Headers; var vertexes = graph.Vertices; foreach (var item in vertexes) { var inEdges = graph.InEdges(item); var outEdges = graph.OutEdges(item); if (inEdges.Count() == 1 && outEdges.Count() == 1) { candidates.Add(new Edge<string>(inEdges.ElementAt(0).Source.ToString(), inEdges.ElementAt(0).Target.ToString())); candidates.Add(new Edge<string>(outEdges.ElementAt(0).Source.ToString(), outEdges.ElementAt(0).Target.ToString())); } } for (int x = candidates.Count() - 1; x > 0; x--) { if (candidates[x - 1].Source == candidates[x].Source && candidates[x - 1].Target == candidates[x].Target) { candidates.RemoveAt(x); } } for (int x = 0; x < candidates.Count; x++) { for (int y = x + 1; y < candidates.Count; y++) { IEdge<object> edge = null; graph.TryGetEdge(candidates[x].Source, candidates[y].Target, out edge); if (edge != null) { var existItems = candidates.Select(z => z.Source == edge.Source.ToString() && z.Target == edge.Target.ToString()).ToList(); bool exist = false; foreach (var item in existItems) { exist = exist || item; } if (exist == false) { List<string> tempList = new List<string>(); for (int z = x; z <= y; z++) { if (tempList.Contains(candidates[z].Source) == false) { tempList.Add(candidates[z].Source); } if (tempList.Contains(candidates[z].Target) == false) { tempList.Add(candidates[z].Target); } } straight.Add(tempList); } } } } return straight; }
private static List <List <string> > GetStraight(MatrixWithHeaders matrixWithHeaders) { Dictionary <object, IEnumerable <IEdge <object> > > vertexEdges = new Dictionary <object, IEnumerable <IEdge <object> > >(); BidirectionalGraph <object, IEdge <object> > graph = Graph.AdjacentyMatrixToGraph(matrixWithHeaders) as BidirectionalGraph <object, IEdge <object> >; List <List <string> > straight = new List <List <string> >(); EdgeList <string, Edge <string> > candidates = new EdgeList <string, Edge <string> >(); var matrix = matrixWithHeaders.Matrix; var headers = matrixWithHeaders.Headers; var vertexes = graph.Vertices; foreach (var item in vertexes) { var inEdges = graph.InEdges(item); var outEdges = graph.OutEdges(item); if (inEdges.Count() == 1 && outEdges.Count() == 1) { candidates.Add(new Edge <string>(inEdges.ElementAt(0).Source.ToString(), inEdges.ElementAt(0).Target.ToString())); candidates.Add(new Edge <string>(outEdges.ElementAt(0).Source.ToString(), outEdges.ElementAt(0).Target.ToString())); } } for (int x = candidates.Count() - 1; x > 0; x--) { if (candidates[x - 1].Source == candidates[x].Source && candidates[x - 1].Target == candidates[x].Target) { candidates.RemoveAt(x); } } for (int x = 0; x < candidates.Count; x++) { for (int y = x + 1; y < candidates.Count; y++) { IEdge <object> edge = null; graph.TryGetEdge(candidates[x].Source, candidates[y].Target, out edge); if (edge != null) { var existItems = candidates.Select(z => z.Source == edge.Source.ToString() && z.Target == edge.Target.ToString()).ToList(); bool exist = false; foreach (var item in existItems) { exist = exist || item; } if (exist == false) { List <string> tempList = new List <string>(); for (int z = x; z <= y; z++) { if (tempList.Contains(candidates[z].Source) == false) { tempList.Add(candidates[z].Source); } if (tempList.Contains(candidates[z].Target) == false) { tempList.Add(candidates[z].Target); } } straight.Add(tempList); } } } } return(straight); }