Skip to content

Commit

Permalink
refactor: rename variables
Browse files Browse the repository at this point in the history
Signed-off-by: Pankaj Khushalani <[email protected]>
  • Loading branch information
pk-218 committed Mar 30, 2024
1 parent 347a2de commit ca9825c
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 37 deletions.
6 changes: 3 additions & 3 deletions benchmarks/BoostMinSpanningTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#include <vector>
#include <Utility/Utils.h>

#define V 10
#define VERTICES 10
#define MAX_WEIGHT 1000

using namespace std;
Expand All @@ -47,8 +47,8 @@ Graph g;

void initializeBoostMinSpanningTree() {

const int vertices = V;
int num_edges = V * (V -1) / 2;
const int vertices = VERTICES;
int num_edges = VERTICES * (VERTICES - 1) / 2;

std::vector<int> edges;
std::vector<int> weight;
Expand Down
10 changes: 5 additions & 5 deletions benchmarks/GraphMlirMinSpanningTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,21 @@
#include <benchmark/benchmark.h>
#include <Utility/Utils.h>

#define V 10
#define VERTICES 10
#define MAX_WEIGHT 1000

using namespace std;

namespace {
Graph<int, 2> g(graph::detail::GRAPH_ADJ_MATRIX_UNDIRECTED_WEIGHTED, V);
Graph<int, 2> g(graph::detail::GRAPH_ADJ_MATRIX_UNDIRECTED_WEIGHTED, VERTICES);
MemRef<int, 2> *input;
intptr_t size[1];
} // namespace

void initializeGraphMlirMinSpanningTree() {
graph::generateRandomGraphI(&g, V);
graph::generateRandomGraphI(&g, VERTICES);
input = &g.get_Memref();
size[0] = V;
size[0] = VERTICES;

MemRef<int, 1> cost = MemRef<int, 1>(size, MAX_WEIGHT);
MemRef<int, 1> visited = MemRef<int, 1>(size, 0);
Expand Down Expand Up @@ -71,7 +71,7 @@ void generateResultGraphMlirMinSpanningTree() {
graph::min_spanning_tree(input, &output, &visited, &cost);

auto parent = output.getData();
for (int i = 0; i < V; i++) {
for (int i = 0; i < VERTICES; i++) {
std::cout << "p[" << i << "] = " << parent[i] << ", ";
}

Expand Down
26 changes: 11 additions & 15 deletions benchmarks/LemonMinSpanningTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,8 @@
using namespace std;
using namespace lemon;

#define V 10
#define MaxWeight 1000
#define UpperLimit 100
#define LowerLimit 2
#define VERTICES 10
#define MAX_WEIGHT 1000

typedef ListGraph::Node Node;
typedef ListGraph::Edge Edge;
Expand All @@ -40,39 +38,37 @@ typedef ListGraph::EdgeMap<int> ECostMap;

namespace {
ListGraph g;
ListGraph::Node nodes[V];
ListGraph::Node nodes[VERTICES];
ECostMap edge_cost_map(g);
} // namespace

void initializeLemonMinSpanningTree() {
for (int i = 0; i < V; i++) {
for (int i = 0; i < VERTICES; i++) {
nodes[i] = g.addNode();
}
std::set<std::pair<int, int>> container;
std::set<std::pair<int, int>>::iterator it;
srand(time(NULL));

int NUM = V; // Number of Vertices
int MAX_EDGES = V * (V - 1) / 2;
int NUMEDGE = MAX_EDGES; // Number of Edges
for (int j = 1; j <= NUMEDGE; j++) {
int a = rand() % NUM;
int b = rand() % NUM;
int edges = VERTICES * (VERTICES - 1) / 2;
for (int j = 1; j <= edges; j++) {
int a = rand() % VERTICES;
int b = rand() % VERTICES;

std::pair<int, int> p = std::make_pair(a, b);
std::pair<int, int> reverse_p = std::make_pair(b, a);

while (container.find(p) != container.end() ||
container.find(reverse_p) != container.end() || a==b) {
a = rand() % NUM;
b = rand() % NUM;
a = rand() % VERTICES;
b = rand() % VERTICES;
p = std::make_pair(a, b);
reverse_p = std::make_pair(b, a);
}

container.insert(p);
container.insert(reverse_p);
edge_cost_map.set(g.addEdge(nodes[a], nodes[b]), 1 + rand() % MaxWeight);
edge_cost_map.set(g.addEdge(nodes[a], nodes[b]), 1 + rand() % MAX_WEIGHT);
}
}

Expand Down
28 changes: 14 additions & 14 deletions benchmarks/MinSpanningTree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,31 +24,31 @@

using namespace std;

#define V 10
#define VERTICES 10
# define INF 1000

namespace {
int input[V][V];
int output[V];
int input[VERTICES][VERTICES];
int output[VERTICES];
} // namespace

void minSpanningTree(int graph[][V], int parent[V]) {
float key[V];
bool visited[V];
void minSpanningTree(int graph[][VERTICES], int parent[VERTICES]) {
float key[VERTICES];
bool visited[VERTICES];

for (int i = 0; i < V; i++) {
for (int i = 0; i < VERTICES; i++) {
key[i] = INF;
visited[i] = false;
}

key[0] = 0;
parent[0] = 0;

for (int count = 0; count < V-1; count++) {
for (int count = 0; count < VERTICES-1; count++) {
int min_index = -1;
float min_cost = INF;
int min_index_temp = -1;
for (int i = 0; i < V; i++) {
for (int i = 0; i < VERTICES; i++) {
min_index_temp = min_index;
if (visited[i] == false && key[i] < min_cost) {
min_cost = key[i];
Expand All @@ -60,7 +60,7 @@ void minSpanningTree(int graph[][V], int parent[V]) {
}
visited[min_index] = true;

for (int v = 0; v < V; v++) {
for (int v = 0; v < VERTICES; v++) {
if (graph[min_index][v] && visited[v] == false && graph[min_index][v] < key[v]) {
parent[v] = min_index;
key[v] = graph[min_index][v];
Expand All @@ -70,10 +70,10 @@ void minSpanningTree(int graph[][V], int parent[V]) {
}

void initializeMinSpanningTree() {
int MAX_EDGES = V * (V - 1) / 2;
int MAX_EDGES = VERTICES * (VERTICES - 1) / 2;
for (int i = 0; i < MAX_EDGES; i++) {
int u = rand() % V;
int v = rand() % V;
int u = rand() % VERTICES;
int v = rand() % VERTICES;
int d = rand() % 1000;
input[u][v] = d;
}
Expand All @@ -99,7 +99,7 @@ void generateResultMinSpanningTree() {

minSpanningTree(input, output);

for (int i = 0; i < V; i++) {
for (int i = 0; i < VERTICES; i++) {
std::cout << "p[" << i << "] = " << output[i] << ", ";
}
std::cout << "\nMinimum Spanning Tree operation finished!\n";
Expand Down

0 comments on commit ca9825c

Please sign in to comment.