TripManager is the central coordinator in LYNX. It owns three trip collections — a waiting queue, an active list, and a history stack — and a city graph used to validate routes and compute distances via Dijkstra’s algorithm. Every trip created in the system passes through TripManager from the moment it is requested to the moment it is completed or cancelled.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.
Internal State
TripManager’s private fields map directly to the three-stage pipeline plus the graph infrastructure.| Field | Type | Purpose |
|---|---|---|
waitingQueue | Queue<Trip> | Pending trips awaiting driver assignment (FIFO) |
activeTrips | DoublyLinkedList<Trip> | Trips currently in progress |
history | Stack<Trip> | Completed and cancelled trips (LIFO) |
cityGraph | Graph<string> | City road network — capacity 7,000 vertices, undirected |
tripCounter | int | Monotonically incrementing ID counter |
cityIdByDisplayName | unordered_map<string, string> | Maps display name → city ID for O(1) graph lookup |
cityGraph(7000, false) and sets tripCounter to zero:
Method Reference
Trip Creation and Lifecycle
Creates a trip, sets its price via
calcPrice, and enqueues it as pendiente. Generates a unique ID in the format TRP-XXXXX. If no driver name is provided, the field is set to "Por asignar".Dequeues the first waiting trip, assigns the given driver, moves the trip to
activeTrips, and marks the driver as occupied via auth.driverAcceptRide(). Returns false if the queue is empty or the driver is unavailable.Finds a trip in
activeTrips by ID, marks it as completado, calls auth.addTripToUser() to update the passenger’s spend, calls auth.driverFinishRide() to free the driver, and pushes the trip to history.Cancels the first waiting trip (FIFO), marks it as cancelado, and pushes it to
history.Cancels a specific active trip by ID, frees the assigned driver if present, and pushes the trip to
history.Viewing
| Method | Description |
|---|---|
viewWaiting() | Prints a summary count and all trips in the waiting queue |
viewWaitingDetailed() | Prints the queue with position numbers using Queue::forEach |
viewActive() | Prints each active trip from the doubly-linked list |
viewHistory() | Dumps the full history stack non-destructively |
Search and Query
Exports all trips, sorts them by ID with HeapSort, then performs a recursive binary search. Returns an empty
Trip if not found.Inserts all trips into a temporary
AVLTree keyed by price and returns only those whose price falls within [precioMin, precioMax].Non-destructively searches the history stack for the most recent trip matching the given passenger DNI using
Stack::findInStack.Iterates the driver list and returns the DNI of the available driver with the highest rating, or an empty string if none are free.
Statistics
| Method | Returns | Description |
|---|---|---|
getTotalPlatformEarnings() | float | Recursive sum of 20% commission on every completed trip |
getTotalIngresosCompletados() | float | Sum of all completed trip prices (gross) |
contarViajesCompletados() | int | Count of completed trips in history |
contarViajesCancelados() | int | Count of cancelled trips in history |
contarViajesEnCurso() | int | Uses countIf on activeTrips |
calcTotalEnCola() | float | Uses Queue::sumBy to total prices in the waiting queue |
City Graph
Reads
cities.csv and connections.csv via FileManager, adds each city as a vertex (keyed by its ID string), and adds each road connection as a weighted undirected edge. Distances are stored internally in units of 100 metres and converted to km on retrieval.Returns a
RouteResult struct with originExists, destinationExists, connected, and kilometers. Both city lookups are O(1) through cityIdByDisplayName; connectivity is verified with Dijkstra.Runs Dijkstra between two city display names and returns the distance in km. Returns
-1 if the graph is not loaded or either city is unknown.O(1) check — queries the
cityIdByDisplayName hash map.ID Utilities
Scans all three collections (waiting queue, active list, history stack) and sets
tripCounter to the highest numeric suffix found in any existing TRP-XXXXX ID. Call this after loading trips from file so that generateId() never produces a duplicate.Exports every trip from all three collections, detects any empty or duplicate
TRP-XXXXX ID, assigns fresh unique IDs to the offending trips, and then redistributes them back into the correct collection based on their status field. Calls rebuildTripCounter() and syncUsedTripIds() internally.Sorting
| Method | Algorithm | Description |
|---|---|---|
sortActiveTripsByPrice() | Selection Sort | Sorts activeTrips in-place, highest price first |
getAllTripsSortedByPrice() | HeapSort | Exports all trips sorted by price descending |
getAllTripsSortedById() | HeapSort | Exports all trips sorted by ID ascending |
Full Trip Lifecycle Example
Status Transitions
loadCityGraph() is guarded by a graphLoaded flag and is a no-op on subsequent calls. Call it once at application startup before any route validation or trip creation.