Skip to content

Commit

Permalink
make improvements of the debug view
Browse files Browse the repository at this point in the history
  • Loading branch information
xieguigang committed Nov 23, 2024
1 parent 337e5eb commit 6359240
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions Data_science/Graph/SparseGraph.vb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
Imports System.Runtime.CompilerServices
Imports System.Xml.Serialization
Imports Microsoft.VisualBasic.Linq
Imports Microsoft.VisualBasic.Math.LinearAlgebra.Matrix

Public Class SparseGraph : Implements ISparseGraph
Expand All @@ -15,6 +16,19 @@ Public Class SparseGraph : Implements ISparseGraph
End Set
End Property

Public ReadOnly Property Vertex As String()
Get
Return graph _
.Select(Iterator Function(e) As IEnumerable(Of String)
Yield e.u
Yield e.v
End Function) _
.IteratesALL _
.Distinct _
.ToArray
End Get
End Property

Public NotInheritable Class Edge : Implements IInteraction

<XmlAttribute> Public Property u As String Implements IInteraction.source
Expand All @@ -28,6 +42,11 @@ Public Class SparseGraph : Implements ISparseGraph
_v = v
End Sub

Sub New(line As IInteraction)
_u = line.source
_v = line.target
End Sub

Public Overrides Function ToString() As String
Return $"[{u}, {v}]"
End Function
Expand Down Expand Up @@ -58,6 +77,11 @@ Public Class SparseGraph : Implements ISparseGraph
Dim index_u As Dictionary(Of String, IInteraction())
Dim graph As Edge()

Public Overrides Function ToString() As String
Dim vlist = Vertex
Return $"sparse graph of {vlist.Length}x{vlist.Length} vertex and {graph.Length} edges."
End Function

Public Function CreateMatrix(keys As String()) As NumericMatrix
Dim rows As New List(Of Double())

Expand Down Expand Up @@ -110,4 +134,11 @@ Public Class SparseGraph : Implements ISparseGraph
Yield edge
Next
End Function

Public Shared Function Copy(g As ISparseGraph) As SparseGraph
Dim edges As Edge() = g.GetGraph.Select(Function(e) New Edge(e)).ToArray
Dim graph As New SparseGraph With {.Edges = edges}

Return graph
End Function
End Class

0 comments on commit 6359240

Please sign in to comment.