You are on page 1of 2

Graphs Lab1 Documentation

Representation: the graph – an object with 3 dictionaries


- dict_in and dict_out : have as a key an integer number representing a valid
vertex
- dict_costs has as a key a pair (vertex1,vertex2) which represent a valid edge
- In dict_in[vertex] we have a list containing the vertices which go into the key
vertex
- In dict_out[vertex] we have a list containing the vertices which come out from
the key vertex
- In dict_costs[(vertex1,vertex2)] : the cost corresponding to that edge
class Graph:
def __init__(self,number_of_vertices,number_of_edges):
#the constructor of a graph has the number of its vertices and edges
def isVertex (self,x):
#checks if x is a vertex or not
def isEdge (self,x):
#checks if x is an edge or not
def addVertex (self,x):
#if x is not already a vertex x is added as a vertex
def addEdge(self,x,y,c):
#if x or y are not already vertices they are added, then if (x,y) is not an edge it is
added with the afferent cost c
def removeVertex(self,x):
#if the vertex x exists it removes it
def removeEdge(self,x,y):
#if the edge (x,y) exists it removes it
def get_NrVertices(self):
#it returns the number of graph’s vertices (self.__number_of_vertices)
def parseVertices_out(self):
#returns a copy of an iterator (copy.deepcopy(self.__dict_out.keys()))
def parseVertices_in(self):
#returns a copy of an iterator (copy.deepcopy(self.__dict_in.keys()))

These are the functionalities already done. I still have to implement the in/out
degree of a vertex (which should return just the length of the list situated at the
key “vertex” in the dictionaries dict_in and dict_out), read/write(also save in other
file) the graph-functionalities which will work with files (these functionalities will
be part of the repository – where the graphs are stored) and the random
generator of edges (vertices will be numbered from 0 to the number of vertices
given).

You might also like