Graph Engine¶
Engine
¶
Bases: Enum
Enum representing different types of graph engines.
Attributes:
Name | Type | Description |
---|---|---|
MEMORY |
In-memory graph engine. |
|
SQLITE |
SQLite-based graph engine. |
Source code in gamms/typing/graph_engine.py
IGraph
¶
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.
Source code in gamms/typing/graph_engine.py
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
|
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. |
KeyError
|
If source or target nodes do not exist in the graph. |
Source code in gamms/typing/graph_engine.py
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. |
Source code in gamms/typing/graph_engine.py
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. |
Source code in gamms/typing/graph_engine.py
get_neighbors(node_id)
abstractmethod
¶
Get the neighbors of a specific node.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
int
|
The unique identifier of the node whose neighbors are to be retrieved. |
required |
Returns:
Type | Description |
---|---|
Iterator[int]
|
Iterator[int]: An iterator that yields the IDs of neighboring nodes. |
Raises:
Type | Description |
---|---|
KeyError
|
If the node with the specified ID does not exist. |
Source code in gamms/typing/graph_engine.py
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. |
Source code in gamms/typing/graph_engine.py
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 |
remove_node(node_id)
abstractmethod
¶
Remove a node from the graph. Removing a node will also remove all edges connected to it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
node_id
|
int
|
The unique identifier of the node to be removed. |
required |
Source code in gamms/typing/graph_engine.py
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. |
Source code in gamms/typing/graph_engine.py
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. |
Source code in gamms/typing/graph_engine.py
IGraphEngine
¶
Bases: ABC
Abstract base class representing the graph engine.
The graph engine manages the underlying graph structure, providing access and control over graph operations.
Source code in gamms/typing/graph_engine.py
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. |
Source code in gamms/typing/graph_engine.py
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.
Source code in gamms/typing/graph_engine.py
Node
¶
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. |
Source code in gamms/typing/graph_engine.py
OSMEdge
¶
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. |