summaryrefslogtreecommitdiffstats
path: root/IO/GraphFile.cs
diff options
context:
space:
mode:
Diffstat (limited to 'IO/GraphFile.cs')
-rw-r--r--IO/GraphFile.cs20
1 files changed, 16 insertions, 4 deletions
diff --git a/IO/GraphFile.cs b/IO/GraphFile.cs
index 9298e4b..a532681 100644
--- a/IO/GraphFile.cs
+++ b/IO/GraphFile.cs
@@ -1,3 +1,4 @@
+using System.Linq;
using System.Text.RegularExpressions;
using Graph.Interfaces;
@@ -43,12 +44,23 @@ namespace Graph.IO
public static void Print(Graph<double> graph, IFileWriter writer)
{
string outstring = "";
- graph.Vertices.ForEach(v =>
+ graph.Vertices.ForEach(vertex =>
{
- outstring += $"\n{v.Id}";
- v.Edges.ForEach(e => outstring += $" {e.V} {e.Weight.ToString("F1")}");
+ outstring += $"\n{vertex.Id}";
+
+ vertex.Edges.ForEach(edge => {
+ var vertex = graph.Vertices.Find(v => v.Id == edge.V);
+ if (vertex != null && vertex.Parent == vertex.Id)
+ outstring += $" {edge.V} {edge.Weight.ToString("F1")}";
+ });
});
writer.WriteAllText(outstring.Trim());
}
}
-} \ No newline at end of file
+}
+
+// var neighbors = graph.Vertices
+// .Where(u => u.Parent == vertex.Id && vertex.Edges.Exists(e => e.V == u.Id));
+
+// var edges = vertex.Edges
+// .Where(e => graph.Vertices.Find(v => v.Id == e.V).Parent == vertex.Id); \ No newline at end of file