diff options
-rw-r--r-- | Graph.cs | 4 | ||||
-rw-r--r-- | IO/GraphFile.cs | 20 |
2 files changed, 19 insertions, 5 deletions
@@ -18,8 +18,10 @@ namespace Graph { Vertex<T> vertex = Vertices.Find(u => u.Id == edge.U); - if (vertex == null) + if (vertex == null) { Vertices.Add(vertex = new Vertex<T>(edge.U)); + vertex = Vertices[Vertices.Count - 1]; + } vertex.Edges.Add(edge); } 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 |