YapyGraph is a relatively simple directed graph implemented in Python. Besides the basic graph creation methods this one also performs subgraph searching.
Vertex.py
is the class that represents a simple vertex. Properties include:
id
- the vertex identifier. Uniqueness isn't enforced by Vertex.label
- an optional string label for the vertex (for those applications that need to assign string labels vertices)number
- an option number for the vertex (for those applications that need to assign numeric identifiers to vertices)degree
- the total degree (in-degree + out-degree). The Graph class maintains this.
Only one method is available. Besides this, a Vertex doesn't "do" anything.
name()
- returns the "name" of the vertex. The "name" is defined as the concatenation of the label and number.
Graph.py
defines a directed graph class. Methods include:
__init__
- constructor that builds an empty graphaddEdge
- adds an edge between two vertices (either new Vertex objects, or existing vertex ids)addVertex
- adds a new vertex, if the vertex id doesn't already existdeleteEdge
- removes the edge between the vertices with the given vertex idsdeleteVertex
- deletes the vertex with the given id, along with all edges connected to itedges
- iterates over all edges, returning (Vertex,Vertex) tuplesfindVertex
- returns the first Vertex that has the given name, or NonehasEdgeBetweenVertices
- returns true if an edge exists between vertices with the given idslabels
- iterates over all labels in the graphnames
- iterates over all names in the graphnumVertices
- returns the number of vertices__rep__
- returns a dot representation of the graphsearch
- searches for every instances of a given subgraphvertices
- returns a list of vertices
Unit tests are located in tests
. Run nosetests
to run all the unit tests.
nosetests --with-path=.. tests/testGraph.py
git clone
this repo- Create a virtual environment:
python3 -m venv PATH_TO_YAPYGRAPH
cd PATH_TO_YAPYGRAPH
- "Activate" the venv:
source bin/activate
- Install nose:
pip install nose
- Install pathmunge for nose:
pip install nose-pathmunge