This is a small CLI application which performs some operations over a weighted graph, such as:
- Number of vertices (nodes)
- Number of edges
- List all vertices
- Shortest path between two vertices
- Graph diameter
- Vertex with maximum degree centrality
- Vertex with maximum betweenness centrality
Developed by Mario Simão for the Programming Languages class, during the Computer and Electronic Engineering course at the Federal University of Rio de Janeiro (UFRJ).
$ make all
$ ./graph <command> [<args>]
The available commands are listed below.
Displays information about all commands.
$ ./graph help
Number of edges and vertices.
$ ./graph number <filename>
List all vertices.
$ ./graph vertices <filename>
Shortest path between source and target vertices
$ ./graph vertices <filename> <source> <target>
Graph diameter (longest path between all shortest paths).
$ ./graph diameter <filename>
Vertex with maximum degree centrality.
$ ./graph diameter <filename>
Vertex with maximum betweenness centrality.
$ ./graph betweenness <filename>
This program only supports CSV files where rows represent edges. Each edge is formed by the vertices names and a weight.
To represent the following graph
the CSV file would be:
A,B,0.9
A,C,3
B,D,4
C,D,2.6
D,E,1
This example is already on this repository (see simple.csv
).
To find the shortest path between A and E, execute
$ ./graph path simple.csv A E
and the program should return
Shortest path between 'A' and 'E'
Distance: 5.9
Path: E <- D <- B <- A
This repository also includes an example of European cities and the driving distances in hours between them. See europe.csv
.
To find longest path among the all possible shortest paths, execute:
$ ./graph diameter europe.csv
And the result would be from Lisbon to Sofia!
Graph diameter: longest path among the shortest paths between all vertices
Distance: 52
Path: sofia <- bucharest <- budapest <- bratislava <- prague <- berlin <- paris <- madrid <- lisbon