This is a C++ library for performing various graph algorithms. It includes implementations for algorithms such as checking if a graph is connected, finding the shortest path between two vertices, detecting cycles in a graph, determining if a graph is bipartite, and finding negative cycles in a weighted graph.
The library consists of several files:
Algorithms.cpp
andAlgorithms.hpp
: Implementations of various graph algorithms.Graph.cpp
andGraph.hpp
: Implementation of the Graph class used to represent a graph.Demo.cpp
: A demonstration of how to use the library to perform graph operations.testCounter.cpp
: A test runner to ensure a minimum number of tests are written.
These files contain the implementation of various graph algorithms, including:
isConnected
: Checks if the graph is connected.shortestPath
: Finds the shortest path between two vertices in the graph.isContainsCycle
: Checks if the graph contains a cycle.isBipartite
: Checks if the graph is bipartite.negativeCycle
: Finds a negative cycle in the graph.
These files contain the implementation of the Graph
class, which represents a graph using an adjacency matrix.
loadGraph
: Loads a graph from a given adjacency matrix.printGraph
: Prints information about the graph, including the number of vertices and edges.getMatrix
: Returns the adjacency matrix of the graph.
This file demonstrates how to use the graph algorithms library to perform various operations on graphs.
This file contains a test runner to ensure that a minimum number of tests are written for the library.
To use the library, include the necessary header files (Algorithms.hpp
and Graph.hpp
) in your C++ project and link against the implementation files (Algorithms.cpp
and Graph.cpp
).
#include "Algorithms.hpp"
#include "Graph.hpp"
#include <iostream>
int main() {
// Create a graph
ariel::Graph g;
// Load graph data
std::vector<std::vector<int>> graphData = {
{0, 1, 0},
{1, 0, 1},
{0, 1, 0}
};
g.loadGraph(graphData);
// Use graph algorithms
std::cout << "Is connected: " << ariel::Algorithms::isConnected(g) << std::endl;
// Perform other operations...
return 0;
}
CXX
: Specifies the C++ compiler asclang++
.CXXFLAGS
: Compiler flags for C++ code, including-std=c++11
,-Werror
(treats warnings as errors), and-Wsign-conversion
(warns about implicit conversions that may change the sign of a value).VALGRIND_FLAGS
: Flags for runningvalgrind
memory analysis.
SOURCES
: List of source files includingGraph.cpp
,Algorithms.cpp
,TestCounter.cpp
, andTest.cpp
.OBJECTS
: List of object files derived from source files by replacing.cpp
with.o
.
run
: Executes bothdemo
andtest
.demo
: Compiles and linksDemo.o
and other object files (excludingTestCounter.o
andTest.o
) into an executable nameddemo
.test
: Compiles and linksTestCounter.o
andTest.o
and other object files (excludingDemo.o
) into an executable namedtest
.tidy
: Runsclang-tidy
on source files with specific checks, treating warnings as errors.valgrind
: Runsvalgrind
on bothdemo
andtest
executables, checking for memory leaks.
%.o: %.cpp
: Compiles each.cpp
file into an object file.
clean
: Removes object files (*.o
),demo
, andtest
executables.