[docs]classGraph(object):"""Abstract base Graph class. All graph interfaces should inherit from the class. """def__init__(self,name=None,n_vertices=None,edges=None,directed=None):ifnameisnotNone:self.name=name;ifdirectedisnotNone:self.directed=directed;else:self.directed=False;ifn_verticesisnotNone:self.add_vertex(n_vertices=n_vertices);ifedgesisnotNone:self.add_edge(edges);@propertydefname(self):ifhasattr(self,'_name'):returnself._name;else:returntype(self).__name__;@name.setterdefname(self,value):self._name=str(value);@propertydefdirected(self):returnself._directed;@directed.setterdefdirected(self,value):self._directed=bool(value);### Vertices@propertydefn_vertices(self):"""Number of vertices in the graph."""returnNone;@n_vertices.setterdefn_vertices(self,value):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defvertex(self,index):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
@propertydefvertices(self):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defadd_vertex(self,n_vertices=None,index=None,vertex=None):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defremove_vertex(self,index=None,vertex=None):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defvertex_property(self,name,index=None):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defvertex_properties(self):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defadd_vertex_property(self,name,source,dtype=None):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defset_vertex_property(self,name,source):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defremove_vertex_property(self,name):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defvertex_degrees(self):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defvertex_degree(self,index):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defvertex_out_degrees(self):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defvertex_out_degree(self,index):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defvertex_in_degrees(self):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defvertex_in_degree(self,index):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
### Edges @propertydefn_edges(self):"""Number of edges in the graph."""returnNone;@n_edges.setterdefn_edges(self,value):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defedge(self,edge):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
@propertydefedges(self):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defedge_connectivity(self):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defadd_edge(self,edge):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defremove_edge(self,edge):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defedge_property(self,name):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defedge_properties(self):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defadd_edge_property(self,name,source,dtype=None):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defset_edge_property(self,name,source):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defremove_edge_property(self,name):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
### IO
[docs]defsave(self,filename):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defload(self,filename):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
################################################################################## Graphs with spatial geometry###############################################################################
[docs]classGeometricGraph(Graph):"""Base class for graphs whose vertices are embedded in an Eucledian space."""def__init__(self,name=None,n_vertices=None,edges=None,directed=False,vertex_coordinates=None,vertex_radii=None,edge_coordinates=None,edge_radii=None,edge_geometries=None,shape=None):super(GeometricGraph,self).__init__(name=name,n_vertices=n_vertices,edges=edges,directed=directed);ifvertex_coordinatesisnotNone:self.vertex_coordinates=vertex_coordinates;ifvertex_radiiisnotNone:self.vertex_radii=vertex_radii;ifedge_coordinatesisnotNone:self.edge_coordinates=edge_coordinates;ifedge_radiiisnotNone:self.edge_radii=edge_radii;ifedge_geometriesisnotNone:self.edge_geometries=edge_geometries;self.shape=shape;@propertydefshape(self):"""The shape of the underlying space in which the graph is embedded."""returnself._shape;@shape.setterdefshape(self,value):self._shape=value;@propertydefndim(self):returnlen(self.shape);### Vertices
[docs]defvertex_coordinates(self,axis=None,vertex=None):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defset_vertex_coordinates(self,coordinates,axis=None,vertex=None):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defvertex_radii(self,vertex=None):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defset_vertex_radii(self,radius,vertex=None):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
### Edges
[docs]defedge_coordinates(self,edge=None):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defset_edge_coordinates(self,coordinates,axis=None,edge=None):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defedge_radii(self,edge=None):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defset_edge_radii(self,edge=None):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defedge_geometry(self,*args,**kwargs):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defset_edge_geometry(self,*args,**kwargs):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defreduce_edge_geometry(self):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defexpand_edge_geometry(self):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
### Functionality#def from_skeleton(self, skeleton):# raise NotImplementedError('Not implemented in graph class %s!' % self.name)#def skeleton(self, sink = None, dtype = bool):# raise NotImplementedError('Not implemented in graph class %s!' % self.name);### Functionalitydef__str__(self):s=super(GeometricGraph,self).__str__();try:shape=self.shape;shape='%r'%shapeifshapeisnotNoneelse'';except:shape='';try:edge_geometry_type=self.edge_geometry_type;ifedge_geometry_typeisNone:edge_geometry_type=''elifedge_geometry_type=='graph':edge_geometry_type='|G|'else:edge_geometry_type='|E|'except:edge_geometry_type='';returns+shape+edge_geometry_type;
[docs]classAnnotatedGraph(GeometricGraph):"""Base class for graphs whose vertices are embedded in an Eucledian space and have an annotation."""def__init__(self,name=None,n_vertices=None,edges=None,directed=False,vertex_coordinates=None,vertex_radii=None,edge_coordinates=None,edge_radii=None,edge_geometries=None,shape=None,vertex_labels=None,edge_labels=None,annotation=None):super(AnnotatedGraph,self).__init__(name=name,n_vertices=n_vertices,edges=edges,directed=directed,vertex_coordinates=vertex_coordinates,vertex_radii=vertex_radii,edge_coordinates=edge_coordinates,edge_radii=edge_radii,edge_geometries=edge_geometries,shape=shape);ifvertex_labelsisnotNone:self.vertex_labels=vertex_labels;ifedge_labelsisnotNone:self.edge_labels=edge_labels;self.annotation=annotation;@propertydefannotation(self):returnself._annotation;@annotation.setterdefannotation(self,value):self._annotation=value;### Vertices
[docs]defvertex_annotation(self):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defset_vertex_annotation(self,value):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
### Edges
[docs]defedge_annotation(self):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)
[docs]defset_edge_annotation(self,value):raiseNotImplementedError('Not implemented in graph class %s!'%self.name)