本文整理汇总了Golang中github.com/gonum/graph.Edge类的典型用法代码示例。如果您正苦于以下问题:Golang Edge类的具体用法?Golang Edge怎么用?Golang Edge使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Edge类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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{}{}
}
开发者ID:vladimir-ch,项目名称:dcel,代码行数:29,代码来源:dcel.go
示例2: Cost
func (g *TileGraph) Cost(e graph.Edge) float64 {
if edge := g.EdgeBetween(e.Head(), e.Tail()); edge != nil {
return 1
}
return inf
}
开发者ID:cjnygard,项目名称:origin,代码行数:7,代码来源:tilegraph.go
示例3: Weight
func (g *TileGraph) Weight(e graph.Edge) float64 {
if edge := g.EdgeBetween(e.From(), e.To()); edge != nil {
return 1
}
return inf
}
开发者ID:baijum,项目名称:graph,代码行数:7,代码来源:tilegraph.go
示例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
}
开发者ID:cjnygard,项目名称:origin,代码行数:8,代码来源:mutablegr.go
示例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)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:8,代码来源:dense_directed_matrix.go
示例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
}
开发者ID:RomainVabre,项目名称:origin,代码行数:8,代码来源:directed.go
示例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
}
开发者ID:cjnygard,项目名称:origin,代码行数:8,代码来源:mutdir.go
示例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
}
开发者ID:RomainVabre,项目名称:origin,代码行数:8,代码来源:undirected.go
示例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())
}
开发者ID:cjnygard,项目名称:origin,代码行数:11,代码来源:mutablegr.go
示例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())
}
开发者ID:jacobxk,项目名称:graph,代码行数:11,代码来源:undirected.go
示例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)
}
开发者ID:sbinet,项目名称:gonum-graph,代码行数:13,代码来源:dense_directed_matrix.go
示例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())
}
开发者ID:cjnygard,项目名称:origin,代码行数:11,代码来源:mutdir.go
示例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())
}
开发者ID:sbinet,项目名称:gonum-graph,代码行数:14,代码来源:directed.go
示例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}
}
开发者ID:cjnygard,项目名称:origin,代码行数:13,代码来源:mutablegr.go
示例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)
}
开发者ID:sbinet,项目名称:gonum-graph,代码行数:11,代码来源:batagelj_brandes_test.go
示例16: Weight
// Weight returns the weight of the given edge.
func (g *Grid) Weight(e graph.Edge) float64 {
if e := g.EdgeBetween(e.From(), e.To()); e != nil {
if !g.AllowDiagonal {
return 1
}
ux, uy := g.XY(e.From())
vx, vy := g.XY(e.To())
return math.Hypot(ux-vx, uy-vy)
}
return math.Inf(1)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:13,代码来源:grid.go
示例17: SetEdge
// SetEdge adds e, an edge from one node to another. If the nodes do not exist, they are added.
// It will panic if the IDs of the e.From and e.To are equal.
func (g *UndirectedGraph) SetEdge(e graph.Edge) {
var (
from = e.From()
fid = from.ID()
to = e.To()
tid = to.ID()
)
if fid == tid {
panic("simple: adding self edge")
}
if !g.Has(from) {
g.AddNode(from)
}
if !g.Has(to) {
g.AddNode(to)
}
g.edges[fid][tid] = e
g.edges[tid][fid] = e
}
开发者ID:sbinet,项目名称:gonum-graph,代码行数:24,代码来源:undirected.go
示例18: SetEdgeWeight
func (g *UndirectedDenseGraph) SetEdgeWeight(e graph.Edge) {
fid := e.From().ID()
tid := e.To().ID()
if fid == tid {
panic("concrete: set edge cost of illegal edge")
}
g.mat.SetSym(fid, tid, e.Weight())
}
开发者ID:jmptrader,项目名称:graph,代码行数:8,代码来源:dense_undirected_matrix.go
示例19: SetEdge
// SetEdge 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, SetEdge panics.
func (g *DirectedMatrix) SetEdge(e graph.Edge) {
fid := e.From().ID()
tid := e.To().ID()
if fid == tid {
panic("simple: set illegal edge")
}
g.mat.Set(fid, tid, e.Weight())
}
开发者ID:sbinet,项目名称:gonum-graph,代码行数:10,代码来源:dense_directed_matrix.go
示例20: SetEdge
func (g *DirectedGraph) SetEdge(e graph.Edge, cost float64) {
var (
from = e.From()
fid = from.ID()
to = e.To()
tid = to.ID()
)
if fid == tid {
panic("concrete: adding self edge")
}
if !g.Has(from) {
g.AddNode(from)
}
if !g.Has(to) {
g.AddNode(to)
}
g.successors[fid][tid] = WeightedEdge{Edge: e, Cost: cost}
g.predecessors[tid][fid] = WeightedEdge{Edge: e, Cost: cost}
}
开发者ID:RomainVabre,项目名称:origin,代码行数:23,代码来源:directed.go
注:本文中的github.com/gonum/graph.Edge类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论