Skip to content

esimon113/pathfinder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Pathfinder

This repo is a personal learning project focussed on implementing some graph algorithms while improving my skills in:

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.

Features

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.

Project Structure

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)

Building and Running

Build and Run

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

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)

Examples

# 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

Inspirations / Future Ideas

Shortest Paths

Minimum Spanning Tree (greedy algorithms)

Max-Flow Algorithms

Strongly Connected Components

Topological Sort

Graph Coloring Algorithms

Tours through Graphs

Other

Resources / Interesting

About

Implementing some graph-algorithms while playing around with odin-lang...

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages