Documentation Index
Fetch the complete documentation index at: https://mintlify.com/yeremyacuna/LYNX/llms.txt
Use this file to discover all available pages before exploring further.
Graph<T> is a weighted adjacency-list graph that forms the backbone of LYNX’s geographic routing layer. Each vertex stores an arbitrary data value of type T; edges carry integer weights and are stored as a singly-linked list hanging off each vertex. LYNX instantiates the graph as Graph<string> where vertex data is a city ID string, and the graph is configured as undirected so that road distances apply symmetrically between any two cities. The full city graph is loaded once at startup and then queried repeatedly to price trip routes via Dijkstra’s algorithm.
Adjacency-List Structure
Internally, the graph is an array ofVertex structs. Each vertex owns a linked list of Edge structs:
addEdge is O(1). For an undirected graph, two Edge objects are created — one in each direction.
Template
T is the vertex data type. LYNX uses Graph<string> with short city ID strings (e.g., "LIM", "CUS").
Constructor
capacity— fixed maximum number of vertices. LYNX allocates 7000 for the city graph.directed— passtruefor a directed graph; LYNX usesfalse(undirected).
Method Reference
| Method | Signature | Description |
|---|---|---|
addVertex | int addVertex(T value) | Appends a new vertex and returns its index; returns -1 if the graph is full |
addEdge | void addEdge(int from, int to, int weight = 1) | Adds a weighted edge; adds the reverse edge automatically if undirected |
removeEdge | void removeEdge(int from, int to) | Removes the edge (and its reverse for undirected graphs) |
hasEdge | bool hasEdge(int from, int to) const | Returns true if a direct edge exists from from to to |
degree | int degree(int v) const | Returns the number of edges leaving vertex v |
bfs | void bfs(int start) const | Breadth-first traversal from start; uses an internal Queue<int> and prints vertices in BFS order |
dfs | void dfs(int start) const | Iterative depth-first traversal using an internal Stack<int> |
dfsRecursive | void dfsRecursive(int start) const | Recursive DFS traversal |
dijkstra | void dijkstra(int start) const | Prints shortest distances and full paths from start to all reachable vertices |
dijkstraDistance | int dijkstraDistance(int start, int target) const | Returns the shortest-path distance as an integer; returns -1 if unreachable |
getData | T getData(int v) const | Returns the data stored at vertex v |
isEmpty | bool isEmpty() const | Returns true when no vertices have been added |
getSize | int getSize() const | Current vertex count |
isDirected | bool isDirected() const | Returns true if the graph was constructed as directed |
print | void print() const | Prints the full adjacency list with weights |
clear | void clear() | Removes all edges and marks all vertices inactive; resets size to 0 |
findVertex | int findVertex(T value) const | Linear scan; returns the index of the first vertex whose data equals value, or -1 |
Dijkstra’s Algorithm in Detail
Bothdijkstra and dijkstraDistance use an internal Heap<DijkstraNode> configured as a min-heap priority queue. DijkstraNode is a private nested struct inside Graph<T> — it is not accessible from outside the class:
2147483647 (the sentinel “infinity” constant used in the source), sets dist[start] = 0, and relaxes edges by pushing updated DijkstraNode entries onto the heap. Stale entries (where curr.dist > dist[v]) are skipped with a continue check, avoiding the need to support a decrease-key operation.
dijkstra(start)— prints distances and reconstructed paths to every reachable vertex. Useful for debugging the city graph.dijkstraDistance(start, target)— returns only the integer distance to a single target. Returns-1if the target is unreachable. This is the method called byTripManagerto price a route.
City Graph Loading
TripManager::loadCityGraph(FileManager&) builds the production graph:
- Reads
cities.csv— each row provides a city ID and display name. Every city is added withaddVertex, and the returned index is stored in anunordered_map<string, int>keyed by city ID. - Reads
connections.csv— each row provides two city IDs and a distance in kilometres. The loader multiplies by 100 to convert to integer units of 100 metres before callingaddEdge. - A second
unordered_map<string, string>maps display names back to city IDs so that user-facing city name input can be translated to graph vertex indices.
Weight unit. Edge weights in the graph are stored in units of 100 metres (i.e., kilometres × 100, cast to
int). The value returned by dijkstraDistance is therefore in these same units. Divide by 100.0 to recover kilometres:Code Example
Complexity
| Operation | Time Complexity |
|---|---|
addVertex | O(1) |
addEdge | O(1) |
removeEdge | O(E) per vertex adjacency list |
hasEdge | O(E) |
degree | O(E) |
bfs | O(V + E) |
dfs | O(V + E) |
dfsRecursive | O(V + E) |
dijkstra | O((V + E) log V) |
dijkstraDistance | O((V + E) log V) |
findVertex | O(V) |
clear | O(V + E) |