A library of C++ code that implements graph theoretical algorithms to be used by projects that require some form of graph structured data.
Compile using cmake: Clone this project, go to the project main directory and run the following command and cmake will take care of all the compiling process.
cmake --build $(pwd)/cmake-build-debug --target GraphTheory -- -j 2
Then:
cd cmake-build-debug
./GraphTheory
// Include the Algorithm to be used.
#include "Algorithms/DijkstrasDistanceAlgorithm.h";
#include "Utils/Graph.h"
#include <iostream>
1. Dijkstra's Algorithm - Returns the length of the shortest path from a source vertex to every other vertex in the graph.
// Create an empty directed graph A.
Graph G('A', 'D');
// Add vertices and edges to the directed graph G.
G.add_edge('b', 'a', 15);
G.add_edge('b', 'c', 10);
G.add_edge('d', 'c', 10);
G.add_edge('d', 'g', 1);
G.add_edge('g', 'f', 2);
G.add_edge('f', 'e', 1);
G.add_edge('d', 'e', 8);
G.add_edge('b', 'd', 2);
G.add_edge('b', 'g', 6);
G.add_edge('g', 'a', 4);
G.add_edge('f', 'a', 7);
G.add_edge('e', 'c', 2);
// Compute the distance from vertex b to every other vertex in G.
map<char, int> distances_map = dijkstras_distances('b', G);
L(a) = 7
L(b) = 0
L(c) = 8
L(d) = 2
L(e) = 6
L(f) = 5
L(g) = 3