Skip to content

Commit

Permalink
Integrated hingetree optimization, some fixes to GYO
Browse files Browse the repository at this point in the history
  • Loading branch information
cem-okulmus committed Apr 5, 2020
1 parent 07308a7 commit 1a4c120
Show file tree
Hide file tree
Showing 10 changed files with 214 additions and 46 deletions.
1 change: 1 addition & 0 deletions algorithms/algorithms.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import . "github.com/cem-okulmus/BalancedGo/lib"
type Algorithm interface {
Name() string
FindDecomp(K int) Decomp
FindDecompGraph(G Graph, K int) Decomp
}

type UpdateAlgorithm interface {
Expand Down
4 changes: 4 additions & 0 deletions algorithms/balDetKDecomp.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,10 @@ func (b BalDetKDecomp) FindDecomp(K int) Decomp {
return b.FindGHD(K, b.Graph, []Special{})
}

func (b BalDetKDecomp) FindDecompGraph(G Graph, K int) Decomp {
return b.FindGHD(K, G, []Special{})
}

func (b BalDetKDecomp) FindDecompUpdate(K int, currentGraph Graph, Sp []Special) Decomp {

fmt.Println("Ghost edges", b.Graph.Edges)
Expand Down
4 changes: 4 additions & 0 deletions algorithms/balKDecomp.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,10 @@ func (b BalKDecomp) FindDecomp(K int) Decomp {
return b.findDecompParallelFull(K, b.Graph)
}

func (b BalKDecomp) FindDecompGraph(G Graph, K int) Decomp {
return b.findDecompParallelFull(K, G)
}

func (b BalKDecomp) Name() string {
return "Akatov"
}
4 changes: 4 additions & 0 deletions algorithms/balsepGlobal.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,10 @@ func (g BalSepGlobal) FindDecomp(K int) Decomp {
return g.findDecompParallelFull(K, g.Graph, []Special{})
}

func (b BalSepGlobal) FindDecompGraph(G Graph, K int) Decomp {
return b.findDecompParallelFull(K, G, []Special{})
}

func (g BalSepGlobal) Name() string {
return "BalSep Global"
}
4 changes: 4 additions & 0 deletions algorithms/balsepLocal.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,10 @@ func (g BalSepLocal) FindDecomp(K int) Decomp {
return g.findDecompParallelFull(K, g.Graph, []Special{})
}

func (g BalSepLocal) FindDecompGraph(G Graph, K int) Decomp {
return g.findDecompParallelFull(K, G, []Special{})
}

func (g BalSepLocal) Name() string {
return "BalSep Local"
}
4 changes: 4 additions & 0 deletions algorithms/detKDecomp.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,10 @@ func (d DetKDecomp) Name() string {
}
}

func (d DetKDecomp) FindDecompGraph(G Graph, K int) Decomp {
return d.FindHD(K, G, []Special{})
}

func (d DetKDecomp) FindDecompUpdate(K int, currentGraph Graph, Sp []Special) Decomp {
fmt.Println("Ghost edges", d.Graph.Edges)
return d.FindHD(K, d.Graph, Sp)
Expand Down
16 changes: 16 additions & 0 deletions algorithms/divideKDecomp.go
Original file line number Diff line number Diff line change
Expand Up @@ -544,6 +544,13 @@ func (d DivideKDecomp) FindDecomp(K int) Decomp {
return output
}

func (d DivideKDecomp) FindDecompGraph(G Graph, K int) Decomp {
output := d.decomp(DivideComp{Edges: G.Edges})
output.Root = postProcess(output.Root, []int{})

return output
}

func (d DivideKDecomp) Name() string {
return "DivideK"
}
Expand All @@ -564,6 +571,15 @@ func (d DivideKDecompPar) FindDecomp(K int) Decomp {
return output
}

func (d DivideKDecompPar) FindDecompGraph(G Graph, K int) Decomp {
div := DivideKDecomp{Graph: d.Graph, K: d.K, BalFactor: d.BalFactor}

output := div.decompParallel(DivideComp{Edges: G.Edges})
output.Root = postProcess(output.Root, []int{})

return output
}

func (d DivideKDecompPar) Name() string {
return "DivideK-Par"
}
Expand Down
41 changes: 35 additions & 6 deletions balanced.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var Version string
var Date string
var Build string

func outputStanza(algorithm string, decomp Decomp, msec float64, parsedGraph Graph, gml string, K int, heuristic float64) {
func outputStanza(algorithm string, decomp Decomp, msec float64, parsedGraph Graph, gml string, K int, heuristic float64, hinge float64) {
decomp.RestoreSubedges()

fmt.Println("Used algorithm: " + algorithm + " @" + Version)
Expand All @@ -51,6 +51,9 @@ func outputStanza(algorithm string, decomp Decomp, msec float64, parsedGraph Gra
fmt.Print("(", msec/60000.0, "min )")
}
}
if hinge > 0.0 {
fmt.Println("\nHingeTree: ", hinge, " ms")
}

fmt.Println("\nWidth: ", decomp.CheckWidth())
correct := decomp.Correct(parsedGraph)
Expand Down Expand Up @@ -84,7 +87,7 @@ func main() {
useHeuristic := flagSet.Int("heuristic", 0, "turn on to activate edge ordering\n\t1 ... Degree Ordering\n\t2 ... Max. Separator Ordering\n\t3 ... MCSO\n\t4 ... Edge Degree Ordering")
gyö := flagSet.Bool("g", false, "perform a GYÖ reduct")
typeC := flagSet.Bool("t", false, "perform a Type Collapse")
//hingeFlag := flagSet.Bool("hinge", false, "use isHinge Optimization")
hingeFlag := flagSet.Bool("h", false, "use hingeTree Optimization")
numCPUs := flagSet.Int("cpu", -1, "Set number of CPUs to use")
bench := flagSet.Bool("bench", false, "Benchmark mode, reduces unneeded output (incompatible with -log flag)")
akatovTest := flagSet.Bool("akatov", false, "Use Balanced Decomposition algorithm")
Expand Down Expand Up @@ -251,6 +254,23 @@ func main() {
fmt.Println("Graph with subedges \n", parsedGraph)
}

var hinget Hingetree
var msecHinge float64

if *hingeFlag {
startHinge := time.Now()

hinget = GetHingeTree(parsedGraph)

dHinge := time.Now().Sub(startHinge)
msecHinge = dHinge.Seconds() * float64(time.Second/time.Millisecond)

if !*bench {
fmt.Println("Produced Hingetree: ")
fmt.Println(hinget)
}
}

if *update {
var solver UpdateAlgorithm

Expand Down Expand Up @@ -289,7 +309,7 @@ func main() {
}
}

outputStanza(solver.Name(), decomp, msec, parsedGraph, *gml, *width, heuristic)
outputStanza(solver.Name(), decomp, msec, parsedGraph, *gml, *width, heuristic, msecHinge)
return
}

Expand Down Expand Up @@ -358,13 +378,22 @@ func main() {
k := 1
solved := false
for !solved {
decomp = solver.FindDecomp(k)
if *hingeFlag {
decomp = hinget.DecompHinge(solver, k, parsedGraph)
} else {
decomp = solver.FindDecomp(k)
}

solved = decomp.Correct(parsedGraph)
k++
}
*width = k - 1 // for correct output
} else {
decomp = solver.FindDecomp(*width)
if *hingeFlag {
decomp = hinget.DecompHinge(solver, *width, parsedGraph)
} else {
decomp = solver.FindDecomp(*width)
}
}

if *akatovTest {
Expand All @@ -390,7 +419,7 @@ func main() {
}
}

outputStanza(solver.Name(), decomp, msec, parsedGraph, *gml, *width, heuristic)
outputStanza(solver.Name(), decomp, msec, parsedGraph, *gml, *width, heuristic, msecHinge)
return
}

Expand Down
Loading

0 comments on commit 1a4c120

Please sign in to comment.