This project compares the performance of the Dijkstra and A* algorithms in a graph traversal scenario. The graph includes vertices with coordinates, trails with Euclidean distances, and portals that act as zero-distance paths. The A* algorithm uses the Euclidean distance as its heuristic function. The goal is to find the shortest path from a starting vertex to a destination vertex while considering a limited energy budget and a maximum number of usable portals.
- Graph Representation: The graph can be represented using either an adjacency list or an adjacency matrix.
- Portals: Special edges that allow instant travel between two vertices (zero distance).
- Energy Constraint: The total energy available limits the distance that can be traveled.
- Heuristic Function: The A* algorithm uses the Euclidean distance as a heuristic to guide the search.
- Performance Metrics: The program measures the execution time and path length for both Dijkstra and A* algorithms.
- C++ Compiler (e.g.,
g++
)
- C++ Standard Library (No external dependencies required)
The project includes a Makefile
to simplify the compilation process. Below are the available commands:
- Compile the Program:
To compile the program, run:
make
This will generate the executable in the ./bin/ folder.
- Clean Build Files: To remove all compiled object files and the executable, run:
make clean
- Compile with Specific Test Flags: The Makefile supports different test modes. You can compile the program with specific test flags using the TEST variable:
For testing algorithms (TEST_ALGS):
make all TEST=algs
For testing adjacency list space (TEST_LIST_SPACE):
make all TEST=list-space
For testing adjacency matrix space (TEST_MATRIZ_SPACE):
make all TEST=matriz-space
After compiling, run the program using:
./bin/a.out < input_file.txt
- n: Number of vertices.
- m: Number of trails.
- k: Number of portals.
- dijkOrAstar (Optional): Test mode:
0
for none1
for Dijkstra2
for A*
Each line contains the x and y coordinates of a vertex.
Each line contains two integers representing the start and end vertices of a trail.
Each line contains two integers representing the start and end vertices of a portal.
- s: The amount of energy available.
- q: The maximum number of usable portals.
The output of the program depends on the compilation type.