Graph Engine¶
Bases: ABC
Abstract base class representing the graph engine.
The graph engine manages the underlying graph structure, providing access and control over graph operations.
graph
abstractmethod
property
¶
Get the current graph managed by the engine.
Returns:
Name | Type | Description |
---|---|---|
IGraph |
IGraph
|
The graph instance being managed. |
Raises:
Type | Description |
---|---|
RuntimeError
|
If the graph has not been initialized. |
attach_networkx_graph(G)
abstractmethod
¶
Attach a NetworkX graph to the graph engine.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
G
|
Graph
|
The NetworkX graph to attach. |
required |
Returns:
Name | Type | Description |
---|---|---|
IGraph |
IGraph
|
The graph instance created from the NetworkX graph. |
Raises:
Type | Description |
---|---|
ValueError
|
If the provided graph is invalid or cannot be attached. |
terminate()
abstractmethod
¶
Terminate the graph engine and perform necessary cleanup operations.
This method should ensure that all resources allocated to the graph engine are properly released and that any ongoing operations are gracefully stopped.
Graph¶
Bases: ABC
Abstract base class representing a graph structure.
The graph consists of nodes and edges, allowing for addition, removal, and retrieval of these elements.
add_edge(edge_data)
abstractmethod
¶
Add a new edge to the graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edge_data
|
Dict[str, Any]
|
A dictionary containing the edge's attributes. Expected keys include: - 'id' (int): Unique identifier for the edge. - 'source' (int): ID of the source node. - 'target' (int): ID of the target node. - 'length' (float): Length of the edge. - 'linestring' (List[Tuple[float, float]], optional): Geometry of the edge. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the edge_data is missing required fields, contains invalid data, or references non-existent nodes. |
KeyError
|
If an edge with the same ID already exists in the graph. |
add_node(node_data)
abstractmethod
¶
Add a new node to the graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_data
|
Dict[str, Any]
|
A dictionary containing the node's attributes. Expected keys include: - 'id' (int): Unique identifier for the node. - 'x' (float): X-coordinate of the node. - 'y' (float): Y-coordinate of the node. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If the node_data is missing required fields or contains invalid data. |
KeyError
|
If a node with the same ID already exists in the graph. |
get_edge(edge_id)
abstractmethod
¶
Retrieve the attributes of a specific edge.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edge_id
|
int
|
The unique identifier of the edge to retrieve. |
required |
Returns:
Name | Type | Description |
---|---|---|
OSMEdge |
OSMEdge
|
A dictionary containing the edge's attributes. |
Raises:
Type | Description |
---|---|
KeyError
|
If the edge with the specified ID does not exist. |
get_edges()
abstractmethod
¶
Creates an iterator of edge IDs in the graph.
Returns:
Type | Description |
---|---|
Iterator[int]
|
Iterator[int]: An iterator that yields edge IDs. |
get_node(node_id)
abstractmethod
¶
Retrieve the attributes of a specific node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
int
|
The unique identifier of the node to retrieve. |
required |
Returns:
Type | Description |
---|---|
Node
|
Dict[str, Any]: A dictionary containing the node's attributes. |
Raises:
Type | Description |
---|---|
KeyError
|
If the node with the specified ID does not exist. |
get_nodes()
abstractmethod
¶
Creates an iterator of node IDs in the graph.
Returns:
Type | Description |
---|---|
Iterator[int]
|
Iterator[int]: An iterator that yields node IDs. |
remove_edge(edge_id)
abstractmethod
¶
Remove an edge from the graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edge_id
|
int
|
The unique identifier of the edge to be removed. |
required |
Raises:
Type | Description |
---|---|
KeyError
|
If the edge with the specified ID does not exist. |
remove_node(node_id)
abstractmethod
¶
Remove a node from the graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
int
|
The unique identifier of the node to be removed. |
required |
Raises:
Type | Description |
---|---|
KeyError
|
If the node with the specified ID does not exist. |
ValueError
|
If removing the node would leave edges without valid source or target nodes. |
update_edge(edge_data)
abstractmethod
¶
Update an existing edge's attributes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
edge_data
|
Dict[str, Any]
|
A dictionary containing the edge's updated attributes. Must include: - 'id' (int): Unique identifier for the edge. - Any other attributes to be updated (e.g., 'source', 'target', 'length', 'linestring'). |
required |
Raises:
Type | Description |
---|---|
KeyError
|
If the edge with the specified ID does not exist. |
ValueError
|
If the provided data is invalid or references non-existent nodes. |
update_node(node_data)
abstractmethod
¶
Update an existing node's attributes.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_data
|
Dict[str, Any]
|
A dictionary containing the node's updated attributes. Must include: - 'id' (int): Unique identifier for the node. - Any other attributes to be updated (e.g., 'x', 'y'). |
required |
Raises:
Type | Description |
---|---|
KeyError
|
If the node with the specified ID does not exist. |
ValueError
|
If the provided data is invalid. |
Represents a node within a graph.
Attributes:
Name | Type | Description |
---|---|---|
id |
int
|
The unique identifier for the node. |
x |
float
|
The x-coordinate of the node's position. |
y |
float
|
The y-coordinate of the node's position. |
Represents an OpenStreetMap (OSM) edge within a graph.
Attributes:
Name | Type | Description |
---|---|---|
id |
int
|
The unique identifier for the edge. |
source |
int
|
The ID of the source node. |
target |
int
|
The ID of the target node. |
length |
float
|
The length of the edge. |
linestring |
LineString
|
The geometry of the edge represented as a LineString. Defaults to None. |