graph/path: implement sophisticated algorithm

Both algorithms are included since the LTA appears to beat the SLTA for
all normal uses, but the SLTA beats the LTA for very large dense graphs.

Leave tools in the benchmark code to allow users to determine which one
they want to use for their data.
This commit is contained in:
kortschak
2017-09-06 12:25:37 +09:30
parent 9baf9959f7
commit 1b3b29f16b
4 changed files with 276 additions and 19 deletions

View File

@@ -7,6 +7,7 @@
package path
import (
"flag"
"fmt"
"io/ioutil"
"math"
@@ -23,6 +24,8 @@ import (
"gonum.org/v1/gonum/graph/topo"
)
var slta = flag.Bool("slta", false, "specify DominatorsSLT benchmark")
func BenchmarkDominators(b *testing.B) {
testdata := filepath.FromSlash("./testdata/flow")
@@ -55,14 +58,25 @@ func BenchmarkDominators(b *testing.B) {
continue
}
b.Run(test, func(b *testing.B) {
for i := 0; i < b.N; i++ {
d := Dominators(g.root, g)
if got := d.Root(); got.ID() != want.ID() {
b.Fatalf("unexpected root node: got:%d want:%d", got.ID(), want.ID())
if *slta {
b.Run(test, func(b *testing.B) {
for i := 0; i < b.N; i++ {
d := DominatorsSLT(g.root, g)
if got := d.Root(); got.ID() != want.ID() {
b.Fatalf("unexpected root node: got:%d want:%d", got.ID(), want.ID())
}
}
}
})
})
} else {
b.Run(test, func(b *testing.B) {
for i := 0; i < b.N; i++ {
d := Dominators(g.root, g)
if got := d.Root(); got.ID() != want.ID() {
b.Fatalf("unexpected root node: got:%d want:%d", got.ID(), want.ID())
}
}
})
}
}
}