-
Notifications
You must be signed in to change notification settings - Fork 1
DiGraph
this class implement directed weighted graph data structure that contains several nodes (vertex) with edges between them.
- nodes- basic dictionary for all the nodes in the graph, the key will be the node_id and the value is NodeData object.
- childes- dictionary that will contains in as a key the parent id of node and in the value another dictionary for each key node_id of a child and the value is the weight of the edge between the parent and the child.
- parents- dictionary that will contains in as a key the child id of node and in the value another dictionary for each key node_id of a parent and the value is the weight of the edge between the child and the parent.
We can see that the class contains following functions: adding and removing a node, adding and removing an edge between two nodes, returning a dictionary of all the nodes in the graph, return a dictionary of all the nodes connected to (into) node_id, return a dictionary of all the nodes connected from node_id, return the number of changes in the graph (mode count), return the sum of nodes (|V|), return the sun of edges (|E|). This is a DiGraph class use another class for representing nodes in the graph called NodeData, NodeData is a node object class, this class represents a node in a graph and each node has key, position, weight and tag (for use in graph algorithms) and info (use as metadata of the node).
The class has a road-system or communication network in mind - and supports a large number of nodes (over 100,000). The implementation is based on an efficient compact representation.
-
v_size()
- return the number of nodes in the graph (|V|) -
e_size()
- return the number of edges in the graph (|E|) -
get_all_v()
- return a dictionary of graph nodes {(node_id : NodeData)} -
all_in_edges_of_node(node_id)
- return a dictionary of all the nodes connected to node {(parent_id, weight)} -
all_in_edges_of_node(node_id)
- return a dictionary of all the nodes connected from the node {(child_id, weight)} -
get_mc()
- return graph mode count -
add_edge(node1_id, node2_id, weight)
- connect between two nodes with weight -
add_node(node_id, position)
- adding node to the graph -
remove_node(node_id)
- remove node from the graph and all the connections with other nodes -
remove_edge(node1_id, node2_id)
- removing connection between node1_id and node2_id