forked from meshtag/GraphMLIR
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbfsExample.cpp
More file actions
57 lines (47 loc) · 1.61 KB
/
bfsExample.cpp
File metadata and controls
57 lines (47 loc) · 1.61 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
//====- bfs.cpp - Example of graph-opt tool ========================//
//
// The graph.bfs operation will be compiled into an object file with the
// graph-opt tool.
// This file will be linked with the object file to generate the executable
// file.
//
//===----------------------------------------------------------------------===//
#include <Interface/Container.h>
#include <Interface/GraphContainer.h>
#include <Interface/graph.h>
#include <iostream>
#include <vector>
int main() {
// Graph<float, 2>
// sample_graph(graph::detail::GRAPH_ADJ_MATRIX_DIRECTED_WEIGHTED, 5);
// use for unweighted graph
// sample_graph.addEdge(0,2);
// sample_graph.addEdge(2,3);
// sample_graph.addEdge(3,2);
// sample_graph.addEdge(2,2);
// sample_graph.addEdge(1,2);
// use for weighted graph
Graph<float, 2> sample_graph(
graph::detail::GRAPH_INC_MATRIX_DIRECTED_WEIGHTED, 6);
sample_graph.addEdge(1,0,2);
sample_graph.addEdge(3,1,3);
sample_graph.addEdge(4,1,4);
sample_graph.addEdge(4,2,5);
sample_graph.addEdge(5,1,6);
// this will print the original graph.
std::cout << "Printing graph in format it was entered ( "
"GRAPH_ADJ_MARIX_DIRECTED_WEIGHTED )\n";
sample_graph.printGraphOg();
auto x = sample_graph.get_Memref();
auto x1 = sample_graph.get_Memref();
if (x == x1) {
std::cout<< "the two memref are equal "<<std::endl;
}
// this will print the linear 2d matrix in 2d form.
std::cout
<< "Printing graph in form of 2d matrix after conversion to memref\n";
sample_graph.printGraph();
graph::graph_bfs(x, x, x);
x.release();
std::cout << "End of the program! \n";
}