Skip to content

Commit e68a834

Browse files
authored
Merge pull request #36 from elecbug/elecbug/master
feat: add onlydiameter func
2 parents f97ce8b + 0f5587d commit e68a834

2 files changed

Lines changed: 18 additions & 0 deletions

File tree

graph/algorithm/diameter.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,20 @@ func Diameter(g *graph.Graph, cfg *Config) int {
2323

2424
return result
2525
}
26+
27+
// OnlyDiameter computes the diameter of the graph using only the lengths of all-pairs shortest paths.
28+
func OnlyDiameter(g *graph.Graph, cfg *Config) int {
29+
result := 0
30+
31+
paths := AllShortestPathLength(g, cfg)
32+
33+
for _, v := range paths {
34+
for _, d := range v {
35+
if d > result {
36+
result = d
37+
}
38+
}
39+
}
40+
41+
return result
42+
}

graph/graph_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ func graphMetrics(t *testing.T, g *graph.Graph, text string) {
183183
})
184184
t.Run("Diameter", func(t *testing.T) {
185185
results["diameter"] = algorithm.Diameter(g, cfg)
186+
results["only_diameter"] = algorithm.OnlyDiameter(g, cfg)
186187
})
187188
t.Run("EdgeBetweennessCentrality", func(t *testing.T) {
188189
results["edge_betweenness_centrality"] = algorithm.EdgeBetweennessCentrality(g, cfg)

0 commit comments

Comments
 (0)