Skip to content

Commit

Permalink
[p3] Remove traces of old phase 3 wmedian naming
Browse files Browse the repository at this point in the history
  • Loading branch information
vibridi committed Sep 19, 2023
1 parent 02b21e4 commit 79b6516
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 29 deletions.
2 changes: 1 addition & 1 deletion autolayout_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ var defaultOptions = options{
NetworkSimplexThoroughness: 28,
NetworkSimplexMaxIterFactor: 0,
NetworkSimplexBalance: graph.OptionNsBalanceV,
GraphvizDotMaxIter: 24,
WMedianMaxIter: 24,
NetworkSimplexAuxiliaryGraphWeightFactor: 4,
LayerSpacing: 150.0,
NodeSpacing: 60.0,
Expand Down
4 changes: 2 additions & 2 deletions internal/graph/params.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ type Params struct {

// ---- phase3 options ---

// Maximum number of iterations of the GraphvizDot orderer.
GraphvizDotMaxIter uint
// Maximum number of iterations of the WMedian orderer.
WMedianMaxIter uint

// ---- phase4 options ---

Expand Down
2 changes: 1 addition & 1 deletion internal/phase3/alg_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func (alg Alg) Process(g *graph.DGraph, params graph.Params) {
case NoOrdering:
return
case WMedian:
execGraphvizDot(g, params)
execWeightedMedian(g, params)
default:
panic("ordering: unknown alg value")
}
Expand Down
42 changes: 21 additions & 21 deletions internal/phase3/wmedian.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const (
initDirectionBottom initDirection = 1
)

type graphvizDotProcessor struct {
type wmedianProcessor struct {
positions graph.NodeIntMap
flipEqual bool
transposeEqual bool
Expand All @@ -27,7 +27,7 @@ type graphvizDotProcessor struct {
// https://www.researchgate.net/publication/3187542_A_Technique_for_Drawing_Directed_Graphs
//
// Note that ELK's implementation is based on the original algorithm proposed by Sugiyama et al. instead of Graphviz.
func execGraphvizDot(g *graph.DGraph, params graph.Params) {
func execWeightedMedian(g *graph.DGraph, params graph.Params) {
if len(g.Layers) == 1 {
// no crossings to reduce
return
Expand All @@ -36,11 +36,11 @@ func execGraphvizDot(g *graph.DGraph, params graph.Params) {
// insert virtual nodes so that edges with length >1 have length 1
breakLongEdges(g)

maxiter := int(params.GraphvizDotMaxIter)
maxiter := int(params.WMedianMaxIter)
fixedPositions := initFixedPositions(g.Edges)

bestx_top, bestpos_top := graphvizRun(g, graphvizRunParams{maxiter, fixedPositions, initDirectionTop})
bestx_btm, bestpos_btm := graphvizRun(g, graphvizRunParams{maxiter, fixedPositions, initDirectionBottom})
bestx_top, bestpos_top := wmedianRun(g, wmedianRunParams{maxiter, fixedPositions, initDirectionTop})
bestx_btm, bestpos_btm := wmedianRun(g, wmedianRunParams{maxiter, fixedPositions, initDirectionBottom})

var (
bestx = 0
Expand All @@ -65,13 +65,13 @@ func execGraphvizDot(g *graph.DGraph, params graph.Params) {
}
}

type graphvizRunParams struct {
type wmedianRunParams struct {
maxiter int
fixedPositions fixedPositions
dir initDirection
}

type graphvizInitFn func(n *graph.Node, visited graph.NodeSet, indices map[int]int)
type wmedianInitFn func(n *graph.Node, visited graph.NodeSet, indices map[int]int)

// node order is maintained in three different places:
// - in g.Layers.Nodes, which is a slice
Expand All @@ -80,8 +80,8 @@ type graphvizInitFn func(n *graph.Node, visited graph.NodeSet, indices map[int]i
//
// at each iteration, this algorithm will update the node positions in all three places
// a copy of the best p.positions is kept and at the end it is propagated to g.Layers and node.LayerPos
func graphvizRun(g *graph.DGraph, params graphvizRunParams) (int, graph.NodeIntMap) {
p := &graphvizDotProcessor{
func wmedianRun(g *graph.DGraph, params wmedianRunParams) (int, graph.NodeIntMap) {
p := &wmedianProcessor{
positions: graph.NodeIntMap{},
fixedPositions: params.fixedPositions,
}
Expand Down Expand Up @@ -134,7 +134,7 @@ func graphvizRun(g *graph.DGraph, params graphvizRunParams) (int, graph.NodeIntM
return bestx, bestp
}

func (p *graphvizDotProcessor) initPositions(g *graph.DGraph, layer *graph.Layer, fn graphvizInitFn) {
func (p *wmedianProcessor) initPositions(g *graph.DGraph, layer *graph.Layer, fn wmedianInitFn) {
// initialize positions
visited := graph.NodeSet{}
indices := map[int]int{}
Expand All @@ -146,7 +146,7 @@ func (p *graphvizDotProcessor) initPositions(g *graph.DGraph, layer *graph.Layer
}
}

func (p *graphvizDotProcessor) initPositionsFromTop(n *graph.Node, visited graph.NodeSet, indices map[int]int) {
func (p *wmedianProcessor) initPositionsFromTop(n *graph.Node, visited graph.NodeSet, indices map[int]int) {
if visited[n] {
return
}
Expand All @@ -159,7 +159,7 @@ func (p *graphvizDotProcessor) initPositionsFromTop(n *graph.Node, visited graph
}
}

func (p *graphvizDotProcessor) initPositionsFromBottom(n *graph.Node, visited graph.NodeSet, indices map[int]int) {
func (p *wmedianProcessor) initPositionsFromBottom(n *graph.Node, visited graph.NodeSet, indices map[int]int) {
if visited[n] {
return
}
Expand All @@ -172,7 +172,7 @@ func (p *graphvizDotProcessor) initPositionsFromBottom(n *graph.Node, visited gr
}
}

func (p *graphvizDotProcessor) initPositionsFlatEdges(n *graph.Node, visited graph.NodeSet, indices map[int]int) {
func (p *wmedianProcessor) initPositionsFlatEdges(n *graph.Node, visited graph.NodeSet, indices map[int]int) {
h, i := p.fixedPositions.head(n)
if i > 0 {
for h != nil && h != n {
Expand All @@ -191,7 +191,7 @@ func (p *graphvizDotProcessor) initPositionsFlatEdges(n *graph.Node, visited gra
// The weighted median routine assigns an order to each vertex in layer L(i) based on the current order
// of adjacent nodes in the next rank. Next is L(i)-1 in top-bottom sweep, or L(i)+1 in bottom-top sweep.
// Nodes with no adjacent nodes in the next layer are kept in place.
func (p *graphvizDotProcessor) wmedianTopBottom(layers map[int]*graph.Layer) {
func (p *wmedianProcessor) wmedianTopBottom(layers map[int]*graph.Layer) {
medians := graph.NodeFloatMap{}
for r := 1; r < len(layers); r++ {
for _, v := range layers[r].Nodes {
Expand All @@ -201,7 +201,7 @@ func (p *graphvizDotProcessor) wmedianTopBottom(layers map[int]*graph.Layer) {
}
}

func (p *graphvizDotProcessor) wmedianBottomTop(layers map[int]*graph.Layer) {
func (p *wmedianProcessor) wmedianBottomTop(layers map[int]*graph.Layer) {
medians := graph.NodeFloatMap{}
for r := len(layers) - 1; r >= 0; r-- {
for _, v := range layers[r].Nodes {
Expand Down Expand Up @@ -245,7 +245,7 @@ func medianOf(adpos []int) float64 {

// returns an ordered array of the present positions of the nodes
// adjacent to v in the given adjacent rank.
func (p *graphvizDotProcessor) adjacentNodesPositions(n *graph.Node, edges []*graph.Edge, adjLayer int) []int {
func (p *wmedianProcessor) adjacentNodesPositions(n *graph.Node, edges []*graph.Edge, adjLayer int) []int {
res := []int{}
for _, e := range edges {
if e.SelfLoops() {
Expand All @@ -260,7 +260,7 @@ func (p *graphvizDotProcessor) adjacentNodesPositions(n *graph.Node, edges []*gr
return res
}

func (p *graphvizDotProcessor) sortLayer(nodes []*graph.Node, medians graph.NodeFloatMap) {
func (p *wmedianProcessor) sortLayer(nodes []*graph.Node, medians graph.NodeFloatMap) {
ep := len(nodes) // end pointer
// back iteration slightly more efficient because it compares the iteration variable to zero
for iter := len(nodes) - 1; iter >= 0; iter-- {
Expand Down Expand Up @@ -308,7 +308,7 @@ func (p *graphvizDotProcessor) sortLayer(nodes []*graph.Node, medians graph.Node
// transpose sweeps through layers in order and swaps pairs of adjacent nodes in the same layer;
// it counts the number of crossings between L, L-1 and L+1, if there's an improvement it keeps looping
// until no improvement is found.
func (p *graphvizDotProcessor) transpose(layers map[int]*graph.Layer) {
func (p *wmedianProcessor) transpose(layers map[int]*graph.Layer) {
improved := true
for improved {
improved = false
Expand Down Expand Up @@ -372,22 +372,22 @@ func crossingsAround(l int, layers map[int]*graph.Layer) int {
return countCrossings(layers[l-1], layers[l]) + countCrossings(layers[l], layers[l+1])
}

func (p *graphvizDotProcessor) swap(v, w *graph.Node) {
func (p *wmedianProcessor) swap(v, w *graph.Node) {
iv := p.getPos(v)
iw := p.getPos(w)
p.setPos(v, iw)
p.setPos(w, iv)
}

func (p *graphvizDotProcessor) getPos(n *graph.Node) int {
func (p *wmedianProcessor) getPos(n *graph.Node) int {
pos := p.positions[n]
if pos != n.LayerPos {
panic("gansner-north orderer: corrupted state: node in-layer position mismatch")
}
return pos
}

func (p *graphvizDotProcessor) setPos(n *graph.Node, pos int) {
func (p *wmedianProcessor) setPos(n *graph.Node, pos int) {
p.positions[n] = pos
n.LayerPos = pos
}
6 changes: 3 additions & 3 deletions internal/phase3/wmedian_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import (
// 1: {Index: 1, Nodes: []*graph.Node{nodes[4], nodes[5], nodes[6], nodes[7]}},
// }
//
// p := &graphvizDotProcessor{positions: graph.NodeIntMap{}}
// p := &wmedianProcessor{positions: graph.NodeIntMap{}}
//
// for _, l := range layers {
// for i, n := range l.Nodes {
Expand All @@ -67,7 +67,7 @@ import (

// func TestAAA(t *testing.T) {
// g := buildGraph()
// execGraphvizDot(g, graph.Params{})
// execWeightedMedian(g, graph.Params{})
// }

// func TestGansnerNorthOrdering(t *testing.T) {
Expand All @@ -84,7 +84,7 @@ import (
// for _, subg := range dg.ConnectedComponents() {
// t.Run("component:"+subg.Nodes[0].ID, func(t *testing.T) {
// phase2.NetworkSimplex.Process(subg, graph.Params{})
// execGraphvizDot(subg, graph.Params{})
// execWeightedMedian(subg, graph.Params{})
//
// indices := map[int]map[int]bool{}
// for _, n := range subg.Nodes {
Expand Down
2 changes: 1 addition & 1 deletion internal/testfiles/bugfix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ func TestCrashers(t *testing.T) {
})
})

t.Run("phase3 GraphvizDot", func(t *testing.T) {
t.Run("phase3 WMedian", func(t *testing.T) {
t.Run("identical edge segfault in cross counting", func(t *testing.T) {
src := graph.EdgeSlice(cacooArch)
assert.NotPanics(t, func() { _ = autog.Layout(src) })
Expand Down

0 comments on commit 79b6516

Please sign in to comment.