0% found this document useful (0 votes)
20 views2 pages

Graphs Lab1 Documentation

This document describes a graph representation using three dictionaries: dict_in, dict_out, and dict_costs. dict_in and dict_out store incoming and outgoing vertices for each vertex as keys. dict_costs stores the cost for each edge as a key-value pair. The Graph class initializes a graph with a number of vertices and edges. It contains methods for checking vertices and edges, adding/removing vertices and edges, and getting the number of vertices. Additional methods will implement in/out degree of vertices and reading/writing the graph to files.

Uploaded by

Pop Robert
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views2 pages

Graphs Lab1 Documentation

This document describes a graph representation using three dictionaries: dict_in, dict_out, and dict_costs. dict_in and dict_out store incoming and outgoing vertices for each vertex as keys. dict_costs stores the cost for each edge as a key-value pair. The Graph class initializes a graph with a number of vertices and edges. It contains methods for checking vertices and edges, adding/removing vertices and edges, and getting the number of vertices. Additional methods will implement in/out degree of vertices and reading/writing the graph to files.

Uploaded by

Pop Robert
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as ODT, PDF, TXT or read online on Scribd
You are on page 1/ 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