| Name | Number |
|---|---|
| Bárbara Gomes | up202305089 |
| Tomás Morais | up202304692 |
| Tomás Silva | up202307796 |
Grade : 18,3
The dataset contains key information for representing an urban map as a graph, with intersections as nodes and street segments as edges. The driving and walking times provide weights for these edges, and the parking information at each location can be used to prioritize certain paths when considering travel routes. This dataset allows route optimization or travel time analysis, with the flexibility to handle different modes of transportation and parking considerations.
- The graph used to represent the dataset is composed of many nodes, each representing a different location in Porto, and edges between them representing the streets that connect the respective locations.
- To represent the two different travel times (driving and walking), each edge contains two “weight values”, one for each travel mode.
- We assume that every street is “two-way”, so between every two nodes with a connection, there are two directed edges with opposite directions.
- To check if a location has parking space (needed for some algorithms), a boolean member
hasParkingwas added to the vertex class.
- A new instance of the
Graphclass is created. - File
Locations.csvis opened and read. - For each line containing information about a specific location, a
vertexis created with its attributes corresponding to the content and added to the graph. - File
Distances.csvis opened and read. - For each line containing information about a street connecting two locations, the corresponding nodes are obtained and a bidirectional
edgeis added between them.
Time Complexity: O(V + E)
Keep track of a set containing nodes for which the shortest path distance d(u) from the source s has already been determined:
- Start with
S = {s}, settingd(s) = 0while all other nodes haved(u) = ∞. - Continuously select the unexplored node
vwith the smallest tentative distance, add it toS, and updated(v)as:
d(v) = min(d(v), d(u) + w(u,v)) where(u,v)is an edge of the graph. - A Mutable Priority Queue helps manage edge relaxation efficiently by prioritizing nodes with the shortest known distance.
After all iterations, the shortest path from the source node to any other node is obtained.
Time Complexity: O((V + E) log V)
- Source and Destination nodes are obtained from the graph based on user input.
- Dijkstra is applied to find the shortest distances from the source node to all other nodes.
- The desired path and corresponding traversal time are obtained from
getDrivingPath(orgetWalkingPath) andgetDrivingDist(orgetWalkingDist). - All nodes (except the source and destination) are removed from the graph.
- Steps 2 and 3 are repeated to find the alternative independent route (if any exists).
Time Complexity: O(V log V + E)
- Source and Destination nodes are obtained from the graph based on user input.
- Apply restrictions:
- If
IncludeNodesexist, these nodes must be included. - If
AvoidNodesexist, remove the corresponding vertices from the graph. - If
AvoidSegmentsexist, remove both directions of each edge to avoid.
- Find the shortest path from Source to IncludeNode and then from IncludeNode to Destination using Dijkstra’s algorithm.
- Calculate total driving distance and output the computed path and distance.
Time Complexity: O(N)
- Source and Destination nodes are obtained from the graph based on user input.
- Identify nodes with parking space.
- Apply Dijkstra to obtain the minimum time to reach the destination from any parking node.
- Sort parking nodes by their walking time relative to
maxWalkTimeand check for a valid route. -
- If yes, select the solution with the smallest total time.
- If no, select the two alternatives with the smallest walking time.
Time Complexity: O((V + E) log V)

