Skip to content

Commit

Permalink
Added additional heuristic
Browse files Browse the repository at this point in the history
  • Loading branch information
cem-okulmus committed Dec 19, 2019
1 parent 68bc408 commit 80eac89
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 7 deletions.
10 changes: 6 additions & 4 deletions balanced.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ func main() {
localBal := flag.Bool("local", false, "Test out local BalSep")
globalBal := flag.Bool("global", false, "Test out global BalSep")
balanceFactorFlag := flag.Int("balfactor", 2, "Determines the factor that balanced separator check uses")
useHeuristic := flag.Int("heuristic", 0, "turn on to activate edge ordering\n\t1 ... Degree Ordering\n\t2 ... Max. Separator Ordering\n\t3 ... MCSO")
useHeuristic := flag.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ö := flag.Bool("g", false, "perform a GYÖ reduct and show the resulting graph")
typeC := flag.Bool("t", false, "perform a Type Collapse and show the resulting graph")
//hingeFlag := flag.Bool("hinge", false, "use isHinge Optimization")
Expand Down Expand Up @@ -178,11 +178,13 @@ func main() {
heuristicMessage = "Using max seperator ordering as a heuristic"
break
case 3:
a := GetMSCOrder(parsedGraph.Edges)
parsedGraph.Edges = a
fmt.Println("Received, ", a)
parsedGraph.Edges = GetMSCOrder(parsedGraph.Edges)
heuristicMessage = "Using MSC ordering as a heuristic"
break
case 4:
parsedGraph.Edges = GetEdgeDegreeOrder(parsedGraph.Edges)
heuristicMessage = "Using edge degree ordering as a heuristic"
break
}
d := time.Now().Sub(start)

Expand Down
29 changes: 27 additions & 2 deletions lib/heuristics.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ func GetMaxSepOrder(edges Edges) Edges {
return edges
}

func edgeDegree(edges Edges, edge Edge) int {
func edgeVertexDegree(edges Edges, edge Edge) int {
var output int

for _, v := range edge.Vertices {
Expand All @@ -191,6 +191,31 @@ func GetDegreeOrder(edges Edges) Edges {
if edges.Len() <= 1 {
return edges
}
sort.Slice(edges.Slice(), func(i, j int) bool { return edgeDegree(edges, edges.Slice()[i]) > edgeDegree(edges, edges.Slice()[j]) })
sort.Slice(edges.Slice(), func(i, j int) bool {
return edgeVertexDegree(edges, edges.Slice()[i]) > edgeVertexDegree(edges, edges.Slice()[j])
})
return edges
}

func edgeDegree(edges Edges, edge Edge) int {
output := 0

for i := range edges.Slice() {
if edges.Slice()[i].areNeighbours(edge) {
output++
}
}

return output
}

func GetEdgeDegreeOrder(edges Edges) Edges {
if edges.Len() <= 1 {
return edges
}
sort.Slice(edges.Slice(), func(i, j int) bool {
return edgeDegree(edges, edges.Slice()[i]) > edgeDegree(edges, edges.Slice()[j])
})
return edges

}
2 changes: 1 addition & 1 deletion lib/preprocessing.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func (g Graph) GYÖReduct() (Graph, []GYÖReduct) {
//Perform vertex removal
g2, ops2 := g1.removeVertices()
// fmt.Println("After Vertex Removal:")
// for _, e := range g2.Edges {
// for _, e := range g2.Edges.Slice() {
// fmt.Printf("%v %v\n", e, Edge{Vertices: e.Vertices})
// }

Expand Down

0 comments on commit 80eac89

Please sign in to comment.