Bellman-Ford

command module
v0.0.0-...-2fe9fae Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 17, 2026 License: MIT Imports: 6 Imported by: 0

README

Bellman-Ford

Bellman-Ford implementation

Overview

This application computes the shortest paths between all vertex pairs in a directed graph using the Bellman-Ford algorithm. It returns the total cost of the shortest of the shortest paths, and detects if there is a negative-cost directed cycle within the graph (in which case the cost of the shortest paths is invalid).

Input format

The graph must be represented by an adjacency list in a text file. The first line must contain the number of verticies in the graph. Each additional line must contain three integers representing an edge, with the first integer being the id of the tail vertex, the second the id of the head vertex, and the third the edge cost. Vertex ids must range from 1 to n, the total number of verticies.

Usage

go run main.go -i paths.txt

2018/04/24 14:48:12 The min path was of cost -4
2018/04/24 14:48:12 There was a negative cost cycle detected.

Documentation

The Go Gopher

There is no documentation for this package.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL