Class DiGraph - GiladShotland/EX3-OOP GitHub Wiki
For implementing the DiGraph class I created the NodeInfo class for representing the nodes in the graph.
DiGraph
This class represents the directed weighted graph.
The class includes the following methods:
-
v_size() - return a number of vertices (nodes) in the graph
-
e_size() - return the number of edges in the graph
-
get_all_v() - return a dictionary with all the vertices in the graph (every node object mapped by its id)
-
get_mc() - return and integer represents the mode count (number of changes) of the graph
-
all_out_edges_of_node(node_id : int) - return a dictionary with all the edges that going out from the node (the weight of the edge is mapped by the destination node's id)
-
all_int_edges_of_node(node_id : int) - return a dictionary with all the edges that going into the node (the weight of the edge is mapped by the source node's id)
-
add_node(node_id : int) - add a node with a given id to the graph (return true if the node was successfully added)
-
add_edge(self, id1: int, id2: int, weight: float) - add an edge to the graph between node1 (represented with id1) as the source and node2 (represented with id2) with weight given (return true if edge was successfully added)
-
remove_node(id1 : int) - remove a node given from the graph(and all the edges connected to it, return true if the node was successfully removed)
-
remove_e
1.NodeInfo
This class represents a node in a graph, and stores the weight,key, all the edges that go out from the node and go into the node. The class includes the following methods:
1.get_key - getting an integer represents the id of the node
2.get_weight -getting a float represents the weight of the node
3.set_weight - setting a float as the node's weight