openGPMP
Open Source Mathematics Package
|
#include <graphs.hpp>
Public Member Functions | |
Graph (int v) | |
Constructor for the Graph class. More... | |
void | add_edge (int v, int w, int weight) |
Adds an edge between two vertices with a specified weight. More... | |
void | dfs (int start) |
Performs Depth-First Search (DFS) traversal starting from a given vertex. More... | |
void | dfs_rec (int v, std::vector< bool > &visited) |
Helper function for recursive Depth-First Search (DFS) traversal. More... | |
void | bfs (int start) |
Performs Breadth-First Search (BFS) traversal starting from a given vertex. More... | |
void | dijkstra (int start) |
Applies Dijkstra's algorithm to find the single-source shortest paths in the graph. More... | |
void | bellman_ford (int start) |
Applies Bellman-Ford algorithm to find the single-source shortest paths in the graph, handling negative weights. More... | |
std::vector< std::pair< int, std::pair< int, int > > > | kruskal () |
Applies Kruskal's algorithm to find the minimum spanning tree of the graph. More... | |
void | floyd_warshall () |
Applies Floyd-Warshall algorithm to find all-pairs shortest paths in the graph. More... | |
void | topo_sort () |
Performs topological sorting on a Directed Acyclic Graph (DAG) More... | |
std::vector< std::vector< int > > | connected_components () |
Finds connected components in an undirected graph using Depth-First Search (DFS) More... | |
bool | is_bipartite () |
Determines if a given graph is bipartite using BFS (Breadth First Search) More... | |
std::vector< double > | betweenness_centrality () |
Calculates betweenness centrality for each vertex in the graph. More... | |
bool | has_hamiltonian_circuit () |
Checks if the graph contains a Hamiltonian circuit. More... | |
bool | has_eulerian_path () |
Checks if the graph contains an Eulerian path. More... | |
int | eccentricity (int vertex) |
Calculates the eccentricity of a specified vertex in the graph. More... | |
int | radius () |
Calculates the radius of the graph. More... | |
std::vector< int > | greedy_coloring () |
Performs graph coloring using the greedy algorithm. More... | |
int | chromatic_number () |
Calculates the chromatic number of the graph. More... | |
std::vector< std::pair< int, int > > | match_cardinality () |
Finds a maximum cardinality matching in the graph using a greedy algorithm. More... | |
std::vector< std::pair< int, int > > | match_wt () |
Finds a maximum weight matching in the graph using a greedy algorithm. More... | |
bool | is_planar () |
Checks if the graph is planar using Kuratowski's theorem. More... | |
void | planar_gen (int num_vertices, double radius) |
Generates a random planar graph using the random geometric graph model. More... | |
bool | has_k5 () |
Checks if the graph contains a subgraph that is a subdivision of K5. More... | |
bool | has_k33 () |
Checks if the graph contains a subgraph that is a subdivision of K3,3. More... | |
bool | is_k33 (const std::set< int > &k_vertices) |
Checks if a set of vertices forms a subgraph that is a subdivision of K3,3. More... | |
double | euclid_dist (const std::pair< double, double > &point1, const std::pair< double, double > &point2) |
Calculates the Euclidean distance between two 2D points. More... | |
std::vector< uint64_t > | compress () |
Compresses the graph using Elias Gamma encoding. More... | |
void | decompress (const std::vector< uint64_t > &compressed) |
Decompresses a compressed graph using Elias Gamma encoding. More... | |
Public Attributes | |
int | vertices |
std::vector< std::vector< std::pair< int, int > > > | adj_list |
Private Member Functions | |
void | topo_sort_util (int v, std::vector< bool > &visited, std::stack< int > &topo_stack) |
Helper function for topological sorting. More... | |
int | find (std::vector< int > &parent, int i) |
Finds the representative element of the set that contains the given element. More... | |
void | union_sets (std::vector< int > &parent, int x, int y) |
Unions two sets by rank in the disjoint set data structure. More... | |
void | dfs_connected_components (int v, std::vector< bool > &visited, std::vector< int > &component) |
Performs Depth-First Search (DFS) traversal to find connected components in an undirected graph. More... | |
int | choose_random_neighbor (int vertex) |
Chooses a random neighbor of a given vertex. More... | |
bool | hamiltonian_circuit_util (int v, std::vector< bool > &visited, std::vector< int > &path, int count) |
Utility function for finding a Hamiltonian circuit. More... | |
Private Attributes | |
std::vector< bool > | is_matched |
Definition at line 49 of file graphs.hpp.
|
inline |
Constructor for the Graph class.
v | Number of vertices in the graph |
Definition at line 58 of file graphs.hpp.
void gpmp::Graph::add_edge | ( | int | v, |
int | w, | ||
int | weight | ||
) |
Adds an edge between two vertices with a specified weight.
v | The first vertex |
w | The second vertex |
weight | The weight of the edge |
Definition at line 44 of file graphs.cpp.
References adj_list.
Referenced by main().
void gpmp::Graph::bellman_ford | ( | int | start | ) |
Applies Bellman-Ford algorithm to find the single-source shortest paths in the graph, handling negative weights.
start | The starting vertex for Bellman-Ford algorithm |
Definition at line 116 of file graphs.cpp.
References u.
Referenced by main().
std::vector< double > gpmp::Graph::betweenness_centrality | ( | ) |
Calculates betweenness centrality for each vertex in the graph.
Definition at line 298 of file graphs.cpp.
void gpmp::Graph::bfs | ( | int | start | ) |
Performs Breadth-First Search (BFS) traversal starting from a given vertex.
start | The starting vertex for BFS traversal |
Definition at line 65 of file graphs.cpp.
Referenced by main().
|
private |
Chooses a random neighbor of a given vertex.
vertex | The vertex for which a random neighbor is chosen |
int gpmp::Graph::chromatic_number | ( | ) |
Calculates the chromatic number of the graph.
Definition at line 467 of file graphs.cpp.
References u.
std::vector< uint64_t > gpmp::Graph::compress | ( | ) |
Compresses the graph using Elias Gamma encoding.
Definition at line 693 of file graphs.cpp.
std::vector< std::vector< int > > gpmp::Graph::connected_components | ( | ) |
Finds connected components in an undirected graph using Depth-First Search (DFS)
Definition at line 254 of file graphs.cpp.
void gpmp::Graph::decompress | ( | const std::vector< uint64_t > & | compressed | ) |
Decompresses a compressed graph using Elias Gamma encoding.
compressed | Vector of uint64_t representing the compressed graph |
Definition at line 719 of file graphs.cpp.
void gpmp::Graph::dfs | ( | int | start | ) |
Performs Depth-First Search (DFS) traversal starting from a given vertex.
start | The starting vertex for DFS traversal |
Definition at line 49 of file graphs.cpp.
Referenced by main().
|
private |
Performs Depth-First Search (DFS) traversal to find connected components in an undirected graph.
This method is a helper function used by the connected_components method
v | The current vertex during DFS traversal |
visited | A vector indicating whether each vertex has been visited |
component | The connected component being formed during the traversal |
Definition at line 353 of file graphs.cpp.
References u.
void gpmp::Graph::dfs_rec | ( | int | v, |
std::vector< bool > & | visited | ||
) |
Helper function for recursive Depth-First Search (DFS) traversal.
v | The current vertex |
visited | A vector indicating whether each vertex has been visited |
Definition at line 54 of file graphs.cpp.
void gpmp::Graph::dijkstra | ( | int | start | ) |
Applies Dijkstra's algorithm to find the single-source shortest paths in the graph.
start | The starting vertex for Dijkstra's algorithm |
Definition at line 86 of file graphs.cpp.
References u.
Referenced by main().
int gpmp::Graph::eccentricity | ( | int | vertex | ) |
Calculates the eccentricity of a specified vertex in the graph.
vertex | The vertex for which eccentricity is calculated |
Definition at line 431 of file graphs.cpp.
References u.
double gpmp::Graph::euclid_dist | ( | const std::pair< double, double > & | point1, |
const std::pair< double, double > & | point2 | ||
) |
Calculates the Euclidean distance between two 2D points.
point1 | The first 2D point |
point2 | The second 2D point |
Definition at line 686 of file graphs.cpp.
|
private |
Finds the representative element of the set that contains the given element.
parent | The parent vector representing disjoint sets |
i | The element to find |
Definition at line 242 of file graphs.cpp.
void gpmp::Graph::floyd_warshall | ( | ) |
Applies Floyd-Warshall algorithm to find all-pairs shortest paths in the graph.
Definition at line 170 of file graphs.cpp.
Referenced by main().
std::vector< int > gpmp::Graph::greedy_coloring | ( | ) |
Performs graph coloring using the greedy algorithm.
Definition at line 511 of file graphs.cpp.
References u.
|
private |
Utility function for finding a Hamiltonian circuit.
v | The current vertex in the exploration |
visited | Vector indicating whether each vertex has been visited |
path | Vector representing the current path in the exploration |
count | The count of vertices visited so far |
Definition at line 395 of file graphs.cpp.
bool gpmp::Graph::has_eulerian_path | ( | ) |
Checks if the graph contains an Eulerian path.
Definition at line 381 of file graphs.cpp.
bool gpmp::Graph::has_hamiltonian_circuit | ( | ) |
Checks if the graph contains a Hamiltonian circuit.
Definition at line 367 of file graphs.cpp.
bool gpmp::Graph::has_k33 | ( | ) |
Checks if the graph contains a subgraph that is a subdivision of K3,3.
Definition at line 654 of file graphs.cpp.
bool gpmp::Graph::has_k5 | ( | ) |
Checks if the graph contains a subgraph that is a subdivision of K5.
Definition at line 624 of file graphs.cpp.
References u.
bool gpmp::Graph::is_bipartite | ( | ) |
Determines if a given graph is bipartite using BFS (Breadth First Search)
Definition at line 269 of file graphs.cpp.
References u.
bool gpmp::Graph::is_k33 | ( | const std::set< int > & | k_vertices | ) |
Checks if a set of vertices forms a subgraph that is a subdivision of K3,3.
vertices | The set of vertices to be checked |
Definition at line 672 of file graphs.cpp.
bool gpmp::Graph::is_planar | ( | ) |
Checks if the graph is planar using Kuratowski's theorem.
Definition at line 589 of file graphs.cpp.
std::vector< std::pair< int, std::pair< int, int > > > gpmp::Graph::kruskal | ( | ) |
Applies Kruskal's algorithm to find the minimum spanning tree of the graph.
Definition at line 139 of file graphs.cpp.
References u.
Referenced by main().
std::vector< std::pair< int, int > > gpmp::Graph::match_cardinality | ( | ) |
Finds a maximum cardinality matching in the graph using a greedy algorithm.
Definition at line 535 of file graphs.cpp.
References u.
std::vector< std::pair< int, int > > gpmp::Graph::match_wt | ( | ) |
Finds a maximum weight matching in the graph using a greedy algorithm.
Definition at line 557 of file graphs.cpp.
References u.
void gpmp::Graph::planar_gen | ( | int | num_vertices, |
double | radius | ||
) |
Generates a random planar graph using the random geometric graph model.
num_vertices | The number of vertices in the generated graph |
radius | The radius parameter for the random geometric graph model |
Definition at line 597 of file graphs.cpp.
References u.
int gpmp::Graph::radius | ( | ) |
Calculates the radius of the graph.
Definition at line 456 of file graphs.cpp.
void gpmp::Graph::topo_sort | ( | ) |
Performs topological sorting on a Directed Acyclic Graph (DAG)
Definition at line 209 of file graphs.cpp.
Referenced by main().
|
private |
Helper function for topological sorting.
v | The current vertex |
visited | A vector indicating whether each vertex has been visited |
topo_stack | The stack used for topological sorting |
Definition at line 227 of file graphs.cpp.
References u.
|
private |
Unions two sets by rank in the disjoint set data structure.
parent | The parent vector representing disjoint sets |
x | The representative element of the first set |
y | The representative element of the second set |
Definition at line 248 of file graphs.cpp.
std::vector<std::vector<std::pair<int, int> > > gpmp::Graph::adj_list |
Definition at line 52 of file graphs.hpp.
Referenced by add_edge().
|
private |
Definition at line 259 of file graphs.hpp.
int gpmp::Graph::vertices |
Definition at line 51 of file graphs.hpp.