diff --git a/cmd/internal/graph/common.go b/cmd/internal/graph/common.go index 92259cf..9d242a1 100644 --- a/cmd/internal/graph/common.go +++ b/cmd/internal/graph/common.go @@ -23,6 +23,7 @@ import ( type WeightedGraph interface { graph.Weighted + graph.WeightedMultigraphBuilder WeightedEdges() graph.WeightedEdges diff --git a/cmd/internal/graph/dot/graph.go b/cmd/internal/graph/dot/graph.go index 8645851..8291e76 100644 --- a/cmd/internal/graph/dot/graph.go +++ b/cmd/internal/graph/dot/graph.go @@ -25,19 +25,23 @@ import ( "gonum.org/v1/gonum/graph/multi" ) -// DOTDirectedGraph is a graph to unmarshal DOT graphs. -type DOTDirectedGraph struct { - *igraph.DirectedGraph +// DOTWeightedGraph is a graph to unmarshal DOT graphs. +type DOTWeightedGraph struct { + igraph.WeightedGraph WeightAttribute string } // NewDOTDirectedGraph returns a graph with no nodes or edges. -func NewDOTDirectedGraph(weightAttr string) *DOTDirectedGraph { - return &DOTDirectedGraph{DirectedGraph: igraph.NewDirectedGraph(), WeightAttribute: weightAttr} +func NewDOTDirectedGraph(weightAttr string) DOTWeightedGraph { + return DOTWeightedGraph{WeightedGraph: igraph.NewDirectedGraph(), WeightAttribute: weightAttr} +} + +func NewDOTUndirectedGraph(weightAttr string) DOTWeightedGraph { + return DOTWeightedGraph{WeightedGraph: igraph.NewUndirectedGraph(), WeightAttribute: weightAttr} } // NewLine returns a DOT-aware weighted line. -func (g *DOTDirectedGraph) NewLine(from, to graph.Node) graph.Line { +func (g *DOTWeightedGraph) NewLine(from, to graph.Node) graph.Line { var defaultWeight float64 if g.WeightAttribute == "" { defaultWeight = 1 @@ -45,16 +49,16 @@ func (g *DOTDirectedGraph) NewLine(from, to graph.Node) graph.Line { defaultWeight = math.NaN() } - e := g.DirectedGraph.NewWeightedLine(from, to, defaultWeight).(multi.WeightedLine) + e := g.WeightedGraph.NewWeightedLine(from, to, defaultWeight).(multi.WeightedLine) return &weightedLine{WeightedLine: e, weightAttribute: g.WeightAttribute} } // NewNode returns a DOT-aware Node. -func (g *DOTDirectedGraph) NewNode() graph.Node { - return &Node{Node: g.DirectedGraph.NewNode()} +func (g *DOTWeightedGraph) NewNode() graph.Node { + return &Node{Node: g.WeightedGraph.NewNode()} } // SetLine adds a DOT-aware weighted line to the graph. -func (g *DOTDirectedGraph) SetLine(e graph.Line) { - g.DirectedGraph.SetWeightedLine(e.(*weightedLine)) +func (g *DOTWeightedGraph) SetLine(e graph.Line) { + g.WeightedGraph.SetWeightedLine(e.(*weightedLine)) }