本文整理汇总了Golang中github.com/gonum/graph.Node类的典型用法代码示例。如果您正苦于以下问题:Golang Node类的具体用法?Golang Node怎么用?Golang Node使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Node类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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()])
}
开发者ID:jacobxk,项目名称:graph,代码行数:7,代码来源:undirected.go
示例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
}
开发者ID:Grissess,项目名称:sdnd16,代码行数:27,代码来源:bfs_tree.go
示例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
}
开发者ID:ppitonak,项目名称:origin,代码行数:28,代码来源:image_pipeline.go
示例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)
}
开发者ID:sbinet,项目名称:gonum-graph,代码行数:9,代码来源:limited.go
示例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
}
开发者ID:sbinet,项目名称:gonum-graph,代码行数:26,代码来源:gn.go
示例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
}
开发者ID:sbinet,项目名称:gonum-graph,代码行数:31,代码来源:gn.go
示例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
}
开发者ID:sbinet,项目名称:gonum-graph,代码行数:34,代码来源:traverse.go
示例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
}
开发者ID:dctse,项目名称:openshift-cucumber,代码行数:36,代码来源:image_pipeline.go
示例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
}
开发者ID:cjnygard,项目名称:origin,代码行数:7,代码来源:dense.go
示例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}
}
开发者ID:sbinet,项目名称:gonum-graph,代码行数:7,代码来源:bench_test.go
示例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)
}
开发者ID:jmptrader,项目名称:graph,代码行数:9,代码来源:grid.go
示例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
}
开发者ID:sbinet,项目名称:gonum-graph,代码行数:10,代码来源:spanning_tree.go
示例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]
}
开发者ID:RomainVabre,项目名称:origin,代码行数:8,代码来源:shortest.go
示例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
}
开发者ID:RomainVabre,项目名称:origin,代码行数:27,代码来源:shortest.go
示例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
}
开发者ID:sbinet,项目名称:gonum-graph,代码行数:9,代码来源:louvain.go
示例16: HasEdge
func (g *TileGraph) HasEdge(u, v graph.Node) bool {
if !g.Has(u) || !g.Has(v) {
return false
}
r1, c1 := g.IDToCoords(u.ID())
r2, c2 := g.IDToCoords(v.ID())
return (c1 == c2 && (r2 == r1+1 || r2 == r1-1)) || (r1 == r2 && (c2 == c1+1 || c2 == c1-1))
}
开发者ID:baijum,项目名称:graph,代码行数:8,代码来源:tilegraph.go
示例17: Weight
// Weight returns the weight of the minimum path between u and v.
func (p AllShortest) Weight(u, v graph.Node) float64 {
from, fromOK := p.indexOf[u.ID()]
to, toOK := p.indexOf[v.ID()]
if !fromOK || !toOK {
return math.Inf(1)
}
return p.dist.At(from, to)
}
开发者ID:RomainVabre,项目名称:origin,代码行数:9,代码来源:shortest.go
示例18: nodeID
func nodeID(n graph.Node) string {
switch n := n.(type) {
case Node:
return n.DOTID()
default:
return fmt.Sprint(n.ID())
}
}
开发者ID:sbinet,项目名称:gonum-graph,代码行数:8,代码来源:dot.go
示例19: AddNode
// Adds a node to the graph. Implementation note: if you add a node close to or at
// the max int on your machine NewNode will become slower.
func (g *DirectedGraph) AddNode(n graph.Node) {
g.nodeMap[n.ID()] = n
g.successors[n.ID()] = make(map[int]WeightedEdge)
g.predecessors[n.ID()] = make(map[int]WeightedEdge)
delete(g.freeMap, n.ID())
g.maxID = max(g.maxID, n.ID())
}
开发者ID:cjnygard,项目名称:origin,代码行数:10,代码来源:mutdir.go
示例20: EdgeBetween
func (g *UndirectedGraph) EdgeBetween(u, v graph.Node) graph.Edge {
// We don't need to check if neigh exists because
// it's implicit in the neighbors access.
if !g.Has(u) {
return nil
}
return g.neighbors[u.ID()][v.ID()]
}
开发者ID:jacobxk,项目名称:graph,代码行数:9,代码来源:undirected.go
注:本文中的github.com/gonum/graph.Node类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论