本文整理汇总了Golang中github.com/gonum/graph.Edge类的典型用法代码示例。如果您正苦于以下问题:Golang Edge类的具体用法?Golang Edge怎么用?Golang Edge使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Edge类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: RemoveEdge
// RemoveEdge removes the edge between nodes identified by e.From and e.To and
// its adjacent faces from g.
func (g *Graph) RemoveEdge(e graph.Edge) {
h := g.Halfedge(e.From(), e.To())
if h == nil {
// Nothing to do.
return
}
// Remove any adjacent faces.
if h.Face() != nil {
g.RemoveFace(h.Face())
}
if h.Twin().Face() != nil {
g.RemoveFace(h.Twin().Face())
}
// Detach both halfedges from their From nodes and update affected
// halfedges.
detach(h)
detach(h.Twin())
id := h.Edge().ID()
delete(g.edges, id)
if g.nextEdgeID != 0 && id == g.nextEdgeID {
g.nextEdgeID--
}
g.freeEdges[id] = struct{}{}
}
示例2: Cost
func (g *TileGraph) Cost(e graph.Edge) float64 {
if edge := g.EdgeBetween(e.Head(), e.Tail()); edge != nil {
return 1
}
return inf
}
示例3: Weight
func (g *TileGraph) Weight(e graph.Edge) float64 {
if edge := g.EdgeBetween(e.From(), e.To()); edge != nil {
return 1
}
return inf
}
示例4: Cost
func (g *Graph) Cost(e graph.Edge) float64 {
if n, ok := g.neighbors[e.Head().ID()]; ok {
if we, ok := n[e.Tail().ID()]; ok {
return we.Cost
}
}
return inf
}
示例5: SetEdgeWeight
func (g *DirectedDenseGraph) SetEdgeWeight(e graph.Edge, weight float64) {
fid := e.From().ID()
tid := e.To().ID()
if fid == tid {
panic("concrete: set edge cost of illegal edge")
}
g.mat.Set(fid, tid, weight)
}
示例6: Weight
func (g *DirectedGraph) Weight(e graph.Edge) float64 {
if s, ok := g.successors[e.From().ID()]; ok {
if we, ok := s[e.To().ID()]; ok {
return we.Cost
}
}
return inf
}
示例7: Cost
func (g *DirectedGraph) Cost(e graph.Edge) float64 {
if s, ok := g.successors[e.Head().ID()]; ok {
if we, ok := s[e.Tail().ID()]; ok {
return we.Cost
}
}
return inf
}
示例8: Weight
func (g *Graph) Weight(e graph.Edge) float64 {
if n, ok := g.neighbors[e.From().ID()]; ok {
if we, ok := n[e.To().ID()]; ok {
return we.Cost
}
}
return inf
}
示例9: RemoveUndirectedEdge
func (g *Graph) RemoveUndirectedEdge(e graph.Edge) {
head, tail := e.Head(), e.Tail()
if _, ok := g.nodeMap[head.ID()]; !ok {
return
} else if _, ok := g.nodeMap[tail.ID()]; !ok {
return
}
delete(g.neighbors[head.ID()], tail.ID())
delete(g.neighbors[tail.ID()], head.ID())
}
示例10: RemoveEdge
func (g *UndirectedGraph) RemoveEdge(e graph.Edge) {
from, to := e.From(), e.To()
if _, ok := g.nodeMap[from.ID()]; !ok {
return
} else if _, ok := g.nodeMap[to.ID()]; !ok {
return
}
delete(g.neighbors[from.ID()], to.ID())
delete(g.neighbors[to.ID()], from.ID())
}
示例11: RemoveEdge
// RemoveEdge removes e from the graph, leaving the terminal nodes. If the edge does not exist
// it is a no-op.
func (g *DirectedMatrix) RemoveEdge(e graph.Edge) {
fid := e.From().ID()
if !g.has(fid) {
return
}
tid := e.To().ID()
if !g.has(tid) {
return
}
g.mat.Set(fid, tid, g.absent)
}
示例12: RemoveDirectedEdge
func (g *DirectedGraph) RemoveDirectedEdge(e graph.Edge) {
head, tail := e.Head(), e.Tail()
if _, ok := g.nodeMap[head.ID()]; !ok {
return
} else if _, ok := g.nodeMap[tail.ID()]; !ok {
return
}
delete(g.successors[head.ID()], tail.ID())
delete(g.predecessors[tail.ID()], head.ID())
}
示例13: RemoveEdge
// RemoveEdge removes e from the graph, leaving the terminal nodes. If the edge does not exist
// it is a no-op.
func (g *DirectedGraph) RemoveEdge(e graph.Edge) {
from, to := e.From(), e.To()
if _, ok := g.nodes[from.ID()]; !ok {
return
}
if _, ok := g.nodes[to.ID()]; !ok {
return
}
delete(g.from[from.ID()], to.ID())
delete(g.to[to.ID()], from.ID())
}
示例14: AddUndirectedEdge
func (g *Graph) AddUndirectedEdge(e graph.Edge, cost float64) {
head, tail := e.Head(), e.Tail()
if !g.NodeExists(head) {
g.AddNode(head)
}
if !g.NodeExists(tail) {
g.AddNode(tail)
}
g.neighbors[head.ID()][tail.ID()] = WeightedEdge{Edge: e, Cost: cost}
g.neighbors[tail.ID()][head.ID()] = WeightedEdge{Edge: e, Cost: cost}
}
示例15: SetEdge
func (g *gnDirected) SetEdge(e graph.Edge) {
switch {
case e.From().ID() == e.To().ID():
g.addSelfLoop = true
return
case g.DirectedBuilder.HasEdgeFromTo(e.From(), e.To()):
g.addMultipleEdge = true
}
g.DirectedBuilder.SetEdge(e)
}