コード例 #1
0
ファイル: tilegraph.go プロジェクト: baijum/graph
func (g *TileGraph) Weight(e graph.Edge) float64 {
	if edge := g.EdgeBetween(e.From(), e.To()); edge != nil {
		return 1
	}

	return inf
}
コード例 #2
0
ファイル: dcel.go プロジェクト: vladimir-ch/dcel
// 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{}{}
}
コード例 #3
0
ファイル: undirected.go プロジェクト: RomainVabre/origin
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
}
コード例 #4
0
func (g *DirectedDenseGraph) 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.Set(fid, tid, e.Weight())
}
コード例 #5
0
// 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())
}
コード例 #6
0
func (g *UndirectedDenseGraph) 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.SetSym(fid, tid, weight)
}
コード例 #7
0
ファイル: directed.go プロジェクト: RomainVabre/origin
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
}
コード例 #8
0
ファイル: undirected.go プロジェクト: jacobxk/graph
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())
}
コード例 #9
0
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)
}
コード例 #10
0
// 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)
}
コード例 #11
0
ファイル: grid.go プロジェクト: RomainVabre/origin
// 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)
}
コード例 #12
0
ファイル: directed.go プロジェクト: sbinet/gonum-graph
// 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())
}
コード例 #13
0
ファイル: undirected.go プロジェクト: sbinet/gonum-graph
// 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
}
コード例 #14
0
ファイル: directed.go プロジェクト: RomainVabre/origin
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}
}
コード例 #15
0
func (g *gnUndirected) SetEdge(e graph.Edge) {
	switch {
	case e.From().ID() == e.To().ID():
		g.addSelfLoop = true
		return
	case e.From().ID() > e.To().ID():
		g.addBackwards = true
	case g.UndirectedBuilder.HasEdgeBetween(e.From(), e.To()):
		g.addMultipleEdge = true
	}

	g.UndirectedBuilder.SetEdge(e)
}
コード例 #16
0
func (g *DirectedDenseGraph) RemoveEdge(e graph.Edge) {
	g.mat.Set(e.From().ID(), e.To().ID(), g.absent)
}
コード例 #17
0
func (g *DirectedDenseGraph) Weight(e graph.Edge) float64 {
	return g.mat.At(e.From().ID(), e.To().ID())
}