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()); }
/// <summary> /// Called when [alpha memory] is visited. /// </summary> /// <param name="am">The am.</param> public override void OnAlphaMemory(AlphaMemory am) { _sb.Append("").AppendLine(string.Format("Alpha: {0} - ({1})", am, string.Join(", ", am.Conditions.ToArray()))); _sb.Append(_indentString).AppendLine(" |"); _sb.Append(_indentString).AppendLine(" | ====== MATCHES ======"); foreach (ItemInAlphaMemory item in am.Items) { _sb.Append(_indentString).AppendLine(string.Format(" | {0}", item.WME)); } }