1.3. Embedded Graphs
This is the Embedded graph class which inherits structure from nx.Graph.
Note that this class can be imported as:
import cereeberus
T = cereeberus.EmbeddedGraph()
- class cereeberus.reeb.embeddedgraph.EmbeddedGraph[source]
A class to represent a graph with 2D embedded coordinates for each vertex.
- Attributes
- graphnx.Graph
a NetworkX graph object
- coordinatesdict
a dictionary mapping vertices to their (x, y) coordinates
- add_node(vertex, x, y)[source]
Adds a vertex to the graph and assigns it the given coordinates.
- Parameters:
vertex (str) – The vertex to be added.
x (float) – The x-coordinate of the vertex.
y (float) – The y-coordinate of the vertex.
- add_nodes_from(nodes, coordinates)[source]
Adds multiple vertices to the graph and assigns them the given coordinates.
- Parameters:
nodes (list) – A list of vertices to be added.
coordinates (dict) – A dictionary mapping vertices to their coordinates.
- add_edge(u, v)[source]
Adds an edge between the vertices u and v if they exist.
- Parameters:
u (str) – The first vertex of the edge.
v (str) – The second vertex of the edge.
- get_coordinates(vertex)[source]
Returns the coordinates of the given vertex.
- Parameters:
vertex (str) – The vertex whose coordinates are to be returned.
- Returns:
The coordinates of the vertex.
- Return type:
tuple
- set_coordinates(vertex, x, y)[source]
Sets the coordinates of the given vertex.
- Parameters:
vertex (str) – The vertex whose coordinates are to be set.
x (float) – The new x-coordinate of the vertex.
y (float) – The new y-coordinate of the vertex.
- Raises:
ValueError – If the vertex does not exist in the graph.
- get_bounding_box()[source]
Method to find a bounding box of the vertex coordinates in the graph.
- Returns:
A list of tuples representing the minimum and maximum x and y coordinates.
- Return type:
list
- get_bounding_radius()[source]
Method to find the radius of the bounding circle of the vertex coordinates in the graph.
- Returns:
The radius of the bounding circle.
- Return type:
float
- get_mean_centered_coordinates()[source]
Method to find the mean-centered coordinates of the vertices in the graph.
- Returns:
A dictionary mapping vertices to their mean-centered coordinates.
- Return type:
dict
- set_mean_centered_coordinates()[source]
Method to set the mean-centered coordinates of the vertices in the graph. Warning: This overwrites the original coordinates
- g_omega(theta)[source]
Function to compute the function \(g_\omega(v)\) for all vertices \(v\) in the graph in the direction of \(\theta \in [0,2\pi]\) . This function is defined by \(g_\omega(v) = \langle \texttt{pos}(v), \omega \rangle\) .
- Parameters:
theta (float) – The angle in \([0,2\pi]\) for the direction to compute the \(g(v)\) values.
- Returns:
A dictionary mapping vertices to their \(g(v)\) values.
- Return type:
dict
- g_omega_edges(theta)[source]
Calculates the function value of the edges of the graph by making the value equal to the max vertex value
- Parameters:
theta (float) – The direction of the function to be calculated.
- Returns:
- dict
A dictionary of the function values of the edges.
- sort_vertices(theta, return_g=False)[source]
Function to sort the vertices of the graph according to the function g_omega(v) in the direction of theta in [0,2*np.pi].
- Parameters:
theta (float) – The angle in [0,2*np.pi] for the direction to sort the vertices.
return_g (bool) – Whether to return the g(v) values along with the sorted vertices.
- Returns:
- list
A list of vertices sorted in increasing order of the \(g(v)\) values. If
return_g
is True, also returns theg
dictionary with the function valuesg[vertex_name]=func_value
.
- sort_edges(theta, return_g=False)[source]
Function to sort the edges of the graph according to the function
\[g_\omega(e) = \max \{ g_\omega(v) \mid v \in e \}\]in the direction of \(\theta \in [0,2\pi]\) .
- Parameters:
theta (float) – The angle in \([0,2\pi]\) for the direction to sort the edges.
return_g (bool) – Whether to return the \(g(v)\) values along with the sorted edges.
- Returns:
A list of edges sorted in increasing order of the \(g(v)\) values. If
return_g
is True, also returns theg
dictionary with the function valuesg[vertex_name]=func_value
.
- lower_edges(v, omega)[source]
Function to compute the number of lower edges of a vertex v for a specific direction (included by the use of sorted v_list).
- Parameters:
v (str) – The vertex to compute the number of lower edges for.
omega (tuple) – The direction vector to consider given as an angle in [0, 2pi].
- Returns:
The number of lower edges of the vertex v.
- Return type:
int
- plot(bounding_circle=False, color_nodes_theta=None, ax=None, **kwargs)[source]
Function to plot the graph with the embedded coordinates.
If
bounding_circle
is True, a bounding circle is drawn around the graph.If
color_nodes_theta
is not None, it should be given as a theta in \([0,2\pi]\). Then the nodes are colored according to the \(g(v)\) values in the direction of theta.