Is it feasible to sub-class, at the same time, the Graph, Vertex and Edge classes in graph-tool
in order to implement the behaviour of a certain type of graphs, such as social networks?
More specifically, I would like to have a class CollaborationNetwork(Graph)
that comprises instances of class Person(Vertex)
, class Publication(Vertex)
, class Authored(Edge)
, etc.
I imagine that the Person and Publication vertices are identified by a property_map
, while the Graph methods are wrapped into likes of add_authorship(Person, Publication)
that creates an instance of Authored
.
What I am not sure is if implementing such abstraction based on graph-tool
with makes sense and, if yes, how to connect CollaborationNetwork
to the sub-classes of Vertex and Edge.
(I know how only Subclassing Graph from the graph_tool package can work).
About the motivation:
I will be simulating the growth of a social network and will be comparing it with actual data, which is stored as a Neo4j graph.
I like the py2neo OGM approach, which represents these Person and Publication data as python objects.
It is possible, but I don't see any real advantage of doing so.
Subclassing
Vertex
is easy, but there are severalEdge
classes, depending on wether the graph is directed or filtered. In order to make it work, you would have to wrap theGraph
methods in your derived class that returnVertex
orEdge
objects (or iterators thereof) so that they convert them to your derivedEdge
andVertex
objects.Doing all this only so that the classes have different names seems to me like a waste of effort. But it is not impossible.
A simpler strategy would be to create a separate class (say
CitationGraph
), that does not subclassGraph
, but instead contains an instance of one. You can then implement convenience functions likeadd_person
andadd_publication
that perform your basic operations, while allowing you to access the underlyingGraph
at any point. Doing so will prevent lots of headaches, and even gives you things likepickle
support basically for free.