rename things
This commit is contained in:
parent
6cc1de4d05
commit
27a7ce31e9
|
@ -19,35 +19,35 @@ package dot
|
||||||
import (
|
import (
|
||||||
"math"
|
"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"
|
||||||
"gonum.org/v1/gonum/graph/multi"
|
"gonum.org/v1/gonum/graph/multi"
|
||||||
)
|
)
|
||||||
|
|
||||||
// DOTMarkovChain is a graph representing an absorbing Markov chain.
|
// DOTDirectedGraph is a graph representing an absorbing Markov chain.
|
||||||
type DOTMarkovChain struct {
|
type DOTDirectedGraph struct {
|
||||||
*markov.AbsorbingMarkovChain
|
*igraph.DirectedGraph
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewDOTMarkovChain returns an absorbing Markov chain with no nodes or
|
// NewDOTDirectedGraph returns an absorbing Markov chain with no nodes or
|
||||||
// edges.
|
// edges.
|
||||||
func NewDOTMarkovChain() *DOTMarkovChain {
|
func NewDOTDirectedGraph() *DOTDirectedGraph {
|
||||||
return &DOTMarkovChain{AbsorbingMarkovChain: markov.NewAbsorbingMarkovChain()}
|
return &DOTDirectedGraph{DirectedGraph: igraph.NewDirectedGraph()}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewLine returns a DOT-aware weighted line.
|
// NewLine returns a DOT-aware weighted line.
|
||||||
func (g *DOTMarkovChain) NewLine(from, to graph.Node) graph.Line {
|
func (g *DOTDirectedGraph) NewLine(from, to graph.Node) graph.Line {
|
||||||
e := g.AbsorbingMarkovChain.NewWeightedLine(from, to, math.NaN()).(multi.WeightedLine)
|
e := g.DirectedGraph.NewWeightedLine(from, to, math.NaN()).(multi.WeightedLine)
|
||||||
return &weightedLine{WeightedLine: e}
|
return &weightedLine{WeightedLine: e}
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewNode returns a DOT-aware Node.
|
// NewNode returns a DOT-aware Node.
|
||||||
func (g *DOTMarkovChain) NewNode() graph.Node {
|
func (g *DOTDirectedGraph) NewNode() graph.Node {
|
||||||
return &Node{Node: g.AbsorbingMarkovChain.NewNode()}
|
return &Node{Node: g.DirectedGraph.NewNode()}
|
||||||
}
|
}
|
||||||
|
|
||||||
// SetLine adds a DOT-aware weighted line to the Markov chain.
|
// SetLine adds a DOT-aware weighted line to the Markov chain.
|
||||||
func (g *DOTMarkovChain) SetLine(e graph.Line) {
|
func (g *DOTDirectedGraph) SetLine(e graph.Line) {
|
||||||
g.AbsorbingMarkovChain.SetWeightedLine(e.(*weightedLine))
|
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
|
You should have received a copy of the GNU General Public License
|
||||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
package markov
|
package graph
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"gonum.org/v1/gonum/graph"
|
"gonum.org/v1/gonum/graph"
|
||||||
|
@ -23,22 +23,20 @@ import (
|
||||||
"gonum.org/v1/gonum/mat"
|
"gonum.org/v1/gonum/mat"
|
||||||
)
|
)
|
||||||
|
|
||||||
// AbsorbingMarkovChain is a graph representing an absorbing Markov chain. This
|
// DirectedGraph embeds a multi.WeightedDirectedGraph (as opposed to
|
||||||
// embeds a multi.WeightedDirectedGraph (as opposed to
|
|
||||||
// simple.WeightedDirectedGraph) to handle self loops.
|
// simple.WeightedDirectedGraph) to handle self loops.
|
||||||
type AbsorbingMarkovChain struct {
|
type DirectedGraph struct {
|
||||||
*multi.WeightedDirectedGraph
|
*multi.WeightedDirectedGraph
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewAbsorbingMarkovChain returns an absorbing Markov chain with no nodes or
|
// NewDirectedGraph returns a graph with no nodes or edges.
|
||||||
// edges.
|
func NewDirectedGraph() *DirectedGraph {
|
||||||
func NewAbsorbingMarkovChain() *AbsorbingMarkovChain {
|
return &DirectedGraph{WeightedDirectedGraph: multi.NewWeightedDirectedGraph()}
|
||||||
return &AbsorbingMarkovChain{WeightedDirectedGraph: multi.NewWeightedDirectedGraph()}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AbsorbingNodes returns all the nodes in the Markov chain identified as
|
// AbsorbingNodes returns all the nodes in the Markov chain identified as
|
||||||
// absorbing nodes.
|
// absorbing nodes.
|
||||||
func (g *AbsorbingMarkovChain) AbsorbingNodes() []graph.Node {
|
func (g *DirectedGraph) AbsorbingNodes() []graph.Node {
|
||||||
absorbingNodes := make([]graph.Node, 0)
|
absorbingNodes := make([]graph.Node, 0)
|
||||||
for nodes := g.Nodes(); nodes.Next(); {
|
for nodes := g.Nodes(); nodes.Next(); {
|
||||||
u := nodes.Node()
|
u := nodes.Node()
|
||||||
|
@ -58,7 +56,7 @@ func (g *AbsorbingMarkovChain) AbsorbingNodes() []graph.Node {
|
||||||
}
|
}
|
||||||
|
|
||||||
// AdjacencyMatrix returns the graph's adjacency matrix.
|
// 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)
|
adj := simple.NewDirectedMatrix(g.Nodes().Len(), 0, 0, 0)
|
||||||
for edges := g.WeightedEdges(); edges.Next(); {
|
for edges := g.WeightedEdges(); edges.Next(); {
|
||||||
e := edges.WeightedEdge()
|
e := edges.WeightedEdge()
|
|
@ -21,7 +21,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"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"
|
"github.com/spf13/cobra"
|
||||||
"gonum.org/v1/gonum/graph/encoding/dot"
|
"gonum.org/v1/gonum/graph/encoding/dot"
|
||||||
|
@ -58,7 +58,7 @@ func parse(cmd *cobra.Command, args []string) {
|
||||||
panic(err)
|
panic(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
graph := markovDOT.NewDOTMarkovChain()
|
graph := idot.NewDOTDirectedGraph()
|
||||||
err = dot.UnmarshalMulti(data, graph)
|
err = dot.UnmarshalMulti(data, graph)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -72,7 +72,7 @@ func parse(cmd *cobra.Command, args []string) {
|
||||||
outputMatrix(matrix)
|
outputMatrix(matrix)
|
||||||
}
|
}
|
||||||
|
|
||||||
func orderedAdjMatrix(g *markovDOT.DOTMarkovChain) (*mat.Dense, error) {
|
func orderedAdjMatrix(g *idot.DOTDirectedGraph) (*mat.Dense, error) {
|
||||||
matrix := g.AdjacencyMatrix()
|
matrix := g.AdjacencyMatrix()
|
||||||
if len(nodeOrder) == 0 {
|
if len(nodeOrder) == 0 {
|
||||||
return matrix, nil
|
return matrix, nil
|
||||||
|
@ -86,7 +86,7 @@ func orderedAdjMatrix(g *markovDOT.DOTMarkovChain) (*mat.Dense, error) {
|
||||||
nodes := g.Nodes()
|
nodes := g.Nodes()
|
||||||
newOrder := make([]int, nodes.Len())
|
newOrder := make([]int, nodes.Len())
|
||||||
for nodes.Next() {
|
for nodes.Next() {
|
||||||
node := nodes.Node().(*markovDOT.Node)
|
node := nodes.Node().(*idot.Node)
|
||||||
id := node.DOTID()
|
id := node.DOTID()
|
||||||
|
|
||||||
var ok bool
|
var ok bool
|
||||||
|
|
Loading…
Reference in New Issue