func (g *AcyclicGraph) Walk(cb WalkFunc) error {
	defer g.debug.BeginOperation(typeWalk, "").End("")
	w := &Walker{Callback: cb, Reverse: true}
	w.Update(g)
	return w.Wait()
}
Walk walks the graph, calling your callback as each node is visited.
This will walk nodes in parallel if it can. Because the walk is done
in parallel, the error returned will be a multierror.
package dag
import (
	"fmt"
	"sort"
	"strings"
	"github.com/hashicorp/go-multierror"
)
type AcyclicGraph struct {
	Graph
}
type WalkFunc func(Vertex) error
type DepthWalkFunc func(Vertex, int) error
func (g *AcyclicGraph) DirectedGraph() Grapher {
	return g
}
func (g *AcyclicGraph) Ancestors(v Vertex) (*Set, error) {
	s := new(Set)
	start := AsVertexList(g.DownEdges(v))
	memoFunc := func(v Vertex, d int) error {
		s.Add(v)
		return nil
	}
	if err := g.DepthFirstWalk(start, memoFunc); err != nil {
		return nil, err
	}
	return s, nil
}
func (g *AcyclicGraph) Descendents(v Vertex) (*Set, error) {
	s := new(Set)
	start := AsVertexList(g.UpEdges(v))
	memoFunc := func(v Vertex, d int) error {
		s.Add(v)
		return nil
	}
	if err := g.ReverseDepthFirstWalk(start, memoFunc); err != nil {
		return nil, err
	}
	return s, nil
}
func (g *AcyclicGraph) Root() (Vertex, error) {
	roots := make([]Vertex, 0, 1)
	for _, v := range g.Vertices() {
		if g.UpEdges(v).Len() == 0 {
			roots = append(roots, v)
		}
	}
	if len(roots) > 1 {
		return nil, fmt.Errorf("multiple roots: %#v", roots)
	}
	if len(roots) == 0 {
		return nil, fmt.Errorf("no roots found")
	}
	return roots[0], nil
}
func (g *AcyclicGraph) TransitiveReduction() {
	defer g.debug.BeginOperation("TransitiveReduction", "").End("")
	for _, u := range g.Vertices() {
		uTargets := g.DownEdges(u)
		vs := AsVertexList(g.DownEdges(u))
		g.DepthFirstWalk(vs, func(v Vertex, d int) error {
			shared := uTargets.Intersection(g.DownEdges(v))
			for _, vPrime := range AsVertexList(shared) {
				g.RemoveEdge(BasicEdge(u, vPrime))
			}
			return nil
		})
	}
}
func (g *AcyclicGraph) Validate() error {
	if _, err := g.Root(); err != nil {
		return err
	}
	var err error
	cycles := g.Cycles()
	if len(cycles) > 0 {
		for _, cycle := range cycles {
			cycleStr := make([]string, len(cycle))
			for j, vertex := range cycle {
				cycleStr[j] = VertexName(vertex)
			}
			err = multierror.Append(err, fmt.Errorf(
				"Cycle: %s", strings.Join(cycleStr, ", ")))
		}
	}
	for _, e := range g.Edges() {
		if e.Source() == e.Target() {
			err = multierror.Append(err, fmt.Errorf(
				"Self reference: %s", VertexName(e.Source())))
		}
	}
	return err
}
func (g *AcyclicGraph) Cycles() [][]Vertex {
	var cycles [][]Vertex
	for _, cycle := range StronglyConnected(&g.Graph) {
		if len(cycle) > 1 {
			cycles = append(cycles, cycle)
		}
	}
	return cycles
}