From f172cab6a025d46dbbeeff1e8ac4709d21a228f1 Mon Sep 17 00:00:00 2001 From: filifa Date: Sun, 4 May 2025 13:24:48 -0400 Subject: [PATCH] make weightedEdge a weightedLine --- cmd/internal/markov/absorbing.go | 12 ++++++------ cmd/internal/markov/nodes_edges.go | 15 ++++----------- cmd/root.go | 2 +- 3 files changed, 11 insertions(+), 18 deletions(-) diff --git a/cmd/internal/markov/absorbing.go b/cmd/internal/markov/absorbing.go index c71f242..fd78203 100644 --- a/cmd/internal/markov/absorbing.go +++ b/cmd/internal/markov/absorbing.go @@ -140,10 +140,10 @@ func (g *AbsorbingMarkovChain) AdjacencyMatrix() *mat.Dense { return a } -// NewEdge returns a weightedEdge that can be added to the Markov chain. -func (g *AbsorbingMarkovChain) NewEdge(from, to graph.Node) graph.Edge { +// NewLine returns a weightedLine that can be added to the Markov chain. +func (g *AbsorbingMarkovChain) NewLine(from, to graph.Node) graph.Line { e := g.WeightedDirectedGraph.NewWeightedLine(from, to, math.NaN()).(multi.WeightedLine) - return &weightedEdge{WeightedLine: e} + return &weightedLine{WeightedLine: e} } // NewNode returns a Node that can be added to the Markov chain. @@ -151,7 +151,7 @@ func (g *AbsorbingMarkovChain) NewNode() graph.Node { return &Node{Node: g.WeightedDirectedGraph.NewNode()} } -// SetEdge adds a weighted edge to the Markov chain. -func (g *AbsorbingMarkovChain) SetEdge(e graph.Edge) { - g.WeightedDirectedGraph.SetWeightedLine(e.(*weightedEdge)) +// SetLine adds a weighted edge to the Markov chain. +func (g *AbsorbingMarkovChain) SetLine(e graph.Line) { + g.WeightedDirectedGraph.SetWeightedLine(e.(*weightedLine)) } diff --git a/cmd/internal/markov/nodes_edges.go b/cmd/internal/markov/nodes_edges.go index ad7acf3..5f7e9d7 100644 --- a/cmd/internal/markov/nodes_edges.go +++ b/cmd/internal/markov/nodes_edges.go @@ -42,25 +42,18 @@ func (n *Node) DOTID() string { return n.dotID } -// weightedEdge is a DOT-aware multi.WeightedLine. By being a +// weightedLine is a DOT-aware multi.WeightedLine. By being a // multi.WeightedLine, it allows for self-loops, which are important for // absorbing Markov chains. // TODO: this is a little confusing, maybe just have checks in the code that // there's only one line in each edge? -type weightedEdge struct { +type weightedLine struct { multi.WeightedLine } -// ReversedEdge returns a new weightedEdge with the same weight, but the -// direction reversed. It exists mainly to satisfy the graph.Edge interface. -func (e *weightedEdge) ReversedEdge() graph.Edge { - revLine := multi.WeightedLine{F: e.T, T: e.F, W: e.W} - return &weightedEdge{WeightedLine: revLine} -} - // SetAttribute enables storing the weight read from a DOT file. It errors if -// an attribute is read that can't be stored in a weightedEdge. -func (e *weightedEdge) SetAttribute(attr encoding.Attribute) error { +// an attribute is read that can't be stored in a weightedLine. +func (e *weightedLine) SetAttribute(attr encoding.Attribute) error { var err error switch attr.Key { diff --git a/cmd/root.go b/cmd/root.go index a22b84b..d6360df 100644 --- a/cmd/root.go +++ b/cmd/root.go @@ -59,7 +59,7 @@ func parse(cmd *cobra.Command, args []string) { } graph := markov.NewAbsorbingMarkovChain() - err = dot.Unmarshal(data, graph) + err = dot.UnmarshalMulti(data, graph) if err != nil { panic(err) }