rename things
This commit is contained in:
parent
6cc1de4d05
commit
27a7ce31e9
|
@ -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))
|
||||
}
|
|
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
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()
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue