eolearn.core.graph¶
The module implements the core graph data structure. It is used, for example, to model dependencies among tasks in the eoworkflow module.
-
class
eolearn.core.graph.
DirectedGraph
(adjacency_dict=None)[source]¶ Bases:
object
A directed graph using adjacency-list representation.
Constructs a new graph from an adjacency list. If adjacency_dict is None, an empty graph is constructed.
- Parameters
adjacency_dict – A dictionary mapping vertices to lists neighbors
-
get_indegrees
()[source]¶ Returns a dictionary containing in-degrees of vertices of the graph.
Note that if
u
is not in graph thenindegrees[u]=0
due todefaultdict
behavior!
-
get_indegree
(vertex)[source]¶ Returns the in-degree of the vertex.
The in-degree is the number of vertices
vertex'
such thatvertex' -> vertex
is an edge of the graph.- Parameters
vertex – Vertex
-
get_outdegree
(vertex)[source]¶ Returns the out-degree of the vertex.
The out-degree is the number of vertices
vertex'
such thatvertex -> vertex'
is an edge of the graph.- Parameters
vertex – Vertex
-
add_edge
(u_vertex, v_vertex)[source]¶ Adds the edge
u_vertex -> v_vertex
to the graph if the edge is not already present.- Parameters
u_vertex – Vertex
v_vertex – Vertex
- Returns
True
if a new edge was added.False
otherwise.
-
del_edge
(u_vertex, v_vertex)[source]¶ Removes the edge
u_vertex -> v_vertex
from the graph if the edge is present.- Parameters
u_vertex – Vertex
v_vertex – Vertex
- Returns
True
if the existing edge was removed.False
otherwise.
-
add_vertex
(vertex)[source]¶ Adds a new vertex to the graph if not present.
- Parameters
vertex – Vertex
- Returns
True
ifvertex
added and not yet present.False
otherwise.
-
del_vertex
(vertex)[source]¶ Removes the vertex
vertex
and all incident edges from the graph.Note that this is an expensive operation that should be avoided!
Running time is O(V+E)
- Parameters
vertex – Vertex
- Returns
True
ifvertex
was removed from the graph.False
otherwise.
-
is_edge
(u_vertex, v_vertex)[source]¶ True if
u_vertex -> v_vertex
is an edge of the graph. False otherwise.- Parameters
u_vertex – Vertex
v_vertex – Vertex