From 27a7ce31e9dc21041f467eca2c07754f99a81049 Mon Sep 17 00:00:00 2001 From: filifa Date: Tue, 6 May 2025 22:24:28 -0400 Subject: [PATCH] rename things --- .../dot/markov.go => graph/dot/graph.go} | 26 +++++++++---------- .../{markov => graph}/dot/nodes_edges.go | 0 .../{markov/absorbing.go => graph/graph.go} | 18 ++++++------- cmd/root.go | 8 +++--- 4 files changed, 25 insertions(+), 27 deletions(-) rename cmd/internal/{markov/dot/markov.go => graph/dot/graph.go} (56%) rename cmd/internal/{markov => graph}/dot/nodes_edges.go (100%) rename cmd/internal/{markov/absorbing.go => graph/graph.go} (76%) diff --git a/cmd/internal/markov/dot/markov.go b/cmd/internal/graph/dot/graph.go similarity index 56% rename from cmd/internal/markov/dot/markov.go rename to cmd/internal/graph/dot/graph.go index c5dcbd6..3990440 100644 --- a/cmd/internal/markov/dot/markov.go +++ b/cmd/internal/graph/dot/graph.go @@ -19,35 +19,35 @@ package dot import ( "math" - "scm.dairydemon.net/filifa/gv2adj/cmd/internal/markov" + igraph "scm.dairydemon.net/filifa/gv2adj/cmd/internal/graph" "gonum.org/v1/gonum/graph" "gonum.org/v1/gonum/graph/multi" ) -// DOTMarkovChain is a graph representing an absorbing Markov chain. -type DOTMarkovChain struct { - *markov.AbsorbingMarkovChain +// DOTDirectedGraph is a graph representing an absorbing Markov chain. +type DOTDirectedGraph struct { + *igraph.DirectedGraph } -// NewDOTMarkovChain returns an absorbing Markov chain with no nodes or +// NewDOTDirectedGraph returns an absorbing Markov chain with no nodes or // edges. -func NewDOTMarkovChain() *DOTMarkovChain { - return &DOTMarkovChain{AbsorbingMarkovChain: markov.NewAbsorbingMarkovChain()} +func NewDOTDirectedGraph() *DOTDirectedGraph { + return &DOTDirectedGraph{DirectedGraph: igraph.NewDirectedGraph()} } // NewLine returns a DOT-aware weighted line. -func (g *DOTMarkovChain) NewLine(from, to graph.Node) graph.Line { - e := g.AbsorbingMarkovChain.NewWeightedLine(from, to, math.NaN()).(multi.WeightedLine) +func (g *DOTDirectedGraph) NewLine(from, to graph.Node) graph.Line { + e := g.DirectedGraph.NewWeightedLine(from, to, math.NaN()).(multi.WeightedLine) return &weightedLine{WeightedLine: e} } // NewNode returns a DOT-aware Node. -func (g *DOTMarkovChain) NewNode() graph.Node { - return &Node{Node: g.AbsorbingMarkovChain.NewNode()} +func (g *DOTDirectedGraph) NewNode() graph.Node { + return &Node{Node: g.DirectedGraph.NewNode()} } // SetLine adds a DOT-aware weighted line to the Markov chain. -func (g *DOTMarkovChain) SetLine(e graph.Line) { - g.AbsorbingMarkovChain.SetWeightedLine(e.(*weightedLine)) +func (g *DOTDirectedGraph) SetLine(e graph.Line) { + g.DirectedGraph.SetWeightedLine(e.(*weightedLine)) } diff --git a/cmd/internal/markov/dot/nodes_edges.go b/cmd/internal/graph/dot/nodes_edges.go similarity index 100% rename from cmd/internal/markov/dot/nodes_edges.go rename to cmd/internal/graph/dot/nodes_edges.go diff --git a/cmd/internal/markov/absorbing.go b/cmd/internal/graph/graph.go similarity index 76% rename from cmd/internal/markov/absorbing.go rename to cmd/internal/graph/graph.go index eaa1c57..8453ea5 100644 --- a/cmd/internal/markov/absorbing.go +++ b/cmd/internal/graph/graph.go @@ -14,7 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see . */ -package markov +package graph import ( "gonum.org/v1/gonum/graph" @@ -23,22 +23,20 @@ import ( "gonum.org/v1/gonum/mat" ) -// AbsorbingMarkovChain is a graph representing an absorbing Markov chain. This -// embeds a multi.WeightedDirectedGraph (as opposed to +// DirectedGraph embeds a multi.WeightedDirectedGraph (as opposed to // simple.WeightedDirectedGraph) to handle self loops. -type AbsorbingMarkovChain struct { +type DirectedGraph struct { *multi.WeightedDirectedGraph } -// NewAbsorbingMarkovChain returns an absorbing Markov chain with no nodes or -// edges. -func NewAbsorbingMarkovChain() *AbsorbingMarkovChain { - return &AbsorbingMarkovChain{WeightedDirectedGraph: multi.NewWeightedDirectedGraph()} +// NewDirectedGraph returns a graph with no nodes or edges. +func NewDirectedGraph() *DirectedGraph { + return &DirectedGraph{WeightedDirectedGraph: multi.NewWeightedDirectedGraph()} } // AbsorbingNodes returns all the nodes in the Markov chain identified as // absorbing nodes. -func (g *AbsorbingMarkovChain) AbsorbingNodes() []graph.Node { +func (g *DirectedGraph) AbsorbingNodes() []graph.Node { absorbingNodes := make([]graph.Node, 0) for nodes := g.Nodes(); nodes.Next(); { u := nodes.Node() @@ -58,7 +56,7 @@ func (g *AbsorbingMarkovChain) AbsorbingNodes() []graph.Node { } // AdjacencyMatrix returns the graph's adjacency matrix. -func (g *AbsorbingMarkovChain) AdjacencyMatrix() *mat.Dense { +func (g *DirectedGraph) AdjacencyMatrix() *mat.Dense { adj := simple.NewDirectedMatrix(g.Nodes().Len(), 0, 0, 0) for edges := g.WeightedEdges(); edges.Next(); { e := edges.WeightedEdge() diff --git a/cmd/root.go b/cmd/root.go index 290f86c..be4b4f1 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -21,7 +21,7 @@ import ( "fmt" "os" - markovDOT "scm.dairydemon.net/filifa/gv2adj/cmd/internal/markov/dot" + idot "scm.dairydemon.net/filifa/gv2adj/cmd/internal/graph/dot" "github.com/spf13/cobra" "gonum.org/v1/gonum/graph/encoding/dot" @@ -58,7 +58,7 @@ func parse(cmd *cobra.Command, args []string) { panic(err) } - graph := markovDOT.NewDOTMarkovChain() + graph := idot.NewDOTDirectedGraph() err = dot.UnmarshalMulti(data, graph) if err != nil { panic(err) @@ -72,7 +72,7 @@ func parse(cmd *cobra.Command, args []string) { outputMatrix(matrix) } -func orderedAdjMatrix(g *markovDOT.DOTMarkovChain) (*mat.Dense, error) { +func orderedAdjMatrix(g *idot.DOTDirectedGraph) (*mat.Dense, error) { matrix := g.AdjacencyMatrix() if len(nodeOrder) == 0 { return matrix, nil @@ -86,7 +86,7 @@ func orderedAdjMatrix(g *markovDOT.DOTMarkovChain) (*mat.Dense, error) { nodes := g.Nodes() newOrder := make([]int, nodes.Len()) for nodes.Next() { - node := nodes.Node().(*markovDOT.Node) + node := nodes.Node().(*idot.Node) id := node.DOTID() var ok bool