Documentation ¶
Overview ¶
Package simple provides a suite of simple graph implementations satisfying the gonum/graph interfaces.
All types in simple return the graph.Empty value for empty iterators.
Index ¶
- type DirectedGraph
- func (g *DirectedGraph) AddNode(n graph.Node)
- func (g *DirectedGraph) Edge(uid, vid int64) graph.Edge
- func (g *DirectedGraph) Edges() graph.Edges
- func (g *DirectedGraph) From(id int64) graph.Nodes
- func (g *DirectedGraph) HasEdgeBetween(xid, yid int64) bool
- func (g *DirectedGraph) HasEdgeFromTo(uid, vid int64) bool
- func (g *DirectedGraph) NewEdge(from, to graph.Node) graph.Edge
- func (g *DirectedGraph) NewNode() graph.Node
- func (g *DirectedGraph) Node(id int64) graph.Node
- func (g *DirectedGraph) Nodes() graph.Nodes
- func (g *DirectedGraph) RemoveEdge(fid, tid int64)
- func (g *DirectedGraph) RemoveNode(id int64)
- func (g *DirectedGraph) SetEdge(e graph.Edge)
- func (g *DirectedGraph) To(id int64) graph.Nodes
- type DirectedMatrix
- func (g *DirectedMatrix) Edge(uid, vid int64) graph.Edge
- func (g *DirectedMatrix) Edges() graph.Edges
- func (g *DirectedMatrix) From(id int64) graph.Nodes
- func (g *DirectedMatrix) HasEdgeBetween(xid, yid int64) bool
- func (g *DirectedMatrix) HasEdgeFromTo(uid, vid int64) bool
- func (g *DirectedMatrix) Matrix() mat.Matrix
- func (g *DirectedMatrix) Node(id int64) graph.Node
- func (g *DirectedMatrix) Nodes() graph.Nodes
- func (g *DirectedMatrix) RemoveEdge(fid, tid int64)
- func (g *DirectedMatrix) SetEdge(e graph.Edge)
- func (g *DirectedMatrix) SetWeightedEdge(e graph.WeightedEdge)
- func (g *DirectedMatrix) To(id int64) graph.Nodes
- func (g *DirectedMatrix) Weight(xid, yid int64) (w float64, ok bool)
- func (g *DirectedMatrix) WeightedEdge(uid, vid int64) graph.WeightedEdge
- func (g *DirectedMatrix) WeightedEdges() graph.WeightedEdges
- type Edge
- type Node
- type UndirectedGraph
- func (g *UndirectedGraph) AddNode(n graph.Node)
- func (g *UndirectedGraph) Edge(uid, vid int64) graph.Edge
- func (g *UndirectedGraph) EdgeBetween(xid, yid int64) graph.Edge
- func (g *UndirectedGraph) Edges() graph.Edges
- func (g *UndirectedGraph) From(id int64) graph.Nodes
- func (g *UndirectedGraph) HasEdgeBetween(xid, yid int64) bool
- func (g *UndirectedGraph) NewEdge(from, to graph.Node) graph.Edge
- func (g *UndirectedGraph) NewNode() graph.Node
- func (g *UndirectedGraph) Node(id int64) graph.Node
- func (g *UndirectedGraph) Nodes() graph.Nodes
- func (g *UndirectedGraph) RemoveEdge(fid, tid int64)
- func (g *UndirectedGraph) RemoveNode(id int64)
- func (g *UndirectedGraph) SetEdge(e graph.Edge)
- type UndirectedMatrix
- func (g *UndirectedMatrix) Edge(uid, vid int64) graph.Edge
- func (g *UndirectedMatrix) EdgeBetween(uid, vid int64) graph.Edge
- func (g *UndirectedMatrix) Edges() graph.Edges
- func (g *UndirectedMatrix) From(id int64) graph.Nodes
- func (g *UndirectedMatrix) HasEdgeBetween(uid, vid int64) bool
- func (g *UndirectedMatrix) Matrix() mat.Matrix
- func (g *UndirectedMatrix) Node(id int64) graph.Node
- func (g *UndirectedMatrix) Nodes() graph.Nodes
- func (g *UndirectedMatrix) RemoveEdge(fid, tid int64)
- func (g *UndirectedMatrix) SetEdge(e graph.Edge)
- func (g *UndirectedMatrix) SetWeightedEdge(e graph.WeightedEdge)
- func (g *UndirectedMatrix) Weight(xid, yid int64) (w float64, ok bool)
- func (g *UndirectedMatrix) WeightedEdge(uid, vid int64) graph.WeightedEdge
- func (g *UndirectedMatrix) WeightedEdgeBetween(uid, vid int64) graph.WeightedEdge
- func (g *UndirectedMatrix) WeightedEdges() graph.WeightedEdges
- type WeightedDirectedGraph
- func (g *WeightedDirectedGraph) AddNode(n graph.Node)
- func (g *WeightedDirectedGraph) Edge(uid, vid int64) graph.Edge
- func (g *WeightedDirectedGraph) Edges() graph.Edges
- func (g *WeightedDirectedGraph) From(id int64) graph.Nodes
- func (g *WeightedDirectedGraph) HasEdgeBetween(xid, yid int64) bool
- func (g *WeightedDirectedGraph) HasEdgeFromTo(uid, vid int64) bool
- func (g *WeightedDirectedGraph) NewNode() graph.Node
- func (g *WeightedDirectedGraph) NewWeightedEdge(from, to graph.Node, weight float64) graph.WeightedEdge
- func (g *WeightedDirectedGraph) Node(id int64) graph.Node
- func (g *WeightedDirectedGraph) Nodes() graph.Nodes
- func (g *WeightedDirectedGraph) RemoveEdge(fid, tid int64)
- func (g *WeightedDirectedGraph) RemoveNode(id int64)
- func (g *WeightedDirectedGraph) SetWeightedEdge(e graph.WeightedEdge)
- func (g *WeightedDirectedGraph) To(id int64) graph.Nodes
- func (g *WeightedDirectedGraph) Weight(xid, yid int64) (w float64, ok bool)
- func (g *WeightedDirectedGraph) WeightedEdge(uid, vid int64) graph.WeightedEdge
- func (g *WeightedDirectedGraph) WeightedEdges() graph.WeightedEdges
- type WeightedEdge
- type WeightedUndirectedGraph
- func (g *WeightedUndirectedGraph) AddNode(n graph.Node)
- func (g *WeightedUndirectedGraph) Edge(uid, vid int64) graph.Edge
- func (g *WeightedUndirectedGraph) EdgeBetween(xid, yid int64) graph.Edge
- func (g *WeightedUndirectedGraph) Edges() graph.Edges
- func (g *WeightedUndirectedGraph) From(id int64) graph.Nodes
- func (g *WeightedUndirectedGraph) HasEdgeBetween(xid, yid int64) bool
- func (g *WeightedUndirectedGraph) NewNode() graph.Node
- func (g *WeightedUndirectedGraph) NewWeightedEdge(from, to graph.Node, weight float64) graph.WeightedEdge
- func (g *WeightedUndirectedGraph) Node(id int64) graph.Node
- func (g *WeightedUndirectedGraph) Nodes() graph.Nodes
- func (g *WeightedUndirectedGraph) RemoveEdge(fid, tid int64)
- func (g *WeightedUndirectedGraph) RemoveNode(id int64)
- func (g *WeightedUndirectedGraph) SetWeightedEdge(e graph.WeightedEdge)
- func (g *WeightedUndirectedGraph) Weight(xid, yid int64) (w float64, ok bool)
- func (g *WeightedUndirectedGraph) WeightedEdge(uid, vid int64) graph.WeightedEdge
- func (g *WeightedUndirectedGraph) WeightedEdgeBetween(xid, yid int64) graph.WeightedEdge
- func (g *WeightedUndirectedGraph) WeightedEdges() graph.WeightedEdges
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type DirectedGraph ¶
type DirectedGraph struct {
// contains filtered or unexported fields
}
DirectedGraph implements a generalized directed graph.
func NewDirectedGraph ¶
func NewDirectedGraph() *DirectedGraph
NewDirectedGraph returns a DirectedGraph.
func (*DirectedGraph) AddNode ¶
func (g *DirectedGraph) AddNode(n graph.Node)
AddNode adds n to the graph. It panics if the added node ID matches an existing node ID.
func (*DirectedGraph) Edge ¶
func (g *DirectedGraph) Edge(uid, vid int64) graph.Edge
Edge returns the edge from u to v if such an edge exists and nil otherwise. The node v must be directly reachable from u as defined by the From method.
func (*DirectedGraph) Edges ¶
func (g *DirectedGraph) Edges() graph.Edges
Edges returns all the edges in the graph.
func (*DirectedGraph) From ¶
func (g *DirectedGraph) From(id int64) graph.Nodes
From returns all nodes in g that can be reached directly from n.
func (*DirectedGraph) HasEdgeBetween ¶
func (g *DirectedGraph) HasEdgeBetween(xid, yid int64) bool
HasEdgeBetween returns whether an edge exists between nodes x and y without considering direction.
func (*DirectedGraph) HasEdgeFromTo ¶
func (g *DirectedGraph) HasEdgeFromTo(uid, vid int64) bool
HasEdgeFromTo returns whether an edge exists in the graph from u to v.
func (*DirectedGraph) NewEdge ¶
func (g *DirectedGraph) NewEdge(from, to graph.Node) graph.Edge
NewEdge returns a new Edge from the source to the destination node.
func (*DirectedGraph) NewNode ¶
func (g *DirectedGraph) NewNode() graph.Node
NewNode returns a new unique Node to be added to g. The Node's ID does not become valid in g until the Node is added to g.
func (*DirectedGraph) Node ¶
func (g *DirectedGraph) Node(id int64) graph.Node
Node returns the node with the given ID if it exists in the graph, and nil otherwise.
func (*DirectedGraph) Nodes ¶
func (g *DirectedGraph) Nodes() graph.Nodes
Nodes returns all the nodes in the graph.
func (*DirectedGraph) RemoveEdge ¶
func (g *DirectedGraph) RemoveEdge(fid, tid int64)
RemoveEdge removes the edge with the given end point IDs from the graph, leaving the terminal nodes. If the edge does not exist it is a no-op.
func (*DirectedGraph) RemoveNode ¶
func (g *DirectedGraph) RemoveNode(id int64)
RemoveNode removes the node with the given ID from the graph, as well as any edges attached to it. If the node is not in the graph it is a no-op.
func (*DirectedGraph) SetEdge ¶
func (g *DirectedGraph) SetEdge(e graph.Edge)
SetEdge adds e, an edge from one node to another. If the nodes do not exist, they are added and are set to the nodes of the edge otherwise. It will panic if the IDs of the e.From and e.To are equal.
type DirectedMatrix ¶
type DirectedMatrix struct {
// contains filtered or unexported fields
}
DirectedMatrix represents a directed graph using an adjacency matrix such that all IDs are in a contiguous block from 0 to n-1. Edges are stored implicitly as an edge weight, so edges stored in the graph are not recoverable.
func NewDirectedMatrix ¶
func NewDirectedMatrix(n int, init, self, absent float64) *DirectedMatrix
NewDirectedMatrix creates a directed dense graph with n nodes. All edges are initialized with the weight given by init. The self parameter specifies the cost of self connection, and absent specifies the weight returned for absent edges.
func NewDirectedMatrixFrom ¶
func NewDirectedMatrixFrom(nodes []graph.Node, init, self, absent float64) *DirectedMatrix
NewDirectedMatrixFrom creates a directed dense graph with the given nodes. The IDs of the nodes must be contiguous from 0 to len(nodes)-1, but may be in any order. If IDs are not contiguous NewDirectedMatrixFrom will panic. All edges are initialized with the weight given by init. The self parameter specifies the cost of self connection, and absent specifies the weight returned for absent edges.
func (*DirectedMatrix) Edge ¶
func (g *DirectedMatrix) Edge(uid, vid int64) graph.Edge
Edge returns the edge from u to v if such an edge exists and nil otherwise. The node v must be directly reachable from u as defined by the From method.
func (*DirectedMatrix) Edges ¶
func (g *DirectedMatrix) Edges() graph.Edges
Edges returns all the edges in the graph.
func (*DirectedMatrix) From ¶
func (g *DirectedMatrix) From(id int64) graph.Nodes
From returns all nodes in g that can be reached directly from n.
func (*DirectedMatrix) HasEdgeBetween ¶
func (g *DirectedMatrix) HasEdgeBetween(xid, yid int64) bool
HasEdgeBetween returns whether an edge exists between nodes x and y without considering direction.
func (*DirectedMatrix) HasEdgeFromTo ¶
func (g *DirectedMatrix) HasEdgeFromTo(uid, vid int64) bool
HasEdgeFromTo returns whether an edge exists in the graph from u to v.
func (*DirectedMatrix) Matrix ¶
func (g *DirectedMatrix) Matrix() mat.Matrix
Matrix returns the mat.Matrix representation of the graph. The orientation of the matrix is such that the matrix entry at G_{ij} is the weight of the edge from node i to node j.
func (*DirectedMatrix) Node ¶
func (g *DirectedMatrix) Node(id int64) graph.Node
Node returns the node with the given ID if it exists in the graph, and nil otherwise.
func (*DirectedMatrix) Nodes ¶
func (g *DirectedMatrix) Nodes() graph.Nodes
Nodes returns all the nodes in the graph.
func (*DirectedMatrix) RemoveEdge ¶
func (g *DirectedMatrix) RemoveEdge(fid, tid int64)
RemoveEdge removes the edge with the given end point nodes from the graph, leaving the terminal nodes. If the edge does not exist it is a no-op.
func (*DirectedMatrix) SetEdge ¶
func (g *DirectedMatrix) SetEdge(e graph.Edge)
SetEdge sets e, an edge from one node to another with unit weight. If the ends of the edge are not in g or the edge is a self loop, SetEdge panics. SetEdge will store the nodes of e in the graph if it was initialized with NewDirectedMatrixFrom.
func (*DirectedMatrix) SetWeightedEdge ¶
func (g *DirectedMatrix) SetWeightedEdge(e graph.WeightedEdge)
SetWeightedEdge sets e, an edge from one node to another. If the ends of the edge are not in g or the edge is a self loop, SetWeightedEdge panics. SetWeightedEdge will store the nodes of e in the graph if it was initialized with NewDirectedMatrixFrom.
func (*DirectedMatrix) To ¶
func (g *DirectedMatrix) To(id int64) graph.Nodes
To returns all nodes in g that can reach directly to n.
func (*DirectedMatrix) Weight ¶
func (g *DirectedMatrix) Weight(xid, yid int64) (w float64, ok bool)
Weight returns the weight for the edge between x and y if Edge(x, y) returns a non-nil Edge. If x and y are the same node or there is no joining edge between the two nodes the weight value returned is either the graph's absent or self value. Weight returns true if an edge exists between x and y or if x and y have the same ID, false otherwise.
func (*DirectedMatrix) WeightedEdge ¶
func (g *DirectedMatrix) WeightedEdge(uid, vid int64) graph.WeightedEdge
WeightedEdge returns the weighted edge from u to v if such an edge exists and nil otherwise. The node v must be directly reachable from u as defined by the From method.
func (*DirectedMatrix) WeightedEdges ¶
func (g *DirectedMatrix) WeightedEdges() graph.WeightedEdges
WeightedEdges returns all the edges in the graph.
type Edge ¶
Edge is a simple graph edge.
func (Edge) ReversedEdge ¶
ReversedLine returns a new Edge with the F and T fields swapped.
type UndirectedGraph ¶
type UndirectedGraph struct {
// contains filtered or unexported fields
}
UndirectedGraph implements a generalized undirected graph.
func NewUndirectedGraph ¶
func NewUndirectedGraph() *UndirectedGraph
NewUndirectedGraph returns an UndirectedGraph.
func (*UndirectedGraph) AddNode ¶
func (g *UndirectedGraph) AddNode(n graph.Node)
AddNode adds n to the graph. It panics if the added node ID matches an existing node ID.
func (*UndirectedGraph) Edge ¶
func (g *UndirectedGraph) Edge(uid, vid int64) graph.Edge
Edge returns the edge from u to v if such an edge exists and nil otherwise. The node v must be directly reachable from u as defined by the From method.
func (*UndirectedGraph) EdgeBetween ¶
func (g *UndirectedGraph) EdgeBetween(xid, yid int64) graph.Edge
EdgeBetween returns the edge between nodes x and y.
func (*UndirectedGraph) Edges ¶
func (g *UndirectedGraph) Edges() graph.Edges
Edges returns all the edges in the graph.
func (*UndirectedGraph) From ¶
func (g *UndirectedGraph) From(id int64) graph.Nodes
From returns all nodes in g that can be reached directly from n.
func (*UndirectedGraph) HasEdgeBetween ¶
func (g *UndirectedGraph) HasEdgeBetween(xid, yid int64) bool
HasEdgeBetween returns whether an edge exists between nodes x and y.
func (*UndirectedGraph) NewEdge ¶
func (g *UndirectedGraph) NewEdge(from, to graph.Node) graph.Edge
NewEdge returns a new Edge from the source to the destination node.
func (*UndirectedGraph) NewNode ¶
func (g *UndirectedGraph) NewNode() graph.Node
NewNode returns a new unique Node to be added to g. The Node's ID does not become valid in g until the Node is added to g.
func (*UndirectedGraph) Node ¶
func (g *UndirectedGraph) Node(id int64) graph.Node
Node returns the node with the given ID if it exists in the graph, and nil otherwise.
func (*UndirectedGraph) Nodes ¶
func (g *UndirectedGraph) Nodes() graph.Nodes
Nodes returns all the nodes in the graph.
func (*UndirectedGraph) RemoveEdge ¶
func (g *UndirectedGraph) RemoveEdge(fid, tid int64)
RemoveEdge removes the edge with the given end IDs from the graph, leaving the terminal nodes. If the edge does not exist it is a no-op.
func (*UndirectedGraph) RemoveNode ¶
func (g *UndirectedGraph) RemoveNode(id int64)
RemoveNode removes the node with the given ID from the graph, as well as any edges attached to it. If the node is not in the graph it is a no-op.
func (*UndirectedGraph) SetEdge ¶
func (g *UndirectedGraph) SetEdge(e graph.Edge)
SetEdge adds e, an edge from one node to another. If the nodes do not exist, they are added and are set to the nodes of the edge otherwise. It will panic if the IDs of the e.From and e.To are equal.
type UndirectedMatrix ¶
type UndirectedMatrix struct {
// contains filtered or unexported fields
}
UndirectedMatrix represents an undirected graph using an adjacency matrix such that all IDs are in a contiguous block from 0 to n-1. Edges are stored implicitly as an edge weight, so edges stored in the graph are not recoverable.
func NewUndirectedMatrix ¶
func NewUndirectedMatrix(n int, init, self, absent float64) *UndirectedMatrix
NewUndirectedMatrix creates an undirected dense graph with n nodes. All edges are initialized with the weight given by init. The self parameter specifies the cost of self connection, and absent specifies the weight returned for absent edges.
func NewUndirectedMatrixFrom ¶
func NewUndirectedMatrixFrom(nodes []graph.Node, init, self, absent float64) *UndirectedMatrix
NewUndirectedMatrixFrom creates an undirected dense graph with the given nodes. The IDs of the nodes must be contiguous from 0 to len(nodes)-1, but may be in any order. If IDs are not contiguous NewUndirectedMatrixFrom will panic. All edges are initialized with the weight given by init. The self parameter specifies the cost of self connection, and absent specifies the weight returned for absent edges.
func (*UndirectedMatrix) Edge ¶
func (g *UndirectedMatrix) Edge(uid, vid int64) graph.Edge
Edge returns the edge from u to v if such an edge exists and nil otherwise. The node v must be directly reachable from u as defined by the From method.
func (*UndirectedMatrix) EdgeBetween ¶
func (g *UndirectedMatrix) EdgeBetween(uid, vid int64) graph.Edge
EdgeBetween returns the edge between nodes x and y.
func (*UndirectedMatrix) Edges ¶
func (g *UndirectedMatrix) Edges() graph.Edges
Edges returns all the edges in the graph.
func (*UndirectedMatrix) From ¶
func (g *UndirectedMatrix) From(id int64) graph.Nodes
From returns all nodes in g that can be reached directly from n.
func (*UndirectedMatrix) HasEdgeBetween ¶
func (g *UndirectedMatrix) HasEdgeBetween(uid, vid int64) bool
HasEdgeBetween returns whether an edge exists between nodes x and y.
func (*UndirectedMatrix) Matrix ¶
func (g *UndirectedMatrix) Matrix() mat.Matrix
Matrix returns the mat.Matrix representation of the graph.
func (*UndirectedMatrix) Node ¶
func (g *UndirectedMatrix) Node(id int64) graph.Node
Node returns the node with the given ID if it exists in the graph, and nil otherwise.
func (*UndirectedMatrix) Nodes ¶
func (g *UndirectedMatrix) Nodes() graph.Nodes
Nodes returns all the nodes in the graph.
func (*UndirectedMatrix) RemoveEdge ¶
func (g *UndirectedMatrix) RemoveEdge(fid, tid int64)
RemoveEdge removes the edge with the given end point IDs from the graph, leaving the terminal nodes. If the edge does not exist it is a no-op.
func (*UndirectedMatrix) SetEdge ¶
func (g *UndirectedMatrix) SetEdge(e graph.Edge)
SetEdge sets e, an edge from one node to another with unit weight. If the ends of the edge are not in g or the edge is a self loop, SetEdge panics. SetEdge will store the nodes of e in the graph if it was initialized with NewUndirectedMatrixFrom.
func (*UndirectedMatrix) SetWeightedEdge ¶
func (g *UndirectedMatrix) SetWeightedEdge(e graph.WeightedEdge)
SetWeightedEdge sets e, an edge from one node to another. If the ends of the edge are not in g or the edge is a self loop, SetWeightedEdge panics. SetWeightedEdge will store the nodes of e in the graph if it was initialized with NewUndirectedMatrixFrom.
func (*UndirectedMatrix) Weight ¶
func (g *UndirectedMatrix) Weight(xid, yid int64) (w float64, ok bool)
Weight returns the weight for the edge between x and y if Edge(x, y) returns a non-nil Edge. If x and y are the same node or there is no joining edge between the two nodes the weight value returned is either the graph's absent or self value. Weight returns true if an edge exists between x and y or if x and y have the same ID, false otherwise.
func (*UndirectedMatrix) WeightedEdge ¶
func (g *UndirectedMatrix) WeightedEdge(uid, vid int64) graph.WeightedEdge
WeightedEdge returns the weighted edge from u to v if such an edge exists and nil otherwise. The node v must be directly reachable from u as defined by the From method.
func (*UndirectedMatrix) WeightedEdgeBetween ¶
func (g *UndirectedMatrix) WeightedEdgeBetween(uid, vid int64) graph.WeightedEdge
WeightedEdgeBetween returns the weighted edge between nodes x and y.
func (*UndirectedMatrix) WeightedEdges ¶
func (g *UndirectedMatrix) WeightedEdges() graph.WeightedEdges
WeightedEdges returns all the edges in the graph.
type WeightedDirectedGraph ¶
type WeightedDirectedGraph struct {
// contains filtered or unexported fields
}
WeightedDirectedGraph implements a generalized weighted directed graph.
func NewWeightedDirectedGraph ¶
func NewWeightedDirectedGraph(self, absent float64) *WeightedDirectedGraph
NewWeightedDirectedGraph returns a WeightedDirectedGraph with the specified self and absent edge weight values.
func (*WeightedDirectedGraph) AddNode ¶
func (g *WeightedDirectedGraph) AddNode(n graph.Node)
AddNode adds n to the graph. It panics if the added node ID matches an existing node ID.
func (*WeightedDirectedGraph) Edge ¶
func (g *WeightedDirectedGraph) Edge(uid, vid int64) graph.Edge
Edge returns the edge from u to v if such an edge exists and nil otherwise. The node v must be directly reachable from u as defined by the From method.
func (*WeightedDirectedGraph) Edges ¶
func (g *WeightedDirectedGraph) Edges() graph.Edges
Edges returns all the edges in the graph.
func (*WeightedDirectedGraph) From ¶
func (g *WeightedDirectedGraph) From(id int64) graph.Nodes
From returns all nodes in g that can be reached directly from n.
func (*WeightedDirectedGraph) HasEdgeBetween ¶
func (g *WeightedDirectedGraph) HasEdgeBetween(xid, yid int64) bool
HasEdgeBetween returns whether an edge exists between nodes x and y without considering direction.
func (*WeightedDirectedGraph) HasEdgeFromTo ¶
func (g *WeightedDirectedGraph) HasEdgeFromTo(uid, vid int64) bool
HasEdgeFromTo returns whether an edge exists in the graph from u to v.
func (*WeightedDirectedGraph) NewNode ¶
func (g *WeightedDirectedGraph) NewNode() graph.Node
NewNode returns a new unique Node to be added to g. The Node's ID does not become valid in g until the Node is added to g.
func (*WeightedDirectedGraph) NewWeightedEdge ¶
func (g *WeightedDirectedGraph) NewWeightedEdge(from, to graph.Node, weight float64) graph.WeightedEdge
NewWeightedEdge returns a new weighted edge from the source to the destination node.
func (*WeightedDirectedGraph) Node ¶
func (g *WeightedDirectedGraph) Node(id int64) graph.Node
Node returns the node with the given ID if it exists in the graph, and nil otherwise.
func (*WeightedDirectedGraph) Nodes ¶
func (g *WeightedDirectedGraph) Nodes() graph.Nodes
Nodes returns all the nodes in the graph.
func (*WeightedDirectedGraph) RemoveEdge ¶
func (g *WeightedDirectedGraph) RemoveEdge(fid, tid int64)
RemoveEdge removes the edge with the given end point IDs from the graph, leaving the terminal nodes. If the edge does not exist it is a no-op.
func (*WeightedDirectedGraph) RemoveNode ¶
func (g *WeightedDirectedGraph) RemoveNode(id int64)
RemoveNode removes the node with the given ID from the graph, as well as any edges attached to it. If the node is not in the graph it is a no-op.
func (*WeightedDirectedGraph) SetWeightedEdge ¶
func (g *WeightedDirectedGraph) SetWeightedEdge(e graph.WeightedEdge)
SetWeightedEdge adds a weighted edge from one node to another. If the nodes do not exist, they are added and are set to the nodes of the edge otherwise. It will panic if the IDs of the e.From and e.To are equal.
func (*WeightedDirectedGraph) To ¶
func (g *WeightedDirectedGraph) To(id int64) graph.Nodes
To returns all nodes in g that can reach directly to n.
func (*WeightedDirectedGraph) Weight ¶
func (g *WeightedDirectedGraph) Weight(xid, yid int64) (w float64, ok bool)
Weight returns the weight for the edge between x and y if Edge(x, y) returns a non-nil Edge. If x and y are the same node or there is no joining edge between the two nodes the weight value returned is either the graph's absent or self value. Weight returns true if an edge exists between x and y or if x and y have the same ID, false otherwise.
func (*WeightedDirectedGraph) WeightedEdge ¶
func (g *WeightedDirectedGraph) WeightedEdge(uid, vid int64) graph.WeightedEdge
WeightedEdge returns the weighted edge from u to v if such an edge exists and nil otherwise. The node v must be directly reachable from u as defined by the From method.
func (*WeightedDirectedGraph) WeightedEdges ¶
func (g *WeightedDirectedGraph) WeightedEdges() graph.WeightedEdges
WeightedEdges returns all the weighted edges in the graph.
type WeightedEdge ¶
WeightedEdge is a simple weighted graph edge.
func (WeightedEdge) From ¶
func (e WeightedEdge) From() graph.Node
From returns the from-node of the edge.
func (WeightedEdge) ReversedEdge ¶
func (e WeightedEdge) ReversedEdge() graph.Edge
ReversedLine returns a new Edge with the F and T fields swapped. The weight of the new Edge is the same as the weight of the receiver.
func (WeightedEdge) Weight ¶
func (e WeightedEdge) Weight() float64
Weight returns the weight of the edge.
type WeightedUndirectedGraph ¶
type WeightedUndirectedGraph struct {
// contains filtered or unexported fields
}
WeightedUndirectedGraph implements a generalized weighted undirected graph.
func NewWeightedUndirectedGraph ¶
func NewWeightedUndirectedGraph(self, absent float64) *WeightedUndirectedGraph
NewWeightedUndirectedGraph returns an WeightedUndirectedGraph with the specified self and absent edge weight values.
func (*WeightedUndirectedGraph) AddNode ¶
func (g *WeightedUndirectedGraph) AddNode(n graph.Node)
AddNode adds n to the graph. It panics if the added node ID matches an existing node ID.
func (*WeightedUndirectedGraph) Edge ¶
func (g *WeightedUndirectedGraph) Edge(uid, vid int64) graph.Edge
Edge returns the edge from u to v if such an edge exists and nil otherwise. The node v must be directly reachable from u as defined by the From method.
func (*WeightedUndirectedGraph) EdgeBetween ¶
func (g *WeightedUndirectedGraph) EdgeBetween(xid, yid int64) graph.Edge
EdgeBetween returns the edge between nodes x and y.
func (*WeightedUndirectedGraph) Edges ¶
func (g *WeightedUndirectedGraph) Edges() graph.Edges
Edges returns all the edges in the graph.
func (*WeightedUndirectedGraph) From ¶
func (g *WeightedUndirectedGraph) From(id int64) graph.Nodes
From returns all nodes in g that can be reached directly from n.
func (*WeightedUndirectedGraph) HasEdgeBetween ¶
func (g *WeightedUndirectedGraph) HasEdgeBetween(xid, yid int64) bool
HasEdgeBetween returns whether an edge exists between nodes x and y.
func (*WeightedUndirectedGraph) NewNode ¶
func (g *WeightedUndirectedGraph) NewNode() graph.Node
NewNode returns a new unique Node to be added to g. The Node's ID does not become valid in g until the Node is added to g.
func (*WeightedUndirectedGraph) NewWeightedEdge ¶
func (g *WeightedUndirectedGraph) NewWeightedEdge(from, to graph.Node, weight float64) graph.WeightedEdge
NewWeightedEdge returns a new weighted edge from the source to the destination node.
func (*WeightedUndirectedGraph) Node ¶
func (g *WeightedUndirectedGraph) Node(id int64) graph.Node
Node returns the node with the given ID if it exists in the graph, and nil otherwise.
func (*WeightedUndirectedGraph) Nodes ¶
func (g *WeightedUndirectedGraph) Nodes() graph.Nodes
Nodes returns all the nodes in the graph.
func (*WeightedUndirectedGraph) RemoveEdge ¶
func (g *WeightedUndirectedGraph) RemoveEdge(fid, tid int64)
RemoveEdge removes the edge with the given end point IDs from the graph, leaving the terminal nodes. If the edge does not exist it is a no-op.
func (*WeightedUndirectedGraph) RemoveNode ¶
func (g *WeightedUndirectedGraph) RemoveNode(id int64)
RemoveNode removes the node with the given ID from the graph, as well as any edges attached to it. If the node is not in the graph it is a no-op.
func (*WeightedUndirectedGraph) SetWeightedEdge ¶
func (g *WeightedUndirectedGraph) SetWeightedEdge(e graph.WeightedEdge)
SetWeightedEdge adds a weighted edge from one node to another. If the nodes do not exist, they are added and are set to the nodes of the edge otherwise. It will panic if the IDs of the e.From and e.To are equal.
func (*WeightedUndirectedGraph) Weight ¶
func (g *WeightedUndirectedGraph) Weight(xid, yid int64) (w float64, ok bool)
Weight returns the weight for the edge between x and y if Edge(x, y) returns a non-nil Edge. If x and y are the same node or there is no joining edge between the two nodes the weight value returned is either the graph's absent or self value. Weight returns true if an edge exists between x and y or if x and y have the same ID, false otherwise.
func (*WeightedUndirectedGraph) WeightedEdge ¶
func (g *WeightedUndirectedGraph) WeightedEdge(uid, vid int64) graph.WeightedEdge
WeightedEdge returns the weighted edge from u to v if such an edge exists and nil otherwise. The node v must be directly reachable from u as defined by the From method.
func (*WeightedUndirectedGraph) WeightedEdgeBetween ¶
func (g *WeightedUndirectedGraph) WeightedEdgeBetween(xid, yid int64) graph.WeightedEdge
WeightedEdgeBetween returns the weighted edge between nodes x and y.
func (*WeightedUndirectedGraph) WeightedEdges ¶
func (g *WeightedUndirectedGraph) WeightedEdges() graph.WeightedEdges
WeightedEdges returns all the weighted edges in the graph.