本文整理汇总了Golang中github.com/gonum/graph.Node.ID方法的典型用法代码示例。如果您正苦于以下问题:Golang Node.ID方法的具体用法?Golang Node.ID怎么用?Golang Node.ID使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/gonum/graph.Node
的用法示例。
在下文中一共展示了Node.ID方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Degree
func (g *UndirectedGraph) Degree(n graph.Node) int {
if _, ok := g.nodeMap[n.ID()]; !ok {
return 0
}
return len(g.neighbors[n.ID()])
}
示例2: BFSTree
// Builds a BFS tree (as a directed graph) from the given graph and start node.
func BFSTree(g graph.Graph, start graph.Node) *simple.DirectedGraph {
if !g.Has(start) {
panic(fmt.Sprintf("BFSTree: Start node %r not in graph %r", start, g))
}
ret := simple.NewDirectedGraph(0.0, math.Inf(1))
seen := make(map[int]bool)
q := queue.New()
q.Add(start)
ret.AddNode(simple.Node(start.ID()))
for q.Length() > 0 {
node := q.Peek().(graph.Node)
q.Remove()
for _, neighbor := range g.From(node) {
if !seen[neighbor.ID()] {
seen[neighbor.ID()] = true
ret.AddNode(simple.Node(neighbor.ID()))
ret.SetEdge(simple.Edge{F: simple.Node(node.ID()), T: simple.Node(neighbor.ID()), W: g.Edge(node, neighbor).Weight()})
q.Add(neighbor)
}
}
}
return ret
}
示例3: NewImagePipelineFromImageTagLocation
// NewImagePipelineFromImageTagLocation returns the ImagePipeline and all the nodes contributing to it
func NewImagePipelineFromImageTagLocation(g osgraph.Graph, node graph.Node, imageTagLocation ImageTagLocation) (ImagePipeline, IntSet) {
covered := IntSet{}
covered.Insert(node.ID())
flow := ImagePipeline{}
flow.Image = imageTagLocation
for _, input := range g.PredecessorNodesByEdgeKind(node, buildedges.BuildOutputEdgeKind) {
covered.Insert(input.ID())
build := input.(*buildgraph.BuildConfigNode)
if flow.Build != nil {
// report this as an error (unexpected duplicate input build)
}
if build.BuildConfig == nil {
// report this as as a missing build / broken link
break
}
base, src, coveredInputs, _ := findBuildInputs(g, build)
covered.Insert(coveredInputs.List()...)
flow.Build = build
flow.BaseImage = base
flow.Source = src
}
return flow, covered
}
示例4: XY
// XY returns the cartesian coordinates of n. If n is not a node
// in the grid, (NaN, NaN) is returned.
func (l *LimitedVisionGrid) XY(n graph.Node) (x, y float64) {
if !l.Has(n) {
return math.NaN(), math.NaN()
}
r, c := l.RowCol(n.ID())
return float64(c), float64(r)
}
示例5: From
func (g *GraphNode) From(n graph.Node) []graph.Node {
if n.ID() == g.ID() {
return g.neighbors
}
visited := map[int]struct{}{g.id: struct{}{}}
for _, root := range g.roots {
visited[root.ID()] = struct{}{}
if result := root.findNeighbors(n, visited); result != nil {
return result
}
}
for _, neigh := range g.neighbors {
visited[neigh.ID()] = struct{}{}
if gn, ok := neigh.(*GraphNode); ok {
if result := gn.findNeighbors(n, visited); result != nil {
return result
}
}
}
return nil
}
示例6: findNeighbors
func (g *GraphNode) findNeighbors(n graph.Node, visited map[int]struct{}) []graph.Node {
if n.ID() == g.ID() {
return g.neighbors
}
for _, root := range g.roots {
if _, ok := visited[root.ID()]; ok {
continue
}
visited[root.ID()] = struct{}{}
if result := root.findNeighbors(n, visited); result != nil {
return result
}
}
for _, neigh := range g.neighbors {
if _, ok := visited[neigh.ID()]; ok {
continue
}
visited[neigh.ID()] = struct{}{}
if gn, ok := neigh.(*GraphNode); ok {
if result := gn.findNeighbors(n, visited); result != nil {
return result
}
}
}
return nil
}
示例7: Walk
// Walk performs a depth-first traversal of the graph g starting from the given node,
// depending on the the EdgeFilter field and the until parameter if they are non-nil. The
// traversal follows edges for which EdgeFilter(edge) is true and returns the first node
// for which until(node) is true. During the traversal, if the Visit field is non-nil, it
// is called with the nodes joined by each followed edge.
func (d *DepthFirst) Walk(g graph.Graph, from graph.Node, until func(graph.Node) bool) graph.Node {
if d.visited == nil {
d.visited = &intsets.Sparse{}
}
d.stack.Push(from)
d.visited.Insert(from.ID())
for d.stack.Len() > 0 {
t := d.stack.Pop()
if until != nil && until(t) {
return t
}
for _, n := range g.From(t) {
if d.EdgeFilter != nil && !d.EdgeFilter(g.Edge(t, n)) {
continue
}
if d.visited.Has(n.ID()) {
continue
}
if d.Visit != nil {
d.Visit(t, n)
}
d.visited.Insert(n.ID())
d.stack.Push(n)
}
}
return nil
}
示例8: NewImagePipelineFromImageTagLocation
// NewImagePipelineFromImageTagLocation returns the ImagePipeline and all the nodes contributing to it
func NewImagePipelineFromImageTagLocation(g osgraph.Graph, node graph.Node, imageTagLocation ImageTagLocation) (ImagePipeline, IntSet) {
covered := IntSet{}
covered.Insert(node.ID())
flow := ImagePipeline{}
flow.Image = imageTagLocation
for _, input := range g.PredecessorNodesByEdgeKind(node, buildedges.BuildOutputEdgeKind) {
covered.Insert(input.ID())
build := input.(*buildgraph.BuildConfigNode)
if flow.Build != nil {
// report this as an error (unexpected duplicate input build)
}
if build.BuildConfig == nil {
// report this as as a missing build / broken link
break
}
base, src, coveredInputs, _ := findBuildInputs(g, build)
covered.Insert(coveredInputs.List()...)
flow.BaseImage = base
flow.Source = src
flow.Build = build
flow.LastSuccessfulBuild, flow.LastUnsuccessfulBuild, flow.ActiveBuilds = buildedges.RelevantBuilds(g, flow.Build)
}
for _, input := range g.SuccessorNodesByEdgeKind(node, imageedges.ReferencedImageStreamGraphEdgeKind) {
covered.Insert(input.ID())
imageStreamNode := input.(*imagegraph.ImageStreamNode)
flow.DestinationResolved = (len(imageStreamNode.Status.DockerImageRepository) != 0)
}
return flow, covered
}
示例9: EdgeTo
func (g *DenseGraph) EdgeTo(n, succ graph.Node) graph.Edge {
if g.adjacencyMatrix[n.ID()*g.numNodes+succ.ID()] != inf {
return Edge{n, succ}
}
return nil
}
示例10: coordinatesForID
func coordinatesForID(n graph.Node, c, r int) [2]int {
id := n.ID()
if id >= c*r {
panic("out of range")
}
return [2]int{id / r, id % r}
}
示例11: XY
// XY returns the cartesian coordinates of n. If n is not a node
// in the grid, (NaN, NaN) is returned.
func (g *Grid) XY(n graph.Node) (x, y float64) {
if !g.Has(n) {
return math.NaN(), math.NaN()
}
r, c := g.RowCol(n.ID())
return float64(c), float64(r)
}
示例12: key
// key returns the key for the node u and whether the node is
// in the queue. If the node is not in the queue, key is returned
// as +Inf.
func (q *primQueue) key(u graph.Node) (key float64, ok bool) {
i, ok := q.indexOf[u.ID()]
if !ok {
return math.Inf(1), false
}
return q.nodes[i].Weight(), ok
}
示例13: WeightTo
// WeightTo returns the weight of the minimum path to v.
func (p Shortest) WeightTo(v graph.Node) float64 {
to, toOK := p.indexOf[v.ID()]
if !toOK {
return math.Inf(1)
}
return p.dist[to]
}
示例14: newShortestFrom
func newShortestFrom(u graph.Node, nodes []graph.Node) Shortest {
indexOf := make(map[int]int, len(nodes))
uid := u.ID()
for i, n := range nodes {
indexOf[n.ID()] = i
if n.ID() == uid {
u = n
}
}
p := Shortest{
from: u,
nodes: nodes,
indexOf: indexOf,
dist: make([]float64, len(nodes)),
next: make([]int, len(nodes)),
}
for i := range nodes {
p.dist[i] = math.Inf(1)
p.next[i] = -1
}
p.dist[indexOf[uid]] = 0
return p
}
示例15: From
// From returns all nodes in g that can be reached directly from u.
func (g *ReducedUndirected) From(u graph.Node) []graph.Node {
out := g.edges[u.ID()]
nodes := make([]graph.Node, len(out))
for i, vid := range out {
nodes[i] = g.nodes[vid]
}
return nodes
}