Skip to content
This repository has been archived by the owner on Apr 26, 2019. It is now read-only.

Commit

Permalink
{network,search}: rename ShortestPaths => AllShortest
Browse files Browse the repository at this point in the history
  • Loading branch information
kortschak committed Jun 8, 2015
1 parent 1831df9 commit dcb4cfb
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion network/betweenness.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ func Betweenness(g graph.Graph) map[int]float64 {
//
// where \sigma_{st} and \sigma_{st}(v) are number of the shortest paths from s to t.
// and the subset of those paths containing v respectively.
func BetweennessWeighted(g graph.CostGraph, p search.ShortestPaths) map[int]float64 {
func BetweennessWeighted(g graph.CostGraph, p search.AllShortest) map[int]float64 {
cb := make(map[int]float64)

nodes := g.NodeList()
Expand Down
8 changes: 4 additions & 4 deletions network/distance.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
//
// For directed graphs the incoming paths are used. Infinite distances are
// not considered.
func Closeness(g graph.Graph, p search.ShortestPaths) map[int]float64 {
func Closeness(g graph.Graph, p search.AllShortest) map[int]float64 {
nodes := g.NodeList()
c := make(map[int]float64, len(nodes))
for _, u := range nodes {
Expand All @@ -45,7 +45,7 @@ func Closeness(g graph.Graph, p search.ShortestPaths) map[int]float64 {
//
// For directed graphs the incoming paths are used. Infinite distances are
// not considered.
func Farness(g graph.Graph, p search.ShortestPaths) map[int]float64 {
func Farness(g graph.Graph, p search.AllShortest) map[int]float64 {
nodes := g.NodeList()
f := make(map[int]float64, len(nodes))
for _, u := range nodes {
Expand All @@ -72,7 +72,7 @@ func Farness(g graph.Graph, p search.ShortestPaths) map[int]float64 {
//
// For directed graphs the incoming paths are used. Infinite distances are
// not considered.
func Harmonic(g graph.Graph, p search.ShortestPaths) map[int]float64 {
func Harmonic(g graph.Graph, p search.AllShortest) map[int]float64 {
nodes := g.NodeList()
h := make(map[int]float64, len(nodes))
for i, u := range nodes {
Expand Down Expand Up @@ -101,7 +101,7 @@ func Harmonic(g graph.Graph, p search.ShortestPaths) map[int]float64 {
//
// For directed graphs the incoming paths are used. Infinite distances are
// not considered.
func Residual(g graph.Graph, p search.ShortestPaths) map[int]float64 {
func Residual(g graph.Graph, p search.AllShortest) map[int]float64 {
nodes := g.NodeList()
r := make(map[int]float64, len(nodes))
for i, u := range nodes {
Expand Down
4 changes: 2 additions & 2 deletions search/dijkstra.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func DijkstraFrom(u graph.Node, g graph.Graph, weight graph.CostFunc) Shortest {
// DijkstraAllPaths will panic if g has a negative edge weight.
//
// The time complexity of DijkstrAllPaths is O(|V|.|E|+|V|^2.log|V|).
func DijkstraAllPaths(g graph.Graph, weight graph.CostFunc) (paths ShortestPaths) {
func DijkstraAllPaths(g graph.Graph, weight graph.CostFunc) (paths AllShortest) {
var (
from = g.Neighbors
edgeTo func(graph.Node, graph.Node) graph.Edge
Expand Down Expand Up @@ -108,7 +108,7 @@ func DijkstraAllPaths(g graph.Graph, weight graph.CostFunc) (paths ShortestPaths
for i := range dist {
dist[i] = math.Inf(1)
}
paths = ShortestPaths{
paths = AllShortest{
nodes: nodes,
indexOf: indexOf,

Expand Down
2 changes: 1 addition & 1 deletion search/dijkstra_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func TestDijkstraAllPaths(t *testing.T) {
}

var (
pt search.ShortestPaths
pt search.AllShortest

panicked bool
)
Expand Down
4 changes: 2 additions & 2 deletions search/floydwarshall.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
// implement graph.Coster, UniformCost is used.
//
// The time complexity of FloydWarshall is O(|V|^3).
func FloydWarshall(g graph.Graph, weight graph.CostFunc) (paths ShortestPaths, ok bool) {
func FloydWarshall(g graph.Graph, weight graph.CostFunc) (paths AllShortest, ok bool) {
var (
from = g.Neighbors
edgeTo func(graph.Node, graph.Node) graph.Edge
Expand Down Expand Up @@ -47,7 +47,7 @@ func FloydWarshall(g graph.Graph, weight graph.CostFunc) (paths ShortestPaths, o
for i := range dist {
dist[i] = math.Inf(1)
}
paths = ShortestPaths{
paths = AllShortest{
nodes: nodes,
indexOf: indexOf,

Expand Down
2 changes: 1 addition & 1 deletion search/johnson_apsp.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
// If weight is nil and the graph does not implement graph.Coster, UniformCost is used.
//
// The time complexity of JonsonAllPaths is O(|V|.|E|+|V|^2.log|V|).
func JohnsonAllPaths(g graph.Graph, weight graph.CostFunc) (paths ShortestPaths, ok bool) {
func JohnsonAllPaths(g graph.Graph, weight graph.CostFunc) (paths AllShortest, ok bool) {
jg := johnsonWeightAdjuster{
g: g,
from: g.Neighbors,
Expand Down
18 changes: 9 additions & 9 deletions search/shortest.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,9 @@ func (p Shortest) To(v graph.Node) (path []graph.Node, weight float64) {
return path, p.dist[p.indexOf[v.ID()]]
}

// ShortestPaths is a shortest-path tree created by the FloydWarshall or DijkstraAllPaths
// AllShortest is a shortest-path tree created by the FloydWarshall or DijkstraAllPaths
// functions.
type ShortestPaths struct {
type AllShortest struct {
// nodes hold the nodes of the analysed
// graph.
nodes []graph.Node
Expand Down Expand Up @@ -141,16 +141,16 @@ type ShortestPaths struct {
forward bool
}

func (p ShortestPaths) at(from, to int) (mid []int) {
func (p AllShortest) at(from, to int) (mid []int) {
return p.next[from+to*len(p.nodes)]
}

func (p ShortestPaths) set(from, to int, weight float64, mid ...int) {
func (p AllShortest) set(from, to int, weight float64, mid ...int) {
p.dist.Set(from, to, weight)
p.next[from+to*len(p.nodes)] = append(p.next[from+to*len(p.nodes)][:0], mid...)
}

func (p ShortestPaths) add(from, to int, mid ...int) {
func (p AllShortest) add(from, to int, mid ...int) {
loop: // These are likely to be rare, so just loop over collisions.
for _, k := range mid {
for _, v := range p.next[from+to*len(p.nodes)] {
Expand All @@ -163,7 +163,7 @@ loop: // These are likely to be rare, so just loop over collisions.
}

// Weight returns the weight of the minimum path between u and v.
func (p ShortestPaths) Weight(u, v graph.Node) float64 {
func (p AllShortest) Weight(u, v graph.Node) float64 {
from, fromOK := p.indexOf[u.ID()]
to, toOK := p.indexOf[v.ID()]
if !fromOK || !toOK {
Expand All @@ -176,7 +176,7 @@ func (p ShortestPaths) Weight(u, v graph.Node) float64 {
// one shortest path exists between u and v, a randomly chosen path will be returned and
// unique is returned false. If a cycle with zero weight exists in the path, it will not
// be included, but unique will be returned false.
func (p ShortestPaths) Between(u, v graph.Node) (path []graph.Node, weight float64, unique bool) {
func (p AllShortest) Between(u, v graph.Node) (path []graph.Node, weight float64, unique bool) {
from, fromOK := p.indexOf[u.ID()]
to, toOK := p.indexOf[v.ID()]
if !fromOK || !toOK || len(p.at(from, to)) == 0 {
Expand Down Expand Up @@ -229,7 +229,7 @@ func (p ShortestPaths) Between(u, v graph.Node) (path []graph.Node, weight float

// AllBetween returns all shortest paths from u to v and the weight of the paths. Paths
// containing zero-weight cycles are not returned.
func (p ShortestPaths) AllBetween(u, v graph.Node) (paths [][]graph.Node, weight float64) {
func (p AllShortest) AllBetween(u, v graph.Node) (paths [][]graph.Node, weight float64) {
from, fromOK := p.indexOf[u.ID()]
to, toOK := p.indexOf[v.ID()]
if !fromOK || !toOK || len(p.at(from, to)) == 0 {
Expand All @@ -248,7 +248,7 @@ func (p ShortestPaths) AllBetween(u, v graph.Node) (paths [][]graph.Node, weight
return paths, p.dist.At(from, to)
}

func (p ShortestPaths) allBetween(from, to int, seen []bool, path []graph.Node, paths [][]graph.Node) [][]graph.Node {
func (p AllShortest) allBetween(from, to int, seen []bool, path []graph.Node, paths [][]graph.Node) [][]graph.Node {
if p.forward {
seen[from] = true
} else {
Expand Down

0 comments on commit dcb4cfb

Please sign in to comment.