gv2adj/cmd/internal/markov/dot/markov.go

54 lines
1.7 KiB
Go

/*
Copyright © 2025 filifa
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
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 <http://www.gnu.org/licenses/>.
*/
package dot
import (
"math"
"scm.dairydemon.net/filifa/gv2adj/cmd/internal/markov"
"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
}
// NewDOTMarkovChain returns an absorbing Markov chain with no nodes or
// edges.
func NewDOTMarkovChain() *DOTMarkovChain {
return &DOTMarkovChain{AbsorbingMarkovChain: markov.NewAbsorbingMarkovChain()}
}
// 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)
return &weightedLine{WeightedLine: e}
}
// NewNode returns a DOT-aware Node.
func (g *DOTMarkovChain) NewNode() graph.Node {
return &Node{Node: g.AbsorbingMarkovChain.NewNode()}
}
// SetLine adds a DOT-aware weighted line to the Markov chain.
func (g *DOTMarkovChain) SetLine(e graph.Line) {
g.AbsorbingMarkovChain.SetWeightedLine(e.(*weightedLine))
}