This module provide a simple pure python implementation for a graph interface do not implement copy concept.

class core.graph.graph.Graph(graph=None)[source]

Bases: core.graph.interface.graph.IGraph, core.graph.interface.graph.IVertexListGraph, core.graph.interface.graph.IEdgeListGraph, core.graph.interface.graph.IMutableVertexGraph, core.graph.interface.graph.IMutableEdgeGraph, core.graph.interface.graph.IExtendGraph

Directed graph with multiple links in this implementation: - vertices are tuple of edge_in, edge_out - edges are tuple of source,target

add_edge(edge=(None, None), eid=None)[source]

add an edge to the graph, if eid is not provided create a new eid

Parameters:
  • edge : a tuple (vertex source,vertex target)
  • eid : the id of the created edge
Types:
  • edge : (vid,vid)
  • eid : eid
Returns:

the id of the newly created edge

Return type:

eid

add_vertex(vid=None)[source]

add a vertex to the graph, if vid is not provided create a new vid

Parameters:vid (vid) -- the id of the vertex to add, default=None
Returns:the id of the created vertex
Return type:vid
clear()[source]

remove all vertices and edges don't change references to objects

clear_edges()[source]

remove all the edges of the graph don't change references to objects

edges(vid=None)[source]

retrieve the edges linked to a specified vertex, all if vid is None

Parameters:vid (vid) -- id of the reference vertex, default=None
Return type:iter of eid
extend(graph)[source]

add the specified graph to self, create new vid and eid

Parameters:graph (Graph) -- the graph to add
Returns:two dictionnary specifying correspondence between graph id and self id
Return type:({vid:vid},{eid:eid})
has_edge(eid)[source]

test wether an edge belong to the graph

Parameters:eid (eid) -- edge id to test
Return type:bool
has_vertex(vid)[source]

test wether a vertex belong to the graph

Parameters:vid (vid) -- vertex id to test
Return type:bool
in_edges(vid)[source]

retrieve the edges linked to a specified vertex, oriented inside the vertex

Parameters:vid (vid) -- id of the reference vertex, default=None
Return type:iter of eid
in_neighbors(vid)[source]

iterator on the neighbors of vid where edges are directed from neighbor to vid

Parameters:vid (vid) -- id of the reference vertex
Return type:iter of vid
is_valid()[source]

test the validity of the graph

Return type:bool
nb_edges(vid=None)[source]

number of edges linked to a specified vertex, total number if vid is None

Parameters:vid (vid) -- id of the reference vertex, default=None
Return type:iter of eid
nb_in_edges(vid)[source]

number of edges linked to a specified vertex, oriented inside vertex

Parameters:vid (vid) -- id of the reference vertex, default=None
Return type:iter of eid
nb_in_neighbors(vid)[source]

number of neighbors such as edges are directed from neighbor to vid

Parameters:vid (vid) -- id of the reference vertex
Return type:int
nb_neighbors(vid)[source]

number of neighbors regardless of the orientation of the edge

Parameters:vid (vid) -- id of the reference vertex
Return type:int
nb_out_edges(vid)[source]

number of edges linked to a specified vertex, oriented outside vertex

Parameters:vid (vid) -- id of the reference vertex, default=None
Return type:iter of eid
nb_out_neighbors(vid)[source]

number of neighbors such as edges are directed from vid to neighbor

Parameters:vid (vid) -- id of the reference vertex
Return type:int
nb_vertices()[source]

return the total number of vertices

Return type:int
neighbors(vid)[source]

iterator on the neighbors of vid regardless of the orientation of the edge

Parameters:vid (vid) -- id of the reference vertex
Return type:iter of vid
out_edges(vid)[source]

retrieve the edges linked to a specified vertex, oriented outside the vertex

Parameters:vid (vid) -- id of the reference vertex, default=None
Return type:iter of eid
out_neighbors(vid)[source]

iterator on the neighbors of vid where edges are directed from vid to neighbor

Parameters:vid (vid) -- id of the reference vertex
Return type:iter of vid
remove_edge(eid)[source]

remove a specified edge from the graph

Parameters:eid (eid) -- id of the edge to remove
remove_vertex(vid)[source]

remove a specified vertex of the graph remove all the edges attached to it

Parameters:vid (vid) -- the id of the vertex to remove
source(eid)[source]

retrieve the source of an edge

Parameters:eid (eid) -- id of the edge
Return type:vid
target(eid)[source]

retrieve the target of an edge

Parameters:eid (eid) -- id of the edge
Return type:vid
vertices()[source]

iterator on vertices

Return type:iter of vid

Previous topic

<no title>

Next topic

<no title>

This Page