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:

  1. v_size() - return a number of vertices (nodes) in the graph

  2. e_size() - return the number of edges in the graph

  3. get_all_v() - return a dictionary with all the vertices in the graph (every node object mapped by its id)

  4. get_mc() - return and integer represents the mode count (number of changes) of the graph

  5. 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)

  6. 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)

  7. add_node(node_id : int) - add a node with a given id to the graph (return true if the node was successfully added)

  8. 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)

  9. 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)

  10. 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

Related Links:

1.Graph Theory

2.Directed Graph