knapscak and graph optimization problems can represent any road map (including those with one-way streetsby weighted digraph similarlythe structure of the world wide web can be represented as digraph in which the nodes are web pages and there is an edge from node to node if and only if there is link to page on page traffic patterns could be modeled by adding weight to each edge indicating how often is it used there are also many less obvious uses of graphs biologists use graphs to model things ranging from the way proteins interact with each other to gene expression networks physicists use graphs to describe phase transitions epidemiologists use graphs to model disease trajectories and so on figure contains classes implementing abstract types corresponding to nodesweighted edgesand edges having class for nodes may seem like overkill after allnone of the methods in class node perform any interesting computation we introduced the class merely to give us the flexibility of decidingperhaps at some later pointto introduce subclass of node with additional properties class node(object)def __init__(selfname)"""assumes name is string""self name name def getname(self)return self name def __str__(self)return self name class edge(object)def __init__(selfsrcdest)"""assumes src and dest are nodes""self src src self dest dest def getsource(self)return self src def getdestination(self)return self dest def __str__(self)return self src getname('->self dest getname(class weightededge(edge)def __init__(selfsrcdestweight )"""assumes src and dest are nodesweight float""self src src self dest dest self weight weight def getweight(self)return self weight def __str__(self)return self src getname('->(str(self weight')'self dest getname(figure nodes and edges