update comments
This commit is contained in:
parent
99d144532e
commit
4cac82441a
|
@ -23,6 +23,8 @@ import (
|
||||||
"gonum.org/v1/gonum/mat"
|
"gonum.org/v1/gonum/mat"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// WeightedGraph is an interface so we can construct adjacency matrices for
|
||||||
|
// both directed and undirected graphs.
|
||||||
type WeightedGraph interface {
|
type WeightedGraph interface {
|
||||||
graph.Weighted
|
graph.Weighted
|
||||||
graph.WeightedMultigraph
|
graph.WeightedMultigraph
|
||||||
|
@ -31,6 +33,8 @@ type WeightedGraph interface {
|
||||||
WeightedEdges() graph.WeightedEdges
|
WeightedEdges() graph.WeightedEdges
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// WeightedMatrix is an interface to handle the construction of both directed
|
||||||
|
// and undirected adjacency matrices.
|
||||||
type WeightedMatrix interface {
|
type WeightedMatrix interface {
|
||||||
graph.Weighted
|
graph.Weighted
|
||||||
|
|
||||||
|
@ -65,6 +69,7 @@ func copyEdges(g WeightedGraph, adj WeightedMatrix) {
|
||||||
for edges := g.WeightedEdges(); edges.Next(); {
|
for edges := g.WeightedEdges(); edges.Next(); {
|
||||||
e := edges.WeightedEdge()
|
e := edges.WeightedEdge()
|
||||||
if e.From() == e.To() {
|
if e.From() == e.To() {
|
||||||
|
// the simple Matrix classes don't handle self loops
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,7 +25,7 @@ import (
|
||||||
"gonum.org/v1/gonum/graph/multi"
|
"gonum.org/v1/gonum/graph/multi"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DOTWeightedGraph is a graph to unmarshal DOT graphs.
|
// DOTWeightedGraph is a struct to unmarshal DOT graphs.
|
||||||
type DOTWeightedGraph struct {
|
type DOTWeightedGraph struct {
|
||||||
igraph.WeightedGraph
|
igraph.WeightedGraph
|
||||||
WeightAttribute string
|
WeightAttribute string
|
||||||
|
@ -36,6 +36,7 @@ func NewDOTDirectedGraph(weightAttr string) DOTWeightedGraph {
|
||||||
return DOTWeightedGraph{WeightedGraph: multi.NewWeightedDirectedGraph(), WeightAttribute: weightAttr}
|
return DOTWeightedGraph{WeightedGraph: multi.NewWeightedDirectedGraph(), WeightAttribute: weightAttr}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// NewDOTUndirectedGraph returns a graph with no nodes or edges.
|
||||||
func NewDOTUndirectedGraph(weightAttr string) DOTWeightedGraph {
|
func NewDOTUndirectedGraph(weightAttr string) DOTWeightedGraph {
|
||||||
return DOTWeightedGraph{WeightedGraph: multi.NewWeightedUndirectedGraph(), WeightAttribute: weightAttr}
|
return DOTWeightedGraph{WeightedGraph: multi.NewWeightedUndirectedGraph(), WeightAttribute: weightAttr}
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,8 +48,8 @@ type weightedLine struct {
|
||||||
weightAttribute string
|
weightAttribute string
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetAttribute enables storing the weight read from a DOT file. It errors if
|
// SetAttribute enables storing the weight read from a DOT file. It only errors
|
||||||
// an attribute is read that can't be stored in a weightedLine.
|
// if the weight can't be parsed as a float.
|
||||||
func (e *weightedLine) SetAttribute(attr encoding.Attribute) error {
|
func (e *weightedLine) SetAttribute(attr encoding.Attribute) error {
|
||||||
var err error
|
var err error
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue