openGPMP
Open Source Mathematics Package
Functions
graphs_ex.cpp File Reference
#include <iostream>
#include <openGPMP/disct.hpp>
#include <vector>

Go to the source code of this file.

Functions

int main ()
 

Function Documentation

◆ main()

int main ( void  )

Definition at line 5 of file graphs_ex.cpp.

5  {
6  gpmp::Graph g(6);
7  g.add_edge(0, 1, 2);
8  g.add_edge(0, 2, 4);
9  g.add_edge(1, 3, 3);
10  g.add_edge(1, 4, 1);
11  g.add_edge(2, 5, 5);
12 
13  std::cout << "DFS Traversal starting from vertex 0: ";
14  g.dfs(0);
15  std::cout << std::endl;
16 
17  std::cout << "BFS Traversal starting from vertex 0: ";
18  g.bfs(0);
19  std::cout << std::endl;
20 
21  g.dijkstra(0);
22 
23  g.bellman_ford(0);
24 
25  std::cout << "Kruskal's Minimum Spanning Tree:\n";
26  std::vector<std::pair<int, std::pair<int, int>>> kruskalMST = g.kruskal();
27  for (const auto &edge : kruskalMST) {
28  std::cout << "Edge: " << edge.second.first << " - "
29  << edge.second.second << " | Weight: " << edge.first << "\n";
30  }
31 
32  g.floyd_warshall();
33 
34  std::cout << "Graph for Topological Sorting:\n";
35  gpmp::Graph dag(6);
36  dag.add_edge(0, 1, 1);
37  dag.add_edge(0, 2, 1);
38  dag.add_edge(1, 3, 1);
39  dag.add_edge(2, 3, 1);
40  dag.add_edge(3, 4, 1);
41  dag.add_edge(4, 5, 1);
42  dag.topo_sort();
43 
44  return 0;
45 }

References gpmp::Graph::add_edge(), gpmp::Graph::bellman_ford(), gpmp::Graph::bfs(), gpmp::Graph::dfs(), gpmp::Graph::dijkstra(), gpmp::Graph::floyd_warshall(), gpmp::Graph::kruskal(), and gpmp::Graph::topo_sort().