https://github.com/matiascarabella/graph-matrix-pathfinder
Set of tools for graph manipulation and analysis, including pathfinding algorithms and cycle detection.
https://github.com/matiascarabella/graph-matrix-pathfinder
adjacency-matrix bellman-ford cycle-detection dijkstra graph graph-algorithms java pre-order-traversal shortest-path
Last synced: 3 months ago
JSON representation
Set of tools for graph manipulation and analysis, including pathfinding algorithms and cycle detection.
- Host: GitHub
- URL: https://github.com/matiascarabella/graph-matrix-pathfinder
- Owner: MatiasCarabella
- License: mit
- Created: 2024-06-11T02:10:19.000Z (12 months ago)
- Default Branch: main
- Last Pushed: 2024-11-24T01:20:52.000Z (6 months ago)
- Last Synced: 2024-12-28T00:23:49.755Z (5 months ago)
- Topics: adjacency-matrix, bellman-ford, cycle-detection, dijkstra, graph, graph-algorithms, java, pre-order-traversal, shortest-path
- Language: Java
- Homepage:
- Size: 11.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Graph Matrix Implementation
Java implementation of graph data structures and algorithms using adjacency matrices. This project provides a set of tools for graph manipulation and analysis, including multiple pathfinding algorithms and cycle detection.
## Features
### Graph Operations
- Create weighted directed graphs with a specified number of vertices
- Add weighted edges between vertices
- Visualize the graph structure through adjacency matrix representation### Algorithms
- **Shortest Path Finding**:
- Bellman-Ford algorithm for detecting negative cycles and finding shortest paths
- Dijkstra's algorithm for efficient shortest path calculation in non-negative weighted graphs
- **Graph Analysis**:
- Cycle detection using Depth-First Search (DFS)
- Tree height calculation from any starting node
- Pre-order graph traversal## Implementation Details
The project consists of two main classes:
- `Grafo`: Contains all graph operations and algorithms
- `Main`: Provides example usage and testing scenarios### Data Structure
- Uses an adjacency matrix representation (`int[][]`)
- Infinity is represented by `Integer.MAX_VALUE`
- Vertices are zero-indexed internally but displayed one-indexed in output## Usage Example
```java
// Create a graph with 13 vertices
Grafo grafo = new Grafo(13);// Add weighted edges
grafo.agregarArista(0, 1, 200); // Add edge from vertex 1 to 2 with weight 200
grafo.agregarArista(0, 12, 250); // Add edge from vertex 1 to 13 with weight 250// Find shortest path using Dijkstra's algorithm
grafo.caminoMasCortoDijkstra(0, 2); // Find shortest path from vertex 1 to 3// Detect cycles
List> ciclos = grafo.encontrarCiclos();
```## Output
The program provides detailed output for all operations:
- Adjacency matrix visualization
- Shortest path routes and distances
- Cycle detection results
- Tree height calculations
- Pre-order traversal sequences## Requirements
- Java Development Kit (JDK) 8 or higher
## Building and Running
1. Compile the project:
```bash
javac Main.java
```2. Run the program:
```bash
java Main
```## License
This project is licensed under the [MIT License](LICENSE).
## Acknowledgments
- Implemented as part of a university project for graph theory and algorithms
- Based on classical graph theory algorithms and data structures