Implementation of management and visualisation of directed multigraphs permitting loops
Use the Node()
class to create multiple Nodes indentifiable via value.
node0 = Node(value=0)
node1 = Node(value=1)
node2 = Node(value=2)
You can assign parent and child nodes directly on creation of a node or later with the Node().register_parent()
or Node().register_child()
functions.
node3 = Node(value=3, parents=[node0])
node1.register_parent(node0)
node1.register_child(node2)
To print the parents of children of a node, use the Node().print_parents()
or Node().print_childs()
functions.
node1.print_parents()
node1.print_childs()
Get the whole graph a node is connected to with the get_graph(node)
function.
my_graph = get_graph(node0)
Draw the graph by using the draw()
function.
draw(my_graph)
Or just generate a random graph with the generate_graph()
function where
n
is the number of nodes
tweak
is a value to tweak the number of parents and childs each node should have
my_graph2 = generate_graph(n=10, tweak=6)