public static List <Path> GetPathsForPointInGraph(IGraphBasics <Point, IEdgeBasics <Point> > CurrentGraph, Point CurrentPoint) { List <Path> currentListPaths = new List <Path> ( CurrentGraph.EdgeCollection .Where(i2 => i2.StartPoint.Equals(CurrentPoint)) .Select(i2 => { Path currentPath = Path.InitPath(); currentPath.AddEdge(i2); return(currentPath); })); for (int i = 0; i < currentListPaths.Count(); i++) { Path currentPath = currentListPaths[i]; IEnumerable <IEdgeBasics <Point> > candidatesToPath = CurrentGraph.EdgeCollection.Where(i1 => i1.StartPoint.Equals(currentPath.ListPathEdges.Last().EndPoint)); foreach (IEdgeBasics <Point> e in candidatesToPath) { if (!currentPath.ListPathPoints.Contains(e.EndPoint)) { Path newPath = Path.InitPath(currentPath); newPath.AddEdge(e); currentListPaths.Add(newPath); } } } return(currentListPaths); }
public static DirectedGraph DirectedGraphIntersection(IGraphBasics <Point, Edge> g1, IGraphBasics <Point, Edge> g2) { string graphName = g1.GraphName + "∩" + g2.GraphName; DirectedGraph OutGraph = new DirectedGraph(graphName); List <Point> ListTempPoints = g1.PointCollection.ToList(); List <Edge> ListTempEdges = g1.EdgeCollection.ToList(); ListTempPoints.AddRange((g2.PointCollection).Except(g1.PointCollection)); ListTempEdges = ListTempEdges.Intersect(g2.EdgeCollection, new DirectedEdgeEqualityComparer()).ToList(); foreach (Point p in ListTempPoints) { OutGraph.AddPoint(new Point(p.Name)); } int i = 0; foreach (Edge e in ListTempEdges) { OutGraph.AddEdge(new Edge(graphName + "_" + i.ToString(), e)); i++; } return(OutGraph); }
public static void PrintAllEdgesForGraph(IGraphBasics <Point, IEdgeBasics <Point> > CurrentGraph) { foreach (KeyValuePair <Point, IEnumerable <AbstractPath <IEdgeBasics <Point>, Point> > > kvp in GraphUtils.GetAllPathsForGraph(CurrentGraph)) { Console.WriteLine("Point: {0}\n {1}", kvp.Key, String.Join("\n ", kvp.Value.Select(i1 => String.Join("->", i1.ListPathPoints)))); } }
public static void PrintOneSidedComp(IGraphBasics <Point, IEdgeBasics <Point> > CurrentGraph) { foreach (IEnumerable <Point> collP in GraphUtils.GetCollectionPointsOneSidedCompOfGraph(CurrentGraph)) { Console.WriteLine("Graph: {{{0}}}", String.Join(",", collP)); } }
public static bool CheckCycles(IGraphBasics <Point, AbstractEdge <Point> > CurrentGraph) { if (CheckSimpleCycles(CurrentGraph)) { return(true); } List <Path> listPaths = CurrentGraph.EdgeCollection.Select <AbstractEdge <Point>, Path>(i1 => { Path path = Path.InitPath(); path.AddEdge(i1); return(path); }).ToList(); for (int i = 0; i < listPaths.Count(); i++) { Path currentPath = listPaths[i]; IEnumerable <AbstractEdge <Point> > candidatesToPath = CurrentGraph.EdgeCollection.Where(i1 => i1.StartPoint.Equals(currentPath.ListPathEdges.Last().EndPoint)); foreach (Edge e in candidatesToPath) { if (currentPath.ListPathPoints.Contains(e.EndPoint)) { return(true); } else { Path newPath = Path.InitPath(currentPath); newPath.AddEdge(e); listPaths.Add(newPath); } } } return(false); }
public override string ConvertFromGrapch(IGraphBasics <Point, IEdgeBasics <Point> > InitialGraph) { string content = InitialGraph.GraphName + "\n | "; List <Point> points = (InitialGraph.PointCollection.ToList()); points.Sort((i1, i2) => { return(i1.Name.CompareTo(i2.Name)); }); content = String.Concat(content, String.Join("| ", points.Select(i1 => i1.Name))); content = String.Concat(content, "\n"); byte[,] matrix = new byte[points.Count, points.Count]; foreach (IEdgeBasics <Point> e in InitialGraph.EdgeCollection) { matrix[points.IndexOf(e.StartPoint), points.IndexOf(e.EndPoint)] += 1; } for (int i = 0; i < matrix.GetLength(0); i++) { content = String.Concat(content, points[i].ToString()); for (int j = 0; j < matrix.GetLength(1); j++) { content = String.Concat(content, " | "); content = String.Concat(content, matrix[i, j].ToString()); } content = String.Concat(content, "\n"); } return(content); }
public static int CountOutDegreeForPoint(IGraphBasics <Point, AbstractEdge <Point> > CurrentGraph, Point CurrentPoint) { if (!CurrentGraph.PointCollection.Contains(CurrentPoint)) { throw new Exception("Point " + CurrentPoint.ToString() + " not contains in graph " + CurrentGraph); } return(CurrentGraph.EdgeCollection.Count(i1 => i1.StartPoint.Equals(CurrentPoint))); }
public static IEnumerable <Point> GetOutDegreeForPoint(IGraphBasics <Point, IEdgeBasics <Point> > CurrentGraph, Point CurrentPoint) { if (!CurrentGraph.PointCollection.Contains(CurrentPoint)) { throw new Exception("Point " + CurrentPoint.ToString() + " not contains in graph " + CurrentGraph); } HashSet <Point> inPoints = new HashSet <Point>(CurrentGraph.EdgeCollection.Where(i1 => i1.StartPoint.Equals(CurrentPoint)).Select(i1 => i1.EndPoint)); return(inPoints); }
public override string ConvertFromGrapch(IGraphBasics <Point, IEdgeBasics <Point> > InitialGraph) { List <Point> points = (InitialGraph.PointCollection.ToList()); points.Sort(); StringBuilder HtmlStringBuilder = new StringBuilder(); HtmlStringBuilder.AppendFormat("<!DOCTYPE HTML><html><head><meta charset =\"utf-8\"></head><body><table border = \"1\"><caption>{0}</caption>", InitialGraph.GraphName); HtmlStringBuilder.AppendFormat("<tr><th></th><th>{0}</th></tr>", String.Join("</th><th>", points.Select(i1 => i1.Name))); string[,] matrix = new string[points.Count, points.Count]; foreach (IEdgeBasics <Point> e in InitialGraph.EdgeCollection) { if (e is IValuedEdgeBasics <Point> ) { if (String.IsNullOrEmpty(matrix[points.IndexOf(e.StartPoint), points.IndexOf(e.EndPoint)])) { matrix[points.IndexOf(e.StartPoint), points.IndexOf(e.EndPoint)] = (e as IValuedEdgeBasics <Point>).EdgeValue.ToString("0.00"); } else { matrix[points.IndexOf(e.StartPoint), points.IndexOf(e.EndPoint)] += String.Format(", {0}", (e as IValuedEdgeBasics <Point>).EdgeValue.ToString("0.00")); } } else if (String.IsNullOrEmpty(matrix[points.IndexOf(e.StartPoint), points.IndexOf(e.EndPoint)])) { matrix[points.IndexOf(e.StartPoint), points.IndexOf(e.EndPoint)] = "1"; } else { matrix[points.IndexOf(e.StartPoint), points.IndexOf(e.EndPoint)] += ", 1"; } } for (int i = 0; i < matrix.GetLength(0); i++) { HtmlStringBuilder.AppendFormat("<tr><th>{0}</th>", points[i].ToString()); for (int j = 0; j < matrix.GetLength(1); j++) { if (String.IsNullOrEmpty(matrix[i, j])) { HtmlStringBuilder.AppendFormat("<td>{0}</td>", 0); } else { HtmlStringBuilder.AppendFormat("<td>{0}</td>", matrix[i, j].ToString()); } } HtmlStringBuilder.Append("</tr>"); } HtmlStringBuilder.Append("</table></body></html>"); return(HtmlStringBuilder.ToString()); }
public static bool CheckSimpleCycles(IGraphBasics <Point, AbstractEdge <Point> > CurrentGraph) { if (CurrentGraph.EdgeCollection.Count(i1 => i1.StartPoint.Equals(i1.EndPoint)) != 0) { return(true); } else { return(false); } }
public static IEnumerable <Point> GetOutTransitiveClosureForPoint(IGraphBasics <Point, IEdgeBasics <Point> > CurrentGraph, Point CurrentPoint) { List <Point> listTransitivePoints = new List <Point>(GetOutDegreeForPoint(CurrentGraph, CurrentPoint)); for (int pointID = 0; pointID < listTransitivePoints.Count(); pointID++) { listTransitivePoints = listTransitivePoints.Union(GetOutDegreeForPoint(CurrentGraph, listTransitivePoints[pointID])).ToList(); } return(listTransitivePoints); }
public static void PrintTransitiveClosureForAllPoints(IGraphBasics <Point, IEdgeBasics <Point> > CurrentGraph) { foreach (KeyValuePair <Point, IEnumerable <Point> > kvp in GraphUtils.GetOutTransitiveClosureForAllPoints(CurrentGraph)) { Console.WriteLine("Point {0}, Out transitive closure = {{{1}}}", kvp.Key, String.Join(",", kvp.Value)); } Console.WriteLine(); foreach (KeyValuePair <Point, IEnumerable <Point> > kvp in GraphUtils.GetInTransitiveClosureForAllPoints(CurrentGraph)) { Console.WriteLine("Point {0}, In transitive closure = {{{1}}}", kvp.Key, String.Join(",", kvp.Value)); } Console.WriteLine("\nOneSides Graphs:\n"); }
public override string ConvertFromGrapch(IGraphBasics <Point, IEdgeBasics <Point> > InitialGraph) { List <Point> points = (InitialGraph.PointCollection.ToList()); points.Sort((i1, i2) => { return(i1.Name.CompareTo(i2.Name)); }); StringBuilder HtmlStringBuilder; try { int fileLength = points.Select(i1 => i1.Name.Length).Aggregate((i1, i2) => i1 + i2) * 2; // Double length (row and columns) names of points fileLength += 126; // <!DOCTYPE HTML><html><head><meta charset =\"utf-8\"></head><body><table border = "1"><caption></caption></table></body></html> fileLength += InitialGraph.GraphName.Length; // Plus Graph name fileLength += ((InitialGraph.PointCollection.Count() + 2) * (InitialGraph.PointCollection.Count() + 1)) * 9; // Count <tr></tr>, <th></th>, <td></td> fileLength += (InitialGraph.PointCollection.Count() * InitialGraph.PointCollection.Count()); // Reserved for 0 or 1 in ref matrix HtmlStringBuilder = new StringBuilder(fileLength, fileLength); } catch (ArgumentOutOfRangeException ex) { Console.WriteLine(ex.Message); HtmlStringBuilder = new StringBuilder(Int32.MaxValue); } if (HtmlStringBuilder == null) { HtmlStringBuilder = new StringBuilder(); } HtmlStringBuilder.AppendFormat("<!DOCTYPE HTML><html><head><meta charset =\"utf-8\"></head><body><table border = \"1\"><caption>{0}</caption>", InitialGraph.GraphName); HtmlStringBuilder.AppendFormat("<tr><th></th><th>{0}</th></tr>", String.Join("</th><th>", points.Select(i1 => i1.Name))); byte[,] matrix = new byte[points.Count, points.Count]; foreach (IEdgeBasics <Point> e in InitialGraph.EdgeCollection) { matrix[points.IndexOf(e.StartPoint), points.IndexOf(e.EndPoint)] += 1; } for (int i = 0; i < matrix.GetLength(0); i++) { HtmlStringBuilder.AppendFormat("<tr><th>{0}</th>", points[i].ToString()); for (int j = 0; j < matrix.GetLength(1); j++) { HtmlStringBuilder.AppendFormat("<td>{0}</td>", matrix[i, j].ToString()); } HtmlStringBuilder.Append("</tr>"); } HtmlStringBuilder.Append("</table></body></html>"); return(HtmlStringBuilder.ToString()); }
public static string GenerateGraphDescription(IGraphBasics <Point, AbstractEdge <Point> > CurrentGraph) { StringBuilder descriptionBuilder = new StringBuilder(String.Format("{0} = ", CurrentGraph.GraphName)); descriptionBuilder.AppendFormat("{{{0}}} – множество вершин", String.Join(", ", CurrentGraph.PointCollection.Select(i1 => i1.Name))); foreach (Point p in CurrentGraph.PointCollection) { IEnumerable <string> listEndPointsIDs = CurrentGraph.EdgeCollection.Where(i1 => i1.StartPoint.Equals(p)).Select(i1 => i1.EndPoint.Name); if (listEndPointsIDs.Count() > 0) { descriptionBuilder.Append(", "); descriptionBuilder.AppendFormat("Г({0}) = {{ {1} }}", new string[] { p.Name, String.Join(", ", listEndPointsIDs) }); } } descriptionBuilder.Append(" – отображения."); return(descriptionBuilder.ToString()); }
public static bool IsDirectedTree(IGraphBasics <Point, AbstractEdge <Point> > CurrentGraph) { if (CheckCycles(CurrentGraph)) { return(false); } IEnumerable <KeyValuePair <Point, int> > inDegrees = CountInDegreeForAllPoint(CurrentGraph); if (CurrentGraph.EdgeCollection.Count(i1 => i1.StartPoint == i1.EndPoint) == 0 && inDegrees.Count(i1 => i1.Value == 0) == 1 && inDegrees.Count(i1 => i1.Value > 1) == 0) { return(true); } else { return(false); } }
public static DirectedGraph DirectedGraphUnion(IGraphBasics <Point, Edge> g1, IGraphBasics <Point, Edge> g2) { string graphName = g1.GraphName + "∪" + g2.GraphName; DirectedGraph OutGraph = new DirectedGraph(graphName); IEnumerable <Point> ListTempPoints = g1.PointCollection.Union(g2.PointCollection, new PointEqualityComparer()); IEnumerable <Edge> ListTempEdges = g1.EdgeCollection.Union(g2.EdgeCollection, new DirectedEdgeEqualityComparer()); foreach (Point p in ListTempPoints) { OutGraph.AddPoint(new Point(p.Name)); } int i = 0; foreach (Edge e in ListTempEdges) { OutGraph.AddEdge(new Edge(graphName + "_" + i.ToString(), e)); i++; } return(OutGraph); }
public override string ConvertFromGrapch(IGraphBasics <Point, IEdgeBasics <Point> > InitialGraph) { List <Point> points = (InitialGraph.PointCollection.ToList()); points.Sort((i1, i2) => { return(i1.Name.CompareTo(i2.Name)); }); List <IEdgeBasics <Point> > edges = (InitialGraph.EdgeCollection.ToList()); edges.Sort((i1, i2) => { return(i1.Name.CompareTo(i2.Name)); }); StringBuilder HtmlStringBuilder; HtmlStringBuilder = new StringBuilder(); HtmlStringBuilder.AppendFormat("<!DOCTYPE HTML><html><head><meta charset =\"utf-8\"></head><body><table border = \"1\"><caption>{0}</caption>", InitialGraph.GraphName); HtmlStringBuilder.AppendFormat("<tr><th></th><th>{0}</th></tr>", String.Join("</th><th>", edges.Select(i1 => i1.Name))); short[,] matrix = new short[points.Count, edges.Count]; foreach (var e in edges) { int eid = edges.IndexOf(e); int esp = points.IndexOf(e.StartPoint); int eep = points.IndexOf(e.EndPoint); matrix[esp, eid] += 1; matrix[eep, eid] -= 1; } for (int i = 0; i < matrix.GetLength(0); i++) { HtmlStringBuilder.AppendFormat("<tr><th>{0}</th>", points[i].ToString()); for (int j = 0; j < matrix.GetLength(1); j++) { HtmlStringBuilder.AppendFormat("<td id = >{0}</td>", matrix[i, j].ToString()); } HtmlStringBuilder.Append("</tr>"); } HtmlStringBuilder.Append("</table></body></html>"); return(HtmlStringBuilder.ToString()); }
public abstract CustomType ConvertFromGrapch(IGraphBasics <Point, IEdgeBasics <Point> > InitialGraph);
public static IEnumerable <KeyValuePair <Point, IEnumerable <Point> > > GetOutTransitiveClosureForAllPoints(IGraphBasics <Point, IEdgeBasics <Point> > CurrentGraph) { return(CurrentGraph.PointCollection.Select(i1 => new KeyValuePair <Point, IEnumerable <Point> >(i1, GetOutTransitiveClosureForPoint(CurrentGraph, i1)) )); }
public static IEnumerable <IEnumerable <Point> > GetCollectionPointsOneSidedCompOfGraph(IGraphBasics <Point, IEdgeBasics <Point> > CurrentGraph) { List <KeyValuePair <List <Point>, List <Point> > > listKvpPoints = new List <KeyValuePair <List <Point>, List <Point> > >(CurrentGraph.EdgeCollection .Select(i1 => { KeyValuePair <List <Point>, List <Point> > kvp = new KeyValuePair <List <Point>, List <Point> >(new List <Point>(), new List <Point>()); kvp.Key.Add(i1.StartPoint); if (!i1.StartPoint.Equals(i1.EndPoint)) { kvp.Key.Add(i1.EndPoint); } kvp.Value.Add(i1.EndPoint); return(kvp); } )); bool calcEnd = false; while (!calcEnd) { foreach (KeyValuePair <List <Point>, List <Point> > kvp in listKvpPoints) { IEnumerable <Point> pointCondidates = CurrentGraph.EdgeCollection .Where(i1 => kvp.Value.Contains(i1.StartPoint)) .Select(i1 => i1.EndPoint) .Except(kvp.Key) .ToList(); kvp.Key.AddRange(pointCondidates); kvp.Value.Clear(); kvp.Value.AddRange(pointCondidates); } for (int listID = 0; listID < listKvpPoints.Count;) { KeyValuePair <List <Point>, List <Point> > currentList = listKvpPoints[listID]; listKvpPoints .RemoveAll(i1 => i1.Value.Count() == 0 && !currentList.Equals(i1) && (i1.Key.Except(currentList.Key).Count() == 0)); listID = listKvpPoints.IndexOf(currentList) + 1; } if (listKvpPoints.Count(i1 => i1.Value.Count() == 0) == listKvpPoints.Count()) { calcEnd = true; } } return(listKvpPoints.Select(i1 => i1.Key)); }
public static IEnumerable <IGraphBasics <Point, IEdgeBasics <Point> > > GetCollectionOneSidedStrongComponentsOfGraph(IGraphBasics <Point, IEdgeBasics <Point> > CurrentGraph, Point StartPoint) { if (!CurrentGraph.PointCollection.Contains(StartPoint)) { throw new Exception(String.Format("Start point {1} not contained in graph {0}.", CurrentGraph.GraphName, StartPoint)); } BaseMinimalGraph <Point, IEdgeBasics <Point> > originalGraph = new BaseMinimalGraph <Point, IEdgeBasics <Point> >() { GraphName = CurrentGraph.GraphName, EdgeCollection = CurrentGraph.EdgeCollection.ToList(), PointCollection = CurrentGraph.PointCollection.ToList() }; List <IGraphBasics <Point, IEdgeBasics <Point> > > listOneSidedGraphs = new List <IGraphBasics <Point, IEdgeBasics <Point> > >(); Point tmpPoint = StartPoint; bool algEnd = false; while (!algEnd) { IEnumerable <Point> inTrClosure = GetInTransitiveClosureForPoint(originalGraph, tmpPoint); IEnumerable <Point> outTrClosure = GetOutTransitiveClosureForPoint(originalGraph, tmpPoint); IEnumerable <Point> trClosure = inTrClosure.Intersect(outTrClosure); if (trClosure.Count() != 0) { IGraphBasics <Point, IEdgeBasics <Point> > OneSidedStrongComponent = new BaseMinimalGraph <Point, IEdgeBasics <Point> >() { GraphName = String.Format("One-side_strong_comp\n {0}", String.Join(",", trClosure)), PointCollection = trClosure.ToList(), EdgeCollection = originalGraph.EdgeCollection.Where(i1 => trClosure.Contains(i1.EndPoint) && trClosure.Contains(i1.StartPoint)).ToList() }; listOneSidedGraphs.Add(OneSidedStrongComponent); originalGraph.EdgeCollection = originalGraph.EdgeCollection.Where(i1 => !trClosure.Contains(i1.EndPoint) && !trClosure.Contains(i1.StartPoint)).ToList(); originalGraph.PointCollection = originalGraph.PointCollection.Except(OneSidedStrongComponent.PointCollection).ToList(); } else { List <Point> tmpListPoints = originalGraph.PointCollection.ToList(); tmpListPoints.Remove(tmpPoint); originalGraph.PointCollection = tmpListPoints; originalGraph.EdgeCollection = originalGraph.EdgeCollection.Where(i1 => !i1.EndPoint.Equals(tmpPoint) && !i1.StartPoint.Equals(tmpPoint)).ToList(); } if (originalGraph.PointCollection.Count() == 0) { algEnd = true; } else { tmpPoint = originalGraph.PointCollection.First(); } } return(listOneSidedGraphs); }
public static IEnumerable <KeyValuePair <Point, ValuedPath> > GetMinimalPathFromPointToAllPointsInGraph(IGraphBasics <Point, IValuedEdgeBasics <Point> > CurrentGraph, Point CurrentPoint) { Dictionary <Point, ValuedPath> dictionaryPermMinValuedPaths = new Dictionary <Point, ValuedPath>(); Dictionary <Point, ValuedPath> dictionaryValuedPaths = new Dictionary <Point, ValuedPath>(); if (CurrentGraph.EdgeCollection.Count(i1 => i1.StartPoint.Equals(CurrentPoint)) == 0) { return(dictionaryPermMinValuedPaths); } foreach (IValuedEdgeBasics <Point> ve in CurrentGraph.EdgeCollection.Where(i1 => i1.StartPoint.Equals(CurrentPoint))) { ValuedPath tempValPath = ValuedPath.InitPath(); tempValPath.AddEdge(ve); if (dictionaryValuedPaths.ContainsKey(tempValPath.ListPathPoints.Last())) { if (dictionaryValuedPaths[tempValPath.ListPathPoints.Last()].PathLengrh > tempValPath.PathLengrh) { dictionaryValuedPaths[tempValPath.ListPathPoints.Last()] = tempValPath; } } else { dictionaryValuedPaths.Add(tempValPath.ListPathPoints.Last(), tempValPath); } } ValuedPath selectedTempPath = dictionaryValuedPaths.Values.OrderBy(i1 => i1.PathLengrh).First(); dictionaryPermMinValuedPaths.Add(selectedTempPath.ListPathPoints.Last(), selectedTempPath); bool algEnd = false; while (!algEnd) { foreach (IValuedEdgeBasics <Point> ve in CurrentGraph.EdgeCollection.Where(i1 => i1.StartPoint.Equals(selectedTempPath.ListPathPoints.Last()) && !selectedTempPath.ListPathPoints.Contains(i1.EndPoint) && !dictionaryPermMinValuedPaths.ContainsKey(i1.EndPoint))) { ValuedPath tempValPath = ValuedPath.InitPath(selectedTempPath); tempValPath.AddEdge(ve); if (dictionaryValuedPaths.ContainsKey(ve.EndPoint)) { if (dictionaryValuedPaths[tempValPath.ListPathPoints.Last()].PathLengrh > tempValPath.PathLengrh) { dictionaryValuedPaths[tempValPath.ListPathPoints.Last()] = tempValPath; } } else { dictionaryValuedPaths.Add(tempValPath.ListPathPoints.Last(), tempValPath); } } dictionaryValuedPaths.Remove(selectedTempPath.ListPathPoints.Last()); //dictionaryValuedPaths.Remove(selectedTempPath.ListPathPoints.Last()); if (dictionaryValuedPaths.Count == 0) { algEnd = true; } else { selectedTempPath = dictionaryValuedPaths.Values.OrderBy(i1 => i1.PathLengrh).First(); dictionaryPermMinValuedPaths.Add(selectedTempPath.ListPathPoints.Last(), selectedTempPath); } } return(dictionaryPermMinValuedPaths); }
public static IEnumerable <KeyValuePair <Point, int> > CountOutDegreeForAllPoint(IGraphBasics <Point, AbstractEdge <Point> > CurrentGraph) { return(CurrentGraph.PointCollection. Select(i1 => { return new KeyValuePair <Point, int>(i1, CountOutDegreeForPoint(CurrentGraph, i1)); })); }
public static IEnumerable <KeyValuePair <Point, IEnumerable <AbstractPath <IEdgeBasics <Point>, Point> > > > GetAllPathsForGraph(IGraphBasics <Point, IEdgeBasics <Point> > CurrentGraph) { List <KeyValuePair <Point, IEnumerable <AbstractPath <IEdgeBasics <Point>, Point> > > > listPathsByPoints = new List <KeyValuePair <Point, IEnumerable <AbstractPath <IEdgeBasics <Point>, Point> > > >(); foreach (Point p in CurrentGraph.PointCollection) { listPathsByPoints.Add(new KeyValuePair <Point, IEnumerable <AbstractPath <IEdgeBasics <Point>, Point> > >(p, GetPathsForPointInGraph(CurrentGraph, p))); } return(listPathsByPoints); }
public static IEnumerable <KeyValuePair <Point, int> > GetPointsWithMinOutDegree(IGraphBasics <Point, AbstractEdge <Point> > CurrentGraph) { IEnumerable <KeyValuePair <Point, int> > listDegrees = CountOutDegreeForAllPoint(CurrentGraph); int minDegree = listDegrees.Min(i1 => i1.Value); return(listDegrees.Where(i1 => i1.Value == minDegree)); }
public override string ConvertFromGrapch(IGraphBasics <Point, IEdgeBasics <Point> > InitialGraph) { StringBuilder content = new StringBuilder(String.Format("{0} \n", InitialGraph.GraphName)); List <Point> points = (InitialGraph.PointCollection.ToList()); points.Sort((i1, i2) => { return(i1.Name.CompareTo(i2.Name)); }); string[,] matrix = new string[points.Count + 1, points.Count + 1]; for (int i = 0; i < points.Count; i++) { matrix[i + 1, 0] = points[i].ToString(); matrix[0, i + 1] = points[i].ToString(); } foreach (IEdgeBasics <Point> e in InitialGraph.EdgeCollection) { if (e is IValuedEdgeBasics <Point> ) { if (String.IsNullOrEmpty(matrix[points.IndexOf(e.StartPoint) + 1, points.IndexOf(e.EndPoint) + 1])) { matrix[points.IndexOf(e.StartPoint) + 1, points.IndexOf(e.EndPoint) + 1] = (e as IValuedEdgeBasics <Point>).EdgeValue.ToString("0.00"); } else { matrix[points.IndexOf(e.StartPoint) + 1, points.IndexOf(e.EndPoint) + 1] += (String.Format(", {0}", (e as IValuedEdgeBasics <Point>).EdgeValue.ToString("0.00"))); } } else if (String.IsNullOrEmpty(matrix[points.IndexOf(e.StartPoint) + 1, points.IndexOf(e.EndPoint) + 1])) { matrix[points.IndexOf(e.StartPoint) + 1, points.IndexOf(e.EndPoint) + 1] = "1"; } else { matrix[points.IndexOf(e.StartPoint) + 1, points.IndexOf(e.EndPoint) + 1] += ", 1"; } } int[] maxColumnLength = new int[matrix.GetLength(1)]; for (int j = 0; j < matrix.GetLength(1); j++) { int maxLength = 0; for (int i = 0; i < matrix.GetLength(0); i++) { if (!String.IsNullOrEmpty(matrix[i, j])) { if (matrix[i, j].Length > maxLength) { maxLength = matrix[i, j].Length; } } } maxColumnLength[j] = maxLength; } for (int i = 0; i < matrix.GetLength(0); i++) { for (int j = 0; j < matrix.GetLength(1); j++) { if (!String.IsNullOrEmpty(matrix[i, j])) { content.AppendFormat("{0}{1} | ", matrix[i, j], new String(' ', maxColumnLength[j] - matrix[i, j].Length)); } else { content.AppendFormat("{0}{1} | ", 0, new String(' ', maxColumnLength[j] - 1)); } } content.Append("\n"); } return(content.ToString()); }