This repo is a personal learning project focussed on implementing some graph algorithms while improving my skills in:
- Algorithms and Datastructures
- The Odin Programming Language
- Neovim as a dev environment
My main goal is to understand the algorithms and have some fun playing around...
Odin is a general-purpose programming language with distinct typing built for high performance, modern systems and data-oriented programming.
Odin is the C alternative for the Joy of Programming.
This project implements several graph pathfinding algorithms:
- BFS (Breadth-First Search): Finds shortest paths in unweighted graphs
- Dijkstra's Algorithm: Finds shortest paths in graphs with non-negative edge weights
- Bellman-Ford Algorithm: Finds shortest paths in graphs that may contain negative edge weights (but no negative cycles)
- Floyd-Warshall Algorithm: Solves all-pairs shortest-path problem for graphs containing both positive and negative edges, but also no negative cycles
The project includes graph generation utilities that can create random directed graphs with configurable parameters. These graphs are made reproducible by using the number of nodes to generate as the seed for the random number generator.
pathfinder/
├── main.odin # Entry point and CLI
├── types.odin # Type definitions (Edge, Graph)
├── graphGenerator.odin # Graph generation functions
├── shortestPaths.odin # Pathfinding algorithms
└── utils.odin # Utility functions (path reconstruction, graph printing)
odin run .Or with arguments:
odin build .
./pathfinder [NUM_NODES] [MIN_EDGES] [MAX_EDGES] [MIN_WEIGHT] [MAX_WEIGHT] [START_NODE_ID] [DESTINATION_NODE_ID] [OPTIONS]Usage: pathfinder [NUM_NODES] [MIN_EDGES] [MAX_EDGES] [MIN_WEIGHT] [MAX_WEIGHT] [START_NODE_ID] [DESTINATION_NODE_ID] [OPTIONS]
Options:
-h, --help Show this help message
-n, --negative-cycles Allow negative cycles in graph generation
-v, --verbose Print the generated graph
Positional Arguments:
NUM_NODES Number of nodes in the graph (default: 100)
MIN_EDGES Minimum edges per node (default: 1)
MAX_EDGES Maximum edges per node (default: 10)
MIN_WEIGHT Minimum edge weight (default: -10.0)
MAX_WEIGHT Maximum edge weight (default: 10.0)
START_NODE_ID Start NodeId for the path calculation (default: 0)
DESTINATION_NODE_ID Destination NodeId for the path calculation (default: 2)
# Run with default parameters
odin run .
# Show help
odin run . --help
# Generate a graph with 200 nodes
odin run . 200
# Custom graph parameters
odin run . 200 2 15 -5.0 5.0
# Custom graph with specific start and destination nodes
odin run . 200 2 15 -5.0 5.0 0 42
# Verbose output
odin run . 200 --verbose
# Allow negative cycles
odin run . 100 -n -v- LEACH Algorithm
- Directed Diffusion Algorithm
- Algorithm visualization: Build some sort of GUI
- Benchmarks