dag

package module
v0.0.0-...-c07d7e5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 20, 2023 License: MIT Imports: 5 Imported by: 2

README

Random DAG Generator in Go

random-dag-generator-go is a library for (you guessed it!) generating random Directed Acyclic Graphs (DAGs) in Go.

DAG A DAG B

Features

  • Generate random Directed Acyclic Graphs (DAGs), controlling:
    • exact quantity of nodes in the DAG
    • maximum outdegree of each node
    • probability of adding new edges during graph generation
  • Render a DAG using graphviz and DOT

Demo

package main

import (
	"flag"
	"math/rand"

	dag "github.com/laser/random-dag-generator-go"
	gvz "github.com/laser/random-dag-generator-go/render/graphviz"
)

func main() {
	flag.Parse()

	graph := dag.Random(
		dag.WithNodeQty(10),
		dag.WithMaxOutdegree(3),
		dag.WithEdgeFactor(0.5))

	converted := gvz.From(graph)

	gvz.RenderTo(converted, "/tmp/flarp.png")
}

Documentation

Index

Constants

View Source
const SEPARATOR = "->"

Variables

This section is empty.

Functions

func Partition

func Partition(edges []Edge) (partitions [][]Edge)

Partition partitions a set of edges into a slice of subgraphs

Types

type Edge

type Edge struct {
	SourceNodeId NodeId
	TargetNodeId NodeId
}

func (Edge) GetSourceNodeID

func (e Edge) GetSourceNodeID() string

func (Edge) GetTargetNodeID

func (e Edge) GetTargetNodeID() string

type Graph

type Graph struct {
	Nodes []Node
	Edges []Edge
}

func Random

func Random(options ...Options) (out Graph)

Random generates a random DAG using the provided options

func (Graph) GetEdges

func (g Graph) GetEdges() (out []gvz.RenderableGraphEdge)

func (Graph) GetNodes

func (g Graph) GetNodes() (out []gvz.RenderableGraphNode)

type GroupKey

type GroupKey string

type Node

type Node struct {
	Id NodeId
}

func (Node) GetID

func (n Node) GetID() string

type NodeId

type NodeId string

type Options

type Options func(opts *config)

func WithEdgeFactor

func WithEdgeFactor(edgeFactor float64) Options

WithEdgeFactor sets the probability of adding a new edge between nodes during the graph generation

func WithMaxOutdegree

func WithMaxOutdegree(maxOutdegree int) Options

WithMaxOutdegree sets the maximum number of edges directed outdegree of a node

func WithNodeQty

func WithNodeQty(nodeQty int) Options

WithNodeQty sets the number of nodes indegree the DAG

Directories

Path Synopsis
cmd
render

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL