make weightedEdge a weightedLine

This commit is contained in:
filifa 2025-05-04 13:24:48 -04:00
parent 692b8a581b
commit f172cab6a0
3 changed files with 11 additions and 18 deletions

View File

@ -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))
}

View File

@ -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 {

View File

@ -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)
}